@@ -3528,6 +3528,23 @@ bool Parser::canDelayMemberDeclParsing() {
3528
3528
return !BackTrack.willBacktrack ();
3529
3529
}
3530
3530
3531
+ bool Parser::delayParsingDeclList (SourceLoc LBLoc, SourceLoc &RBLoc,
3532
+ SourceLoc PosBeforeLB,
3533
+ ParseDeclOptions Options,
3534
+ IterableDeclContext *IDC) {
3535
+ bool error = false ;
3536
+
3537
+ if (Tok.is (tok::r_brace)) {
3538
+ RBLoc = consumeToken ();
3539
+ } else {
3540
+ RBLoc = Tok.getLoc ();
3541
+ error = true ;
3542
+ }
3543
+ State->delayDeclList (IDC, Options.toRaw (), CurDeclContext, { LBLoc, RBLoc },
3544
+ PosBeforeLB);
3545
+ return error;
3546
+ }
3547
+
3531
3548
// / Parse an 'extension' declaration.
3532
3549
// /
3533
3550
// / \verbatim
@@ -3592,14 +3609,8 @@ Parser::parseDeclExtension(ParseDeclOptions Flags, DeclAttributes &Attributes) {
3592
3609
Scope S (this , ScopeKind::Extension);
3593
3610
ParseDeclOptions Options (PD_HasContainerType | PD_InExtension);
3594
3611
if (canDelayMemberDeclParsing ()) {
3595
- if (Tok.is (tok::r_brace)) {
3596
- RBLoc = consumeToken ();
3597
- } else {
3598
- RBLoc = Tok.getLoc ();
3612
+ if (delayParsingDeclList (LBLoc, RBLoc, PosBeforeLB, Options, ext))
3599
3613
status.setIsParseError ();
3600
- }
3601
- State->delayDeclList (ext, Options.toRaw (), CurDeclContext, { LBLoc, RBLoc },
3602
- PosBeforeLB);
3603
3614
} else {
3604
3615
if (parseDeclList (LBLoc, RBLoc, diag::expected_rbrace_extension,
3605
3616
Options, ext))
@@ -5732,14 +5743,8 @@ ParserResult<EnumDecl> Parser::parseDeclEnum(ParseDeclOptions Flags,
5732
5743
Scope S (this , ScopeKind::ClassBody);
5733
5744
ParseDeclOptions Options (PD_HasContainerType | PD_AllowEnumElement | PD_InEnum);
5734
5745
if (canDelayMemberDeclParsing ()) {
5735
- if (Tok.is (tok::r_brace)) {
5736
- RBLoc = consumeToken ();
5737
- } else {
5738
- RBLoc = Tok.getLoc ();
5746
+ if (delayParsingDeclList (LBLoc, RBLoc, PosBeforeLB, Options, ED))
5739
5747
Status.setIsParseError ();
5740
- }
5741
- State->delayDeclList (ED, Options.toRaw (), CurDeclContext, { LBLoc, RBLoc },
5742
- PosBeforeLB);
5743
5748
} else {
5744
5749
if (parseDeclList (LBLoc, RBLoc, diag::expected_rbrace_enum,
5745
5750
Options, ED))
@@ -6017,14 +6022,8 @@ ParserResult<StructDecl> Parser::parseDeclStruct(ParseDeclOptions Flags,
6017
6022
Scope S (this , ScopeKind::StructBody);
6018
6023
ParseDeclOptions Options (PD_HasContainerType | PD_InStruct);
6019
6024
if (canDelayMemberDeclParsing ()) {
6020
- if (Tok.is (tok::r_brace)) {
6021
- RBLoc = consumeToken ();
6022
- } else {
6023
- RBLoc = Tok.getLoc ();
6025
+ if (delayParsingDeclList (LBLoc, RBLoc, PosBeforeLB, Options, SD))
6024
6026
Status.setIsParseError ();
6025
- }
6026
- State->delayDeclList (SD, Options.toRaw (), CurDeclContext, { LBLoc, RBLoc },
6027
- PosBeforeLB);
6028
6027
} else {
6029
6028
if (parseDeclList (LBLoc, RBLoc, diag::expected_rbrace_struct,
6030
6029
Options,SD))
@@ -6141,14 +6140,8 @@ ParserResult<ClassDecl> Parser::parseDeclClass(ParseDeclOptions Flags,
6141
6140
ParseDeclOptions Options (PD_HasContainerType | PD_AllowDestructor |
6142
6141
PD_InClass);
6143
6142
if (canDelayMemberDeclParsing ()) {
6144
- if (Tok.is (tok::r_brace)) {
6145
- RBLoc = consumeToken ();
6146
- } else {
6147
- RBLoc = Tok.getLoc ();
6143
+ if (delayParsingDeclList (LBLoc, RBLoc, PosBeforeLB, Options, CD))
6148
6144
Status.setIsParseError ();
6149
- }
6150
- State->delayDeclList (CD, Options.toRaw (), CurDeclContext, { LBLoc, RBLoc },
6151
- PosBeforeLB);
6152
6145
} else {
6153
6146
if (parseDeclList (LBLoc, RBLoc, diag::expected_rbrace_class,
6154
6147
Options, CD))
@@ -6246,15 +6239,8 @@ parseDeclProtocol(ParseDeclOptions Flags, DeclAttributes &Attributes) {
6246
6239
PD_DisallowInit |
6247
6240
PD_InProtocol);
6248
6241
if (canDelayMemberDeclParsing ()) {
6249
- if (Tok.is (tok::r_brace)) {
6250
- RBraceLoc = consumeToken ();
6251
- } else {
6252
- RBraceLoc = Tok.getLoc ();
6242
+ if (delayParsingDeclList (LBraceLoc, RBraceLoc, PosBeforeLB, Options, Proto))
6253
6243
Status.setIsParseError ();
6254
- }
6255
- State->delayDeclList (Proto, Options.toRaw (), CurDeclContext,
6256
- { LBraceLoc, RBraceLoc },
6257
- PosBeforeLB);
6258
6244
} else {
6259
6245
if (parseDeclList (LBraceLoc, RBraceLoc, diag::expected_rbrace_protocol,
6260
6246
Options, Proto))
0 commit comments