@@ -5241,7 +5241,6 @@ namespace {
5241
5241
friend class CodeCompletionTypeContextAnalyzer ;
5242
5242
Expr *ChildExpr;
5243
5243
llvm::function_ref<bool (ParentTy, ParentTy)> Predicate;
5244
- bool AncestorsWithinBrace;
5245
5244
5246
5245
bool arePositionsSame (Expr *E1 , Expr *E2 ) {
5247
5246
return E1 ->getSourceRange ().Start == E2 ->getSourceRange ().Start &&
@@ -5250,15 +5249,9 @@ namespace {
5250
5249
5251
5250
public:
5252
5251
llvm::SmallVector<ParentTy, 5 > Ancestors;
5253
- llvm::SmallVector<size_t , 1 > FarthestAncestorIndex;
5254
- ParentTy ParentClosest;
5255
- ParentTy ParentFarthest;
5256
5252
ExprParentFinder (Expr* ChildExpr,
5257
- llvm::function_ref<bool (ParentTy, ParentTy)> Predicate,
5258
- bool AncestorsWithinBrace = false ) :
5259
- ChildExpr (ChildExpr), Predicate(Predicate),
5260
- AncestorsWithinBrace (AncestorsWithinBrace),
5261
- FarthestAncestorIndex ({0 }) {}
5253
+ llvm::function_ref<bool (ParentTy, ParentTy)> Predicate) :
5254
+ ChildExpr (ChildExpr), Predicate(Predicate) {}
5262
5255
5263
5256
std::pair<bool , Expr *> walkToExprPre (Expr *E) override {
5264
5257
// Finish if we found the target. 'ChildExpr' might have been replaced
@@ -5270,13 +5263,6 @@ namespace {
5270
5263
Ancestors.push_back (E);
5271
5264
return { true , E };
5272
5265
}
5273
- if (E == ChildExpr || arePositionsSame (E, ChildExpr)) {
5274
- if (!Ancestors.empty ()) {
5275
- ParentClosest = Ancestors.back ();
5276
- ParentFarthest = Ancestors[FarthestAncestorIndex.back ()];
5277
- }
5278
- return {false , nullptr };
5279
- }
5280
5266
return { true , E };
5281
5267
}
5282
5268
@@ -5289,14 +5275,10 @@ namespace {
5289
5275
std::pair<bool , Stmt *> walkToStmtPre (Stmt *S) override {
5290
5276
if (Predicate (S, Parent))
5291
5277
Ancestors.push_back (S);
5292
- if (AncestorsWithinBrace && isa<BraceStmt>(S))
5293
- FarthestAncestorIndex.push_back (Ancestors.size ());
5294
5278
return { true , S };
5295
5279
}
5296
5280
5297
5281
Stmt *walkToStmtPost (Stmt *S) override {
5298
- if (AncestorsWithinBrace && isa<BraceStmt>(S))
5299
- FarthestAncestorIndex.pop_back ();
5300
5282
if (Predicate (S, Parent))
5301
5283
Ancestors.pop_back ();
5302
5284
return S;
@@ -5338,8 +5320,7 @@ class CodeCompletionTypeContextAnalyzer {
5338
5320
ExprParentFinder Finder;
5339
5321
5340
5322
public:
5341
- CodeCompletionTypeContextAnalyzer (DeclContext *DC, Expr *ParsedExpr,
5342
- bool AncestorsWithinBrace = false ) : DC(DC),
5323
+ CodeCompletionTypeContextAnalyzer (DeclContext *DC, Expr *ParsedExpr) : DC(DC),
5343
5324
ParsedExpr (ParsedExpr), SM(DC->getASTContext ().SourceMgr),
5344
5325
Context(DC->getASTContext ()),
5345
5326
Finder(ParsedExpr, [](ASTWalker::ParentTy Node, ASTWalker::ParentTy Parent) {
@@ -5389,7 +5370,7 @@ class CodeCompletionTypeContextAnalyzer {
5389
5370
}
5390
5371
} else
5391
5372
return false ;
5392
- }, /* AncestorsWithinBrace= */ AncestorsWithinBrace ) {}
5373
+ }) {}
5393
5374
5394
5375
void analyzeExpr (Expr *Parent, llvm::function_ref<void (Type)> Callback,
5395
5376
SmallVectorImpl<StringRef> &PossibleNames) {
@@ -5647,7 +5628,8 @@ void CodeCompletionCallbacksImpl::doneParsing() {
5647
5628
if (isa<BindOptionalExpr>(ParsedExpr) || isa<ForceValueExpr>(ParsedExpr))
5648
5629
Lookup.setIsUnwrappedOptional (true );
5649
5630
5650
- ::CodeCompletionTypeContextAnalyzer TypeAnalyzer (CurDeclContext, ParsedExpr);
5631
+ ::CodeCompletionTypeContextAnalyzer TypeAnalyzer (CurDeclContext,
5632
+ ParsedExpr);
5651
5633
llvm::SmallVector<Type, 2 > PossibleTypes;
5652
5634
if (TypeAnalyzer.Analyze (PossibleTypes)) {
5653
5635
Lookup.setExpectedTypes (PossibleTypes);
@@ -5692,7 +5674,7 @@ void CodeCompletionCallbacksImpl::doneParsing() {
5692
5674
case CompletionKind::ForEachSequence:
5693
5675
case CompletionKind::PostfixExprBeginning: {
5694
5676
::CodeCompletionTypeContextAnalyzer Analyzer (CurDeclContext,
5695
- CodeCompleteTokenExpr);
5677
+ CodeCompleteTokenExpr);
5696
5678
llvm::SmallVector<Type, 1 > Types;
5697
5679
if (Analyzer.Analyze (Types)) {
5698
5680
Lookup.setExpectedTypes (Types);
@@ -5720,7 +5702,7 @@ void CodeCompletionCallbacksImpl::doneParsing() {
5720
5702
Lookup.setHaveLParen (true );
5721
5703
5722
5704
::CodeCompletionTypeContextAnalyzer TypeAnalyzer (CurDeclContext,
5723
- CodeCompleteTokenExpr);
5705
+ CodeCompleteTokenExpr);
5724
5706
SmallVector<Type, 2 > PossibleTypes;
5725
5707
SmallVector<StringRef, 2 > PossibleNames;
5726
5708
if (TypeAnalyzer.Analyze (PossibleTypes, PossibleNames)) {
@@ -5844,9 +5826,8 @@ void CodeCompletionCallbacksImpl::doneParsing() {
5844
5826
case CompletionKind::UnresolvedMember: {
5845
5827
Lookup.setHaveDot (DotLoc);
5846
5828
SmallVector<Type, 2 > PossibleTypes;
5847
- ::CodeCompletionTypeContextAnalyzer
5848
- TypeAnalyzer (CurDeclContext, CodeCompleteTokenExpr,
5849
- /* AncestorsWithinBrace=*/ true );
5829
+ ::CodeCompletionTypeContextAnalyzer TypeAnalyzer (CurDeclContext,
5830
+ CodeCompleteTokenExpr);
5850
5831
if (TypeAnalyzer.Analyze (PossibleTypes))
5851
5832
Lookup.setExpectedTypes (PossibleTypes);
5852
5833
Lookup.getUnresolvedMemberCompletions (PossibleTypes);
0 commit comments