<div dir="ltr">Thanks!</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Apr 5, 2013 at 2:38 AM, Daniel Jasper <span dir="ltr"><<a href="mailto:djasper@google.com" target="_blank">djasper@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: djasper<br>
Date: Fri Apr  5 04:38:50 2013<br>
New Revision: 178860<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=178860&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=178860&view=rev</a><br>
Log:<br>
Improve formatting of multi-variable DeclStmts.<br>
<br>
This fixed <a href="http://llvm.org/PR15670" target="_blank">llvm.org/PR15670</a><br>
<br>
Before:<br>
aaaaaaaaa a = aaaaaaaaaaaaaaaaaaaa, b = bbbbbbbbbbbbbbbbbbbb,<br>
                                    c = cccccccccccccccccccc,<br>
                                    d = dddddddddddddddddddd;<br>
aaaaaaaaa *a = aaaaaaaaaaaaaaaaaaa, *b = bbbbbbbbbbbbbbbbbbb,<br>
                                     *c = ccccccccccccccccccc,<br>
                                      *d = ddddddddddddddddddd;<br>
<br>
After:<br>
aaaaaaaaa a = aaaaaaaaaaaaaaaaaaaa, b = bbbbbbbbbbbbbbbbbbbb,<br>
          c = cccccccccccccccccccc, d = dddddddddddddddddddd;<br>
aaaaaaaaa *a = aaaaaaaaaaaaaaaaaaa, *b = bbbbbbbbbbbbbbbbbbb,<br>
          *c = ccccccccccccccccccc, *d = ddddddddddddddddddd;<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=178860&r1=178859&r2=178860&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=178860&r1=178859&r2=178860&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/lib/Format/Format.cpp (original)<br>
+++ cfe/trunk/lib/Format/Format.cpp Fri Apr  5 04:38:50 2013<br>
@@ -798,9 +798,18 @@ private:<br>
       }<br>
     } else {<br>
       if (Current.is(tok::equal) &&<br>
-          (RootToken.is(tok::kw_for) || State.ParenLevel == 0)) {<br>
-        State.Stack.back().VariablePos =<br>
-            State.Column - Previous.FormatTok.TokenLength;<br>
+          (RootToken.is(tok::kw_for) || State.ParenLevel == 0) &&<br>
+          State.Stack.back().VariablePos == 0) {<br>
+        State.Stack.back().VariablePos = State.Column;<br>
+        // Move over * and & if they are bound to the variable name.<br>
+        const AnnotatedToken *Tok = &Previous;<br>
+        while (Tok &&<br>
+               State.Stack.back().VariablePos >= Tok->FormatTok.TokenLength) {<br>
+          State.Stack.back().VariablePos -= Tok->FormatTok.TokenLength;<br>
+          if (Tok->SpacesRequiredBefore != 0)<br>
+            break;<br>
+          Tok = Tok->Parent;<br>
+        }<br>
         if (Previous.PartOfMultiVariableDeclStmt)<br>
           State.Stack.back().LastSpace = State.Stack.back().VariablePos;<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=178860&r1=178859&r2=178860&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=178860&r1=178859&r2=178860&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)<br>
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Apr  5 04:38:50 2013<br>
@@ -1864,7 +1864,22 @@ TEST_F(FormatTest, DeclarationsOfMultipl<br>
       "bool aaaaaaaaaaaaaaaaaaaaa =\n"<br>
       "         bbbbbbbbbbbbbbbbbbbbbbbbbbbb && cccccccccccccccccccccccccccc,\n"<br>
       "     d = e && f;");<br>
+  verifyFormat("aaaaaaaaa a = aaaaaaaaaaaaaaaaaaaa, b = bbbbbbbbbbbbbbbbbbbb,\n"<br>
+               "          c = cccccccccccccccccccc, d = dddddddddddddddddddd;");<br>
+  verifyFormat("aaaaaaaaa *a = aaaaaaaaaaaaaaaaaaa, *b = bbbbbbbbbbbbbbbbbbb,\n"<br>
+               "          *c = ccccccccccccccccccc, *d = ddddddddddddddddddd;");<br>
+  verifyFormat("aaaaaaaaa ***a = aaaaaaaaaaaaaaaaaaa, ***b = bbbbbbbbbbbbbbb,\n"<br>
+               "          ***c = ccccccccccccccccccc, ***d = ddddddddddddddd;");<br>
+  // FIXME: If multiple variables are defined, the "*" needs to move to the new<br>
+  // line. Also fix indent for breaking after the type, this looks bad.<br>
+  verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *\n"<br>
+               "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa = aaaaaaaaaaaaaaaaaaa,\n"<br>
+               "    *b = bbbbbbbbbbbbbbbbbbb;");<br>
<br>
+  // Not ideal, but pointer-with-type does not allow much here.<br>
+  verifyGoogleFormat(<br>
+      "aaaaaaaaa* a = aaaaaaaaaaaaaaaaaaa, *b = bbbbbbbbbbbbbbbbbbb,\n"<br>
+      "           *b = bbbbbbbbbbbbbbbbbbb, *d = ddddddddddddddddddd;");<br>
 }<br>
<br>
 TEST_F(FormatTest, ConditionalExpressionsInBrackets) {<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>