diff options
Diffstat (limited to 'clang/lib/Format/ContinuationIndenter.cpp')
-rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index a80e87ddfc8..442f9fa8505 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -125,8 +125,11 @@ bool ContinuationIndenter::mustBreak(const LineState &State) { if (Previous.is(tok::semi) && State.LineContainsContinuedForLoopSection) return true; if ((startsNextParameter(Current, Style) || Previous.is(tok::semi) || - Current.is(tok::question) || - (Current.Type == TT_ConditionalExpr && Previous.isNot(tok::question))) && + (Style.BreakBeforeTernaryOperators && + (Current.is(tok::question) || (Current.Type == TT_ConditionalExpr && + Previous.isNot(tok::question)))) || + (!Style.BreakBeforeTernaryOperators && + (Previous.is(tok::question) || Previous.Type == TT_ConditionalExpr))) && State.Stack.back().BreakBeforeParameter && !Current.isTrailingComment() && !Current.isOneOf(tok::r_paren, tok::r_brace)) return true; @@ -357,7 +360,9 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State, } else { State.Column = State.Stack.back().CallContinuation; } - } else if (Current.Type == TT_ConditionalExpr) { + } else if (State.Stack.back().QuestionColumn != 0 && + (Current.Type == TT_ConditionalExpr || + Previous.Type == TT_ConditionalExpr)) { State.Column = State.Stack.back().QuestionColumn; } else if (Previous.is(tok::comma) && State.Stack.back().VariablePos != 0) { State.Column = State.Stack.back().VariablePos; @@ -398,14 +403,15 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State, State.Column += Style.ContinuationIndentWidth; } - if (Current.is(tok::question)) - State.Stack.back().BreakBeforeParameter = true; if ((Previous.isOneOf(tok::comma, tok::semi) && !State.Stack.back().AvoidBinPacking) || Previous.Type == TT_BinaryOperator) State.Stack.back().BreakBeforeParameter = false; if (Previous.Type == TT_TemplateCloser && State.ParenLevel == 0) State.Stack.back().BreakBeforeParameter = false; + if (Current.is(tok::question) || + (PreviousNonComment && PreviousNonComment->is(tok::question))) + State.Stack.back().BreakBeforeParameter = true; if (!DryRun) { unsigned Newlines = 1; @@ -465,7 +471,10 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State, if (Current.Type == TT_ArraySubscriptLSquare && State.Stack.back().StartOfArraySubscripts == 0) State.Stack.back().StartOfArraySubscripts = State.Column; - if (Current.is(tok::question)) + if ((Current.is(tok::question) && Style.BreakBeforeTernaryOperators) || + (Current.getPreviousNonComment() && Current.isNot(tok::colon) && + Current.getPreviousNonComment()->is(tok::question) && + !Style.BreakBeforeTernaryOperators)) State.Stack.back().QuestionColumn = State.Column; if (!Current.opensScope() && !Current.closesScope()) State.LowestLevelOnLine = |