[PATCH] D93806: [clang-format] PR48569 clang-format fails to align case label with `switch` with Whitesmith Indentation
MyDeveloperDay via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Dec 26 07:19:29 PST 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc7dcc4c72588: [clang-format] PR48569 clang-format fails to align case label with `switch`… (authored by MyDeveloperDay).
Changed prior to commit:
https://reviews.llvm.org/D93806?vs=313699&id=313746#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D93806/new/
https://reviews.llvm.org/D93806
Files:
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -13658,7 +13658,7 @@
" {\n"
" switch (a)\n"
" {\n"
- " case 2:\n"
+ " case 2:\n"
" {\n"
" }\n"
" break;\n"
@@ -13670,18 +13670,18 @@
" {\n"
" switch (a)\n"
" {\n"
- " case 0:\n"
+ " case 0:\n"
" break;\n"
- " case 1:\n"
+ " case 1:\n"
" {\n"
" foo();\n"
" break;\n"
" }\n"
- " case 2:\n"
+ " case 2:\n"
" {\n"
" }\n"
" break;\n"
- " default:\n"
+ " default:\n"
" break;\n"
" }\n"
" }\n",
@@ -13691,12 +13691,12 @@
" {\n"
" switch (a)\n"
" {\n"
- " case 0:\n"
+ " case 0:\n"
" {\n"
" foo(x);\n"
" }\n"
" break;\n"
- " default:\n"
+ " default:\n"
" {\n"
" foo(1);\n"
" }\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2244,18 +2244,26 @@
--Line->Level;
if (LeftAlignLabel)
Line->Level = 0;
+
+ bool RemoveWhitesmithsCaseIndent =
+ (!Style.IndentCaseBlocks &&
+ Style.BreakBeforeBraces == FormatStyle::BS_Whitesmiths);
+
+ if (RemoveWhitesmithsCaseIndent)
+ --Line->Level;
+
if (!Style.IndentCaseBlocks && CommentsBeforeNextToken.empty() &&
FormatTok->Tok.is(tok::l_brace)) {
- CompoundStatementIndenter Indenter(this, Line->Level,
- Style.BraceWrapping.AfterCaseLabel,
- Style.BraceWrapping.IndentBraces);
+
+ CompoundStatementIndenter Indenter(
+ this, Line->Level, Style.BraceWrapping.AfterCaseLabel,
+ Style.BraceWrapping.IndentBraces || RemoveWhitesmithsCaseIndent);
parseBlock(/*MustBeDeclaration=*/false);
if (FormatTok->Tok.is(tok::kw_break)) {
if (Style.BraceWrapping.AfterControlStatement ==
FormatStyle::BWACS_Always) {
addUnwrappedLine();
- if (!Style.IndentCaseBlocks &&
- Style.BreakBeforeBraces == FormatStyle::BS_Whitesmiths) {
+ if (RemoveWhitesmithsCaseIndent) {
Line->Level++;
}
}
@@ -2276,6 +2284,7 @@
void UnwrappedLineParser::parseCaseLabel() {
assert(FormatTok->Tok.is(tok::kw_case) && "'case' expected");
+
// FIXME: fix handling of complex expressions here.
do {
nextToken();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93806.313746.patch
Type: text/x-patch
Size: 3185 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201226/d42efd64/attachment.bin>
More information about the cfe-commits
mailing list