diff options
author | Daniel Jasper <djasper@google.com> | 2013-08-23 11:57:34 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-08-23 11:57:34 +0000 |
commit | f438cb761945d49111ed96fc3a25cc8e5da722a0 (patch) | |
tree | a903ac21705ac12ccf67c0fa58a53d1734ced763 /clang/lib/Format/ContinuationIndenter.cpp | |
parent | 377496bbaddcf6fdacbe3cd149a9ad1302bca99e (diff) | |
download | bcm5719-llvm-f438cb761945d49111ed96fc3a25cc8e5da722a0.tar.gz bcm5719-llvm-f438cb761945d49111ed96fc3a25cc8e5da722a0.zip |
clang-format: Fix corner case for string splitting ..
.. in conjunction with Style.AlwaysBreakBeforeMultilineStrings. Also,
simplify the implementation by handling newly split strings and already
split strings by the same code.
llvm-svn: 189102
Diffstat (limited to 'clang/lib/Format/ContinuationIndenter.cpp')
-rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 005eec82b7b..4f6fca9a2b8 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -116,12 +116,9 @@ bool ContinuationIndenter::mustBreak(const LineState &State) { !Current.isOneOf(tok::r_paren, tok::r_brace)) return true; if (Style.AlwaysBreakBeforeMultilineStrings && - State.Column > State.Stack.back().Indent && - Current.is(tok::string_literal) && Previous.isNot(tok::lessless) && - Previous.Type != TT_InlineASMColon && - ((Current.getNextNonComment() && - Current.getNextNonComment()->is(tok::string_literal)) || - (Current.TokenText.find("\\\n") != StringRef::npos))) + State.Column > State.Stack.back().Indent && // Breaking saves columns. + Previous.isNot(tok::lessless) && Previous.Type != TT_InlineASMColon && + NextIsMultilineString(State)) return true; if (!Style.BreakBeforeBinaryOperators) { @@ -547,13 +544,8 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State, } State.Column += Current.CodePointCount; - State.NextToken = State.NextToken->Next; - - unsigned Penalty = 0; - if (Newline || !Style.AlwaysBreakBeforeMultilineStrings || - Current.isNot(tok::string_literal) || !Current.CanBreakBefore) - Penalty += breakProtrudingToken(Current, State, DryRun); + unsigned Penalty = breakProtrudingToken(Current, State, DryRun); // If the previous has a special role, let it consume tokens as appropriate. // It is necessary to start at the previous token for the only implemented @@ -688,5 +680,19 @@ unsigned ContinuationIndenter::getColumnLimit() const { return Style.ColumnLimit - (Line.InPPDirective ? 2 : 0); } +bool ContinuationIndenter::NextIsMultilineString(const LineState &State) { + const FormatToken &Current = *State.NextToken; + if (!Current.is(tok::string_literal)) + return false; + if (Current.getNextNonComment() && + Current.getNextNonComment()->is(tok::string_literal)) + return true; // Implicit concatenation. + if (State.Column + Current.CodePointCount + Current.UnbreakableTailLength > + Style.ColumnLimit) + return true; // String will be split. + // String literal might have escaped newlines. + return Current.TokenText.find("\\\n") != StringRef::npos; +} + } // namespace format } // namespace clang |