]> granicus.if.org Git - clang/commitdiff
Collect namespaces that need updating in a PCH chain. WIP
authorSebastian Redl <sebastian.redl@getdesigned.at>
Thu, 5 Aug 2010 21:22:19 +0000 (21:22 +0000)
committerSebastian Redl <sebastian.redl@getdesigned.at>
Thu, 5 Aug 2010 21:22:19 +0000 (21:22 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@110378 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Decl.h
include/clang/Frontend/PCHWriter.h
lib/Frontend/PCHWriterDecl.cpp

index 169b74e01b4556c495723ccdcc42c890caec41db..1a6c5833fff997d40b1397bf17963ea55e1477af 100644 (file)
@@ -239,7 +239,7 @@ class NamespaceDecl : public NamedDecl, public DeclContext {
   // there will be one NamespaceDecl for each declaration.
   // NextNamespace points to the next extended declaration.
   // OrigNamespace points to the original namespace declaration.
-  // OrigNamespace of the first namespace decl points to itself.
+  // OrigNamespace of the first namespace decl points to its anonymous namespace
   NamespaceDecl *NextNamespace;
 
   /// \brief A pointer to either the original namespace definition for
@@ -277,7 +277,7 @@ public:
     return !getIdentifier();
   }
 
-  /// \brief Return the next extended namespace declaration or null if this
+  /// \brief Return the next extended namespace declaration or null if there
   /// is none.
   NamespaceDecl *getNextNamespace() { return NextNamespace; }
   const NamespaceDecl *getNextNamespace() const { return NextNamespace; }
index 811a5062167e8a3c29c9478d4f982330ee65902c..9f8b54c2fd5b749818a89c4b5d7bd7770d2bbd18 100644 (file)
@@ -22,6 +22,7 @@
 #include "clang/Frontend/PCHDeserializationListener.h"
 #include "clang/Sema/SemaConsumer.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Bitcode/BitstreamWriter.h"
 #include <map>
@@ -219,6 +220,13 @@ private:
   /// record.
   llvm::SmallVector<uint64_t, 16> ExternalDefinitions;
 
+  /// \brief Namespaces that have received extensions since their PCH form.
+  ///
+  /// Basically, when we're chaining and encountering a namespace, we check if
+  /// its primary namespace comes from the chain. If it does, we add the primary
+  /// to this set, so that we can write out lexical content updates for it.
+  llvm::SmallPtrSet<const NamespaceDecl *, 16> UpdatedNamespaces;
+
   /// \brief Statements that we've encountered while serializing a
   /// declaration or type.
   llvm::SmallVector<Stmt *, 16> StmtsToEmit;
@@ -390,12 +398,17 @@ public:
   /// \brief Emit a UnresolvedSet structure.
   void AddUnresolvedSet(const UnresolvedSetImpl &Set, RecordData &Record);
 
-  /// brief Emit a C++ base specifier.
+  /// \brief Emit a C++ base specifier.
   void AddCXXBaseSpecifier(const CXXBaseSpecifier &Base, RecordData &Record);
 
   /// \brief Add a string to the given record.
   void AddString(const std::string &Str, RecordData &Record);
 
+  /// \brief Mark a namespace as needing an update.
+  void AddUpdatedNamespace(const NamespaceDecl *NS) {
+    UpdatedNamespaces.insert(NS);
+  }
+
   /// \brief Note that the identifier II occurs at the given offset
   /// within the identifier table.
   void SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset);
index 9e9835adb424551813b42edcd5d22985a98ceee4..a3d47bba585b7e8b0ef22e94f65e243714c32cfe 100644 (file)
@@ -600,6 +600,11 @@ void PCHDeclWriter::VisitNamespaceDecl(NamespaceDecl *D) {
   else
     Writer.AddDeclRef(D->getOriginalNamespace(), Record);
   Code = pch::DECL_NAMESPACE;
+
+  if (Writer.hasChain() && !D->isOriginalNamespace() &&
+      D->getOriginalNamespace()->getPCHLevel() > 0) {
+    Writer.AddUpdatedNamespace(D->getOriginalNamespace());
+  }
 }
 
 void PCHDeclWriter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {