diff options
author | Steve Naroff <snaroff@apple.com> | 2007-07-19 21:32:11 +0000 |
---|---|---|
committer | Steve Naroff <snaroff@apple.com> | 2007-07-19 21:32:11 +0000 |
commit | 57eb2c5f58628f0a40a95b4ea383bdbe5bc33ad0 (patch) | |
tree | 3fe906b9f9d6604987af3d97d1e7c820a8d5920b | |
parent | 68ee4e8efc466e8346ae755724e0ff8082c6bc37 (diff) | |
download | bcm5719-llvm-57eb2c5f58628f0a40a95b4ea383bdbe5bc33ad0.tar.gz bcm5719-llvm-57eb2c5f58628f0a40a95b4ea383bdbe5bc33ad0.zip |
Finish fixing crasher with compound literals.
We still need to do sematic analysis (and implement initializers), however this
should complete the parsing & ast building for compound literals.
llvm-svn: 40067
-rw-r--r-- | clang/AST/StmtPrinter.cpp | 4 | ||||
-rw-r--r-- | clang/Sema/SemaExpr.cpp | 9 | ||||
-rw-r--r-- | clang/include/clang/AST/Expr.h | 22 | ||||
-rw-r--r-- | clang/include/clang/AST/StmtNodes.def | 9 |
4 files changed, 34 insertions, 10 deletions
diff --git a/clang/AST/StmtPrinter.cpp b/clang/AST/StmtPrinter.cpp index ef956284619..a3fff024305 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 999f29a8ae3..0d4c04a6f83 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<Expr*>(Op); + // FIXME: put back this assert when initializers are worked out. + //assert((InitExpr != 0) && "ParseCompoundLiteral(): missing expression"); + Expr *literalExpr = static_cast<Expr*>(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 ff689c4b95f..fcf83b4ca3d 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 221de3eb526..c48b6ca5c47 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 |