r174363 - Fix some linebreak decisions in Google format.
Daniel Jasper
djasper at google.com
Tue Feb 5 01:41:22 PST 2013
Author: djasper
Date: Tue Feb 5 03:41:21 2013
New Revision: 174363
URL: http://llvm.org/viewvc/llvm-project?rev=174363&view=rev
Log:
Fix some linebreak decisions in Google format.
Before:
f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa +
aaaaaaaaaaaaaaaaaaaa);
aaaaaaa(aaaaaaaaaaaaa, aaaaaaaaaaaaa, aaaaaaaaaaaaa(aaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaa));
After:
f(aaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaa);
aaaaaaa(aaaaaaaaaaaaa,
aaaaaaaaaaaaa,
aaaaaaaaaaaaa(aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaa));
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=174363&r1=174362&r2=174363&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Tue Feb 5 03:41:21 2013
@@ -229,8 +229,9 @@ public:
LineState State;
State.Column = FirstIndent;
State.NextToken = &RootToken;
- State.Stack.push_back(ParenState(FirstIndent + 4, FirstIndent,
- !Style.BinPackParameters));
+ State.Stack.push_back(
+ ParenState(FirstIndent + 4, FirstIndent, !Style.BinPackParameters,
+ /*HasMultiParameterLine=*/ false));
State.VariablePos = 0;
State.LineContainsContinuedForLoopSection = false;
@@ -262,11 +263,12 @@ private:
}
struct ParenState {
- ParenState(unsigned Indent, unsigned LastSpace, bool AvoidBinPacking)
+ ParenState(unsigned Indent, unsigned LastSpace, bool AvoidBinPacking,
+ bool HasMultiParameterLine)
: Indent(Indent), LastSpace(LastSpace), AssignmentColumn(0),
FirstLessLess(0), BreakBeforeClosingBrace(false), QuestionColumn(0),
AvoidBinPacking(AvoidBinPacking), BreakAfterComma(false),
- HasMultiParameterLine(false) {
+ HasMultiParameterLine(HasMultiParameterLine) {
}
/// \brief The position to which a specific parenthesis level needs to be
@@ -554,8 +556,9 @@ private:
NewIndent = 4 + State.Stack.back().LastSpace;
AvoidBinPacking = !Style.BinPackParameters;
}
- State.Stack.push_back(ParenState(NewIndent, State.Stack.back().LastSpace,
- AvoidBinPacking));
+ State.Stack.push_back(
+ ParenState(NewIndent, State.Stack.back().LastSpace, AvoidBinPacking,
+ State.Stack.back().HasMultiParameterLine));
}
// If we encounter a closing ), ], } or >, we can remove a level from our
@@ -676,8 +679,7 @@ private:
return false;
// Trying to insert a parameter on a new line if there are already more than
// one parameter on the current line is bin packing.
- if (State.NextToken->Parent->is(tok::comma) &&
- State.Stack.back().HasMultiParameterLine &&
+ if (State.Stack.back().HasMultiParameterLine &&
State.Stack.back().AvoidBinPacking)
return false;
return true;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=174363&r1=174362&r2=174363&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Feb 5 03:41:21 2013
@@ -1093,6 +1093,13 @@ TEST_F(FormatTest, BreaksDesireably) {
}
TEST_F(FormatTest, FormatsOneParameterPerLineIfNecessary) {
+ verifyGoogleFormat("f(aaaaaaaaaaaaaaaaaaaa,\n"
+ " aaaaaaaaaaaaaaaaaaaa,\n"
+ " aaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaa);");
+ verifyGoogleFormat(
+ "aaaaaaa(aaaaaaaaaaaaa,\n"
+ " aaaaaaaaaaaaa,\n"
+ " aaaaaaaaaaaaa(aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaa));");
verifyGoogleFormat(
"aaaaaaaa(aaaaaaaaaaaaa,\n"
" aaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
More information about the cfe-commits
mailing list