summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/ContinuationIndenter.cpp
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2013-09-10 12:29:48 +0000
committerAlexander Kornienko <alexfh@google.com>2013-09-10 12:29:48 +0000
commit917f9e04b5ca1d0a2a331e8c2d57ef101a17fe00 (patch)
tree941395afbea77d66c1a765950e9a21ea2e66cc94 /clang/lib/Format/ContinuationIndenter.cpp
parent0e0498b288a9ba0125277558d8cc1024972fcc75 (diff)
downloadbcm5719-llvm-917f9e04b5ca1d0a2a331e8c2d57ef101a17fe00.tar.gz
bcm5719-llvm-917f9e04b5ca1d0a2a331e8c2d57ef101a17fe00.zip
Correctly calculate OriginalColumn after multi-line tokens.
Summary: This also unifies the handling of escaped newlines for all tokens. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D1638 llvm-svn: 190405
Diffstat (limited to 'clang/lib/Format/ContinuationIndenter.cpp')
-rw-r--r--clang/lib/Format/ContinuationIndenter.cpp26
1 files changed, 7 insertions, 19 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index 0b380041dfe..f1924c3776d 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -611,9 +611,8 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
return Penalty;
}
-unsigned
-ContinuationIndenter::addMultilineStringLiteral(const FormatToken &Current,
- LineState &State) {
+unsigned ContinuationIndenter::addMultilineToken(const FormatToken &Current,
+ LineState &State) {
// Break before further function parameters on all levels.
for (unsigned i = 0, e = State.Stack.size(); i != e; ++i)
State.Stack[i].BreakBeforeParameter = true;
@@ -631,6 +630,11 @@ ContinuationIndenter::addMultilineStringLiteral(const FormatToken &Current,
unsigned ContinuationIndenter::breakProtrudingToken(const FormatToken &Current,
LineState &State,
bool DryRun) {
+ // Don't break multi-line tokens other than block comments. Instead, just
+ // update the state.
+ if (Current.Type != TT_BlockComment && Current.IsMultiline)
+ return addMultilineToken(Current, State);
+
if (!Current.isOneOf(tok::string_literal, tok::comment))
return 0;
@@ -639,12 +643,6 @@ unsigned ContinuationIndenter::breakProtrudingToken(const FormatToken &Current,
if (Current.is(tok::string_literal) &&
Current.Type != TT_ImplicitStringLiteral) {
- // Don't break string literals with (in case of non-raw strings, escaped)
- // newlines. As clang-format must not change the string's content, it is
- // unlikely that we'll end up with a better format.
- if (Current.IsMultiline)
- return addMultilineStringLiteral(Current, State);
-
// Only break up default narrow strings.
if (!Current.TokenText.startswith("\""))
return 0;
@@ -662,16 +660,6 @@ unsigned ContinuationIndenter::breakProtrudingToken(const FormatToken &Current,
} else if (Current.Type == TT_LineComment &&
(Current.Previous == NULL ||
Current.Previous->Type != TT_ImplicitStringLiteral)) {
- // Don't break line comments with escaped newlines. These look like
- // separate line comments, but in fact contain a single line comment with
- // multiple lines including leading whitespace and the '//' markers.
- //
- // FIXME: If we want to handle them correctly, we'll need to adjust
- // leading whitespace in consecutive lines when changing indentation of
- // the first line similar to what we do with block comments.
- if (Current.IsMultiline)
- return 0;
-
Token.reset(new BreakableLineComment(
Current, StartColumn, State.Line->InPPDirective, Encoding, Style));
} else {
OpenPOWER on IntegriCloud