<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Dec 24, 2013 at 2:31 PM, 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: Tue Dec 24 07:31:25 2013<br>
New Revision: 197980<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=197980&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=197980&view=rev</a><br>
Log:<br>
clang-format: (WebKit) Disallow 1-line constructors with initializers.<br>
<br>
Before:<br>
Constructor() : a(a) {}<br>
<br>
After:<br>
Constructor()<br>
: a(a)<br>
{<br>
}<br>
<br>
This style guide is pretty precise about this.<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=197980&r1=197979&r2=197980&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=197980&r1=197979&r2=197980&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Format/Format.cpp (original)<br>
+++ cfe/trunk/lib/Format/Format.cpp Tue Dec 24 07:31:25 2013<br>
@@ -480,7 +480,7 @@ public:<br>
SmallVectorImpl<AnnotatedLine *>::const_iterator I,<br>
SmallVectorImpl<AnnotatedLine *>::const_iterator E) {<br>
// We can never merge stuff if there are trailing line comments.<br>
- AnnotatedLine *TheLine = *I;<br>
+ const AnnotatedLine *TheLine = *I;<br>
if (TheLine->Last->Type == TT_LineComment)<br>
return 0;<br>
<br>
@@ -498,7 +498,8 @@ public:<br>
if (I + 1 == E || I[1]->Type == LT_Invalid)<br>
return 0;<br>
<br>
- if (TheLine->Last->Type == TT_FunctionLBrace) {<br>
+ if (TheLine->Last->Type == TT_FunctionLBrace &&<br>
+ TheLine->First != TheLine->Last) {<br>
return Style.AllowShortFunctionsOnASingleLine<br>
? tryMergeSimpleBlock(I, E, Limit)<br>
: 0;<br>
@@ -510,9 +511,11 @@ public:<br>
}<br>
if (I[1]->First->Type == TT_FunctionLBrace &&<br>
Style.BreakBeforeBraces != FormatStyle::BS_Attach) {<br>
- // Reduce the column limit by the number of spaces we need to insert<br>
- // around braces.<br>
- Limit = Limit > 3 ? Limit - 3 : 0;<br>
+ // Check for Limit <= 2 to accomodate for the " {".<br></blockquote><div><br></div><div>So why don't we need to account for the full " { "?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ if (Limit <= 2 || (Style.ColumnLimit == 0 && containsMustBreak(TheLine)))<br>
+ return 0;<br>
+ Limit -= 2;<br>
+<br>
unsigned MergedLines = 0;<br>
if (Style.AllowShortFunctionsOnASingleLine) {<br>
MergedLines = tryMergeSimpleBlock(I + 1, E, Limit);<br>
@@ -641,6 +644,14 @@ private:<br>
return 1 + I[1]->Last->TotalLength + 1 + I[2]->Last->TotalLength <= Limit;<br>
}<br>
<br>
+ bool containsMustBreak(const AnnotatedLine *Line) {<br>
+ for (const FormatToken *Tok = Line->First; Tok; Tok = Tok->Next) {<br>
+ if (Tok->MustBreakBefore)<br>
+ return true;<br>
+ }<br>
+ return false;<br>
+ }<br>
+<br>
const FormatStyle &Style;<br>
};<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=197980&r1=197979&r2=197980&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=197980&r1=197979&r2=197980&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)<br>
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Dec 24 07:31:25 2013<br>
@@ -6997,6 +6997,16 @@ TEST_F(FormatTest, AllmanBraceBreaking)<br>
"}\n",<br>
BreakBeforeBrace);<br>
<br>
+ BreakBeforeBrace.ColumnLimit = 19;<br>
+ verifyFormat("void f() { int i; }", BreakBeforeBrace);<br>
+ BreakBeforeBrace.ColumnLimit = 18;<br>
+ verifyFormat("void f()\n"<br>
+ "{\n"<br>
+ " int i;\n"<br>
+ "}",<br>
+ BreakBeforeBrace);<br>
+ BreakBeforeBrace.ColumnLimit = 80;<br>
+<br>
FormatStyle BreakBeforeBraceShortIfs = BreakBeforeBrace;<br>
BreakBeforeBraceShortIfs.AllowShortIfStatementsOnASingleLine = true;<br>
BreakBeforeBraceShortIfs.AllowShortLoopsOnASingleLine = true;<br>
@@ -7716,16 +7726,26 @@ TEST_F(FormatTest, FormatsWithWebKitStyl<br>
" : aaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"<br>
" , aaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaa, // break\n"<br>
" aaaaaaaaaaaaaa)\n"<br>
- " , aaaaaaaaaaaaaaaaaaaaaaa() {}",<br>
+ " , aaaaaaaaaaaaaaaaaaaaaaa()\n"<br>
+ "{\n"<br>
+ "}",<br>
Style);<br>
verifyFormat("SomeClass::Constructor()\n"<br>
- " : a(a) {}",<br>
+ " : a(a)\n"<br>
+ "{\n"<br>
+ "}",<br>
Style);<br>
+ EXPECT_EQ("SomeClass::Constructor()\n"<br>
+ " : a(a)\n"<br>
+ "{\n"<br>
+ "}",<br>
+ format("SomeClass::Constructor():a(a){}", Style));<br>
verifyFormat("SomeClass::Constructor()\n"<br>
" : a(a)\n"<br>
" , b(b)\n"<br>
- " , c(c) {}",<br>
- Style);<br>
+ " , c(c)\n"<br>
+ "{\n"<br>
+ "}", Style);<br>
verifyFormat("SomeClass::Constructor()\n"<br>
" : a(a)\n"<br>
"{\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>