Browse Source

Augment the interface of ExternalASTSource::FindExternalLexicalDecls()
to allow clients to specify that they've already (correctly) loaded
declarations, and that no further action is needed.

Also, make sure that we clear the "has external lexical declarations"
bit before calling FindExternalLexicalDecls(), to avoid infinite
recursion.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135306 91177308-0d34-0410-b5e6-96231b3b80d8

Douglas Gregor 14 years ago
parent
commit
ba6ffaf21e

+ 19 - 5
include/clang/AST/ExternalASTSource.h

@@ -32,6 +32,20 @@ class Selector;
 class Stmt;
 class Stmt;
 class TagDecl;
 class TagDecl;
 
 
+/// \brief Enumeration describing the result of loading information from
+/// an external source.
+enum ExternalLoadResult {
+  /// \brief Loading the external information has succeeded.
+  ELR_Success,
+  
+  /// \brief Loading the external information has failed.
+  ELR_Failure,
+  
+  /// \brief The external information has already been loaded, and therefore
+  /// no additional processing is required.
+  ELR_AlreadyLoaded
+};
+  
 /// \brief Abstract interface for external sources of AST nodes.
 /// \brief Abstract interface for external sources of AST nodes.
 ///
 ///
 /// External AST sources provide AST nodes constructed from some
 /// External AST sources provide AST nodes constructed from some
@@ -132,10 +146,10 @@ public:
   /// declaration kind is one we are looking for. If NULL, all declarations
   /// declaration kind is one we are looking for. If NULL, all declarations
   /// are returned.
   /// are returned.
   ///
   ///
-  /// \return true if an error occurred
+  /// \return an indication of whether the load succeeded or failed.
   ///
   ///
   /// The default implementation of this method is a no-op.
   /// The default implementation of this method is a no-op.
-  virtual bool FindExternalLexicalDecls(const DeclContext *DC,
+  virtual ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC,
                                         bool (*isKindWeWant)(Decl::Kind),
                                         bool (*isKindWeWant)(Decl::Kind),
                                         llvm::SmallVectorImpl<Decl*> &Result);
                                         llvm::SmallVectorImpl<Decl*> &Result);
 
 
@@ -143,14 +157,14 @@ public:
   /// DeclContext.
   /// DeclContext.
   ///
   ///
   /// \return true if an error occurred
   /// \return true if an error occurred
-  bool FindExternalLexicalDecls(const DeclContext *DC,
+  ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC,
                                 llvm::SmallVectorImpl<Decl*> &Result) {
                                 llvm::SmallVectorImpl<Decl*> &Result) {
     return FindExternalLexicalDecls(DC, 0, Result);
     return FindExternalLexicalDecls(DC, 0, Result);
   }
   }
 
 
   template <typename DeclTy>
   template <typename DeclTy>
-  bool FindExternalLexicalDeclsBy(const DeclContext *DC,
-                                llvm::SmallVectorImpl<Decl*> &Result) {
+  ExternalLoadResult FindExternalLexicalDeclsBy(const DeclContext *DC,
+                                  llvm::SmallVectorImpl<Decl*> &Result) {
     return FindExternalLexicalDecls(DC, DeclTy::classofKind, Result);
     return FindExternalLexicalDecls(DC, DeclTy::classofKind, Result);
   }
   }
 
 

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

@@ -1070,7 +1070,7 @@ public:
   ///
   ///
   /// \returns true if there was an error while reading the
   /// \returns true if there was an error while reading the
   /// declarations for this declaration context.
   /// declarations for this declaration context.
-  virtual bool FindExternalLexicalDecls(const DeclContext *DC,
+  virtual ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC,
                                         bool (*isKindWeWant)(Decl::Kind),
                                         bool (*isKindWeWant)(Decl::Kind),
                                         llvm::SmallVectorImpl<Decl*> &Decls);
                                         llvm::SmallVectorImpl<Decl*> &Decls);
 
 

+ 1 - 1
include/clang/Serialization/ChainedIncludesSource.h

@@ -47,7 +47,7 @@ protected:
   virtual DeclContextLookupResult
   virtual DeclContextLookupResult
   FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name);
   FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name);
   virtual void MaterializeVisibleDecls(const DeclContext *DC);
   virtual void MaterializeVisibleDecls(const DeclContext *DC);
-  virtual bool FindExternalLexicalDecls(const DeclContext *DC,
+  virtual ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC,
                                         bool (*isKindWeWant)(Decl::Kind),
                                         bool (*isKindWeWant)(Decl::Kind),
                                         llvm::SmallVectorImpl<Decl*> &Result);
                                         llvm::SmallVectorImpl<Decl*> &Result);
   virtual void CompleteType(TagDecl *Tag);
   virtual void CompleteType(TagDecl *Tag);

+ 8 - 3
lib/AST/Decl.cpp

@@ -2361,8 +2361,15 @@ void RecordDecl::LoadFieldsFromExternalStorage() const {
   ExternalASTSource::Deserializing TheFields(Source);
   ExternalASTSource::Deserializing TheFields(Source);
 
 
   llvm::SmallVector<Decl*, 64> Decls;
   llvm::SmallVector<Decl*, 64> Decls;
-  if (Source->FindExternalLexicalDeclsBy<FieldDecl>(this, Decls))
+  LoadedFieldsFromExternalStorage = true;  
+  switch (Source->FindExternalLexicalDeclsBy<FieldDecl>(this, Decls)) {
+  case ELR_Success:
+    break;
+    
+  case ELR_AlreadyLoaded:
+  case ELR_Failure:
     return;
     return;
+  }
 
 
 #ifndef NDEBUG
 #ifndef NDEBUG
   // Check that all decls we got were FieldDecls.
   // Check that all decls we got were FieldDecls.
@@ -2370,8 +2377,6 @@ void RecordDecl::LoadFieldsFromExternalStorage() const {
     assert(isa<FieldDecl>(Decls[i]));
     assert(isa<FieldDecl>(Decls[i]));
 #endif
 #endif
 
 
-  LoadedFieldsFromExternalStorage = true;
-
   if (Decls.empty())
   if (Decls.empty())
     return;
     return;
 
 

+ 9 - 4
lib/AST/DeclBase.cpp

@@ -839,12 +839,17 @@ DeclContext::LoadLexicalDeclsFromExternalStorage() const {
   // Notify that we have a DeclContext that is initializing.
   // Notify that we have a DeclContext that is initializing.
   ExternalASTSource::Deserializing ADeclContext(Source);
   ExternalASTSource::Deserializing ADeclContext(Source);
 
 
+  // Load the external declarations, if any.
   llvm::SmallVector<Decl*, 64> Decls;
   llvm::SmallVector<Decl*, 64> Decls;
-  if (Source->FindExternalLexicalDecls(this, Decls))
-    return;
-
-  // There is no longer any lexical storage in this context
   ExternalLexicalStorage = false;
   ExternalLexicalStorage = false;
+  switch (Source->FindExternalLexicalDecls(this, Decls)) {
+  case ELR_Success:
+    break;
+    
+  case ELR_Failure:
+  case ELR_AlreadyLoaded:
+    return;
+  }
 
 
   if (Decls.empty())
   if (Decls.empty())
     return;
     return;

+ 2 - 2
lib/AST/ExternalASTSource.cpp

@@ -51,11 +51,11 @@ ExternalASTSource::FindExternalVisibleDeclsByName(const DeclContext *DC,
 
 
 void ExternalASTSource::MaterializeVisibleDecls(const DeclContext *DC) { }
 void ExternalASTSource::MaterializeVisibleDecls(const DeclContext *DC) { }
 
 
-bool 
+ExternalLoadResult 
 ExternalASTSource::FindExternalLexicalDecls(const DeclContext *DC,
 ExternalASTSource::FindExternalLexicalDecls(const DeclContext *DC,
                                             bool (*isKindWeWant)(Decl::Kind),
                                             bool (*isKindWeWant)(Decl::Kind),
                                          llvm::SmallVectorImpl<Decl*> &Result) {
                                          llvm::SmallVectorImpl<Decl*> &Result) {
-  return true;
+  return ELR_AlreadyLoaded;
 }
 }
 
 
 void ExternalASTSource::getMemoryBufferSizes(MemoryBufferSizes &sizes) const { }
 void ExternalASTSource::getMemoryBufferSizes(MemoryBufferSizes &sizes) const { }

+ 2 - 5
lib/Serialization/ASTReader.cpp

@@ -4008,12 +4008,9 @@ Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) {
   llvm_unreachable("Broken chain");
   llvm_unreachable("Broken chain");
 }
 }
 
 
-bool ASTReader::FindExternalLexicalDecls(const DeclContext *DC,
+ExternalLoadResult ASTReader::FindExternalLexicalDecls(const DeclContext *DC,
                                          bool (*isKindWeWant)(Decl::Kind),
                                          bool (*isKindWeWant)(Decl::Kind),
                                          llvm::SmallVectorImpl<Decl*> &Decls) {
                                          llvm::SmallVectorImpl<Decl*> &Decls) {
-  assert(DC->hasExternalLexicalStorage() &&
-         "DeclContext has no lexical decls in storage");
-
   // There might be lexical decls in multiple parts of the chain, for the TU
   // There might be lexical decls in multiple parts of the chain, for the TU
   // at least.
   // at least.
   // DeclContextOffsets might reallocate as we load additional decls below,
   // DeclContextOffsets might reallocate as we load additional decls below,
@@ -4038,7 +4035,7 @@ bool ASTReader::FindExternalLexicalDecls(const DeclContext *DC,
   }
   }
 
 
   ++NumLexicalDeclContextsRead;
   ++NumLexicalDeclContextsRead;
-  return false;
+  return ELR_Success;
 }
 }
 
 
 DeclContext::lookup_result
 DeclContext::lookup_result

+ 2 - 1
lib/Serialization/ChainedIncludesSource.cpp

@@ -185,7 +185,8 @@ ChainedIncludesSource::FindExternalVisibleDeclsByName(const DeclContext *DC,
 void ChainedIncludesSource::MaterializeVisibleDecls(const DeclContext *DC) {
 void ChainedIncludesSource::MaterializeVisibleDecls(const DeclContext *DC) {
   return getFinalReader().MaterializeVisibleDecls(DC);
   return getFinalReader().MaterializeVisibleDecls(DC);
 }
 }
-bool ChainedIncludesSource::FindExternalLexicalDecls(const DeclContext *DC,
+ExternalLoadResult 
+ChainedIncludesSource::FindExternalLexicalDecls(const DeclContext *DC,
                                       bool (*isKindWeWant)(Decl::Kind),
                                       bool (*isKindWeWant)(Decl::Kind),
                                       llvm::SmallVectorImpl<Decl*> &Result) {
                                       llvm::SmallVectorImpl<Decl*> &Result) {
   return getFinalReader().FindExternalLexicalDecls(DC, isKindWeWant, Result);
   return getFinalReader().FindExternalLexicalDecls(DC, isKindWeWant, Result);