Kaynağa Gözat

Use forward declarations for ASTDeclContextNameLookupTable and add a missing delete.

It would be nice to use OwningPtr here, but DeclContextInfo is stored in a DenseMap.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154763 91177308-0d34-0410-b5e6-96231b3b80d8
Benjamin Kramer 13 yıl önce
ebeveyn
işleme
b1758c6625

+ 6 - 1
include/clang/Serialization/ASTReader.h

@@ -170,6 +170,9 @@ class ReadMethodPoolVisitor;
 
 
 namespace reader {
 namespace reader {
   class ASTIdentifierLookupTrait;
   class ASTIdentifierLookupTrait;
+  /// \brief The on-disk hash table used for the DeclContext's Name lookup table.
+  typedef OnDiskChainedHashTable<ASTDeclContextNameLookupTrait>
+    ASTDeclContextNameLookupTable;
 }
 }
 
 
 } // end namespace serialization
 } // end namespace serialization
@@ -323,7 +326,9 @@ private:
   // TU, and when we read those update records, the actual context will not
   // TU, and when we read those update records, the actual context will not
   // be available yet (unless it's the TU), so have this pending map using the
   // be available yet (unless it's the TU), so have this pending map using the
   // ID as a key. It will be realized when the context is actually loaded.
   // ID as a key. It will be realized when the context is actually loaded.
-  typedef SmallVector<std::pair<void *, ModuleFile*>, 1> DeclContextVisibleUpdates;
+  typedef
+    SmallVector<std::pair<serialization::reader::ASTDeclContextNameLookupTable *,
+                          ModuleFile*>, 1> DeclContextVisibleUpdates;
   typedef llvm::DenseMap<serialization::DeclID, DeclContextVisibleUpdates>
   typedef llvm::DenseMap<serialization::DeclID, DeclContextVisibleUpdates>
       DeclContextVisibleUpdatesPending;
       DeclContextVisibleUpdatesPending;
 
 

+ 8 - 2
include/clang/Serialization/Module.h

@@ -27,9 +27,14 @@ namespace clang {
 
 
 class DeclContext;
 class DeclContext;
 class Module;
 class Module;
-  
+template<typename Info> class OnDiskChainedHashTable;
+
 namespace serialization {
 namespace serialization {
 
 
+namespace reader {
+  class ASTDeclContextNameLookupTrait;
+}
+
 /// \brief Specifies the kind of module that has been loaded.
 /// \brief Specifies the kind of module that has been loaded.
 enum ModuleKind {
 enum ModuleKind {
   MK_Module,   ///< File is a module proper.
   MK_Module,   ///< File is a module proper.
@@ -43,7 +48,8 @@ struct DeclContextInfo {
   DeclContextInfo()
   DeclContextInfo()
     : NameLookupTableData(), LexicalDecls(), NumLexicalDecls() {}
     : NameLookupTableData(), LexicalDecls(), NumLexicalDecls() {}
 
 
-  void *NameLookupTableData; // an ASTDeclContextNameLookupTable.
+  OnDiskChainedHashTable<reader::ASTDeclContextNameLookupTrait>
+    *NameLookupTableData; // an ASTDeclContextNameLookupTable.
   const KindDeclIDPair *LexicalDecls;
   const KindDeclIDPair *LexicalDecls;
   unsigned NumLexicalDecls;
   unsigned NumLexicalDecls;
 };
 };

+ 5 - 4
lib/Serialization/ASTReader.cpp

@@ -1911,7 +1911,8 @@ ASTReader::ReadASTBlock(ModuleFile &F) {
     case UPDATE_VISIBLE: {
     case UPDATE_VISIBLE: {
       unsigned Idx = 0;
       unsigned Idx = 0;
       serialization::DeclID ID = ReadDeclID(F, Record, Idx);
       serialization::DeclID ID = ReadDeclID(F, Record, Idx);
-      void *Table = ASTDeclContextNameLookupTable::Create(
+      ASTDeclContextNameLookupTable *Table =
+        ASTDeclContextNameLookupTable::Create(
                         (const unsigned char *)BlobStart + Record[Idx++],
                         (const unsigned char *)BlobStart + Record[Idx++],
                         (const unsigned char *)BlobStart,
                         (const unsigned char *)BlobStart,
                         ASTDeclContextNameLookupTrait(*this, F));
                         ASTDeclContextNameLookupTrait(*this, F));
@@ -4908,7 +4909,7 @@ namespace {
       
       
       // Look for this name within this module.
       // Look for this name within this module.
       ASTDeclContextNameLookupTable *LookupTable =
       ASTDeclContextNameLookupTable *LookupTable =
-        (ASTDeclContextNameLookupTable*)Info->second.NameLookupTableData;
+        Info->second.NameLookupTableData;
       ASTDeclContextNameLookupTable::iterator Pos
       ASTDeclContextNameLookupTable::iterator Pos
         = LookupTable->find(This->Name);
         = LookupTable->find(This->Name);
       if (Pos == LookupTable->end())
       if (Pos == LookupTable->end())
@@ -4997,7 +4998,7 @@ namespace {
       
       
       // Look for this name within this module.
       // Look for this name within this module.
       ASTDeclContextNameLookupTable *LookupTable =
       ASTDeclContextNameLookupTable *LookupTable =
-        (ASTDeclContextNameLookupTable*)Info->second.NameLookupTableData;
+        Info->second.NameLookupTableData;
       for (ASTDeclContextNameLookupTable::key_iterator
       for (ASTDeclContextNameLookupTable::key_iterator
              I = LookupTable->key_begin(),
              I = LookupTable->key_begin(),
              E = LookupTable->key_end(); I != E; ++I) {
              E = LookupTable->key_end(); I != E; ++I) {
@@ -6364,6 +6365,6 @@ ASTReader::~ASTReader() {
     for (DeclContextVisibleUpdates::iterator J = I->second.begin(),
     for (DeclContextVisibleUpdates::iterator J = I->second.begin(),
                                              F = I->second.end();
                                              F = I->second.end();
          J != F; ++J)
          J != F; ++J)
-      delete static_cast<ASTDeclContextNameLookupTable*>(J->first);
+      delete J->first;
   }
   }
 }
 }

+ 4 - 1
lib/Serialization/ASTReaderDecl.cpp

@@ -13,6 +13,7 @@
 //===----------------------------------------------------------------------===//
 //===----------------------------------------------------------------------===//
 
 
 #include "ASTCommon.h"
 #include "ASTCommon.h"
+#include "ASTReaderInternals.h"
 #include "clang/Serialization/ASTReader.h"
 #include "clang/Serialization/ASTReader.h"
 #include "clang/Sema/IdentifierResolver.h"
 #include "clang/Sema/IdentifierResolver.h"
 #include "clang/Sema/Sema.h"
 #include "clang/Sema/Sema.h"
@@ -2104,7 +2105,9 @@ Decl *ASTReader::ReadDeclRecord(DeclID ID) {
       DeclContextVisibleUpdates &U = I->second;
       DeclContextVisibleUpdates &U = I->second;
       for (DeclContextVisibleUpdates::iterator UI = U.begin(), UE = U.end();
       for (DeclContextVisibleUpdates::iterator UI = U.begin(), UE = U.end();
            UI != UE; ++UI) {
            UI != UE; ++UI) {
-        UI->second->DeclContextInfos[DC].NameLookupTableData = UI->first;
+        DeclContextInfo &Info = UI->second->DeclContextInfos[DC];
+        delete Info.NameLookupTableData;
+        Info.NameLookupTableData = UI->first;
       }
       }
       PendingVisibleUpdates.erase(I);
       PendingVisibleUpdates.erase(I);
     }
     }

+ 0 - 4
lib/Serialization/ASTReaderInternals.h

@@ -79,10 +79,6 @@ public:
                      unsigned DataLen);
                      unsigned DataLen);
 };
 };
 
 
-/// \brief The on-disk hash table used for the DeclContext's Name lookup table.
-typedef OnDiskChainedHashTable<ASTDeclContextNameLookupTrait>
-  ASTDeclContextNameLookupTable;
-
 /// \brief Class that performs lookup for an identifier stored in an AST file.
 /// \brief Class that performs lookup for an identifier stored in an AST file.
 class ASTIdentifierLookupTrait {
 class ASTIdentifierLookupTrait {
   ASTReader &Reader;
   ASTReader &Reader;

+ 1 - 2
lib/Serialization/Module.cpp

@@ -45,8 +45,7 @@ ModuleFile::~ModuleFile() {
        E = DeclContextInfos.end();
        E = DeclContextInfos.end();
        I != E; ++I) {
        I != E; ++I) {
     if (I->second.NameLookupTableData)
     if (I->second.NameLookupTableData)
-      delete static_cast<ASTDeclContextNameLookupTable*>(
-                                                 I->second.NameLookupTableData);
+      delete I->second.NameLookupTableData;
   }
   }
   
   
   delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable);
   delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable);