@@ -335,22 +335,16 @@ bool UnwrappedLineParser::precededByCommentOrPPDirective() const {
335335}
336336
337337// / \brief Parses a level, that is ???.
338- // / \param OpeningBrace Opening brace (\p nullptr if absent) of that level
339- // / \param CanContainBracedList If the content can contain (at any level) a
340- // / braced list.
341- // / \param NextLBracesType The type for left brace found in this level.
338+ // / \param OpeningBrace Opening brace (\p nullptr if absent) of that level.
342339// / \param IfKind The \p if statement kind in the level.
343340// / \param IfLeftBrace The left brace of the \p if block in the level.
344341// / \returns true if a simple block of if/else/for/while, or false otherwise.
345342// / (A simple block has a single statement.)
346343bool UnwrappedLineParser::parseLevel (const FormatToken *OpeningBrace,
347- bool CanContainBracedList,
348- TokenType NextLBracesType,
349344 IfStmtKind *IfKind,
350345 FormatToken **IfLeftBrace) {
351- auto NextLevelLBracesType = NextLBracesType == TT_CompoundRequirementLBrace
352- ? TT_BracedListLBrace
353- : TT_Unknown;
346+ const bool InRequiresExpression =
347+ OpeningBrace && OpeningBrace->is (TT_RequiresExpressionLBrace);
354348 const bool IsPrecededByCommentOrPPDirective =
355349 !Style.RemoveBracesLLVM || precededByCommentOrPPDirective ();
356350 FormatToken *IfLBrace = nullptr ;
@@ -370,10 +364,10 @@ bool UnwrappedLineParser::parseLevel(const FormatToken *OpeningBrace,
370364 else if (FormatTok->getType () == TT_MacroBlockEnd)
371365 kind = tok::r_brace;
372366
373- auto ParseDefault = [this , OpeningBrace, NextLevelLBracesType, IfKind ,
374- &IfLBrace, &HasDoWhile, & HasLabel, &StatementCount] {
375- parseStructuralElement (! OpeningBrace, NextLevelLBracesType, IfKind ,
376- &IfLBrace, HasDoWhile ? nullptr : &HasDoWhile,
367+ auto ParseDefault = [this , OpeningBrace, IfKind, &IfLBrace, &HasDoWhile ,
368+ &HasLabel, &StatementCount] {
369+ parseStructuralElement (OpeningBrace, IfKind, &IfLBrace ,
370+ HasDoWhile ? nullptr : &HasDoWhile,
377371 HasLabel ? nullptr : &HasLabel);
378372 ++StatementCount;
379373 assert (StatementCount > 0 && " StatementCount overflow!" );
@@ -385,23 +379,20 @@ bool UnwrappedLineParser::parseLevel(const FormatToken *OpeningBrace,
385379 addUnwrappedLine ();
386380 break ;
387381 case tok::l_brace:
388- if (NextLBracesType != TT_Unknown ) {
389- FormatTok->setFinalizedType (NextLBracesType );
382+ if (InRequiresExpression ) {
383+ FormatTok->setFinalizedType (TT_RequiresExpressionLBrace );
390384 } else if (FormatTok->Previous &&
391385 FormatTok->Previous ->ClosesRequiresClause ) {
392386 // We need the 'default' case here to correctly parse a function
393387 // l_brace.
394388 ParseDefault ();
395389 continue ;
396390 }
397- if (CanContainBracedList && FormatTok->isNot (TT_MacroBlockBegin) &&
391+ if (!InRequiresExpression && FormatTok->isNot (TT_MacroBlockBegin) &&
398392 tryToParseBracedList ()) {
399393 continue ;
400394 }
401- parseBlock (/* MustBeDeclaration=*/ false , /* AddLevels=*/ 1u ,
402- /* MunchSemi=*/ true , /* KeepBraces=*/ true , /* IfKind=*/ nullptr ,
403- /* UnindentWhitesmithsBraces=*/ false , CanContainBracedList,
404- NextLBracesType);
395+ parseBlock ();
405396 ++StatementCount;
406397 assert (StatementCount > 0 && " StatementCount overflow!" );
407398 addUnwrappedLine ();
@@ -725,10 +716,11 @@ bool UnwrappedLineParser::mightFitOnOneLine(
725716 return Line.Level * Style.IndentWidth + Length <= ColumnLimit;
726717}
727718
728- FormatToken *UnwrappedLineParser::parseBlock (
729- bool MustBeDeclaration, unsigned AddLevels, bool MunchSemi, bool KeepBraces,
730- IfStmtKind *IfKind, bool UnindentWhitesmithsBraces,
731- bool CanContainBracedList, TokenType NextLBracesType) {
719+ FormatToken *UnwrappedLineParser::parseBlock (bool MustBeDeclaration,
720+ unsigned AddLevels, bool MunchSemi,
721+ bool KeepBraces,
722+ IfStmtKind *IfKind,
723+ bool UnindentWhitesmithsBraces) {
732724 auto HandleVerilogBlockLabel = [this ]() {
733725 // ":" name
734726 if (Style.isVerilog () && FormatTok->is (tok::colon)) {
@@ -796,8 +788,7 @@ FormatToken *UnwrappedLineParser::parseBlock(
796788 Line->Level += AddLevels;
797789
798790 FormatToken *IfLBrace = nullptr ;
799- const bool SimpleBlock =
800- parseLevel (Tok, CanContainBracedList, NextLBracesType, IfKind, &IfLBrace);
791+ const bool SimpleBlock = parseLevel (Tok, IfKind, &IfLBrace);
801792
802793 if (eof ())
803794 return IfLBrace;
@@ -957,8 +948,7 @@ static bool ShouldBreakBeforeBrace(const FormatStyle &Style,
957948 }
958949}
959950
960- void UnwrappedLineParser::parseChildBlock (
961- bool CanContainBracedList, clang::format::TokenType NextLBracesType) {
951+ void UnwrappedLineParser::parseChildBlock () {
962952 assert (FormatTok->is (tok::l_brace));
963953 FormatTok->setBlockKind (BK_Block);
964954 const FormatToken *OpeningBrace = FormatTok;
@@ -970,7 +960,7 @@ void UnwrappedLineParser::parseChildBlock(
970960 ScopedDeclarationState DeclarationState (*Line, DeclarationScopeStack,
971961 /* MustBeDeclaration=*/ false );
972962 Line->Level += SkipIndent ? 0 : 1 ;
973- parseLevel (OpeningBrace, CanContainBracedList, NextLBracesType );
963+ parseLevel (OpeningBrace);
974964 flushComments (isOnNewLine (*FormatTok));
975965 Line->Level -= SkipIndent ? 0 : 1 ;
976966 }
@@ -1390,7 +1380,7 @@ void UnwrappedLineParser::readTokenWithJavaScriptASI() {
13901380}
13911381
13921382void UnwrappedLineParser::parseStructuralElement (
1393- bool IsTopLevel, TokenType NextLBracesType , IfStmtKind *IfKind,
1383+ const FormatToken *OpeningBrace , IfStmtKind *IfKind,
13941384 FormatToken **IfLeftBrace, bool *HasDoWhile, bool *HasLabel) {
13951385 if (Style.Language == FormatStyle::LK_TableGen &&
13961386 FormatTok->is (tok::pp_include)) {
@@ -1656,6 +1646,9 @@ void UnwrappedLineParser::parseStructuralElement(
16561646 default :
16571647 break ;
16581648 }
1649+
1650+ const bool InRequiresExpression =
1651+ OpeningBrace && OpeningBrace->is (TT_RequiresExpressionLBrace);
16591652 do {
16601653 const FormatToken *Previous = FormatTok->Previous ;
16611654 switch (FormatTok->Tok .getKind ()) {
@@ -1798,7 +1791,7 @@ void UnwrappedLineParser::parseStructuralElement(
17981791 parseParens ();
17991792 // Break the unwrapped line if a K&R C function definition has a parameter
18001793 // declaration.
1801- if (!IsTopLevel || !Style.isCpp () || !Previous || eof ())
1794+ if (OpeningBrace || !Style.isCpp () || !Previous || eof ())
18021795 break ;
18031796 if (isC78ParameterDecl (FormatTok,
18041797 Tokens->peekNextToken (/* SkipComment=*/ true ),
@@ -1831,8 +1824,8 @@ void UnwrappedLineParser::parseStructuralElement(
18311824 parseChildBlock ();
18321825 break ;
18331826 case tok::l_brace:
1834- if (NextLBracesType != TT_Unknown )
1835- FormatTok->setFinalizedType (NextLBracesType );
1827+ if (InRequiresExpression )
1828+ FormatTok->setFinalizedType (TT_BracedListLBrace );
18361829 if (!tryToParsePropertyAccessor () && !tryToParseBracedList ()) {
18371830 // A block outside of parentheses must be the last part of a
18381831 // structural element.
@@ -3464,8 +3457,7 @@ void UnwrappedLineParser::parseRequiresExpression(FormatToken *RequiresToken) {
34643457
34653458 if (FormatTok->is (tok::l_brace)) {
34663459 FormatTok->setFinalizedType (TT_RequiresExpressionLBrace);
3467- parseChildBlock (/* CanContainBracedList=*/ false ,
3468- /* NextLBracesType=*/ TT_CompoundRequirementLBrace);
3460+ parseChildBlock ();
34693461 }
34703462}
34713463
0 commit comments