Skip to content

Commit bf31600

Browse files
committed
[clang-format][NFC] Clean up signatures of some parser functions
Removed TT_CompoundRequirementLBrace and parameters CanContainBracedList and NextLBracesType.
1 parent a63efd2 commit bf31600

File tree

4 files changed

+29
-45
lines changed

4 files changed

+29
-45
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: 24 additions & 34 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,9 +364,9 @@ 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,
367+
auto ParseDefault = [this, OpeningBrace, InRequiresExpression, IfKind,
374368
&IfLBrace, &HasDoWhile, &HasLabel, &StatementCount] {
375-
parseStructuralElement(!OpeningBrace, NextLevelLBracesType, IfKind,
369+
parseStructuralElement(OpeningBrace, InRequiresExpression, IfKind,
376370
&IfLBrace, HasDoWhile ? nullptr : &HasDoWhile,
377371
HasLabel ? nullptr : &HasLabel);
378372
++StatementCount;
@@ -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,8 +1380,9 @@ void UnwrappedLineParser::readTokenWithJavaScriptASI() {
13901380
}
13911381

13921382
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) {
13951386
if (Style.Language == FormatStyle::LK_TableGen &&
13961387
FormatTok->is(tok::pp_include)) {
13971388
nextToken();
@@ -1798,7 +1789,7 @@ void UnwrappedLineParser::parseStructuralElement(
17981789
parseParens();
17991790
// Break the unwrapped line if a K&R C function definition has a parameter
18001791
// declaration.
1801-
if (!IsTopLevel || !Style.isCpp() || !Previous || eof())
1792+
if (OpeningBrace || !Style.isCpp() || !Previous || eof())
18021793
break;
18031794
if (isC78ParameterDecl(FormatTok,
18041795
Tokens->peekNextToken(/*SkipComment=*/true),
@@ -1831,8 +1822,8 @@ void UnwrappedLineParser::parseStructuralElement(
18311822
parseChildBlock();
18321823
break;
18331824
case tok::l_brace:
1834-
if (NextLBracesType != TT_Unknown)
1835-
FormatTok->setFinalizedType(NextLBracesType);
1825+
if (InRequiresExpression)
1826+
FormatTok->setFinalizedType(TT_BracedListLBrace);
18361827
if (!tryToParsePropertyAccessor() && !tryToParseBracedList()) {
18371828
// A block outside of parentheses must be the last part of a
18381829
// structural element.
@@ -3464,8 +3455,7 @@ void UnwrappedLineParser::parseRequiresExpression(FormatToken *RequiresToken) {
34643455

34653456
if (FormatTok->is(tok::l_brace)) {
34663457
FormatTok->setFinalizedType(TT_RequiresExpressionLBrace);
3467-
parseChildBlock(/*CanContainBracedList=*/false,
3468-
/*NextLBracesType=*/TT_CompoundRequirementLBrace);
3458+
parseChildBlock();
34693459
}
34703460
}
34713461

clang/lib/Format/UnwrappedLineParser.h

Lines changed: 4 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,8 @@ 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,
146+
bool InRequiresExpression = false,
152147
IfStmtKind *IfKind = nullptr,
153148
FormatToken **IfLeftBrace = nullptr,
154149
bool *HasDoWhile = nullptr,

0 commit comments

Comments
 (0)