diff options
author | Daniel Jasper <djasper@google.com> | 2014-12-02 09:46:56 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2014-12-02 09:46:56 +0000 |
commit | 8c6e9ef676c92e554c47ddbf7db09bcf9af81692 (patch) | |
tree | 23619a165a0f8318176af0309ed282a31df5b9cb /clang/lib/Format/ContinuationIndenter.cpp | |
parent | 15f91c5240ab3dfea362300cf017d4d88f2f27df (diff) | |
download | bcm5719-llvm-8c6e9ef676c92e554c47ddbf7db09bcf9af81692.tar.gz bcm5719-llvm-8c6e9ef676c92e554c47ddbf7db09bcf9af81692.zip |
clang-format: precedence-based indentation when breaking before operators.
Before:
bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
== aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
* bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
&& aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
> ccccccccccccccccccccccccccccccccccccccccc;
After:
bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
== aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
* bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
&& aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
> ccccccccccccccccccccccccccccccccccccccccc;
Not particularly pretty, but can probably help to uncover bugs. And if this
bugs somebody, parentheses can help.
llvm-svn: 223111
Diffstat (limited to 'clang/lib/Format/ContinuationIndenter.cpp')
-rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index f8d292bcc0a..53381703513 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -168,7 +168,7 @@ bool ContinuationIndenter::mustBreak(const LineState &State) { if (State.Column < getNewLineColumn(State)) return false; - if (!Style.BreakBeforeBinaryOperators) { + if (Style.BreakBeforeBinaryOperators == FormatStyle::BOS_None) { // If we need to break somewhere inside the LHS of a binary expression, we // should also break after the operator. Otherwise, the formatting would // hide the operator precedence, e.g. in: @@ -740,11 +740,12 @@ void ContinuationIndenter::moveStatePastFakeLParens(LineState &State, if (Previous && Previous->getPrecedence() > prec::Assignment && Previous->isOneOf(TT_BinaryOperator, TT_ConditionalExpr) && Previous->getPrecedence() != prec::Relational) { - bool BreakBeforeOperator = Previous->is(tok::lessless) || - (Previous->is(TT_BinaryOperator) && - Style.BreakBeforeBinaryOperators) || - (Previous->is(TT_ConditionalExpr) && - Style.BreakBeforeTernaryOperators); + bool BreakBeforeOperator = + Previous->is(tok::lessless) || + (Previous->is(TT_BinaryOperator) && + Style.BreakBeforeBinaryOperators != FormatStyle::BOS_None) || + (Previous->is(TT_ConditionalExpr) && + Style.BreakBeforeTernaryOperators); if ((!Newline && !BreakBeforeOperator) || (!State.Stack.back().LastOperatorWrapped && BreakBeforeOperator)) NewParenState.NoLineBreak = true; @@ -766,7 +767,7 @@ void ContinuationIndenter::moveStatePastFakeLParens(LineState &State, // other expression, unless the indentation needs to be skipped. if (*I == prec::Conditional || (!SkipFirstExtraIndent && *I > prec::Assignment && - !Current.isTrailingComment() && !Style.BreakBeforeBinaryOperators)) + !Current.isTrailingComment())) NewParenState.Indent += Style.ContinuationIndentWidth; if ((Previous && !Previous->opensScope()) || *I > prec::Comma) NewParenState.BreakBeforeParameter = false; |