r215529 - clang-format: Format long lists in columns if without bin-packing.

Daniel Jasper djasper at google.com
Wed Aug 13 01:46:22 PDT 2014


Author: djasper
Date: Wed Aug 13 03:46:21 2014
New Revision: 215529

URL: http://llvm.org/viewvc/llvm-project?rev=215529&view=rev
Log:
clang-format: Format long lists in columns if without bin-packing.

After (even with BinPacking = false):
  const Aaaaaa aaaaa = {
      aaaaa,  bbbbb,  ccccc,  ddddd,  eeeee,  ffffff, ggggg, hhhhhh,
      iiiiii, jjjjjj, kkkkkk, aaaaa,  bbbbb,  ccccc,  ddddd, eeeee,
      ffffff, ggggg,  hhhhhh, iiiiii, jjjjjj, kkkkkk,
  };

Before:
  <each element on its own line>

This fixes http://llvm.org/PR20623.

Modified:
    cfe/trunk/lib/Format/FormatToken.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/FormatToken.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatToken.cpp?rev=215529&r1=215528&r2=215529&view=diff
==============================================================================
--- cfe/trunk/lib/Format/FormatToken.cpp (original)
+++ cfe/trunk/lib/Format/FormatToken.cpp Wed Aug 13 03:46:21 2014
@@ -131,9 +131,11 @@ void CommaSeparatedList::precomputeForma
   if (!Token->MatchingParen || Token->isNot(tok::l_brace))
     return;
 
-  // In C++11 braced list style, we should not format in columns unless we allow
-  // bin-packing of function parameters.
-  if (Style.Cpp11BracedListStyle && !Style.BinPackParameters)
+  // In C++11 braced list style, we should not format in columns unless they
+  // have many items (20 or more) or we allow bin-packing of function
+  // parameters.
+  if (Style.Cpp11BracedListStyle && !Style.BinPackParameters &&
+      Commas.size() < 19)
     return;
 
   FormatToken *ItemBegin = Token->Next;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=215529&r1=215528&r2=215529&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Aug 13 03:46:21 2014
@@ -5441,6 +5441,13 @@ TEST_F(FormatTest, LayoutCxx11BraceIniti
                "    kkkkkk,\n"
                "};",
                NoBinPacking);
+  verifyFormat(
+      "const Aaaaaa aaaaa = {\n"
+      "    aaaaa,  bbbbb,  ccccc,  ddddd,  eeeee,  ffffff, ggggg, hhhhhh,\n"
+      "    iiiiii, jjjjjj, kkkkkk, aaaaa,  bbbbb,  ccccc,  ddddd, eeeee,\n"
+      "    ffffff, ggggg,  hhhhhh, iiiiii, jjjjjj, kkkkkk,\n"
+      "};",
+      NoBinPacking);
 
   // FIXME: The alignment of these trailing comments might be bad. Then again,
   // this might be utterly useless in real code.





More information about the cfe-commits mailing list