Skip to content

Commit a2046ca

Browse files
authored
[clang-format][NFC] Clean up signatures of some parser functions (#66569)
Removed TT_CompoundRequirementLBrace and parameters CanContainBracedList and NextLBracesType.
1 parent 87f937e commit a2046ca

File tree

4 files changed

+31
-46
lines changed

4 files changed

+31
-46
lines changed

clang/lib/Format/FormatToken.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ namespace format {
4141
TYPE(CaseLabelColon) \
4242
TYPE(CastRParen) \
4343
TYPE(ClassLBrace) \
44-
TYPE(CompoundRequirementLBrace) \
4544
/* ternary ?: expression */ \
4645
TYPE(ConditionalExpr) \
4746
/* the condition in an if statement */ \

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1698,7 +1698,7 @@ class AnnotatingParser {
16981698
TT_RecordLBrace, TT_StructLBrace, TT_UnionLBrace, TT_RequiresClause,
16991699
TT_RequiresClauseInARequiresExpression, TT_RequiresExpression,
17001700
TT_RequiresExpressionLParen, TT_RequiresExpressionLBrace,
1701-
TT_CompoundRequirementLBrace, TT_BracedListLBrace)) {
1701+
TT_BracedListLBrace)) {
17021702
CurrentToken->setType(TT_Unknown);
17031703
}
17041704
CurrentToken->Role.reset();

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -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.)
346343
bool 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

13921382
void 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

clang/lib/Format/UnwrappedLineParser.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,20 +125,15 @@ class UnwrappedLineParser {
125125
void parseFile();
126126
bool precededByCommentOrPPDirective() const;
127127
bool parseLevel(const FormatToken *OpeningBrace = nullptr,
128-
bool CanContainBracedList = true,
129-
TokenType NextLBracesType = TT_Unknown,
130128
IfStmtKind *IfKind = nullptr,
131129
FormatToken **IfLeftBrace = nullptr);
132130
bool mightFitOnOneLine(UnwrappedLine &Line,
133131
const FormatToken *OpeningBrace = nullptr) const;
134132
FormatToken *parseBlock(bool MustBeDeclaration = false,
135133
unsigned AddLevels = 1u, bool MunchSemi = true,
136134
bool KeepBraces = true, IfStmtKind *IfKind = nullptr,
137-
bool UnindentWhitesmithsBraces = false,
138-
bool CanContainBracedList = true,
139-
TokenType NextLBracesType = TT_Unknown);
140-
void parseChildBlock(bool CanContainBracedList = true,
141-
TokenType NextLBracesType = TT_Unknown);
135+
bool UnindentWhitesmithsBraces = false);
136+
void parseChildBlock();
142137
void parsePPDirective();
143138
void parsePPDefine();
144139
void parsePPIf(bool IfDef);
@@ -147,8 +142,7 @@ class UnwrappedLineParser {
147142
void parsePPPragma();
148143
void parsePPUnknown();
149144
void readTokenWithJavaScriptASI();
150-
void parseStructuralElement(bool IsTopLevel = false,
151-
TokenType NextLBracesType = TT_Unknown,
145+
void parseStructuralElement(const FormatToken *OpeningBrace = nullptr,
152146
IfStmtKind *IfKind = nullptr,
153147
FormatToken **IfLeftBrace = nullptr,
154148
bool *HasDoWhile = nullptr,

0 commit comments

Comments
 (0)