diff --git a/clang/AST/StmtPrinter.cpp b/clang/AST/StmtPrinter.cpp index ef956284619f..a3fff0243056 100644 --- a/clang/AST/StmtPrinter.cpp +++ b/clang/AST/StmtPrinter.cpp @@ -423,6 +423,10 @@ void StmtPrinter::VisitCastExpr(CastExpr *Node) { OS << "(" << Node->getType().getAsString() << ")"; PrintExpr(Node->getSubExpr()); } +void StmtPrinter::VisitCompoundLiteralExpr(CompoundLiteralExpr *Node) { + OS << "(" << Node->getType().getAsString() << ")"; + PrintExpr(Node->getInitializer()); +} void StmtPrinter::VisitImplicitCastExpr(ImplicitCastExpr *Node) { // No need to print anything, simply forward to the sub expression. PrintExpr(Node->getSubExpr()); diff --git a/clang/Sema/SemaExpr.cpp b/clang/Sema/SemaExpr.cpp index 999f29a8ae37..0d4c04a6f835 100644 --- a/clang/Sema/SemaExpr.cpp +++ b/clang/Sema/SemaExpr.cpp @@ -472,14 +472,15 @@ ParseCallExpr(ExprTy *Fn, SourceLocation LParenLoc, Action::ExprResult Sema:: ParseCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty, - SourceLocation RParenLoc, ExprTy *Op) { + SourceLocation RParenLoc, ExprTy *InitExpr) { assert((Ty != 0) && "ParseCompoundLiteral(): missing type"); QualType literalType = QualType::getFromOpaquePtr(Ty); - assert((Op != 0) && "ParseCompoundLiteral(): missing expression"); - Expr *literalExpr = static_cast(Op); + // FIXME: put back this assert when initializers are worked out. + //assert((InitExpr != 0) && "ParseCompoundLiteral(): missing expression"); + Expr *literalExpr = static_cast(InitExpr); // FIXME: add semantic analysis (C99 6.5.2.5). - return false; // FIXME: instantiate a CompoundLiteralExpr + return new CompoundLiteralExpr(literalType, literalExpr); } Action::ExprResult Sema:: diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h index ff689c4b95fe..fcf83b4ca3d6 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -434,6 +434,25 @@ public: static bool classof(const MemberExpr *) { return true; } }; +/// CompoundLiteralExpr - [C99 6.5.2.5] +/// +class CompoundLiteralExpr : public Expr { + Expr *Init; +public: + CompoundLiteralExpr(QualType ty, Expr *init) : + Expr(CompoundLiteralExprClass, ty), Init(init) {} + + Expr *getInitializer() const { return Init; } + + virtual SourceRange getSourceRange() const { return SourceRange(); } // FIXME + + virtual void visit(StmtVisitor &Visitor); + static bool classof(const Stmt *T) { + return T->getStmtClass() == CompoundLiteralExprClass; + } + static bool classof(const CompoundLiteralExpr *) { return true; } +}; + /// ImplicitCastExpr - Allows us to explicitly represent implicit type /// conversions. For example: converting T[]->T*, void f()->void (*f)(), /// float->double, short->int, etc. @@ -447,7 +466,7 @@ public: Expr *getSubExpr() { return Op; } const Expr *getSubExpr() const { return Op; } - virtual SourceRange getSourceRange() const { return SourceRange(); } + virtual SourceRange getSourceRange() const { return SourceRange(); } // FIXME virtual void visit(StmtVisitor &Visitor); static bool classof(const Stmt *T) { @@ -479,7 +498,6 @@ public: static bool classof(const CastExpr *) { return true; } }; - class BinaryOperator : public Expr { public: enum Opcode { diff --git a/clang/include/clang/AST/StmtNodes.def b/clang/include/clang/AST/StmtNodes.def index 221de3eb526a..c48b6ca5c479 100644 --- a/clang/include/clang/AST/StmtNodes.def +++ b/clang/include/clang/AST/StmtNodes.def @@ -59,14 +59,15 @@ STMT(44, CastExpr , Expr) STMT(45, BinaryOperator , Expr) STMT(46, ConditionalOperator , Expr) STMT(47, ImplicitCastExpr , Expr) +STMT(48, CompoundLiteralExpr , Expr) // GNU Extensions. -STMT(48, AddrLabel , Expr) +STMT(49, AddrLabel , Expr) // C++ Expressions. -STMT(49, CXXCastExpr , Expr) -STMT(50, CXXBoolLiteralExpr , Expr) -LAST_EXPR(50) +STMT(50, CXXCastExpr , Expr) +STMT(51, CXXBoolLiteralExpr , Expr) +LAST_EXPR(51) #undef STMT #undef FIRST_STMT