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

Douglas Gregor dgregor at apple.com
Sun Feb 21 10:22:14 PST 2010


Author: dgregor
Date: Sun Feb 21 12:22:14 2010
New Revision: 96738

URL: http://llvm.org/viewvc/llvm-project?rev=96738&view=rev
Log:
Implement PCH support for C++ namespaces.

Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/include/clang/Frontend/PCHBitCodes.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=96738&r1=96737&r2=96738&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Sun Feb 21 12:22:14 2010
@@ -267,8 +267,8 @@
   }
 
   void setAnonymousNamespace(NamespaceDecl *D) {
-    assert(D->isAnonymousNamespace());
-    assert(D->getParent() == this);
+    assert(!D || D->isAnonymousNamespace());
+    assert(!D || D->getParent() == this);
     AnonymousNamespace = D;
   }
 

Modified: cfe/trunk/include/clang/Frontend/PCHBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHBitCodes.h?rev=96738&r1=96737&r2=96738&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHBitCodes.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHBitCodes.h Sun Feb 21 12:22:14 2010
@@ -524,7 +524,9 @@
       /// 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.

Modified: cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderDecl.cpp?rev=96738&r1=96737&r2=96738&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderDecl.cpp Sun Feb 21 12:22:14 2010
@@ -39,6 +39,7 @@
     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 @@
   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<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
+  D->setOriginalNamespace(
+                    cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
+  D->setAnonymousNamespace(
+                    cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
+}
+
 void PCHDeclReader::VisitTypeDecl(TypeDecl *TD) {
   VisitNamedDecl(TD);
   TD->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
@@ -743,6 +756,10 @@
   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");

Modified: cfe/trunk/lib/Frontend/PCHWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriterDecl.cpp?rev=96738&r1=96737&r2=96738&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriterDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriterDecl.cpp Sun Feb 21 12:22:14 2010
@@ -42,6 +42,7 @@
     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 @@
   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);





More information about the cfe-commits mailing list