]> granicus.if.org Git - clang/commitdiff
Fix ObjC block declarations.
authorDaniel Jasper <djasper@google.com>
Wed, 9 Jan 2013 08:36:49 +0000 (08:36 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 9 Jan 2013 08:36:49 +0000 (08:36 +0000)
Before: int ( ^ Block1) (int, int) = ^ (int i, int j)
After:  int (^Block1) (int, int) = ^(int i, int j)

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

lib/Format/Format.cpp
test/Index/comment-c-decls.c
test/Index/format-comment-cdecls.c
unittests/Format/FormatTest.cpp

index e8c6210fae247959a8ea7802f98b81bca0d81279..16e8c2d6c5cb30d7a55c9081de27e97dbdfb3593 100644 (file)
@@ -846,8 +846,9 @@ private:
     if (Current.Type == TT_Unknown) {
       if (Current.is(tok::star) || Current.is(tok::amp)) {
         Current.Type = determineStarAmpUsage(Current, IsRHS);
-      } else if (Current.is(tok::minus) || Current.is(tok::plus)) {
-        Current.Type = determinePlusMinusUsage(Current);
+      } else if (Current.is(tok::minus) || Current.is(tok::plus) ||
+                 Current.is(tok::caret)) {
+        Current.Type = determinePlusMinusCaretUsage(Current);
       } else if (Current.is(tok::minusminus) || Current.is(tok::plusplus)) {
         Current.Type = determineIncrementUsage(Current);
       } else if (Current.is(tok::exclaim)) {
@@ -905,7 +906,7 @@ private:
     return TT_PointerOrReference;
   }
 
-  TokenType determinePlusMinusUsage(const AnnotatedToken &Tok) {
+  TokenType determinePlusMinusCaretUsage(const AnnotatedToken &Tok) {
     // At the start of the line, +/- specific ObjectiveC method declarations.
     if (Tok.Parent == NULL)
       return TT_ObjCMethodSpecifier;
index be45ee205fb7ba27b71dcb44366797e40c166167..f6d3feec81c377f0ecbeb33aef2e3051b496ff83 100644 (file)
@@ -95,10 +95,10 @@ enum e {
  *\brief block declaration
 */
 int (^Block) (int i, int j);
-// CHECK: <Declaration>int ( ^ Block) (int, int)</Declaration>
+// CHECK: <Declaration>int (^Block) (int, int)</Declaration>
 
 /**
  *\brief block declaration
 */
 int (^Block1) (int i, int j) = ^(int i, int j) { return i + j; };
-// CHECK: <Declaration>int ( ^ Block1) (int, int) = ^ (int i, int j) {\n}</Declaration>
+// CHECK: <Declaration>int (^Block1) (int, int) = ^(int i, int j) {\n}</Declaration>
index b1539fe1cc892eaaa7f3810cadd5e9177b74fa80..31ec95b9212810db7873b719af377cf3c4580355 100644 (file)
@@ -90,10 +90,10 @@ enum e {
  *\brief block declaration
 */
 int (^Block) (int i, int j);
-// CHECK: <Declaration>int ( ^ Block) (int, int)</Declaration>
+// CHECK: <Declaration>int (^Block) (int, int)</Declaration>
 
 /**
  *\brief block declaration
 */
 int (^Block1) (int i, int j) = ^(int i, int j) { return i + j; };
-// CHECK: <Declaration>int ( ^ Block1) (int, int) = ^ (int i, int j) {\n}</Declaration>
+// CHECK: <Declaration>int (^Block1) (int, int) = ^(int i, int j) {\n}</Declaration>
index 9bf3097a5c13daa0496dfcf13a0d9f6dbfedfaa7..2e6424dd00d68d48504f0d37dc32b7ce89be7e6a 100644 (file)
@@ -1122,6 +1122,11 @@ TEST_F(FormatTest, FormatForObjectiveCMethodDecls) {
           "outRange8:(NSRange) out_range8  outRange9:(NSRange) out_range9;"));
 }
 
+TEST_F(FormatTest, FormatObjCBlocks) {
+  verifyFormat("int (^Block) (int, int);");
+  verifyFormat("int (^Block1) (int, int) = ^(int i, int j)");
+}
+
 TEST_F(FormatTest, ObjCAt) {
   verifyFormat("@autoreleasepool");
   verifyFormat("@catch");