r181870 - Improve formatting of function types.

Daniel Jasper djasper at google.com
Wed May 15 00:51:51 PDT 2013


Author: djasper
Date: Wed May 15 02:51:51 2013
New Revision: 181870

URL: http://llvm.org/viewvc/llvm-project?rev=181870&view=rev
Log:
Improve formatting of function types.

The function type detection in r181438 and r181764 detected function
types too eagerly. This led to inconsistent formatting of inline
assembly and (together with r181687) to an incorrect formatting of calls
in macros.

Before: #define DEREF_AND_CALL_F(parameter) f (*parameter)
After:  #define DEREF_AND_CALL_F(parameter) f(*parameter)

Modified:
    cfe/trunk/lib/Format/TokenAnnotator.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=181870&r1=181869&r2=181870&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed May 15 02:51:51 2013
@@ -155,6 +155,9 @@ private:
       }
 
       if (CurrentToken->is(tok::r_paren)) {
+        if (CurrentToken->Children.empty() ||
+            !CurrentToken->Children[0].isOneOf(tok::l_paren, tok::l_square))
+          Left->DefinesFunctionType = false;
         if (CurrentToken->Parent->closesScope())
           CurrentToken->Parent->MatchingParen->NoMoreTokensOnLevel = true;
         Left->MatchingParen = CurrentToken;
@@ -173,9 +176,7 @@ private:
       }
       if (CurrentToken->isOneOf(tok::r_square, tok::r_brace))
         return false;
-      if (Left->Parent &&
-          !Left->Parent->isOneOf(tok::kw_sizeof, tok::kw_alignof) &&
-          CurrentToken->Parent->Type == TT_PointerOrReference &&
+      if (CurrentToken->Parent->Type == TT_PointerOrReference &&
           CurrentToken->Parent->Parent->isOneOf(tok::l_paren, tok::coloncolon))
         Left->DefinesFunctionType = true;
       updateParameterCount(Left, CurrentToken);

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=181870&r1=181869&r2=181870&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed May 15 02:51:51 2013
@@ -1110,7 +1110,7 @@ TEST_F(FormatTest, FormatsInlineASM) {
       "asm(\"movq\\t%%rbx, %%rsi\\n\\t\"\n"
       "    \"cpuid\\n\\t\"\n"
       "    \"xchgq\\t%%rbx, %%rsi\\n\\t\"\n"
-      "    : \"=a\" (*rEAX), \"=S\" (*rEBX), \"=c\" (*rECX), \"=d\" (*rEDX)\n"
+      "    : \"=a\"(*rEAX), \"=S\"(*rEBX), \"=c\"(*rECX), \"=d\"(*rEDX)\n"
       "    : \"a\"(value));");
 }
 
@@ -2803,9 +2803,9 @@ TEST_F(FormatTest, FormatsFunctionTypes)
   verifyGoogleFormat("A<void*(int*, SomeType*)>;");
   verifyGoogleFormat("void* (*a)(int);");
 
-  // Other constructs can look like function types:
+  // Other constructs can look somewhat like function types:
   verifyFormat("A<sizeof(*x)> a;");
-  verifyFormat("A<alignof(*x)> a;");
+  verifyFormat("#define DEREF_AND_CALL_F(x) f(*x)");
 }
 
 TEST_F(FormatTest, BreaksLongDeclarations) {





More information about the cfe-commits mailing list