forked from OSchip/llvm-project
clang-format: Cleanup redundant calculation of ParenLevel.
No functional changes intended. llvm-svn: 208304
This commit is contained in:
parent
c5e51926dc
commit
05cd586863
|
@ -78,10 +78,9 @@ LineState ContinuationIndenter::getInitialState(unsigned FirstIndent,
|
||||||
/*AvoidBinPacking=*/false,
|
/*AvoidBinPacking=*/false,
|
||||||
/*NoLineBreak=*/false));
|
/*NoLineBreak=*/false));
|
||||||
State.LineContainsContinuedForLoopSection = false;
|
State.LineContainsContinuedForLoopSection = false;
|
||||||
State.ParenLevel = 0;
|
|
||||||
State.StartOfStringLiteral = 0;
|
State.StartOfStringLiteral = 0;
|
||||||
State.StartOfLineLevel = State.ParenLevel;
|
State.StartOfLineLevel = 0;
|
||||||
State.LowestLevelOnLine = State.ParenLevel;
|
State.LowestLevelOnLine = 0;
|
||||||
State.IgnoreStackForComparison = false;
|
State.IgnoreStackForComparison = false;
|
||||||
|
|
||||||
// The first token has already been indented and thus consumed.
|
// The first token has already been indented and thus consumed.
|
||||||
|
@ -190,13 +189,13 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
|
||||||
State.Stack.back().ObjCSelectorNameFound &&
|
State.Stack.back().ObjCSelectorNameFound &&
|
||||||
State.Stack.back().BreakBeforeParameter)
|
State.Stack.back().BreakBeforeParameter)
|
||||||
return true;
|
return true;
|
||||||
if (Previous.ClosesTemplateDeclaration && State.ParenLevel == 0 &&
|
if (Previous.ClosesTemplateDeclaration && Current.NestingLevel == 0 &&
|
||||||
!Current.isTrailingComment())
|
!Current.isTrailingComment())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if ((Current.Type == TT_StartOfName || Current.is(tok::kw_operator)) &&
|
if ((Current.Type == TT_StartOfName || Current.is(tok::kw_operator)) &&
|
||||||
State.Line->MightBeFunctionDecl &&
|
State.Line->MightBeFunctionDecl &&
|
||||||
State.Stack.back().BreakBeforeParameter && State.ParenLevel == 0)
|
State.Stack.back().BreakBeforeParameter && Current.NestingLevel == 0)
|
||||||
return true;
|
return true;
|
||||||
if (startsSegmentOfBuilderTypeCall(Current) &&
|
if (startsSegmentOfBuilderTypeCall(Current) &&
|
||||||
(State.Stack.back().CallContinuation != 0 ||
|
(State.Stack.back().CallContinuation != 0 ||
|
||||||
|
@ -248,7 +247,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
|
||||||
FormatToken &Current = *State.NextToken;
|
FormatToken &Current = *State.NextToken;
|
||||||
const FormatToken &Previous = *State.NextToken->Previous;
|
const FormatToken &Previous = *State.NextToken->Previous;
|
||||||
if (Current.is(tok::equal) &&
|
if (Current.is(tok::equal) &&
|
||||||
(State.Line->First->is(tok::kw_for) || State.ParenLevel == 0) &&
|
(State.Line->First->is(tok::kw_for) || Current.NestingLevel == 0) &&
|
||||||
State.Stack.back().VariablePos == 0) {
|
State.Stack.back().VariablePos == 0) {
|
||||||
State.Stack.back().VariablePos = State.Column;
|
State.Stack.back().VariablePos = State.Column;
|
||||||
// Move over * and & if they are bound to the variable name.
|
// Move over * and & if they are bound to the variable name.
|
||||||
|
@ -343,7 +342,7 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
|
||||||
const FormatToken *NextNonComment = Previous.getNextNonComment();
|
const FormatToken *NextNonComment = Previous.getNextNonComment();
|
||||||
if (!NextNonComment)
|
if (!NextNonComment)
|
||||||
NextNonComment = &Current;
|
NextNonComment = &Current;
|
||||||
// The first line break on any ParenLevel causes an extra penalty in order
|
// The first line break on any NestingLevel causes an extra penalty in order
|
||||||
// prefer similar line breaks.
|
// prefer similar line breaks.
|
||||||
if (!State.Stack.back().ContainsLineBreak)
|
if (!State.Stack.back().ContainsLineBreak)
|
||||||
Penalty += 15;
|
Penalty += 15;
|
||||||
|
@ -386,7 +385,7 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
|
||||||
// ^(int *i) {
|
// ^(int *i) {
|
||||||
// // ...
|
// // ...
|
||||||
// }];
|
// }];
|
||||||
// Thus, we set LastSpace of the next higher ParenLevel, to which we move
|
// Thus, we set LastSpace of the next higher NestingLevel, to which we move
|
||||||
// when we consume all of the "}"'s FakeRParens at the "{".
|
// when we consume all of the "}"'s FakeRParens at the "{".
|
||||||
if (State.Stack.size() > 1)
|
if (State.Stack.size() > 1)
|
||||||
State.Stack[State.Stack.size() - 2].LastSpace =
|
State.Stack[State.Stack.size() - 2].LastSpace =
|
||||||
|
@ -398,7 +397,7 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
|
||||||
!State.Stack.back().AvoidBinPacking) ||
|
!State.Stack.back().AvoidBinPacking) ||
|
||||||
Previous.Type == TT_BinaryOperator)
|
Previous.Type == TT_BinaryOperator)
|
||||||
State.Stack.back().BreakBeforeParameter = false;
|
State.Stack.back().BreakBeforeParameter = false;
|
||||||
if (Previous.Type == TT_TemplateCloser && State.ParenLevel == 0)
|
if (Previous.Type == TT_TemplateCloser && Current.NestingLevel == 0)
|
||||||
State.Stack.back().BreakBeforeParameter = false;
|
State.Stack.back().BreakBeforeParameter = false;
|
||||||
if (NextNonComment->is(tok::question) ||
|
if (NextNonComment->is(tok::question) ||
|
||||||
(PreviousNonComment && PreviousNonComment->is(tok::question)))
|
(PreviousNonComment && PreviousNonComment->is(tok::question)))
|
||||||
|
@ -416,8 +415,8 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
|
||||||
|
|
||||||
if (!Current.isTrailingComment())
|
if (!Current.isTrailingComment())
|
||||||
State.Stack.back().LastSpace = State.Column;
|
State.Stack.back().LastSpace = State.Column;
|
||||||
State.StartOfLineLevel = State.ParenLevel;
|
State.StartOfLineLevel = Current.NestingLevel;
|
||||||
State.LowestLevelOnLine = State.ParenLevel;
|
State.LowestLevelOnLine = Current.NestingLevel;
|
||||||
|
|
||||||
// Any break on this level means that the parent level has been broken
|
// Any break on this level means that the parent level has been broken
|
||||||
// and we need to avoid bin packing there.
|
// and we need to avoid bin packing there.
|
||||||
|
@ -465,7 +464,7 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
|
||||||
NextNonComment = &Current;
|
NextNonComment = &Current;
|
||||||
if (NextNonComment->is(tok::l_brace) &&
|
if (NextNonComment->is(tok::l_brace) &&
|
||||||
NextNonComment->BlockKind == BK_Block)
|
NextNonComment->BlockKind == BK_Block)
|
||||||
return State.ParenLevel == 0 ? State.FirstIndent
|
return Current.NestingLevel == 0 ? State.FirstIndent
|
||||||
: State.Stack.back().Indent;
|
: State.Stack.back().Indent;
|
||||||
if (Current.isOneOf(tok::r_brace, tok::r_square)) {
|
if (Current.isOneOf(tok::r_brace, tok::r_square)) {
|
||||||
if (Current.closesBlockTypeList(Style) ||
|
if (Current.closesBlockTypeList(Style) ||
|
||||||
|
@ -501,7 +500,8 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
|
||||||
PreviousNonComment->Type == TT_AttributeParen)) ||
|
PreviousNonComment->Type == TT_AttributeParen)) ||
|
||||||
((NextNonComment->Type == TT_StartOfName ||
|
((NextNonComment->Type == TT_StartOfName ||
|
||||||
NextNonComment->is(tok::kw_operator)) &&
|
NextNonComment->is(tok::kw_operator)) &&
|
||||||
State.ParenLevel == 0 && (!Style.IndentFunctionDeclarationAfterType ||
|
Current.NestingLevel == 0 &&
|
||||||
|
(!Style.IndentFunctionDeclarationAfterType ||
|
||||||
State.Line->StartsDefinition)))
|
State.Line->StartsDefinition)))
|
||||||
return std::max(State.Stack.back().LastSpace, State.Stack.back().Indent);
|
return std::max(State.Stack.back().LastSpace, State.Stack.back().Indent);
|
||||||
if (NextNonComment->Type == TT_ObjCSelectorName) {
|
if (NextNonComment->Type == TT_ObjCSelectorName) {
|
||||||
|
@ -573,7 +573,7 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
|
||||||
State.Stack.back().QuestionColumn = State.Column;
|
State.Stack.back().QuestionColumn = State.Column;
|
||||||
if (!Current.opensScope() && !Current.closesScope())
|
if (!Current.opensScope() && !Current.closesScope())
|
||||||
State.LowestLevelOnLine =
|
State.LowestLevelOnLine =
|
||||||
std::min(State.LowestLevelOnLine, State.ParenLevel);
|
std::min(State.LowestLevelOnLine, Current.NestingLevel);
|
||||||
if (Current.isMemberAccess())
|
if (Current.isMemberAccess())
|
||||||
State.Stack.back().StartOfFunctionCall =
|
State.Stack.back().StartOfFunctionCall =
|
||||||
Current.LastOperator ? 0 : State.Column + Current.ColumnWidth;
|
Current.LastOperator ? 0 : State.Column + Current.ColumnWidth;
|
||||||
|
@ -754,7 +754,6 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
|
||||||
State.Stack.back().LastSpace,
|
State.Stack.back().LastSpace,
|
||||||
AvoidBinPacking, NoLineBreak));
|
AvoidBinPacking, NoLineBreak));
|
||||||
State.Stack.back().BreakBeforeParameter = BreakBeforeParameter;
|
State.Stack.back().BreakBeforeParameter = BreakBeforeParameter;
|
||||||
++State.ParenLevel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we encounter a closing ), ], } or >, we can remove a level from our
|
// If we encounter a closing ), ], } or >, we can remove a level from our
|
||||||
|
@ -764,7 +763,6 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
|
||||||
(Current.is(tok::r_brace) && State.NextToken != State.Line->First) ||
|
(Current.is(tok::r_brace) && State.NextToken != State.Line->First) ||
|
||||||
State.NextToken->Type == TT_TemplateCloser)) {
|
State.NextToken->Type == TT_TemplateCloser)) {
|
||||||
State.Stack.pop_back();
|
State.Stack.pop_back();
|
||||||
--State.ParenLevel;
|
|
||||||
}
|
}
|
||||||
if (Current.is(tok::r_square)) {
|
if (Current.is(tok::r_square)) {
|
||||||
// If this ends the array subscript expr, reset the corresponding value.
|
// If this ends the array subscript expr, reset the corresponding value.
|
||||||
|
|
|
@ -290,13 +290,10 @@ struct LineState {
|
||||||
/// \brief \c true if this line contains a continued for-loop section.
|
/// \brief \c true if this line contains a continued for-loop section.
|
||||||
bool LineContainsContinuedForLoopSection;
|
bool LineContainsContinuedForLoopSection;
|
||||||
|
|
||||||
/// \brief The level of nesting inside (), [], <> and {}.
|
/// \brief The \c NestingLevel at the start of this line.
|
||||||
unsigned ParenLevel;
|
|
||||||
|
|
||||||
/// \brief The \c ParenLevel at the start of this line.
|
|
||||||
unsigned StartOfLineLevel;
|
unsigned StartOfLineLevel;
|
||||||
|
|
||||||
/// \brief The lowest \c ParenLevel on the current line.
|
/// \brief The lowest \c NestingLevel on the current line.
|
||||||
unsigned LowestLevelOnLine;
|
unsigned LowestLevelOnLine;
|
||||||
|
|
||||||
/// \brief The start column of the string literal, if we're in a string
|
/// \brief The start column of the string literal, if we're in a string
|
||||||
|
@ -339,8 +336,6 @@ struct LineState {
|
||||||
if (LineContainsContinuedForLoopSection !=
|
if (LineContainsContinuedForLoopSection !=
|
||||||
Other.LineContainsContinuedForLoopSection)
|
Other.LineContainsContinuedForLoopSection)
|
||||||
return LineContainsContinuedForLoopSection;
|
return LineContainsContinuedForLoopSection;
|
||||||
if (ParenLevel != Other.ParenLevel)
|
|
||||||
return ParenLevel < Other.ParenLevel;
|
|
||||||
if (StartOfLineLevel != Other.StartOfLineLevel)
|
if (StartOfLineLevel != Other.StartOfLineLevel)
|
||||||
return StartOfLineLevel < Other.StartOfLineLevel;
|
return StartOfLineLevel < Other.StartOfLineLevel;
|
||||||
if (LowestLevelOnLine != Other.LowestLevelOnLine)
|
if (LowestLevelOnLine != Other.LowestLevelOnLine)
|
||||||
|
|
Loading…
Reference in New Issue