r195301 - clang-format: Improve formatting of ObjC method expressions.

Daniel Jasper djasper at google.com
Wed Nov 20 17:46:33 PST 2013


Author: djasper
Date: Wed Nov 20 19:46:33 2013
New Revision: 195301

URL: http://llvm.org/viewvc/llvm-project?rev=195301&view=rev
Log:
clang-format: Improve formatting of ObjC method expressions.

In particular, make breaking after a parameter's ":" more of a last
resort choice as it significantly affects the readability gained by
aligning the parameters.

Before (in Chromium style - which doesn't allow bin-packing):
  {
    popup_window_.reset([[RenderWidgetPopupWindow alloc]
        initWithContentRect:
            NSMakeRect(
                origin_global.x, origin_global.y, pos.width(), pos.height())
                  styleMask:NSBorderlessWindowMask
                    backing:NSBackingStoreBuffered
                      defer:NO]);
  }

After:
  {
    popup_window_.reset([[RenderWidgetPopupWindow alloc]
        initWithContentRect:NSMakeRect(origin_global.x,
                                       origin_global.y,
                                       pos.width(),
                                       pos.height())
                  styleMask:NSBorderlessWindowMask
                    backing:NSBackingStoreBuffered
                      defer:NO]);
  }

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=195301&r1=195300&r2=195301&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Nov 20 19:46:33 2013
@@ -1181,7 +1181,7 @@ unsigned TokenAnnotator::splitPenalty(co
   if (Right.Type == TT_ObjCSelectorName)
     return 0;
   if (Left.is(tok::colon) && Left.Type == TT_ObjCMethodExpr)
-    return 50;
+    return 500;
 
   if (Left.is(tok::l_paren) && InFunctionDecl)
     return 100;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=195301&r1=195300&r2=195301&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Nov 20 19:46:33 2013
@@ -5520,6 +5520,17 @@ TEST_F(FormatTest, FormatObjCMethodExpr)
       "                    der:NO]);\n"
       "}",
       getLLVMStyleWithColumns(70));
+  verifyFormat("{\n"
+               "  popup_window_.reset([[RenderWidgetPopupWindow alloc]\n"
+               "      initWithContentRect:NSMakeRect(origin_global.x,\n"
+               "                                     origin_global.y,\n"
+               "                                     pos.width(),\n"
+               "                                     pos.height())\n"
+               "                styleMask:NSBorderlessWindowMask\n"
+               "                  backing:NSBackingStoreBuffered\n"
+               "                    defer:NO]);\n"
+               "}",
+               getChromiumStyle());
   verifyFormat("[contentsContainer replaceSubview:[subviews objectAtIndex:0]\n"
                "                             with:contentsNativeView];");
 





More information about the cfe-commits mailing list