clang-format: [ObjC] Fix using selector names as macro arguments.
authorDaniel Jasper <djasper@google.com>
Mon, 20 Oct 2014 12:01:45 +0000 (12:01 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 20 Oct 2014 12:01:45 +0000 (12:01 +0000)
Before:
  [self aaaaa:MACRO(a, b :, c :)];

After:
  [self aaaaa:MACRO(a, b:, c:)];

llvm-svn: 220197

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

index ad14aab..33627e5 100644 (file)
@@ -413,6 +413,11 @@ private:
       } else if (Contexts.size() == 1 &&
                  !Line.First->isOneOf(tok::kw_enum, tok::kw_case)) {
         Tok->Type = TT_InheritanceColon;
+      } else if (Tok->Previous->is(tok::identifier) && Tok->Next &&
+                 Tok->Next->isOneOf(tok::r_paren, tok::comma)) {
+        // This handles a special macro in ObjC code where selectors including
+        // the colon are passed as macro arguments.
+        Tok->Type = TT_ObjCMethodExpr;
       } else if (Contexts.back().ContextKind == tok::l_paren) {
         Tok->Type = TT_InlineASMColon;
       }
index 6961ab5..a16ee2c 100644 (file)
@@ -6539,6 +6539,7 @@ TEST_F(FormatTest, FormatObjCMethodExpr) {
   verifyFormat("return in[42];");
   verifyFormat("for (id foo in [self getStuffFor:bla]) {\n"
                "}");
+  verifyFormat("[self aaaaa:MACRO(a, b:, c:)];");
 
   verifyFormat("[self stuffWithInt:(4 + 2) float:4.5];");
   verifyFormat("[self stuffWithInt:a ? b : c float:4.5];");