[PATCH] D93938: [clang-format] Fixed AfterEnum handling
Ally Tiritoglu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Jan 3 13:02:41 PST 2021
atirit updated this revision to Diff 314301.
atirit added a comment.
Squashed commits
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D93938/new/
https://reviews.llvm.org/D93938
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
@@ -1344,12 +1344,52 @@
Style.AllowShortEnumsOnASingleLine = true;
verifyFormat("enum { A, B, C } ShortEnum1, ShortEnum2;", Style);
Style.AllowShortEnumsOnASingleLine = false;
+ verifyFormat("enum {\n"
+ " A,\n"
+ " B,\n"
+ " C\n"
+ "} ShortEnum1, ShortEnum2;",
+ Style);
+}
+
+TEST_F(FormatTest, AfterEnum) {
+ FormatStyle Style = getLLVMStyle();
+ Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+
+ Style.AllowShortEnumsOnASingleLine = true;
+ Style.BraceWrapping.AfterEnum = true;
+ verifyFormat("enum { A, B, C } Test1;", Style);
+ verifyFormat("enum\n"
+ "{\n"
+ " A,\n"
+ " B, // foo\n"
+ " C\n"
+ "} Test2;",
+ Style);
+ Style.BraceWrapping.AfterEnum = false;
+ verifyFormat("enum { A, B, C } Test3;", Style);
+ verifyFormat("enum {\n"
+ " A,\n"
+ " B, // foo\n"
+ " C\n"
+ "} Test4;",
+ Style);
+
+ Style.AllowShortEnumsOnASingleLine = false;
+ Style.BraceWrapping.AfterEnum = true;
verifyFormat("enum\n"
"{\n"
" A,\n"
" B,\n"
" C\n"
- "} ShortEnum1, ShortEnum2;",
+ "} Test5;",
+ Style);
+ Style.BraceWrapping.AfterEnum = false;
+ verifyFormat("enum {\n"
+ " A,\n"
+ " B,\n"
+ " C\n"
+ "} Test6;",
Style);
}
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -694,6 +694,8 @@
return Style.BraceWrapping.AfterUnion;
if (InitialToken.is(tok::kw_struct))
return Style.BraceWrapping.AfterStruct;
+ if (InitialToken.is(tok::kw_enum))
+ return Style.BraceWrapping.AfterEnum;
return false;
}
@@ -2482,8 +2484,9 @@
return true;
}
- if (!Style.AllowShortEnumsOnASingleLine)
+ if (!Style.AllowShortEnumsOnASingleLine && Style.BraceWrapping.AfterEnum)
addUnwrappedLine();
+
// Parse enum body.
nextToken();
if (!Style.AllowShortEnumsOnASingleLine) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93938.314301.patch
Type: text/x-patch
Size: 2501 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210103/6db0fe71/attachment.bin>
More information about the cfe-commits
mailing list