@@ -512,28 +512,15 @@ void Decl::visitAuxiliaryDecls(
512512
513513void Decl::forEachAttachedMacro (MacroRole role,
514514 MacroCallback macroCallback) const {
515- for (auto customAttrConst : getExpandedAttrs ().getAttributes <CustomAttr>()) {
516- auto customAttr = const_cast <CustomAttr *>(customAttrConst);
517- auto *macroDecl = getResolvedMacro (customAttr);
518-
519- if (!macroDecl)
520- continue ;
521-
522- if (!macroDecl->getMacroRoles ().contains (role))
515+ for (auto *customAttr : getExpandedAttrs ().getAttributes <CustomAttr>()) {
516+ auto *macroDecl = customAttr->getResolvedMacro ();
517+ if (!macroDecl || !macroDecl->getMacroRoles ().contains (role))
523518 continue ;
524519
525520 macroCallback (customAttr, macroDecl);
526521 }
527522}
528523
529- MacroDecl *Decl::getResolvedMacro (CustomAttr *customAttr) const {
530- auto declRef = evaluateOrDefault (
531- getASTContext ().evaluator ,
532- ResolveMacroRequest{customAttr, getDeclContext ()}, ConcreteDeclRef ());
533-
534- return dyn_cast_or_null<MacroDecl>(declRef.getDecl ());
535- }
536-
537524unsigned Decl::getAttachedMacroDiscriminator (DeclBaseName macroName,
538525 MacroRole role,
539526 const CustomAttr *attr) const {
@@ -12508,27 +12495,22 @@ void MissingDecl::forEachMacroExpandedDecl(MacroExpandedDeclCallback callback) {
1250812495 auto macroRef = unexpandedMacro.macroRef ;
1250912496 auto *baseDecl = unexpandedMacro.baseDecl ;
1251012497
12511- // If the macro itself is a macro expansion expression, it should come with
12512- // a top-level code declaration that we can use for resolution. For such
12513- // cases, resolve the macro to determine whether it is a declaration or
12514- // code-item macro, meaning that it can produce declarations. In such cases,
12515- // expand the macro and use its substituted declaration (a MacroExpansionDecl)
12516- // instead.
12498+ // If the macro itself is a macro expansion expression, resolve it to
12499+ // determine whether it is a declaration or code-item macro, meaning that it
12500+ // can produce declarations. In such cases, expand the macro and use its
12501+ // substituted declaration (a MacroExpansionDecl) instead.
1251712502 if (auto freestanding = macroRef.dyn_cast <FreestandingMacroExpansion *>()) {
1251812503 if (auto expr = dyn_cast<MacroExpansionExpr>(freestanding)) {
1251912504 bool replacedWithDecl = false ;
12520- if (auto tlcd = dyn_cast_or_null<TopLevelCodeDecl>(baseDecl)) {
12521- ASTContext &ctx = tlcd->getASTContext ();
12522- if (auto macro = evaluateOrDefault (
12523- ctx.evaluator ,
12524- ResolveMacroRequest{macroRef, tlcd->getDeclContext ()},
12525- nullptr )) {
12505+ if (isa_and_nonnull<TopLevelCodeDecl>(baseDecl)) {
12506+ auto &eval = getASTContext ().evaluator ;
12507+ if (auto macro = evaluateOrDefault (eval, ResolveMacroRequest{macroRef},
12508+ nullptr )) {
1252612509 auto macroDecl = cast<MacroDecl>(macro.getDecl ());
1252712510 auto roles = macroDecl->getMacroRoles ();
1252812511 if (roles.contains (MacroRole::Declaration) ||
1252912512 roles.contains (MacroRole::CodeItem)) {
12530- (void )evaluateOrDefault (ctx.evaluator ,
12531- ExpandMacroExpansionExprRequest{expr},
12513+ (void )evaluateOrDefault (eval, ExpandMacroExpansionExprRequest{expr},
1253212514 std::nullopt );
1253312515 if (auto substituted = expr->getSubstituteDecl ()) {
1253412516 macroRef = substituted;
0 commit comments