r216377 - clang-format: Improve formatting of nested builder-type calls.

Daniel Jasper djasper at google.com
Mon Aug 25 01:48:17 PDT 2014


Author: djasper
Date: Mon Aug 25 03:48:17 2014
New Revision: 216377

URL: http://llvm.org/viewvc/llvm-project?rev=216377&view=rev
Log:
clang-format: Improve formatting of nested builder-type calls.

Before:
  f(FirstToken->WhitespaceRange.getBegin().getLocWithOffset(
      First->LastNewlineOffset));

After:
  f(FirstToken->WhitespaceRange.getBegin()
        .getLocWithOffset(First->LastNewlineOffset));

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=216377&r1=216376&r2=216377&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Mon Aug 25 03:48:17 2014
@@ -854,9 +854,10 @@ void ContinuationIndenter::moveStatePast
             getColumnLimit(State))
       BreakBeforeParameter = true;
   }
-  bool NoLineBreak = State.Stack.back().NoLineBreak ||
-                     (Current.Type == TT_TemplateOpener &&
-                      State.Stack.back().ContainsUnwrappedBuilder);
+  bool NoLineBreak =
+      State.Stack.back().NoLineBreak ||
+      ((Current.NestingLevel != 0 || Current.Type == TT_TemplateOpener) &&
+       State.Stack.back().ContainsUnwrappedBuilder);
   State.Stack.push_back(ParenState(NewIndent, NewIndentLevel,
                                    State.Stack.back().LastSpace,
                                    AvoidBinPacking, NoLineBreak));

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=216377&r1=216376&r2=216377&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Aug 25 03:48:17 2014
@@ -3765,9 +3765,12 @@ TEST_F(FormatTest, FormatsBuilderPattern
                "    .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<\n"
                "        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa>();");
 
-  // Prefer not to break after empty parentheses.
+  // Prefer not to break after empty parentheses ...
   verifyFormat("FirstToken->WhitespaceRange.getBegin().getLocWithOffset(\n"
                "    First->LastNewlineOffset);");
+  // ... unless nested.
+  verifyFormat("f(FirstToken->WhitespaceRange.getBegin()\n"
+               "      .getLocWithOffset(First->LastNewlineOffset));");
 }
 
 TEST_F(FormatTest, BreaksAccordingToOperatorPrecedence) {





More information about the cfe-commits mailing list