NewProggie created this revision.
NewProggie added reviewers: poiru, djasper, klimek.
NewProggie added a subscriber: cfe-commits.
Herald added a subscriber: klimek.

This patch adds an option to remove the blank after comma between several 
function parameters. The default value is still to keep the blank.

http://reviews.llvm.org/D16765

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/Format.cpp
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -10954,6 +10954,19 @@
   verifyFormat("A<A<int>>();", Spaces);
 }
 
+TEST_F(FormatTest, SpacesBetweenFunctionParameters) {
+  FormatStyle Spaces = getLLVMStyle();
+  Spaces.SpacesBetweenFunctionParameters = false;
+
+  verifyFormat("void foo(int a);", Spaces);
+  verifyFormat("void foo(int a,double b);", Spaces);
+  verifyFormat("void foo(int a,double b,char c);", Spaces);
+
+  Spaces.SpacesBetweenFunctionParameters = true;
+  verifyFormat("void foo(int a, double b);", Spaces);
+  verifyFormat("void foo(int a, double b, char c);", Spaces);
+}
+
 TEST_F(FormatTest, TripleAngleBrackets) {
   verifyFormat("f<<<1, 1>>>();");
   verifyFormat("f<<<1, 1, 1, s>>>();");
Index: lib/Format/TokenAnnotator.cpp
===================================================================
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2074,7 +2074,7 @@
   if (Right.is(TT_OverloadedOperatorLParen))
     return Style.SpaceBeforeParens == FormatStyle::SBPO_Always;
   if (Left.is(tok::comma))
-    return true;
+    return Style.SpacesBetweenFunctionParameters;
   if (Right.is(tok::comma))
     return false;
   if (Right.isOneOf(TT_CtorInitializerColon, TT_ObjCBlockLParen))
Index: lib/Format/Format.cpp
===================================================================
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -322,6 +322,8 @@
     IO.mapOptional("SpaceInEmptyParentheses", Style.SpaceInEmptyParentheses);
     IO.mapOptional("SpacesBeforeTrailingComments",
                    Style.SpacesBeforeTrailingComments);
+    IO.mapOptional("SpacesBetweenFunctionParameters",
+                   Style.SpacesBetweenFunctionParameters);
     IO.mapOptional("SpacesInAngles", Style.SpacesInAngles);
     IO.mapOptional("SpacesInContainerLiterals",
                    Style.SpacesInContainerLiterals);
@@ -516,6 +518,7 @@
   LLVMStyle.ObjCSpaceBeforeProtocolList = true;
   LLVMStyle.PointerAlignment = FormatStyle::PAS_Right;
   LLVMStyle.SpacesBeforeTrailingComments = 1;
+  LLVMStyle.SpacesBetweenFunctionParameters = true;
   LLVMStyle.Standard = FormatStyle::LS_Cpp11;
   LLVMStyle.UseTab = FormatStyle::UT_Never;
   LLVMStyle.ReflowComments = true;
@@ -561,6 +564,7 @@
   GoogleStyle.ObjCSpaceBeforeProtocolList = false;
   GoogleStyle.PointerAlignment = FormatStyle::PAS_Left;
   GoogleStyle.SpacesBeforeTrailingComments = 2;
+  GoogleStyle.SpacesBetweenFunctionParameters = true;
   GoogleStyle.Standard = FormatStyle::LS_Auto;
 
   GoogleStyle.PenaltyReturnTypeOnItsOwnLine = 200;
Index: include/clang/Format/Format.h
===================================================================
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -539,6 +539,9 @@
   /// commonly have different usage patterns and a number of special cases.
   unsigned SpacesBeforeTrailingComments;
 
+  /// \b If \c true, spaces will be inserted between function parameters.
+  bool SpacesBetweenFunctionParameters;
+
   /// \brief If \c true, spaces will be inserted after '<' and before '>' in
   /// template argument lists
   bool SpacesInAngles;
@@ -657,6 +660,8 @@
            SpaceBeforeParens == R.SpaceBeforeParens &&
            SpaceInEmptyParentheses == R.SpaceInEmptyParentheses &&
            SpacesBeforeTrailingComments == R.SpacesBeforeTrailingComments &&
+           SpacesBetweenFunctionParameters ==
+               R.SpacesBetweenFunctionParameters &&
            SpacesInAngles == R.SpacesInAngles &&
            SpacesInContainerLiterals == R.SpacesInContainerLiterals &&
            SpacesInCStyleCastParentheses == R.SpacesInCStyleCastParentheses &&
Index: docs/ClangFormatStyleOptions.rst
===================================================================
--- docs/ClangFormatStyleOptions.rst
+++ docs/ClangFormatStyleOptions.rst
@@ -611,6 +611,9 @@
   This does not affect trailing block comments (``/**/`` - comments) as those
   commonly have different usage patterns and a number of special cases.
 
+**SpacesBetweenFunctionParameters** (``bool``)
+  If ``true``, a space will be inserted between several function parameters.
+
 **SpacesInAngles** (``bool``)
   If ``true``, spaces will be inserted after '<' and before '>' in
   template argument lists
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to