Skip to content

Commit aa51e04

Browse files
committed
Remove PreWalkAction/PostWalkAction constructors
Help avoid using e.g `PreWalkAction::SkipChildren` directly, and reduce duplication of walk actions to take.
1 parent 0bdc011 commit aa51e04

File tree

3 files changed

+17
-24
lines changed

3 files changed

+17
-24
lines changed

include/swift/AST/ASTWalker.h

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,17 @@ class ASTWalker {
170170
// The 'Result' set of types, which do take a payload.
171171
template <typename T>
172172
struct ContinueWalkResult {
173+
ContinueWalkAction Action;
173174
T Value;
174175
};
175176
template <typename T>
176177
struct SkipChildrenIfWalkResult {
177-
bool Cond;
178+
SkipChildrenIfWalkAction Action;
178179
T Value;
179180
};
180181
template <typename T>
181182
struct StopIfWalkResult {
182-
bool Cond;
183+
StopIfWalkAction Action;
183184
T Value;
184185
};
185186
};
@@ -212,7 +213,7 @@ class ASTWalker {
212213
/// Continue the current walk, replacing the current node with \p node.
213214
template <typename T>
214215
static _Detail::ContinueWalkResult<T> Continue(T node) {
215-
return {std::move(node)};
216+
return {Continue(), std::move(node)};
216217
}
217218

218219
/// Continue the current walk, replacing the current node with \p node.
@@ -228,7 +229,7 @@ class ASTWalker {
228229
template <typename T>
229230
static _Detail::SkipChildrenIfWalkResult<T>
230231
SkipChildrenIf(bool cond, T node) {
231-
return {cond, std::move(node)};
232+
return {SkipChildrenIf(cond), std::move(node)};
232233
}
233234

234235
/// If \p cond is true, this is equivalent to \c Action::Continue(node).
@@ -243,7 +244,7 @@ class ASTWalker {
243244
/// Otherwise, it is equivalent to \c Action::Continue(node).
244245
template <typename T>
245246
static _Detail::StopIfWalkResult<T> StopIf(bool cond, T node) {
246-
return {cond, std::move(node)};
247+
return {StopIf(cond), std::move(node)};
247248
}
248249

249250
/// Continue the current walk.
@@ -283,8 +284,6 @@ class ASTWalker {
283284
enum Kind { Stop, SkipChildren, Continue };
284285
Kind Action;
285286

286-
PreWalkAction(Kind action) : Action(action) {}
287-
288287
PreWalkAction(_Detail::ContinueWalkAction) : Action(Continue) {}
289288
PreWalkAction(_Detail::StopWalkAction) : Action(Stop) {}
290289

@@ -303,8 +302,6 @@ class ASTWalker {
303302
enum Kind { Stop, Continue };
304303
Kind Action;
305304

306-
PostWalkAction(Kind action) : Action(action) {}
307-
308305
PostWalkAction(_Detail::ContinueWalkAction) : Action(Continue) {}
309306
PostWalkAction(_Detail::StopWalkAction) : Action(Stop) {}
310307

@@ -340,21 +337,18 @@ class ASTWalker {
340337

341338
template <typename U>
342339
PreWalkResult(_Detail::ContinueWalkResult<U> Result)
343-
: Action(PreWalkAction::Continue), Value(std::move(Result.Value)) {}
340+
: Action(Result.Action), Value(std::move(Result.Value)) {}
344341

345342
template <typename U>
346343
PreWalkResult(_Detail::SkipChildrenIfWalkResult<U> Result)
347-
: Action(Result.Cond ? PreWalkAction::SkipChildren
348-
: PreWalkAction::Continue),
349-
Value(std::move(Result.Value)) {}
344+
: Action(Result.Action), Value(std::move(Result.Value)) {}
350345

351346
template <typename U>
352347
PreWalkResult(_Detail::StopIfWalkResult<U> Result)
353-
: Action(Result.Cond ? PreWalkAction::Stop : PreWalkAction::Continue),
354-
Value(std::move(Result.Value)) {}
348+
: Action(Result.Action), Value(std::move(Result.Value)) {}
355349

356-
PreWalkResult(_Detail::StopWalkAction)
357-
: Action(PreWalkAction::Stop), Value(llvm::None) {}
350+
PreWalkResult(_Detail::StopWalkAction Action)
351+
: Action(Action), Value(llvm::None) {}
358352
};
359353

360354
/// Do not construct directly, use \c Action::<action> instead.
@@ -385,15 +379,14 @@ class ASTWalker {
385379

386380
template <typename U>
387381
PostWalkResult(_Detail::ContinueWalkResult<U> Result)
388-
: Action(PostWalkAction::Continue), Value(std::move(Result.Value)) {}
382+
: Action(Result.Action), Value(std::move(Result.Value)) {}
389383

390384
template <typename U>
391385
PostWalkResult(_Detail::StopIfWalkResult<U> Result)
392-
: Action(Result.Cond ? PostWalkAction::Stop : PostWalkAction::Continue),
393-
Value(std::move(Result.Value)) {}
386+
: Action(Result.Action), Value(std::move(Result.Value)) {}
394387

395-
PostWalkResult(_Detail::StopWalkAction)
396-
: Action(PostWalkAction::Stop), Value(llvm::None) {}
388+
PostWalkResult(_Detail::StopWalkAction Action)
389+
: Action(Action), Value(llvm::None) {}
397390
};
398391

399392
/// This method is called when first visiting an expression

lib/AST/Module.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3664,7 +3664,7 @@ class LocalTypeDeclCollector : public ASTWalker {
36643664
default:
36653665
break;
36663666
}
3667-
return PreWalkAction::Continue;
3667+
return Action::Continue();
36683668
}
36693669
};
36703670
} // namespace

lib/IDE/CursorInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class NodeFinder : ASTWalker {
175175

176176
PreWalkAction walkToDeclPre(Decl *D) override {
177177
if (!rangeContainsLocToResolve(D->getSourceRangeIncludingAttrs())) {
178-
return PreWalkAction::SkipChildren;
178+
return Action::SkipChildren();
179179
}
180180

181181
if (auto *newDC = dyn_cast<DeclContext>(D)) {

0 commit comments

Comments
 (0)