r333539 - Revert "[clang-format] Fix putting ObjC message arguments in one line for multiline receiver"

Jacek Olesiak via cfe-commits cfe-commits at lists.llvm.org
Wed May 30 05:57:58 PDT 2018


Author: jolesiak
Date: Wed May 30 05:57:58 2018
New Revision: 333539

URL: http://llvm.org/viewvc/llvm-project?rev=333539&view=rev
Log:
Revert "[clang-format] Fix putting ObjC message arguments in one line for multiline receiver"

Summary:
This reverts commit db9e5e9a616d7fdd4d1ba4c3b2cd89d8a0238533 (rC333171).

Mentioned change introduced unintended formatting of ObjC code due to split priorities inherited from C/C++, e.g.:
```
fooooooo = [
    [obj fooo] aaa:42 aaa:42];
```
instead of
```
fooooooo =
    [[obj fooo] aaa:42
                aaa:42];
```
when formatted with ColumnLimit = 30.

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: benhamilton, klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D47527

Modified:
    cfe/trunk/lib/Format/ContinuationIndenter.cpp
    cfe/trunk/unittests/Format/FormatTestObjC.cpp

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=333539&r1=333538&r2=333539&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Wed May 30 05:57:58 2018
@@ -1387,29 +1387,6 @@ void ContinuationIndenter::moveStatePast
        (Current.is(tok::greater) && Current.is(TT_DictLiteral))))
     State.Stack.pop_back();
 
-  // Reevaluate whether ObjC message arguments fit into one line.
-  // If a receiver spans multiple lines, e.g.:
-  //   [[object block:^{
-  //     return 42;
-  //   }] a:42 b:42];
-  // BreakBeforeParameter is calculated based on an incorrect assumption
-  // (it is checked whether the whole expression fits into one line without
-  // considering a line break inside a message receiver).
-  // We check whether arguements fit after receiver scope closer (into the same
-  // line).
-  if (Current.MatchingParen && Current.MatchingParen->Previous) {
-    const FormatToken &CurrentScopeOpener = *Current.MatchingParen->Previous;
-    if (CurrentScopeOpener.is(TT_ObjCMethodExpr) &&
-        CurrentScopeOpener.MatchingParen) {
-      int NecessarySpaceInLine =
-          getLengthToMatchingParen(CurrentScopeOpener, State.Stack) +
-          CurrentScopeOpener.TotalLength - Current.TotalLength - 1;
-      if (State.Column + Current.ColumnWidth + NecessarySpaceInLine <=
-          Style.ColumnLimit)
-        State.Stack.back().BreakBeforeParameter = false;
-    }
-  }
-
   if (Current.is(tok::r_square)) {
     // If this ends the array subscript expr, reset the corresponding value.
     const FormatToken *NextNonComment = Current.getNextNonComment();

Modified: cfe/trunk/unittests/Format/FormatTestObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestObjC.cpp?rev=333539&r1=333538&r2=333539&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestObjC.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestObjC.cpp Wed May 30 05:57:58 2018
@@ -796,41 +796,6 @@ TEST_F(FormatTestObjC, FormatObjCMethodE
   verifyFormat("[((Foo *)foo) bar];");
   verifyFormat("[((Foo *)foo) bar:1 blech:2];");
 
-  // Message receiver taking multiple lines.
-  Style.ColumnLimit = 20;
-  // Non-corner case.
-  verifyFormat("[[object block:^{\n"
-               "  return 42;\n"
-               "}] a:42 b:42];");
-  // Arguments just fit into one line.
-  verifyFormat("[[object block:^{\n"
-               "  return 42;\n"
-               "}] aaaaaaa:42 b:42];");
-  // Arguments just over a column limit.
-  verifyFormat("[[object block:^{\n"
-               "  return 42;\n"
-               "}] aaaaaaa:42\n"
-               "        bb:42];");
-  // Arguments just fit into one line.
-  Style.ColumnLimit = 23;
-  verifyFormat("[[obj a:42\n"
-               "      b:42\n"
-               "      c:42\n"
-               "      d:42] e:42 f:42];");
-
-  // Arguments do not fit into one line with a receiver.
-  Style.ColumnLimit = 20;
-  verifyFormat("[[obj a:42] a:42\n"
-               "            b:42];");
-  verifyFormat("[[obj a:42] a:42\n"
-               "            b:42\n"
-               "            c:42];");
-  verifyFormat("[[obj aaaaaa:42\n"
-               "           b:42]\n"
-               "    cc:42\n"
-               "     d:42];");
-
-
   Style.ColumnLimit = 70;
   verifyFormat(
       "void f() {\n"




More information about the cfe-commits mailing list