@@ -41,8 +41,7 @@ using namespace swift::syntax;
41
41
// /
42
42
// / \param isExprBasic Whether we're only parsing an expr-basic.
43
43
ParserResult<Expr> Parser::parseExprImpl (Diag<> Message,
44
- bool isExprBasic,
45
- bool allowAmpPrefix) {
44
+ bool isExprBasic) {
46
45
// Start a context for creating expression syntax.
47
46
SyntaxParsingContext ExprParsingContext (SyntaxContext, SyntaxContextKind::Expr);
48
47
@@ -64,8 +63,7 @@ ParserResult<Expr> Parser::parseExprImpl(Diag<> Message,
64
63
}
65
64
66
65
auto expr = parseExprSequence (Message, isExprBasic,
67
- /* forConditionalDirective*/ false ,
68
- allowAmpPrefix);
66
+ /* forConditionalDirective*/ false );
69
67
if (expr.hasCodeCompletion ())
70
68
return expr;
71
69
if (expr.isNull ())
@@ -170,8 +168,7 @@ ParserResult<Expr> Parser::parseExprArrow() {
170
168
// / apply to everything to its right.
171
169
ParserResult<Expr> Parser::parseExprSequence (Diag<> Message,
172
170
bool isExprBasic,
173
- bool isForConditionalDirective,
174
- bool allowAmpPrefix) {
171
+ bool isForConditionalDirective) {
175
172
SyntaxParsingContext ExprSequnceContext (SyntaxContext, SyntaxContextKind::Expr);
176
173
177
174
SmallVector<Expr*, 8 > SequencedExprs;
@@ -182,36 +179,10 @@ ParserResult<Expr> Parser::parseExprSequence(Diag<> Message,
182
179
while (true ) {
183
180
if (isForConditionalDirective && Tok.isAtStartOfLine ())
184
181
break ;
185
-
186
- ParserResult<Expr> Primary;
187
-
188
- SourceLoc AmpPrefix;
189
- if (Tok.is (tok::amp_prefix)) {
190
- SyntaxParsingContext AmpCtx (SyntaxContext, SyntaxKind::InOutExpr);
191
- AmpPrefix = consumeToken (tok::amp_prefix);
192
-
193
- auto SubExpr = parseExprUnary (Message, isExprBasic);
194
- auto allowNextAmpPrefix = Tok.isBinaryOperator ();
195
- if (SubExpr.hasCodeCompletion ()) {
196
- Primary = makeParserCodeCompletionResult<Expr>();
197
- } else if (SubExpr.isNull ()) {
198
- Primary = nullptr ;
199
- } else if (allowAmpPrefix || allowNextAmpPrefix) {
200
- Primary = makeParserResult (
201
- new (Context) InOutExpr (AmpPrefix, SubExpr.get (), Type ()));
202
- } else {
203
- diagnose (AmpPrefix, diag::extraneous_amp_prefix);
204
- // In the long run, we should assign SubExpr to Primary to improve
205
- // single-pass diagnostic completeness, but for now, doing so exposes
206
- // diagnostic bugs in Sema where '&' is wrongly suggested as a fix.
207
- Primary = makeParserErrorResult (new (Context) ErrorExpr (
208
- {AmpPrefix, SubExpr.get ()->getSourceRange ().End }));
209
- }
210
- allowAmpPrefix = allowNextAmpPrefix;
211
- } else {
212
- // Parse a unary expression.
213
- Primary = parseExprSequenceElement (Message, isExprBasic);
214
- }
182
+
183
+ // Parse a unary expression.
184
+ ParserResult<Expr> Primary =
185
+ parseExprSequenceElement (Message, isExprBasic);
215
186
216
187
HasCodeCompletion |= Primary.hasCodeCompletion ();
217
188
if (Primary.isNull ()) {
@@ -256,8 +227,7 @@ ParserResult<Expr> Parser::parseExprSequence(Diag<> Message,
256
227
SyntaxKind::BinaryOperatorExpr);
257
228
Expr *Operator = parseExprOperator ();
258
229
SequencedExprs.push_back (Operator);
259
- allowAmpPrefix = true ;
260
-
230
+
261
231
// The message is only valid for the first subexpr.
262
232
Message = diag::expected_expr_after_operator;
263
233
break ;
@@ -508,6 +478,19 @@ ParserResult<Expr> Parser::parseExprUnary(Diag<> Message, bool isExprBasic) {
508
478
// If the next token is not an operator, just parse this as expr-postfix.
509
479
return parseExprPostfix (Message, isExprBasic);
510
480
481
+ case tok::amp_prefix: {
482
+ SyntaxParsingContext AmpCtx (SyntaxContext, SyntaxKind::InOutExpr);
483
+ SourceLoc Loc = consumeToken (tok::amp_prefix);
484
+
485
+ ParserResult<Expr> SubExpr = parseExprUnary (Message, isExprBasic);
486
+ if (SubExpr.hasCodeCompletion ())
487
+ return makeParserCodeCompletionResult<Expr>();
488
+ if (SubExpr.isNull ())
489
+ return nullptr ;
490
+ return makeParserResult (
491
+ new (Context) InOutExpr (Loc, SubExpr.get (), Type ()));
492
+ }
493
+
511
494
case tok::backslash:
512
495
return parseExprKeyPath ();
513
496
@@ -923,8 +906,7 @@ ParserResult<Expr> Parser::parseExprSuper(bool isExprBasic) {
923
906
indexArgLabelLocs,
924
907
rSquareLoc,
925
908
trailingClosure,
926
- SyntaxKind::FunctionCallArgumentList,
927
- /* allowAmpPrefix*/ true );
909
+ SyntaxKind::FunctionCallArgumentList);
928
910
if (status.hasCodeCompletion ())
929
911
return makeParserCodeCompletionResult<Expr>();
930
912
if (status.isError ())
@@ -1272,8 +1254,7 @@ Parser::parseExprPostfixSuffix(ParserResult<Expr> Result, bool isExprBasic,
1272
1254
tok::l_square, tok::r_square,
1273
1255
/* isPostfix=*/ true , isExprBasic, lSquareLoc, indexArgs,
1274
1256
indexArgLabels, indexArgLabelLocs, rSquareLoc, trailingClosure,
1275
- SyntaxKind::FunctionCallArgumentList,
1276
- /* allowAmpPrefix*/ true );
1257
+ SyntaxKind::FunctionCallArgumentList);
1277
1258
if (status.hasCodeCompletion ())
1278
1259
return makeParserCodeCompletionResult<Expr>();
1279
1260
if (status.isError () || Result.isNull ())
@@ -1709,8 +1690,7 @@ ParserResult<Expr> Parser::parseExprPrimary(Diag<> ID, bool isExprBasic) {
1709
1690
argLabelLocs,
1710
1691
rParenLoc,
1711
1692
trailingClosure,
1712
- SyntaxKind::FunctionCallArgumentList,
1713
- /* allowAmpPrefix*/ true );
1693
+ SyntaxKind::FunctionCallArgumentList);
1714
1694
if (status.isError ())
1715
1695
return nullptr ;
1716
1696
@@ -2954,8 +2934,7 @@ ParserStatus Parser::parseExprList(tok leftTok, tok rightTok,
2954
2934
SmallVectorImpl<SourceLoc> &exprLabelLocs,
2955
2935
SourceLoc &rightLoc,
2956
2936
Expr *&trailingClosure,
2957
- SyntaxKind Kind,
2958
- bool allowAmpPrefix) {
2937
+ SyntaxKind Kind) {
2959
2938
trailingClosure = nullptr ;
2960
2939
2961
2940
StructureMarkerRAII ParsingExprList (*this , Tok);
@@ -2992,8 +2971,7 @@ ParserStatus Parser::parseExprList(tok leftTok, tok rightTok,
2992
2971
DeclRefKind::Ordinary,
2993
2972
DeclNameLoc (Loc));
2994
2973
} else {
2995
- auto ParsedSubExpr = parseExpr (diag::expected_expr_in_expr_list,
2996
- /* allowAmpPrefix*/ allowAmpPrefix);
2974
+ auto ParsedSubExpr = parseExpr (diag::expected_expr_in_expr_list);
2997
2975
SubExpr = ParsedSubExpr.getPtrOrNull ();
2998
2976
Status = ParsedSubExpr;
2999
2977
}
@@ -3237,8 +3215,7 @@ Parser::parseExprCallSuffix(ParserResult<Expr> fn, bool isExprBasic) {
3237
3215
argLabelLocs,
3238
3216
rParenLoc,
3239
3217
trailingClosure,
3240
- SyntaxKind::FunctionCallArgumentList,
3241
- /* allowAmpPrefix*/ true );
3218
+ SyntaxKind::FunctionCallArgumentList);
3242
3219
3243
3220
// Form the call.
3244
3221
auto Result = makeParserResult (status | fn,
0 commit comments