@@ -2789,87 +2789,72 @@ static void addNamespaceMembers(Decl *decl,
27892789 if (declOwner && declOwner != redeclOwner->getTopLevelModule ())
27902790 continue ;
27912791 }
2792+ for (auto member : redecl->decls ()) {
2793+ if (auto classTemplate = dyn_cast<clang::ClassTemplateDecl>(member)) {
2794+ // Add all specializations to a worklist so we don't accidentally mutate
2795+ // the list of decls we're iterating over.
2796+ llvm::SmallPtrSet<const clang::ClassTemplateSpecializationDecl *, 16 > specWorklist;
2797+ for (auto spec : classTemplate->specializations ())
2798+ specWorklist.insert (spec);
2799+ for (auto spec : specWorklist) {
2800+ if (auto import =
2801+ ctx.getClangModuleLoader ()->importDeclDirectly (spec))
2802+ if (addedMembers.insert (import ).second )
2803+ members.push_back (import );
2804+ }
2805+ }
27922806
2793- std::function<void (clang::DeclContext *)> addDeclsFromContext =
2794- [&](clang::DeclContext *declContext) {
2795- for (auto member : declContext->decls ()) {
2796- if (auto classTemplate =
2797- dyn_cast<clang::ClassTemplateDecl>(member)) {
2798- // Add all specializations to a worklist so we don't accidentally
2799- // mutate the list of decls we're iterating over.
2800- llvm::SmallPtrSet<const clang::ClassTemplateSpecializationDecl *,
2801- 16 >
2802- specWorklist;
2803- for (auto spec : classTemplate->specializations ())
2804- specWorklist.insert (spec);
2805- for (auto spec : specWorklist) {
2806- if (auto import =
2807- ctx.getClangModuleLoader ()->importDeclDirectly (spec))
2808- if (addedMembers.insert (import ).second )
2809- members.push_back (import );
2810- }
2807+ auto lookupAndAddMembers = [&](DeclName name) {
2808+ auto allResults = evaluateOrDefault (
2809+ ctx.evaluator , ClangDirectLookupRequest ({decl, redecl, name}), {});
2810+
2811+ for (auto found : allResults) {
2812+ auto clangMember = cast<clang::NamedDecl *>(found);
2813+ if (auto importedDecl =
2814+ ctx.getClangModuleLoader ()->importDeclDirectly (clangMember)) {
2815+ if (addedMembers.insert (importedDecl).second ) {
2816+ members.push_back (importedDecl);
2817+
2818+ // Handle macro-expanded declarations.
2819+ importedDecl->visitAuxiliaryDecls ([&](Decl *decl) {
2820+ auto valueDecl = dyn_cast<ValueDecl>(decl);
2821+ if (!valueDecl)
2822+ return ;
2823+
2824+ // Bail out if the auxiliary decl was not produced by a macro.
2825+ auto module = decl->getDeclContext ()->getParentModule ();
2826+ auto *sf = module ->getSourceFileContainingLocation (decl->getLoc ());
2827+ if (!sf || sf->Kind != SourceFileKind::MacroExpansion)
2828+ return ;
2829+
2830+ members.push_back (valueDecl);
2831+ });
28112832 }
2833+ }
2834+ }
2835+ };
28122836
2813- auto lookupAndAddMembers = [&](clang::NamedDecl *namedDecl) {
2814- auto name = ctx.getClangModuleLoader ()->importName (namedDecl);
2815- if (!name)
2816- return ;
2817-
2818- auto allResults = evaluateOrDefault (
2819- ctx.evaluator , ClangDirectLookupRequest ({decl, redecl, name}),
2820- {});
2821-
2822- for (auto found : allResults) {
2823- auto clangMember = cast<clang::NamedDecl *>(found);
2824- if (auto importedDecl =
2825- ctx.getClangModuleLoader ()->importDeclDirectly (
2826- clangMember)) {
2827- if (addedMembers.insert (importedDecl).second ) {
2828- members.push_back (importedDecl);
2829-
2830- // Handle macro-expanded declarations.
2831- importedDecl->visitAuxiliaryDecls ([&](Decl *decl) {
2832- auto valueDecl = dyn_cast<ValueDecl>(decl);
2833- if (!valueDecl)
2834- return ;
2835-
2836- // Bail out if the auxiliary decl was not produced by a
2837- // macro.
2838- auto module = decl->getDeclContext ()->getParentModule ();
2839- auto *sf = module ->getSourceFileContainingLocation (
2840- decl->getLoc ());
2841- if (!sf || sf->Kind != SourceFileKind::MacroExpansion)
2842- return ;
2843-
2844- members.push_back (valueDecl);
2845- });
2846- }
2847- }
2848- }
2849- };
2850-
2851- // Look through `extern` blocks.
2852- if (auto linkageSpecDecl = dyn_cast<clang::LinkageSpecDecl>(member))
2853- addDeclsFromContext (linkageSpecDecl);
2854-
2855- auto namedDecl = dyn_cast<clang::NamedDecl>(member);
2856- if (!namedDecl)
2837+ auto namedDecl = dyn_cast<clang::NamedDecl>(member);
2838+ if (!namedDecl)
2839+ continue ;
2840+ auto name = ctx.getClangModuleLoader ()->importName (namedDecl);
2841+ if (!name)
2842+ continue ;
2843+ lookupAndAddMembers (name);
2844+
2845+ // Unscoped enums could have their enumerators present
2846+ // in the parent namespace.
2847+ if (auto *ed = dyn_cast<clang::EnumDecl>(member)) {
2848+ if (!ed->isScoped ()) {
2849+ for (const auto *ecd : ed->enumerators ()) {
2850+ auto name = ctx.getClangModuleLoader ()->importName (ecd);
2851+ if (!name)
28572852 continue ;
2858- lookupAndAddMembers (namedDecl);
2859-
2860- // Unscoped enums could have their enumerators present
2861- // in the parent namespace.
2862- if (auto *ed = dyn_cast<clang::EnumDecl>(member)) {
2863- if (!ed->isScoped ()) {
2864- for (auto *ecd : ed->enumerators ()) {
2865- lookupAndAddMembers (ecd);
2866- }
2867- }
2868- }
2853+ lookupAndAddMembers (name);
28692854 }
2870- };
2871-
2872- addDeclsFromContext (redecl);
2855+ }
2856+ }
2857+ }
28732858 }
28742859}
28752860
0 commit comments