Skip to content

Commit b26310e

Browse files
committed
TypeLoc: Offload TypeLoc off the ASTWalker
1 parent 1420a38 commit b26310e

File tree

12 files changed

+21
-66
lines changed

12 files changed

+21
-66
lines changed

include/swift/AST/ASTWalker.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class ModuleDecl;
2525
class Stmt;
2626
class Pattern;
2727
class TypeRepr;
28-
class TypeLoc;
2928
class ParameterList;
3029
enum class AccessKind: unsigned char;
3130

@@ -177,19 +176,6 @@ class ASTWalker {
177176
/// returns failure.
178177
virtual bool walkToDeclPost(Decl *D) { return true; }
179178

180-
/// This method is called when first visiting a TypeLoc, before
181-
/// walking into its TypeRepr children. If it returns false, the subtree is
182-
/// skipped.
183-
///
184-
/// \param TL The TypeLoc to check.
185-
virtual bool walkToTypeLocPre(TypeLoc &TL) { return true; }
186-
187-
/// This method is called after visiting the children of a TypeLoc.
188-
/// If it returns false, the remaining traversal is terminated and returns
189-
/// failure.
190-
virtual bool walkToTypeLocPost(TypeLoc &TL) { return true; }
191-
192-
193179
/// This method is called when first visiting a TypeRepr, before
194180
/// walking into its children. If it returns false, the subtree is skipped.
195181
///

include/swift/IDE/Utils.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,6 @@ class NameMatcher: public ASTWalker {
280280
bool walkToDeclPost(Decl *D) override;
281281
std::pair<bool, Stmt*> walkToStmtPre(Stmt *S) override;
282282
Stmt* walkToStmtPost(Stmt *S) override;
283-
bool walkToTypeLocPre(TypeLoc &TL) override;
284-
bool walkToTypeLocPost(TypeLoc &TL) override;
285283
bool walkToTypeReprPre(TypeRepr *T) override;
286284
bool walkToTypeReprPost(TypeRepr *T) override;
287285
std::pair<bool, Pattern*> walkToPatternPre(Pattern *P) override;

lib/AST/ASTScopeCreation.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1781,7 +1781,6 @@ void ScopeCreator::forEachClosureIn(
17811781
return {false, P};
17821782
}
17831783
bool walkToDeclPre(Decl *D) override { return false; }
1784-
bool walkToTypeLocPre(TypeLoc &TL) override { return false; }
17851784
bool walkToTypeReprPre(TypeRepr *T) override { return false; }
17861785
bool walkToParameterListPre(ParameterList *PL) override { return false; }
17871786
};

lib/AST/ASTWalker.cpp

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,9 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
155155
if (doIt(typeRepr))
156156
return true;
157157
for (auto &Inherit : ED->getInherited()) {
158-
if (doIt(Inherit))
159-
return true;
158+
if (auto *const TyR = Inherit.getTypeRepr())
159+
if (doIt(TyR))
160+
return true;
160161
}
161162
if (visitTrailingRequirements(ED))
162163
return true;
@@ -258,9 +259,10 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
258259
}
259260

260261
bool visitAbstractTypeParamDecl(AbstractTypeParamDecl *TPD) {
261-
for (auto Inherit: TPD->getInherited()) {
262-
if (doIt(Inherit))
263-
return true;
262+
for (const auto &Inherit: TPD->getInherited()) {
263+
if (auto *const TyR = Inherit.getTypeRepr())
264+
if (doIt(TyR))
265+
return true;
264266
}
265267

266268
if (const auto ATD = dyn_cast<AssociatedTypeDecl>(TPD)) {
@@ -282,9 +284,10 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
282284

283285
bool WalkGenerics = visitGenericParamListIfNeeded(NTD);
284286

285-
for (auto &Inherit : NTD->getInherited()) {
286-
if (doIt(Inherit))
287-
return true;
287+
for (const auto &Inherit : NTD->getInherited()) {
288+
if (auto *const TyR = Inherit.getTypeRepr())
289+
if (doIt(Inherit.getTypeRepr()))
290+
return true;
288291
}
289292

290293
// Visit requirements
@@ -355,8 +358,9 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
355358
bool WalkGenerics = visitGenericParamListIfNeeded(SD);
356359

357360
visit(SD->getIndices());
358-
if (doIt(SD->getElementTypeLoc()))
359-
return true;
361+
if (auto *const TyR = SD->getElementTypeLoc().getTypeRepr())
362+
if (doIt(TyR))
363+
return true;
360364

361365
// Visit trailing requirements
362366
if (WalkGenerics && visitTrailingRequirements(SD))
@@ -388,10 +392,12 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
388392
visit(PD);
389393
visit(AFD->getParameters());
390394

391-
if (auto *FD = dyn_cast<FuncDecl>(AFD))
395+
if (auto *FD = dyn_cast<FuncDecl>(AFD)) {
392396
if (!isa<AccessorDecl>(FD))
393-
if (doIt(FD->getBodyResultTypeLoc()))
394-
return true;
397+
if (auto *const TyR = FD->getBodyResultTypeLoc().getTypeRepr())
398+
if (doIt(TyR))
399+
return true;
400+
}
395401

396402
// Visit trailing requirements
397403
if (WalkGenerics && visitTrailingRequirements(AFD))
@@ -1319,21 +1325,6 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
13191325
return false;
13201326
}
13211327

1322-
bool doIt(TypeLoc &TL) {
1323-
if (!Walker.walkToTypeLocPre(TL))
1324-
return false;
1325-
1326-
// No "visit" since TypeLocs are not a class hierarchy. Clients can do what
1327-
// they want in walkToTypeLocPre.
1328-
1329-
if (auto typerepr = TL.getTypeRepr())
1330-
if (doIt(typerepr))
1331-
return true;
1332-
1333-
// If we didn't bail out, do post-order visitation.
1334-
return !Walker.walkToTypeLocPost(TL);
1335-
}
1336-
13371328
/// Returns true on failure.
13381329
bool doIt(TypeRepr *T) {
13391330
// Do the pre-order visitation. If it returns false, we just

lib/AST/Expr.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,6 @@ forEachImmediateChildExpr(llvm::function_ref<Expr *(Expr *)> callback) {
423423
}
424424
bool walkToDeclPre(Decl *D) override { return false; }
425425
bool walkToTypeReprPre(TypeRepr *T) override { return false; }
426-
bool walkToTypeLocPre(TypeLoc &TL) override { return false; }
427426
};
428427

429428
this->walk(ChildWalker(callback, this));
@@ -453,7 +452,6 @@ void Expr::forEachChildExpr(llvm::function_ref<Expr *(Expr *)> callback) {
453452
}
454453
bool walkToDeclPre(Decl *D) override { return false; }
455454
bool walkToTypeReprPre(TypeRepr *T) override { return false; }
456-
bool walkToTypeLocPre(TypeLoc &TL) override { return false; }
457455
};
458456

459457
this->walk(ChildWalker(callback));

lib/AST/Pattern.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ namespace {
187187
std::pair<bool, Stmt *> walkToStmtPre(Stmt *S) override {
188188
return { false, S };
189189
}
190-
bool walkToTypeLocPre(TypeLoc &TL) override { return false; }
191190
bool walkToTypeReprPre(TypeRepr *T) override { return false; }
192191
bool walkToParameterListPre(ParameterList *PL) override { return false; }
193192
bool walkToDeclPre(Decl *D) override { return false; }

lib/IDE/ExprContextAnalysis.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ class ExprFinder : public ASTWalker {
177177
return {isInterstingRange(S), S};
178178
}
179179

180-
bool walkToTypeLocPre(TypeLoc &TL) override { return false; }
181180
bool walkToTypeReprPre(TypeRepr *T) override { return false; }
182181
};
183182
} // anonymous namespace

lib/IDE/SwiftSourceDocInfo.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -468,16 +468,6 @@ Expr *NameMatcher::walkToExprPost(Expr *E) {
468468
return E;
469469
}
470470

471-
bool NameMatcher::walkToTypeLocPre(TypeLoc &TL) {
472-
if (isDone() || shouldSkip(TL.getSourceRange()))
473-
return false;
474-
return true;
475-
}
476-
477-
bool NameMatcher::walkToTypeLocPost(TypeLoc &TL) {
478-
return !isDone();
479-
}
480-
481471
bool NameMatcher::walkToTypeReprPre(TypeRepr *T) {
482472
if (isDone() || shouldSkip(T->getSourceRange()))
483473
return false;

lib/Parse/ParseStmt.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2467,7 +2467,6 @@ struct FallthroughFinder : ASTWalker {
24672467
}
24682468

24692469
bool walkToDeclPre(Decl *d) override { return false; }
2470-
bool walkToTypeLocPre(TypeLoc &tl) override { return false; }
24712470
bool walkToTypeReprPre(TypeRepr *t) override { return false; }
24722471

24732472
static FallthroughStmt *findFallthrough(Stmt *s) {

lib/Sema/CSGen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ namespace {
158158
}
159159

160160
/// Ignore types.
161-
bool walkToTypeLocPre(TypeLoc &TL) override { return false; }
161+
bool walkToTypeReprPre(TypeRepr *T) override { return false; }
162162
};
163163

164164
/// Given a collection of "linked" expressions, analyzes them for
@@ -305,7 +305,7 @@ namespace {
305305
}
306306

307307
/// Ignore types.
308-
bool walkToTypeLocPre(TypeLoc &TL) override { return false; }
308+
bool walkToTypeReprPre(TypeRepr *T) override { return false; }
309309
};
310310

311311
/// For a given expression, given information that is global to the

0 commit comments

Comments
 (0)