AvoidBinPacking(AvoidBinPacking), BreakBeforeParameter(false),
NoLineBreak(NoLineBreak), ColonPos(0), StartOfFunctionCall(0),
NestedNameSpecifierContinuation(0), CallContinuation(0),
- VariablePos(0) {}
+ VariablePos(0), ForFakeParenthesis(false) {}
/// \brief The position to which a specific parenthesis level needs to be
/// indented.
/// Used to align further variables if necessary.
unsigned VariablePos;
+ /// \brief \c true if this \c ParenState was created for a fake parenthesis.
+ ///
+ /// Does not need to be considered for memoization / the comparison function
+ /// as otherwise identical states will have the same fake/non-fake
+ /// \c ParenStates.
+ bool ForFakeParenthesis;
+
bool operator<(const ParenState &Other) const {
if (Indent != Other.Indent)
return Indent < Other.Indent;
E = Current.FakeLParens.rend();
I != E; ++I) {
ParenState NewParenState = State.Stack.back();
+ NewParenState.ForFakeParenthesis = true;
NewParenState.Indent =
std::max(std::max(State.Column, NewParenState.Indent),
State.Stack.back().LastSpace);
// prepare for the following tokens.
if (Current.opensScope()) {
unsigned NewIndent;
+ unsigned LastSpace = State.Stack.back().LastSpace;
bool AvoidBinPacking;
if (Current.is(tok::l_brace)) {
- NewIndent = Style.IndentWidth + State.Stack.back().LastSpace;
+ NewIndent = Style.IndentWidth + LastSpace;
AvoidBinPacking = false;
} else {
- NewIndent = 4 + std::max(State.Stack.back().LastSpace,
- State.Stack.back().StartOfFunctionCall);
+ NewIndent =
+ 4 + std::max(LastSpace, State.Stack.back().StartOfFunctionCall);
AvoidBinPacking = !Style.BinPackParameters;
}
- State.Stack.push_back(
- ParenState(NewIndent, State.Stack.back().LastSpace, AvoidBinPacking,
- State.Stack.back().NoLineBreak));
if (Current.NoMoreTokensOnLevel && Current.FakeLParens.empty()) {
// This parenthesis was the last token possibly making use of Indent and
- // LastSpace of the next higher ParenLevel. Thus, erase them to acieve
+ // LastSpace of the next higher ParenLevel. Thus, erase them to achieve
// better memoization results.
- State.Stack[State.Stack.size() - 2].Indent = 0;
- State.Stack[State.Stack.size() - 2].LastSpace = 0;
+ for (unsigned i = State.Stack.size() - 1; i > 0; --i) {
+ State.Stack[i].Indent = 0;
+ State.Stack[i].LastSpace = 0;
+ if (!State.Stack[i].ForFakeParenthesis)
+ break;
+ }
}
+ State.Stack.push_back(ParenState(NewIndent, LastSpace, AvoidBinPacking,
+ State.Stack.back().NoLineBreak));
++State.ParenLevel;
}