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