[PATCH] D17922: [clang-format] Don't add a space before Obj-C selector methods that are also clang-format keywords

Kent Sutherland via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 6 20:30:00 PST 2016


ksuther created this revision.
ksuther added a reviewer: djasper.
ksuther added a subscriber: cfe-commits.
Herald added a subscriber: klimek.

The following Obj-C methods will get formatted with an extra space between the right paren and the name:

`- (void)delete:(id)sender`
`- (void)export:(id)sender`

So they'll incorrectly appear as:

`- (void) delete:(id)sender`
`- (void) export:(id)sender`

The fix is to check if the token is a TT_SelectorName instead of tok::identifier. That way keywords recognized by clang-format still get treated as an Obj-C method name (because they're both a TT_SelectorName and tok::delete type).

http://reviews.llvm.org/D17922

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

Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -7433,6 +7433,7 @@
                "                         y:(id<yyyyyyyyyyyyyyyyyyyy>)y\n"
                "    NS_DESIGNATED_INITIALIZER;",
                getLLVMStyleWithColumns(60));
+  verifyFormat("- (void)delete:(id)sender\n");
 
   // Continuation indent width should win over aligning colons if the function
   // name is long.
Index: lib/Format/TokenAnnotator.cpp
===================================================================
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2077,7 +2077,7 @@
   if (Line.Type == LT_ObjCMethodDecl) {
     if (Left.is(TT_ObjCMethodSpecifier))
       return true;
-    if (Left.is(tok::r_paren) && Right.is(tok::identifier))
+    if (Left.is(tok::r_paren) && Right.is(TT_SelectorName))
       // Don't space between ')' and <id>
       return false;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17922.49930.patch
Type: text/x-patch
Size: 1011 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160307/d029fba4/attachment.bin>


More information about the cfe-commits mailing list