diff options
Diffstat (limited to 'contrib/llvm-project/clang/lib/AST/ExternalASTMerger.cpp')
-rw-r--r-- | contrib/llvm-project/clang/lib/AST/ExternalASTMerger.cpp | 52 |
1 files changed, 23 insertions, 29 deletions
diff --git a/contrib/llvm-project/clang/lib/AST/ExternalASTMerger.cpp b/contrib/llvm-project/clang/lib/AST/ExternalASTMerger.cpp index 88bbe90a4e90..8bad3b36244e 100644 --- a/contrib/llvm-project/clang/lib/AST/ExternalASTMerger.cpp +++ b/contrib/llvm-project/clang/lib/AST/ExternalASTMerger.cpp @@ -64,24 +64,24 @@ LookupSameContext(Source<TranslationUnitDecl *> SourceTU, const DeclContext *DC, Source<DeclarationName> SourceName = *SourceNameOrErr; DeclContext::lookup_result SearchResult = SourceParentDC.get()->lookup(SourceName.get()); - size_t SearchResultSize = SearchResult.size(); - if (SearchResultSize == 0 || SearchResultSize > 1) { - // There are two cases here. First, we might not find the name. - // We might also find multiple copies, in which case we have no - // guarantee that the one we wanted is the one we pick. (E.g., - // if we have two specializations of the same template it is - // very hard to determine which is the one you want.) - // - // The Origins map fixes this problem by allowing the origin to be - // explicitly recorded, so we trigger that recording by returning - // nothing (rather than a possibly-inaccurate guess) here. - return nullptr; - } else { - NamedDecl *SearchResultDecl = SearchResult[0]; + + // There are two cases here. First, we might not find the name. + // We might also find multiple copies, in which case we have no + // guarantee that the one we wanted is the one we pick. (E.g., + // if we have two specializations of the same template it is + // very hard to determine which is the one you want.) + // + // The Origins map fixes this problem by allowing the origin to be + // explicitly recorded, so we trigger that recording by returning + // nothing (rather than a possibly-inaccurate guess) here. + if (SearchResult.isSingleResult()) { + NamedDecl *SearchResultDecl = SearchResult.front(); if (isa<DeclContext>(SearchResultDecl) && SearchResultDecl->getKind() == DC->getDeclKind()) return cast<DeclContext>(SearchResultDecl)->getPrimaryContext(); return nullptr; // This type of lookup is unsupported + } else { + return nullptr; } } @@ -187,10 +187,7 @@ public: /// Implements the ASTImporter interface for tracking back a declaration /// to its original declaration it came from. Decl *GetOriginalDecl(Decl *To) override { - auto It = ToOrigin.find(To); - if (It != ToOrigin.end()) - return It->second; - return nullptr; + return ToOrigin.lookup(To); } /// Whenever a DeclContext is imported, ensure that ExternalASTSource's origin @@ -425,16 +422,14 @@ void ExternalASTMerger::RemoveSources(llvm::ArrayRef<ImporterSource> Sources) { logs() << "(ExternalASTMerger*)" << (void *)this << " removing source (ASTContext*)" << (void *)&S.getASTContext() << "\n"; - Importers.erase( - std::remove_if(Importers.begin(), Importers.end(), - [&Sources](std::unique_ptr<ASTImporter> &Importer) -> bool { - for (const ImporterSource &S : Sources) { - if (&Importer->getFromContext() == &S.getASTContext()) - return true; - } - return false; - }), - Importers.end()); + llvm::erase_if(Importers, + [&Sources](std::unique_ptr<ASTImporter> &Importer) -> bool { + for (const ImporterSource &S : Sources) { + if (&Importer->getFromContext() == &S.getASTContext()) + return true; + } + return false; + }); for (OriginMap::iterator OI = Origins.begin(), OE = Origins.end(); OI != OE; ) { std::pair<const DeclContext *, DCOrigin> Origin = *OI; bool Erase = false; @@ -543,4 +538,3 @@ void ExternalASTMerger::FindExternalLexicalDecls( return false; }); } - |