]> granicus.if.org Git - clang/commitdiff
Improve formatting of function types.
authorDaniel Jasper <djasper@google.com>
Wed, 15 May 2013 07:51:51 +0000 (07:51 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 15 May 2013 07:51:51 +0000 (07:51 +0000)
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)

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

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

index 11f81fd8baf732ba57c46480160c845b6d77628d..e0552de01db7a19c5319ff80ea33e3b887bbdd6c 100644 (file)
@@ -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);
index 206343bb690a2f14f72f8c344ab7d288f21ebd5a..081303af6a14e6338ea2f5cb6fc2f60319474106 100644 (file)
@@ -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) {