[clang] dc4ab97 - [clang-format] Revert 6dcde65 due to missing commit message title
Owen Pan via cfe-commits
cfe-commits at lists.llvm.org
Tue May 23 18:49:00 PDT 2023
Author: Owen Pan
Date: 2023-05-23T18:48:52-07:00
New Revision: dc4ab97085c052e99cb4218f8250ee8d064c1be3
URL: https://github.com/llvm/llvm-project/commit/dc4ab97085c052e99cb4218f8250ee8d064c1be3
DIFF: https://github.com/llvm/llvm-project/commit/dc4ab97085c052e99cb4218f8250ee8d064c1be3.diff
LOG: [clang-format] Revert 6dcde65 due to missing commit message title
This reverts commit 6dcde658b2380d7ca1451ea5d1099af3e294ea16.
Added:
Modified:
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 66c1205757257..31b45fa7cc898 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -491,11 +491,7 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) {
// Keep a stack of positions of lbrace tokens. We will
// update information about whether an lbrace starts a
// braced init list or a
diff erent block during the loop.
- struct StackEntry {
- FormatToken *Tok;
- const FormatToken *PrevTok;
- };
- SmallVector<StackEntry, 8> LBraceStack;
+ SmallVector<FormatToken *, 8> LBraceStack;
assert(Tok->is(tok::l_brace));
do {
// Get next non-comment token.
@@ -525,12 +521,12 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) {
} else {
Tok->setBlockKind(BK_Unknown);
}
- LBraceStack.push_back({Tok, PrevTok});
+ LBraceStack.push_back(Tok);
break;
case tok::r_brace:
if (LBraceStack.empty())
break;
- if (LBraceStack.back().Tok->is(BK_Unknown)) {
+ if (LBraceStack.back()->is(BK_Unknown)) {
bool ProbablyBracedList = false;
if (Style.Language == FormatStyle::LK_Proto) {
ProbablyBracedList = NextTok->isOneOf(tok::comma, tok::r_square);
@@ -558,7 +554,7 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) {
// If we already marked the opening brace as braced list, the closing
// must also be part of it.
- ProbablyBracedList = LBraceStack.back().Tok->is(TT_BracedListLBrace);
+ ProbablyBracedList = LBraceStack.back()->is(TT_BracedListLBrace);
ProbablyBracedList = ProbablyBracedList ||
(Style.isJavaScript() &&
@@ -574,14 +570,8 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) {
ProbablyBracedList =
ProbablyBracedList ||
NextTok->isOneOf(tok::comma, tok::period, tok::colon,
- tok::r_paren, tok::r_square, tok::ellipsis);
-
- // Distinguish between braced list in a constructor initializer list
- // followed by constructor body, or just adjacent blocks.
- ProbablyBracedList =
- ProbablyBracedList ||
- (NextTok->is(tok::l_brace) && LBraceStack.back().PrevTok &&
- LBraceStack.back().PrevTok->is(tok::identifier));
+ tok::r_paren, tok::r_square, tok::l_brace,
+ tok::ellipsis);
ProbablyBracedList =
ProbablyBracedList ||
@@ -605,10 +595,10 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) {
}
if (ProbablyBracedList) {
Tok->setBlockKind(BK_BracedInit);
- LBraceStack.back().Tok->setBlockKind(BK_BracedInit);
+ LBraceStack.back()->setBlockKind(BK_BracedInit);
} else {
Tok->setBlockKind(BK_Block);
- LBraceStack.back().Tok->setBlockKind(BK_Block);
+ LBraceStack.back()->setBlockKind(BK_Block);
}
}
LBraceStack.pop_back();
@@ -625,8 +615,8 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) {
case tok::kw_switch:
case tok::kw_try:
case tok::kw___try:
- if (!LBraceStack.empty() && LBraceStack.back().Tok->is(BK_Unknown))
- LBraceStack.back().Tok->setBlockKind(BK_Block);
+ if (!LBraceStack.empty() && LBraceStack.back()->is(BK_Unknown))
+ LBraceStack.back()->setBlockKind(BK_Block);
break;
default:
break;
@@ -636,9 +626,9 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) {
} while (Tok->isNot(tok::eof) && !LBraceStack.empty());
// Assume other blocks for all unclosed opening braces.
- for (const auto &Entry : LBraceStack)
- if (Entry.Tok->is(BK_Unknown))
- Entry.Tok->setBlockKind(BK_Block);
+ for (FormatToken *LBrace : LBraceStack)
+ if (LBrace->is(BK_Unknown))
+ LBrace->setBlockKind(BK_Block);
FormatTok = Tokens->setPosition(StoredPosition);
}
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 28a4008080566..942c6259015e9 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -13732,26 +13732,6 @@ TEST_F(FormatTest, FormatsBracedListsInColumnLayout) {
" struct Dummy {};\n"
" f(v);\n"
"}");
- verifyFormat("void foo() {\n"
- " { // asdf\n"
- " { int a; }\n"
- " }\n"
- " {\n"
- " { int b; }\n"
- " }\n"
- "}");
- verifyFormat("namespace n {\n"
- "void foo() {\n"
- " {\n"
- " {\n"
- " statement();\n"
- " if (false) {\n"
- " }\n"
- " }\n"
- " }\n"
- " {}\n"
- "}\n"
- "} // namespace n");
// Long lists should be formatted in columns even if they are nested.
verifyFormat(
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 6a3ecc6deb5f9..b875b6f7144ef 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -40,8 +40,6 @@ class TokenAnnotatorTest : public ::testing::Test {
EXPECT_EQ((FormatTok)->getType(), Type) << *(FormatTok)
#define EXPECT_TOKEN_PRECEDENCE(FormatTok, Prec) \
EXPECT_EQ((FormatTok)->getPrecedence(), Prec) << *(FormatTok)
-#define EXPECT_BRACE_KIND(FormatTok, Kind) \
- EXPECT_EQ(FormatTok->getBlockKind(), Kind) << *(FormatTok)
#define EXPECT_TOKEN(FormatTok, Kind, Type) \
do { \
EXPECT_TOKEN_KIND(FormatTok, Kind); \
@@ -1802,22 +1800,6 @@ TEST_F(TokenAnnotatorTest, UnderstandsLabels) {
EXPECT_TOKEN(Tokens[3], tok::colon, TT_CaseLabelColon);
}
-TEST_F(TokenAnnotatorTest, UnderstandsNestedBlocks) {
- // The closing braces are not annotated. It doesn't seem to cause a problem.
- // So we only test for the opening braces.
- auto Tokens = annotate("{\n"
- " {\n"
- " { int a = 0; }\n"
- " }\n"
- " {}\n"
- "}");
- ASSERT_EQ(Tokens.size(), 14u) << Tokens;
- EXPECT_BRACE_KIND(Tokens[0], BK_Block);
- EXPECT_BRACE_KIND(Tokens[1], BK_Block);
- EXPECT_BRACE_KIND(Tokens[2], BK_Block);
- EXPECT_BRACE_KIND(Tokens[10], BK_Block);
-}
-
} // namespace
} // namespace format
} // namespace clang
More information about the cfe-commits
mailing list