summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
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
commitdc7d5817e2932b295007c2951a11fe021df15b92 (patch)
treeea4d1c44d480c9712ebdd202b691fd6965561229 /clang/lib/Format
parent0ccdd1315b74e9a5aaf1b967dd2d7967e24211b8 (diff)
downloadbcm5719-llvm-dc7d5817e2932b295007c2951a11fe021df15b92.tar.gz
bcm5719-llvm-dc7d5817e2932b295007c2951a11fe021df15b92.zip
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 }; llvm-svn: 175620
Diffstat (limited to 'clang/lib/Format')
-rw-r--r--clang/lib/Format/Format.cpp15
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp4
2 files changed, 12 insertions, 7 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 21f32d257c1..625f93151ff 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/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);
}
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index ac7301eebd0..2bce7c0f349 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -266,7 +266,7 @@ private:
}
return true;
}
-
+
void updateParameterCount(AnnotatedToken *Left, AnnotatedToken *Current) {
if (Current->is(tok::comma))
++Left->ParameterCount;
@@ -835,6 +835,8 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) {
Current->Parent->is(tok::string_literal) &&
Current->Children[0].is(tok::string_literal)) {
Current->MustBreakBefore = true;
+ } else if (Current->FormatTok.NewlinesBefore > 1) {
+ Current->MustBreakBefore = true;
} else {
Current->MustBreakBefore = false;
}
OpenPOWER on IntegriCloud