Formatter: Detect ObjC method expressions after casts.
authorNico Weber <nicolasweber@gmx.de>
Wed, 13 Feb 2013 03:48:27 +0000 (03:48 +0000)
committerNico Weber <nicolasweber@gmx.de>
Wed, 13 Feb 2013 03:48:27 +0000 (03:48 +0000)
Not all casts are correctly detected yet, but it helps in some cases.

llvm-svn: 175028

clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

index 2370597..ececc7c 100644 (file)
@@ -197,7 +197,7 @@ private:
         !Parent || Parent->is(tok::colon) || Parent->is(tok::l_square) ||
         Parent->is(tok::l_paren) || Parent->is(tok::kw_return) ||
         Parent->is(tok::kw_throw) || isUnaryOperator(*Parent) ||
-        Parent->Type == TT_ObjCForIn ||
+        Parent->Type == TT_ObjCForIn || Parent->Type == TT_CastRParen ||
         getBinOpPrecedence(Parent->FormatTok.Tok.getKind(), true, true) >
         prec::Unknown;
     bool StartsObjCArrayLiteral = Parent && Parent->is(tok::at);
index f28bc88..f2ccdb0 100644 (file)
@@ -2405,7 +2405,8 @@ TEST_F(FormatTest, FormatObjCMethodExpr) {
   verifyFormat("int a = &[foo bar:baz];");
   verifyFormat("int a = *[foo bar:baz];");
   // FIXME: Make casts work, without breaking f()[4].
-  //verifyFormat("int a = (int) [foo bar:baz];");
+  //verifyFormat("int a = (int)[foo bar:baz];");
+  verifyFormat("return (MyType *)[self.tableView cellForRowAtIndexPath:cell];");
 
   // Binary operators.
   verifyFormat("[foo bar:baz], [foo bar:baz];");