<div style="font-family: arial, helvetica, sans-serif; font-size: 10pt"><div dir="ltr">On Mon, Dec 17, 2012 at 3:29 AM, Daniel Jasper <span dir="ltr"><<a href="mailto:djasper@google.com" target="_blank" class="cremed">djasper@google.com</a>></span> wrote:<br>
<div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: djasper<br>
Date: Mon Dec 17 05:29:41 2012<br>
New Revision: 170316<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=170316&view=rev" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project?rev=170316&view=rev</a><br>
Log:<br>
Fix several formatting problems.<br>
<br>
More specifically:<br>
- Improve formatting of static initializers.<br>
- Fix formatting of lines comments in enums.<br>
- Fix formmating of trailing line comments.<br></blockquote><div><br></div><div style>Where possible, it would be good to keep such improvements in independent commits... It makes reviewing them easier.</div><div> </div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Modified:<br>
    cfe/trunk/lib/Format/Format.cpp<br>
    cfe/trunk/lib/Format/UnwrappedLineParser.cpp<br>
    cfe/trunk/lib/Format/UnwrappedLineParser.h<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=170316&r1=170315&r2=170316&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=170316&r1=170315&r2=170316&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/lib/Format/Format.cpp (original)<br>
+++ cfe/trunk/lib/Format/Format.cpp Mon Dec 17 05:29:41 2012<br>
@@ -734,15 +734,16 @@<br>
   }<br>
<br>
   bool canBreakBetween(const FormatToken &Left, const FormatToken &Right) {<br>
-    if (<a href="http://Right.Tok.is" target="_blank" class="cremed">Right.Tok.is</a>(tok::r_paren))<br>
+    if (<a href="http://Right.Tok.is" target="_blank" class="cremed">Right.Tok.is</a>(tok::r_paren) || <a href="http://Right.Tok.is" target="_blank" class="cremed">Right.Tok.is</a>(tok::l_brace) ||<br>
+        <a href="http://Right.Tok.is" target="_blank" class="cremed">Right.Tok.is</a>(tok::comment) || <a href="http://Right.Tok.is" target="_blank" class="cremed">Right.Tok.is</a>(tok::greater))<br>
       return false;<br>
     if (isBinaryOperator(Left))<br>
       return true;<br>
     if (<a href="http://Right.Tok.is" target="_blank" class="cremed">Right.Tok.is</a>(tok::lessless))<br>
       return true;<br>
-    return <a href="http://Right.Tok.is" target="_blank" class="cremed">Right.Tok.is</a>(tok::colon) || <a href="http://Left.Tok.is" target="_blank" class="cremed">Left.Tok.is</a>(tok::comma) ||<br>
-        <a href="http://Left.Tok.is" target="_blank" class="cremed">Left.Tok.is</a>(tok::semi) || <a href="http://Left.Tok.is" target="_blank" class="cremed">Left.Tok.is</a>(tok::equal) ||<br>
-        <a href="http://Left.Tok.is" target="_blank" class="cremed">Left.Tok.is</a>(tok::ampamp) || <a href="http://Left.Tok.is" target="_blank" class="cremed">Left.Tok.is</a>(tok::pipepipe) ||<br>
+    return <a href="http://Right.Tok.is" target="_blank" class="cremed">Right.Tok.is</a>(tok::colon) || <a href="http://Left.Tok.is" target="_blank" class="cremed">Left.Tok.is</a>(tok::comma) || <a href="http://Left.Tok.is" target="_blank" class="cremed">Left.Tok.is</a>(<br>

+        tok::semi) || <a href="http://Left.Tok.is" target="_blank" class="cremed">Left.Tok.is</a>(tok::equal) || <a href="http://Left.Tok.is" target="_blank" class="cremed">Left.Tok.is</a>(tok::ampamp) ||<br>
+        <a href="http://Left.Tok.is" target="_blank" class="cremed">Left.Tok.is</a>(tok::pipepipe) || <a href="http://Left.Tok.is" target="_blank" class="cremed">Left.Tok.is</a>(tok::l_brace) ||<br>
         (<a href="http://Left.Tok.is" target="_blank" class="cremed">Left.Tok.is</a>(tok::l_paren) && !<a href="http://Right.Tok.is" target="_blank" class="cremed">Right.Tok.is</a>(tok::r_paren));<br>
   }<br>
<br>
<br>
Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=170316&r1=170315&r2=170316&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=170316&r1=170315&r2=170316&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)<br>
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Mon Dec 17 05:29:41 2012<br>
@@ -43,7 +43,8 @@<br>
       parsePPDirective();<br>
       break;<br>
     case tok::comment:<br>
-      parseComment();<br>
+      nextToken();<br>
+      addUnwrappedLine();<br>
       break;<br>
     case tok::l_brace:<br>
       Error |= parseBlock();<br>
@@ -90,22 +91,16 @@<br>
   }<br>
 }<br>
<br>
-void UnwrappedLineParser::parseComment() {<br>
-  while (!eof()) {<br>
-    nextToken();<br>
-    if (FormatTok.NewlinesBefore > 0) {<br>
-      addUnwrappedLine();<br>
-      return;<br>
-    }<br>
-  }<br>
-}<br>
-<br>
-void UnwrappedLineParser::parseStatement() {<br>
+void UnwrappedLineParser::parseComments() {<br>
   // Consume leading line comments, e.g. for branches without compounds.<br>
   while (<a href="http://FormatTok.Tok.is" target="_blank" class="cremed">FormatTok.Tok.is</a>(tok::comment)) {<br>
     nextToken();<br>
     addUnwrappedLine();<br>
   }<br>
+}<br>
+<br>
+void UnwrappedLineParser::parseStatement() {<br>
+  parseComments();<br>
<br>
   switch (FormatTok.Tok.getKind()) {<br>
   case tok::kw_namespace:<br>
@@ -164,6 +159,12 @@<br>
         return;<br>
       }<br>
       break;<br>
+    case tok::equal:<br>
+      nextToken();<br>
+      // Skip initializers as they will be formatted by a later step.<br>
+      if (<a href="http://FormatTok.Tok.is" target="_blank" class="cremed">FormatTok.Tok.is</a>(tok::l_brace))<br>
+        nextToken();<br>
+      break;<br>
     default:<br>
       nextToken();<br>
       break;<br>
@@ -325,6 +326,7 @@<br>
       nextToken();<br>
       addUnwrappedLine();<br>
       ++Line.Level;<br>
+      parseComments();<br>
       break;<br>
     case tok::l_paren:<br>
       parseParens();<br>
@@ -332,6 +334,7 @@<br>
     case tok::comma:<br>
       nextToken();<br>
       addUnwrappedLine();<br>
+      parseComments();<br>
       break;<br>
     case tok::r_brace:<br>
       if (HasContents)<br>
<br>
Modified: cfe/trunk/lib/Format/UnwrappedLineParser.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.h?rev=170316&r1=170315&r2=170316&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.h?rev=170316&r1=170315&r2=170316&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/lib/Format/UnwrappedLineParser.h (original)<br>
+++ cfe/trunk/lib/Format/UnwrappedLineParser.h Mon Dec 17 05:29:41 2012<br>
@@ -96,7 +96,7 @@<br>
   bool parseLevel();<br>
   bool parseBlock(unsigned AddLevels = 1);<br>
   void parsePPDirective();<br>
-  void parseComment();<br>
+  void parseComments();<br>
   void parseStatement();<br>
   void parseParens();<br>
   void parseIfThenElse();<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=170316&r1=170315&r2=170316&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=170316&r1=170315&r2=170316&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)<br>
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Dec 17 05:29:41 2012<br>
@@ -245,6 +245,19 @@<br>
   EXPECT_EQ("int i  // This is a fancy variable\n    = 5;",<br>
             format("int i  // This is a fancy variable\n= 5;"));<br>
<br>
+  EXPECT_EQ("enum E {\n"<br>
+            "  // comment\n"<br>
+            "  VAL_A,  // comment\n"<br>
+            "  VAL_B\n"<br>
+            "};",<br>
+            format("enum E{\n// comment\nVAL_A,// comment\nVAL_B};"));<br>
+<br>
+  verifyFormat(<br>
+      "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa =\n"<br>
+      "    bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;  // Trailing comment");<br>
+}<br>
+<br>
+TEST_F(FormatTest, UnderstandsMultiLineComments) {<br>
   verifyFormat("f(/*test=*/ true);");<br>
 }<br>
<br>
@@ -319,6 +332,15 @@<br>
                "}");<br>
 }<br>
<br>
+TEST_F(FormatTest, StaticInitializers) {<br>
+  verifyFormat("static SomeClass SC = { 1, 'a' };");<br>
+<br>
+  // FIXME: Format like enums if the static initializer does not fit on a line.<br>
+  verifyFormat(<br>
+      "static SomeClass WithALoooooooooooooooooooongName = { 100000000,\n"<br>
+      "    \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\" };");<br>
+}<br>
+<br>
 //===----------------------------------------------------------------------===//<br>
 // Line break tests.<br>
 //===----------------------------------------------------------------------===//<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu" class="cremed">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank" class="cremed">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div></div>