From b530fa374a8d4d96e61bf1dae8f4a73f4b3d2436 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Thu, 10 Jan 2013 00:25:19 +0000 Subject: [PATCH] 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172023 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/Format.cpp | 2 ++ lib/Format/UnwrappedLineParser.cpp | 5 +++++ test/Index/comment-objc-decls.m | 2 +- unittests/Format/FormatTest.cpp | 8 ++++++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index e271ba2e13..beea48e9a3 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -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) diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index c049ac607d..9b2a1e90e1 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -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; } diff --git a/test/Index/comment-objc-decls.m b/test/Index/comment-objc-decls.m index c61d99598d..0e3c072121 100644 --- a/test/Index/comment-objc-decls.m +++ b/test/Index/comment-objc-decls.m @@ -32,7 +32,7 @@ @end // CHECK: @protocol MyProto\n@end // CHECK: - (unsigned int)MethodMyProto:(id)anObject inRange:(unsigned int)range; -// CHECK: @optional\n @property(readwrite, copy, atomic) id PropertyMyProto; +// CHECK: @optional\n@property(readwrite, copy, atomic) id PropertyMyProto; // CHECK: + (id)ClassMethodMyProto; /** diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index b536e012eb..9ed6b5f0f9 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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) { -- 2.40.0