summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/ContinuationIndenter.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-11-20 14:54:39 +0000
committerDaniel Jasper <djasper@google.com>2013-11-20 14:54:39 +0000
commit48437ce508df1badb71467dc3cc42aa22d3b5d1e (patch)
treeb49f62c449b96cc059c7586921120f38f827d538 /clang/lib/Format/ContinuationIndenter.cpp
parentf93e8152c4834c3e25932d7ae8d7be98ce2ab3eb (diff)
downloadbcm5719-llvm-48437ce508df1badb71467dc3cc42aa22d3b5d1e.tar.gz
bcm5719-llvm-48437ce508df1badb71467dc3cc42aa22d3b5d1e.zip
Simplify fix proposed in r195240.
llvm-svn: 195253
Diffstat (limited to 'clang/lib/Format/ContinuationIndenter.cpp')
-rw-r--r--clang/lib/Format/ContinuationIndenter.cpp24
1 files changed, 8 insertions, 16 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index bbc1ac53824..c8b8b7e8f3c 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -224,14 +224,13 @@ unsigned ContinuationIndenter::addTokenToState(LineState &State, bool Newline,
if (Newline)
Penalty = addTokenOnNewLine(State, DryRun);
else
- Penalty = addTokenOnCurrentLine(State, DryRun, ExtraSpaces);
+ addTokenOnCurrentLine(State, DryRun, ExtraSpaces);
return moveStateToNextToken(State, DryRun, Newline) + Penalty;
}
-unsigned ContinuationIndenter::addTokenOnCurrentLine(LineState &State,
- bool DryRun,
- unsigned ExtraSpaces) {
+void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
+ unsigned ExtraSpaces) {
FormatToken &Current = *State.NextToken;
const FormatToken &Previous = *State.NextToken->Previous;
if (Current.is(tok::equal) &&
@@ -250,15 +249,6 @@ unsigned ContinuationIndenter::addTokenOnCurrentLine(LineState &State,
State.Stack.back().LastSpace = State.Stack.back().VariablePos;
}
- unsigned Penalty = 0;
- // A break before a "<<" will get Style.PenaltyBreakFirstLessLess, so a
- // continuation with "<<" has a smaller penalty in general.
- // If the LHS is long, we don't want to penalize the break though, so we
- // also add Style.PenaltyBreakFirstLessLess.
- if (Current.is(tok::lessless) && State.Stack.back().FirstLessLess == 0 &&
- State.Column > Style.ColumnLimit / 2)
- Penalty += Style.PenaltyBreakFirstLessLess;
-
unsigned Spaces = Current.SpacesRequiredBefore + ExtraSpaces;
if (!DryRun)
@@ -317,7 +307,6 @@ unsigned ContinuationIndenter::addTokenOnCurrentLine(LineState &State,
State.Stack[State.Stack.size() - 2].CallContinuation == 0)
State.Stack.back().LastSpace = State.Column;
}
- return Penalty;
}
unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
@@ -343,8 +332,11 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
Penalty += State.NextToken->SplitPenalty;
// Breaking before the first "<<" is generally not desirable if the LHS is
- // short (not breaking with a long LHS is penalized in addTokenOnCurrentLine).
- if (Current.is(tok::lessless) && State.Stack.back().FirstLessLess == 0)
+ // short. Also always add the penalty if the LHS is split over mutliple lines
+ // to avoid unncessary line breaks that just work around this penalty.
+ if (Current.is(tok::lessless) && State.Stack.back().FirstLessLess == 0 &&
+ (State.Column <= Style.ColumnLimit / 2 ||
+ State.Stack.back().BreakBeforeParameter))
Penalty += Style.PenaltyBreakFirstLessLess;
if (Current.is(tok::l_brace) && Current.BlockKind == BK_Block) {
OpenPOWER on IntegriCloud