]> granicus.if.org Git - clang/commitdiff
Formatter: @optional and @required go on their own line.
authorNico Weber <nicolasweber@gmx.de>
Thu, 10 Jan 2013 00:25:19 +0000 (00:25 +0000)
committerNico Weber <nicolasweber@gmx.de>
Thu, 10 Jan 2013 00:25:19 +0000 (00:25 +0000)
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

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

lib/Format/Format.cpp
lib/Format/UnwrappedLineParser.cpp
test/Index/comment-objc-decls.m
unittests/Format/FormatTest.cpp

index e271ba2e13abb581ffdc2246f80b09e887d2068a..beea48e9a3f52b6e8a27bb4aea8d758577b50a11 100644 (file)
@@ -273,6 +273,7 @@ private:
   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 @@ private:
   /// 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)
index c049ac607d3f0ac101b210b9f7bb52662394ca0c..9b2a1e90e1f70b2b89b96d4ce2db9783bdbe5ce0 100644 (file)
@@ -215,6 +215,11 @@ void UnwrappedLineParser::parseStructuralElement() {
       return parseObjCProtocol();
     case tok::objc_end:
       return; // Handled by the caller.
+    case tok::objc_optional:
+    case tok::objc_required:
+      nextToken();
+      addUnwrappedLine();
+      return;
     default:
       break;
     }
index c61d99598d0cc4a1bbfc7d9a3d97172a07544d1f..0e3c0721211b1edc46d90aa8f2aefe286629717e 100644 (file)
@@ -32,7 +32,7 @@
 @end
 // CHECK: <Declaration>@protocol MyProto\n@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@property(readwrite, copy, atomic) id PropertyMyProto;</Declaration>
 // CHECK: <Declaration>+ (id)ClassMethodMyProto;</Declaration>
 
 /**
index b536e012ebd10ed78f0ee4d93a7bd75880bd059b..9ed6b5f0f9a34f34785fa0773d03d2243ccadd09 100644 (file)
@@ -1340,6 +1340,14 @@ TEST_F(FormatTest, FormatObjCProtocol) {
                "@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) {