Skip to content

Commit c01eb93

Browse files
committed
[CodeCompletion][NFC] Use ASTWalker::ParentTy instead of ASTNode
in 'ExprParentFinder'. There's no reason to re-pack into ASTNode.
1 parent d898f6d commit c01eb93

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4917,19 +4917,19 @@ namespace {
49174917
class ExprParentFinder : public ASTWalker {
49184918
friend class CodeCompletionTypeContextAnalyzer;
49194919
Expr *ChildExpr;
4920-
llvm::function_ref<bool(ASTNode)> Predicate;
4920+
llvm::function_ref<bool(ParentTy)> Predicate;
49214921

49224922
bool arePositionsSame(Expr *E1, Expr *E2) {
49234923
return E1->getSourceRange().Start == E2->getSourceRange().Start &&
49244924
E1->getSourceRange().End == E2->getSourceRange().End;
49254925
}
49264926

49274927
public:
4928-
llvm::SmallVector<ASTNode, 5> Ancestors;
4929-
ASTNode ParentClosest;
4930-
ASTNode ParentFarthest;
4928+
llvm::SmallVector<ParentTy, 5> Ancestors;
4929+
ParentTy ParentClosest;
4930+
ParentTy ParentFarthest;
49314931
ExprParentFinder(Expr* ChildExpr,
4932-
llvm::function_ref<bool(ASTNode)> Predicate) :
4932+
llvm::function_ref<bool(ParentTy)> Predicate) :
49334933
ChildExpr(ChildExpr), Predicate(Predicate) {}
49344934

49354935
std::pair<bool, Expr *> walkToExprPre(Expr *E) override {
@@ -4989,8 +4989,9 @@ class CodeCompletionTypeContextAnalyzer {
49894989
public:
49904990
CodeCompletionTypeContextAnalyzer(DeclContext *DC, Expr *ParsedExpr) : DC(DC),
49914991
ParsedExpr(ParsedExpr), SM(DC->getASTContext().SourceMgr),
4992-
Context(DC->getASTContext()), Finder(ParsedExpr, [](ASTNode Node) {
4993-
if (auto E = Node.dyn_cast<Expr *>()) {
4992+
Context(DC->getASTContext()),
4993+
Finder(ParsedExpr, [](ASTWalker::ParentTy Node) {
4994+
if (auto E = Node.getAsExpr()) {
49944995
switch(E->getKind()) {
49954996
case ExprKind::Call:
49964997
case ExprKind::Binary:
@@ -4999,8 +5000,8 @@ class CodeCompletionTypeContextAnalyzer {
49995000
return true;
50005001
default:
50015002
return false;
5002-
}
5003-
} else if (auto S = Node.dyn_cast<Stmt *>()) {
5003+
}
5004+
} else if (auto S = Node.getAsStmt()) {
50045005
switch (S->getKind()) {
50055006
case StmtKind::Return:
50065007
case StmtKind::ForEach:
@@ -5012,7 +5013,7 @@ class CodeCompletionTypeContextAnalyzer {
50125013
default:
50135014
return false;
50145015
}
5015-
} else if (auto D = Node.dyn_cast<Decl *>()) {
5016+
} else if (auto D = Node.getAsDecl()) {
50165017
switch (D->getKind()) {
50175018
case DeclKind::PatternBinding:
50185019
return true;
@@ -5021,7 +5022,7 @@ class CodeCompletionTypeContextAnalyzer {
50215022
}
50225023
} else
50235024
return false;
5024-
}) {}
5025+
}) {}
50255026

50265027
void analyzeExpr(Expr *Parent, llvm::function_ref<void(Type)> Callback,
50275028
SmallVectorImpl<StringRef> &PossibleNames) {
@@ -5148,11 +5149,11 @@ class CodeCompletionTypeContextAnalyzer {
51485149

51495150
for (auto It = Finder.Ancestors.rbegin(); It != Finder.Ancestors.rend();
51505151
++ It) {
5151-
if (auto Parent = It->dyn_cast<Expr *>()) {
5152+
if (auto Parent = It->getAsExpr()) {
51525153
analyzeExpr(Parent, Callback, PossibleNames);
5153-
} else if (auto Parent = It->dyn_cast<Stmt *>()) {
5154+
} else if (auto Parent = It->getAsStmt()) {
51545155
analyzeStmt(Parent, Callback);
5155-
} else if (auto Parent = It->dyn_cast<Decl *>()) {
5156+
} else if (auto Parent = It->getAsDecl()) {
51565157
analyzeDecl(Parent, Callback);
51575158
}
51585159
if (!PossibleTypes.empty() || !PossibleNames.empty())
@@ -5429,12 +5430,12 @@ void CodeCompletionCallbacksImpl::doneParsing() {
54295430
case CompletionKind::UnresolvedMember : {
54305431
Lookup.setHaveDot(SourceLoc());
54315432
SmallVector<Type, 1> PossibleTypes;
5432-
ExprParentFinder Walker(UnresolvedExpr, [&](ASTNode Node) {
5433-
return Node.is<Expr *>();
5433+
ExprParentFinder Walker(UnresolvedExpr, [&](ASTWalker::ParentTy Node) {
5434+
return Node.getAsExpr();
54345435
});
54355436
CurDeclContext->walkContext(Walker);
54365437
bool Success = false;
5437-
if (auto PE = Walker.ParentFarthest.get<Expr *>()) {
5438+
if (auto PE = Walker.ParentFarthest.getAsExpr()) {
54385439
prepareForRetypechecking(PE);
54395440
Success = typeCheckUnresolvedExpr(*CurDeclContext, UnresolvedExpr, PE,
54405441
PossibleTypes);

0 commit comments

Comments
 (0)