@@ -158,7 +158,8 @@ Parser::ParseExpressionWithLeadingExtension(SourceLocation ExtLoc) {
158
158
// / Parse an expr that doesn't include (top-level) commas.
159
159
ExprResult Parser::ParseAssignmentExpression (TypeCastState isTypeCast) {
160
160
if (Tok.is (tok::code_completion)) {
161
- Actions.CodeCompleteOrdinaryName (getCurScope (), Sema::PCC_Expression);
161
+ Actions.CodeCompleteExpression (getCurScope (),
162
+ PreferredType.get (Tok.getLocation ()));
162
163
cutOffParsing ();
163
164
return ExprError ();
164
165
}
@@ -271,7 +272,10 @@ Parser::ParseRHSOfBinaryExpression(ExprResult LHS, prec::Level MinPrec) {
271
272
getLangOpts ().CPlusPlus11 );
272
273
SourceLocation ColonLoc;
273
274
275
+ auto SavedType = PreferredType;
274
276
while (1 ) {
277
+ // Every iteration may rely on a preferred type for the whole expression.
278
+ PreferredType = SavedType;
275
279
// If this token has a lower precedence than we are allowed to parse (e.g.
276
280
// because we are called recursively, or because the token is not a binop),
277
281
// then we are done!
@@ -392,15 +396,8 @@ Parser::ParseRHSOfBinaryExpression(ExprResult LHS, prec::Level MinPrec) {
392
396
}
393
397
}
394
398
395
- // Code completion for the right-hand side of a binary expression goes
396
- // through a special hook that takes the left-hand side into account.
397
- if (Tok.is (tok::code_completion)) {
398
- Actions.CodeCompleteBinaryRHS (getCurScope (), LHS.get (),
399
- OpToken.getKind ());
400
- cutOffParsing ();
401
- return ExprError ();
402
- }
403
-
399
+ PreferredType.enterBinary (Actions, Tok.getLocation (), LHS.get (),
400
+ OpToken.getKind ());
404
401
// Parse another leaf here for the RHS of the operator.
405
402
// ParseCastExpression works here because all RHS expressions in C have it
406
403
// as a prefix, at least. However, in C++, an assignment-expression could
@@ -763,6 +760,7 @@ ExprResult Parser::ParseCastExpression(bool isUnaryExpression,
763
760
bool isVectorLiteral) {
764
761
ExprResult Res;
765
762
tok::TokenKind SavedKind = Tok.getKind ();
763
+ auto SavedType = PreferredType;
766
764
NotCastExpr = false ;
767
765
768
766
// This handles all of cast-expression, unary-expression, postfix-expression,
@@ -1114,6 +1112,9 @@ ExprResult Parser::ParseCastExpression(bool isUnaryExpression,
1114
1112
// -- cast-expression
1115
1113
Token SavedTok = Tok;
1116
1114
ConsumeToken ();
1115
+
1116
+ PreferredType.enterUnary (Actions, Tok.getLocation (), SavedTok.getKind (),
1117
+ SavedTok.getLocation ());
1117
1118
// One special case is implicitly handled here: if the preceding tokens are
1118
1119
// an ambiguous cast expression, such as "(T())++", then we recurse to
1119
1120
// determine whether the '++' is prefix or postfix.
@@ -1135,6 +1136,7 @@ ExprResult Parser::ParseCastExpression(bool isUnaryExpression,
1135
1136
case tok::amp: { // unary-expression: '&' cast-expression
1136
1137
// Special treatment because of member pointers
1137
1138
SourceLocation SavedLoc = ConsumeToken ();
1139
+ PreferredType.enterUnary (Actions, Tok.getLocation (), tok::amp, SavedLoc);
1138
1140
Res = ParseCastExpression (false , true );
1139
1141
if (!Res.isInvalid ())
1140
1142
Res = Actions.ActOnUnaryOp (getCurScope (), SavedLoc, SavedKind, Res.get ());
@@ -1149,6 +1151,7 @@ ExprResult Parser::ParseCastExpression(bool isUnaryExpression,
1149
1151
case tok::kw___real: // unary-expression: '__real' cast-expression [GNU]
1150
1152
case tok::kw___imag: { // unary-expression: '__imag' cast-expression [GNU]
1151
1153
SourceLocation SavedLoc = ConsumeToken ();
1154
+ PreferredType.enterUnary (Actions, Tok.getLocation (), SavedKind, SavedLoc);
1152
1155
Res = ParseCastExpression (false );
1153
1156
if (!Res.isInvalid ())
1154
1157
Res = Actions.ActOnUnaryOp (getCurScope (), SavedLoc, SavedKind, Res.get ());
@@ -1423,7 +1426,8 @@ ExprResult Parser::ParseCastExpression(bool isUnaryExpression,
1423
1426
Res = ParseBlockLiteralExpression ();
1424
1427
break ;
1425
1428
case tok::code_completion: {
1426
- Actions.CodeCompleteOrdinaryName (getCurScope (), Sema::PCC_Expression);
1429
+ Actions.CodeCompleteExpression (getCurScope (),
1430
+ PreferredType.get (Tok.getLocation ()));
1427
1431
cutOffParsing ();
1428
1432
return ExprError ();
1429
1433
}
@@ -1458,6 +1462,7 @@ ExprResult Parser::ParseCastExpression(bool isUnaryExpression,
1458
1462
// that the address of the function is being taken, which is illegal in CL.
1459
1463
1460
1464
// These can be followed by postfix-expr pieces.
1465
+ PreferredType = SavedType;
1461
1466
Res = ParsePostfixExpressionSuffix (Res);
1462
1467
if (getLangOpts ().OpenCL )
1463
1468
if (Expr *PostfixExpr = Res.get ()) {
@@ -1497,13 +1502,17 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
1497
1502
// Now that the primary-expression piece of the postfix-expression has been
1498
1503
// parsed, see if there are any postfix-expression pieces here.
1499
1504
SourceLocation Loc;
1505
+ auto SavedType = PreferredType;
1500
1506
while (1 ) {
1507
+ // Each iteration relies on preferred type for the whole expression.
1508
+ PreferredType = SavedType;
1501
1509
switch (Tok.getKind ()) {
1502
1510
case tok::code_completion:
1503
1511
if (InMessageExpression)
1504
1512
return LHS;
1505
1513
1506
- Actions.CodeCompletePostfixExpression (getCurScope (), LHS);
1514
+ Actions.CodeCompletePostfixExpression (
1515
+ getCurScope (), LHS, PreferredType.get (Tok.getLocation ()));
1507
1516
cutOffParsing ();
1508
1517
return ExprError ();
1509
1518
@@ -1545,6 +1554,7 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
1545
1554
Loc = T.getOpenLocation ();
1546
1555
ExprResult Idx, Length;
1547
1556
SourceLocation ColonLoc;
1557
+ PreferredType.enterSubscript (Actions, Tok.getLocation (), LHS.get ());
1548
1558
if (getLangOpts ().CPlusPlus11 && Tok.is (tok::l_brace)) {
1549
1559
Diag (Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
1550
1560
Idx = ParseBraceInitializer ();
@@ -1726,6 +1736,8 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
1726
1736
bool MayBePseudoDestructor = false ;
1727
1737
Expr* OrigLHS = !LHS.isInvalid () ? LHS.get () : nullptr ;
1728
1738
1739
+ PreferredType.enterMemAccess (Actions, Tok.getLocation (), OrigLHS);
1740
+
1729
1741
if (getLangOpts ().CPlusPlus && !LHS.isInvalid ()) {
1730
1742
Expr *Base = OrigLHS;
1731
1743
const Type* BaseType = Base->getType ().getTypePtrOrNull ();
@@ -1772,7 +1784,8 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
1772
1784
// Code completion for a member access expression.
1773
1785
Actions.CodeCompleteMemberReferenceExpr (
1774
1786
getCurScope (), Base, CorrectedBase, OpLoc, OpKind == tok::arrow,
1775
- Base && ExprStatementTokLoc == Base->getBeginLoc ());
1787
+ Base && ExprStatementTokLoc == Base->getBeginLoc (),
1788
+ PreferredType.get (Tok.getLocation ()));
1776
1789
1777
1790
cutOffParsing ();
1778
1791
return ExprError ();
@@ -2326,14 +2339,16 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,
2326
2339
return ExprError ();
2327
2340
SourceLocation OpenLoc = T.getOpenLocation ();
2328
2341
2342
+ PreferredType.enterParenExpr (Tok.getLocation (), OpenLoc);
2343
+
2329
2344
ExprResult Result (true );
2330
2345
bool isAmbiguousTypeId;
2331
2346
CastTy = nullptr ;
2332
2347
2333
2348
if (Tok.is (tok::code_completion)) {
2334
- Actions.CodeCompleteOrdinaryName ( getCurScope (),
2335
- ExprType >= CompoundLiteral? Sema::PCC_ParenthesizedExpression
2336
- : Sema::PCC_Expression );
2349
+ Actions.CodeCompleteExpression (
2350
+ getCurScope (), PreferredType. get (Tok. getLocation ()),
2351
+ /* IsParenthesized= */ ExprType >= CompoundLiteral );
2337
2352
cutOffParsing ();
2338
2353
return ExprError ();
2339
2354
}
@@ -2414,6 +2429,8 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,
2414
2429
T.consumeClose ();
2415
2430
ColonProtection.restore ();
2416
2431
RParenLoc = T.getCloseLocation ();
2432
+
2433
+ PreferredType.enterTypeCast (Tok.getLocation (), Ty.get ().get ());
2417
2434
ExprResult SubExpr = ParseCastExpression (/* isUnaryExpression=*/ false );
2418
2435
2419
2436
if (Ty.isInvalid () || SubExpr.isInvalid ())
@@ -2544,6 +2561,7 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,
2544
2561
return ExprError ();
2545
2562
}
2546
2563
2564
+ PreferredType.enterTypeCast (Tok.getLocation (), CastTy.get ());
2547
2565
// Parse the cast-expression that follows it next.
2548
2566
// TODO: For cast expression with CastTy.
2549
2567
Result = ParseCastExpression (/* isUnaryExpression=*/ false ,
@@ -2845,7 +2863,8 @@ bool Parser::ParseExpressionList(SmallVectorImpl<Expr *> &Exprs,
2845
2863
if (Completer)
2846
2864
Completer ();
2847
2865
else
2848
- Actions.CodeCompleteOrdinaryName (getCurScope (), Sema::PCC_Expression);
2866
+ Actions.CodeCompleteExpression (getCurScope (),
2867
+ PreferredType.get (Tok.getLocation ()));
2849
2868
cutOffParsing ();
2850
2869
return true ;
2851
2870
}
0 commit comments