@@ -79,6 +79,24 @@ enum class LazyInitializerWalking {
7979 InAccessor
8080};
8181
82+ // / Specifies the behavior for walking a macro expansion, whether we want to
83+ // / see the macro arguments, the expansion, or both.
84+ enum class MacroWalking {
85+ // / Walk into the expansion of the macro, to see the semantic effect of
86+ // / the macro expansion.
87+ Expansion,
88+
89+ // / Walk into the arguments of the macro as written in the source code.
90+ // /
91+ // / The actual arguments walked may not make it into the program itself,
92+ // / because they can be translated by the macro in arbitrary ways.
93+ Arguments,
94+
95+ // / Walk into both the arguments of the macro as written in the source code
96+ // / and also the macro expansion.
97+ ArgumentsAndExpansion
98+ };
99+
82100// / An abstract class used to traverse an AST.
83101class ASTWalker {
84102public:
@@ -504,6 +522,26 @@ class ASTWalker {
504522 return LazyInitializerWalking::InPatternBinding;
505523 }
506524
525+ // / This method configures how the walker should walk into uses of macros.
526+ virtual MacroWalking getMacroWalkingBehavior () const {
527+ return MacroWalking::ArgumentsAndExpansion;
528+ }
529+
530+ // / Determine whether we should walk macro arguments (as they appear in
531+ // / source) and the expansion (which is semantically part of the program).
532+ std::pair<bool , bool > shouldWalkMacroArgumentsAndExpansion () const {
533+ switch (getMacroWalkingBehavior ()) {
534+ case MacroWalking::Expansion:
535+ return std::make_pair (false , true );
536+
537+ case MacroWalking::Arguments:
538+ return std::make_pair (true , false );
539+
540+ case MacroWalking::ArgumentsAndExpansion:
541+ return std::make_pair (true , true );
542+ }
543+ }
544+
507545 // / This method configures whether the walker should visit the body of a
508546 // / closure that was checked separately from its enclosing expression.
509547 // /
@@ -541,10 +579,6 @@ class ASTWalker {
541579 // / TODO: Consider changing this to false by default.
542580 virtual bool shouldWalkSerializedTopLevelInternalDecls () { return true ; }
543581
544- // / Whether we should walk into expanded macros, whether it be from a
545- // / \c MacroExpansionExpr or declarations created by attached macros.
546- virtual bool shouldWalkMacroExpansions () { return true ; }
547-
548582 // / walkToParameterListPre - This method is called when first visiting a
549583 // / ParameterList, before walking into its parameters.
550584 // /
0 commit comments