r176092 - Fix bad line break decision.

Daniel Jasper djasper at google.com
Tue Feb 26 05:59:15 PST 2013


Author: djasper
Date: Tue Feb 26 07:59:14 2013
New Revision: 176092

URL: http://llvm.org/viewvc/llvm-project?rev=176092&view=rev
Log:
Fix bad line break decision.

Before:
if (Intervals[i].getRange().getFirst() < Intervals[i - 1]
                                             .getRange().getLast()) {}

After:
if (Intervals[i].getRange().getFirst() <
    Intervals[i - 1].getRange().getLast()) {}

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=176092&r1=176091&r2=176092&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Feb 26 07:59:14 2013
@@ -890,10 +890,10 @@ unsigned TokenAnnotator::splitPenalty(co
 
   if (Right.is(tok::arrow) || Right.is(tok::period)) {
     if (Line.Type == LT_BuilderTypeCall)
-      return 5; // Should be smaller than breaking at a nested comma.
+      return 5;
     if ((Left.is(tok::r_paren) || Left.is(tok::r_square)) &&
         Left.MatchingParen && Left.MatchingParen->ParameterCount > 0)
-      return 10;
+      return 20; // Should be smaller than breaking at a nested comma.
     return 150;
   }
 
@@ -928,7 +928,7 @@ unsigned TokenAnnotator::splitPenalty(co
     return prec::Shift;
   }
   if (Left.Type == TT_ConditionalExpr)
-    return prec::Assignment;
+    return prec::Conditional;
   prec::Level Level = getPrecedence(Left);
 
   if (Level != prec::Unknown)

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=176092&r1=176091&r2=176092&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Feb 26 07:59:14 2013
@@ -1185,6 +1185,8 @@ TEST_F(FormatTest, BreaksAsHighAsPossibl
       "if ((aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa && aaaaaaaaaaaaaaaaaaaaaaaaaa) ||\n"
       "    (bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb && bbbbbbbbbbbbbbbbbbbbbbbbbb))\n"
       "  f();");
+  verifyFormat("if (Intervals[i].getRange().getFirst() <\n"
+               "    Intervals[i - 1].getRange().getLast()) {\n}");
 }
 
 TEST_F(FormatTest, BreaksDesireably) {





More information about the cfe-commits mailing list