@@ -1093,7 +1093,7 @@ bool Parser::parseSpecializeAttribute(
1093
1093
llvm::function_ref<bool(Parser &)> parseSILSIPModule) {
1094
1094
assert (ClosingBrace == tok::r_paren || ClosingBrace == tok::r_square);
1095
1095
1096
- SourceLoc lParenLoc = consumeToken ();
1096
+ SourceLoc lParenLoc = consumeAttributeLParen ();
1097
1097
bool DiscardAttribute = false ;
1098
1098
StringRef AttrName = " _specialize" ;
1099
1099
@@ -1157,7 +1157,7 @@ Parser::parseStorageRestrictionsAttribute(SourceLoc AtLoc, SourceLoc Loc) {
1157
1157
}
1158
1158
1159
1159
// Consume '('
1160
- SourceLoc lParenLoc = consumeToken ();
1160
+ SourceLoc lParenLoc = consumeAttributeLParen ();
1161
1161
1162
1162
SmallVector<Identifier> initializesProperties;
1163
1163
SmallVector<Identifier> accessesProperties;
@@ -1319,7 +1319,7 @@ Parser::parseImplementsAttribute(SourceLoc AtLoc, SourceLoc Loc) {
1319
1319
return Status;
1320
1320
}
1321
1321
1322
- SourceLoc lParenLoc = consumeToken ();
1322
+ SourceLoc lParenLoc = consumeAttributeLParen ();
1323
1323
1324
1324
DeclNameLoc MemberNameLoc;
1325
1325
DeclNameRef MemberName;
@@ -1379,13 +1379,13 @@ Parser::parseImplementsAttribute(SourceLoc AtLoc, SourceLoc Loc) {
1379
1379
ParserResult<DifferentiableAttr>
1380
1380
Parser::parseDifferentiableAttribute (SourceLoc atLoc, SourceLoc loc) {
1381
1381
StringRef AttrName = " differentiable" ;
1382
- SourceLoc lParenLoc = loc, rParenLoc = loc;
1382
+ SourceLoc rParenLoc = loc;
1383
1383
DifferentiabilityKind diffKind = DifferentiabilityKind::Normal;
1384
1384
SmallVector<ParsedAutoDiffParameter, 8 > parameters;
1385
1385
TrailingWhereClause *whereClause = nullptr ;
1386
1386
1387
1387
// Parse '('.
1388
- if (consumeIf (tok::l_paren, lParenLoc )) {
1388
+ if (consumeIfAttributeLParen ( )) {
1389
1389
// Parse @differentiable attribute arguments.
1390
1390
if (parseDifferentiableAttributeArguments (
1391
1391
diffKind, parameters, whereClause))
@@ -1415,7 +1415,7 @@ bool Parser::parseExternAttribute(DeclAttributes &Attributes,
1415
1415
SourceLoc lParenLoc = Tok.getLoc (), rParenLoc;
1416
1416
1417
1417
// Parse @_extern(<language>, ...)
1418
- if (!consumeIf (tok::l_paren )) {
1418
+ if (!consumeIfAttributeLParen ( )) {
1419
1419
diagnose (Loc, diag::attr_expected_lparen, AttrName,
1420
1420
DeclAttribute::isDeclModifier (DAK_Extern));
1421
1421
return false ;
@@ -1857,7 +1857,7 @@ static bool parseQualifiedDeclName(Parser &P, Diag<> nameParseError,
1857
1857
ParserResult<DerivativeAttr> Parser::parseDerivativeAttribute (SourceLoc atLoc,
1858
1858
SourceLoc loc) {
1859
1859
StringRef AttrName = " derivative" ;
1860
- SourceLoc lParenLoc = loc, rParenLoc = loc;
1860
+ SourceLoc rParenLoc = loc;
1861
1861
TypeRepr *baseType = nullptr ;
1862
1862
DeclNameRefWithLoc original;
1863
1863
SmallVector<ParsedAutoDiffParameter, 8 > parameters;
@@ -1885,7 +1885,7 @@ ParserResult<DerivativeAttr> Parser::parseDerivativeAttribute(SourceLoc atLoc,
1885
1885
return errorAndSkipUntilConsumeRightParen (*this , AttrName);
1886
1886
};
1887
1887
// Parse '('.
1888
- if (!consumeIf (tok::l_paren, lParenLoc )) {
1888
+ if (!consumeIfAttributeLParen ( )) {
1889
1889
diagnose (getEndOfPreviousLoc (), diag::attr_expected_lparen, AttrName,
1890
1890
/* DeclModifier*/ false );
1891
1891
return makeParserError ();
@@ -1937,7 +1937,7 @@ ParserResult<DerivativeAttr> Parser::parseDerivativeAttribute(SourceLoc atLoc,
1937
1937
ParserResult<TransposeAttr> Parser::parseTransposeAttribute (SourceLoc atLoc,
1938
1938
SourceLoc loc) {
1939
1939
StringRef AttrName = " transpose" ;
1940
- SourceLoc lParenLoc = loc, rParenLoc = loc;
1940
+ SourceLoc rParenLoc = loc;
1941
1941
TypeRepr *baseType = nullptr ;
1942
1942
DeclNameRefWithLoc original;
1943
1943
SmallVector<ParsedAutoDiffParameter, 8 > parameters;
@@ -1966,7 +1966,7 @@ ParserResult<TransposeAttr> Parser::parseTransposeAttribute(SourceLoc atLoc,
1966
1966
};
1967
1967
1968
1968
// Parse '('.
1969
- if (!consumeIf (tok::l_paren, lParenLoc )) {
1969
+ if (!consumeIfAttributeLParen ( )) {
1970
1970
diagnose (getEndOfPreviousLoc (), diag::attr_expected_lparen, AttrName,
1971
1971
/* DeclModifier*/ false );
1972
1972
return makeParserError ();
@@ -2270,7 +2270,7 @@ bool Parser::parseBackDeployedAttribute(DeclAttributes &Attributes,
2270
2270
SourceLoc Loc) {
2271
2271
std::string AtAttrName = (llvm::Twine (" @" ) + AttrName).str ();
2272
2272
auto LeftLoc = Tok.getLoc ();
2273
- if (!consumeIf (tok::l_paren )) {
2273
+ if (!consumeIfAttributeLParen ( )) {
2274
2274
diagnose (Loc, diag::attr_expected_lparen, AtAttrName,
2275
2275
DeclAttribute::isDeclModifier (DAK_BackDeployed));
2276
2276
return false ;
@@ -2418,7 +2418,7 @@ Parser::parseDocumentationAttribute(SourceLoc AtLoc, SourceLoc Loc) {
2418
2418
llvm::Optional<AccessLevel> Visibility = llvm::None;
2419
2419
llvm::Optional<StringRef> Metadata = llvm::None;
2420
2420
2421
- if (!consumeIf (tok::l_paren )) {
2421
+ if (!consumeIfAttributeLParen ( )) {
2422
2422
diagnose (Loc, diag::attr_expected_lparen, AttrName,
2423
2423
declModifier);
2424
2424
return makeParserError ();
@@ -2503,7 +2503,7 @@ Parser::parseMacroRoleAttribute(
2503
2503
}
2504
2504
2505
2505
// Parse the argments.
2506
- SourceLoc lParenLoc = consumeToken ();
2506
+ SourceLoc lParenLoc = consumeAttributeLParen ();
2507
2507
SourceLoc rParenLoc;
2508
2508
llvm::Optional<MacroRole> role;
2509
2509
bool sawRole = false ;
@@ -2750,7 +2750,7 @@ static llvm::Optional<Identifier> parseSingleAttrOptionImpl(
2750
2750
return llvm::None;
2751
2751
}
2752
2752
2753
- P.consumeToken (tok::l_paren );
2753
+ P.consumeAttributeLParen ( );
2754
2754
2755
2755
StringRef parsedName = P.Tok .getText ();
2756
2756
if (!P.consumeIf (tok::identifier)) {
@@ -2913,7 +2913,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
2913
2913
break ;
2914
2914
2915
2915
case DAK_Effects: {
2916
- if (!consumeIf (tok::l_paren )) {
2916
+ if (!consumeIfAttributeLParen ( )) {
2917
2917
diagnose (Loc, diag::attr_expected_lparen, AttrName,
2918
2918
DeclAttribute::isDeclModifier (DK));
2919
2919
return makeParserSuccess ();
@@ -3093,7 +3093,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3093
3093
break ;
3094
3094
}
3095
3095
3096
- consumeToken (tok::l_paren );
3096
+ consumeAttributeLParen ( );
3097
3097
3098
3098
// Parse the subject.
3099
3099
if (Tok.isContextualKeyword (" set" )) {
@@ -3145,7 +3145,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3145
3145
}
3146
3146
3147
3147
case DAK_SPIAccessControl: {
3148
- if (!consumeIf (tok::l_paren )) {
3148
+ if (!consumeIfAttributeLParen ( )) {
3149
3149
diagnose (Loc, diag::attr_expected_lparen, AttrName,
3150
3150
DeclAttribute::isDeclModifier (DK));
3151
3151
return makeParserSuccess ();
@@ -3186,7 +3186,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3186
3186
case DAK_CDecl:
3187
3187
case DAK_Expose:
3188
3188
case DAK_SILGenName: {
3189
- if (!consumeIf (tok::l_paren )) {
3189
+ if (!consumeIfAttributeLParen ( )) {
3190
3190
diagnose (Loc, diag::attr_expected_lparen, AttrName,
3191
3191
DeclAttribute::isDeclModifier (DK));
3192
3192
return makeParserSuccess ();
@@ -3293,7 +3293,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3293
3293
}
3294
3294
3295
3295
case DAK_Section: {
3296
- if (!consumeIf (tok::l_paren )) {
3296
+ if (!consumeIfAttributeLParen ( )) {
3297
3297
diagnose (Loc, diag::attr_expected_lparen, AttrName,
3298
3298
DeclAttribute::isDeclModifier (DK));
3299
3299
return makeParserSuccess ();
@@ -3333,12 +3333,12 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3333
3333
}
3334
3334
3335
3335
case DAK_Alignment: {
3336
- if (!consumeIf (tok::l_paren )) {
3336
+ if (!consumeIfAttributeLParen ( )) {
3337
3337
diagnose (Loc, diag::attr_expected_lparen, AttrName,
3338
3338
DeclAttribute::isDeclModifier (DK));
3339
3339
return makeParserSuccess ();
3340
3340
}
3341
-
3341
+
3342
3342
if (Tok.isNot (tok::integer_literal)) {
3343
3343
diagnose (Loc, diag::alignment_must_be_positive_integer);
3344
3344
return makeParserSuccess ();
@@ -3380,7 +3380,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3380
3380
}
3381
3381
3382
3382
case DAK_Semantics: {
3383
- if (!consumeIf (tok::l_paren )) {
3383
+ if (!consumeIfAttributeLParen ( )) {
3384
3384
diagnose (Loc, diag::attr_expected_lparen, AttrName,
3385
3385
DeclAttribute::isDeclModifier (DK));
3386
3386
return makeParserSuccess ();
@@ -3415,7 +3415,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3415
3415
}
3416
3416
case DAK_OriginallyDefinedIn: {
3417
3417
auto LeftLoc = Tok.getLoc ();
3418
- if (!consumeIf (tok::l_paren )) {
3418
+ if (!consumeIfAttributeLParen ( )) {
3419
3419
diagnose (Loc, diag::attr_expected_lparen, AttrName,
3420
3420
DeclAttribute::isDeclModifier (DK));
3421
3421
return makeParserSuccess ();
@@ -3505,7 +3505,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3505
3505
break ;
3506
3506
}
3507
3507
case DAK_Available: {
3508
- if (!consumeIf (tok::l_paren )) {
3508
+ if (!consumeIfAttributeLParen ( )) {
3509
3509
diagnose (Loc, diag::attr_expected_lparen, AttrName,
3510
3510
DeclAttribute::isDeclModifier (DK));
3511
3511
return makeParserSuccess ();
@@ -3523,7 +3523,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3523
3523
DeclAttribute::isDeclModifier (DK));
3524
3524
return makeParserSuccess ();
3525
3525
}
3526
- SourceLoc LParenLoc = consumeToken (tok::l_paren );
3526
+ SourceLoc LParenLoc = consumeAttributeLParen ( );
3527
3527
llvm::Optional<StringRef> filename;
3528
3528
{
3529
3529
// Parse 'sourceFile'.
@@ -3574,7 +3574,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3574
3574
}
3575
3575
3576
3576
// Parse the leading '('.
3577
- SourceLoc LParenLoc = consumeToken (tok::l_paren );
3577
+ SourceLoc LParenLoc = consumeAttributeLParen ( );
3578
3578
3579
3579
// Parse the names, with trailing colons (if there are present) and populate
3580
3580
// the inout parameters
@@ -3640,7 +3640,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3640
3640
return makeParserSuccess ();
3641
3641
}
3642
3642
3643
- SourceLoc LParenLoc = consumeToken (tok::l_paren );
3643
+ SourceLoc LParenLoc = consumeAttributeLParen ( );
3644
3644
DeclNameRef replacedFunction;
3645
3645
{
3646
3646
// Parse 'for'.
@@ -3691,7 +3691,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3691
3691
return makeParserSuccess ();
3692
3692
}
3693
3693
3694
- SourceLoc LParenLoc = consumeToken (tok::l_paren );
3694
+ SourceLoc LParenLoc = consumeAttributeLParen ( );
3695
3695
ParserResult<TypeRepr> ErasedType;
3696
3696
bool invalid = false ;
3697
3697
{
@@ -3792,7 +3792,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3792
3792
3793
3793
case DAK_UnavailableFromAsync: {
3794
3794
StringRef message;
3795
- if (consumeIf (tok::l_paren )) {
3795
+ if (consumeIfAttributeLParen ( )) {
3796
3796
if (!Tok.is (tok::identifier)) {
3797
3797
llvm_unreachable (" Flag must start with an identifier" );
3798
3798
}
@@ -3882,7 +3882,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3882
3882
return makeParserSuccess ();
3883
3883
}
3884
3884
3885
- consumeToken (tok::l_paren );
3885
+ consumeAttributeLParen ( );
3886
3886
3887
3887
if (!Tok.canBeArgumentLabel ()) {
3888
3888
diagnose (Loc, diag::attr_rawlayout_expected_label, " 'size', 'like', or 'likeArrayOf'" );
@@ -4160,6 +4160,10 @@ ParserResult<CustomAttr> Parser::parseCustomAttribute(
4160
4160
4161
4161
initParser.emplace (*this , initContext);
4162
4162
}
4163
+ if (getEndOfPreviousLoc () != Tok.getLoc ()) {
4164
+ diagnose (getEndOfPreviousLoc (), diag::attr_extra_whitespace_before_lparen)
4165
+ .warnUntilSwiftVersion (6 );
4166
+ }
4163
4167
auto result = parseArgumentList (tok::l_paren, tok::r_paren,
4164
4168
/* isExprBasic*/ true ,
4165
4169
/* allowTrailingClosure*/ false );
@@ -4427,10 +4431,11 @@ static bool parseDifferentiableTypeAttributeArgument(
4427
4431
SourceLoc &diffKindLocResult, bool emitDiagnostics) {
4428
4432
Parser::CancellableBacktrackingScope backtrack (P);
4429
4433
4430
- SourceLoc beginLoc, kindLoc, endLoc;
4434
+ SourceLoc beginLoc = P.Tok .getLoc ();
4435
+ SourceLoc kindLoc, endLoc;
4431
4436
4432
4437
// Match '( <identifier> )', and store the identifier token to `argument`.
4433
- if (!P.consumeIf (tok::l_paren, beginLoc ))
4438
+ if (!P.consumeIfAttributeLParen ( ))
4434
4439
return false ;
4435
4440
auto argument = P.Tok ;
4436
4441
if (!P.consumeIf (tok::identifier, kindLoc))
@@ -4498,7 +4503,7 @@ bool Parser::parseConventionAttributeInternal(SourceLoc atLoc, SourceLoc attrLoc
4498
4503
ConventionTypeAttr *&result,
4499
4504
bool justChecking) {
4500
4505
SourceLoc LPLoc = Tok.getLoc ();
4501
- if (!consumeIfNotAtStartOfLine (tok::l_paren )) {
4506
+ if (!consumeIfAttributeLParen ( )) {
4502
4507
if (!justChecking)
4503
4508
diagnose (Tok, diag::convention_attribute_expected_lparen);
4504
4509
return true ;
@@ -4764,7 +4769,7 @@ ParserStatus Parser::parseTypeAttribute(TypeOrCustomAttr &result,
4764
4769
case TAK_opened: {
4765
4770
// Parse the opened existential ID string in parens
4766
4771
SourceLoc beginLoc = Tok.getLoc (), idLoc, endLoc;
4767
- if (!consumeIfNotAtStartOfLine (tok::l_paren )) {
4772
+ if (!consumeAttributeLParen ( )) {
4768
4773
if (!justChecking)
4769
4774
diagnose (Tok, diag::opened_attribute_expected_lparen);
4770
4775
return makeParserError ();
@@ -4817,7 +4822,7 @@ ParserStatus Parser::parseTypeAttribute(TypeOrCustomAttr &result,
4817
4822
4818
4823
// Parse the opened ID string in parens
4819
4824
SourceLoc beginLoc = Tok.getLoc (), idLoc, endLoc;
4820
- if (!consumeIfNotAtStartOfLine (tok::l_paren )) {
4825
+ if (!consumeIfAttributeLParen ( )) {
4821
4826
if (!justChecking)
4822
4827
diagnose (Tok, diag::pack_element_attribute_expected_lparen);
4823
4828
return makeParserError ();
@@ -4892,12 +4897,12 @@ ParserStatus Parser::parseTypeAttribute(TypeOrCustomAttr &result,
4892
4897
case TAK__opaqueReturnTypeOf: {
4893
4898
// Parse the mangled decl name and index.
4894
4899
auto beginLoc = Tok.getLoc ();
4895
- if (!consumeIfNotAtStartOfLine (tok::l_paren )) {
4900
+ if (!consumeIfAttributeLParen ( )) {
4896
4901
if (!justChecking)
4897
4902
diagnose (Tok, diag::attr_expected_lparen, " _opaqueReturnTypeOf" , false );
4898
4903
return makeParserError ();
4899
4904
}
4900
-
4905
+
4901
4906
if (!Tok.is (tok::string_literal)) {
4902
4907
if (!justChecking)
4903
4908
diagnose (Tok, diag::opened_attribute_id_value);
0 commit comments