[cfe-commits] r40067 - in /cfe/trunk: AST/StmtPrinter.cpp Sema/SemaExpr.cpp include/clang/AST/Expr.h include/clang/AST/StmtNodes.def

Steve Naroff snaroff at apple.com
Thu Jul 19 14:32:11 PDT 2007


Author: snaroff
Date: Thu Jul 19 16:32:11 2007
New Revision: 40067

URL: http://llvm.org/viewvc/llvm-project?rev=40067&view=rev
Log:
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.

Modified:
    cfe/trunk/AST/StmtPrinter.cpp
    cfe/trunk/Sema/SemaExpr.cpp
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/include/clang/AST/StmtNodes.def

Modified: cfe/trunk/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/StmtPrinter.cpp?rev=40067&r1=40066&r2=40067&view=diff

==============================================================================
--- cfe/trunk/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/AST/StmtPrinter.cpp Thu Jul 19 16:32:11 2007
@@ -423,6 +423,10 @@
   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());

Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=40067&r1=40066&r2=40067&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Thu Jul 19 16:32:11 2007
@@ -472,14 +472,15 @@
 
 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::

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=40067&r1=40066&r2=40067&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Thu Jul 19 16:32:11 2007
@@ -434,6 +434,25 @@
   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 @@
   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 @@
   static bool classof(const CastExpr *) { return true; }
 };
 
-
 class BinaryOperator : public Expr {
 public:
   enum Opcode {

Modified: cfe/trunk/include/clang/AST/StmtNodes.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/StmtNodes.def?rev=40067&r1=40066&r2=40067&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/StmtNodes.def (original)
+++ cfe/trunk/include/clang/AST/StmtNodes.def Thu Jul 19 16:32:11 2007
@@ -59,14 +59,15 @@
 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





More information about the cfe-commits mailing list