r173806 - Allow all parameters on next line for function calls in Chrome.

Daniel Jasper djasper at google.com
Tue Jan 29 08:03:49 PST 2013


Author: djasper
Date: Tue Jan 29 10:03:49 2013
New Revision: 173806

URL: http://llvm.org/viewvc/llvm-project?rev=173806&view=rev
Log:
Allow all parameters on next line for function calls in Chrome.

The style guide only forbids this for function declarations. So,
now

someFunction(
    aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa, aaaaaaaaaaaa);

Is allowed in Chromium mode.

Modified:
    cfe/trunk/include/clang/Format/Format.h
    cfe/trunk/lib/Format/Format.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/include/clang/Format/Format.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=173806&r1=173805&r2=173806&view=diff
==============================================================================
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Tue Jan 29 10:03:49 2013
@@ -61,9 +61,9 @@ struct FormatStyle {
   /// will either all be on the same line or will have one line each.
   bool BinPackParameters;
 
-  /// \brief Allow putting all parameters of a function declaration/call onto
-  /// the next line without calling this bin-packing.
-  bool AllowAllParametersOnNextLine;
+  /// \brief Allow putting all parameters of a function declaration onto
+  /// the next line even if \c BinPackParameters is \c false.
+  bool AllowAllParametersOfDeclarationOnNextLine;
 
   /// \brief Allow putting the return type of a function onto its own line.
   bool AllowReturnTypeOnItsOwnLine;

Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=173806&r1=173805&r2=173806&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Tue Jan 29 10:03:49 2013
@@ -178,7 +178,7 @@ FormatStyle getLLVMStyle() {
   LLVMStyle.IndentCaseLabels = false;
   LLVMStyle.SpacesBeforeTrailingComments = 1;
   LLVMStyle.BinPackParameters = true;
-  LLVMStyle.AllowAllParametersOnNextLine = true;
+  LLVMStyle.AllowAllParametersOfDeclarationOnNextLine = true;
   LLVMStyle.AllowReturnTypeOnItsOwnLine = true;
   LLVMStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = false;
   LLVMStyle.AllowShortIfStatementsOnASingleLine = false;
@@ -196,7 +196,7 @@ FormatStyle getGoogleStyle() {
   GoogleStyle.IndentCaseLabels = true;
   GoogleStyle.SpacesBeforeTrailingComments = 2;
   GoogleStyle.BinPackParameters = false;
-  GoogleStyle.AllowAllParametersOnNextLine = true;
+  GoogleStyle.AllowAllParametersOfDeclarationOnNextLine = true;
   GoogleStyle.AllowReturnTypeOnItsOwnLine = false;
   GoogleStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
   GoogleStyle.AllowShortIfStatementsOnASingleLine = false;
@@ -206,7 +206,7 @@ FormatStyle getGoogleStyle() {
 
 FormatStyle getChromiumStyle() {
   FormatStyle ChromiumStyle = getGoogleStyle();
-  ChromiumStyle.AllowAllParametersOnNextLine = false;
+  ChromiumStyle.AllowAllParametersOfDeclarationOnNextLine = false;
   ChromiumStyle.SplitTemplateClosingGreater = true;
   return ChromiumStyle;
 }
@@ -652,10 +652,11 @@ private:
 
     if (!Style.BinPackParameters && Newline) {
       // If we are breaking after '(', '{', '<', this is not bin packing unless
-      // AllowAllParametersOnNextLine is false.
+      // AllowAllParametersOfDeclarationOnNextLine is false.
       if ((Previous.isNot(tok::l_paren) && Previous.isNot(tok::l_brace) &&
            Previous.Type != TT_TemplateOpener) ||
-          !Style.AllowAllParametersOnNextLine)
+          (!Style.AllowAllParametersOfDeclarationOnNextLine &&
+           Line.MustBeDeclaration))
         State.Stack.back().BreakAfterComma = true;
 
       // Any break on this level means that the parent level has been broken

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=173806&r1=173805&r2=173806&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Jan 29 10:03:49 2013
@@ -1051,10 +1051,15 @@ TEST_F(FormatTest, FormatsOneParameterPe
                      "  a);");
 
   FormatStyle Style = getGoogleStyle();
-  Style.AllowAllParametersOnNextLine = false;
-  verifyFormat("aaaaaaaaaaaaaaa(aaaaaaaaa,\n"
+  Style.AllowAllParametersOfDeclarationOnNextLine = false;
+  verifyFormat("void aaaaaaaaaa(aaaaaaaaa,\n"
                "                aaaaaaaaa,\n"
-               "                aaaaaaaaaaaaaaaaaaaaa).aaaaaaaaaaaaaaaaaa();",
+               "                aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);",
+               Style);
+  verifyFormat("void f() {\n"
+               "  aaaaaaaaaaaaaaaaaaaaaaaa(\n"
+               "      aaaaaaaaa, aaaaaaaaa, aaaaaaaaaaaaaaaaaaaaa).aaaaaaa();\n"
+               "}",
                Style);
 }
 





More information about the cfe-commits mailing list