diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2015-08-05 22:41:45 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2015-08-05 22:41:45 +0000 |
commit | 3cb15729aff241e28c9854bd09609fb74e7bac37 (patch) | |
tree | a51bd54acbb78d140ec33b26f1779ad74c5bdf6e /clang/lib | |
parent | ae0d4365454456203a6f284c5d0e6ed994883c86 (diff) | |
download | llvm-3cb15729aff241e28c9854bd09609fb74e7bac37.zip llvm-3cb15729aff241e28c9854bd09609fb74e7bac37.tar.gz llvm-3cb15729aff241e28c9854bd09609fb74e7bac37.tar.bz2 |
function_ref-ize ExternalASTSource::FindExternalLexicalDecl and remove its
useless return value. Switch to using it directly when completing the
redeclaration chain for an anonymous declaration, and reduce the set of
declarations that we load in the process to just those of the right kind.
llvm-svn: 244161
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/AST/Decl.cpp | 18 | ||||
-rw-r--r-- | clang/lib/AST/DeclBase.cpp | 9 | ||||
-rw-r--r-- | clang/lib/AST/ExternalASTSource.cpp | 14 | ||||
-rw-r--r-- | clang/lib/Frontend/ChainedIncludesSource.cpp | 13 | ||||
-rw-r--r-- | clang/lib/Sema/MultiplexExternalSemaSource.cpp | 12 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTReader.cpp | 54 |
6 files changed, 50 insertions, 70 deletions
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 9d44a69..ab96094 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -3639,10 +3639,6 @@ bool RecordDecl::isMsStruct(const ASTContext &C) const { return hasAttr<MSStructAttr>() || C.getLangOpts().MSBitfields == 1; } -static bool isFieldOrIndirectField(Decl::Kind K) { - return FieldDecl::classofKind(K) || IndirectFieldDecl::classofKind(K); -} - void RecordDecl::LoadFieldsFromExternalStorage() const { ExternalASTSource *Source = getASTContext().getExternalSource(); assert(hasExternalLexicalStorage() && Source && "No external storage?"); @@ -3651,16 +3647,10 @@ void RecordDecl::LoadFieldsFromExternalStorage() const { ExternalASTSource::Deserializing TheFields(Source); SmallVector<Decl*, 64> Decls; - LoadedFieldsFromExternalStorage = true; - switch (Source->FindExternalLexicalDecls(this, isFieldOrIndirectField, - Decls)) { - case ELR_Success: - break; - - case ELR_AlreadyLoaded: - case ELR_Failure: - return; - } + LoadedFieldsFromExternalStorage = true; + Source->FindExternalLexicalDecls(this, [](Decl::Kind K) { + return FieldDecl::classofKind(K) || IndirectFieldDecl::classofKind(K); + }, Decls); #ifndef NDEBUG // Check that all decls we got were FieldDecls. diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp index e772f19..40b135f 100644 --- a/clang/lib/AST/DeclBase.cpp +++ b/clang/lib/AST/DeclBase.cpp @@ -1059,14 +1059,7 @@ DeclContext::LoadLexicalDeclsFromExternalStorage() const { // Load the external declarations, if any. SmallVector<Decl*, 64> Decls; ExternalLexicalStorage = false; - switch (Source->FindExternalLexicalDecls(this, Decls)) { - case ELR_Success: - break; - - case ELR_Failure: - case ELR_AlreadyLoaded: - return false; - } + Source->FindExternalLexicalDecls(this, Decls); if (Decls.empty()) return false; diff --git a/clang/lib/AST/ExternalASTSource.cpp b/clang/lib/AST/ExternalASTSource.cpp index 1c82c35..8a44c05 100644 --- a/clang/lib/AST/ExternalASTSource.cpp +++ b/clang/lib/AST/ExternalASTSource.cpp @@ -92,17 +92,13 @@ ExternalASTSource::FindExternalVisibleDeclsByName(const DeclContext *DC, return false; } -void ExternalASTSource::completeVisibleDeclsMap(const DeclContext *DC) { -} +void ExternalASTSource::completeVisibleDeclsMap(const DeclContext *DC) {} -ExternalLoadResult -ExternalASTSource::FindExternalLexicalDecls(const DeclContext *DC, - bool (*isKindWeWant)(Decl::Kind), - SmallVectorImpl<Decl*> &Result) { - return ELR_AlreadyLoaded; -} +void ExternalASTSource::FindExternalLexicalDecls( + const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant, + SmallVectorImpl<Decl *> &Result) {} -void ExternalASTSource::getMemoryBufferSizes(MemoryBufferSizes &sizes) const { } +void ExternalASTSource::getMemoryBufferSizes(MemoryBufferSizes &sizes) const {} uint32_t ExternalASTSource::incrementGeneration(ASTContext &C) { uint32_t OldGeneration = CurrentGeneration; diff --git a/clang/lib/Frontend/ChainedIncludesSource.cpp b/clang/lib/Frontend/ChainedIncludesSource.cpp index cc0504b..5a5d2d5 100644 --- a/clang/lib/Frontend/ChainedIncludesSource.cpp +++ b/clang/lib/Frontend/ChainedIncludesSource.cpp @@ -47,9 +47,9 @@ protected: CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset) override; bool FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name) override; - ExternalLoadResult + void FindExternalLexicalDecls(const DeclContext *DC, - bool (*isKindWeWant)(Decl::Kind), + llvm::function_ref<bool(Decl::Kind)> IsKindWeWant, SmallVectorImpl<Decl *> &Result) override; void CompleteType(TagDecl *Tag) override; void CompleteType(ObjCInterfaceDecl *Class) override; @@ -246,11 +246,10 @@ ChainedIncludesSource::FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name) { return getFinalReader().FindExternalVisibleDeclsByName(DC, Name); } -ExternalLoadResult -ChainedIncludesSource::FindExternalLexicalDecls(const DeclContext *DC, - bool (*isKindWeWant)(Decl::Kind), - SmallVectorImpl<Decl*> &Result) { - return getFinalReader().FindExternalLexicalDecls(DC, isKindWeWant, Result); +void ChainedIncludesSource::FindExternalLexicalDecls( + const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant, + SmallVectorImpl<Decl *> &Result) { + return getFinalReader().FindExternalLexicalDecls(DC, IsKindWeWant, Result); } void ChainedIncludesSource::CompleteType(TagDecl *Tag) { return getFinalReader().CompleteType(Tag); diff --git a/clang/lib/Sema/MultiplexExternalSemaSource.cpp b/clang/lib/Sema/MultiplexExternalSemaSource.cpp index 9ecb5a7..0f93421 100644 --- a/clang/lib/Sema/MultiplexExternalSemaSource.cpp +++ b/clang/lib/Sema/MultiplexExternalSemaSource.cpp @@ -107,15 +107,11 @@ void MultiplexExternalSemaSource::completeVisibleDeclsMap(const DeclContext *DC) Sources[i]->completeVisibleDeclsMap(DC); } -ExternalLoadResult MultiplexExternalSemaSource:: -FindExternalLexicalDecls(const DeclContext *DC, - bool (*isKindWeWant)(Decl::Kind), - SmallVectorImpl<Decl*> &Result) { +void MultiplexExternalSemaSource::FindExternalLexicalDecls( + const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant, + SmallVectorImpl<Decl *> &Result) { for(size_t i = 0; i < Sources.size(); ++i) - // FIXME: The semantics of the return result is unclear to me... - Sources[i]->FindExternalLexicalDecls(DC, isKindWeWant, Result); - - return ELR_Success; + Sources[i]->FindExternalLexicalDecls(DC, IsKindWeWant, Result); } void MultiplexExternalSemaSource::FindFileRegionDecls(FileID File, diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 5223138..abc91e7 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -5910,8 +5910,13 @@ void ASTReader::CompleteRedeclChain(const Decl *D) { } else DC->lookup(Name); } else if (needsAnonymousDeclarationNumber(cast<NamedDecl>(D))) { - // FIXME: It'd be nice to do something a bit more targeted here. - D->getDeclContext()->decls_begin(); + // Find all declarations of this kind from the relevant context. + for (auto *DCDecl : cast<Decl>(D->getLexicalDeclContext())->redecls()) { + auto *DC = cast<DeclContext>(DCDecl); + SmallVector<Decl*, 8> Decls; + FindExternalLexicalDecls( + DC, [&](Decl::Kind K) { return K == D->getKind(); }, Decls); + } } } @@ -6174,47 +6179,48 @@ namespace { class FindExternalLexicalDeclsVisitor { ASTReader &Reader; const DeclContext *DC; - bool (*isKindWeWant)(Decl::Kind); + llvm::function_ref<bool(Decl::Kind)> IsKindWeWant; SmallVectorImpl<Decl*> &Decls; bool PredefsVisited[NUM_PREDEF_DECL_IDS]; public: - FindExternalLexicalDeclsVisitor(ASTReader &Reader, const DeclContext *DC, - bool (*isKindWeWant)(Decl::Kind), - SmallVectorImpl<Decl*> &Decls) - : Reader(Reader), DC(DC), isKindWeWant(isKindWeWant), Decls(Decls) - { + FindExternalLexicalDeclsVisitor( + ASTReader &Reader, const DeclContext *DC, + llvm::function_ref<bool(Decl::Kind)> IsKindWeWant, + SmallVectorImpl<Decl *> &Decls) + : Reader(Reader), DC(DC), IsKindWeWant(IsKindWeWant), Decls(Decls) { for (unsigned I = 0; I != NUM_PREDEF_DECL_IDS; ++I) PredefsVisited[I] = false; } static bool visitPostorder(ModuleFile &M, void *UserData) { - FindExternalLexicalDeclsVisitor *This - = static_cast<FindExternalLexicalDeclsVisitor *>(UserData); + return (*static_cast<FindExternalLexicalDeclsVisitor*>(UserData))(M); + } - ModuleFile::DeclContextInfosMap::iterator Info - = M.DeclContextInfos.find(This->DC); + bool operator()(ModuleFile &M) { + ModuleFile::DeclContextInfosMap::iterator Info = + M.DeclContextInfos.find(DC); if (Info == M.DeclContextInfos.end() || Info->second.LexicalDecls.empty()) return false; // Load all of the declaration IDs for (const KindDeclIDPair &P : Info->second.LexicalDecls) { - if (This->isKindWeWant && !This->isKindWeWant((Decl::Kind)P.first)) + if (!IsKindWeWant((Decl::Kind)P.first)) continue; // Don't add predefined declarations to the lexical context more // than once. if (P.second < NUM_PREDEF_DECL_IDS) { - if (This->PredefsVisited[P.second]) + if (PredefsVisited[P.second]) continue; - This->PredefsVisited[P.second] = true; + PredefsVisited[P.second] = true; } - if (Decl *D = This->Reader.GetLocalDecl(M, P.second)) { - if (!This->DC->isDeclInLexicalTraversal(D)) - This->Decls.push_back(D); + if (Decl *D = Reader.GetLocalDecl(M, P.second)) { + if (!DC->isDeclInLexicalTraversal(D)) + Decls.push_back(D); } } @@ -6223,16 +6229,16 @@ namespace { }; } -ExternalLoadResult ASTReader::FindExternalLexicalDecls(const DeclContext *DC, - bool (*isKindWeWant)(Decl::Kind), - SmallVectorImpl<Decl*> &Decls) { +void ASTReader::FindExternalLexicalDecls( + const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant, + SmallVectorImpl<Decl *> &Decls) { // There might be lexical decls in multiple modules, for the TU at - // least. Walk all of the modules in the order they were loaded. - FindExternalLexicalDeclsVisitor Visitor(*this, DC, isKindWeWant, Decls); + // least. FIXME: Only look in multiple module files in the very rare + // cases where this can actually happen. + FindExternalLexicalDeclsVisitor Visitor(*this, DC, IsKindWeWant, Decls); ModuleMgr.visitDepthFirst( nullptr, &FindExternalLexicalDeclsVisitor::visitPostorder, &Visitor); ++NumLexicalDeclContextsRead; - return ELR_Success; } namespace { |