Skip to content

Commit 5c2ed51

Browse files
committed
[AST] NFC: Add a bit more ASTWalker documentation
1 parent 87251e0 commit 5c2ed51

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

include/swift/AST/ASTWalker.h

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,22 @@ class ASTWalker {
149149
/// A namespace for ASTWalker actions that may be returned from pre-walk and
150150
/// post-walk functions.
151151
///
152-
/// Each action returns a separate underscored type, which is then consumed
153-
/// by PreWalkAction/PreWalkResult/PostWalkAction/PostWalkAction. It is
154-
/// designed this way to achieve a pseudo form of return type overloading,
152+
/// Only certain AST nodes support being replaced during a walk. The
153+
/// visitation methods for such nodes use the PreWalkResult/PostWalkResult
154+
/// types, which store both the action to take, along with the AST node to
155+
/// splice into the tree in place of the old node. The node must be provided
156+
/// to \c Action::<action> function, e.g \c Action::Continue(E) or
157+
/// \c Action::SkipChildren(E). The only exception is \c Action::Stop(),
158+
/// which never accepts a node.
159+
///
160+
/// AST nodes that do not support being replaced during a walk use visitation
161+
/// methods that return PreWalkAction/PostWalkAction. These just store the
162+
/// walking action to perform, and you return e.g \c Action::Continue() or
163+
/// \c Action::SkipChildren().
164+
///
165+
/// Each function here returns a separate underscored type, which is then
166+
/// consumed by PreWalkAction/PreWalkResult/PostWalkAction/PostWalkAction. It
167+
/// is designed this way to achieve a pseudo form of return type overloading,
155168
/// where e.g \c Action::Continue() can become either a pre-walk action or a
156169
/// post-walk action, but \c Action::SkipChildren() can only become a pre-walk
157170
/// action.
@@ -225,6 +238,9 @@ class ASTWalker {
225238
};
226239

227240
/// Do not construct directly, use \c Action::<action> instead.
241+
///
242+
/// A pre-visitation action for AST nodes that do not support being replaced
243+
/// while walking.
228244
struct PreWalkAction {
229245
enum Kind { Stop, SkipChildren, Continue };
230246
Kind Action;
@@ -242,6 +258,9 @@ class ASTWalker {
242258
};
243259

244260
/// Do not construct directly, use \c Action::<action> instead.
261+
///
262+
/// A post-visitation action for AST nodes that do not support being replaced
263+
/// while walking.
245264
struct PostWalkAction {
246265
enum Kind { Stop, Continue };
247266
Kind Action;
@@ -256,6 +275,10 @@ class ASTWalker {
256275
};
257276

258277
/// Do not construct directly, use \c Action::<action> instead.
278+
///
279+
/// A pre-visitation result for AST nodes that support being replaced while
280+
/// walking. Stores both the walking action to take, along with the node to
281+
/// splice into the AST in place of the old node.
259282
template <typename T>
260283
struct PreWalkResult {
261284
PreWalkAction Action;
@@ -297,6 +320,10 @@ class ASTWalker {
297320
};
298321

299322
/// Do not construct directly, use \c Action::<action> instead.
323+
///
324+
/// A post-visitation result for AST nodes that support being replaced while
325+
/// walking. Stores both the walking action to take, along with the node to
326+
/// splice into the AST in place of the old node.
300327
template <typename T>
301328
struct PostWalkResult {
302329
PostWalkAction Action;

0 commit comments

Comments
 (0)