]> granicus.if.org Git - clang/commitdiff
Finish fixing crasher with compound literals.
authorSteve Naroff <snaroff@apple.com>
Thu, 19 Jul 2007 21:32:11 +0000 (21:32 +0000)
committerSteve Naroff <snaroff@apple.com>
Thu, 19 Jul 2007 21:32:11 +0000 (21:32 +0000)
We still need to do sematic analysis (and implement initializers), however this
should complete the parsing & ast building for compound literals.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40067 91177308-0d34-0410-b5e6-96231b3b80d8

AST/StmtPrinter.cpp
Sema/SemaExpr.cpp
include/clang/AST/Expr.h
include/clang/AST/StmtNodes.def

index ef956284619ff027ee011898779646e514d6330a..a3fff0243056a5b4c4fbb09b88b86ff2c5dba638 100644 (file)
@@ -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());
index 999f29a8ae376693bbb00c920d7fc353f35b0fb4..0d4c04a6f8357c2dcad325c1e88d47e1dd2e0162 100644 (file)
@@ -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::
index ff689c4b95fe0d6e6b79674d1e78d41d3612f52a..fcf83b4ca3d661a5f69d81a8a1fbfeb454a48739 100644 (file)
@@ -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 {
index 221de3eb526a365e02fabc849a6c9e3254d94aaf..c48b6ca5c4795413fcae4455470fe679cd8c6aa6 100644 (file)
@@ -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