r208304 - clang-format: Cleanup redundant calculation of ParenLevel.
Daniel Jasper
djasper at google.com
Thu May 8 05:21:31 PDT 2014
Author: djasper
Date: Thu May 8 07:21:30 2014
New Revision: 208304
URL: http://llvm.org/viewvc/llvm-project?rev=208304&view=rev
Log:
clang-format: Cleanup redundant calculation of ParenLevel.
No functional changes intended.
Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/ContinuationIndenter.h
Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=208304&r1=208303&r2=208304&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Thu May 8 07:21:30 2014
@@ -78,10 +78,9 @@ LineState ContinuationIndenter::getIniti
/*AvoidBinPacking=*/false,
/*NoLineBreak=*/false));
State.LineContainsContinuedForLoopSection = false;
- State.ParenLevel = 0;
State.StartOfStringLiteral = 0;
- State.StartOfLineLevel = State.ParenLevel;
- State.LowestLevelOnLine = State.ParenLevel;
+ State.StartOfLineLevel = 0;
+ State.LowestLevelOnLine = 0;
State.IgnoreStackForComparison = false;
// The first token has already been indented and thus consumed.
@@ -190,13 +189,13 @@ bool ContinuationIndenter::mustBreak(con
State.Stack.back().ObjCSelectorNameFound &&
State.Stack.back().BreakBeforeParameter)
return true;
- if (Previous.ClosesTemplateDeclaration && State.ParenLevel == 0 &&
+ if (Previous.ClosesTemplateDeclaration && Current.NestingLevel == 0 &&
!Current.isTrailingComment())
return true;
if ((Current.Type == TT_StartOfName || Current.is(tok::kw_operator)) &&
State.Line->MightBeFunctionDecl &&
- State.Stack.back().BreakBeforeParameter && State.ParenLevel == 0)
+ State.Stack.back().BreakBeforeParameter && Current.NestingLevel == 0)
return true;
if (startsSegmentOfBuilderTypeCall(Current) &&
(State.Stack.back().CallContinuation != 0 ||
@@ -248,7 +247,7 @@ void ContinuationIndenter::addTokenOnCur
FormatToken &Current = *State.NextToken;
const FormatToken &Previous = *State.NextToken->Previous;
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 = State.Column;
// Move over * and & if they are bound to the variable name.
@@ -343,7 +342,7 @@ unsigned ContinuationIndenter::addTokenO
const FormatToken *NextNonComment = Previous.getNextNonComment();
if (!NextNonComment)
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.
if (!State.Stack.back().ContainsLineBreak)
Penalty += 15;
@@ -386,7 +385,7 @@ unsigned ContinuationIndenter::addTokenO
// ^(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 "{".
if (State.Stack.size() > 1)
State.Stack[State.Stack.size() - 2].LastSpace =
@@ -398,7 +397,7 @@ unsigned ContinuationIndenter::addTokenO
!State.Stack.back().AvoidBinPacking) ||
Previous.Type == TT_BinaryOperator)
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;
if (NextNonComment->is(tok::question) ||
(PreviousNonComment && PreviousNonComment->is(tok::question)))
@@ -416,8 +415,8 @@ unsigned ContinuationIndenter::addTokenO
if (!Current.isTrailingComment())
State.Stack.back().LastSpace = State.Column;
- State.StartOfLineLevel = State.ParenLevel;
- State.LowestLevelOnLine = State.ParenLevel;
+ State.StartOfLineLevel = Current.NestingLevel;
+ State.LowestLevelOnLine = Current.NestingLevel;
// Any break on this level means that the parent level has been broken
// and we need to avoid bin packing there.
@@ -465,8 +464,8 @@ unsigned ContinuationIndenter::getNewLin
NextNonComment = &Current;
if (NextNonComment->is(tok::l_brace) &&
NextNonComment->BlockKind == BK_Block)
- return State.ParenLevel == 0 ? State.FirstIndent
- : State.Stack.back().Indent;
+ return Current.NestingLevel == 0 ? State.FirstIndent
+ : State.Stack.back().Indent;
if (Current.isOneOf(tok::r_brace, tok::r_square)) {
if (Current.closesBlockTypeList(Style) ||
(Current.MatchingParen &&
@@ -501,8 +500,9 @@ unsigned ContinuationIndenter::getNewLin
PreviousNonComment->Type == TT_AttributeParen)) ||
((NextNonComment->Type == TT_StartOfName ||
NextNonComment->is(tok::kw_operator)) &&
- State.ParenLevel == 0 && (!Style.IndentFunctionDeclarationAfterType ||
- State.Line->StartsDefinition)))
+ Current.NestingLevel == 0 &&
+ (!Style.IndentFunctionDeclarationAfterType ||
+ State.Line->StartsDefinition)))
return std::max(State.Stack.back().LastSpace, State.Stack.back().Indent);
if (NextNonComment->Type == TT_ObjCSelectorName) {
if (!State.Stack.back().ObjCSelectorNameFound) {
@@ -573,7 +573,7 @@ unsigned ContinuationIndenter::moveState
State.Stack.back().QuestionColumn = State.Column;
if (!Current.opensScope() && !Current.closesScope())
State.LowestLevelOnLine =
- std::min(State.LowestLevelOnLine, State.ParenLevel);
+ std::min(State.LowestLevelOnLine, Current.NestingLevel);
if (Current.isMemberAccess())
State.Stack.back().StartOfFunctionCall =
Current.LastOperator ? 0 : State.Column + Current.ColumnWidth;
@@ -754,7 +754,6 @@ unsigned ContinuationIndenter::moveState
State.Stack.back().LastSpace,
AvoidBinPacking, NoLineBreak));
State.Stack.back().BreakBeforeParameter = BreakBeforeParameter;
- ++State.ParenLevel;
}
// If we encounter a closing ), ], } or >, we can remove a level from our
@@ -764,7 +763,6 @@ unsigned ContinuationIndenter::moveState
(Current.is(tok::r_brace) && State.NextToken != State.Line->First) ||
State.NextToken->Type == TT_TemplateCloser)) {
State.Stack.pop_back();
- --State.ParenLevel;
}
if (Current.is(tok::r_square)) {
// If this ends the array subscript expr, reset the corresponding value.
Modified: cfe/trunk/lib/Format/ContinuationIndenter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.h?rev=208304&r1=208303&r2=208304&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.h (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.h Thu May 8 07:21:30 2014
@@ -290,13 +290,10 @@ struct LineState {
/// \brief \c true if this line contains a continued for-loop section.
bool LineContainsContinuedForLoopSection;
- /// \brief The level of nesting inside (), [], <> and {}.
- unsigned ParenLevel;
-
- /// \brief The \c ParenLevel at the start of this line.
+ /// \brief The \c NestingLevel at the start of this line.
unsigned StartOfLineLevel;
- /// \brief The lowest \c ParenLevel on the current line.
+ /// \brief The lowest \c NestingLevel on the current line.
unsigned LowestLevelOnLine;
/// \brief The start column of the string literal, if we're in a string
@@ -339,8 +336,6 @@ struct LineState {
if (LineContainsContinuedForLoopSection !=
Other.LineContainsContinuedForLoopSection)
return LineContainsContinuedForLoopSection;
- if (ParenLevel != Other.ParenLevel)
- return ParenLevel < Other.ParenLevel;
if (StartOfLineLevel != Other.StartOfLineLevel)
return StartOfLineLevel < Other.StartOfLineLevel;
if (LowestLevelOnLine != Other.LowestLevelOnLine)
More information about the cfe-commits
mailing list