]> granicus.if.org Git - clang/commitdiff
clang-format: Improve expression heuristics.
authorDaniel Jasper <djasper@google.com>
Mon, 30 Jun 2014 13:44:47 +0000 (13:44 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 30 Jun 2014 13:44:47 +0000 (13:44 +0000)
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');

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@212040 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp

index 0760f35bbbc287c95ecc77fb6e856d02b88bd53f..c1fbf81e1199be1fe3ae2ba5fea9ade24acddd91 100644 (file)
@@ -164,6 +164,8 @@ private:
           CurrentToken->Previous->Previous->isOneOf(tok::l_paren,
                                                     tok::coloncolon))
         MightBeFunctionType = true;
+      if (CurrentToken->Previous->Type == TT_BinaryOperator)
+        Contexts.back().IsExpression = true;
       if (CurrentToken->is(tok::r_paren)) {
         if (MightBeFunctionType && CurrentToken->Next &&
             (CurrentToken->Next->is(tok::l_paren) ||
index 11a42a51faffb5cdaa72e2a6ca6038c982947efd..75eea9827530114167ac12ae368eb7c611fcaf31 100644 (file)
@@ -4841,6 +4841,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
   verifyIndependentOfContext("MACRO(int *i);");
   verifyIndependentOfContext("MACRO(auto *a);");
   verifyIndependentOfContext("MACRO(const A *a);");
+  verifyIndependentOfContext("MACRO('0' <= c && c <= '9');");
   // FIXME: Is there a way to make this work?
   // verifyIndependentOfContext("MACRO(A *a);");