[cfe-commits] r172093 - in /cfe/trunk: lib/Format/Format.cpp test/Index/comment-objc-decls.m unittests/Format/FormatTest.cpp

Nico Weber nicolasweber at gmx.de
Thu Jan 10 11:19:14 PST 2013


Author: nico
Date: Thu Jan 10 13:19:14 2013
New Revision: 172093

URL: http://llvm.org/viewvc/llvm-project?rev=172093&view=rev
Log:
Formatter: Add space before '(' in @implemenation, @interface, @protocol lines

The first token in @implementation, @interface, and @protocol lines is now
marked TT_ObjCDecl, and lines starting with a TT_ObjCDecl token are now marked
LT_ObjCMethodDecl.


Modified:
    cfe/trunk/lib/Format/Format.cpp
    cfe/trunk/test/Index/comment-objc-decls.m
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=172093&r1=172092&r2=172093&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Thu Jan 10 13:19:14 2013
@@ -37,6 +37,7 @@
   TT_DirectorySeparator,
   TT_LineComment,
   TT_ObjCBlockLParen,
+  TT_ObjCDecl,
   TT_ObjCMethodSpecifier,
   TT_OverloadedOperator,
   TT_PointerOrReference,
@@ -53,6 +54,7 @@
   LT_Other,
   LT_PreprocessorDirective,
   LT_VirtualFunctionDecl,
+  LT_ObjCDecl, // An @interface, @implementation, or @protocol line.
   LT_ObjCMethodDecl
 };
 
@@ -835,6 +837,8 @@
 
     if (RootToken.Type == TT_ObjCMethodSpecifier)
       CurrentLineType = LT_ObjCMethodDecl;
+    else if (RootToken.Type == TT_ObjCDecl)
+      CurrentLineType = LT_ObjCDecl;
 
     if (!RootToken.Children.empty())
       calculateExtraInformation(RootToken.Children[0]);
@@ -879,6 +883,15 @@
                   Current.Parent->Type == TT_TemplateCloser)) {
         // FIXME: We need to get smarter and understand more cases of casts.
         Current.Type = TT_CastRParen;
+      } else if (Current.is(tok::at) && Current.Children.size()) {
+        switch (Current.Children[0].FormatTok.Tok.getObjCKeywordID()) {
+        case tok::objc_interface:
+        case tok::objc_implementation:
+        case tok::objc_protocol:
+          Current.Type = TT_ObjCDecl;
+        default:
+          break;
+        }
       }
     }
 
@@ -997,8 +1010,9 @@
     if (Left.is(tok::l_paren))
       return false;
     if (Right.is(tok::l_paren)) {
-      return Left.is(tok::kw_if) || Left.is(tok::kw_for) ||
-             Left.is(tok::kw_while) || Left.is(tok::kw_switch) ||
+      return CurrentLineType == LT_ObjCDecl || Left.is(tok::kw_if) ||
+             Left.is(tok::kw_for) || Left.is(tok::kw_while) ||
+             Left.is(tok::kw_switch) ||
              Left.is(tok::kw_return) || Left.is(tok::kw_catch);
     }
     if (Left.is(tok::at) &&

Modified: cfe/trunk/test/Index/comment-objc-decls.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/comment-objc-decls.m?rev=172093&r1=172092&r2=172093&view=diff
==============================================================================
--- cfe/trunk/test/Index/comment-objc-decls.m (original)
+++ cfe/trunk/test/Index/comment-objc-decls.m Thu Jan 10 13:19:14 2013
@@ -90,7 +90,7 @@
   id IvarMyClassExtension;
 }
 @end
-// CHECK: <Declaration>@interface MyClass() {\n  id IvarMyClassExtension;\n}\n at end</Declaration>
+// CHECK: <Declaration>@interface MyClass () {\n  id IvarMyClassExtension;\n}\n at end</Declaration>
 // CHECK: <Declaration>id IvarMyClassExtension</Declaration>
 
 
@@ -108,7 +108,7 @@
 */
 @property (copy) id PropertyMyClassCategory;
 @end
-// CHECK: <Declaration>@interface MyClass(Category)\n at end</Declaration>
+// CHECK: <Declaration>@interface MyClass (Category)\n at end</Declaration>
 // CHECK: <Declaration>- (void)MethodMyClassCategory;</Declaration>
 // CHECK: <Declaration>@property(readwrite, copy, atomic) id PropertyMyClassCategory;</Declaration>
 // CHECK: <Declaration>- (id)PropertyMyClassCategory;</Declaration>
@@ -162,7 +162,7 @@
 */
 - (void) setPropertyMyClassCategory : (id) arg {}
 @end
-// CHECK: <Declaration>@implementation MyClass(Category)\n at end</Declaration>
+// CHECK: <Declaration>@implementation MyClass (Category)\n at end</Declaration>
 // CHECK: <Declaration>- (void)MethodMyClassCategory;</Declaration>
 // CHECK: <Declaration>- (id)PropertyMyClassCategory;</Declaration>
 // CHECK: <Declaration>- (void)setPropertyMyClassCategory:(id)arg;</Declaration>

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=172093&r1=172092&r2=172093&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Jan 10 13:19:14 2013
@@ -1232,16 +1232,15 @@
                "+ (id)init;\n"
                "@end");
 
-  // FIXME: there should be a space before '(' for categories.
-  verifyFormat("@interface Foo(HackStuff)\n"
+  verifyFormat("@interface Foo (HackStuff)\n"
                "+ (id)init;\n"
                "@end");
 
-  verifyFormat("@interface Foo()\n"
+  verifyFormat("@interface Foo ()\n"
                "+ (id)init;\n"
                "@end");
 
-  verifyFormat("@interface Foo(HackStuff)<MyProtocol>\n"
+  verifyFormat("@interface Foo (HackStuff)<MyProtocol>\n"
                "+ (id)init;\n"
                "@end");
 
@@ -1263,19 +1262,19 @@
                "+ (id)init;\n"
                "@end");
 
-  verifyFormat("@interface Foo(HackStuff) {\n"
+  verifyFormat("@interface Foo (HackStuff) {\n"
                "  int _i;\n"
                "}\n"
                "+ (id)init;\n"
                "@end");
 
-  verifyFormat("@interface Foo() {\n"
+  verifyFormat("@interface Foo () {\n"
                "  int _i;\n"
                "}\n"
                "+ (id)init;\n"
                "@end");
 
-  verifyFormat("@interface Foo(HackStuff)<MyProtocol> {\n"
+  verifyFormat("@interface Foo (HackStuff)<MyProtocol> {\n"
                "  int _i;\n"
                "}\n"
                "+ (id)init;\n"
@@ -1341,8 +1340,7 @@
                "+ (id)init {}\n"
                "@end");
 
-  // FIXME: there should be a space before '(' for categories.
-  verifyFormat("@implementation Foo(HackStuff)\n"
+  verifyFormat("@implementation Foo (HackStuff)\n"
                "+ (id)init {}\n"
                "@end");
 }





More information about the cfe-commits mailing list