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

Nico Weber nicolasweber at gmx.de
Wed Jan 9 16:25:19 PST 2013


Author: nico
Date: Wed Jan  9 18:25:19 2013
New Revision: 172023

URL: http://llvm.org/viewvc/llvm-project?rev=172023&view=rev
Log:
Formatter: @optional and @required go on their own line.

Previously:
@protocol myProtocol
- (void)mandatoryWithInt:(int)i;
@optional - (void) optional;
@required - (void) required;
@end

Now:
@protocol myProtocol
- (void)mandatoryWithInt:(int)i;
@optional
- (void)optional;
@required
- (void)required;
@end


Modified:
    cfe/trunk/lib/Format/Format.cpp
    cfe/trunk/lib/Format/UnwrappedLineParser.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=172023&r1=172022&r2=172023&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Wed Jan  9 18:25:19 2013
@@ -273,6 +273,7 @@
   void addTokenToState(bool Newline, bool DryRun, IndentState &State) {
     const AnnotatedToken &Current = *State.NextToken;
     const AnnotatedToken &Previous = *State.NextToken->Parent;
+    assert(State.Indent.size());
     unsigned ParenLevel = State.Indent.size() - 1;
 
     if (Newline) {
@@ -357,6 +358,7 @@
   /// accordingly.
   void moveStateToNextToken(IndentState &State) {
     const AnnotatedToken &Current = *State.NextToken;
+    assert(State.Indent.size());
     unsigned ParenLevel = State.Indent.size() - 1;
 
     if (Current.is(tok::lessless) && State.FirstLessLess[ParenLevel] == 0)

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=172023&r1=172022&r2=172023&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Wed Jan  9 18:25:19 2013
@@ -215,6 +215,11 @@
       return parseObjCProtocol();
     case tok::objc_end:
       return; // Handled by the caller.
+    case tok::objc_optional:
+    case tok::objc_required:
+      nextToken();
+      addUnwrappedLine();
+      return;
     default:
       break;
     }

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=172023&r1=172022&r2=172023&view=diff
==============================================================================
--- cfe/trunk/test/Index/comment-objc-decls.m (original)
+++ cfe/trunk/test/Index/comment-objc-decls.m Wed Jan  9 18:25:19 2013
@@ -32,7 +32,7 @@
 @end
 // CHECK: <Declaration>@protocol MyProto\n at end</Declaration>
 // CHECK: <Declaration>- (unsigned int)MethodMyProto:(id)anObject inRange:(unsigned int)range;</Declaration>
-// CHECK: <Declaration>@optional\n    @property(readwrite, copy, atomic) id PropertyMyProto;</Declaration>
+// CHECK: <Declaration>@optional\n at property(readwrite, copy, atomic) id PropertyMyProto;</Declaration>
 // CHECK: <Declaration>+ (id)ClassMethodMyProto;</Declaration>
 
 /**

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=172023&r1=172022&r2=172023&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Jan  9 18:25:19 2013
@@ -1340,6 +1340,14 @@
                "@end\n"
                "@protocol Bar\n"
                "@end");
+
+  verifyFormat("@protocol myProtocol\n"
+               "- (void)mandatoryWithInt:(int)i;\n"
+               "@optional\n"
+               "- (void)optional;\n"
+               "@required\n"
+               "- (void)required;\n"
+               "@end\n");
 }
 
 TEST_F(FormatTest, ObjCAt) {





More information about the cfe-commits mailing list