aboutsummaryrefslogtreecommitdiff
path: root/lib/Format/Format.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Format/Format.cpp')
-rw-r--r--lib/Format/Format.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index 939211cf65..ee3516af0c 100644
--- a/lib/Format/Format.cpp
+++ b/lib/Format/Format.cpp
@@ -251,6 +251,7 @@ public:
State.VariablePos = 0;
State.LineContainsContinuedForLoopSection = false;
State.ParenLevel = 0;
+ State.StartOfLineLevel = State.ParenLevel;
DEBUG({
DebugTokenState(*State.NextToken);
@@ -384,6 +385,9 @@ private:
/// \brief The level of nesting inside (), [], <> and {}.
unsigned ParenLevel;
+ /// \brief The \c ParenLevel at the start of this line.
+ unsigned StartOfLineLevel;
+
/// \brief A stack keeping track of properties applying to parenthesis
/// levels.
std::vector<ParenState> Stack;
@@ -401,6 +405,8 @@ private:
return LineContainsContinuedForLoopSection;
if (Other.ParenLevel != ParenLevel)
return Other.ParenLevel < ParenLevel;
+ if (Other.StartOfLineLevel < StartOfLineLevel)
+ return Other.StartOfLineLevel < StartOfLineLevel;
return Other.Stack < Stack;
}
};
@@ -489,6 +495,7 @@ private:
}
State.Stack.back().LastSpace = State.Column;
+ State.StartOfLineLevel = State.ParenLevel;
if (Current.is(tok::colon) && Current.Type != TT_ConditionalExpr)
State.Stack.back().Indent += 2;
} else {
@@ -772,6 +779,14 @@ private:
!(State.NextToken->is(tok::r_brace) &&
State.Stack.back().BreakBeforeClosingBrace))
return false;
+ // This prevents breaks like:
+ // ...
+ // SomeParameter, OtherParameter).DoSomething(
+ // ...
+ // As they hide "DoSomething" and generally bad for readability.
+ if (State.NextToken->Parent->is(tok::l_paren) &&
+ State.ParenLevel <= State.StartOfLineLevel)
+ 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.Stack.back().HasMultiParameterLine &&