Skip to content

Commit 5c64324

Browse files
committed
[IDE] Refactor ExprContextAnalyzer. NFC
We don't need to keep ExprFinder beyond analysis.
1 parent 2fb5425 commit 5c64324

File tree

1 file changed

+54
-54
lines changed

1 file changed

+54
-54
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -5166,7 +5166,6 @@ class ExprContextAnalyzer {
51665166
Expr *ParsedExpr;
51675167
SourceManager &SM;
51685168
ASTContext &Context;
5169-
ExprParentFinder Finder;
51705169

51715170
// Results populated by Analyze()
51725171
SmallVector<Type, 2> PossibleTypes;
@@ -5238,59 +5237,6 @@ class ExprContextAnalyzer {
52385237
return !PossibleTypes.empty() || !PossibleNames.empty();
52395238
}
52405239

5241-
public:
5242-
ExprContextAnalyzer(DeclContext *DC, Expr *ParsedExpr) : DC(DC),
5243-
ParsedExpr(ParsedExpr), SM(DC->getASTContext().SourceMgr),
5244-
Context(DC->getASTContext()),
5245-
Finder(ParsedExpr, [](ASTWalker::ParentTy Node, ASTWalker::ParentTy Parent) {
5246-
if (auto E = Node.getAsExpr()) {
5247-
switch(E->getKind()) {
5248-
case ExprKind::Call:
5249-
case ExprKind::Binary:
5250-
case ExprKind::PrefixUnary:
5251-
case ExprKind::Assign:
5252-
case ExprKind::Subscript:
5253-
return true;
5254-
case ExprKind::Tuple: {
5255-
auto ParentE = Parent.getAsExpr();
5256-
return !ParentE || (!isa<CallExpr>(ParentE) &&
5257-
!isa<SubscriptExpr>(ParentE) &&
5258-
!isa<BinaryExpr>(ParentE) &&
5259-
!isa<TupleShuffleExpr>(ParentE));
5260-
}
5261-
default:
5262-
return false;
5263-
}
5264-
} else if (auto S = Node.getAsStmt()) {
5265-
switch (S->getKind()) {
5266-
case StmtKind::Return:
5267-
case StmtKind::ForEach:
5268-
case StmtKind::RepeatWhile:
5269-
case StmtKind::If:
5270-
case StmtKind::While:
5271-
case StmtKind::Guard:
5272-
return true;
5273-
default:
5274-
return false;
5275-
}
5276-
} else if (auto D = Node.getAsDecl()) {
5277-
switch (D->getKind()) {
5278-
case DeclKind::PatternBinding:
5279-
return true;
5280-
default:
5281-
return false;
5282-
}
5283-
} else if (auto P = Node.getAsPattern()) {
5284-
switch (P->getKind()) {
5285-
case PatternKind::Expr:
5286-
return true;
5287-
default:
5288-
return false;
5289-
}
5290-
} else
5291-
return false;
5292-
}) {}
5293-
52945240
void analyzeExpr(Expr *Parent) {
52955241
switch (Parent->getKind()) {
52965242
case ExprKind::Call:
@@ -5421,10 +5367,64 @@ class ExprContextAnalyzer {
54215367
}
54225368
}
54235369

5370+
public:
5371+
ExprContextAnalyzer(DeclContext *DC, Expr *ParsedExpr)
5372+
: DC(DC), ParsedExpr(ParsedExpr), SM(DC->getASTContext().SourceMgr),
5373+
Context(DC->getASTContext()) {}
5374+
54245375
bool Analyze() {
54255376
// We cannot analyze without target.
54265377
if (!ParsedExpr)
54275378
return false;
5379+
5380+
ExprParentFinder Finder(ParsedExpr, [](ASTWalker::ParentTy Node,
5381+
ASTWalker::ParentTy Parent) {
5382+
if (auto E = Node.getAsExpr()) {
5383+
switch (E->getKind()) {
5384+
case ExprKind::Call:
5385+
case ExprKind::Binary:
5386+
case ExprKind::PrefixUnary:
5387+
case ExprKind::Assign:
5388+
case ExprKind::Subscript:
5389+
return true;
5390+
case ExprKind::Tuple: {
5391+
auto ParentE = Parent.getAsExpr();
5392+
return !ParentE ||
5393+
(!isa<CallExpr>(ParentE) && !isa<SubscriptExpr>(ParentE) &&
5394+
!isa<BinaryExpr>(ParentE) && !isa<TupleShuffleExpr>(ParentE));
5395+
}
5396+
default:
5397+
return false;
5398+
}
5399+
} else if (auto S = Node.getAsStmt()) {
5400+
switch (S->getKind()) {
5401+
case StmtKind::Return:
5402+
case StmtKind::ForEach:
5403+
case StmtKind::RepeatWhile:
5404+
case StmtKind::If:
5405+
case StmtKind::While:
5406+
case StmtKind::Guard:
5407+
return true;
5408+
default:
5409+
return false;
5410+
}
5411+
} else if (auto D = Node.getAsDecl()) {
5412+
switch (D->getKind()) {
5413+
case DeclKind::PatternBinding:
5414+
return true;
5415+
default:
5416+
return false;
5417+
}
5418+
} else if (auto P = Node.getAsPattern()) {
5419+
switch (P->getKind()) {
5420+
case PatternKind::Expr:
5421+
return true;
5422+
default:
5423+
return false;
5424+
}
5425+
} else
5426+
return false;
5427+
});
54285428
DC->walkContext(Finder);
54295429

54305430
if (Finder.Ancestors.empty())

0 commit comments

Comments
 (0)