@@ -2800,21 +2800,11 @@ static void diagnoseOperatorFixityAttributes(Parser &P,
2800
2800
static unsigned skipUntilMatchingRBrace (Parser &P,
2801
2801
bool &HasPoundDirective,
2802
2802
bool &HasOperatorDeclarations,
2803
- bool &HasNestedClassDeclarations,
2804
- SyntaxParsingContext *&SyntaxContext) {
2803
+ bool &HasNestedClassDeclarations) {
2805
2804
HasPoundDirective = false ;
2806
2805
HasOperatorDeclarations = false ;
2807
2806
HasNestedClassDeclarations = false ;
2808
2807
2809
- bool isRootCtx = SyntaxContext->isRoot ();
2810
- SyntaxParsingContext BlockItemListContext (SyntaxContext,
2811
- SyntaxKind::CodeBlockItemList);
2812
- if (isRootCtx) {
2813
- BlockItemListContext.setTransparent ();
2814
- }
2815
- SyntaxParsingContext BlockItemContext (SyntaxContext,
2816
- SyntaxKind::CodeBlockItem);
2817
- SyntaxParsingContext BodyContext (SyntaxContext, SyntaxKind::TokenList);
2818
2808
unsigned OpenBraces = 1 ;
2819
2809
2820
2810
bool LastTokenWasFunc = false ;
@@ -3998,8 +3988,7 @@ bool Parser::canDelayMemberDeclParsing(bool &HasOperatorDeclarations,
3998
3988
skipUntilMatchingRBrace (*this ,
3999
3989
HasPoundDirective,
4000
3990
HasOperatorDeclarations,
4001
- HasNestedClassDeclarations,
4002
- SyntaxContext);
3991
+ HasNestedClassDeclarations);
4003
3992
if (!HasPoundDirective)
4004
3993
BackTrack.cancelBacktrack ();
4005
3994
return !BackTrack.willBacktrack ();
@@ -4690,25 +4679,24 @@ static ParameterList *parseOptionalAccessorArgument(SourceLoc SpecifierLoc,
4690
4679
return ParameterList::create (P.Context , StartLoc, param, EndLoc);
4691
4680
}
4692
4681
4693
- static unsigned skipBracedBlock (Parser &P,
4694
- SyntaxParsingContext *& SyntaxContext) {
4695
- SyntaxParsingContext CodeBlockContext ( SyntaxContext, SyntaxKind::CodeBlock );
4696
- P. consumeToken (tok::l_brace);
4682
+ bool Parser:: skipBracedBlock () {
4683
+ SyntaxParsingContext disabled ( SyntaxContext);
4684
+ SyntaxContext-> disable ( );
4685
+ consumeToken (tok::l_brace);
4697
4686
4698
4687
// We don't care if a skipped function body contained any of these, so
4699
4688
// just ignore them.
4700
4689
bool HasPoundDirectives;
4701
4690
bool HasOperatorDeclarations;
4702
4691
bool HasNestedClassDeclarations;
4703
4692
4704
- unsigned OpenBraces = skipUntilMatchingRBrace (P ,
4693
+ unsigned OpenBraces = skipUntilMatchingRBrace (* this ,
4705
4694
HasPoundDirectives,
4706
4695
HasOperatorDeclarations,
4707
- HasNestedClassDeclarations,
4708
- SyntaxContext);
4709
- if (P.consumeIf (tok::r_brace))
4696
+ HasNestedClassDeclarations);
4697
+ if (consumeIf (tok::r_brace))
4710
4698
OpenBraces--;
4711
- return OpenBraces;
4699
+ return OpenBraces != 0 ;
4712
4700
}
4713
4701
4714
4702
// / Returns a descriptive name for the given accessor/addressor kind.
@@ -5578,20 +5566,8 @@ void Parser::consumeAbstractFunctionBody(AbstractFunctionDecl *AFD,
5578
5566
SourceRange BodyRange;
5579
5567
BodyRange.Start = Tok.getLoc ();
5580
5568
5581
- // Consume the '{', and find the matching '}'.
5582
- unsigned OpenBraces = skipBracedBlock (*this , SyntaxContext);
5583
- if (OpenBraces != 0 && Tok.isNot (tok::code_complete)) {
5584
- assert (Tok.is (tok::eof));
5585
- // We hit EOF, and not every brace has a pair. Recover by searching
5586
- // for the next decl except variable decls and cutting off before
5587
- // that point.
5588
- backtrackToPosition (BeginParserPosition);
5589
- consumeToken (tok::l_brace);
5590
- while (Tok.is (tok::kw_var) || Tok.is (tok::kw_let) ||
5591
- (Tok.isNot (tok::eof) && !isStartOfDecl ())) {
5592
- consumeToken ();
5593
- }
5594
- }
5569
+ // Advance the parser to the end of the block; '{' ... '}'.
5570
+ skipBracedBlock ();
5595
5571
5596
5572
BodyRange.End = PreviousLoc;
5597
5573
@@ -7033,12 +7009,13 @@ Parser::parseDeclPrecedenceGroup(ParseDeclOptions flags,
7033
7009
if (parseIdentifier (name, nameLoc, diag::expected_precedencegroup_name)) {
7034
7010
// If the identifier is missing or a keyword or something, try to
7035
7011
// skip the entire body.
7036
- if (consumeIf (tok::l_brace)) {
7012
+ if (!Tok.isAtStartOfLine () && Tok.isNot (tok::eof) &&
7013
+ peekToken ().is (tok::l_brace))
7014
+ consumeToken ();
7015
+ if (Tok.is (tok::l_brace)) {
7016
+ consumeToken (tok::l_brace);
7037
7017
skipUntilDeclRBrace ();
7038
7018
(void ) consumeIf (tok::r_brace);
7039
- } else if (Tok.isNot (tok::eof) && peekToken ().is (tok::l_brace)) {
7040
- consumeToken ();
7041
- skipBracedBlock (*this , SyntaxContext);
7042
7019
}
7043
7020
return nullptr ;
7044
7021
}
0 commit comments