@@ -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
@@ -919,8 +902,7 @@ ParserResult<Expr> Parser::parseExprSuper(bool isExprBasic) {
919
902
indexArgLabelLocs,
920
903
rSquareLoc,
921
904
trailingClosure,
922
- SyntaxKind::FunctionCallArgumentList,
923
- /* allowAmpPrefix*/ true );
905
+ SyntaxKind::FunctionCallArgumentList);
924
906
if (status.hasCodeCompletion ())
925
907
return makeParserCodeCompletionResult<Expr>();
926
908
if (status.isError ())
@@ -1268,8 +1250,7 @@ Parser::parseExprPostfixSuffix(ParserResult<Expr> Result, bool isExprBasic,
1268
1250
tok::l_square, tok::r_square,
1269
1251
/* isPostfix=*/ true , isExprBasic, lSquareLoc, indexArgs,
1270
1252
indexArgLabels, indexArgLabelLocs, rSquareLoc, trailingClosure,
1271
- SyntaxKind::FunctionCallArgumentList,
1272
- /* allowAmpPrefix*/ true );
1253
+ SyntaxKind::FunctionCallArgumentList);
1273
1254
if (status.hasCodeCompletion ())
1274
1255
return makeParserCodeCompletionResult<Expr>();
1275
1256
if (status.isError () || Result.isNull ())
@@ -1705,8 +1686,7 @@ ParserResult<Expr> Parser::parseExprPrimary(Diag<> ID, bool isExprBasic) {
1705
1686
argLabelLocs,
1706
1687
rParenLoc,
1707
1688
trailingClosure,
1708
- SyntaxKind::FunctionCallArgumentList,
1709
- /* allowAmpPrefix*/ true );
1689
+ SyntaxKind::FunctionCallArgumentList);
1710
1690
if (status.isError ())
1711
1691
return nullptr ;
1712
1692
@@ -2942,8 +2922,7 @@ ParserStatus Parser::parseExprList(tok leftTok, tok rightTok,
2942
2922
SmallVectorImpl<SourceLoc> &exprLabelLocs,
2943
2923
SourceLoc &rightLoc,
2944
2924
Expr *&trailingClosure,
2945
- SyntaxKind Kind,
2946
- bool allowAmpPrefix) {
2925
+ SyntaxKind Kind) {
2947
2926
trailingClosure = nullptr ;
2948
2927
2949
2928
StructureMarkerRAII ParsingExprList (*this , Tok);
@@ -2980,8 +2959,7 @@ ParserStatus Parser::parseExprList(tok leftTok, tok rightTok,
2980
2959
DeclRefKind::Ordinary,
2981
2960
DeclNameLoc (Loc));
2982
2961
} else {
2983
- auto ParsedSubExpr = parseExpr (diag::expected_expr_in_expr_list,
2984
- /* allowAmpPrefix*/ allowAmpPrefix);
2962
+ auto ParsedSubExpr = parseExpr (diag::expected_expr_in_expr_list);
2985
2963
SubExpr = ParsedSubExpr.getPtrOrNull ();
2986
2964
Status = ParsedSubExpr;
2987
2965
}
@@ -3225,8 +3203,7 @@ Parser::parseExprCallSuffix(ParserResult<Expr> fn, bool isExprBasic) {
3225
3203
argLabelLocs,
3226
3204
rParenLoc,
3227
3205
trailingClosure,
3228
- SyntaxKind::FunctionCallArgumentList,
3229
- /* allowAmpPrefix*/ true );
3206
+ SyntaxKind::FunctionCallArgumentList);
3230
3207
3231
3208
// Form the call.
3232
3209
auto Result = makeParserResult (status | fn,
0 commit comments