[cfe-commits] r172110 - in /cfe/trunk: lib/Format/Format.cpp unittests/Format/FormatTest.cpp

Nico Weber nicolasweber at gmx.de
Thu Jan 10 13:30:43 PST 2013


Author: nico
Date: Thu Jan 10 15:30:42 2013
New Revision: 172110

URL: http://llvm.org/viewvc/llvm-project?rev=172110&view=rev
Log:
Formatter: No spaces around '=' in @property lines.

Before:
@property(assign, getter = isEditable) BOOL editable;

Now:
@property(assign, getter=isEditable) BOOL editable;

It'd be nice if some Apple person could let me know if spaces are preferred
around '=' in @synthesize lines (see FIXME in the test).


Modified:
    cfe/trunk/lib/Format/Format.cpp
    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=172110&r1=172109&r2=172110&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Thu Jan 10 15:30:42 2013
@@ -39,6 +39,7 @@
   TT_ObjCBlockLParen,
   TT_ObjCDecl,
   TT_ObjCMethodSpecifier,
+  TT_ObjCProperty,
   TT_OverloadedOperator,
   TT_PointerOrReference,
   TT_PureVirtualSpecifier,
@@ -55,7 +56,8 @@
   LT_PreprocessorDirective,
   LT_VirtualFunctionDecl,
   LT_ObjCDecl, // An @interface, @implementation, or @protocol line.
-  LT_ObjCMethodDecl
+  LT_ObjCMethodDecl,
+  LT_ObjCProperty // An @property line.
 };
 
 class AnnotatedToken {
@@ -841,6 +843,8 @@
       CurrentLineType = LT_ObjCMethodDecl;
     else if (RootToken.Type == TT_ObjCDecl)
       CurrentLineType = LT_ObjCDecl;
+    else if (RootToken.Type == TT_ObjCProperty)
+      CurrentLineType = LT_ObjCProperty;
 
     if (!RootToken.Children.empty())
       calculateExtraInformation(RootToken.Children[0]);
@@ -891,6 +895,10 @@
         case tok::objc_implementation:
         case tok::objc_protocol:
           Current.Type = TT_ObjCDecl;
+          break;
+        case tok::objc_property:
+          Current.Type = TT_ObjCProperty;
+          break;
         default:
           break;
         }
@@ -1044,6 +1052,9 @@
         // Don't space between ':' and '('
         return false;
     }
+    if (CurrentLineType == LT_ObjCProperty &&
+        (Tok.is(tok::equal) || Tok.Parent->is(tok::equal)))
+      return false;
 
     if (Tok.Type == TT_CtorInitializerColon || Tok.Type == TT_ObjCBlockLParen)
       return true;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=172110&r1=172109&r2=172110&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Jan 10 15:30:42 2013
@@ -1430,7 +1430,6 @@
   verifyFormat("@[");
   verifyFormat("@{");
 
-
   EXPECT_EQ("@interface", format("@ interface"));
 
   // The precise formatting of this doesn't matter, nobody writes code like
@@ -1452,10 +1451,16 @@
   verifyFormat("@synchronized(self) {\n"
                "  f();\n"
                "}");
+
+  // FIXME: Some Apple code examples don't have spaces around '=' for
+  // @synthesize, decide if that's desired or not in LLVM style. Google style
+  // definitely wants spaces.
   verifyFormat("@synthesize dropArrowPosition = dropArrowPosition_;");
+  verifyGoogleFormat("@synthesize dropArrowPosition = dropArrowPosition_;");
 
-  // FIXME: "getter=bar" should not be surround by spaces in @property.
   verifyFormat("@property(assign, nonatomic) CGFloat hoverAlpha;");
+  verifyFormat("@property(assign, getter=isEditable) BOOL editable;");
+  verifyGoogleFormat("@property(assign, getter=isEditable) BOOL editable;");
 }
 
 } // end namespace tooling





More information about the cfe-commits mailing list