<div dir="ltr"><div class="gmail_default" style>On Sun, Jan 13, 2013 at 5:10 PM, Daniel Jasper <span dir="ltr"><<a href="mailto:djasper@google.com" target="_blank">djasper@google.com</a>></span> wrote:<br></div><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: Sun Jan 13 10:10:20 2013<br>
New Revision: 172361<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=172361&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=172361&view=rev</a><br>
Log:<br>
Stronger respect the input codes line breaks wrt. comments.<br>
<br>
clang-format should not change whether or not there is a line break<br>
before a line comment as this strongly influences the percieved binding.<br>
<br>
User input: void f(int a,<br>
// b is awesome<br>
int b);<br>
void g(int a, // a is awesome<br>
int b);<br>
Before: void f(int a, // b is awesome<br>
int b);<br>
void g(int a, // a is awesome<br>
int b);<br>
After: <unchanged from input><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=172361&r1=172360&r2=172361&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=172361&r1=172360&r2=172361&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Format/Format.cpp (original)<br>
+++ cfe/trunk/lib/Format/Format.cpp Sun Jan 13 10:10:20 2013<br>
@@ -901,9 +901,12 @@<br>
if (Current.FormatTok.MustBreakBefore) {<br>
Current.MustBreakBefore = true;<br>
} else {<br>
- if (Current.Type == TT_CtorInitializerColon || Current.Parent->Type ==<br>
- TT_LineComment || (Current.is(tok::string_literal) &&<br>
- Current.Parent->is(tok::string_literal))) {<br>
+ if (Current.Type == TT_LineComment) {<br>
+ Current.MustBreakBefore = Current.FormatTok.NewlinesBefore > 0;<br></blockquote><div><br></div><div style>I assume we don't care about escaped newlines here?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ } else if (Current.Type == TT_CtorInitializerColon ||<br>
+ Current.Parent->Type == TT_LineComment ||<br>
+ (Current.is(tok::string_literal) &&<br>
+ Current.Parent->is(tok::string_literal))) {<br>
Current.MustBreakBefore = true;<br>
} else {<br>
Current.MustBreakBefore = false;<br>
@@ -1219,7 +1222,10 @@<br>
return false;<br>
<br>
if (Right.is(tok::comment))<br>
- return !Right.Children.empty();<br>
+ // We rely on MustBreakBefore being set correctly here as we should not<br>
+ // change the "binding" behavior of a comment.<br>
+ return false;<br>
+<br>
if (Right.is(tok::r_paren) || Right.is(tok::l_brace) ||<br>
Right.is(tok::greater))<br>
return 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=172361&r1=172360&r2=172361&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=172361&r1=172360&r2=172361&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)<br>
+++ cfe/trunk/unittests/Format/FormatTest.cpp Sun Jan 13 10:10:20 2013<br>
@@ -285,6 +285,14 @@<br>
verifyFormat("void f() {\n"<br>
" // Doesn't do anything\n"<br>
"}");<br>
+ verifyFormat("void f(int i, // some comment (probably for i)\n"<br>
+ " int j, // some comment (probably for j)\n"<br>
+ " int k); // some comment (probably for k)");<br>
+ verifyFormat("void f(int i,\n"<br>
+ " // some comment (probably for j)\n"<br>
+ " int j,\n"<br>
+ " // some comment (probably for k)\n"<br>
+ " int k);");<br>
<br>
verifyFormat("int i // This is a fancy variable\n"<br>
" = 5;");<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>