@@ -50,6 +50,25 @@ struct ReferenceMetaData {
5050 : Kind(Kind), AccKind(AccKind), isImplicit(isImplicit) {}
5151};
5252
53+ // / Specifies how the initialization expression of a \c lazy variable should be
54+ // / walked by the ASTWalker.
55+ enum class LazyInitializerWalking {
56+ // / No lazy initialization expressions will be walked.
57+ None,
58+
59+ // / The lazy initialization expression will only be walked as a part of
60+ // / the variable's pattern binding decl. This is the default behavior, and is
61+ // / consistent with the initializer being syntactically part of the pattern
62+ // / binding.
63+ InPatternBinding,
64+
65+ // / The lazy initialization expression will only be walked as part of the
66+ // / body of the synthesized accessor for the lazy variable. In such an
67+ // / accessor, the expression is denoted by LazyInitializerExpr. This is mainly
68+ // / useful for code emission.
69+ InAccessor
70+ };
71+
5372// / An abstract class used to traverse an AST.
5473class ASTWalker {
5574public:
@@ -193,15 +212,13 @@ class ASTWalker {
193212 // / params in AbstractFunctionDecl and NominalTypeDecl.
194213 virtual bool shouldWalkIntoGenericParams () { return false ; }
195214
196- // / This method configures whether the walker should walk into the
197- // / initializers of lazy variables. These initializers are semantically
198- // / different from other initializers in their context and so sometimes
199- // / should not be visited.
200- // /
201- // / Note that visiting the body of the lazy getter will find a
202- // / LazyInitializerExpr with the initializer as its sub-expression.
203- // / However, ASTWalker does not walk into LazyInitializerExprs on its own.
204- virtual bool shouldWalkIntoLazyInitializers () { return true ; }
215+ // / This method configures how the walker should walk the initializers of
216+ // / lazy variables. These initializers are semantically different from other
217+ // / initializers in their context and so sometimes should be visited as part
218+ // / of the synthesized getter, or should not be visited at all.
219+ virtual LazyInitializerWalking getLazyInitializerWalkingBehavior () {
220+ return LazyInitializerWalking::InPatternBinding;
221+ }
205222
206223 // / This method configures whether the walker should visit the body of a
207224 // / closure that was checked separately from its enclosing expression.
0 commit comments