@@ -1510,7 +1510,12 @@ void Parser::parseAllAvailabilityMacroArguments() {
1510
1510
AvailabilityMacroMap Map;
1511
1511
1512
1512
SourceManager &SM = Context.SourceMgr ;
1513
- const LangOptions &LangOpts = Context.LangOpts ;
1513
+ LangOptions LangOpts = Context.LangOpts ;
1514
+ // The sub-parser is not actually parsing the source file but the LangOpts
1515
+ // AvailabilityMacros. No point creating a libSyntax tree for it. In fact, the
1516
+ // creation of a libSyntax tree would always fail because the
1517
+ // AvailibilityMacro is not valid Swift source code.
1518
+ LangOpts.BuildSyntaxTree = false ;
1514
1519
1515
1520
for (StringRef macro: LangOpts.AvailabilityMacros ) {
1516
1521
@@ -2145,7 +2150,7 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
2145
2150
bool SuppressLaterDiags = false ;
2146
2151
if (parseList (tok::r_paren, LeftLoc, RightLoc, false ,
2147
2152
diag::originally_defined_in_missing_rparen,
2148
- SyntaxKind::Unknown , [&]() -> ParserStatus {
2153
+ SyntaxKind::AvailabilitySpecList , [&]() -> ParserStatus {
2149
2154
SWIFT_DEFER {
2150
2155
if (NK != NextSegmentKind::PlatformVersion) {
2151
2156
NK = (NextSegmentKind)((uint8_t )NK + (uint8_t )1 );
@@ -2154,6 +2159,8 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
2154
2159
switch (NK) {
2155
2160
// Parse 'module: "original_module_name"'.
2156
2161
case NextSegmentKind::ModuleName: {
2162
+ SyntaxParsingContext argumentContext (SyntaxContext,
2163
+ SyntaxKind::AvailabilityLabeledArgument);
2157
2164
// Parse 'module' ':'.
2158
2165
if (!Tok.is (tok::identifier) || Tok.getText () != " module" ||
2159
2166
!peekToken ().is (tok::colon)) {
@@ -2182,6 +2189,8 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
2182
2189
}
2183
2190
// Parse 'OSX 13.13'.
2184
2191
case NextSegmentKind::PlatformVersion: {
2192
+ SyntaxParsingContext argumentContext (SyntaxContext,
2193
+ SyntaxKind::AvailabilityVersionRestriction);
2185
2194
if ((Tok.is (tok::identifier) || Tok.is (tok::oper_binary_spaced)) &&
2186
2195
(peekToken ().isAny (tok::integer_literal, tok::floating_literal) ||
2187
2196
peekAvailabilityMacroName ())) {
@@ -4421,6 +4430,7 @@ Parser::parseDecl(ParseDeclOptions Flags,
4421
4430
4422
4431
if (shouldParseExperimentalConcurrency () &&
4423
4432
Tok.isContextualKeyword (" actor" ) && peekToken ().is (tok::identifier)) {
4433
+ Tok.setKind (tok::contextual_keyword);
4424
4434
DeclParsingContext.setCreateSyntax (SyntaxKind::ClassDecl);
4425
4435
DeclResult = parseDeclClass (Flags, Attributes);
4426
4436
break ;
@@ -5007,6 +5017,9 @@ ParserStatus Parser::parseDeclItem(bool &PreviousHadSemi,
5007
5017
.fixItInsert (endOfPrevious, " ;" );
5008
5018
}
5009
5019
5020
+ SyntaxParsingContext DeclContext (SyntaxContext,
5021
+ SyntaxKind::MemberDeclListItem);
5022
+
5010
5023
if (Tok.isAny (tok::pound_sourceLocation, tok::pound_line)) {
5011
5024
auto LineDirectiveStatus = parseLineDirective (Tok.is (tok::pound_line));
5012
5025
if (LineDirectiveStatus.isErrorOrHasCompletion ())
@@ -5015,8 +5028,6 @@ ParserStatus Parser::parseDeclItem(bool &PreviousHadSemi,
5015
5028
}
5016
5029
5017
5030
ParserResult<Decl> Result;
5018
- SyntaxParsingContext DeclContext (SyntaxContext,
5019
- SyntaxKind::MemberDeclListItem);
5020
5031
if (loadCurrentSyntaxNodeFromCache ()) {
5021
5032
return ParserStatus ();
5022
5033
}
@@ -7540,7 +7551,6 @@ ParserResult<ClassDecl> Parser::parseDeclClass(ParseDeclOptions Flags,
7540
7551
// part of
7541
7552
SourceLoc ClassLoc;
7542
7553
if (isExplicitActorDecl) {
7543
- assert (Tok.is (tok::identifier) && Tok.isContextualKeyword (" actor" ));
7544
7554
ClassLoc = consumeToken ();
7545
7555
} else {
7546
7556
ClassLoc = consumeToken (tok::kw_class);
0 commit comments