diff options
author | Daniel Jasper <djasper@google.com> | 2014-03-27 16:14:13 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2014-03-27 16:14:13 +0000 |
commit | 5d2587daa2b5218094fbe7c2395a49e87f9bd29f (patch) | |
tree | 777ada61232f53fd418eb2535e4f7d9403406039 /clang/lib/Format/ContinuationIndenter.cpp | |
parent | 9ee0e303d68054a8fdb1b071a7de6ddcc8b9ecd9 (diff) | |
download | bcm5719-llvm-5d2587daa2b5218094fbe7c2395a49e87f9bd29f.tar.gz bcm5719-llvm-5d2587daa2b5218094fbe7c2395a49e87f9bd29f.zip |
clang-format: Avoid line-breaks that increase the current column.
While these might make sense for some rule (e.g. break after multi-line
operand), they generally appear ugly and confusing.
Before:
fffffffffff(R\"x(
multiline raw string literal xxxxxxxxxxxxxx
)x\" + bbbbbb)
After:
fffffffffff(R\"x(
multiline raw string literal xxxxxxxxxxxxxx
)x\" +
bbbbbb)
llvm-svn: 204937
Diffstat (limited to 'clang/lib/Format/ContinuationIndenter.cpp')
-rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 55d700fd805..a8ab72c4ca5 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -144,7 +144,13 @@ bool ContinuationIndenter::mustBreak(const LineState &State) { Previous.Type == TT_ArrayInitializerLSquare) && getLengthToMatchingParen(Previous) + State.Column > getColumnLimit(State)) return true; + if (Current.Type == TT_CtorInitializerColon && + (!Style.AllowShortFunctionsOnASingleLine || + Style.BreakConstructorInitializersBeforeComma || Style.ColumnLimit != 0)) + return true; + if (State.Column < getNewLineColumn(State)) + return false; if (!Style.BreakBeforeBinaryOperators) { // If we need to break somewhere inside the LHS of a binary expression, we // should also break after the operator. Otherwise, the formatting would @@ -204,10 +210,6 @@ bool ContinuationIndenter::mustBreak(const LineState &State) { if (Previous.BlockKind == BK_Block && Previous.is(tok::l_brace) && !Current.isOneOf(tok::r_brace, tok::comment)) return true; - if (Current.Type == TT_CtorInitializerColon && - (!Style.AllowShortFunctionsOnASingleLine || - Style.BreakConstructorInitializersBeforeComma || Style.ColumnLimit != 0)) - return true; return false; } @@ -446,6 +448,8 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State, } unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) { + if (!State.NextToken || !State.NextToken->Previous) + return 0; FormatToken &Current = *State.NextToken; const FormatToken &Previous = *State.NextToken->Previous; // If we are continuing an expression, we want to use the continuation indent. @@ -528,7 +532,7 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) { return State.FirstIndent + Style.ConstructorInitializerIndentWidth; if (NextNonComment->Type == TT_CtorInitializerComma) return State.Stack.back().Indent; - if (State.Stack.back().Indent == State.FirstIndent && + if (State.Stack.back().Indent == State.FirstIndent && PreviousNonComment && PreviousNonComment->isNot(tok::r_brace)) // Ensure that we fall back to the continuation indent width instead of // just flushing continuations left. |