@@ -5078,6 +5078,42 @@ ClangDirectLookupRequest::evaluate(Evaluator &evaluator,
50785078 return filteredDecls;
50795079}
50805080
5081+ namespace {
5082+ // / Collects name lookup results into the given tiny vector, for use in the
5083+ // / various Clang importer lookup routines.
5084+ class CollectLookupResults {
5085+ DeclName name;
5086+ TinyPtrVector<ValueDecl *> &result;
5087+
5088+ public:
5089+ CollectLookupResults (DeclName name, TinyPtrVector<ValueDecl *> &result)
5090+ : name(name), result(result) { }
5091+
5092+ void add (ValueDecl *imported) {
5093+ result.push_back (imported);
5094+
5095+ // Expand any macros introduced by the Clang importer.
5096+ imported->visitAuxiliaryDecls ([&](Decl *decl) {
5097+ auto valueDecl = dyn_cast<ValueDecl>(decl);
5098+ if (!valueDecl)
5099+ return ;
5100+
5101+ // Bail out if the auxiliary decl was not produced by a macro.
5102+ auto module = decl->getDeclContext ()->getParentModule ();
5103+ auto *sf = module ->getSourceFileContainingLocation (decl->getLoc ());
5104+ if (!sf || sf->Kind != SourceFileKind::MacroExpansion)
5105+ return ;
5106+
5107+ // Only produce results that match the requested name.
5108+ if (!valueDecl->getName ().matchesRef (name))
5109+ return ;
5110+
5111+ result.push_back (valueDecl);
5112+ });
5113+ }
5114+ };
5115+ }
5116+
50815117TinyPtrVector<ValueDecl *> CXXNamespaceMemberLookup::evaluate (
50825118 Evaluator &evaluator, CXXNamespaceMemberLookupDescriptor desc) const {
50835119 EnumDecl *namespaceDecl = desc.namespaceDecl ;
@@ -5087,6 +5123,8 @@ TinyPtrVector<ValueDecl *> CXXNamespaceMemberLookup::evaluate(
50875123 auto &ctx = namespaceDecl->getASTContext ();
50885124
50895125 TinyPtrVector<ValueDecl *> result;
5126+ CollectLookupResults collector (name, result);
5127+
50905128 llvm::SmallPtrSet<clang::NamedDecl *, 8 > importedDecls;
50915129 for (auto redecl : clangNamespaceDecl->redecls ()) {
50925130 auto allResults = evaluateOrDefault (
@@ -5102,7 +5140,7 @@ TinyPtrVector<ValueDecl *> CXXNamespaceMemberLookup::evaluate(
51025140 continue ;
51035141 if (auto import =
51045142 ctx.getClangModuleLoader ()->importDeclDirectly (clangMember))
5105- result. push_back (cast<ValueDecl>(import ));
5143+ collector. add (cast<ValueDecl>(import ));
51065144 }
51075145 }
51085146
@@ -6202,28 +6240,7 @@ TinyPtrVector<ValueDecl *> ClangRecordMemberLookup::evaluate(
62026240
62036241 // The set of declarations we found.
62046242 TinyPtrVector<ValueDecl *> result;
6205- auto addResult = [&result, name](ValueDecl *imported) {
6206- result.push_back (imported);
6207-
6208- // Expand any macros introduced by the Clang importer.
6209- imported->visitAuxiliaryDecls ([&](Decl *decl) {
6210- auto valueDecl = dyn_cast<ValueDecl>(decl);
6211- if (!valueDecl)
6212- return ;
6213-
6214- // Bail out if the auxiliary decl was not produced by a macro.
6215- auto module = decl->getDeclContext ()->getParentModule ();
6216- auto *sf = module ->getSourceFileContainingLocation (decl->getLoc ());
6217- if (!sf || sf->Kind != SourceFileKind::MacroExpansion)
6218- return ;
6219-
6220- // Only produce results that match the requested name.
6221- if (!valueDecl->getName ().matchesRef (name))
6222- return ;
6223-
6224- result.push_back (valueDecl);
6225- });
6226- };
6243+ CollectLookupResults collector (name, result);
62276244
62286245 // Find the results that are actually a member of "recordDecl".
62296246 ClangModuleLoader *clangModuleLoader = ctx.getClangModuleLoader ();
@@ -6261,7 +6278,7 @@ TinyPtrVector<ValueDecl *> ClangRecordMemberLookup::evaluate(
62616278 continue ;
62626279 }
62636280
6264- addResult (cast<ValueDecl>(imported));
6281+ collector. add (cast<ValueDecl>(imported));
62656282 }
62666283
62676284 if (inheritance) {
@@ -6280,7 +6297,7 @@ TinyPtrVector<ValueDecl *> ClangRecordMemberLookup::evaluate(
62806297 if (!imported)
62816298 continue ;
62826299
6283- addResult (imported);
6300+ collector. add (imported);
62846301 }
62856302 }
62866303
@@ -6329,7 +6346,7 @@ TinyPtrVector<ValueDecl *> ClangRecordMemberLookup::evaluate(
63296346 if (foundNameArities.count (getArity (foundInBase)))
63306347 continue ;
63316348
6332- addResult (foundInBase);
6349+ collector. add (foundInBase);
63336350 }
63346351 }
63356352 }
0 commit comments