@@ -4917,19 +4917,19 @@ namespace {
4917
4917
class ExprParentFinder : public ASTWalker {
4918
4918
friend class CodeCompletionTypeContextAnalyzer ;
4919
4919
Expr *ChildExpr;
4920
- llvm::function_ref<bool (ASTNode )> Predicate;
4920
+ llvm::function_ref<bool (ParentTy )> Predicate;
4921
4921
4922
4922
bool arePositionsSame (Expr *E1 , Expr *E2 ) {
4923
4923
return E1 ->getSourceRange ().Start == E2 ->getSourceRange ().Start &&
4924
4924
E1 ->getSourceRange ().End == E2 ->getSourceRange ().End ;
4925
4925
}
4926
4926
4927
4927
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;
4931
4931
ExprParentFinder (Expr* ChildExpr,
4932
- llvm::function_ref<bool (ASTNode )> Predicate) :
4932
+ llvm::function_ref<bool (ParentTy )> Predicate) :
4933
4933
ChildExpr (ChildExpr), Predicate(Predicate) {}
4934
4934
4935
4935
std::pair<bool , Expr *> walkToExprPre (Expr *E) override {
@@ -4989,8 +4989,9 @@ class CodeCompletionTypeContextAnalyzer {
4989
4989
public:
4990
4990
CodeCompletionTypeContextAnalyzer (DeclContext *DC, Expr *ParsedExpr) : DC(DC),
4991
4991
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 ()) {
4994
4995
switch (E->getKind ()) {
4995
4996
case ExprKind::Call:
4996
4997
case ExprKind::Binary:
@@ -4999,8 +5000,8 @@ class CodeCompletionTypeContextAnalyzer {
4999
5000
return true ;
5000
5001
default :
5001
5002
return false ;
5002
- }
5003
- } else if (auto S = Node.dyn_cast <Stmt *> ()) {
5003
+ }
5004
+ } else if (auto S = Node.getAsStmt ()) {
5004
5005
switch (S->getKind ()) {
5005
5006
case StmtKind::Return:
5006
5007
case StmtKind::ForEach:
@@ -5012,7 +5013,7 @@ class CodeCompletionTypeContextAnalyzer {
5012
5013
default :
5013
5014
return false ;
5014
5015
}
5015
- } else if (auto D = Node.dyn_cast <Decl *> ()) {
5016
+ } else if (auto D = Node.getAsDecl ()) {
5016
5017
switch (D->getKind ()) {
5017
5018
case DeclKind::PatternBinding:
5018
5019
return true ;
@@ -5021,7 +5022,7 @@ class CodeCompletionTypeContextAnalyzer {
5021
5022
}
5022
5023
} else
5023
5024
return false ;
5024
- }) {}
5025
+ }) {}
5025
5026
5026
5027
void analyzeExpr (Expr *Parent, llvm::function_ref<void (Type)> Callback,
5027
5028
SmallVectorImpl<StringRef> &PossibleNames) {
@@ -5148,11 +5149,11 @@ class CodeCompletionTypeContextAnalyzer {
5148
5149
5149
5150
for (auto It = Finder.Ancestors .rbegin (); It != Finder.Ancestors .rend ();
5150
5151
++ It) {
5151
- if (auto Parent = It->dyn_cast <Expr *> ()) {
5152
+ if (auto Parent = It->getAsExpr ()) {
5152
5153
analyzeExpr (Parent, Callback, PossibleNames);
5153
- } else if (auto Parent = It->dyn_cast <Stmt *> ()) {
5154
+ } else if (auto Parent = It->getAsStmt ()) {
5154
5155
analyzeStmt (Parent, Callback);
5155
- } else if (auto Parent = It->dyn_cast <Decl *> ()) {
5156
+ } else if (auto Parent = It->getAsDecl ()) {
5156
5157
analyzeDecl (Parent, Callback);
5157
5158
}
5158
5159
if (!PossibleTypes.empty () || !PossibleNames.empty ())
@@ -5429,12 +5430,12 @@ void CodeCompletionCallbacksImpl::doneParsing() {
5429
5430
case CompletionKind::UnresolvedMember : {
5430
5431
Lookup.setHaveDot (SourceLoc ());
5431
5432
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 ();
5434
5435
});
5435
5436
CurDeclContext->walkContext (Walker);
5436
5437
bool Success = false ;
5437
- if (auto PE = Walker.ParentFarthest .get <Expr *> ()) {
5438
+ if (auto PE = Walker.ParentFarthest .getAsExpr ()) {
5438
5439
prepareForRetypechecking (PE);
5439
5440
Success = typeCheckUnresolvedExpr (*CurDeclContext, UnresolvedExpr, PE,
5440
5441
PossibleTypes);
0 commit comments