@@ -5078,6 +5078,42 @@ ClangDirectLookupRequest::evaluate(Evaluator &evaluator,
5078
5078
return filteredDecls;
5079
5079
}
5080
5080
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
+
5081
5117
TinyPtrVector<ValueDecl *> CXXNamespaceMemberLookup::evaluate (
5082
5118
Evaluator &evaluator, CXXNamespaceMemberLookupDescriptor desc) const {
5083
5119
EnumDecl *namespaceDecl = desc.namespaceDecl ;
@@ -5087,6 +5123,8 @@ TinyPtrVector<ValueDecl *> CXXNamespaceMemberLookup::evaluate(
5087
5123
auto &ctx = namespaceDecl->getASTContext ();
5088
5124
5089
5125
TinyPtrVector<ValueDecl *> result;
5126
+ CollectLookupResults collector (name, result);
5127
+
5090
5128
llvm::SmallPtrSet<clang::NamedDecl *, 8 > importedDecls;
5091
5129
for (auto redecl : clangNamespaceDecl->redecls ()) {
5092
5130
auto allResults = evaluateOrDefault (
@@ -5102,7 +5140,7 @@ TinyPtrVector<ValueDecl *> CXXNamespaceMemberLookup::evaluate(
5102
5140
continue ;
5103
5141
if (auto import =
5104
5142
ctx.getClangModuleLoader ()->importDeclDirectly (clangMember))
5105
- result. push_back (cast<ValueDecl>(import ));
5143
+ collector. add (cast<ValueDecl>(import ));
5106
5144
}
5107
5145
}
5108
5146
@@ -6202,28 +6240,7 @@ TinyPtrVector<ValueDecl *> ClangRecordMemberLookup::evaluate(
6202
6240
6203
6241
// The set of declarations we found.
6204
6242
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);
6227
6244
6228
6245
// Find the results that are actually a member of "recordDecl".
6229
6246
ClangModuleLoader *clangModuleLoader = ctx.getClangModuleLoader ();
@@ -6261,7 +6278,7 @@ TinyPtrVector<ValueDecl *> ClangRecordMemberLookup::evaluate(
6261
6278
continue ;
6262
6279
}
6263
6280
6264
- addResult (cast<ValueDecl>(imported));
6281
+ collector. add (cast<ValueDecl>(imported));
6265
6282
}
6266
6283
6267
6284
if (inheritance) {
@@ -6280,7 +6297,7 @@ TinyPtrVector<ValueDecl *> ClangRecordMemberLookup::evaluate(
6280
6297
if (!imported)
6281
6298
continue ;
6282
6299
6283
- addResult (imported);
6300
+ collector. add (imported);
6284
6301
}
6285
6302
}
6286
6303
@@ -6329,7 +6346,7 @@ TinyPtrVector<ValueDecl *> ClangRecordMemberLookup::evaluate(
6329
6346
if (foundNameArities.count (getArity (foundInBase)))
6330
6347
continue ;
6331
6348
6332
- addResult (foundInBase);
6349
+ collector. add (foundInBase);
6333
6350
}
6334
6351
}
6335
6352
}
0 commit comments