@@ -5168,9 +5168,9 @@ class ExprContextAnalyzer {
5168
5168
ASTContext &Context;
5169
5169
5170
5170
// Results populated by Analyze()
5171
- SmallVector <Type, 2 > PossibleTypes;
5172
- SmallVector <StringRef, 2 > PossibleNames;
5173
- SmallVector <FunctionTypeAndDecl, 2 > PossibleCallees;
5171
+ SmallVectorImpl <Type> & PossibleTypes;
5172
+ SmallVectorImpl <StringRef> & PossibleNames;
5173
+ SmallVectorImpl <FunctionTypeAndDecl> & PossibleCallees;
5174
5174
5175
5175
void recordPossibleType (Type ty) {
5176
5176
if (!ty || ty->is <ErrorType>())
@@ -5368,9 +5368,13 @@ class ExprContextAnalyzer {
5368
5368
}
5369
5369
5370
5370
public:
5371
- ExprContextAnalyzer (DeclContext *DC, Expr *ParsedExpr)
5371
+ ExprContextAnalyzer (DeclContext *DC, Expr *ParsedExpr,
5372
+ SmallVectorImpl<Type> &PossibleTypes,
5373
+ SmallVectorImpl<StringRef> &PossibleNames,
5374
+ SmallVectorImpl<FunctionTypeAndDecl> &PossibleCallees)
5372
5375
: DC(DC), ParsedExpr(ParsedExpr), SM(DC->getASTContext ().SourceMgr),
5373
- Context(DC->getASTContext ()) {}
5376
+ Context(DC->getASTContext ()), PossibleTypes(PossibleTypes),
5377
+ PossibleNames(PossibleNames), PossibleCallees(PossibleCallees) {}
5374
5378
5375
5379
bool Analyze () {
5376
5380
// We cannot analyze without target.
@@ -5442,9 +5446,29 @@ class ExprContextAnalyzer {
5442
5446
}
5443
5447
return (!PossibleTypes.empty () || !PossibleNames.empty ());
5444
5448
}
5449
+ };
5450
+
5451
+ class ExprContextInfo {
5452
+ SmallVector<Type, 2 > PossibleTypes;
5453
+ SmallVector<StringRef, 2 > PossibleNames;
5454
+ SmallVector<FunctionTypeAndDecl, 2 > PossibleCallees;
5445
5455
5456
+ public:
5457
+ ExprContextInfo (DeclContext *DC, Expr *TargetExpr) {
5458
+ ExprContextAnalyzer Analyzer (DC, TargetExpr, PossibleTypes, PossibleNames,
5459
+ PossibleCallees);
5460
+ Analyzer.Analyze ();
5461
+ }
5462
+
5463
+ // Returns a list of possible context types.
5446
5464
ArrayRef<Type> getPossibleTypes () const { return PossibleTypes; }
5465
+
5466
+ // Returns a list of possible argument label names.
5467
+ // Valid only if \c getKind() is \c CallArgument.
5447
5468
ArrayRef<StringRef> getPossibleNames () const { return PossibleNames; }
5469
+
5470
+ // Returns a list of possible callee
5471
+ // Valid only if \c getKind() is \c CallArgument.
5448
5472
ArrayRef<FunctionTypeAndDecl> getPossibleCallees () const {
5449
5473
return PossibleCallees;
5450
5474
}
@@ -5542,10 +5566,8 @@ void CodeCompletionCallbacksImpl::doneParsing() {
5542
5566
if (isa<BindOptionalExpr>(ParsedExpr) || isa<ForceValueExpr>(ParsedExpr))
5543
5567
Lookup.setIsUnwrappedOptional (true );
5544
5568
5545
- ::ExprContextAnalyzer TypeAnalyzer (CurDeclContext, ParsedExpr);
5546
- if (TypeAnalyzer.Analyze ()) {
5547
- Lookup.setExpectedTypes (TypeAnalyzer.getPossibleTypes ());
5548
- }
5569
+ ExprContextInfo ContextInfo (CurDeclContext, ParsedExpr);
5570
+ Lookup.setExpectedTypes (ContextInfo.getPossibleTypes ());
5549
5571
Lookup.getValueExprCompletions (*ExprType, ReferencedDecl.getDecl ());
5550
5572
break ;
5551
5573
}
@@ -5585,10 +5607,8 @@ void CodeCompletionCallbacksImpl::doneParsing() {
5585
5607
5586
5608
case CompletionKind::ForEachSequence:
5587
5609
case CompletionKind::PostfixExprBeginning: {
5588
- ::ExprContextAnalyzer Analyzer (CurDeclContext, CodeCompleteTokenExpr);
5589
- if (Analyzer.Analyze ()) {
5590
- Lookup.setExpectedTypes (Analyzer.getPossibleTypes ());
5591
- }
5610
+ ExprContextInfo ContextInfo (CurDeclContext, CodeCompleteTokenExpr);
5611
+ Lookup.setExpectedTypes (ContextInfo.getPossibleTypes ());
5592
5612
DoPostfixExprBeginning ();
5593
5613
break ;
5594
5614
}
@@ -5611,21 +5631,18 @@ void CodeCompletionCallbacksImpl::doneParsing() {
5611
5631
case CompletionKind::PostfixExprParen: {
5612
5632
Lookup.setHaveLParen (true );
5613
5633
5614
- ::ExprContextAnalyzer TypeAnalyzer (CurDeclContext, CodeCompleteTokenExpr);
5615
- if (TypeAnalyzer.Analyze ()) {
5616
- Lookup.setExpectedTypes (TypeAnalyzer.getPossibleTypes ());
5617
- }
5618
-
5634
+ ExprContextInfo ContextInfo (CurDeclContext, CodeCompleteTokenExpr);
5635
+ Lookup.setExpectedTypes (ContextInfo.getPossibleTypes ());
5619
5636
if (ShouldCompleteCallPatternAfterParen) {
5620
5637
if (ExprType) {
5621
5638
Lookup.getValueExprCompletions (*ExprType, ReferencedDecl.getDecl ());
5622
5639
} else {
5623
- for (auto &typeAndDecl : TypeAnalyzer .getPossibleCallees ())
5640
+ for (auto &typeAndDecl : ContextInfo .getPossibleCallees ())
5624
5641
Lookup.getValueExprCompletions (typeAndDecl.first , typeAndDecl.second );
5625
5642
}
5626
5643
} else {
5627
5644
// Add argument labels, then fallthrough to get values.
5628
- Lookup.addArgNameCompletionResults (TypeAnalyzer .getPossibleNames ());
5645
+ Lookup.addArgNameCompletionResults (ContextInfo .getPossibleNames ());
5629
5646
}
5630
5647
5631
5648
if (!Lookup.FoundFunctionCalls ||
@@ -5735,10 +5752,9 @@ void CodeCompletionCallbacksImpl::doneParsing() {
5735
5752
}
5736
5753
case CompletionKind::UnresolvedMember: {
5737
5754
Lookup.setHaveDot (DotLoc);
5738
- ::ExprContextAnalyzer TypeAnalyzer (CurDeclContext, CodeCompleteTokenExpr);
5739
- if (TypeAnalyzer.Analyze ())
5740
- Lookup.setExpectedTypes (TypeAnalyzer.getPossibleTypes ());
5741
- Lookup.getUnresolvedMemberCompletions (TypeAnalyzer.getPossibleTypes ());
5755
+ ExprContextInfo ContextInfo (CurDeclContext, CodeCompleteTokenExpr);
5756
+ Lookup.setExpectedTypes (ContextInfo.getPossibleTypes ());
5757
+ Lookup.getUnresolvedMemberCompletions (ContextInfo.getPossibleTypes ());
5742
5758
break ;
5743
5759
}
5744
5760
case CompletionKind::AssignmentRHS : {
@@ -5749,13 +5765,12 @@ void CodeCompletionCallbacksImpl::doneParsing() {
5749
5765
break ;
5750
5766
}
5751
5767
case CompletionKind::CallArg : {
5752
- ::ExprContextAnalyzer Analyzer (CurDeclContext, CodeCompleteTokenExpr);
5753
- Analyzer.Analyze ();
5754
- if (!Analyzer.getPossibleNames ().empty ()) {
5755
- Lookup.addArgNameCompletionResults (Analyzer.getPossibleNames ());
5768
+ ExprContextInfo ContextInfo (CurDeclContext, CodeCompleteTokenExpr);
5769
+ if (!ContextInfo.getPossibleNames ().empty ()) {
5770
+ Lookup.addArgNameCompletionResults (ContextInfo.getPossibleNames ());
5756
5771
break ;
5757
5772
}
5758
- Lookup.setExpectedTypes (Analyzer .getPossibleTypes ());
5773
+ Lookup.setExpectedTypes (ContextInfo .getPossibleTypes ());
5759
5774
DoPostfixExprBeginning ();
5760
5775
break ;
5761
5776
}
0 commit comments