<div dir="ltr">Huh, why this change? The only style without a column limit is WebKit, which explicitly asks for one line per initializer.</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Dec 4, 2013 at 4:21 AM, Alexander Kornienko <span dir="ltr"><<a href="mailto:alexfh@google.com" target="_blank">alexfh@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: alexfh<br>
Date: Wed Dec  4 06:21:08 2013<br>
New Revision: 196378<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=196378&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=196378&view=rev</a><br>
Log:<br>
Leave constructor initializer lists on one line in styles with no column limit.<br>
<br>
Summary:<br>
Allow tryFitMultipleLinesInOne join unwrapped lines when<br>
ContinuationIndenter::mustBreak doesn't agree. But don't merge any lines, that<br>
are separate in the input.<br>
<br>
Reviewers: djasper<br>
<br>
Reviewed By: djasper<br>
<br>
CC: cfe-commits, klimek<br>
<br>
Differential Revision: <a href="http://llvm-reviews.chandlerc.com/D2321" target="_blank">http://llvm-reviews.chandlerc.com/D2321</a><br>
<br>
Modified:<br>
    cfe/trunk/lib/Format/Format.cpp<br>
    cfe/trunk/unittests/Format/FormatTest.cpp<br>
<br>
Modified: cfe/trunk/lib/Format/Format.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=196378&r1=196377&r2=196378&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=196378&r1=196377&r2=196378&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/lib/Format/Format.cpp (original)<br>
+++ cfe/trunk/lib/Format/Format.cpp Wed Dec  4 06:21:08 2013<br>
@@ -439,12 +439,13 @@ public:<br>
<br>
   /// \brief Formats the line starting at \p State, simply keeping all of the<br>
   /// input's line breaking decisions.<br>
-  void format(unsigned FirstIndent, const AnnotatedLine *Line) {<br>
+  void format(unsigned FirstIndent, const AnnotatedLine *Line,<br>
+              bool LineIsMerged) {<br>
     LineState State =<br>
         Indenter->getInitialState(FirstIndent, Line, /*DryRun=*/false);<br>
     while (State.NextToken != NULL) {<br>
       bool Newline =<br>
-          Indenter->mustBreak(State) ||<br>
+          (!LineIsMerged && Indenter->mustBreak(State)) ||<br>
           (Indenter->canBreak(State) && State.NextToken->NewlinesBefore > 0);<br>
       Indenter->addTokenToState(State, Newline, /*DryRun=*/false);<br>
     }<br>
@@ -468,9 +469,6 @@ public:<br>
     if (TheLine->Last->Type == TT_LineComment)<br>
       return 0;<br>
<br>
-    if (Indent > Style.ColumnLimit)<br>
-      return 0;<br>
-<br>
     unsigned Limit =<br>
         Style.ColumnLimit == 0 ? UINT_MAX : Style.ColumnLimit - Indent;<br>
     // If we already exceed the column limit, we set 'Limit' to 0. The different<br>
@@ -479,6 +477,9 @@ public:<br>
                 ? 0<br>
                 : Limit - TheLine->Last->TotalLength;<br>
<br>
+    if (Indent > Limit)<br>
+      return 0;<br>
+<br>
     if (I + 1 == E || I[1]->Type == LT_Invalid)<br>
       return 0;<br>
<br>
@@ -658,6 +659,14 @@ public:<br>
       if (static_cast<int>(Indent) + Offset >= 0)<br>
         Indent += Offset;<br>
       unsigned MergedLines = Joiner.tryFitMultipleLinesInOne(Indent, I, E);<br>
+      if (MergedLines > 0 && Style.ColumnLimit == 0) {<br>
+        // Disallow line merging if there is a break at the start of one of the<br>
+        // input lines.<br>
+        for (unsigned i = 0; i < MergedLines; ++i) {<br>
+          if (I[i + 1]->First->NewlinesBefore > 0)<br>
+            MergedLines = 0;<br>
+        }<br>
+      }<br>
       if (!DryRun) {<br>
         for (unsigned i = 0; i < MergedLines; ++i) {<br>
           join(*I[i], *I[i + 1]);<br>
@@ -702,7 +711,8 @@ public:<br>
           // FIXME: Implement nested blocks for ColumnLimit = 0.<br>
           NoColumnLimitFormatter Formatter(Indenter);<br>
           if (!DryRun)<br>
-            Formatter.format(Indent, &TheLine);<br>
+            Formatter.format(Indent, &TheLine,<br>
+                             /*LineIsMerged=*/MergedLines > 0);<br>
         } else {<br>
           Penalty += format(TheLine, Indent, DryRun);<br>
         }<br>
<br>
Modified: cfe/trunk/unittests/Format/FormatTest.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=196378&r1=196377&r2=196378&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=196378&r1=196377&r2=196378&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)<br>
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Dec  4 06:21:08 2013<br>
@@ -4891,6 +4891,28 @@ TEST_F(FormatTest, PullTrivialFunctionDe<br>
<br>
   verifyFormat("void f() {}", getLLVMStyleWithColumns(11));<br>
   verifyFormat("void f() {\n}", getLLVMStyleWithColumns(10));<br>
+<br>
+  FormatStyle NoColumnLimit = getLLVMStyle();<br>
+  NoColumnLimit.ColumnLimit = 0;<br>
+  EXPECT_EQ("A() : b(0) {}", format("A():b(0){}", NoColumnLimit));<br>
+  EXPECT_EQ("class C {\n"<br>
+            "  A() : b(0) {}\n"<br>
+            "};", format("class C{A():b(0){}};", NoColumnLimit));<br>
+  EXPECT_EQ("A()\n"<br>
+            "    : b(0) {\n"<br>
+            "}",<br>
+            format("A()\n:b(0)\n{\n}", NoColumnLimit));<br>
+<br>
+  FormatStyle DoNotMergeNoColumnLimit = NoColumnLimit;<br>
+  DoNotMergeNoColumnLimit.AllowShortFunctionsOnASingleLine = false;<br>
+  EXPECT_EQ("A()\n"<br>
+            "    : b(0) {\n"<br>
+            "}",<br>
+            format("A():b(0){}", DoNotMergeNoColumnLimit));<br>
+  EXPECT_EQ("A()\n"<br>
+            "    : b(0) {\n"<br>
+            "}",<br>
+            format("A()\n:b(0)\n{\n}", DoNotMergeNoColumnLimit));<br>
 }<br>
<br>
 TEST_F(FormatTest, UnderstandContextOfRecordTypeKeywords) {<br>
@@ -7340,12 +7362,18 @@ TEST_F(FormatTest, FormatsWithWebKitStyl<br>
<br>
   // Constructor initializers are formatted one per line with the "," on the<br>
   // new line.<br>
-  verifyFormat("Constructor()\n"<br>
-               "    : aaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"<br>
-               "    , aaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaa, // break\n"<br>
-               "                               aaaaaaaaaaaaaa)\n"<br>
-               "    , aaaaaaaaaaaaaaaaaaaaaaa() {}",<br>
-               Style);<br>
+  EXPECT_EQ(<br>
+      "Constructor()\n"<br>
+      "    : aaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"<br>
+      "    , aaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaa, // break\n"<br>
+      "                               aaaaaaaaaaaaaa)\n"<br>
+      "    , aaaaaaaaaaaaaaaaaaaaaaa() {}",<br>
+      format("Constructor()\n"<br>
+             "    : aaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"<br>
+             "    , aaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaa, // break\n"<br>
+             "                               aaaaaaaaaaaaaa)\n"<br>
+             "    , aaaaaaaaaaaaaaaaaaaaaaa() {}",<br>
+             Style));<br>
<br>
   // Access specifiers should be aligned left.<br>
   verifyFormat("class C {\n"<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>