From f1579605adf03f94a2ddddc95c764737ead0efe5 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Tue, 29 Jan 2013 16:03:49 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173806 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Format/Format.h | 6 +++--- lib/Format/Format.cpp | 11 ++++++----- unittests/Format/FormatTest.cpp | 11 ++++++++--- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/include/clang/Format/Format.h b/include/clang/Format/Format.h index b21bfd2524..d34a04306e 100644 --- a/include/clang/Format/Format.h +++ b/include/clang/Format/Format.h @@ -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; diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 2522d4d5bf..81c8309ef9 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -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 diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index f8402c06a9..219d73c04d 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -1051,10 +1051,15 @@ TEST_F(FormatTest, FormatsOneParameterPerLineIfNecessary) { " 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); } -- 2.40.0