[clang] b7abab2 - Annotate enum r brace
via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 9 10:53:08 PDT 2023
Author: Björn Schäpers
Date: 2023-10-09T19:53:03+02:00
New Revision: b7abab2f284cca5a712a22b87c1998fbed9f4bc9
URL: https://github.com/llvm/llvm-project/commit/b7abab2f284cca5a712a22b87c1998fbed9f4bc9
DIFF: https://github.com/llvm/llvm-project/commit/b7abab2f284cca5a712a22b87c1998fbed9f4bc9.diff
LOG: Annotate enum r brace
In preparation of #67906.
Added:
Modified:
clang/lib/Format/FormatToken.h
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 092ad4126451bd7..527f1d744a58089 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -68,6 +68,7 @@ namespace format {
TYPE(DictLiteral) \
TYPE(ElseLBrace) \
TYPE(EnumLBrace) \
+ TYPE(EnumRBrace) \
TYPE(FatArrow) \
TYPE(ForEachMacro) \
TYPE(FunctionAnnotationRParen) \
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 399318e26b970ac..3275d7b6a71aaa0 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3713,6 +3713,10 @@ bool UnwrappedLineParser::parseEnum() {
nextToken();
addUnwrappedLine();
}
+ if (auto Prev = FormatTok->getPreviousNonComment();
+ Prev && Prev->is(tok::r_brace)) {
+ Prev->setFinalizedType(TT_EnumRBrace);
+ }
return true;
// There is no addUnwrappedLine() here so that we fall through to parsing a
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 4f006ac8eb951f5..2d590f2af05e63a 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -474,6 +474,7 @@ TEST_F(TokenAnnotatorTest, UnderstandsEnums) {
auto Tokens = annotate("enum E {};");
EXPECT_EQ(Tokens.size(), 6u) << Tokens;
EXPECT_TOKEN(Tokens[2], tok::l_brace, TT_EnumLBrace);
+ EXPECT_TOKEN(Tokens[3], tok::r_brace, TT_EnumRBrace);
}
TEST_F(TokenAnnotatorTest, UnderstandsDefaultedAndDeletedFunctions) {
More information about the cfe-commits
mailing list