From: Douglas Gregor Date: Sun, 21 Feb 2010 18:22:14 +0000 (+0000) Subject: Implement PCH support for C++ namespaces. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0cef483f3b9d6a7f9fdbc5910d0a3ed64130e8e1;p=clang Implement PCH support for C++ namespaces. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96738 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 712e8b0b99..91aeff3439 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -267,8 +267,8 @@ public: } void setAnonymousNamespace(NamespaceDecl *D) { - assert(D->isAnonymousNamespace()); - assert(D->getParent() == this); + assert(!D || D->isAnonymousNamespace()); + assert(!D || D->getParent() == this); AnonymousNamespace = D; } diff --git a/include/clang/Frontend/PCHBitCodes.h b/include/clang/Frontend/PCHBitCodes.h index e22d37ba34..d4014b3075 100644 --- a/include/clang/Frontend/PCHBitCodes.h +++ b/include/clang/Frontend/PCHBitCodes.h @@ -524,7 +524,9 @@ namespace clang { /// associates a declaration name with one or more declaration /// IDs. This data is used when performing qualified name lookup /// into a DeclContext via DeclContext::lookup. - DECL_CONTEXT_VISIBLE + DECL_CONTEXT_VISIBLE, + /// \brief A NamespaceDecl record. + DECL_NAMESPACE }; /// \brief Record codes for each kind of statement or expression. diff --git a/lib/Frontend/PCHReaderDecl.cpp b/lib/Frontend/PCHReaderDecl.cpp index af69664fe1..27349ecbfe 100644 --- a/lib/Frontend/PCHReaderDecl.cpp +++ b/lib/Frontend/PCHReaderDecl.cpp @@ -39,6 +39,7 @@ namespace { void VisitDecl(Decl *D); void VisitTranslationUnitDecl(TranslationUnitDecl *TU); void VisitNamedDecl(NamedDecl *ND); + void VisitNamespaceDecl(NamespaceDecl *D); void VisitTypeDecl(TypeDecl *TD); void VisitTypedefDecl(TypedefDecl *TD); void VisitTagDecl(TagDecl *TD); @@ -96,6 +97,18 @@ void PCHDeclReader::VisitNamedDecl(NamedDecl *ND) { ND->setDeclName(Reader.ReadDeclarationName(Record, Idx)); } +void PCHDeclReader::VisitNamespaceDecl(NamespaceDecl *D) { + VisitNamedDecl(D); + D->setLBracLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + D->setRBracLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + D->setNextNamespace( + cast_or_null(Reader.GetDecl(Record[Idx++]))); + D->setOriginalNamespace( + cast_or_null(Reader.GetDecl(Record[Idx++]))); + D->setAnonymousNamespace( + cast_or_null(Reader.GetDecl(Record[Idx++]))); +} + void PCHDeclReader::VisitTypeDecl(TypeDecl *TD) { VisitNamedDecl(TD); TD->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr()); @@ -743,6 +756,10 @@ Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) { case pch::DECL_BLOCK: D = BlockDecl::Create(*Context, 0, SourceLocation()); break; + + case pch::DECL_NAMESPACE: + D = NamespaceDecl::Create(*Context, 0, SourceLocation(), 0); + break; } assert(D && "Unknown declaration reading PCH file"); diff --git a/lib/Frontend/PCHWriterDecl.cpp b/lib/Frontend/PCHWriterDecl.cpp index d105382b43..e776d32454 100644 --- a/lib/Frontend/PCHWriterDecl.cpp +++ b/lib/Frontend/PCHWriterDecl.cpp @@ -42,6 +42,7 @@ namespace { void VisitDecl(Decl *D); void VisitTranslationUnitDecl(TranslationUnitDecl *D); void VisitNamedDecl(NamedDecl *D); + void VisitNamespaceDecl(NamespaceDecl *D); void VisitTypeDecl(TypeDecl *D); void VisitTypedefDecl(TypedefDecl *D); void VisitTagDecl(TagDecl *D); @@ -99,6 +100,16 @@ void PCHDeclWriter::VisitNamedDecl(NamedDecl *D) { Writer.AddDeclarationName(D->getDeclName(), Record); } +void PCHDeclWriter::VisitNamespaceDecl(NamespaceDecl *D) { + VisitNamedDecl(D); + Writer.AddSourceLocation(D->getLBracLoc(), Record); + Writer.AddSourceLocation(D->getRBracLoc(), Record); + Writer.AddDeclRef(D->getNextNamespace(), Record); + Writer.AddDeclRef(D->getOriginalNamespace(), Record); + Writer.AddDeclRef(D->getAnonymousNamespace(), Record); + Code = pch::DECL_NAMESPACE; +} + void PCHDeclWriter::VisitTypeDecl(TypeDecl *D) { VisitNamedDecl(D); Writer.AddTypeRef(QualType(D->getTypeForDecl(), 0), Record);