@@ -1093,7 +1093,14 @@ 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;
1097
+ if (Tok.is (tok::l_paren)) {
1098
+ lParenLoc = consumeAttributeLParen ();
1099
+ } else {
1100
+ // SIL parsing is positioned at _specialize when entering this and parses
1101
+ // the location of the _specialize keyword as the lParenLoc.
1102
+ lParenLoc = consumeToken ();
1103
+ }
1097
1104
bool DiscardAttribute = false ;
1098
1105
StringRef AttrName = " _specialize" ;
1099
1106
@@ -1157,7 +1164,7 @@ Parser::parseStorageRestrictionsAttribute(SourceLoc AtLoc, SourceLoc Loc) {
1157
1164
}
1158
1165
1159
1166
// Consume '('
1160
- SourceLoc lParenLoc = consumeToken ();
1167
+ SourceLoc lParenLoc = consumeAttributeLParen ();
1161
1168
1162
1169
SmallVector<Identifier> initializesProperties;
1163
1170
SmallVector<Identifier> accessesProperties;
@@ -1319,7 +1326,7 @@ Parser::parseImplementsAttribute(SourceLoc AtLoc, SourceLoc Loc) {
1319
1326
return Status;
1320
1327
}
1321
1328
1322
- SourceLoc lParenLoc = consumeToken ();
1329
+ SourceLoc lParenLoc = consumeAttributeLParen ();
1323
1330
1324
1331
DeclNameLoc MemberNameLoc;
1325
1332
DeclNameRef MemberName;
@@ -1379,13 +1386,13 @@ Parser::parseImplementsAttribute(SourceLoc AtLoc, SourceLoc Loc) {
1379
1386
ParserResult<DifferentiableAttr>
1380
1387
Parser::parseDifferentiableAttribute (SourceLoc atLoc, SourceLoc loc) {
1381
1388
StringRef AttrName = " differentiable" ;
1382
- SourceLoc lParenLoc = loc, rParenLoc = loc;
1389
+ SourceLoc rParenLoc = loc;
1383
1390
DifferentiabilityKind diffKind = DifferentiabilityKind::Normal;
1384
1391
SmallVector<ParsedAutoDiffParameter, 8 > parameters;
1385
1392
TrailingWhereClause *whereClause = nullptr ;
1386
1393
1387
1394
// Parse '('.
1388
- if (consumeIf (tok::l_paren, lParenLoc )) {
1395
+ if (consumeIfAttributeLParen ( )) {
1389
1396
// Parse @differentiable attribute arguments.
1390
1397
if (parseDifferentiableAttributeArguments (
1391
1398
diffKind, parameters, whereClause))
@@ -1415,7 +1422,7 @@ bool Parser::parseExternAttribute(DeclAttributes &Attributes,
1415
1422
SourceLoc lParenLoc = Tok.getLoc (), rParenLoc;
1416
1423
1417
1424
// Parse @_extern(<language>, ...)
1418
- if (!consumeIf (tok::l_paren )) {
1425
+ if (!consumeIfAttributeLParen ( )) {
1419
1426
diagnose (Loc, diag::attr_expected_lparen, AttrName,
1420
1427
DeclAttribute::isDeclModifier (DAK_Extern));
1421
1428
return false ;
@@ -1857,7 +1864,7 @@ static bool parseQualifiedDeclName(Parser &P, Diag<> nameParseError,
1857
1864
ParserResult<DerivativeAttr> Parser::parseDerivativeAttribute (SourceLoc atLoc,
1858
1865
SourceLoc loc) {
1859
1866
StringRef AttrName = " derivative" ;
1860
- SourceLoc lParenLoc = loc, rParenLoc = loc;
1867
+ SourceLoc rParenLoc = loc;
1861
1868
TypeRepr *baseType = nullptr ;
1862
1869
DeclNameRefWithLoc original;
1863
1870
SmallVector<ParsedAutoDiffParameter, 8 > parameters;
@@ -1885,7 +1892,7 @@ ParserResult<DerivativeAttr> Parser::parseDerivativeAttribute(SourceLoc atLoc,
1885
1892
return errorAndSkipUntilConsumeRightParen (*this , AttrName);
1886
1893
};
1887
1894
// Parse '('.
1888
- if (!consumeIf (tok::l_paren, lParenLoc )) {
1895
+ if (!consumeIfAttributeLParen ( )) {
1889
1896
diagnose (getEndOfPreviousLoc (), diag::attr_expected_lparen, AttrName,
1890
1897
/* DeclModifier*/ false );
1891
1898
return makeParserError ();
@@ -1937,7 +1944,7 @@ ParserResult<DerivativeAttr> Parser::parseDerivativeAttribute(SourceLoc atLoc,
1937
1944
ParserResult<TransposeAttr> Parser::parseTransposeAttribute (SourceLoc atLoc,
1938
1945
SourceLoc loc) {
1939
1946
StringRef AttrName = " transpose" ;
1940
- SourceLoc lParenLoc = loc, rParenLoc = loc;
1947
+ SourceLoc rParenLoc = loc;
1941
1948
TypeRepr *baseType = nullptr ;
1942
1949
DeclNameRefWithLoc original;
1943
1950
SmallVector<ParsedAutoDiffParameter, 8 > parameters;
@@ -1966,7 +1973,7 @@ ParserResult<TransposeAttr> Parser::parseTransposeAttribute(SourceLoc atLoc,
1966
1973
};
1967
1974
1968
1975
// Parse '('.
1969
- if (!consumeIf (tok::l_paren, lParenLoc )) {
1976
+ if (!consumeIfAttributeLParen ( )) {
1970
1977
diagnose (getEndOfPreviousLoc (), diag::attr_expected_lparen, AttrName,
1971
1978
/* DeclModifier*/ false );
1972
1979
return makeParserError ();
@@ -2270,7 +2277,7 @@ bool Parser::parseBackDeployedAttribute(DeclAttributes &Attributes,
2270
2277
SourceLoc Loc) {
2271
2278
std::string AtAttrName = (llvm::Twine (" @" ) + AttrName).str ();
2272
2279
auto LeftLoc = Tok.getLoc ();
2273
- if (!consumeIf (tok::l_paren )) {
2280
+ if (!consumeIfAttributeLParen ( )) {
2274
2281
diagnose (Loc, diag::attr_expected_lparen, AtAttrName,
2275
2282
DeclAttribute::isDeclModifier (DAK_BackDeployed));
2276
2283
return false ;
@@ -2418,7 +2425,7 @@ Parser::parseDocumentationAttribute(SourceLoc AtLoc, SourceLoc Loc) {
2418
2425
llvm::Optional<AccessLevel> Visibility = llvm::None;
2419
2426
llvm::Optional<StringRef> Metadata = llvm::None;
2420
2427
2421
- if (!consumeIf (tok::l_paren )) {
2428
+ if (!consumeIfAttributeLParen ( )) {
2422
2429
diagnose (Loc, diag::attr_expected_lparen, AttrName,
2423
2430
declModifier);
2424
2431
return makeParserError ();
@@ -2503,7 +2510,7 @@ Parser::parseMacroRoleAttribute(
2503
2510
}
2504
2511
2505
2512
// Parse the argments.
2506
- SourceLoc lParenLoc = consumeToken ();
2513
+ SourceLoc lParenLoc = consumeAttributeLParen ();
2507
2514
SourceLoc rParenLoc;
2508
2515
llvm::Optional<MacroRole> role;
2509
2516
bool sawRole = false ;
@@ -2750,7 +2757,7 @@ static llvm::Optional<Identifier> parseSingleAttrOptionImpl(
2750
2757
return llvm::None;
2751
2758
}
2752
2759
2753
- P.consumeToken (tok::l_paren );
2760
+ P.consumeAttributeLParen ( );
2754
2761
2755
2762
StringRef parsedName = P.Tok .getText ();
2756
2763
if (!P.consumeIf (tok::identifier)) {
@@ -2913,7 +2920,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
2913
2920
break ;
2914
2921
2915
2922
case DAK_Effects: {
2916
- if (!consumeIf (tok::l_paren )) {
2923
+ if (!consumeIfAttributeLParen ( )) {
2917
2924
diagnose (Loc, diag::attr_expected_lparen, AttrName,
2918
2925
DeclAttribute::isDeclModifier (DK));
2919
2926
return makeParserSuccess ();
@@ -3093,7 +3100,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3093
3100
break ;
3094
3101
}
3095
3102
3096
- consumeToken (tok::l_paren );
3103
+ consumeAttributeLParen ( );
3097
3104
3098
3105
// Parse the subject.
3099
3106
if (Tok.isContextualKeyword (" set" )) {
@@ -3145,7 +3152,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3145
3152
}
3146
3153
3147
3154
case DAK_SPIAccessControl: {
3148
- if (!consumeIf (tok::l_paren )) {
3155
+ if (!consumeIfAttributeLParen ( )) {
3149
3156
diagnose (Loc, diag::attr_expected_lparen, AttrName,
3150
3157
DeclAttribute::isDeclModifier (DK));
3151
3158
return makeParserSuccess ();
@@ -3186,7 +3193,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3186
3193
case DAK_CDecl:
3187
3194
case DAK_Expose:
3188
3195
case DAK_SILGenName: {
3189
- if (!consumeIf (tok::l_paren )) {
3196
+ if (!consumeIfAttributeLParen ( )) {
3190
3197
diagnose (Loc, diag::attr_expected_lparen, AttrName,
3191
3198
DeclAttribute::isDeclModifier (DK));
3192
3199
return makeParserSuccess ();
@@ -3293,7 +3300,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3293
3300
}
3294
3301
3295
3302
case DAK_Section: {
3296
- if (!consumeIf (tok::l_paren )) {
3303
+ if (!consumeIfAttributeLParen ( )) {
3297
3304
diagnose (Loc, diag::attr_expected_lparen, AttrName,
3298
3305
DeclAttribute::isDeclModifier (DK));
3299
3306
return makeParserSuccess ();
@@ -3333,12 +3340,12 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3333
3340
}
3334
3341
3335
3342
case DAK_Alignment: {
3336
- if (!consumeIf (tok::l_paren )) {
3343
+ if (!consumeIfAttributeLParen ( )) {
3337
3344
diagnose (Loc, diag::attr_expected_lparen, AttrName,
3338
3345
DeclAttribute::isDeclModifier (DK));
3339
3346
return makeParserSuccess ();
3340
3347
}
3341
-
3348
+
3342
3349
if (Tok.isNot (tok::integer_literal)) {
3343
3350
diagnose (Loc, diag::alignment_must_be_positive_integer);
3344
3351
return makeParserSuccess ();
@@ -3380,7 +3387,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3380
3387
}
3381
3388
3382
3389
case DAK_Semantics: {
3383
- if (!consumeIf (tok::l_paren )) {
3390
+ if (!consumeIfAttributeLParen ( )) {
3384
3391
diagnose (Loc, diag::attr_expected_lparen, AttrName,
3385
3392
DeclAttribute::isDeclModifier (DK));
3386
3393
return makeParserSuccess ();
@@ -3415,7 +3422,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3415
3422
}
3416
3423
case DAK_OriginallyDefinedIn: {
3417
3424
auto LeftLoc = Tok.getLoc ();
3418
- if (!consumeIf (tok::l_paren )) {
3425
+ if (!consumeIfAttributeLParen ( )) {
3419
3426
diagnose (Loc, diag::attr_expected_lparen, AttrName,
3420
3427
DeclAttribute::isDeclModifier (DK));
3421
3428
return makeParserSuccess ();
@@ -3505,7 +3512,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3505
3512
break ;
3506
3513
}
3507
3514
case DAK_Available: {
3508
- if (!consumeIf (tok::l_paren )) {
3515
+ if (!consumeIfAttributeLParen ( )) {
3509
3516
diagnose (Loc, diag::attr_expected_lparen, AttrName,
3510
3517
DeclAttribute::isDeclModifier (DK));
3511
3518
return makeParserSuccess ();
@@ -3523,7 +3530,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3523
3530
DeclAttribute::isDeclModifier (DK));
3524
3531
return makeParserSuccess ();
3525
3532
}
3526
- SourceLoc LParenLoc = consumeToken (tok::l_paren );
3533
+ SourceLoc LParenLoc = consumeAttributeLParen ( );
3527
3534
llvm::Optional<StringRef> filename;
3528
3535
{
3529
3536
// Parse 'sourceFile'.
@@ -3574,7 +3581,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3574
3581
}
3575
3582
3576
3583
// Parse the leading '('.
3577
- SourceLoc LParenLoc = consumeToken (tok::l_paren );
3584
+ SourceLoc LParenLoc = consumeAttributeLParen ( );
3578
3585
3579
3586
// Parse the names, with trailing colons (if there are present) and populate
3580
3587
// the inout parameters
@@ -3640,7 +3647,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3640
3647
return makeParserSuccess ();
3641
3648
}
3642
3649
3643
- SourceLoc LParenLoc = consumeToken (tok::l_paren );
3650
+ SourceLoc LParenLoc = consumeAttributeLParen ( );
3644
3651
DeclNameRef replacedFunction;
3645
3652
{
3646
3653
// Parse 'for'.
@@ -3691,7 +3698,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3691
3698
return makeParserSuccess ();
3692
3699
}
3693
3700
3694
- SourceLoc LParenLoc = consumeToken (tok::l_paren );
3701
+ SourceLoc LParenLoc = consumeAttributeLParen ( );
3695
3702
ParserResult<TypeRepr> ErasedType;
3696
3703
bool invalid = false ;
3697
3704
{
@@ -3792,7 +3799,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3792
3799
3793
3800
case DAK_UnavailableFromAsync: {
3794
3801
StringRef message;
3795
- if (consumeIf (tok::l_paren )) {
3802
+ if (consumeIfAttributeLParen ( )) {
3796
3803
if (!Tok.is (tok::identifier)) {
3797
3804
llvm_unreachable (" Flag must start with an identifier" );
3798
3805
}
@@ -3882,7 +3889,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3882
3889
return makeParserSuccess ();
3883
3890
}
3884
3891
3885
- consumeToken (tok::l_paren );
3892
+ consumeAttributeLParen ( );
3886
3893
3887
3894
if (!Tok.canBeArgumentLabel ()) {
3888
3895
diagnose (Loc, diag::attr_rawlayout_expected_label, " 'size', 'like', or 'likeArrayOf'" );
@@ -4160,6 +4167,10 @@ ParserResult<CustomAttr> Parser::parseCustomAttribute(
4160
4167
4161
4168
initParser.emplace (*this , initContext);
4162
4169
}
4170
+ if (getEndOfPreviousLoc () != Tok.getLoc ()) {
4171
+ diagnose (getEndOfPreviousLoc (), diag::attr_extra_whitespace_before_lparen)
4172
+ .warnUntilSwiftVersion (6 );
4173
+ }
4163
4174
auto result = parseArgumentList (tok::l_paren, tok::r_paren,
4164
4175
/* isExprBasic*/ true ,
4165
4176
/* allowTrailingClosure*/ false );
@@ -4427,10 +4438,11 @@ static bool parseDifferentiableTypeAttributeArgument(
4427
4438
SourceLoc &diffKindLocResult, bool emitDiagnostics) {
4428
4439
Parser::CancellableBacktrackingScope backtrack (P);
4429
4440
4430
- SourceLoc beginLoc, kindLoc, endLoc;
4441
+ SourceLoc beginLoc = P.Tok .getLoc ();
4442
+ SourceLoc kindLoc, endLoc;
4431
4443
4432
4444
// Match '( <identifier> )', and store the identifier token to `argument`.
4433
- if (!P.consumeIf (tok::l_paren, beginLoc ))
4445
+ if (!P.consumeIfAttributeLParen ( ))
4434
4446
return false ;
4435
4447
auto argument = P.Tok ;
4436
4448
if (!P.consumeIf (tok::identifier, kindLoc))
@@ -4498,7 +4510,7 @@ bool Parser::parseConventionAttributeInternal(SourceLoc atLoc, SourceLoc attrLoc
4498
4510
ConventionTypeAttr *&result,
4499
4511
bool justChecking) {
4500
4512
SourceLoc LPLoc = Tok.getLoc ();
4501
- if (!consumeIfNotAtStartOfLine (tok::l_paren )) {
4513
+ if (!consumeIfAttributeLParen ( )) {
4502
4514
if (!justChecking)
4503
4515
diagnose (Tok, diag::convention_attribute_expected_lparen);
4504
4516
return true ;
@@ -4764,7 +4776,7 @@ ParserStatus Parser::parseTypeAttribute(TypeOrCustomAttr &result,
4764
4776
case TAK_opened: {
4765
4777
// Parse the opened existential ID string in parens
4766
4778
SourceLoc beginLoc = Tok.getLoc (), idLoc, endLoc;
4767
- if (!consumeIfNotAtStartOfLine (tok::l_paren )) {
4779
+ if (!consumeAttributeLParen ( )) {
4768
4780
if (!justChecking)
4769
4781
diagnose (Tok, diag::opened_attribute_expected_lparen);
4770
4782
return makeParserError ();
@@ -4817,7 +4829,7 @@ ParserStatus Parser::parseTypeAttribute(TypeOrCustomAttr &result,
4817
4829
4818
4830
// Parse the opened ID string in parens
4819
4831
SourceLoc beginLoc = Tok.getLoc (), idLoc, endLoc;
4820
- if (!consumeIfNotAtStartOfLine (tok::l_paren )) {
4832
+ if (!consumeIfAttributeLParen ( )) {
4821
4833
if (!justChecking)
4822
4834
diagnose (Tok, diag::pack_element_attribute_expected_lparen);
4823
4835
return makeParserError ();
@@ -4892,12 +4904,12 @@ ParserStatus Parser::parseTypeAttribute(TypeOrCustomAttr &result,
4892
4904
case TAK__opaqueReturnTypeOf: {
4893
4905
// Parse the mangled decl name and index.
4894
4906
auto beginLoc = Tok.getLoc ();
4895
- if (!consumeIfNotAtStartOfLine (tok::l_paren )) {
4907
+ if (!consumeIfAttributeLParen ( )) {
4896
4908
if (!justChecking)
4897
4909
diagnose (Tok, diag::attr_expected_lparen, " _opaqueReturnTypeOf" , false );
4898
4910
return makeParserError ();
4899
4911
}
4900
-
4912
+
4901
4913
if (!Tok.is (tok::string_literal)) {
4902
4914
if (!justChecking)
4903
4915
diagnose (Tok, diag::opened_attribute_id_value);
0 commit comments