r175028 - Formatter: Detect ObjC method expressions after casts.
Nico Weber
nicolasweber at gmx.de
Tue Feb 12 19:48:27 PST 2013
Author: nico
Date: Tue Feb 12 21:48:27 2013
New Revision: 175028
URL: http://llvm.org/viewvc/llvm-project?rev=175028&view=rev
Log:
Formatter: Detect ObjC method expressions after casts.
Not all casts are correctly detected yet, but it helps in some cases.
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=175028&r1=175027&r2=175028&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Feb 12 21:48:27 2013
@@ -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);
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=175028&r1=175027&r2=175028&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Feb 12 21:48:27 2013
@@ -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];");
More information about the cfe-commits
mailing list