<div dir="ltr">Yep. Thank you!</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jan 6, 2014 at 12:21 AM, Sean Silva <span dir="ltr"><<a href="mailto:silvas@purdue.edu" target="_blank">silvas@purdue.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thanks! Did you mean to close <<a href="http://llvm.org/bugs/show_bug.cgi?id=16517" target="_blank">http://llvm.org/bugs/show_bug.cgi?id=16517</a>>?<span class="HOEnZb"><font color="#888888"><div>
<br></div><div>-- Sean Silva</div></font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra">
<br><br><div class="gmail_quote">On Sun, Jan 5, 2014 at 5:38 AM, 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: Sun Jan 5 06:38:10 2014<br>
New Revision: 198558<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=198558&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=198558&view=rev</a><br>
Log:<br>
clang-format: Allow formatting short enums on a single line.<br>
<br>
Before:<br>
enum ShortEnum {<br>
A,<br>
B,<br>
C<br>
};<br>
<br>
After:<br>
enum ShortEnum { A, B, C };<br>
<br>
This seems to be the predominant choice in LLVM/Clang as well as in<br>
Google style.<br>
<br>
Modified:<br>
cfe/trunk/lib/Format/ContinuationIndenter.cpp<br>
cfe/trunk/lib/Format/TokenAnnotator.cpp<br>
cfe/trunk/unittests/Format/FormatTest.cpp<br>
<br>
Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=198558&r1=198557&r2=198558&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=198558&r1=198557&r2=198558&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)<br>
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Sun Jan 5 06:38:10 2014<br>
@@ -182,10 +182,6 @@ bool ContinuationIndenter::mustBreak(con<br>
State.Stack.back().ObjCSelectorNameFound &&<br>
State.Stack.back().BreakBeforeParameter)<br>
return true;<br>
- if (Current.Type == TT_CtorInitializerColon &&<br>
- (!Style.AllowShortFunctionsOnASingleLine ||<br>
- Style.BreakConstructorInitializersBeforeComma || Style.ColumnLimit != 0))<br>
- return true;<br>
if (Previous.ClosesTemplateDeclaration && State.ParenLevel == 0 &&<br>
!Current.isTrailingComment())<br>
return true;<br>
@@ -199,6 +195,18 @@ bool ContinuationIndenter::mustBreak(con<br>
(State.Stack.back().BreakBeforeParameter &&<br>
State.Stack.back().ContainsUnwrappedBuilder)))<br>
return true;<br>
+<br>
+ // The following could be precomputed as they do not depend on the state.<br>
+ // However, as they should take effect only if the UnwrappedLine does not fit<br>
+ // into the ColumnLimit, they are checked here in the ContinuationIndenter.<br>
+ if (Previous.BlockKind == BK_Block && Previous.is(tok::l_brace) &&<br>
+ !Current.isOneOf(tok::r_brace, tok::comment))<br>
+ return true;<br>
+ if (Current.Type == TT_CtorInitializerColon &&<br>
+ (!Style.AllowShortFunctionsOnASingleLine ||<br>
+ Style.BreakConstructorInitializersBeforeComma || Style.ColumnLimit != 0))<br>
+ return true;<br>
+<br>
return false;<br>
}<br>
<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=198558&r1=198557&r2=198558&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=198558&r1=198557&r2=198558&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)<br>
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Sun Jan 5 06:38:10 2014<br>
@@ -1438,9 +1438,6 @@ bool TokenAnnotator::mustBreakBefore(con<br>
Style.BreakConstructorInitializersBeforeComma &&<br>
!Style.ConstructorInitializerAllOnOneLineOrOnePerLine) {<br>
return true;<br>
- } else if (Right.Previous->BlockKind == BK_Block &&<br>
- Right.Previous->isNot(tok::r_brace) && Right.isNot(tok::r_brace)) {<br>
- return true;<br>
} else if (Right.is(tok::l_brace) && (Right.BlockKind == BK_Block)) {<br>
return Style.BreakBeforeBraces == FormatStyle::BS_Allman ||<br>
Style.BreakBeforeBraces == FormatStyle::BS_GNU;<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=198558&r1=198557&r2=198558&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=198558&r1=198557&r2=198558&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)<br>
+++ cfe/trunk/unittests/Format/FormatTest.cpp Sun Jan 5 06:38:10 2014<br>
@@ -1650,18 +1650,21 @@ TEST_F(FormatTest, FormatsEnum) {<br>
verifyFormat("enum X f() {\n a();\n return 42;\n}");<br>
verifyFormat("enum {\n"<br>
" Bar = Foo<int, int>::value\n"<br>
- "};");<br>
+ "};",<br>
+ getLLVMStyleWithColumns(30));<br>
+<br>
+ verifyFormat("enum ShortEnum { A, B, C };");<br>
}<br>
<br>
TEST_F(FormatTest, FormatsEnumsWithErrors) {<br>
verifyFormat("enum Type {\n"<br>
- " One = 0;\n" // These semicolons should be commas.<br>
+ " One = 0; // These semicolons should be commas.\n"<br>
" Two = 1;\n"<br>
"};");<br>
verifyFormat("namespace n {\n"<br>
"enum Type {\n"<br>
" One,\n"<br>
- " Two,\n" // missing };<br>
+ " Two, // missing };\n"<br>
" int i;\n"<br>
"}\n"<br>
"void g() {}");<br>
@@ -1703,13 +1706,11 @@ TEST_F(FormatTest, FormatsEnumClass) {<br>
<br>
TEST_F(FormatTest, FormatsEnumTypes) {<br>
verifyFormat("enum X : int {\n"<br>
- " A,\n"<br>
- " B\n"<br>
- "};");<br>
- verifyFormat("enum X : std::uint32_t {\n"<br>
- " A,\n"<br>
+ " A, // Force multiple lines.\n"<br>
" B\n"<br>
"};");<br>
+ verifyFormat("enum X : int { A, B };");<br>
+ verifyFormat("enum X : std::uint32_t { A, B };");<br>
}<br>
<br>
TEST_F(FormatTest, FormatsBitfields) {<br>
@@ -6605,7 +6606,7 @@ TEST_F(FormatTest, ConfigurableUseOfTab)<br>
"};",<br>
Tab);<br>
verifyFormat("enum A {\n"<br>
- "\ta1,\n"<br>
+ "\ta1, // Force multiple lines\n"<br>
"\ta2,\n"<br>
"\ta3\n"<br>
"};",<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">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></div></blockquote></div><br></div>