r219919 - clang-format: [ObjC] Fix method expression detection.
Daniel Jasper
djasper at google.com
Thu Oct 16 01:38:51 PDT 2014
Author: djasper
Date: Thu Oct 16 03:38:51 2014
New Revision: 219919
URL: http://llvm.org/viewvc/llvm-project?rev=219919&view=rev
Log:
clang-format: [ObjC] Fix method expression detection.
Before:
return (a)[foo bar : baz];
After:
return (a)[foo bar:baz];
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=219919&r1=219918&r2=219919&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Oct 16 03:38:51 2014
@@ -273,8 +273,16 @@ private:
}
if (CurrentToken->isOneOf(tok::r_paren, tok::r_brace))
return false;
- if (CurrentToken->is(tok::colon))
+ if (CurrentToken->is(tok::colon)) {
+ if (Left->Type == TT_ArraySubscriptLSquare) {
+ Left->Type = TT_ObjCMethodExpr;
+ StartsObjCMethodExpr = true;
+ Contexts.back().ColonIsObjCMethodExpr = true;
+ if (Parent && Parent->is(tok::r_paren))
+ Parent->Type = TT_CastRParen;
+ }
ColonFound = true;
+ }
if (CurrentToken->is(tok::comma) &&
Style.Language != FormatStyle::LK_Proto &&
(Left->Type == TT_ArraySubscriptLSquare ||
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=219919&r1=219918&r2=219919&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Oct 16 03:38:51 2014
@@ -6461,6 +6461,7 @@ TEST_F(FormatTest, FormatObjCMethodDecla
TEST_F(FormatTest, FormatObjCMethodExpr) {
verifyFormat("[foo bar:baz];");
verifyFormat("return [foo bar:baz];");
+ verifyFormat("return (a)[foo bar:baz];");
verifyFormat("f([foo bar:baz]);");
verifyFormat("f(2, [foo bar:baz]);");
verifyFormat("f(2, a ? b : c);");
@@ -9137,10 +9138,8 @@ TEST_F(FormatTest, FormatsBlocks) {
verifyFormat("foo(^{ bar(); });");
verifyFormat("foo(a, ^{ bar(); });");
- // FIXME: Make whitespace formatting consistent. Ask a ObjC dev how
- // it would ideally look.
verifyFormat("[operation setCompletionBlock:^{ [self onOperationDone]; }];");
- verifyFormat("int i = {[operation setCompletionBlock : ^{ [self "
+ verifyFormat("int i = {[operation setCompletionBlock:^{ [self "
"onOperationDone]; }]};");
verifyFormat("[operation setCompletionBlock:^(int *i) { f(); }];");
verifyFormat("int a = [operation block:^int(int *i) { return 1; }];");
More information about the cfe-commits
mailing list