[PATCH] D34238: clang-format: Do not binpack initialization lists
Francois Ferrand via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 16 05:26:07 PDT 2017
Typz updated this revision to Diff 102808.
Typz marked an inline comment as done.
Typz added a comment.
remove special case after assignment
https://reviews.llvm.org/D34238
Files:
lib/Format/ContinuationIndenter.cpp
unittests/Format/FormatTest.cpp
Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -5617,6 +5617,17 @@
"};");
verifyFormat("#define A {a, a},");
+ // Binpacking only if there is no trailing comma
+ verifyFormat("const Aaaaaa aaaaa = {aaaaaaaaaa, bbbbbbbbbb,\n"
+ " cccccccccc, dddddddddd};",
+ getLLVMStyleWithColumns(50));
+ verifyFormat("const Aaaaaa aaaaa = {\n"
+ " aaaaaaaaaaa,\n"
+ " bbbbbbbbbbb,\n"
+ " ccccccccccc,\n"
+ " ddddddddddd,\n"
+ "};", getLLVMStyleWithColumns(50));
+
// Cases where distinguising braced lists and blocks is hard.
verifyFormat("vector<int> v{12} GUARDED_BY(mutex);");
verifyFormat("void f() {\n"
@@ -5696,10 +5707,12 @@
" // Second element:\n"
" 2};",
getLLVMStyleWithColumns(30)));
- // A trailing comma should still lead to an enforced line break.
+ // A trailing comma should still lead to an enforced line break and no
+ // binpacking.
EXPECT_EQ("vector<int> SomeVector = {\n"
" // aaa\n"
- " 1, 2,\n"
+ " 1,\n"
+ " 2,\n"
"};",
format("vector<int> SomeVector = { // aaa\n"
" 1, 2, };"));
@@ -5784,7 +5797,7 @@
" X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,\n"
" X86::R8, X86::R9, X86::R10, X86::R11, 0};");
verifyFormat("static const uint16_t CallerSavedRegs64Bittttt[] = {\n"
- " X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,\n"
+ " X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,\n"
" // Separating comment.\n"
" X86::R8, X86::R9, X86::R10, X86::R11, 0};");
verifyFormat("static const uint16_t CallerSavedRegs64Bittttt[] = {\n"
@@ -5863,8 +5876,8 @@
" aaaaaaaaaaaa, a, aaaaaaaaaa, aaaaaaaaa, aaa}};");
// No column layout should be used here.
- verifyFormat("aaaaaaaaaaaaaaa = {aaaaaaaaaaaaaaaaaaaaaaaaaaa, 0, 0,\n"
- " bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb};");
+ verifyFormat("aaaaaaaaaaaaaaa = {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, 0, 0,\n"
+ " bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb};");
verifyNoCrash("a<,");
Index: lib/Format/ContinuationIndenter.cpp
===================================================================
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -1000,8 +1000,7 @@
Current.MatchingParen->Previous &&
Current.MatchingParen->Previous->is(tok::comma);
AvoidBinPacking =
- (Current.is(TT_ArrayInitializerLSquare) && EndsInComma) ||
- Current.is(TT_DictLiteral) ||
+ EndsInComma || Current.is(TT_DictLiteral) ||
Style.Language == FormatStyle::LK_Proto || !Style.BinPackArguments ||
(NextNoComment && NextNoComment->is(TT_DesignatedInitializerPeriod));
if (Current.ParameterCount > 1)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34238.102808.patch
Type: text/x-patch
Size: 3246 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170616/41947b73/attachment.bin>
More information about the cfe-commits
mailing list