aboutsummaryrefslogtreecommitdiff
path: root/lib/Format/Format.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-02-20 12:56:39 +0000
committerDaniel Jasper <djasper@google.com>2013-02-20 12:56:39 +0000
commitc4615b7aaf97e303a4fc675956f7f5572d492885 (patch)
tree77430a4d47484d505b20c7f635da4c9efc545dc3 /lib/Format/Format.cpp
parent8092a940922f307edb569036a3bb6bb722fb3a3d (diff)
Don't remove blank lines within unwrapped lines.
If the code author decides to put empty lines anywhere into the code we should treat them equally, i.e. reduce them to the configured MaxEmptyLinesToKeep. With this change, we e.g. keep the newline in: SomeType ST = { // First value a, // Second value b }; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175620 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/Format.cpp')
-rw-r--r--lib/Format/Format.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index 21f32d257c..625f93151f 100644
--- a/lib/Format/Format.cpp
+++ b/lib/Format/Format.cpp
@@ -278,9 +278,9 @@ public:
LineState State;
State.Column = FirstIndent;
State.NextToken = &RootToken;
- State.Stack.push_back(
- ParenState(FirstIndent + 4, FirstIndent, !Style.BinPackParameters,
- /*HasMultiParameterLine=*/ false));
+ State.Stack.push_back(ParenState(FirstIndent + 4, FirstIndent,
+ !Style.BinPackParameters,
+ /*HasMultiParameterLine=*/ false));
State.VariablePos = 0;
State.LineContainsContinuedForLoopSection = false;
State.ParenLevel = 0;
@@ -368,7 +368,7 @@ private:
/// \brief The position of the colon in an ObjC method declaration/call.
unsigned ColonPos;
-
+
/// \brief Break before third operand in ternary expression.
bool BreakBeforeThirdOperand;
@@ -520,11 +520,14 @@ private:
State.LineContainsContinuedForLoopSection = Previous.isNot(tok::semi);
if (!DryRun) {
+ unsigned NewLines =
+ std::max(1u, std::min(Current.FormatTok.NewlinesBefore,
+ Style.MaxEmptyLinesToKeep + 1));
if (!Line.InPPDirective)
- Whitespaces.replaceWhitespace(Current, 1, State.Column,
+ Whitespaces.replaceWhitespace(Current, NewLines, State.Column,
WhitespaceStartColumn, Style);
else
- Whitespaces.replacePPWhitespace(Current, 1, State.Column,
+ Whitespaces.replacePPWhitespace(Current, NewLines, State.Column,
WhitespaceStartColumn, Style);
}