Skip to content

Commit 16cfca4

Browse files
committed
[ASTWalker] NFC: Rename SkipChildren -> SkipNode
This better describes what the action currently does, and allows us to re-introduce `SkipChildren` with the correct behavior.
1 parent 94c4d11 commit 16cfca4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+357
-359
lines changed

include/swift/AST/ASTWalker.h

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -216,28 +216,27 @@ class ASTWalker {
216216
return {Continue(), std::move(node)};
217217
}
218218

219-
/// Continue the current walk, replacing the current node with \p node.
220-
/// However, skip visiting the children of \p node, and instead resume the
221-
/// walk of the parent node.
219+
/// Skips visiting both the node's children and its post-visitation.
222220
template <typename T>
223-
static _Detail::SkipChildrenIfWalkResult<T> SkipChildren(T node) {
224-
return SkipChildrenIf(true, std::move(node));
221+
static _Detail::SkipChildrenIfWalkResult<T>
222+
SkipNode(T node) {
223+
return SkipNodeIf(true, std::move(node));
225224
}
226225

227-
/// If \p cond is true, this is equivalent to \c Action::SkipChildren(node).
226+
/// If \p cond is true, this is equivalent to \c Action::SkipNode(node).
228227
/// Otherwise, it is equivalent to \c Action::Continue(node).
229228
template <typename T>
230229
static _Detail::SkipChildrenIfWalkResult<T>
231-
SkipChildrenIf(bool cond, T node) {
232-
return {SkipChildrenIf(cond), std::move(node)};
230+
SkipNodeIf(bool cond, T node) {
231+
return {SkipNodeIf(cond), std::move(node)};
233232
}
234233

235234
/// If \p cond is true, this is equivalent to \c Action::Continue(node).
236-
/// Otherwise, it is equivalent to \c Action::SkipChildren(node).
235+
/// Otherwise, it is equivalent to \c Action::SkipNode(node).
237236
template <typename T>
238237
static _Detail::SkipChildrenIfWalkResult<T>
239-
VisitChildrenIf(bool cond, T node) {
240-
return SkipChildrenIf(!cond, std::move(node));
238+
VisitNodeIf(bool cond, T node) {
239+
return SkipNodeIf(!cond, std::move(node));
241240
}
242241

243242
/// If \p cond is true, this is equivalent to \c Action::Stop().
@@ -250,22 +249,23 @@ class ASTWalker {
250249
/// Continue the current walk.
251250
static _Detail::ContinueWalkAction Continue() { return {}; }
252251

253-
/// Continue the current walk, but do not visit the children of the current
254-
/// node. Instead, resume at the parent's post-walk.
255-
static _Detail::SkipChildrenIfWalkAction SkipChildren() {
256-
return SkipChildrenIf(true);
252+
/// Skips visiting both the node's children and its post-visitation.
253+
static _Detail::SkipChildrenIfWalkAction SkipNode() {
254+
return SkipNodeIf(true);
257255
}
258256

259-
/// If \p cond is true, this is equivalent to \c Action::SkipChildren().
257+
/// If \p cond is true, this is equivalent to \c Action::SkipNode().
260258
/// Otherwise, it is equivalent to \c Action::Continue().
261-
static _Detail::SkipChildrenIfWalkAction SkipChildrenIf(bool cond) {
259+
static _Detail::SkipChildrenIfWalkAction
260+
SkipNodeIf(bool cond) {
262261
return {cond};
263262
}
264263

265264
/// If \p cond is true, this is equivalent to \c Action::Continue().
266-
/// Otherwise, it is equivalent to \c Action::SkipChildren().
267-
static _Detail::SkipChildrenIfWalkAction VisitChildrenIf(bool cond) {
268-
return SkipChildrenIf(!cond);
265+
/// Otherwise, it is equivalent to \c Action::SkipNode().
266+
static _Detail::SkipChildrenIfWalkAction
267+
VisitNodeIf(bool cond) {
268+
return SkipNodeIf(!cond);
269269
}
270270

271271
/// Terminate the walk, returning without visiting any other nodes.
@@ -281,14 +281,14 @@ class ASTWalker {
281281
/// A pre-visitation action for AST nodes that do not support being replaced
282282
/// while walking.
283283
struct PreWalkAction {
284-
enum Kind { Stop, SkipChildren, Continue };
284+
enum Kind { Stop, SkipNode, Continue };
285285
Kind Action;
286286

287287
PreWalkAction(_Detail::ContinueWalkAction) : Action(Continue) {}
288288
PreWalkAction(_Detail::StopWalkAction) : Action(Stop) {}
289289

290290
PreWalkAction(_Detail::SkipChildrenIfWalkAction action)
291-
: Action(action.Cond ? SkipChildren : Continue) {}
291+
: Action(action.Cond ? SkipNode : Continue) {}
292292

293293
PreWalkAction(_Detail::StopIfWalkAction action)
294294
: Action(action.Cond ? Stop : Continue) {}

include/swift/Sema/ConstraintSystem.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2685,12 +2685,12 @@ class ConstraintSystem {
26852685

26862686
/// Ignore statements.
26872687
PreWalkResult<Stmt *> walkToStmtPre(Stmt *stmt) override {
2688-
return Action::SkipChildren(stmt);
2688+
return Action::SkipNode(stmt);
26892689
}
26902690

26912691
/// Ignore declarations.
26922692
PreWalkAction walkToDeclPre(Decl *decl) override {
2693-
return Action::SkipChildren();
2693+
return Action::SkipNode();
26942694
}
26952695
};
26962696

@@ -6389,7 +6389,7 @@ class TypeVarRefCollector : public ASTWalker {
63896389
PreWalkAction walkToDeclPre(Decl *D) override {
63906390
// We only need to walk into PatternBindingDecls, other kinds of decls
63916391
// cannot reference outer vars.
6392-
return Action::VisitChildrenIf(isa<PatternBindingDecl>(D));
6392+
return Action::VisitNodeIf(isa<PatternBindingDecl>(D));
63936393
}
63946394

63956395
ArrayRef<TypeVariableType *> getTypeVars() const {

lib/APIDigester/ModuleAnalyzerNodes.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2445,10 +2445,10 @@ class ConstExtractor: public ASTWalker {
24452445
PreWalkResult<Expr *> walkToExprPre(Expr *E) override {
24462446
if (E->isSemanticallyConstExpr()) {
24472447
record(E, E);
2448-
return Action::SkipChildren(E);
2448+
return Action::SkipNode(E);
24492449
}
24502450
if (handleSimpleReference(E)) {
2451-
return Action::SkipChildren(E);
2451+
return Action::SkipNode(E);
24522452
}
24532453
return Action::Continue(E);
24542454
}

lib/AST/ASTScopeCreation.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,47 +115,45 @@ class ScopeCreator final : public ASTAllocated<ScopeCreator> {
115115
scopeCreator
116116
.constructExpandAndInsert<ClosureParametersScope>(
117117
parent, closure);
118-
return Action::SkipChildren(E);
118+
return Action::SkipNode(E);
119119
}
120120
if (auto *capture = dyn_cast<CaptureListExpr>(E)) {
121121
scopeCreator
122122
.constructExpandAndInsert<CaptureListScope>(
123123
parent, capture);
124-
return Action::SkipChildren(E);
124+
return Action::SkipNode(E);
125125
}
126126

127127
// If we have a single value statement expression, we need to add any
128128
// scopes in the underlying statement.
129129
if (auto *SVE = dyn_cast<SingleValueStmtExpr>(E)) {
130130
scopeCreator.addToScopeTree(SVE->getStmt(), parent);
131-
return Action::SkipChildren(E);
131+
return Action::SkipNode(E);
132132
}
133133

134134
// If we have a try/try!/try?, we need to add a scope for it
135135
if (auto anyTry = dyn_cast<AnyTryExpr>(E)) {
136136
scopeCreator.constructExpandAndInsert<TryScope>(parent, anyTry);
137-
return Action::SkipChildren(E);
137+
return Action::SkipNode(E);
138138
}
139139

140140
return Action::Continue(E);
141141
}
142142
PreWalkResult<Stmt *> walkToStmtPre(Stmt *S) override {
143-
if (isa<BraceStmt>(S)) { // closures hidden in here
144-
return Action::Continue(S);
145-
}
146-
return Action::SkipChildren(S);
143+
// Closures can occur in BraceStmts.
144+
return Action::VisitNodeIf(isa<BraceStmt>(S), S);
147145
}
148146
PreWalkResult<Pattern *> walkToPatternPre(Pattern *P) override {
149-
return Action::SkipChildren(P);
147+
return Action::SkipNode(P);
150148
}
151149
PreWalkAction walkToDeclPre(Decl *D) override {
152-
return Action::SkipChildren();
150+
return Action::SkipNode();
153151
}
154152
PreWalkAction walkToTypeReprPre(TypeRepr *T) override {
155-
return Action::SkipChildren();
153+
return Action::SkipNode();
156154
}
157155
PreWalkAction walkToParameterListPre(ParameterList *PL) override {
158-
return Action::SkipChildren();
156+
return Action::SkipNode();
159157
}
160158

161159
MacroWalking getMacroWalkingBehavior() const override {

lib/AST/ASTVerifier.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ ASTWalker::PreWalkResult<Expr *> dispatchVisitPreExprHelper(
125125
return ASTWalker::Action::Continue(node);
126126
}
127127
V.cleanup(node);
128-
return ASTWalker::Action::SkipChildren(node);
128+
return ASTWalker::Action::SkipNode(node);
129129
}
130130

131131
template <typename Verifier, typename Kind>
@@ -141,7 +141,7 @@ ASTWalker::PreWalkResult<Expr *> dispatchVisitPreExprHelper(
141141
return ASTWalker::Action::Continue(node);
142142
}
143143
V.cleanup(node);
144-
return ASTWalker::Action::SkipChildren(node);
144+
return ASTWalker::Action::SkipNode(node);
145145
}
146146

147147
template <typename Verifier, typename Kind>
@@ -157,7 +157,7 @@ ASTWalker::PreWalkResult<Expr *> dispatchVisitPreExprHelper(
157157
return ASTWalker::Action::Continue(node);
158158
}
159159
V.cleanup(node);
160-
return ASTWalker::Action::SkipChildren(node);
160+
return ASTWalker::Action::SkipNode(node);
161161
}
162162

163163
template <typename Verifier, typename Kind>
@@ -170,7 +170,7 @@ ASTWalker::PreWalkResult<Expr *> dispatchVisitPreExprHelper(
170170
return ASTWalker::Action::Continue(node);
171171
}
172172
V.cleanup(node);
173-
return ASTWalker::Action::SkipChildren(node);
173+
return ASTWalker::Action::SkipNode(node);
174174
}
175175

176176
namespace {
@@ -401,7 +401,7 @@ class Verifier : public ASTWalker {
401401
if (shouldVerify(node))
402402
return Action::Continue();
403403
cleanup(node);
404-
return Action::SkipChildren();
404+
return Action::SkipNode();
405405
}
406406

407407
/// Helper template for dispatching pre-visitation.
@@ -419,7 +419,7 @@ class Verifier : public ASTWalker {
419419
if (shouldVerify(node))
420420
return Action::Continue(node);
421421
cleanup(node);
422-
return Action::SkipChildren(node);
422+
return Action::SkipNode(node);
423423
}
424424

425425
/// Helper template for dispatching pre-visitation.
@@ -430,7 +430,7 @@ class Verifier : public ASTWalker {
430430
if (shouldVerify(node))
431431
return Action::Continue(node);
432432
cleanup(node);
433-
return Action::SkipChildren(node);
433+
return Action::SkipNode(node);
434434
}
435435

436436
/// Helper template for dispatching post-visitation.

lib/AST/ASTWalker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,7 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
14551455
switch (Pre.Action) {
14561456
case PreWalkAction::Stop:
14571457
return true;
1458-
case PreWalkAction::SkipChildren:
1458+
case PreWalkAction::SkipNode:
14591459
return false;
14601460
case PreWalkAction::Continue:
14611461
break;
@@ -1479,7 +1479,7 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
14791479
switch (Pre.Action.Action) {
14801480
case PreWalkAction::Stop:
14811481
return nullptr;
1482-
case PreWalkAction::SkipChildren:
1482+
case PreWalkAction::SkipNode:
14831483
assert(*Pre.Value && "Use Action::Stop instead of returning nullptr");
14841484
return *Pre.Value;
14851485
case PreWalkAction::Continue:

lib/AST/Decl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8645,11 +8645,11 @@ swift::findWrappedValuePlaceholder(Expr *init) {
86458645

86468646
virtual PreWalkResult<Expr *> walkToExprPre(Expr *E) override {
86478647
if (placeholder)
8648-
return Action::SkipChildren(E);
8648+
return Action::SkipNode(E);
86498649

86508650
if (auto *value = dyn_cast<PropertyWrapperValuePlaceholderExpr>(E)) {
86518651
placeholder = value;
8652-
return Action::SkipChildren(value);
8652+
return Action::SkipNode(value);
86538653
}
86548654

86558655
return Action::Continue(E);
@@ -9548,7 +9548,7 @@ AbstractFunctionDecl::getBodyFingerprintIncludingLocalTypeMembers() const {
95489548

95499549
PreWalkAction walkToDeclPre(Decl *D) override {
95509550
if (D->isImplicit())
9551-
return Action::SkipChildren();
9551+
return Action::SkipNode();
95529552

95539553
if (auto *idc = dyn_cast<IterableDeclContext>(D)) {
95549554
if (auto fp = idc->getBodyFingerprint())
@@ -9559,7 +9559,7 @@ AbstractFunctionDecl::getBodyFingerprintIncludingLocalTypeMembers() const {
95599559
for (auto *d : idc->getParsedMembers())
95609560
const_cast<Decl *>(d)->walk(*this);
95619561

9562-
return Action::SkipChildren();
9562+
return Action::SkipNode();
95639563
}
95649564

95659565
if (auto *afd = dyn_cast<AbstractFunctionDecl>(D)) {

lib/AST/Expr.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -516,21 +516,21 @@ forEachImmediateChildExpr(llvm::function_ref<Expr *(Expr *)> callback) {
516516

517517
// We're only interested in the immediate children, so don't walk any
518518
// further.
519-
return Action::SkipChildren(E);
519+
return Action::SkipNode(E);
520520
}
521521

522522
PreWalkResult<Stmt *> walkToStmtPre(Stmt *S) override {
523-
return Action::SkipChildren(S);
523+
return Action::SkipNode(S);
524524
}
525525

526526
PreWalkResult<Pattern *> walkToPatternPre(Pattern *P) override {
527-
return Action::SkipChildren(P);
527+
return Action::SkipNode(P);
528528
}
529529
PreWalkAction walkToDeclPre(Decl *D) override {
530-
return Action::SkipChildren();
530+
return Action::SkipNode();
531531
}
532532
PreWalkAction walkToTypeReprPre(TypeRepr *T) override {
533-
return Action::SkipChildren();
533+
return Action::SkipNode();
534534
}
535535
};
536536

@@ -562,17 +562,17 @@ void Expr::forEachChildExpr(llvm::function_ref<Expr *(Expr *)> callback) {
562562
}
563563

564564
PreWalkResult<Stmt *> walkToStmtPre(Stmt *S) override {
565-
return Action::SkipChildren(S);
565+
return Action::SkipNode(S);
566566
}
567567

568568
PreWalkResult<Pattern *> walkToPatternPre(Pattern *P) override {
569-
return Action::SkipChildren(P);
569+
return Action::SkipNode(P);
570570
}
571571
PreWalkAction walkToDeclPre(Decl *D) override {
572-
return Action::SkipChildren();
572+
return Action::SkipNode();
573573
}
574574
PreWalkAction walkToTypeReprPre(TypeRepr *T) override {
575-
return Action::SkipChildren();
575+
return Action::SkipNode();
576576
}
577577
};
578578

lib/AST/InlinableText.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class IsFeatureCheck : public ASTWalker {
6969
}
7070
}
7171

72-
return Action::SkipChildrenIf(foundFeature, expr);
72+
return Action::SkipNodeIf(foundFeature, expr);
7373
}
7474
};
7575

@@ -145,13 +145,13 @@ struct ExtractInactiveRanges : public ASTWalker {
145145
// If there's no active clause, add the entire #if...#endif block.
146146
if (!clause) {
147147
addRange(start, end);
148-
return Action::SkipChildren();
148+
return Action::SkipNode();
149149
}
150150

151151
// If the clause is checking for a particular feature with $ or a compiler
152152
// version, keep the whole thing.
153153
if (anyClauseIsFeatureCheck(icd->getClauses())) {
154-
return Action::SkipChildren();
154+
return Action::SkipNode();
155155
}
156156

157157
// Ignore range from beginning of '#if', '#elseif', or '#else' to the
@@ -174,7 +174,7 @@ struct ExtractInactiveRanges : public ASTWalker {
174174
if (elt.isDecl(DeclKind::IfConfig))
175175
elt.get<Decl *>()->walk(*this);
176176

177-
return Action::SkipChildren();
177+
return Action::SkipNode();
178178
}
179179

180180
/// Gets the ignored ranges in source order.

0 commit comments

Comments
 (0)