r194267 - clang-format: Improve linebreaking and indentation for ObjC calls.

Daniel Jasper djasper at google.com
Fri Nov 8 09:33:24 PST 2013


Author: djasper
Date: Fri Nov  8 11:33:24 2013
New Revision: 194267

URL: http://llvm.org/viewvc/llvm-project?rev=194267&view=rev
Log:
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)]

Modified:
    cfe/trunk/lib/Format/ContinuationIndenter.cpp
    cfe/trunk/lib/Format/TokenAnnotator.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=194267&r1=194266&r2=194267&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Fri Nov  8 11:33:24 2013
@@ -277,7 +277,7 @@ void ContinuationIndenter::addTokenOnCur
     // 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 ||

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=194267&r1=194266&r2=194267&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Nov  8 11:33:24 2013
@@ -1180,7 +1180,7 @@ unsigned TokenAnnotator::splitPenalty(co
   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;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=194267&r1=194266&r2=194267&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Nov  8 11:33:24 2013
@@ -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"





More information about the cfe-commits mailing list