<div dir="ltr">On Wed, Mar 13, 2013 at 8:53 AM, Daniel Jasper <span dir="ltr"><<a href="mailto:djasper@google.com" target="_blank">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: Wed Mar 13 10:53:12 2013<br>
New Revision: 176953<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=176953&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=176953&view=rev</a><br>
Log:<br>
Fix comment indentation before labels.<br>
<br>
Before:<br>
switch (x) {<br>
  // if 1, do f()<br>
case 1:<br>
  f();<br>
}<br>
<br>
After:<br>
switch (x) {<br>
// if 1, do f()<br>
case 1:<br>
  f();<br>
}<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=176953&r1=176952&r2=176953&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=176953&r1=176952&r2=176953&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/lib/Format/Format.cpp (original)<br>
+++ cfe/trunk/lib/Format/Format.cpp Wed Mar 13 10:53:12 2013<br>
@@ -1135,6 +1135,13 @@ public:<br>
     deriveLocalStyle();<br>
     for (unsigned i = 0, e = AnnotatedLines.size(); i != e; ++i) {<br>
       Annotator.calculateFormattingInformation(AnnotatedLines[i]);<br>
+<br>
+      // Adapt level to the next line if this is a comment.<br>
+      // FIXME: Can/should this be done in the UnwrappedLineParser?<br></blockquote><div><br></div><div style>My gut feeling is: yes.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

+      if (i + 1 != e && AnnotatedLines[i].First.is(tok::comment) &&<br>
+          AnnotatedLines[i].First.Children.empty() &&<br>
+          AnnotatedLines[i + 1].First.isNot(tok::r_brace))<br>
+        AnnotatedLines[i].Level = AnnotatedLines[i + 1].Level;<br>
     }<br>
     std::vector<int> IndentForLevel;<br>
     bool PreviousLineWasTouched = false;<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=176953&r1=176952&r2=176953&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=176953&r1=176952&r2=176953&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)<br>
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Mar 13 10:53:12 2013<br>
@@ -427,6 +427,11 @@ TEST_F(FormatTest, FormatsSwitchStatemen<br>
                "default: {\n"<br>
                "  // Do nothing.\n"<br>
                "}");<br>
+  verifyFormat("switch (x) {\n"<br>
+               "// if 1, do f()\n"<br>
+               "case 1:\n"<br>
+               "  f();\n"<br>
+               "}");<br>
<br>
   verifyGoogleFormat("switch (x) {\n"<br>
                      "  case 1:\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></div>