@@ -512,6 +512,11 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
512
512
// Ok, it is a valid attribute, eat it, and then process it.
513
513
StringRef AttrName = Tok.getText ();
514
514
SourceLoc Loc = consumeToken ();
515
+
516
+ // We can only make this attribute a token list intead of an Attribute node
517
+ // because the attribute node may include '@'
518
+ SyntaxParsingContext TokListContext (SyntaxContext, SyntaxKind::TokenList);
519
+
515
520
bool DiscardAttribute = false ;
516
521
517
522
// Diagnose duplicated attributes.
@@ -1853,17 +1858,21 @@ bool Parser::parseTypeAttribute(TypeAttributes &Attributes, bool justChecking) {
1853
1858
bool Parser::parseDeclAttributeList (DeclAttributes &Attributes,
1854
1859
bool &FoundCCToken) {
1855
1860
FoundCCToken = false ;
1856
- while (Tok.is (tok::at_sign)) {
1861
+ if (Tok.isNot (tok::at_sign))
1862
+ return false ;
1863
+ SyntaxParsingContext AttrListCtx (SyntaxContext, SyntaxKind::AttributeList);
1864
+ do {
1857
1865
if (peekToken ().is (tok::code_complete)) {
1858
1866
consumeToken (tok::at_sign);
1859
1867
consumeToken (tok::code_complete);
1860
1868
FoundCCToken = true ;
1861
1869
continue ;
1862
1870
}
1871
+ SyntaxParsingContext AttrCtx (SyntaxContext, SyntaxKind::Attribute);
1863
1872
SourceLoc AtLoc = consumeToken ();
1864
1873
if (parseDeclAttribute (Attributes, AtLoc))
1865
1874
return true ;
1866
- }
1875
+ } while (Tok. is (tok::at_sign));
1867
1876
return false ;
1868
1877
}
1869
1878
@@ -2263,7 +2272,7 @@ Parser::parseDecl(ParseDeclOptions Flags,
2263
2272
2264
2273
switch (Tok.getKind ()) {
2265
2274
// Modifiers
2266
- case tok::kw_static:
2275
+ case tok::kw_static: {
2267
2276
if (StaticLoc.isValid ()) {
2268
2277
diagnose (Tok, diag::decl_already_static,
2269
2278
StaticSpellingKind::KeywordStatic)
@@ -2275,7 +2284,7 @@ Parser::parseDecl(ParseDeclOptions Flags,
2275
2284
}
2276
2285
consumeToken (tok::kw_static);
2277
2286
continue ;
2278
-
2287
+ }
2279
2288
// 'class' is a modifier on func, but is also a top-level decl.
2280
2289
case tok::kw_class: {
2281
2290
SourceLoc ClassLoc = consumeToken (tok::kw_class);
@@ -2302,84 +2311,58 @@ Parser::parseDecl(ParseDeclOptions Flags,
2302
2311
case tok::kw_private:
2303
2312
case tok::kw_fileprivate:
2304
2313
case tok::kw_internal:
2305
- case tok::kw_public:
2314
+ case tok::kw_public: {
2306
2315
// We still model these specifiers as attributes.
2307
2316
parseNewDeclAttribute (Attributes, /* AtLoc=*/ {}, DAK_AccessControl);
2308
2317
continue ;
2309
-
2318
+ }
2310
2319
// Context sensitive keywords.
2311
- case tok::identifier:
2320
+ case tok::identifier: {
2321
+ Optional<DeclAttrKind> Kind;
2312
2322
// FIXME: This is ridiculous, this all needs to be sucked into the
2313
2323
// declparsing goop.
2314
2324
if (Tok.isContextualKeyword (" open" )) {
2315
- parseNewDeclAttribute (Attributes, /* AtLoc=*/ {}, DAK_AccessControl);
2316
- continue ;
2317
- }
2318
- if (Tok.isContextualKeyword (" weak" ) ||
2319
- Tok.isContextualKeyword (" unowned" )) {
2320
- parseNewDeclAttribute (Attributes, /* AtLoc=*/ {}, DAK_Ownership);
2321
- continue ;
2322
- }
2323
- if (Tok.isContextualKeyword (" optional" )) {
2324
- parseNewDeclAttribute (Attributes, /* AtLoc=*/ {}, DAK_Optional);
2325
- continue ;
2326
- }
2327
- if (Tok.isContextualKeyword (" required" )) {
2328
- parseNewDeclAttribute (Attributes, /* AtLoc=*/ {}, DAK_Required);
2329
- continue ;
2330
- }
2331
- if (Tok.isContextualKeyword (" lazy" )) {
2332
- parseNewDeclAttribute (Attributes, /* AtLoc=*/ {}, DAK_Lazy);
2333
- continue ;
2334
- }
2335
- if (Tok.isContextualKeyword (" final" )) {
2336
- parseNewDeclAttribute (Attributes, /* AtLoc=*/ {}, DAK_Final);
2337
- continue ;
2338
- }
2339
- if (Tok.isContextualKeyword (" dynamic" )) {
2340
- parseNewDeclAttribute (Attributes, /* AtLoc*/ {}, DAK_Dynamic);
2341
- continue ;
2342
- }
2343
- if (Tok.isContextualKeyword (" prefix" )) {
2344
- parseNewDeclAttribute (Attributes, /* AtLoc*/ {}, DAK_Prefix);
2345
- continue ;
2346
- }
2347
- if (Tok.isContextualKeyword (" postfix" )) {
2348
- parseNewDeclAttribute (Attributes, /* AtLoc*/ {}, DAK_Postfix);
2349
- continue ;
2350
- }
2351
- if (Tok.isContextualKeyword (" indirect" )) {
2352
- parseNewDeclAttribute (Attributes, /* AtLoc*/ {}, DAK_Indirect);
2353
- continue ;
2354
- }
2355
- if (Tok.isContextualKeyword (" infix" )) {
2356
- parseNewDeclAttribute (Attributes, /* AtLoc*/ {}, DAK_Infix);
2357
- continue ;
2358
- }
2359
- if (Tok.isContextualKeyword (" override" )) {
2360
- parseNewDeclAttribute (Attributes, /* AtLoc*/ {}, DAK_Override);
2361
- continue ;
2362
- }
2363
- if (Tok.isContextualKeyword (" mutating" )) {
2364
- parseNewDeclAttribute (Attributes, /* AtLoc*/ {}, DAK_Mutating);
2365
- continue ;
2366
- }
2367
- if (Tok.isContextualKeyword (" nonmutating" )) {
2368
- parseNewDeclAttribute (Attributes, /* AtLoc*/ {}, DAK_NonMutating);
2369
- continue ;
2370
- }
2371
- if (Tok.isContextualKeyword (" __consuming" )) {
2372
- parseNewDeclAttribute (Attributes, /* AtLoc*/ {}, DAK_Consuming);
2373
- continue ;
2325
+ Kind = DAK_AccessControl;
2326
+ } else if (Tok.isContextualKeyword (" weak" ) ||
2327
+ Tok.isContextualKeyword (" unowned" )) {
2328
+ Kind = DAK_Ownership;
2329
+ } else if (Tok.isContextualKeyword (" optional" )) {
2330
+ Kind = DAK_Optional;
2331
+ } else if (Tok.isContextualKeyword (" required" )) {
2332
+ Kind = DAK_Required;
2333
+ } else if (Tok.isContextualKeyword (" lazy" )) {
2334
+ Kind = DAK_Lazy;
2335
+ } else if (Tok.isContextualKeyword (" final" )) {
2336
+ Kind = DAK_Final;
2337
+ } else if (Tok.isContextualKeyword (" dynamic" )) {
2338
+ Kind = DAK_Dynamic;
2339
+ } else if (Tok.isContextualKeyword (" prefix" )) {
2340
+ Kind = DAK_Prefix;
2341
+ } else if (Tok.isContextualKeyword (" postfix" )) {
2342
+ Kind = DAK_Postfix;
2343
+ } else if (Tok.isContextualKeyword (" indirect" )) {
2344
+ Kind = DAK_Indirect;
2345
+ } else if (Tok.isContextualKeyword (" infix" )) {
2346
+ Kind = DAK_Infix;
2347
+ } else if (Tok.isContextualKeyword (" override" )) {
2348
+ Kind = DAK_Override;
2349
+ } else if (Tok.isContextualKeyword (" mutating" )) {
2350
+ Kind = DAK_Mutating;
2351
+ } else if (Tok.isContextualKeyword (" nonmutating" )) {
2352
+ Kind = DAK_NonMutating;
2353
+ } else if (Tok.isContextualKeyword (" __consuming" )) {
2354
+ Kind = DAK_Consuming;
2355
+ } else if (Tok.isContextualKeyword (" convenience" )) {
2356
+ Kind = DAK_Convenience;
2374
2357
}
2375
- if (Tok. isContextualKeyword ( " convenience " ) ) {
2376
- parseNewDeclAttribute (Attributes, /* AtLoc */ {}, DAK_Convenience );
2358
+ if (Kind ) {
2359
+ parseNewDeclAttribute (Attributes, SourceLoc (), *Kind );
2377
2360
continue ;
2378
2361
}
2379
2362
2380
2363
// Otherwise this is not a context-sensitive keyword.
2381
2364
LLVM_FALLTHROUGH;
2382
-
2365
+ }
2383
2366
case tok::pound_if:
2384
2367
case tok::pound_sourceLocation:
2385
2368
case tok::pound_line:
0 commit comments