[cfe-commits] r107617 - in /cfe/trunk: include/clang/AST/Decl.h include/clang/AST/DeclTemplate.h lib/Frontend/PCHReaderDecl.cpp lib/Frontend/PCHWriterDecl.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Mon Jul 5 03:38:01 PDT 2010


Author: akirtzidis
Date: Mon Jul  5 05:38:01 2010
New Revision: 107617

URL: http://llvm.org/viewvc/llvm-project?rev=107617&view=rev
Log:
Read/write the identifier namespace in PCH for decls that may modify it.

We can now use a PCH'ed <map>.

Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/include/clang/AST/DeclTemplate.h
    cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
    cfe/trunk/lib/Frontend/PCHWriterDecl.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=107617&r1=107616&r2=107617&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Mon Jul  5 05:38:01 2010
@@ -1599,6 +1599,9 @@
   static FunctionDecl *castFromDeclContext(const DeclContext *DC) {
     return static_cast<FunctionDecl *>(const_cast<DeclContext*>(DC));
   }
+
+  friend class PCHDeclReader;
+  friend class PCHDeclWriter;
 };
 
 
@@ -1960,6 +1963,9 @@
   static TagDecl *castFromDeclContext(const DeclContext *DC) {
     return static_cast<TagDecl *>(const_cast<DeclContext*>(DC));
   }
+
+  friend class PCHDeclReader;
+  friend class PCHDeclWriter;
 };
 
 /// EnumDecl - Represents an enum.  As an extension, we allow forward-declared

Modified: cfe/trunk/include/clang/AST/DeclTemplate.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclTemplate.h?rev=107617&r1=107616&r2=107617&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclTemplate.h (original)
+++ cfe/trunk/include/clang/AST/DeclTemplate.h Mon Jul  5 05:38:01 2010
@@ -629,6 +629,9 @@
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const FunctionTemplateDecl *D) { return true; }
   static bool classofKind(Kind K) { return K == FunctionTemplate; }
+
+  friend class PCHDeclReader;
+  friend class PCHDeclWriter;
 };
 
 //===----------------------------------------------------------------------===//
@@ -1527,6 +1530,9 @@
   static bool classofKind(Kind K) { return K == ClassTemplate; }
 
   virtual void Destroy(ASTContext& C);
+
+  friend class PCHDeclReader;
+  friend class PCHDeclWriter;
 };
 
 /// Declaration of a friend template.  For example:

Modified: cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderDecl.cpp?rev=107617&r1=107616&r2=107617&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderDecl.cpp Mon Jul  5 05:38:01 2010
@@ -159,6 +159,7 @@
 
 void PCHDeclReader::VisitTagDecl(TagDecl *TD) {
   VisitTypeDecl(TD);
+  TD->IdentifierNamespace = Record[Idx++];
   TD->setPreviousDeclaration(
                         cast_or_null<TagDecl>(Reader.GetDecl(Record[Idx++])));
   TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
@@ -210,6 +211,7 @@
 void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
   VisitDeclaratorDecl(FD);
 
+  FD->IdentifierNamespace = Record[Idx++];
   switch ((FunctionDecl::TemplatedKind)Record[Idx++]) {
   default: assert(false && "Unhandled TemplatedKind!");
     break;
@@ -282,7 +284,9 @@
   // FunctionDecl's body is handled last at PCHReaderDecl::Visit,
   // after everything else is read.
 
-  FD->setPreviousDeclaration(
+  // Avoid side effects and invariant checking of FunctionDecl's
+  // setPreviousDeclaration.
+  FD->redeclarable_base::setPreviousDeclaration(
                    cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
   FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]);
   FD->setStorageClassAsWritten((FunctionDecl::StorageClass)Record[Idx++]);
@@ -304,11 +308,6 @@
   for (unsigned I = 0; I != NumParams; ++I)
     Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
   FD->setParams(Params.data(), NumParams);
-
-  // FIXME: order this properly w.r.t. friendness
-  // FIXME: this same thing needs to happen for function templates
-  if (FD->isOverloadedOperator() && !FD->getDeclContext()->isRecord())
-    FD->setNonMemberOperator();
 }
 
 void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
@@ -822,6 +821,7 @@
 }
 
 void PCHDeclReader::VisitFriendDecl(FriendDecl *D) {
+  VisitDecl(D);
   if (Record[Idx++])
     D->Friend = Reader.GetTypeSourceInfo(Record, Idx);
   else
@@ -846,6 +846,7 @@
 void PCHDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
   VisitTemplateDecl(D);
 
+  D->IdentifierNamespace = Record[Idx++];
   ClassTemplateDecl *PrevDecl =
       cast_or_null<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]));
   D->setPreviousDeclaration(PrevDecl);
@@ -952,6 +953,7 @@
 void PCHDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
   VisitTemplateDecl(D);
 
+  D->IdentifierNamespace = Record[Idx++];
   FunctionTemplateDecl *PrevDecl =
       cast_or_null<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]));
   D->setPreviousDeclaration(PrevDecl);

Modified: cfe/trunk/lib/Frontend/PCHWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriterDecl.cpp?rev=107617&r1=107616&r2=107617&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriterDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriterDecl.cpp Mon Jul  5 05:38:01 2010
@@ -161,6 +161,7 @@
 
 void PCHDeclWriter::VisitTagDecl(TagDecl *D) {
   VisitTypeDecl(D);
+  Record.push_back(D->getIdentifierNamespace());
   Writer.AddDeclRef(D->getPreviousDeclaration(), Record);
   Record.push_back((unsigned)D->getTagKind()); // FIXME: stable encoding
   Record.push_back(D->isDefinition());
@@ -212,6 +213,7 @@
 void PCHDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
   VisitDeclaratorDecl(D);
 
+  Record.push_back(D->getIdentifierNamespace());
   Record.push_back(D->getTemplatedKind());
   switch (D->getTemplatedKind()) {
   default: assert(false && "Unhandled TemplatedKind!");
@@ -787,6 +789,7 @@
 }
 
 void PCHDeclWriter::VisitFriendDecl(FriendDecl *D) {
+  VisitDecl(D);
   Record.push_back(D->Friend.is<TypeSourceInfo*>());
   if (D->Friend.is<TypeSourceInfo*>())
     Writer.AddTypeSourceInfo(D->Friend.get<TypeSourceInfo*>(), Record);
@@ -811,6 +814,7 @@
 void PCHDeclWriter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
   VisitTemplateDecl(D);
 
+  Record.push_back(D->getIdentifierNamespace());
   Writer.AddDeclRef(D->getPreviousDeclaration(), Record);
   if (D->getPreviousDeclaration() == 0) {
     // This ClassTemplateDecl owns the CommonPtr; write it.
@@ -899,6 +903,7 @@
 void PCHDeclWriter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
   VisitTemplateDecl(D);
 
+  Record.push_back(D->getIdentifierNamespace());
   Writer.AddDeclRef(D->getPreviousDeclaration(), Record);
   if (D->getPreviousDeclaration() == 0) {
     // This FunctionTemplateDecl owns the CommonPtr; write it.





More information about the cfe-commits mailing list