Skip to content

Commit b7abab2

Browse files
Annotate enum r brace
In preparation of #67906.
1 parent 38c31d7 commit b7abab2

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

clang/lib/Format/FormatToken.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ namespace format {
6868
TYPE(DictLiteral) \
6969
TYPE(ElseLBrace) \
7070
TYPE(EnumLBrace) \
71+
TYPE(EnumRBrace) \
7172
TYPE(FatArrow) \
7273
TYPE(ForEachMacro) \
7374
TYPE(FunctionAnnotationRParen) \

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3713,6 +3713,10 @@ bool UnwrappedLineParser::parseEnum() {
37133713
nextToken();
37143714
addUnwrappedLine();
37153715
}
3716+
if (auto Prev = FormatTok->getPreviousNonComment();
3717+
Prev && Prev->is(tok::r_brace)) {
3718+
Prev->setFinalizedType(TT_EnumRBrace);
3719+
}
37163720
return true;
37173721

37183722
// There is no addUnwrappedLine() here so that we fall through to parsing a

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ TEST_F(TokenAnnotatorTest, UnderstandsEnums) {
474474
auto Tokens = annotate("enum E {};");
475475
EXPECT_EQ(Tokens.size(), 6u) << Tokens;
476476
EXPECT_TOKEN(Tokens[2], tok::l_brace, TT_EnumLBrace);
477+
EXPECT_TOKEN(Tokens[3], tok::r_brace, TT_EnumRBrace);
477478
}
478479

479480
TEST_F(TokenAnnotatorTest, UnderstandsDefaultedAndDeletedFunctions) {

0 commit comments

Comments
 (0)