[cfe-commits] r69255 - in /cfe/trunk: include/clang/AST/Expr.h include/clang/Frontend/PCHBitCodes.h lib/Frontend/PCHReader.cpp lib/Frontend/PCHWriter.cpp test/PCH/exprs.c test/PCH/exprs.h

Douglas Gregor dgregor at apple.com
Wed Apr 15 19:33:48 PDT 2009


Author: dgregor
Date: Wed Apr 15 21:33:48 2009
New Revision: 69255

URL: http://llvm.org/viewvc/llvm-project?rev=69255&view=rev
Log:
PCH support for CompoundLiteralExpr. This is the last C expression
that does not require PCH support for statements. Only AddrLabelExpr,
StmtExpr, and BlockExpr remain (for C).

Modified:
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/include/clang/Frontend/PCHBitCodes.h
    cfe/trunk/lib/Frontend/PCHReader.cpp
    cfe/trunk/lib/Frontend/PCHWriter.cpp
    cfe/trunk/test/PCH/exprs.c
    cfe/trunk/test/PCH/exprs.h

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

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Wed Apr 15 21:33:48 2009
@@ -1137,13 +1137,20 @@
     : Expr(CompoundLiteralExprClass, ty), LParenLoc(lparenloc), Init(init),
       FileScope(fileScope) {}
   
+  /// \brief Construct an empty compound literal.
+  explicit CompoundLiteralExpr(EmptyShell Empty)
+    : Expr(CompoundLiteralExprClass, Empty) { }
+
   const Expr *getInitializer() const { return cast<Expr>(Init); }
   Expr *getInitializer() { return cast<Expr>(Init); }
+  void setInitializer(Expr *E) { Init = E; }
 
   bool isFileScope() const { return FileScope; }
-  
+  void setFileScope(bool FS) { FileScope = FS; }
+
   SourceLocation getLParenLoc() const { return LParenLoc; }
-  
+  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
+
   virtual SourceRange getSourceRange() const {
     // FIXME: Init should never be null.
     if (!Init)

Modified: cfe/trunk/include/clang/Frontend/PCHBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHBitCodes.h?rev=69255&r1=69254&r2=69255&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHBitCodes.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHBitCodes.h Wed Apr 15 21:33:48 2009
@@ -419,7 +419,8 @@
       EXPR_IMPLICIT_CAST,
       /// \brief A CStyleCastExpr record.
       EXPR_CSTYLE_CAST,
-      /// FIXME: CompoundLiteralExpr
+      /// \brief A CompoundLiteralExpr record.
+      EXPR_COMPOUND_LITERAL,
       /// \brief An ExtVectorElementExpr record.
       EXPR_EXT_VECTOR_ELEMENT,
       /// \brief An InitListExpr record.

Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=69255&r1=69254&r2=69255&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Wed Apr 15 21:33:48 2009
@@ -257,6 +257,7 @@
     unsigned VisitImplicitCastExpr(ImplicitCastExpr *E);
     unsigned VisitExplicitCastExpr(ExplicitCastExpr *E);
     unsigned VisitCStyleCastExpr(CStyleCastExpr *E);
+    unsigned VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
     unsigned VisitExtVectorElementExpr(ExtVectorElementExpr *E);
     unsigned VisitInitListExpr(InitListExpr *E);
     unsigned VisitDesignatedInitExpr(DesignatedInitExpr *E);
@@ -447,6 +448,14 @@
   return 1;
 }
 
+unsigned PCHStmtReader::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
+  VisitExpr(E);
+  E->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  E->setInitializer(ExprStack.back());
+  E->setFileScope(Record[Idx++]);
+  return 1;
+}
+
 unsigned PCHStmtReader::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
   VisitExpr(E);
   E->setBase(ExprStack.back());
@@ -2103,6 +2112,10 @@
       E = new (Context) CStyleCastExpr(Empty);
       break;
 
+    case pch::EXPR_COMPOUND_LITERAL:
+      E = new (Context) CompoundLiteralExpr(Empty);
+      break;
+
     case pch::EXPR_EXT_VECTOR_ELEMENT:
       E = new (Context) ExtVectorElementExpr(Empty);
       break;

Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=69255&r1=69254&r2=69255&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Wed Apr 15 21:33:48 2009
@@ -464,6 +464,7 @@
     void VisitImplicitCastExpr(ImplicitCastExpr *E);
     void VisitExplicitCastExpr(ExplicitCastExpr *E);
     void VisitCStyleCastExpr(CStyleCastExpr *E);
+    void VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
     void VisitExtVectorElementExpr(ExtVectorElementExpr *E);
     void VisitInitListExpr(InitListExpr *E);
     void VisitDesignatedInitExpr(DesignatedInitExpr *E);
@@ -647,6 +648,14 @@
   Code = pch::EXPR_CSTYLE_CAST;
 }
 
+void PCHStmtWriter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
+  VisitExpr(E);
+  Writer.AddSourceLocation(E->getLParenLoc(), Record);
+  Writer.WriteSubExpr(E->getInitializer());
+  Record.push_back(E->isFileScope());
+  Code = pch::EXPR_COMPOUND_LITERAL;
+}
+
 void PCHStmtWriter::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
   VisitExpr(E);
   Writer.WriteSubExpr(E->getBase());

Modified: cfe/trunk/test/PCH/exprs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/exprs.c?rev=69255&r1=69254&r2=69255&view=diff

==============================================================================
--- cfe/trunk/test/PCH/exprs.c (original)
+++ cfe/trunk/test/PCH/exprs.c Wed Apr 15 21:33:48 2009
@@ -61,6 +61,10 @@
 // CStyleCastExpr
 void_ptr vp1 = &integer;
 
+// CompoundLiteral
+struct S s;
+compound_literal *sptr = &s;
+
 // ExtVectorElementExpr
 ext_vector_element *double_ptr5 = &floating;
 

Modified: cfe/trunk/test/PCH/exprs.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/exprs.h?rev=69255&r1=69254&r2=69255&view=diff

==============================================================================
--- cfe/trunk/test/PCH/exprs.h (original)
+++ cfe/trunk/test/PCH/exprs.h Wed Apr 15 21:33:48 2009
@@ -56,6 +56,9 @@
 // CStyleCastExpr
 typedef typeof((void *)0) void_ptr;
 
+// CompoundLiteral
+typedef typeof((struct S){.x = 3.5}) compound_literal;
+
 // ExtVectorElementExpr
 typedef __attribute__(( ext_vector_type(2) )) double double2;
 extern double2 vec2, vec2b;





More information about the cfe-commits mailing list