]> granicus.if.org Git - clang/commitdiff
PCH support for CompoundLiteralExpr. This is the last C expression
authorDouglas Gregor <dgregor@apple.com>
Thu, 16 Apr 2009 02:33:48 +0000 (02:33 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 16 Apr 2009 02:33:48 +0000 (02:33 +0000)
that does not require PCH support for statements. Only AddrLabelExpr,
StmtExpr, and BlockExpr remain (for C).

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

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

index fbe2953300235c2d64e672c65e4cf157e40ab2b3..9936965bbb7464d08dbb60c62b00e4bf6af16d00 100644 (file)
@@ -1137,13 +1137,20 @@ public:
     : 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)
index 6a75245b8014bba9c6c5e473588599f8bc152540..a4a0675df0772b35e1ddda35fe5719b608de64c5 100644 (file)
@@ -419,7 +419,8 @@ namespace clang {
       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.
index 2da35a09d64bef3e84bc0f008194a988c9542819..e24a155146c8300fda01541a5431bcbc8f52486e 100644 (file)
@@ -257,6 +257,7 @@ namespace {
     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 @@ unsigned PCHStmtReader::VisitCStyleCastExpr(CStyleCastExpr *E) {
   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 @@ Expr *PCHReader::ReadExpr() {
       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;
index f96288864bea4904b3ba9df0299a6a12132328ab..c89e3546bf6ee77bd5a469ec2b68d9cf0b9b337d 100644 (file)
@@ -464,6 +464,7 @@ namespace {
     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 @@ void PCHStmtWriter::VisitCStyleCastExpr(CStyleCastExpr *E) {
   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());
index e08024b9bb87a31cde234be5993bd58ef9d575eb..ced6d178b4ea06700860361a77b53520077982e4 100644 (file)
@@ -61,6 +61,10 @@ conditional_operator *double_ptr4 = &floating;
 // CStyleCastExpr
 void_ptr vp1 = &integer;
 
+// CompoundLiteral
+struct S s;
+compound_literal *sptr = &s;
+
 // ExtVectorElementExpr
 ext_vector_element *double_ptr5 = &floating;
 
index 43fd89595e9fc9c6789fa707af48553958ba65ee..7012422aad331792d89ed77aeeb7d8f55e4f0e34 100644 (file)
@@ -56,6 +56,9 @@ typedef typeof(i? : d0) conditional_operator;
 // 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;