r181828 - Fix expression breaking for one-parameter-per-line styles.

Daniel Jasper djasper at google.com
Tue May 14 13:39:56 PDT 2013


Author: djasper
Date: Tue May 14 15:39:56 2013
New Revision: 181828

URL: http://llvm.org/viewvc/llvm-project?rev=181828&view=rev
Log:
Fix expression breaking for one-parameter-per-line styles.

Before:
  if (aaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaa ||
      aaaaaaaaaaaaaaaaaaaaaaaaaaaa ||
      aaaaaaaaaaaaaaaaaaaaaaaaaaaa ||
      aaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
After:
  if (aaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaa ||
      aaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaa ||
      aaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}

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

Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=181828&r1=181827&r2=181828&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Tue May 14 15:39:56 2013
@@ -543,7 +543,8 @@ private:
       if (State.Stack.back().AvoidBinPacking) {
         // If we are breaking after '(', '{', '<', this is not bin packing
         // unless AllowAllParametersOfDeclarationOnNextLine is false.
-        if ((Previous.isNot(tok::l_paren) && Previous.isNot(tok::l_brace)) ||
+        if (!(Previous.isOneOf(tok::l_paren, tok::l_brace) ||
+              Previous.Type == TT_BinaryOperator) ||
             (!Style.AllowAllParametersOfDeclarationOnNextLine &&
              Line.MustBeDeclaration))
           State.Stack.back().BreakBeforeParameter = true;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=181828&r1=181827&r2=181828&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue May 14 15:39:56 2013
@@ -1646,6 +1646,14 @@ TEST_F(FormatTest, LineBreakingInBinaryE
                "    SourceMgr.getSpellingColumnNumber(\n"
                "        TheLine.Last->FormatTok.Tok.getLocation()) -\n"
                "    1);");
+
+  FormatStyle OnePerLine = getLLVMStyle();
+  OnePerLine.BinPackParameters = false;
+  verifyFormat(
+      "if (aaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaa ||\n"
+      "    aaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaa ||\n"
+      "    aaaaaaaaaaaaaaaaaaaaaaaaaaaa) {\n}",
+      OnePerLine);
 }
 
 TEST_F(FormatTest, ExpressionIndentation) {





More information about the cfe-commits mailing list