@@ -4425,10 +4425,18 @@ ParserStatus Parser::parseDeclItem(bool &PreviousHadSemi,
4425
4425
return Result;
4426
4426
}
4427
4427
4428
- bool Parser::parseMemberDeclList (SourceLoc LBLoc, SourceLoc &RBLoc,
4429
- SourceLoc PosBeforeLB,
4430
- Diag<> ErrorDiag,
4428
+ bool Parser::parseMemberDeclList (SourceLoc &LBLoc, SourceLoc &RBLoc,
4429
+ Diag<> LBraceDiag, Diag<> RBraceDiag,
4431
4430
IterableDeclContext *IDC) {
4431
+ if (parseToken (tok::l_brace, LBLoc, LBraceDiag)) {
4432
+ LBLoc = RBLoc = PreviousLoc;
4433
+
4434
+ // Cache the empty result to prevent delayed parsing.
4435
+ Context.evaluator .cacheOutput (
4436
+ ParseMembersRequest{IDC}, FingerprintAndMembers{None, {}});
4437
+ return true ;
4438
+ }
4439
+
4432
4440
bool HasOperatorDeclarations;
4433
4441
bool HasNestedClassDeclarations;
4434
4442
@@ -4447,7 +4455,7 @@ bool Parser::parseMemberDeclList(SourceLoc LBLoc, SourceLoc &RBLoc,
4447
4455
bool hadError = false ;
4448
4456
ParseDeclOptions Options = getMemberParseDeclOptions (IDC);
4449
4457
auto membersAndHash =
4450
- parseDeclList (LBLoc, RBLoc, ErrorDiag , Options, IDC, hadError);
4458
+ parseDeclList (LBLoc, RBLoc, RBraceDiag , Options, IDC, hadError);
4451
4459
IDC->setMaybeHasOperatorDeclarations ();
4452
4460
IDC->setMaybeHasNestedClassDeclarations ();
4453
4461
Context.evaluator .cacheOutput (
@@ -4617,16 +4625,12 @@ Parser::parseDeclExtension(ParseDeclOptions Flags, DeclAttributes &Attributes) {
4617
4625
SyntaxParsingContext BlockContext (SyntaxContext, SyntaxKind::MemberDeclBlock);
4618
4626
SourceLoc LBLoc, RBLoc;
4619
4627
4620
- auto PosBeforeLB = Tok.getLoc ();
4621
- if (parseToken (tok::l_brace, LBLoc, diag::expected_lbrace_extension)) {
4622
- LBLoc = PreviousLoc;
4623
- RBLoc = LBLoc;
4624
- status.setIsParseError ();
4625
- } else {
4628
+ {
4626
4629
ContextChange CC (*this , ext);
4627
4630
Scope S (this , ScopeKind::Extension);
4628
4631
4629
- if (parseMemberDeclList (LBLoc, RBLoc, PosBeforeLB,
4632
+ if (parseMemberDeclList (LBLoc, RBLoc,
4633
+ diag::expected_lbrace_extension,
4630
4634
diag::expected_rbrace_extension,
4631
4635
ext))
4632
4636
status.setIsParseError ();
@@ -6578,15 +6582,11 @@ ParserResult<EnumDecl> Parser::parseDeclEnum(ParseDeclOptions Flags,
6578
6582
6579
6583
SyntaxParsingContext BlockContext (SyntaxContext, SyntaxKind::MemberDeclBlock);
6580
6584
SourceLoc LBLoc, RBLoc;
6581
- SourceLoc PosBeforeLB = Tok.getLoc ();
6582
- if (parseToken (tok::l_brace, LBLoc, diag::expected_lbrace_enum)) {
6583
- LBLoc = PreviousLoc;
6584
- RBLoc = LBLoc;
6585
- Status.setIsParseError ();
6586
- } else {
6585
+ {
6587
6586
Scope S (this , ScopeKind::EnumBody);
6588
6587
6589
- if (parseMemberDeclList (LBLoc, RBLoc, PosBeforeLB,
6588
+ if (parseMemberDeclList (LBLoc, RBLoc,
6589
+ diag::expected_lbrace_enum,
6590
6590
diag::expected_rbrace_enum,
6591
6591
ED))
6592
6592
Status.setIsParseError ();
@@ -6864,16 +6864,12 @@ ParserResult<StructDecl> Parser::parseDeclStruct(ParseDeclOptions Flags,
6864
6864
// Make the entities of the struct as a code block.
6865
6865
SyntaxParsingContext BlockContext (SyntaxContext, SyntaxKind::MemberDeclBlock);
6866
6866
SourceLoc LBLoc, RBLoc;
6867
- SourceLoc PosBeforeLB = Tok.getLoc ();
6868
- if (parseToken (tok::l_brace, LBLoc, diag::expected_lbrace_struct)) {
6869
- LBLoc = PreviousLoc;
6870
- RBLoc = LBLoc;
6871
- Status.setIsParseError ();
6872
- } else {
6867
+ {
6873
6868
// Parse the body.
6874
6869
Scope S (this , ScopeKind::StructBody);
6875
6870
6876
- if (parseMemberDeclList (LBLoc, RBLoc, PosBeforeLB,
6871
+ if (parseMemberDeclList (LBLoc, RBLoc,
6872
+ diag::expected_lbrace_struct,
6877
6873
diag::expected_rbrace_struct,
6878
6874
SD))
6879
6875
Status.setIsParseError ();
@@ -6980,16 +6976,12 @@ ParserResult<ClassDecl> Parser::parseDeclClass(ParseDeclOptions Flags,
6980
6976
6981
6977
SyntaxParsingContext BlockContext (SyntaxContext, SyntaxKind::MemberDeclBlock);
6982
6978
SourceLoc LBLoc, RBLoc;
6983
- auto PosBeforeLB = Tok.getLoc ();
6984
- if (parseToken (tok::l_brace, LBLoc, diag::expected_lbrace_class)) {
6985
- LBLoc = PreviousLoc;
6986
- RBLoc = LBLoc;
6987
- Status.setIsParseError ();
6988
- } else {
6979
+ {
6989
6980
// Parse the body.
6990
6981
Scope S (this , ScopeKind::ClassBody);
6991
6982
6992
- if (parseMemberDeclList (LBLoc, RBLoc, PosBeforeLB,
6983
+ if (parseMemberDeclList (LBLoc, RBLoc,
6984
+ diag::expected_lbrace_class,
6993
6985
diag::expected_rbrace_class,
6994
6986
CD))
6995
6987
Status.setIsParseError ();
@@ -7081,14 +7073,10 @@ parseDeclProtocol(ParseDeclOptions Flags, DeclAttributes &Attributes) {
7081
7073
SyntaxParsingContext BlockContext (SyntaxContext, SyntaxKind::MemberDeclBlock);
7082
7074
SourceLoc LBraceLoc;
7083
7075
SourceLoc RBraceLoc;
7084
- SourceLoc PosBeforeLB = Tok.getLoc ();
7085
- if (parseToken (tok::l_brace, LBraceLoc, diag::expected_lbrace_protocol)) {
7086
- LBraceLoc = PreviousLoc;
7087
- RBraceLoc = LBraceLoc;
7088
- Status.setIsParseError ();
7089
- } else {
7076
+ {
7090
7077
// Parse the members.
7091
- if (parseMemberDeclList (LBraceLoc, RBraceLoc, PosBeforeLB,
7078
+ if (parseMemberDeclList (LBraceLoc, RBraceLoc,
7079
+ diag::expected_lbrace_protocol,
7092
7080
diag::expected_rbrace_protocol,
7093
7081
Proto))
7094
7082
Status.setIsParseError ();
0 commit comments