|
58 | 58 | #include "swift/AST/GenericParamList.h"
|
59 | 59 | #include "swift/AST/ParameterList.h"
|
60 | 60 | #include "swift/AST/PrettyStackTrace.h"
|
| 61 | +#include "swift/AST/SourceFile.h" |
61 | 62 | using namespace swift;
|
62 | 63 |
|
63 | 64 | void ASTWalker::anchor() {}
|
@@ -115,7 +116,22 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
|
115 | 116 | LLVM_NODISCARD
|
116 | 117 | bool visit(Decl *D) {
|
117 | 118 | SetParentRAII SetParent(Walker, D);
|
118 |
| - return inherited::visit(D); |
| 119 | + // Visit auxiliary decls, which may be decls from macro expansions. |
| 120 | + auto moduleDecl = D->getDeclContext()->getParentModule(); |
| 121 | + bool alreadyFailed = false; |
| 122 | + D->visitAuxiliaryDecls([&](ASTNode node) { |
| 123 | + if (alreadyFailed) return; |
| 124 | + auto *decl = node.dyn_cast<Decl *>(); |
| 125 | + if (!decl) return; |
| 126 | + // Skip macro expansions if asked. |
| 127 | + if (!Walker.shouldWalkMacroExpansions()) |
| 128 | + if (auto *sf = moduleDecl->getSourceFileContainingLocation( |
| 129 | + decl->getLoc())) |
| 130 | + if (sf && sf->Kind == SourceFileKind::MacroExpansion) |
| 131 | + return; |
| 132 | + alreadyFailed = inherited::visit(decl); |
| 133 | + }); |
| 134 | + return alreadyFailed || inherited::visit(D); |
119 | 135 | }
|
120 | 136 |
|
121 | 137 | LLVM_NODISCARD
|
@@ -439,10 +455,11 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
|
439 | 455 | if (auto *expr = expandedNode.dyn_cast<Expr *>()) {
|
440 | 456 | if (!doIt(expr))
|
441 | 457 | return true;
|
442 |
| - } else if (auto *decl = expandedNode.dyn_cast<Decl *>()) { |
443 |
| - if (doIt(decl)) |
| 458 | + } else if (auto *stmt = expandedNode.dyn_cast<Stmt *>()) { |
| 459 | + if (!doIt(stmt)) |
444 | 460 | return true;
|
445 | 461 | }
|
| 462 | + // Decl already visited by `visitAuxiliaryDecls`. |
446 | 463 | }
|
447 | 464 | }
|
448 | 465 | return false;
|
|
0 commit comments