// breaks are chosen.
unsigned Penalty = 0;
- const FormatToken *PreviousNonComment =
- State.NextToken->getPreviousNonComment();
+ const FormatToken *PreviousNonComment = Current.getPreviousNonComment();
+ const FormatToken *NextNonComment = Previous.getNextNonComment();
+ if (!NextNonComment)
+ NextNonComment = &Current;
// The first line break on any ParenLevel causes an extra penalty in order
// prefer similar line breaks.
if (!State.Stack.back().ContainsLineBreak)
Penalty += State.NextToken->SplitPenalty;
+
// Breaking before the first "<<" is generally not desirable if the LHS is
// short. Also always add the penalty if the LHS is split over mutliple lines
// to avoid unncessary line breaks that just work around this penalty.
- if (Current.is(tok::lessless) && State.Stack.back().FirstLessLess == 0 &&
+ if (NextNonComment->is(tok::lessless) &&
+ State.Stack.back().FirstLessLess == 0 &&
(State.Column <= Style.ColumnLimit / 3 ||
State.Stack.back().BreakBeforeParameter))
Penalty += Style.PenaltyBreakFirstLessLess;
- if (Current.is(tok::l_brace) && Current.BlockKind == BK_Block) {
+ if (NextNonComment->is(tok::l_brace) &&
+ NextNonComment->BlockKind == BK_Block) {
State.Column =
State.ParenLevel == 0 ? State.FirstIndent : State.Stack.back().Indent;
} else if (Current.isOneOf(tok::r_brace, tok::r_square)) {
State.Column = State.Stack[State.Stack.size() - 2].LastSpace;
else
State.Column = State.FirstIndent;
- } else if (Current.isStringLiteral() && State.StartOfStringLiteral != 0) {
+ } else if (NextNonComment->isStringLiteral() &&
+ State.StartOfStringLiteral != 0) {
State.Column = State.StartOfStringLiteral;
State.Stack.back().BreakBeforeParameter = true;
- } else if (Current.is(tok::lessless) &&
+ } else if (NextNonComment->is(tok::lessless) &&
State.Stack.back().FirstLessLess != 0) {
State.Column = State.Stack.back().FirstLessLess;
- } else if (Current.isMemberAccess()) {
+ } else if (NextNonComment->isMemberAccess()) {
if (State.Stack.back().CallContinuation == 0) {
State.Column = ContinuationIndent;
State.Stack.back().CallContinuation = State.Column;
State.Column = State.Stack.back().CallContinuation;
}
} else if (State.Stack.back().QuestionColumn != 0 &&
- (Current.Type == TT_ConditionalExpr ||
+ (NextNonComment->Type == TT_ConditionalExpr ||
Previous.Type == TT_ConditionalExpr)) {
State.Column = State.Stack.back().QuestionColumn;
} else if (Previous.is(tok::comma) && State.Stack.back().VariablePos != 0) {
} else if ((PreviousNonComment &&
(PreviousNonComment->ClosesTemplateDeclaration ||
PreviousNonComment->Type == TT_AttributeParen)) ||
- ((Current.Type == TT_StartOfName ||
- Current.is(tok::kw_operator)) &&
+ ((NextNonComment->Type == TT_StartOfName ||
+ NextNonComment->is(tok::kw_operator)) &&
State.ParenLevel == 0 &&
(!Style.IndentFunctionDeclarationAfterType ||
State.Line->StartsDefinition))) {
State.Column =
std::max(State.Stack.back().LastSpace, State.Stack.back().Indent);
- } else if (Current.Type == TT_ObjCSelectorName) {
+ } else if (NextNonComment->Type == TT_ObjCSelectorName) {
if (!State.Stack.back().ObjCSelectorNameFound) {
- if (Current.LongestObjCSelectorName == 0) {
+ if (NextNonComment->LongestObjCSelectorName == 0) {
State.Column = State.Stack.back().Indent;
State.Stack.back().AlignColons = false;
} else {
State.Stack.back().ColonPos =
- State.Stack.back().Indent + Current.LongestObjCSelectorName;
- State.Column = State.Stack.back().ColonPos - Current.ColumnWidth;
+ State.Stack.back().Indent + NextNonComment->LongestObjCSelectorName;
+ State.Column =
+ State.Stack.back().ColonPos - NextNonComment->ColumnWidth;
}
} else if (!State.Stack.back().AlignColons) {
State.Column = State.Stack.back().Indent;
- } else if (State.Stack.back().ColonPos > Current.ColumnWidth) {
- State.Column = State.Stack.back().ColonPos - Current.ColumnWidth;
+ } else if (State.Stack.back().ColonPos > NextNonComment->ColumnWidth) {
+ State.Column = State.Stack.back().ColonPos - NextNonComment->ColumnWidth;
} else {
State.Column = State.Stack.back().Indent;
- State.Stack.back().ColonPos = State.Column + Current.ColumnWidth;
+ State.Stack.back().ColonPos = State.Column + NextNonComment->ColumnWidth;
}
- } else if (Current.Type == TT_ArraySubscriptLSquare) {
+ } else if (NextNonComment->Type == TT_ArraySubscriptLSquare) {
if (State.Stack.back().StartOfArraySubscripts != 0)
State.Column = State.Stack.back().StartOfArraySubscripts;
else
State.Column = ContinuationIndent;
- } else if (Current.Type == TT_StartOfName ||
+ } else if (NextNonComment->Type == TT_StartOfName ||
Previous.isOneOf(tok::coloncolon, tok::equal)) {
State.Column = ContinuationIndent;
} else if (PreviousNonComment &&
// when we consume all of the "}"'s FakeRParens at the "{".
if (State.Stack.size() > 1)
State.Stack[State.Stack.size() - 2].LastSpace = ContinuationIndent;
- } else if (Current.Type == TT_CtorInitializerColon) {
+ } else if (NextNonComment->Type == TT_CtorInitializerColon) {
State.Column = State.FirstIndent + Style.ConstructorInitializerIndentWidth;
- } else if (Current.Type == TT_CtorInitializerComma) {
+ } else if (NextNonComment->Type == TT_CtorInitializerComma) {
State.Column = State.Stack.back().Indent;
} else {
State.Column = State.Stack.back().Indent;
State.Stack.back().BreakBeforeParameter = false;
if (Previous.Type == TT_TemplateCloser && State.ParenLevel == 0)
State.Stack.back().BreakBeforeParameter = false;
- if (Current.is(tok::question) ||
+ if (NextNonComment->is(tok::question) ||
(PreviousNonComment && PreviousNonComment->is(tok::question)))
State.Stack.back().BreakBeforeParameter = true;
if (I[1]->InPPDirective != (*I)->InPPDirective ||
(I[1]->InPPDirective && I[1]->First->HasUnescapedNewline))
return 0;
- Limit = LimitConsideringMacros(I + 1, E, Limit);
+ Limit = limitConsideringMacros(I + 1, E, Limit);
AnnotatedLine &Line = **I;
if (Line.Last->isNot(tok::r_paren))
return 0;
// Check that we still have three lines and they fit into the limit.
if (I + 2 == E || I[2]->Type == LT_Invalid)
return 0;
- Limit = LimitConsideringMacros(I + 2, E, Limit);
+ Limit = limitConsideringMacros(I + 2, E, Limit);
if (!nextTwoLinesFitInto(I, Limit))
return 0;
/// Returns the modified column limit for \p I if it is inside a macro and
/// needs a trailing '\'.
unsigned
- LimitConsideringMacros(SmallVectorImpl<AnnotatedLine *>::const_iterator I,
+ limitConsideringMacros(SmallVectorImpl<AnnotatedLine *>::const_iterator I,
SmallVectorImpl<AnnotatedLine *>::const_iterator E,
unsigned Limit) {
if (I[0]->InPPDirective && I + 1 != E &&