@@ -367,12 +367,6 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
367367 State.Stack .back ().BreakBeforeParameter && !Current.isTrailingComment () &&
368368 !Current.isOneOf (tok::r_paren, tok::r_brace))
369369 return true ;
370- if (State.Stack .back ().IsChainedConditional &&
371- ((Style.BreakBeforeTernaryOperators && Current.is (TT_ConditionalExpr) &&
372- Current.is (tok::colon)) ||
373- (!Style.BreakBeforeTernaryOperators && Previous.is (TT_ConditionalExpr) &&
374- Previous.is (tok::colon))))
375- return true ;
376370 if (((Previous.is (TT_DictLiteral) && Previous.is (tok::l_brace)) ||
377371 (Previous.is (TT_ArrayInitializerLSquare) &&
378372 Previous.ParameterCount > 1 ) ||
@@ -693,9 +687,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
693687 // does not help.
694688 bool HasTwoOperands =
695689 P->OperatorIndex == 0 && !P->NextOperator && !P->is (TT_ConditionalExpr);
696- if ((!BreakBeforeOperator &&
697- !(HasTwoOperands &&
698- Style.AlignOperands != FormatStyle::OAS_DontAlign)) ||
690+ if ((!BreakBeforeOperator && !(HasTwoOperands && Style.AlignOperands )) ||
699691 (!State.Stack .back ().LastOperatorWrapped && BreakBeforeOperator))
700692 State.Stack .back ().NoLineBreakInOperand = true ;
701693 }
@@ -1030,23 +1022,8 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
10301022 if (State.Stack .back ().QuestionColumn != 0 &&
10311023 ((NextNonComment->is (tok::colon) &&
10321024 NextNonComment->is (TT_ConditionalExpr)) ||
1033- Previous.is (TT_ConditionalExpr))) {
1034- if (((NextNonComment->is (tok::colon) && NextNonComment->Next &&
1035- !NextNonComment->Next ->FakeLParens .empty () &&
1036- NextNonComment->Next ->FakeLParens .back () == prec::Conditional) ||
1037- (Previous.is (tok::colon) && !Current.FakeLParens .empty () &&
1038- Current.FakeLParens .back () == prec::Conditional)) &&
1039- !State.Stack .back ().IsWrappedConditional ) {
1040- // NOTE: we may tweak this slightly:
1041- // * not remove the 'lead' ContinuationIndentWidth
1042- // * always un-indent by the operator when BreakBeforeTernaryOperators=true
1043- unsigned Indent = State.Stack .back ().Indent - Style.ContinuationIndentWidth ;
1044- if (Style.BreakBeforeTernaryOperators && State.Stack .back ().UnindentOperator )
1045- Indent -= 2 ;
1046- return Indent;
1047- }
1025+ Previous.is (TT_ConditionalExpr)))
10481026 return State.Stack .back ().QuestionColumn ;
1049- }
10501027 if (Previous.is (tok::comma) && State.Stack .back ().VariablePos != 0 )
10511028 return State.Stack .back ().VariablePos ;
10521029 if ((PreviousNonComment &&
@@ -1122,13 +1099,6 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
11221099 return ContinuationIndent;
11231100 if (Current.is (TT_ProtoExtensionLSquare))
11241101 return State.Stack .back ().Indent ;
1125- if (Current.isBinaryOperator () && State.Stack .back ().UnindentOperator )
1126- return State.Stack .back ().Indent - Current.Tok .getLength () -
1127- Current.SpacesRequiredBefore ;
1128- if (Current.isOneOf (tok::comment, TT_BlockComment, TT_LineComment) &&
1129- NextNonComment->isBinaryOperator () && State.Stack .back ().UnindentOperator )
1130- return State.Stack .back ().Indent - NextNonComment->Tok .getLength () -
1131- NextNonComment->SpacesRequiredBefore ;
11321102 if (State.Stack .back ().Indent == State.FirstIndent && PreviousNonComment &&
11331103 !PreviousNonComment->isOneOf (tok::r_brace, TT_CtorInitializerComma))
11341104 // Ensure that we fall back to the continuation indent width instead of
@@ -1174,10 +1144,6 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
11741144 if (Current.is (TT_ArraySubscriptLSquare) &&
11751145 State.Stack .back ().StartOfArraySubscripts == 0 )
11761146 State.Stack .back ().StartOfArraySubscripts = State.Column ;
1177- if (Current.is (TT_ConditionalExpr) && Current.is (tok::question) &&
1178- ((Current.MustBreakBefore ) ||
1179- (Current.getNextNonComment () && Current.getNextNonComment ()->MustBreakBefore )))
1180- State.Stack .back ().IsWrappedConditional = true ;
11811147 if (Style.BreakBeforeTernaryOperators && Current.is (tok::question))
11821148 State.Stack .back ().QuestionColumn = State.Column ;
11831149 if (!Style.BreakBeforeTernaryOperators && Current.isNot (tok::colon)) {
@@ -1308,7 +1274,7 @@ void ContinuationIndenter::moveStatePastFakeLParens(LineState &State,
13081274 (Previous && (Previous->opensScope () ||
13091275 Previous->isOneOf (tok::semi, tok::kw_return) ||
13101276 (Previous->getPrecedence () == prec::Assignment &&
1311- Style.AlignOperands != FormatStyle::OAS_DontAlign ) ||
1277+ Style.AlignOperands ) ||
13121278 Previous->is (TT_ObjCMethodExpr)));
13131279 for (SmallVectorImpl<prec::Level>::const_reverse_iterator
13141280 I = Current.FakeLParens .rbegin (),
@@ -1318,9 +1284,6 @@ void ContinuationIndenter::moveStatePastFakeLParens(LineState &State,
13181284 NewParenState.Tok = nullptr ;
13191285 NewParenState.ContainsLineBreak = false ;
13201286 NewParenState.LastOperatorWrapped = true ;
1321- NewParenState.IsChainedConditional = false ;
1322- NewParenState.IsWrappedConditional = false ;
1323- NewParenState.UnindentOperator = false ;
13241287 NewParenState.NoLineBreak =
13251288 NewParenState.NoLineBreak || State.Stack .back ().NoLineBreakInOperand ;
13261289
@@ -1332,26 +1295,14 @@ void ContinuationIndenter::moveStatePastFakeLParens(LineState &State,
13321295 // a builder type call after 'return' or, if the alignment after opening
13331296 // brackets is disabled.
13341297 if (!Current.isTrailingComment () &&
1335- (Style.AlignOperands != FormatStyle::OAS_DontAlign ||
1336- *I < prec::Assignment) &&
1298+ (Style.AlignOperands || *I < prec::Assignment) &&
13371299 (!Previous || Previous->isNot (tok::kw_return) ||
13381300 (Style.Language != FormatStyle::LK_Java && *I > 0 )) &&
13391301 (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign ||
1340- *I != prec::Comma || Current.NestingLevel == 0 )) {
1302+ *I != prec::Comma || Current.NestingLevel == 0 ))
13411303 NewParenState.Indent =
13421304 std::max (std::max (State.Column , NewParenState.Indent ),
13431305 State.Stack .back ().LastSpace );
1344- }
1345-
1346- // If BreakBeforeBinaryOperators is set, un-indent a bit to account for
1347- // the operator and keep the operands aligned
1348- if (Style.AlignOperands == FormatStyle::OAS_AlignAfterOperator && Previous &&
1349- (Previous->getPrecedence () == prec::Assignment ||
1350- Previous->is (tok::kw_return) ||
1351- (*I == prec::Conditional && Previous->is (tok::question) &&
1352- Previous->is (TT_ConditionalExpr))) &&
1353- !Newline)
1354- NewParenState.UnindentOperator = true ;
13551306
13561307 // Do not indent relative to the fake parentheses inserted for "." or "->".
13571308 // This is a special case to make the following to statements consistent:
@@ -1365,21 +1316,14 @@ void ContinuationIndenter::moveStatePastFakeLParens(LineState &State,
13651316 Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign)
13661317 NewParenState.StartOfFunctionCall = State.Column ;
13671318
1368- // Indent conditional expressions, unless they are chained "else-if"
1369- // conditionals. Never indent expression where the 'operator' is ',', ';' or
1370- // an assignment (i.e. *I <= prec::Assignment) as those have different
1371- // indentation rules. Indent other expression, unless the indentation needs
1372- // to be skipped.
1373- if (*I == prec::Conditional && Previous && Previous->is (tok::colon) &&
1374- Previous->is (TT_ConditionalExpr) && I == Current.FakeLParens .rbegin () &&
1375- !State.Stack .back ().IsWrappedConditional ) {
1376- NewParenState.IsChainedConditional = true ;
1377- NewParenState.UnindentOperator = State.Stack .back ().UnindentOperator ;
1378- } else if (*I == prec::Conditional ||
1379- (!SkipFirstExtraIndent && *I > prec::Assignment &&
1380- !Current.isTrailingComment ())) {
1319+ // Always indent conditional expressions. Never indent expression where
1320+ // the 'operator' is ',', ';' or an assignment (i.e. *I <=
1321+ // prec::Assignment) as those have different indentation rules. Indent
1322+ // other expression, unless the indentation needs to be skipped.
1323+ if (*I == prec::Conditional ||
1324+ (!SkipFirstExtraIndent && *I > prec::Assignment &&
1325+ !Current.isTrailingComment ()))
13811326 NewParenState.Indent += Style.ContinuationIndentWidth ;
1382- }
13831327 if ((Previous && !Previous->opensScope ()) || *I != prec::Comma)
13841328 NewParenState.BreakBeforeParameter = false ;
13851329 State.Stack .push_back (NewParenState);
0 commit comments