[cfe-commits] r172238 - in /cfe/trunk: lib/Format/Format.cpp test/Index/comment-objc-decls.m unittests/Format/FormatTest.cpp
Manuel Klimek
klimek at google.com
Fri Jan 11 11:17:44 PST 2013
Author: klimek
Date: Fri Jan 11 13:17:44 2013
New Revision: 172238
URL: http://llvm.org/viewvc/llvm-project?rev=172238&view=rev
Log:
Fix single-line optimization for ObjC.
Puts blocks always into multiple lines when they start with an ObjC
keyword or minus.
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=172238&r1=172237&r2=172238&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Fri Jan 11 13:17:44 2013
@@ -1338,10 +1338,12 @@
// brace.
FormatToken *Last = &Combined.RootToken;
bool AllowedTokens =
- !Last->Tok.is(tok::kw_if) && !Last->Tok.is(tok::kw_while) &&
- !Last->Tok.is(tok::kw_do) && !Last->Tok.is(tok::r_brace) &&
- !Last->Tok.is(tok::kw_else) && !Last->Tok.is(tok::kw_try) &&
- !Last->Tok.is(tok::kw_catch) && !Last->Tok.is(tok::kw_for);
+ Last->Tok.isNot(tok::kw_if) && Last->Tok.isNot(tok::kw_while) &&
+ Last->Tok.isNot(tok::kw_do) && Last->Tok.isNot(tok::r_brace) &&
+ Last->Tok.isNot(tok::kw_else) && Last->Tok.isNot(tok::kw_try) &&
+ Last->Tok.isNot(tok::kw_catch) && Last->Tok.isNot(tok::kw_for) &&
+ // This gets rid of all ObjC @ keywords and - based definitions.
+ Last->Tok.isNot(tok::at) && Last->Tok.isNot(tok::minus);
while (!Last->Children.empty())
Last = &Last->Children.back();
if (!Last->Tok.is(tok::l_brace))
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=172238&r1=172237&r2=172238&view=diff
==============================================================================
--- cfe/trunk/test/Index/comment-objc-decls.m (original)
+++ cfe/trunk/test/Index/comment-objc-decls.m Fri Jan 11 13:17:44 2013
@@ -45,7 +45,7 @@
id IvarNSObject;
}
@end
-// CHECK: Declaration>@interface NSObject { id IvarNSObject; }\n at end</Declaration>
+// CHECK: Declaration>@interface NSObject {\n id IvarNSObject;\n}\n at end</Declaration>
// CHECK: <Declaration>id IvarNSObject</Declaration>
/**
@@ -73,7 +73,7 @@
*/
@property (copy) id PropertyMyClass;
@end
-// CHECK: <Declaration>@interface MyClass : NSObject <MyProto> { id IvarMyClass; }\n at end</Declaration>
+// CHECK: <Declaration>@interface MyClass : NSObject <MyProto> {\n id IvarMyClass;\n}\n at end</Declaration>
// CHECK: <Declaration>id IvarMyClass</Declaration>
// CHECK: <Declaration>- (id)MethodMyClass;</Declaration>
// CHECK: <Declaration>+ (id)ClassMethodMyClass;</Declaration>
@@ -90,7 +90,7 @@
id IvarMyClassExtension;
}
@end
-// CHECK: <Declaration>@interface MyClass () { id IvarMyClassExtension; }\n at end</Declaration>
+// CHECK: <Declaration>@interface MyClass () {\n id IvarMyClassExtension;\n}\n at end</Declaration>
// CHECK: <Declaration>id IvarMyClassExtension</Declaration>
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=172238&r1=172237&r2=172238&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Jan 11 13:17:44 2013
@@ -405,9 +405,15 @@
}
TEST_F(FormatTest, FormatObjCTryCatch) {
- verifyFormat("@try { f(); }\n"
- "@catch (NSException e) { @throw; }\n"
- "@finally { exit(42); }");
+ verifyFormat("@try {\n"
+ " f();\n"
+ "}\n"
+ "@catch (NSException e) {\n"
+ " @throw;\n"
+ "}\n"
+ "@finally {\n"
+ " exit(42);\n"
+ "}");
}
TEST_F(FormatTest, StaticInitializers) {
@@ -1305,27 +1311,39 @@
"+(id) init;\n"
"@end");
- verifyFormat("@interface Foo { int _i; }\n"
+ verifyFormat("@interface Foo {\n"
+ " int _i;\n"
+ "}\n"
"+ (id)init;\n"
"@end");
- verifyFormat("@interface Foo : Bar { int _i; }\n"
+ verifyFormat("@interface Foo : Bar {\n"
+ " int _i;\n"
+ "}\n"
"+ (id)init;\n"
"@end");
- verifyFormat("@interface Foo : Bar <Baz, Quux> { int _i; }\n"
+ verifyFormat("@interface Foo : Bar <Baz, Quux> {\n"
+ " int _i;\n"
+ "}\n"
"+ (id)init;\n"
"@end");
- verifyFormat("@interface Foo (HackStuff) { int _i; }\n"
+ verifyFormat("@interface Foo (HackStuff) {\n"
+ " int _i;\n"
+ "}\n"
"+ (id)init;\n"
"@end");
- verifyFormat("@interface Foo () { int _i; }\n"
+ verifyFormat("@interface Foo () {\n"
+ " int _i;\n"
+ "}\n"
"+ (id)init;\n"
"@end");
- verifyFormat("@interface Foo (HackStuff) <MyProtocol> { int _i; }\n"
+ verifyFormat("@interface Foo (HackStuff) <MyProtocol> {\n"
+ " int _i;\n"
+ "}\n"
"+ (id)init;\n"
"@end");
}
@@ -1363,7 +1381,9 @@
" return nil;\n"
"}\n"
"// Look, a comment!\n"
- "- (int)answerWith:(int)i { return i; }\n"
+ "- (int)answerWith:(int)i {\n"
+ " return i;\n"
+ "}\n"
"@end");
verifyFormat("@implementation Foo\n"
@@ -1375,11 +1395,15 @@
"+ (id)init {}\n"
"@end");
- verifyFormat("@implementation Foo { int _i; }\n"
+ verifyFormat("@implementation Foo {\n"
+ " int _i;\n"
+ "}\n"
"+ (id)init {}\n"
"@end");
- verifyFormat("@implementation Foo : Bar { int _i; }\n"
+ verifyFormat("@implementation Foo : Bar {\n"
+ " int _i;\n"
+ "}\n"
"+ (id)init {}\n"
"@end");
@@ -1469,14 +1493,18 @@
TEST_F(FormatTest, ObjCSnippets) {
// FIXME: Make the uncommented lines below pass.
- verifyFormat("@autoreleasepool { foo(); }");
+ verifyFormat("@autoreleasepool {\n"
+ " foo();\n"
+ "}");
verifyFormat("@class Foo, Bar;");
verifyFormat("@compatibility_alias AliasName ExistingClass;");
verifyFormat("@dynamic textColor;");
//verifyFormat("char *buf1 = @encode(int **);");
verifyFormat("Protocol *proto = @protocol(p1);");
//verifyFormat("SEL s = @selector(foo:);");
- verifyFormat("@synchronized(self) { f(); }");
+ verifyFormat("@synchronized(self) {\n"
+ " f();\n"
+ "}");
verifyFormat("@synthesize dropArrowPosition = dropArrowPosition_;");
verifyGoogleFormat("@synthesize dropArrowPosition = dropArrowPosition_;");
More information about the cfe-commits
mailing list