r217687 - clang-format: Improve line breaks at function calls.

Daniel Jasper djasper at google.com
Fri Sep 12 09:35:29 PDT 2014


Author: djasper
Date: Fri Sep 12 11:35:28 2014
New Revision: 217687

URL: http://llvm.org/viewvc/llvm-project?rev=217687&view=rev
Log:
clang-format: Improve line breaks at function calls.

Before:
  EXPECT_CALL(SomeObject, SomeFunction(Parameter)).Times(2).WillRepeatedly(
      Return(SomeValue));

After:
  EXPECT_CALL(SomeObject, SomeFunction(Parameter))
      .Times(2)
      .WillRepeatedly(Return(SomeValue));

Modified:
    cfe/trunk/lib/Format/ContinuationIndenter.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=217687&r1=217686&r2=217687&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Fri Sep 12 11:35:28 2014
@@ -302,6 +302,18 @@ void ContinuationIndenter::addTokenOnCur
   if (startsSegmentOfBuilderTypeCall(Current))
     State.Stack.back().ContainsUnwrappedBuilder = true;
 
+  if (Current.isMemberAccess() && Previous.is(tok::r_paren) &&
+      (Previous.MatchingParen &&
+       (Previous.TotalLength - Previous.MatchingParen->TotalLength > 10))) {
+    // If there is a function call with long parameters, break before trailing
+    // calls. This prevents things like:
+    //   EXPECT_CALL(SomeLongParameter).Times(
+    //       2);
+    // We don't want to do this for short parameters as they can just be
+    // indexes.
+    State.Stack.back().NoLineBreak = true;
+  }
+
   State.Column += Spaces;
   if (Current.isNot(tok::comment) && Previous.is(tok::l_paren) &&
       Previous.Previous && Previous.Previous->isOneOf(tok::kw_if, tok::kw_for))

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=217687&r1=217686&r2=217687&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Sep 12 11:35:28 2014
@@ -4452,6 +4452,11 @@ TEST_F(FormatTest, WrapsAtFunctionCallsI
 
   verifyFormat("EXPECT_CALL(SomeObject, SomeFunction(Parameter))\n"
                "    .WillRepeatedly(Return(SomeValue));");
+  verifyFormat("void f() {\n"
+               "  EXPECT_CALL(SomeObject, SomeFunction(Parameter))\n"
+               "      .Times(2)\n"
+               "      .WillRepeatedly(Return(SomeValue));\n"
+               "}");
   verifyFormat("SomeMap[std::pair(aaaaaaaaaaaa, bbbbbbbbbbbbbbb)].insert(\n"
                "    ccccccccccccccccccccccc);");
   verifyFormat("aaaaa(aaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"





More information about the cfe-commits mailing list