[cfe-commits] r173246 - in /cfe/trunk: include/clang/Format/Format.h lib/Format/Format.cpp unittests/Format/FormatTest.cpp
Daniel Jasper
djasper at google.com
Wed Jan 23 02:08:28 PST 2013
Author: djasper
Date: Wed Jan 23 04:08:28 2013
New Revision: 173246
URL: http://llvm.org/viewvc/llvm-project?rev=173246&view=rev
Log:
Add option to allow putting all parameters onto the next line.
This only affects styles where BinPackParameters is false.
With AllowAllParametersOnNextLine:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaa, aaaaaaaaaa, aaaaaaaaaa, aaaaaaaaaaa, aaaaaaaaaaa);
Without it:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaa,
aaaaaaaaaa,
aaaaaaaaaa,
aaaaaaaaaaa,
aaaaaaaaaaa);
Modified:
cfe/trunk/include/clang/Format/Format.h
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/include/clang/Format/Format.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=173246&r1=173245&r2=173246&view=diff
==============================================================================
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Wed Jan 23 04:08:28 2013
@@ -61,6 +61,10 @@
/// will either all be on the same line or will have one line each.
bool BinPackParameters;
+ /// \brief Allow putting all parameters of a function declaration/call onto
+ /// the next line without calling this bin-packing.
+ bool AllowAllParametersOnNextLine;
+
/// \brief If the constructor initializers don't fit on a line, put each
/// initializer on its own line.
bool ConstructorInitializerAllOnOneLineOrOnePerLine;
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=173246&r1=173245&r2=173246&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Wed Jan 23 04:08:28 2013
@@ -159,6 +159,7 @@
LLVMStyle.IndentCaseLabels = false;
LLVMStyle.SpacesBeforeTrailingComments = 1;
LLVMStyle.BinPackParameters = true;
+ LLVMStyle.AllowAllParametersOnNextLine = true;
LLVMStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = false;
LLVMStyle.AllowShortIfStatementsOnASingleLine = false;
LLVMStyle.ObjCSpaceBeforeProtocolList = true;
@@ -175,6 +176,7 @@
GoogleStyle.IndentCaseLabels = true;
GoogleStyle.SpacesBeforeTrailingComments = 2;
GoogleStyle.BinPackParameters = false;
+ GoogleStyle.AllowAllParametersOnNextLine = true;
GoogleStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
GoogleStyle.AllowShortIfStatementsOnASingleLine = false;
GoogleStyle.ObjCSpaceBeforeProtocolList = false;
@@ -183,7 +185,7 @@
FormatStyle getChromiumStyle() {
FormatStyle ChromiumStyle = getGoogleStyle();
- ChromiumStyle.AllowShortIfStatementsOnASingleLine = false;
+ ChromiumStyle.AllowAllParametersOnNextLine = false;
return ChromiumStyle;
}
@@ -607,12 +609,20 @@
if (Newline && Previous.is(tok::l_brace))
State.Stack.back().BreakBeforeClosingBrace = true;
- // If we are breaking after '(', '{', '<' or ',', we need to break after
- // future commas as well to avoid bin packing.
- if (!Style.BinPackParameters && Newline &&
- (Previous.is(tok::comma) || Previous.is(tok::l_paren) ||
- Previous.is(tok::l_brace) || Previous.Type == TT_TemplateOpener))
- State.Stack.back().BreakAfterComma = true;
+ if (!Style.BinPackParameters && Newline) {
+ // If we are breaking after '(', '{', '<', this is not bin packing unless
+ // AllowAllParametersOnNextLine is false.
+ if ((Previous.isNot(tok::l_paren) && Previous.isNot(tok::l_brace) &&
+ Previous.Type != TT_TemplateOpener) ||
+ !Style.AllowAllParametersOnNextLine)
+ State.Stack.back().BreakAfterComma = true;
+
+ // Any break on this level means that the parent level has been broken
+ // and we need to avoid bin packing there.
+ for (unsigned i = 0, e = State.Stack.size() - 1; i != e; ++i) {
+ State.Stack[i].BreakAfterComma = true;
+ }
+ }
moveStateToNextToken(State);
}
@@ -642,17 +652,6 @@
}
State.Stack.push_back(
ParenState(NewIndent, State.Stack.back().LastSpace));
-
- // If the entire set of parameters will not fit on the current line, we
- // will need to break after commas on this level to avoid bin-packing.
- if (!Style.BinPackParameters && Current.MatchingParen != NULL &&
- !Current.Children.empty()) {
- if (getColumnLimit() < State.Column + Current.FormatTok.TokenLength +
- Current.MatchingParen->TotalLength -
- Current.Children[0].TotalLength) {
- State.Stack.back().BreakAfterComma = true;
- }
- }
}
// If we encounter a closing ), ], } or >, we can remove a level from our
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=173246&r1=173245&r2=173246&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Jan 23 04:08:28 2013
@@ -964,9 +964,15 @@
" aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)));");
verifyGoogleFormat(
- "aaaaaaaaaaaaaaa(aaaaaaaaa,\n"
- " aaaaaaaaa,\n"
- " aaaaaaaaaaaaaaaaaaaaaaa).aaaaaaaaaaaaaaaaaa();");
+ "aaaaaaaaaaaaaaa(\n"
+ " aaaaaaaaa, aaaaaaaaa, aaaaaaaaaaaaaaaaaaaaa).aaaaaaaaaaaaaaaaaa();");
+ verifyGoogleFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
+ " aaaaaaaaaa, aaaaaaaaaa, aaaaaaaaaa, aaaaaaaaaaa);");
+
+ verifyGoogleFormat(
+ "aaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+ " aaaaaaaaaaaa,\n"
+ " aaaaaaaaaaaa);");
verifyGoogleFormat(
"somefunction(someotherFunction(ddddddddddddddddddddddddddddddddddd,\n"
" ddddddddddddddddddddddddddddd),\n"
@@ -979,6 +985,13 @@
verifyGoogleFormat("a(\"a\"\n"
" \"a\",\n"
" a);");
+
+ FormatStyle Style = getGoogleStyle();
+ Style.AllowAllParametersOnNextLine = false;
+ verifyFormat("aaaaaaaaaaaaaaa(aaaaaaaaa,\n"
+ " aaaaaaaaa,\n"
+ " aaaaaaaaaaaaaaaaaaaaa).aaaaaaaaaaaaaaaaaa();",
+ Style);
}
TEST_F(FormatTest, FormatsBuilderPattern) {
More information about the cfe-commits
mailing list