class Stmt;
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.
///
/// External AST sources provide AST nodes constructed from some
/// declaration kind is one we are looking for. If NULL, all declarations
/// 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.
- virtual bool FindExternalLexicalDecls(const DeclContext *DC,
+ virtual ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC,
bool (*isKindWeWant)(Decl::Kind),
llvm::SmallVectorImpl<Decl*> &Result);
/// DeclContext.
///
/// \return true if an error occurred
- bool FindExternalLexicalDecls(const DeclContext *DC,
+ ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC,
llvm::SmallVectorImpl<Decl*> &Result) {
return FindExternalLexicalDecls(DC, 0, Result);
}
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);
}
///
/// \returns true if there was an error while reading the
/// declarations for this declaration context.
- virtual bool FindExternalLexicalDecls(const DeclContext *DC,
+ virtual ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC,
bool (*isKindWeWant)(Decl::Kind),
llvm::SmallVectorImpl<Decl*> &Decls);
virtual DeclContextLookupResult
FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name);
virtual void MaterializeVisibleDecls(const DeclContext *DC);
- virtual bool FindExternalLexicalDecls(const DeclContext *DC,
+ virtual ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC,
bool (*isKindWeWant)(Decl::Kind),
llvm::SmallVectorImpl<Decl*> &Result);
virtual void CompleteType(TagDecl *Tag);
ExternalASTSource::Deserializing TheFields(Source);
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;
+ }
#ifndef NDEBUG
// Check that all decls we got were FieldDecls.
assert(isa<FieldDecl>(Decls[i]));
#endif
- LoadedFieldsFromExternalStorage = true;
-
if (Decls.empty())
return;
// Notify that we have a DeclContext that is initializing.
ExternalASTSource::Deserializing ADeclContext(Source);
+ // Load the external declarations, if any.
llvm::SmallVector<Decl*, 64> Decls;
- if (Source->FindExternalLexicalDecls(this, Decls))
- return;
-
- // There is no longer any lexical storage in this context
ExternalLexicalStorage = false;
+ switch (Source->FindExternalLexicalDecls(this, Decls)) {
+ case ELR_Success:
+ break;
+
+ case ELR_Failure:
+ case ELR_AlreadyLoaded:
+ return;
+ }
if (Decls.empty())
return;
void ExternalASTSource::MaterializeVisibleDecls(const DeclContext *DC) { }
-bool
+ExternalLoadResult
ExternalASTSource::FindExternalLexicalDecls(const DeclContext *DC,
bool (*isKindWeWant)(Decl::Kind),
llvm::SmallVectorImpl<Decl*> &Result) {
- return true;
+ return ELR_AlreadyLoaded;
}
void ExternalASTSource::getMemoryBufferSizes(MemoryBufferSizes &sizes) const { }
llvm_unreachable("Broken chain");
}
-bool ASTReader::FindExternalLexicalDecls(const DeclContext *DC,
+ExternalLoadResult ASTReader::FindExternalLexicalDecls(const DeclContext *DC,
bool (*isKindWeWant)(Decl::Kind),
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
// at least.
// DeclContextOffsets might reallocate as we load additional decls below,
}
++NumLexicalDeclContextsRead;
- return false;
+ return ELR_Success;
}
DeclContext::lookup_result
void ChainedIncludesSource::MaterializeVisibleDecls(const DeclContext *DC) {
return getFinalReader().MaterializeVisibleDecls(DC);
}
-bool ChainedIncludesSource::FindExternalLexicalDecls(const DeclContext *DC,
+ExternalLoadResult
+ChainedIncludesSource::FindExternalLexicalDecls(const DeclContext *DC,
bool (*isKindWeWant)(Decl::Kind),
llvm::SmallVectorImpl<Decl*> &Result) {
return getFinalReader().FindExternalLexicalDecls(DC, isKindWeWant, Result);