diff options
| author | Daniel Jasper <djasper@google.com> | 2013-11-08 17:33:24 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2013-11-08 17:33:24 +0000 |
| commit | 4478e5245e208e63d4fe7cdc218f7e9a7aa29978 (patch) | |
| tree | 911b39c9fbdd118fa09164d5c625c335972c5a33 | |
| parent | 09e604333e56396c88ed4b53dfdf4b2cb0d4370c (diff) | |
| download | bcm5719-llvm-4478e5245e208e63d4fe7cdc218f7e9a7aa29978.tar.gz bcm5719-llvm-4478e5245e208e63d4fe7cdc218f7e9a7aa29978.zip | |
clang-format: Improve linebreaking and indentation for ObjC calls.
Before:
popup_wdow_.reset([[RenderWidgetPopupWindow alloc]
iniithContentRect:
NSMakRet(origin_global.x, origin_global.y, pos.width(), pos.height())
syeMask:NSBorderlessWindowMask
bking:NSBackingStoreBuffered
der:NO]);
[self param:function( //
parameter)]
After:
popup_wdow_.reset([[RenderWidgetPopupWindow alloc]
iniithContentRect:NSMakRet(origin_global.x, origin_global.y, pos.width(),
pos.height())
syeMask:NSBorderlessWindowMask
bking:NSBackingStoreBuffered
der:NO]);
[self param:function( //
parameter)]
llvm-svn: 194267
| -rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 2 | ||||
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 2 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 12 |
3 files changed, 14 insertions, 2 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index d075c7482d0..63232beb9f0 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -277,7 +277,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun, // Treat the condition inside an if as if it was a second function // parameter, i.e. let nested calls have a continuation indent. State.Stack.back().LastSpace = State.Column + 1; // 1 is length of "(". - else if (Previous.is(tok::comma)) + else if (Previous.is(tok::comma) || Previous.Type == TT_ObjCMethodExpr) State.Stack.back().LastSpace = State.Column; else if ((Previous.Type == TT_BinaryOperator || Previous.Type == TT_ConditionalExpr || diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 474f6a5adbb..074e1d78454 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1180,7 +1180,7 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line, if (Right.Type == TT_ObjCSelectorName) return 0; if (Left.is(tok::colon) && Left.Type == TT_ObjCMethodExpr) - return 20; + return 50; if (Left.is(tok::l_paren) && InFunctionDecl) return 100; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 776bf49a4aa..7e4131bd686 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -5432,6 +5432,16 @@ TEST_F(FormatTest, FormatObjCMethodExpr) { " backing:NSBackingStoreBuffered\n" " defer:NO]);\n" "}"); + verifyFormat( + "void f() {\n" + " popup_wdow_.reset([[RenderWidgetPopupWindow alloc]\n" + " iniithContentRect:NSMakRet(origin_global.x, origin_global.y,\n" + " pos.width(), pos.height())\n" + " syeMask:NSBorderlessWindowMask\n" + " bking:NSBackingStoreBuffered\n" + " der:NO]);\n" + "}", + getLLVMStyleWithColumns(70)); verifyFormat("[contentsContainer replaceSubview:[subviews objectAtIndex:0]\n" " with:contentsNativeView];"); @@ -5462,6 +5472,8 @@ TEST_F(FormatTest, FormatObjCMethodExpr) { " aaaaaaaaaa:bbbbbbbbbbbbbbbbb\n" " aaaaa:bbbbbbbbbbb + bbbbbbbbbbbb\n" " aaaa:bbb];"); + verifyFormat("[self param:function( //\n" + " parameter)]"); verifyFormat( "[self aaaaaaaaaa:aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa |\n" " aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa |\n" |

