<div dir="ltr">On Fri, Oct 18, 2013 at 9:34 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: Fri Oct 18 11:34:40 2013<br>
New Revision: 192983<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=192983&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=192983&view=rev</a><br>
Log:<br>
Make clang-format slightly more willing to break before trailing annotations.<br>
<br>
Specifically, prefer breaking before trailing annotations over breaking<br>
before the first parameter.<br>
<br>
Before:<br>
void ffffffffffffffffffffffff(<br>
int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,<br>
int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) OVERRIDE;<br>
<br>
After:<br>
void ffffffffffffffffffffffff(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,<br>
int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)<br>
OVERRIDE;<br>
<br>
Modified:<br>
cfe/trunk/lib/Format/TokenAnnotator.cpp<br>
cfe/trunk/unittests/Format/FormatTest.cpp<br>
<br>
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=192983&r1=192982&r2=192983&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=192983&r1=192982&r2=192983&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)<br>
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Oct 18 11:34:40 2013<br>
@@ -1157,7 +1157,7 @@ unsigned TokenAnnotator::splitPenalty(co<br>
if (Left.is(tok::r_paren) && Line.Type != LT_ObjCProperty &&<br>
(Right.is(tok::kw_const) || (Right.is(tok::identifier) && Right.Next &&<br>
Right.Next->isNot(tok::l_paren))))<br>
- return 150;<br>
+ return 100;<br></blockquote><div><br></div><div>Black magic! :)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
// In for-loops, prefer breaking at ',' and ';'.<br>
if (Line.First->is(tok::kw_for) && Left.is(tok::equal))<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=192983&r1=192982&r2=192983&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=192983&r1=192982&r2=192983&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)<br>
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Oct 18 11:34:40 2013<br>
@@ -2840,33 +2840,36 @@ TEST_F(FormatTest, TrailingReturnType) {<br>
}<br>
<br>
TEST_F(FormatTest, BreaksFunctionDeclarationsWithTrailingTokens) {<br>
- // Avoid breaking before trailing 'const'.<br>
- verifyFormat("void someLongFunction(\n"<br>
- " int someLongParameter) const {}",<br>
- getLLVMStyleWithColumns(46));<br>
+ // Avoid breaking before trailing 'const' or other trailing annotations, if<br>
+ // they are not function-like.<br>
FormatStyle Style = getGoogleStyle();<br>
Style.ColumnLimit = 47;<br>
verifyFormat("void\n"<br>
"someLongFunction(int someLongParameter) const {\n}",<br>
getLLVMStyleWithColumns(47));<br>
- verifyFormat("void someLongFunction(\n"<br>
- " int someLongParameter) const {}",<br>
- Style);<br>
verifyFormat("LoooooongReturnType\n"<br>
"someLoooooooongFunction() const {}",<br>
getLLVMStyleWithColumns(47));<br>
verifyFormat("LoooooongReturnType someLoooooooongFunction()\n"<br>
" const {}",<br>
Style);<br>
+ verifyFormat("void SomeFunction(aaaaa aaaaaaaaaaaaaaaaaaaa,\n"<br>
+ " aaaaa aaaaaaaaaaaaaaaaaaaa) OVERRIDE;");<br>
+ verifyFormat("void SomeFunction(aaaaa aaaaaaaaaaaaaaaaaaaa,\n"<br>
+ " aaaaa aaaaaaaaaaaaaaaaaaaa) OVERRIDE FINAL;");<br>
+ verifyFormat("void SomeFunction(aaaaa aaaaaaaaaaaaaaaaaaaa,\n"<br>
+ " aaaaa aaaaaaaaaaaaaaaaaaaa) override final;");<br>
<br>
- // Avoid breaking before other trailing annotations, if they are not<br>
- // function-like.<br>
- verifyFormat("void SomeFunction(aaaaaaaaaaaaaaaaaaaaaaaaaa,\n"<br>
- " aaaaaaaaaaaaaaaaaaaaaaaaaa) OVERRIDE;");<br>
- verifyFormat("void SomeFunction(aaaaaaaaaaaaaaaaaaaaaaaaaa,\n"<br>
- " aaaaaaaaaaaaaaaaaaaaaaaaaa) OVERRIDE FINAL;");<br>
- verifyFormat("void SomeFunction(aaaaaaaaaaaaaaaaaaaaaaaaaa,\n"<br>
- " aaaaaaaaaaaaaaaaaaaaaaaaaa) override final;");<br>
+ // Unless this would lead to the first parameter being broken.<br>
+ verifyFormat("void someLongFunction(int someLongParameter)\n"<br>
+ " const {}",<br>
+ getLLVMStyleWithColumns(46));<br>
+ verifyFormat("void someLongFunction(int someLongParameter)\n"<br>
+ " const {}",<br>
+ Style);<br>
+ verifyFormat("void SomeFunction(aaaaaaaaaa aaaaaaaaaaaaaaa,\n"<br>
+ " aaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"<br>
+ " LONG_AND_UGLY_ANNOTATION;");<br>
<br>
// Breaking before function-like trailing annotations is fine to keep them<br>
// close to their arguments.<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>