[clang-format] Make parseUnaryOperator non-recursive, NFCI

Summary:
This patch makes the implementation of parseUnaryOperator non-recursive. We had
a problem with a file starting with tens of thousands of +'es and -'es which
caused clang-format to stack overflow.

Reviewers: bkramer

Reviewed By: bkramer

Subscribers: cfe-commits, klimek

Differential Revision: https://reviews.llvm.org/D39498

llvm-svn: 317113
This commit is contained in:
Krasimir Georgiev 2017-11-01 18:20:41 +00:00
parent ca1aa83cbe
commit 87b42549ee
1 changed files with 8 additions and 10 deletions

View File

@ -1662,17 +1662,15 @@ private:
/// \brief Parse unary operator expressions and surround them with fake /// \brief Parse unary operator expressions and surround them with fake
/// parentheses if appropriate. /// parentheses if appropriate.
void parseUnaryOperator() { void parseUnaryOperator() {
if (!Current || Current->isNot(TT_UnaryOperator)) { llvm::SmallVector<FormatToken *, 2> Tokens;
parse(PrecedenceArrowAndPeriod); while (Current && Current->is(TT_UnaryOperator)) {
return; Tokens.push_back(Current);
next();
} }
parse(PrecedenceArrowAndPeriod);
FormatToken *Start = Current; for (FormatToken *Token : llvm::reverse(Tokens))
next(); // The actual precedence doesn't matter.
parseUnaryOperator(); addFakeParenthesis(Token, prec::Unknown);
// The actual precedence doesn't matter.
addFakeParenthesis(Start, prec::Unknown);
} }
void parseConditionalExpr() { void parseConditionalExpr() {