[cfe-commits] r108042 - in /cfe/trunk: include/clang/AST/ExprCXX.h include/clang/Frontend/PCHBitCodes.h lib/AST/ExprCXX.cpp lib/Frontend/PCHReaderStmt.cpp lib/Frontend/PCHWriterStmt.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Sat Jul 10 04:46:15 PDT 2010


Author: akirtzidis
Date: Sat Jul 10 06:46:15 2010
New Revision: 108042

URL: http://llvm.org/viewvc/llvm-project?rev=108042&view=rev
Log:
Add PCH support for the remaining C++ exprs.

Modified:
    cfe/trunk/include/clang/AST/ExprCXX.h
    cfe/trunk/include/clang/Frontend/PCHBitCodes.h
    cfe/trunk/lib/AST/ExprCXX.cpp
    cfe/trunk/lib/Frontend/PCHReaderStmt.cpp
    cfe/trunk/lib/Frontend/PCHWriterStmt.cpp

Modified: cfe/trunk/include/clang/AST/ExprCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=108042&r1=108041&r2=108042&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Sat Jul 10 06:46:15 2010
@@ -648,6 +648,9 @@
   static CXXBindReferenceExpr *Create(ASTContext &C, Expr *SubExpr,
                                       bool ExtendsLifetime, 
                                       bool RequiresTemporaryCopy);
+  
+  explicit CXXBindReferenceExpr(EmptyShell Empty)
+    : Expr(CXXBindReferenceExprClass, Empty) { }
 
   const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
   Expr *getSubExpr() { return cast<Expr>(SubExpr); }
@@ -663,7 +666,7 @@
 
   // extendsLifetime - Whether binding this reference extends the lifetime of
   // the expression being bound. FIXME: Add C++ reference.
-  bool extendsLifetime() { return ExtendsLifetime; }
+  bool extendsLifetime() const { return ExtendsLifetime; }
     
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Stmt *T) {
@@ -674,6 +677,8 @@
   // Iterators
   virtual child_iterator child_begin();
   virtual child_iterator child_end();
+  
+  friend class PCHStmtReader;
 };
 
 /// CXXConstructExpr - Represents a call to a C++ constructor.
@@ -704,13 +709,20 @@
                    ConstructionKind ConstructKind = CK_Complete);
   ~CXXConstructExpr() { }
 
+  /// \brief Construct an empty C++ construction expression.
+  CXXConstructExpr(StmtClass SC, EmptyShell Empty)
+    : Expr(SC, Empty), Constructor(0), Elidable(0), ZeroInitialization(0),
+      ConstructKind(0), Args(0), NumArgs(0) { }
+
   virtual void DoDestroy(ASTContext &C);
 
 public:
-  /// \brief Construct an empty C++ construction expression that will store
-  /// \p numargs arguments.
-  CXXConstructExpr(EmptyShell Empty, ASTContext &C, unsigned numargs);
-  
+  /// \brief Construct an empty C++ construction expression.
+  explicit CXXConstructExpr(EmptyShell Empty)
+    : Expr(CXXConstructExprClass, Empty), Constructor(0),
+      Elidable(0), ZeroInitialization(0),
+      ConstructKind(0), Args(0), NumArgs(0) { }
+
   static CXXConstructExpr *Create(ASTContext &C, QualType T,
                                   SourceLocation Loc,
                                   CXXConstructorDecl *D, bool Elidable,
@@ -783,6 +795,8 @@
   // Iterators
   virtual child_iterator child_begin();
   virtual child_iterator child_end();
+
+  friend class PCHStmtReader;
 };
 
 /// CXXFunctionalCastExpr - Represents an explicit C++ type conversion
@@ -842,6 +856,8 @@
                          Expr **Args,unsigned NumArgs,
                          SourceLocation rParenLoc,
                          bool ZeroInitialization = false);
+  explicit CXXTemporaryObjectExpr(EmptyShell Empty)
+    : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty) { }
 
   ~CXXTemporaryObjectExpr() { }
 
@@ -855,6 +871,8 @@
     return T->getStmtClass() == CXXTemporaryObjectExprClass;
   }
   static bool classof(const CXXTemporaryObjectExpr *) { return true; }
+
+  friend class PCHStmtReader;
 };
 
 /// CXXScalarValueInitExpr - [C++ 5.2.3p2]
@@ -1338,6 +1356,9 @@
     : Expr(UnaryTypeTraitExprClass, ty, false, queried->isDependentType()),
       UTT(utt), Loc(loc), RParen(rparen), QueriedType(queried) { }
 
+  explicit UnaryTypeTraitExpr(EmptyShell Empty)
+    : Expr(UnaryTypeTraitExprClass, Empty), UTT((UnaryTypeTrait)0) { }
+
   virtual SourceRange getSourceRange() const { return SourceRange(Loc, RParen);}
 
   UnaryTypeTrait getTrait() const { return UTT; }
@@ -1354,6 +1375,8 @@
   // Iterators
   virtual child_iterator child_begin();
   virtual child_iterator child_end();
+
+  friend class PCHStmtReader;
 };
 
 /// \brief A reference to an overloaded function set, either an

Modified: cfe/trunk/include/clang/Frontend/PCHBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHBitCodes.h?rev=108042&r1=108041&r2=108042&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHBitCodes.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHBitCodes.h Sat Jul 10 06:46:15 2010
@@ -762,6 +762,8 @@
       EXPR_CXX_MEMBER_CALL,
       /// \brief A CXXConstructExpr record.
       EXPR_CXX_CONSTRUCT,
+      /// \brief A CXXTemporaryObjectExpr record.
+      EXPR_CXX_TEMPORARY_OBJECT,
       // \brief A CXXStaticCastExpr record.
       EXPR_CXX_STATIC_CAST,
       // \brief A CXXDynamicCastExpr record.
@@ -781,7 +783,8 @@
       EXPR_CXX_THROW,             // CXXThrowExpr
       EXPR_CXX_DEFAULT_ARG,       // CXXDefaultArgExpr
       EXPR_CXX_BIND_TEMPORARY,    // CXXBindTemporaryExpr
-      //
+      EXPR_CXX_BIND_REFERENCE,    // CXXBindReferenceExpr
+
       EXPR_CXX_SCALAR_VALUE_INIT, // CXXScalarValueInitExpr
       EXPR_CXX_NEW,               // CXXNewExpr
       EXPR_CXX_DELETE,            // CXXDeleteExpr
@@ -793,7 +796,9 @@
       EXPR_CXX_DEPENDENT_SCOPE_DECL_REF,   // DependentScopeDeclRefExpr
       EXPR_CXX_UNRESOLVED_CONSTRUCT, // CXXUnresolvedConstructExpr
       EXPR_CXX_UNRESOLVED_MEMBER,    // UnresolvedMemberExpr
-      EXPR_CXX_UNRESOLVED_LOOKUP     // UnresolvedLookupExpr
+      EXPR_CXX_UNRESOLVED_LOOKUP,     // UnresolvedLookupExpr
+
+      EXPR_CXX_UNARY_TYPE_TRAIT   // UnaryTypeTraitExpr  
     };
 
     /// \brief The kinds of designators that can occur in a

Modified: cfe/trunk/lib/AST/ExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprCXX.cpp?rev=108042&r1=108041&r2=108042&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprCXX.cpp (original)
+++ cfe/trunk/lib/AST/ExprCXX.cpp Sat Jul 10 06:46:15 2010
@@ -569,14 +569,6 @@
   }
 }
 
-CXXConstructExpr::CXXConstructExpr(EmptyShell Empty, ASTContext &C, 
-                                   unsigned numargs)
-  : Expr(CXXConstructExprClass, Empty), Args(0), NumArgs(numargs) 
-{
-  if (NumArgs)
-    Args = new (C) Stmt*[NumArgs];
-}
-
 void CXXConstructExpr::DoDestroy(ASTContext &C) {
   DestroyChildren(C);
   if (Args)

Modified: cfe/trunk/lib/Frontend/PCHReaderStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderStmt.cpp?rev=108042&r1=108041&r2=108042&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderStmt.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderStmt.cpp Sat Jul 10 06:46:15 2010
@@ -118,6 +118,7 @@
 
     void VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E);
     void VisitCXXConstructExpr(CXXConstructExpr *E);
+    void VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E);
     void VisitCXXNamedCastExpr(CXXNamedCastExpr *E);
     void VisitCXXStaticCastExpr(CXXStaticCastExpr *E);
     void VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E);
@@ -131,6 +132,7 @@
     void VisitCXXThrowExpr(CXXThrowExpr *E);
     void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E);
     void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E);
+    void VisitCXXBindReferenceExpr(CXXBindReferenceExpr *E);
     
     void VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E);
     void VisitCXXNewExpr(CXXNewExpr *E);
@@ -146,6 +148,8 @@
     void VisitOverloadExpr(OverloadExpr *E);
     void VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E);
     void VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E);
+
+    void VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *E);
   };
 }
 
@@ -927,8 +931,9 @@
 
 void PCHStmtReader::VisitCXXConstructExpr(CXXConstructExpr *E) {
   VisitExpr(E);
-  assert(Record[Idx] == E->getNumArgs() &&"Read wrong record during creation?");
-  ++Idx; // NumArgs;
+  E->NumArgs = Record[Idx++];
+  if (E->NumArgs)
+    E->Args = new (*Reader.getContext()) Stmt*[E->NumArgs];
   for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
     E->setArg(I, Reader.ReadSubExpr());
   E->setConstructor(cast<CXXConstructorDecl>(Reader.GetDecl(Record[Idx++])));
@@ -938,6 +943,12 @@
   E->setConstructionKind((CXXConstructExpr::ConstructionKind)Record[Idx++]);
 }
 
+void PCHStmtReader::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
+  VisitCXXConstructExpr(E);
+  E->TyBeginLoc = Reader.ReadSourceLocation(Record, Idx);
+  E->RParenLoc = Reader.ReadSourceLocation(Record, Idx);
+}
+
 void PCHStmtReader::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
   VisitExplicitCastExpr(E);
   E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
@@ -1015,6 +1026,13 @@
   E->setSubExpr(Reader.ReadSubExpr());
 }
 
+void PCHStmtReader::VisitCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
+  VisitExpr(E);
+  E->SubExpr = Reader.ReadSubExpr();
+  E->ExtendsLifetime = Record[Idx++];
+  E->RequiresTemporaryCopy = Record[Idx++];
+}
+
 void PCHStmtReader::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
   VisitExpr(E);
   E->setTypeBeginLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
@@ -1180,6 +1198,15 @@
   E->setNamingClass(cast_or_null<CXXRecordDecl>(Reader.GetDecl(Record[Idx++])));
 }
 
+void PCHStmtReader::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
+  VisitExpr(E);
+  E->UTT = (UnaryTypeTrait)Record[Idx++];
+  SourceRange Range = Reader.ReadSourceRange(Record, Idx);
+  E->Loc = Range.getBegin();
+  E->RParen = Range.getEnd();
+  E->QueriedType = Reader.GetType(Record[Idx++]);
+}
+
 Stmt *PCHReader::ReadStmt() {
   switch (ReadingKind) {
   case Read_Decl:
@@ -1566,8 +1593,11 @@
       break;
         
     case pch::EXPR_CXX_CONSTRUCT:
-      S = new (Context) CXXConstructExpr(Empty, *Context,
-                                      Record[PCHStmtReader::NumExprFields]);
+      S = new (Context) CXXConstructExpr(Empty);
+      break;
+      
+    case pch::EXPR_CXX_TEMPORARY_OBJECT:
+      S = new (Context) CXXTemporaryObjectExpr(Empty);
       break;
 
     case pch::EXPR_CXX_STATIC_CAST:
@@ -1621,6 +1651,9 @@
     case pch::EXPR_CXX_BIND_TEMPORARY:
       S = new (Context) CXXBindTemporaryExpr(Empty);
       break;
+    case pch::EXPR_CXX_BIND_REFERENCE:
+      S = new (Context) CXXBindReferenceExpr(Empty);
+      break;
 
     case pch::EXPR_CXX_SCALAR_VALUE_INIT:
       S = new (Context) CXXScalarValueInitExpr(Empty);
@@ -1663,8 +1696,12 @@
       S = UnresolvedLookupExpr::CreateEmpty(*Context,
                       /*NumTemplateArgs=*/Record[PCHStmtReader::NumExprFields]);
       break;
+      
+    case pch::EXPR_CXX_UNARY_TYPE_TRAIT:
+      S = new (Context) UnaryTypeTraitExpr(Empty);
+      break;
     }
-
+    
     // We hit a STMT_STOP, so we're done with this expression.
     if (Finished)
       break;

Modified: cfe/trunk/lib/Frontend/PCHWriterStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriterStmt.cpp?rev=108042&r1=108041&r2=108042&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriterStmt.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriterStmt.cpp Sat Jul 10 06:46:15 2010
@@ -118,6 +118,7 @@
     void VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E);
     void VisitCXXMemberCallExpr(CXXMemberCallExpr *E);
     void VisitCXXConstructExpr(CXXConstructExpr *E);
+    void VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E);
     void VisitCXXNamedCastExpr(CXXNamedCastExpr *E);
     void VisitCXXStaticCastExpr(CXXStaticCastExpr *E);
     void VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E);
@@ -131,6 +132,7 @@
     void VisitCXXThrowExpr(CXXThrowExpr *E);
     void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E);
     void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E);
+    void VisitCXXBindReferenceExpr(CXXBindReferenceExpr *E);
 
     void VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E);
     void VisitCXXNewExpr(CXXNewExpr *E);
@@ -145,6 +147,8 @@
     void VisitOverloadExpr(OverloadExpr *E);
     void VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E);
     void VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E);
+
+    void VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *E);
   };
 }
 
@@ -949,6 +953,13 @@
   Code = pch::EXPR_CXX_CONSTRUCT;
 }
 
+void PCHStmtWriter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
+  VisitCXXConstructExpr(E);
+  Writer.AddSourceLocation(E->getTypeBeginLoc(), Record);
+  Writer.AddSourceLocation(E->getRParenLoc(), Record);
+  Code = pch::EXPR_CXX_TEMPORARY_OBJECT;
+}
+
 void PCHStmtWriter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
   VisitExplicitCastExpr(E);
   Writer.AddSourceLocation(E->getOperatorLoc(), Record);
@@ -1041,6 +1052,14 @@
   Code = pch::EXPR_CXX_BIND_TEMPORARY;
 }
 
+void PCHStmtWriter::VisitCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
+  VisitExpr(E);
+  Writer.AddStmt(E->getSubExpr());
+  Record.push_back(E->extendsLifetime());
+  Record.push_back(E->requiresTemporaryCopy());
+  Code = pch::EXPR_CXX_BIND_REFERENCE;
+}
+
 void PCHStmtWriter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
   VisitExpr(E);
   Writer.AddSourceLocation(E->getTypeBeginLoc(), Record);
@@ -1226,6 +1245,14 @@
   Code = pch::EXPR_CXX_UNRESOLVED_LOOKUP;
 }
 
+void PCHStmtWriter::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
+  VisitExpr(E);
+  Record.push_back(E->getTrait());
+  Writer.AddSourceRange(E->getSourceRange(), Record);
+  Writer.AddTypeRef(E->getQueriedType(), Record);
+  Code = pch::EXPR_CXX_UNARY_TYPE_TRAIT;
+}
+
 //===----------------------------------------------------------------------===//
 // PCHWriter Implementation
 //===----------------------------------------------------------------------===//





More information about the cfe-commits mailing list