From: Argyrios Kyrtzidis Date: Mon, 5 Jul 2010 10:38:01 +0000 (+0000) Subject: Read/write the identifier namespace in PCH for decls that may modify it. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c8f9af2943699ff623ca08f2e5ed4d72e0351189;p=clang Read/write the identifier namespace in PCH for decls that may modify it. We can now use a PCH'ed . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107617 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 413044bcac..bdfb49e0d0 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -1599,6 +1599,9 @@ public: static FunctionDecl *castFromDeclContext(const DeclContext *DC) { return static_cast(const_cast(DC)); } + + friend class PCHDeclReader; + friend class PCHDeclWriter; }; @@ -1960,6 +1963,9 @@ public: static TagDecl *castFromDeclContext(const DeclContext *DC) { return static_cast(const_cast(DC)); } + + friend class PCHDeclReader; + friend class PCHDeclWriter; }; /// EnumDecl - Represents an enum. As an extension, we allow forward-declared diff --git a/include/clang/AST/DeclTemplate.h b/include/clang/AST/DeclTemplate.h index 9e6cf0c38f..14ef01dcb8 100644 --- a/include/clang/AST/DeclTemplate.h +++ b/include/clang/AST/DeclTemplate.h @@ -629,6 +629,9 @@ public: 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 @@ public: 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: diff --git a/lib/Frontend/PCHReaderDecl.cpp b/lib/Frontend/PCHReaderDecl.cpp index 1a1f23fc49..595a87b3ad 100644 --- a/lib/Frontend/PCHReaderDecl.cpp +++ b/lib/Frontend/PCHReaderDecl.cpp @@ -159,6 +159,7 @@ void PCHDeclReader::VisitTypedefDecl(TypedefDecl *TD) { void PCHDeclReader::VisitTagDecl(TagDecl *TD) { VisitTypeDecl(TD); + TD->IdentifierNamespace = Record[Idx++]; TD->setPreviousDeclaration( cast_or_null(Reader.GetDecl(Record[Idx++]))); TD->setTagKind((TagDecl::TagKind)Record[Idx++]); @@ -210,6 +211,7 @@ void PCHDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) { 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 @@ void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) { // 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(Reader.GetDecl(Record[Idx++]))); FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]); FD->setStorageClassAsWritten((FunctionDecl::StorageClass)Record[Idx++]); @@ -304,11 +308,6 @@ void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) { for (unsigned I = 0; I != NumParams; ++I) Params.push_back(cast(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::VisitAccessSpecDecl(AccessSpecDecl *D) { } void PCHDeclReader::VisitFriendDecl(FriendDecl *D) { + VisitDecl(D); if (Record[Idx++]) D->Friend = Reader.GetTypeSourceInfo(Record, Idx); else @@ -846,6 +846,7 @@ void PCHDeclReader::VisitTemplateDecl(TemplateDecl *D) { void PCHDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) { VisitTemplateDecl(D); + D->IdentifierNamespace = Record[Idx++]; ClassTemplateDecl *PrevDecl = cast_or_null(Reader.GetDecl(Record[Idx++])); D->setPreviousDeclaration(PrevDecl); @@ -952,6 +953,7 @@ void PCHDeclReader::VisitClassTemplatePartialSpecializationDecl( void PCHDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { VisitTemplateDecl(D); + D->IdentifierNamespace = Record[Idx++]; FunctionTemplateDecl *PrevDecl = cast_or_null(Reader.GetDecl(Record[Idx++])); D->setPreviousDeclaration(PrevDecl); diff --git a/lib/Frontend/PCHWriterDecl.cpp b/lib/Frontend/PCHWriterDecl.cpp index 9f7264ede1..983d6dbd77 100644 --- a/lib/Frontend/PCHWriterDecl.cpp +++ b/lib/Frontend/PCHWriterDecl.cpp @@ -161,6 +161,7 @@ void PCHDeclWriter::VisitTypedefDecl(TypedefDecl *D) { 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::VisitDeclaratorDecl(DeclaratorDecl *D) { 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::VisitAccessSpecDecl(AccessSpecDecl *D) { } void PCHDeclWriter::VisitFriendDecl(FriendDecl *D) { + VisitDecl(D); Record.push_back(D->Friend.is()); if (D->Friend.is()) Writer.AddTypeSourceInfo(D->Friend.get(), Record); @@ -811,6 +814,7 @@ void PCHDeclWriter::VisitTemplateDecl(TemplateDecl *D) { 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::VisitClassTemplatePartialSpecializationDecl( 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.