]> granicus.if.org Git - clang/commitdiff
clang-format: Fix ObjC block as first call parameter formatting.
authorDaniel Jasper <djasper@google.com>
Sun, 19 Jan 2014 07:46:32 +0000 (07:46 +0000)
committerDaniel Jasper <djasper@google.com>
Sun, 19 Jan 2014 07:46:32 +0000 (07:46 +0000)
Before:
  foo (^{ bar(); });
After:
  foo(^{ bar(); });

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

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

index d80e5504949052c75b233e1de3525bc58822e981..45d60726dcb25e6ee1e5c5cef099bfbdb328e60d 100644 (file)
@@ -171,6 +171,8 @@ private:
       }
       if (CurrentToken->isOneOf(tok::r_square, tok::r_brace))
         return false;
+      else if (CurrentToken->is(tok::l_brace))
+        Left->Type = TT_Unknown; // Not TT_ObjCBlockLParen
       updateParameterCount(Left, CurrentToken);
       if (CurrentToken->is(tok::comma) && CurrentToken->Next &&
           !CurrentToken->Next->HasUnescapedNewline &&
index 0fade5b42f04ed94d3fbb9981cb76466f072fbe2..cff28d456ce1427e5fd60b49c80bcad33cb1b471 100644 (file)
@@ -5404,11 +5404,6 @@ TEST_F(FormatTest, FormatForObjectiveCMethodDecls) {
   verifyGoogleFormat("- foo:(int)foo;");
 }
 
-TEST_F(FormatTest, FormatObjCBlocks) {
-  verifyFormat("int (^Block)(int, int);");
-  verifyFormat("int (^Block1)(int, int) = ^(int i, int j)");
-}
-
 TEST_F(FormatTest, FormatObjCInterface) {
   verifyFormat("@interface Foo : NSObject <NSSomeDelegate> {\n"
                "@public\n"
@@ -7905,6 +7900,12 @@ TEST_F(FormatTest, FormatsLambdas) {
 }
 
 TEST_F(FormatTest, FormatsBlocks) {
+  verifyFormat("int (^Block)(int, int);");
+  verifyFormat("int (^Block1)(int, int) = ^(int i, int j)");
+
+  verifyFormat("foo(^{ bar(); });");
+  verifyFormat("foo(a, ^{ bar(); });");
+
   // FIXME: Make whitespace formatting consistent. Ask a ObjC dev how
   // it would ideally look.
   verifyFormat("[operation setCompletionBlock:^{ [self onOperationDone]; }];");