clang-format: Improve expression heuristics.

Upon encountering a binary operator inside parentheses, assume that the
parentheses contain an expression.

Before:
  MACRO('0' <= c&& c <= '9');

After:
  MACRO('0' <= c && c <= '9');

llvm-svn: 212040
This commit is contained in:
Daniel Jasper 2014-06-30 13:44:47 +00:00
parent ae82987cf8
commit 91beebd04a
2 changed files with 3 additions and 0 deletions

View File

@ -164,6 +164,8 @@ private:
CurrentToken->Previous->Previous->isOneOf(tok::l_paren, CurrentToken->Previous->Previous->isOneOf(tok::l_paren,
tok::coloncolon)) tok::coloncolon))
MightBeFunctionType = true; MightBeFunctionType = true;
if (CurrentToken->Previous->Type == TT_BinaryOperator)
Contexts.back().IsExpression = true;
if (CurrentToken->is(tok::r_paren)) { if (CurrentToken->is(tok::r_paren)) {
if (MightBeFunctionType && CurrentToken->Next && if (MightBeFunctionType && CurrentToken->Next &&
(CurrentToken->Next->is(tok::l_paren) || (CurrentToken->Next->is(tok::l_paren) ||

View File

@ -4841,6 +4841,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
verifyIndependentOfContext("MACRO(int *i);"); verifyIndependentOfContext("MACRO(int *i);");
verifyIndependentOfContext("MACRO(auto *a);"); verifyIndependentOfContext("MACRO(auto *a);");
verifyIndependentOfContext("MACRO(const A *a);"); verifyIndependentOfContext("MACRO(const A *a);");
verifyIndependentOfContext("MACRO('0' <= c && c <= '9');");
// FIXME: Is there a way to make this work? // FIXME: Is there a way to make this work?
// verifyIndependentOfContext("MACRO(A *a);"); // verifyIndependentOfContext("MACRO(A *a);");