Skip to content

Commit 0a7b436

Browse files
committed
Use Action::Stop in more places
This used to be something we couldn't express in certain walker methods. Update various places where we can now use it.
1 parent 9ff0e64 commit 0a7b436

File tree

5 files changed

+105
-205
lines changed

5 files changed

+105
-205
lines changed

include/swift/IDE/Utils.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,8 @@ class NameMatcher: public ASTWalker {
287287
PreWalkResult<Expr *> walkToExprPre(Expr *E) override;
288288
PostWalkResult<Expr *> walkToExprPost(Expr *E) override;
289289
PreWalkAction walkToDeclPre(Decl *D) override;
290-
PostWalkAction walkToDeclPost(Decl *D) override;
291290
PreWalkResult<Stmt *> walkToStmtPre(Stmt *S) override;
292-
PostWalkResult<Stmt *> walkToStmtPost(Stmt *S) override;
293291
PreWalkAction walkToTypeReprPre(TypeRepr *T) override;
294-
PostWalkAction walkToTypeReprPost(TypeRepr *T) override;
295292
PreWalkResult<Pattern *> walkToPatternPre(Pattern *P) override;
296293
bool shouldWalkIntoGenericParams() override { return true; }
297294

lib/IDE/Formatting.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,6 @@ class RangeWalker: protected ASTWalker {
476476
}
477477

478478
PreWalkAction walkToDeclPre(Decl *D) override {
479-
// TODO: Can we use Action::Stop instead of Action::SkipChildren in this
480-
// function?
481479
if (!walkCustomAttributes(D))
482480
return Action::SkipChildren();
483481

@@ -504,32 +502,32 @@ class RangeWalker: protected ASTWalker {
504502
if (SafeToAskForGenerics) {
505503
if (auto *GP = GC->getParsedGenericParams()) {
506504
if (!handleAngles(GP->getLAngleLoc(), GP->getRAngleLoc(), ContextLoc))
507-
return Action::SkipChildren();
505+
return Action::Stop();
508506
}
509507
}
510508
}
511509

512510
if (auto *NTD = dyn_cast<NominalTypeDecl>(D)) {
513511
if (!handleBraces(NTD->getBraces(), ContextLoc))
514-
return Action::SkipChildren();
512+
return Action::Stop();
515513
} else if (auto *ED = dyn_cast<ExtensionDecl>(D)) {
516514
if (!handleBraces(ED->getBraces(), ContextLoc))
517-
return Action::SkipChildren();
515+
return Action::Stop();
518516
} else if (auto *VD = dyn_cast<VarDecl>(D)) {
519517
if (!handleBraces(VD->getBracesRange(), VD->getNameLoc()))
520-
return Action::SkipChildren();
518+
return Action::Stop();
521519
} else if (isa<AbstractFunctionDecl>(D) || isa<SubscriptDecl>(D)) {
522520
if (isa<SubscriptDecl>(D)) {
523521
if (!handleBraces(cast<SubscriptDecl>(D)->getBracesRange(), ContextLoc))
524-
return Action::SkipChildren();
522+
return Action::Stop();
525523
}
526524
auto *PL = getParameterList(cast<ValueDecl>(D));
527525
if (!handleParens(PL->getLParenLoc(), PL->getRParenLoc(), ContextLoc))
528-
return Action::SkipChildren();
526+
return Action::Stop();
529527
} else if (auto *PGD = dyn_cast<PrecedenceGroupDecl>(D)) {
530528
SourceRange Braces(PGD->getLBraceLoc(), PGD->getRBraceLoc());
531529
if (!handleBraces(Braces, ContextLoc))
532-
return Action::SkipChildren();
530+
return Action::Stop();
533531
} else if (auto *PDD = dyn_cast<PoundDiagnosticDecl>(D)) {
534532
// TODO: add paren locations to PoundDiagnosticDecl
535533
}
@@ -683,20 +681,18 @@ class RangeWalker: protected ASTWalker {
683681
}
684682

685683
PreWalkAction walkToTypeReprPre(TypeRepr *T) override {
686-
// TODO: Can we use Action::Stop instead of Action::SkipChildren in this
687-
// function?
688684
if (auto *TT = dyn_cast<TupleTypeRepr>(T)) {
689685
SourceRange Parens = TT->getParens();
690686
if (!handleParens(Parens.Start, Parens.End, Parens.Start))
691-
return Action::SkipChildren();
687+
return Action::Stop();
692688
} else if (isa<ArrayTypeRepr>(T) || isa<DictionaryTypeRepr>(T)) {
693689
if (!handleSquares(T->getStartLoc(), T->getEndLoc(), T->getStartLoc()))
694-
return Action::SkipChildren();
690+
return Action::Stop();
695691
} else if (auto *GI = dyn_cast<GenericIdentTypeRepr>(T)) {
696692
SourceLoc ContextLoc = GI->getNameLoc().getBaseNameLoc();
697693
SourceRange Brackets = GI->getAngleBrackets();
698694
if (!handleAngles(Brackets.Start, Brackets.End, ContextLoc))
699-
return Action::SkipChildren();
695+
return Action::Stop();
700696
}
701697
return Action::Continue();
702698
}

0 commit comments

Comments
 (0)