@@ -335,22 +335,16 @@ bool UnwrappedLineParser::precededByCommentOrPPDirective() const {
335
335
}
336
336
337
337
// / \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.
342
339
// / \param IfKind The \p if statement kind in the level.
343
340
// / \param IfLeftBrace The left brace of the \p if block in the level.
344
341
// / \returns true if a simple block of if/else/for/while, or false otherwise.
345
342
// / (A simple block has a single statement.)
346
343
bool UnwrappedLineParser::parseLevel (const FormatToken *OpeningBrace,
347
- bool CanContainBracedList,
348
- TokenType NextLBracesType,
349
344
IfStmtKind *IfKind,
350
345
FormatToken **IfLeftBrace) {
351
- auto NextLevelLBracesType = NextLBracesType == TT_CompoundRequirementLBrace
352
- ? TT_BracedListLBrace
353
- : TT_Unknown;
346
+ const bool InRequiresExpression =
347
+ OpeningBrace && OpeningBrace->is (TT_RequiresExpressionLBrace);
354
348
const bool IsPrecededByCommentOrPPDirective =
355
349
!Style .RemoveBracesLLVM || precededByCommentOrPPDirective ();
356
350
FormatToken *IfLBrace = nullptr ;
@@ -370,9 +364,9 @@ bool UnwrappedLineParser::parseLevel(const FormatToken *OpeningBrace,
370
364
else if (FormatTok->getType () == TT_MacroBlockEnd)
371
365
kind = tok::r_brace;
372
366
373
- auto ParseDefault = [this , OpeningBrace, NextLevelLBracesType , IfKind,
367
+ auto ParseDefault = [this , OpeningBrace, InRequiresExpression , IfKind,
374
368
&IfLBrace, &HasDoWhile, &HasLabel, &StatementCount] {
375
- parseStructuralElement (! OpeningBrace, NextLevelLBracesType , IfKind,
369
+ parseStructuralElement (OpeningBrace, InRequiresExpression , IfKind,
376
370
&IfLBrace, HasDoWhile ? nullptr : &HasDoWhile,
377
371
HasLabel ? nullptr : &HasLabel);
378
372
++StatementCount;
@@ -385,23 +379,20 @@ bool UnwrappedLineParser::parseLevel(const FormatToken *OpeningBrace,
385
379
addUnwrappedLine ();
386
380
break ;
387
381
case tok::l_brace:
388
- if (NextLBracesType != TT_Unknown ) {
389
- FormatTok->setFinalizedType (NextLBracesType );
382
+ if (InRequiresExpression ) {
383
+ FormatTok->setFinalizedType (TT_RequiresExpressionLBrace );
390
384
} else if (FormatTok->Previous &&
391
385
FormatTok->Previous ->ClosesRequiresClause ) {
392
386
// We need the 'default' case here to correctly parse a function
393
387
// l_brace.
394
388
ParseDefault ();
395
389
continue ;
396
390
}
397
- if (CanContainBracedList && FormatTok->isNot (TT_MacroBlockBegin) &&
391
+ if (!InRequiresExpression && FormatTok->isNot (TT_MacroBlockBegin) &&
398
392
tryToParseBracedList ()) {
399
393
continue ;
400
394
}
401
- parseBlock (/* MustBeDeclaration=*/ false , /* AddLevels=*/ 1u ,
402
- /* MunchSemi=*/ true , /* KeepBraces=*/ true , /* IfKind=*/ nullptr ,
403
- /* UnindentWhitesmithsBraces=*/ false , CanContainBracedList,
404
- NextLBracesType);
395
+ parseBlock ();
405
396
++StatementCount;
406
397
assert (StatementCount > 0 && " StatementCount overflow!" );
407
398
addUnwrappedLine ();
@@ -725,10 +716,11 @@ bool UnwrappedLineParser::mightFitOnOneLine(
725
716
return Line.Level * Style .IndentWidth + Length <= ColumnLimit;
726
717
}
727
718
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) {
732
724
auto HandleVerilogBlockLabel = [this ]() {
733
725
// ":" name
734
726
if (Style .isVerilog () && FormatTok->is (tok::colon)) {
@@ -796,8 +788,7 @@ FormatToken *UnwrappedLineParser::parseBlock(
796
788
Line->Level += AddLevels;
797
789
798
790
FormatToken *IfLBrace = nullptr ;
799
- const bool SimpleBlock =
800
- parseLevel (Tok, CanContainBracedList, NextLBracesType, IfKind, &IfLBrace);
791
+ const bool SimpleBlock = parseLevel (Tok, IfKind, &IfLBrace);
801
792
802
793
if (eof ())
803
794
return IfLBrace;
@@ -957,8 +948,7 @@ static bool ShouldBreakBeforeBrace(const FormatStyle &Style,
957
948
}
958
949
}
959
950
960
- void UnwrappedLineParser::parseChildBlock (
961
- bool CanContainBracedList, clang::format::TokenType NextLBracesType) {
951
+ void UnwrappedLineParser::parseChildBlock () {
962
952
assert (FormatTok->is (tok::l_brace));
963
953
FormatTok->setBlockKind (BK_Block);
964
954
const FormatToken *OpeningBrace = FormatTok;
@@ -970,7 +960,7 @@ void UnwrappedLineParser::parseChildBlock(
970
960
ScopedDeclarationState DeclarationState (*Line, DeclarationScopeStack,
971
961
/* MustBeDeclaration=*/ false );
972
962
Line->Level += SkipIndent ? 0 : 1 ;
973
- parseLevel (OpeningBrace, CanContainBracedList, NextLBracesType );
963
+ parseLevel (OpeningBrace);
974
964
flushComments (isOnNewLine (*FormatTok));
975
965
Line->Level -= SkipIndent ? 0 : 1 ;
976
966
}
@@ -1390,8 +1380,9 @@ void UnwrappedLineParser::readTokenWithJavaScriptASI() {
1390
1380
}
1391
1381
1392
1382
void UnwrappedLineParser::parseStructuralElement (
1393
- bool IsTopLevel, TokenType NextLBracesType, IfStmtKind *IfKind,
1394
- FormatToken **IfLeftBrace, bool *HasDoWhile, bool *HasLabel) {
1383
+ const FormatToken *OpeningBrace, bool InRequiresExpression,
1384
+ IfStmtKind *IfKind, FormatToken **IfLeftBrace, bool *HasDoWhile,
1385
+ bool *HasLabel) {
1395
1386
if (Style .Language == FormatStyle::LK_TableGen &&
1396
1387
FormatTok->is (tok::pp_include)) {
1397
1388
nextToken ();
@@ -1798,7 +1789,7 @@ void UnwrappedLineParser::parseStructuralElement(
1798
1789
parseParens ();
1799
1790
// Break the unwrapped line if a K&R C function definition has a parameter
1800
1791
// declaration.
1801
- if (!IsTopLevel || !Style .isCpp () || !Previous || eof ())
1792
+ if (OpeningBrace || !Style .isCpp () || !Previous || eof ())
1802
1793
break ;
1803
1794
if (isC78ParameterDecl (FormatTok,
1804
1795
Tokens->peekNextToken (/* SkipComment=*/ true ),
@@ -1831,8 +1822,8 @@ void UnwrappedLineParser::parseStructuralElement(
1831
1822
parseChildBlock ();
1832
1823
break ;
1833
1824
case tok::l_brace:
1834
- if (NextLBracesType != TT_Unknown )
1835
- FormatTok->setFinalizedType (NextLBracesType );
1825
+ if (InRequiresExpression )
1826
+ FormatTok->setFinalizedType (TT_BracedListLBrace );
1836
1827
if (!tryToParsePropertyAccessor () && !tryToParseBracedList ()) {
1837
1828
// A block outside of parentheses must be the last part of a
1838
1829
// structural element.
@@ -3464,8 +3455,7 @@ void UnwrappedLineParser::parseRequiresExpression(FormatToken *RequiresToken) {
3464
3455
3465
3456
if (FormatTok->is (tok::l_brace)) {
3466
3457
FormatTok->setFinalizedType (TT_RequiresExpressionLBrace);
3467
- parseChildBlock (/* CanContainBracedList=*/ false ,
3468
- /* NextLBracesType=*/ TT_CompoundRequirementLBrace);
3458
+ parseChildBlock ();
3469
3459
}
3470
3460
}
3471
3461
0 commit comments