]> granicus.if.org Git - clang/commitdiff
clang-format: Fix bad wrapping of ObjC method exprs.
authorDaniel Jasper <djasper@google.com>
Wed, 6 May 2015 13:13:03 +0000 (13:13 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 6 May 2015 13:13:03 +0000 (13:13 +0000)
Before:
  [aaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaa:
      aaaaaaaa aaa:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa];

After:
  [aaaaaaaaaaaaaaaaaaaaaaaaa
      aaaaaaaaaaaaaaaaa:aaaaaaaa
                    aaa:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa];

Note that this might now violate the column limit and we probably need an
alternative way of indenting these then. However, that is still strictly better
than the messy formatting that clang-format did before.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236598 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/ContinuationIndenter.cpp
unittests/Format/FormatTest.cpp

index 83f719bd1c906c8d2106e1f3b553a88af08de457..430fe7723929a4c6a0c33a419a899f51c8052c7e 100644 (file)
@@ -166,6 +166,9 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
       ((Style.AllowShortFunctionsOnASingleLine != FormatStyle::SFS_All) ||
        Style.BreakConstructorInitializersBeforeComma || Style.ColumnLimit != 0))
     return true;
+  if (Current.is(TT_SelectorName) && State.Stack.back().ObjCSelectorNameFound &&
+      State.Stack.back().BreakBeforeParameter)
+    return true;
 
   if (State.Column < getNewLineColumn(State))
     return false;
@@ -203,9 +206,6 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
       State.Stack.back().FirstLessLess == 0)
     return true;
 
-  if (Current.is(TT_SelectorName) && State.Stack.back().ObjCSelectorNameFound &&
-      State.Stack.back().BreakBeforeParameter)
-    return true;
   if (Current.NestingLevel == 0 && !Current.isTrailingComment()) {
     if (Previous.ClosesTemplateDeclaration)
       return true;
index c0441495b8b34465684e6c0925ff42a9086b665f..7e75de4409a7406192938faae57c4ba713964023 100644 (file)
@@ -7162,6 +7162,13 @@ TEST_F(FormatTest, FormatObjCMethodExpr) {
       "                 aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa |\n"
       "                 aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa];");
 
+  // FIXME: This violates the column limit.
+  verifyFormat(
+      "[aaaaaaaaaaaaaaaaaaaaaaaaa\n"
+      "    aaaaaaaaaaaaaaaaa:aaaaaaaa\n"
+      "                  aaa:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa];",
+      getLLVMStyleWithColumns(60));
+
   // Variadic parameters.
   verifyFormat(
       "NSArray *myStrings = [NSArray stringarray:@\"a\", @\"b\", nil];");