r210529 - clang-format: Increase penalty for wrapping array subscript expressions

Daniel Jasper djasper at google.com
Tue Jun 10 06:27:58 PDT 2014


Author: djasper
Date: Tue Jun 10 08:27:57 2014
New Revision: 210529

URL: http://llvm.org/viewvc/llvm-project?rev=210529&view=rev
Log:
clang-format: Increase penalty for wrapping array subscript expressions

Before:
  aaaaaaaaaaa aaaaaaaaaaaaaaa = aaaaaaaaaaaaaaaaaaaaaaaaaa->aaaaaaaaa[0].aaaaaaa
                                    [0].aaaaaaaaaaaaaaaaaaaaaa();

After:
  aaaaaaaaaaa aaaaaaaaaaaaaaa = aaaaaaaaaaaaaaaaaaaaaaaaaa->aaaaaaaaa[0]
                                    .aaaaaaa[0]
                                    .aaaaaaaaaaaaaaaaaaaaaa();

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

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=210529&r1=210528&r2=210529&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Jun 10 08:27:57 2014
@@ -1309,7 +1309,7 @@ unsigned TokenAnnotator::splitPenalty(co
     if (Style.Language == FormatStyle::LK_Proto)
       return 1;
     if (Right.Type != TT_ObjCMethodExpr)
-      return 250;
+      return 500;
   }
   if (Right.Type == TT_StartOfName || Right.is(tok::kw_operator)) {
     if (Line.First->is(tok::kw_for) && Right.PartOfMultiVariableDeclStmt)

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=210529&r1=210528&r2=210529&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Jun 10 08:27:57 2014
@@ -5110,6 +5110,10 @@ TEST_F(FormatTest, FormatsArrays) {
 
   verifyGoogleFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<int>\n"
                      "    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[aaaaaaaaaaaa];");
+  verifyFormat(
+      "aaaaaaaaaaa aaaaaaaaaaaaaaa = aaaaaaaaaaaaaaaaaaaaaaaaaa->aaaaaaaaa[0]\n"
+      "                                  .aaaaaaa[0]\n"
+      "                                  .aaaaaaaaaaaaaaaaaaaaaa();");
 }
 
 TEST_F(FormatTest, LineStartsWithSpecialCharacter) {





More information about the cfe-commits mailing list