[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-03-18 Thread Eugene Shalygin via cfe-commits

https://github.com/zeule updated 
https://github.com/llvm/llvm-project/pull/131605

>From b0b755a562e80ef712e5c0ddaaaf6c94e2c8ef72 Mon Sep 17 00:00:00 2001
From: Eugene Shalygin 
Date: Mon, 17 Mar 2025 11:23:35 +0100
Subject: [PATCH] [clang-format] option to control bin-packing keyworded
 parameters

The Q_PROPERTY declaration is almost like a function declaration, but
uses keywords as parameter separators. This allows users to provide list
of those keywords to be used to control bin-packing of the macro
parameters.
---
 clang/docs/tools/dump_format_style.py |  1 +
 clang/docs/tools/plurals.txt  |  2 +
 clang/include/clang/Format/Format.h   | 44 ++
 clang/lib/Format/ContinuationIndenter.cpp |  4 ++
 clang/lib/Format/Format.cpp   | 11 
 clang/lib/Format/FormatToken.cpp  |  2 +
 clang/lib/Format/FormatToken.h|  1 +
 clang/lib/Format/TokenAnnotator.cpp   | 54 --
 clang/unittests/Format/ConfigParseTest.cpp| 10 
 clang/unittests/Format/FormatTest.cpp | 57 +++
 clang/unittests/Format/TokenAnnotatorTest.cpp | 33 +++
 11 files changed, 215 insertions(+), 4 deletions(-)

diff --git a/clang/docs/tools/dump_format_style.py 
b/clang/docs/tools/dump_format_style.py
index f035143f6b3d1..ef0763b0d13f1 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -461,6 +461,7 @@ class State:
 "int",
 "std::string",
 "std::vector",
+"std::vector",
 "std::vector",
 "std::vector",
 "std::optional",
diff --git a/clang/docs/tools/plurals.txt b/clang/docs/tools/plurals.txt
index e20b7f970ba43..4177f9f749ea2 100644
--- a/clang/docs/tools/plurals.txt
+++ b/clang/docs/tools/plurals.txt
@@ -1,3 +1,5 @@
 Strings
+FunctionDeclarationsWithKeywords
 IncludeCategories
 RawStringFormats
+FunctionDeclarationWithKeywordes
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index fec47a248abb4..c2466da722467 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2753,6 +2753,48 @@ struct FormatStyle {
   /// \version 3.7
   std::vector ForEachMacros;
 
+  /// Function-like declaration with keyworded parameters.
+  /// Lists possible keywords for a named macro-like function
+  struct FunctionDeclarationWithKeywords {
+std::string Name;
+std::vector Keywords;
+
+bool operator==(const FunctionDeclarationWithKeywords &Other) const {
+  return Name == Other.Name && Keywords == Other.Keywords;
+}
+  };
+
+  /// Allows to format function-like macros with keyworded parameters according
+  /// to the BinPackParameters setting, treating keywords as parameter
+  /// sepratators.
+  ///
+  /// Q_PROPERTY is an example of such a macro:
+  ///
+  /// \code
+  ///   Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+  /// \endcode
+  ///
+  /// With ``BinPackParameters``  set to ``OnePerLine`` (or
+  /// ``AlwaysOnePerLine``) and
+  ///
+  /// \code{.yaml}
+  ///   FunctionDeclarationsWithKeywords:
+  ///   - Name: "Q_PROPERTY"
+  /// Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+  /// \endcode
+  ///
+  /// the line above will be split on these keywords:
+  ///
+  /// \code
+  ///   Q_PROPERTY(
+  ///   int name
+  ///   READ name
+  ///   WRITE setName
+  ///   NOTIFY nameChanged)
+  /// \endcode
+  /// \version 21
+  std::vector 
FunctionDeclarationsWithKeywords;
+
   tooling::IncludeStyle IncludeStyle;
 
   /// A vector of macros that should be interpreted as conditionals
@@ -5327,6 +5369,8 @@ struct FormatStyle {
R.ExperimentalAutoDetectBinPacking &&
FixNamespaceComments == R.FixNamespaceComments &&
ForEachMacros == R.ForEachMacros &&
+   FunctionDeclarationsWithKeywords ==
+   R.FunctionDeclarationsWithKeywords &&
IncludeStyle.IncludeBlocks == R.IncludeStyle.IncludeBlocks &&
IncludeStyle.IncludeCategories == R.IncludeStyle.IncludeCategories 
&&
IncludeStyle.IncludeIsMainRegex ==
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 1969f4297b211..dd4297de73ac0 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -349,6 +349,10 @@ bool ContinuationIndenter::canBreak(const LineState 
&State) {
 }
   }
 
+  // Don't break between function parameter keywords and parameter names.
+  if (Previous.is(TT_FunctionParameterKeyword) && Current.is(TT_StartOfName))
+return false;
+
   // Don't allow breaking before a closing brace of a block-indented braced 
list
   // initializer if there isn't already a break.
   if (Current.is(tok::r_brace) && Current.MatchingParen &&
diff --git a/clang/lib/Format/Format.cpp b/

[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-03-18 Thread Eugene Shalygin via cfe-commits

https://github.com/zeule updated 
https://github.com/llvm/llvm-project/pull/131605

>From f5caba3d2b793ad0591a7bba2d26fdbd5de11f1b Mon Sep 17 00:00:00 2001
From: Eugene Shalygin 
Date: Mon, 17 Mar 2025 11:23:35 +0100
Subject: [PATCH] [clang-format] option to control bin-packing keyworded
 parameters

The Q_PROPERTY declaration is almost like a function declaration, but
uses keywords as parameter separators. This allows users to provide list
of those keywords to be used to control bin-packing of the macro
parameters.
---
 clang/docs/tools/dump_format_style.py |  1 +
 clang/docs/tools/plurals.txt  |  1 +
 clang/include/clang/Format/Format.h   | 44 ++
 clang/lib/Format/ContinuationIndenter.cpp |  4 ++
 clang/lib/Format/Format.cpp   | 11 
 clang/lib/Format/FormatToken.cpp  |  2 +
 clang/lib/Format/FormatToken.h|  1 +
 clang/lib/Format/TokenAnnotator.cpp   | 54 --
 clang/unittests/Format/ConfigParseTest.cpp| 10 
 clang/unittests/Format/FormatTest.cpp | 57 +++
 clang/unittests/Format/TokenAnnotatorTest.cpp | 33 +++
 11 files changed, 214 insertions(+), 4 deletions(-)

diff --git a/clang/docs/tools/dump_format_style.py 
b/clang/docs/tools/dump_format_style.py
index f035143f6b3d1..ef0763b0d13f1 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -461,6 +461,7 @@ class State:
 "int",
 "std::string",
 "std::vector",
+"std::vector",
 "std::vector",
 "std::vector",
 "std::optional",
diff --git a/clang/docs/tools/plurals.txt b/clang/docs/tools/plurals.txt
index e20b7f970ba43..445b5b2dc0f92 100644
--- a/clang/docs/tools/plurals.txt
+++ b/clang/docs/tools/plurals.txt
@@ -1,3 +1,4 @@
 Strings
+FunctionDeclarationWithKeywordes
 IncludeCategories
 RawStringFormats
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index fec47a248abb4..c2466da722467 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2753,6 +2753,48 @@ struct FormatStyle {
   /// \version 3.7
   std::vector ForEachMacros;
 
+  /// Function-like declaration with keyworded parameters.
+  /// Lists possible keywords for a named macro-like function
+  struct FunctionDeclarationWithKeywords {
+std::string Name;
+std::vector Keywords;
+
+bool operator==(const FunctionDeclarationWithKeywords &Other) const {
+  return Name == Other.Name && Keywords == Other.Keywords;
+}
+  };
+
+  /// Allows to format function-like macros with keyworded parameters according
+  /// to the BinPackParameters setting, treating keywords as parameter
+  /// sepratators.
+  ///
+  /// Q_PROPERTY is an example of such a macro:
+  ///
+  /// \code
+  ///   Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+  /// \endcode
+  ///
+  /// With ``BinPackParameters``  set to ``OnePerLine`` (or
+  /// ``AlwaysOnePerLine``) and
+  ///
+  /// \code{.yaml}
+  ///   FunctionDeclarationsWithKeywords:
+  ///   - Name: "Q_PROPERTY"
+  /// Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+  /// \endcode
+  ///
+  /// the line above will be split on these keywords:
+  ///
+  /// \code
+  ///   Q_PROPERTY(
+  ///   int name
+  ///   READ name
+  ///   WRITE setName
+  ///   NOTIFY nameChanged)
+  /// \endcode
+  /// \version 21
+  std::vector 
FunctionDeclarationsWithKeywords;
+
   tooling::IncludeStyle IncludeStyle;
 
   /// A vector of macros that should be interpreted as conditionals
@@ -5327,6 +5369,8 @@ struct FormatStyle {
R.ExperimentalAutoDetectBinPacking &&
FixNamespaceComments == R.FixNamespaceComments &&
ForEachMacros == R.ForEachMacros &&
+   FunctionDeclarationsWithKeywords ==
+   R.FunctionDeclarationsWithKeywords &&
IncludeStyle.IncludeBlocks == R.IncludeStyle.IncludeBlocks &&
IncludeStyle.IncludeCategories == R.IncludeStyle.IncludeCategories 
&&
IncludeStyle.IncludeIsMainRegex ==
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 1969f4297b211..dd4297de73ac0 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -349,6 +349,10 @@ bool ContinuationIndenter::canBreak(const LineState 
&State) {
 }
   }
 
+  // Don't break between function parameter keywords and parameter names.
+  if (Previous.is(TT_FunctionParameterKeyword) && Current.is(TT_StartOfName))
+return false;
+
   // Don't allow breaking before a closing brace of a block-indented braced 
list
   // initializer if there isn't already a break.
   if (Current.is(tok::r_brace) && Current.MatchingParen &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 

[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-03-18 Thread Eugene Shalygin via cfe-commits

https://github.com/zeule updated 
https://github.com/llvm/llvm-project/pull/131605

>From 9a5e2d67775ce1387263c4ad7c18b7dcbdc64b21 Mon Sep 17 00:00:00 2001
From: Eugene Shalygin 
Date: Mon, 17 Mar 2025 11:23:35 +0100
Subject: [PATCH] [clang-format] option to control bin-packing keyworded
 parameters

The Q_PROPERTY declaration is almost like a function declaration, but
uses keywords as parameter separators. This allows users to provide list
of those keywords to be used to control bin-packing of the macro
parameters.
---
 clang/docs/ClangFormatStyleOptions.rst| 32 +++
 clang/docs/tools/dump_format_style.py |  1 +
 clang/docs/tools/plurals.txt  |  1 +
 clang/include/clang/Format/Format.h   | 41 +
 clang/lib/Format/ContinuationIndenter.cpp |  4 ++
 clang/lib/Format/Format.cpp   | 11 
 clang/lib/Format/FormatToken.cpp  |  2 +
 clang/lib/Format/FormatToken.h|  1 +
 clang/lib/Format/TokenAnnotator.cpp   | 54 --
 clang/unittests/Format/ConfigParseTest.cpp| 10 
 clang/unittests/Format/FormatTest.cpp | 57 +++
 clang/unittests/Format/TokenAnnotatorTest.cpp | 33 +++
 12 files changed, 243 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 9ecac68ae72bf..8932c40402a5c 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4032,6 +4032,38 @@ the configuration (without a prefix: ``Auto``).
 
   For example: BOOST_FOREACH.
 
+.. _FunctionDeclarationsWithKeywords:
+
+**FunctionDeclarationsWithKeywords** (``List of 
FunctionDeclarationWithKeywordes``) :versionbadge:`clang-format 21` :ref:`¶ 
`
+  Allows to format function-like macros with keyworded parameters according
+  to the BinPackParameters setting, treating keywords as parameter
+  sepratators.
+
+  Q_PROPERTY is an example of such a macro:
+
+  .. code-block:: c++
+
+Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+
+  With ``BinPackParameters``  set to ``OnePerLine`` (or
+  ``AlwaysOnePerLine``) and
+
+  .. code-block:: yaml
+
+FunctionDeclarationsWithKeywords:
+- Name: "Q_PROPERTY"
+  Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+
+  the line above will be split on these keywords:
+
+  .. code-block:: c++
+
+Q_PROPERTY(
+int name
+READ name
+WRITE setName
+NOTIFY nameChanged)
+
 .. _IfMacros:
 
 **IfMacros** (``List of Strings``) :versionbadge:`clang-format 13` :ref:`¶ 
`
diff --git a/clang/docs/tools/dump_format_style.py 
b/clang/docs/tools/dump_format_style.py
index f035143f6b3d1..ef0763b0d13f1 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -461,6 +461,7 @@ class State:
 "int",
 "std::string",
 "std::vector",
+"std::vector",
 "std::vector",
 "std::vector",
 "std::optional",
diff --git a/clang/docs/tools/plurals.txt b/clang/docs/tools/plurals.txt
index e20b7f970ba43..445b5b2dc0f92 100644
--- a/clang/docs/tools/plurals.txt
+++ b/clang/docs/tools/plurals.txt
@@ -1,3 +1,4 @@
 Strings
+FunctionDeclarationWithKeywordes
 IncludeCategories
 RawStringFormats
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index fec47a248abb4..323dd189d0dc4 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2753,6 +2753,45 @@ struct FormatStyle {
   /// \version 3.7
   std::vector ForEachMacros;
 
+  /// Function-like declaration with keyworded parameters.
+  /// Lists possible keywords for a named macro-like function
+  struct FunctionDeclarationWithKeywords {
+std::string Name;
+std::vector Keywords;
+
+bool operator==(const FunctionDeclarationWithKeywords &Other) const {
+  return Name == Other.Name && Keywords == Other.Keywords;
+}
+  };
+
+  /// Allows to format function-like macros with keyworded parameters according
+  /// to the BinPackParameters setting, treating keywords as parameter
+  /// sepratators.
+  ///
+  /// Q_PROPERTY is an example of such a macro:
+  /// \code
+  ///   Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+  /// \endcode
+  ///
+  /// With ``BinPackParameters``  set to ``OnePerLine`` (or
+  /// ``AlwaysOnePerLine``) and
+  /// \code{.yaml}
+  ///   FunctionDeclarationsWithKeywords:
+  ///   - Name: "Q_PROPERTY"
+  /// Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+  /// \endcode
+  ///
+  /// the line above will be split on these keywords:
+  /// \code
+  ///   Q_PROPERTY(
+  ///   int name
+  ///   READ name
+  ///   WRITE setName
+  ///   NOTIFY nameChanged)
+  /// \endcode
+  /// \version 21
+  std::vector 
FunctionDeclarationsWithKeywords;
+
   tooling::IncludeStyle In

[clang] [clang-format] add option to bin-pack keyworded parameters (PR #131605)

2025-03-17 Thread Eugene Shalygin via cfe-commits


@@ -148,6 +160,24 @@ class AnnotatingParser {
 }
   }
 
+  const FormatStyle::FunctionDeclarationWithKeywords *
+  isInsideFunctionWithKeywordedParameters(const FormatToken &Token) const {
+const FormatToken *Previous = &Token;
+while (auto Prev = Previous->getPreviousNonComment())
+  Previous = Prev;

zeule wrote:

I hardly understand what am I doing here, sorry. In particular, I don't 
understand which pass (is that settings-dependent?) splits consecutive macros 
in the same line into multiple lines? May I rely on that behaviour?

https://github.com/llvm/llvm-project/pull/131605
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add option to bin-pack keyworded parameters (PR #131605)

2025-03-18 Thread Eugene Shalygin via cfe-commits

https://github.com/zeule updated 
https://github.com/llvm/llvm-project/pull/131605

>From 3cffb6a3c8a4bda050b56900d0333aed1cbe0216 Mon Sep 17 00:00:00 2001
From: Eugene Shalygin 
Date: Mon, 17 Mar 2025 11:23:35 +0100
Subject: [PATCH 1/2] [clang-format] add option to bin-pack keyworded
 parameters

The Q_PROPERTY declaration is almost like a function declaration, but
uses keywords as parameter separators. This allows users to provide list
of those keywords to be used to control bin-packing of the macro
parameters.
---
 clang/include/clang/Format/Format.h   | 40 -
 clang/lib/Format/ContinuationIndenter.cpp |  4 ++
 clang/lib/Format/Format.cpp   | 11 +
 clang/lib/Format/FormatToken.cpp  |  2 +
 clang/lib/Format/FormatToken.h|  1 +
 clang/lib/Format/TokenAnnotator.cpp   | 54 +--
 clang/unittests/Format/FormatTest.cpp | 52 ++
 7 files changed, 159 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index fec47a248abb4..22c385d231a1e 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -5247,6 +5247,41 @@ struct FormatStyle {
   /// \version 20
   WrapNamespaceBodyWithEmptyLinesStyle WrapNamespaceBodyWithEmptyLines;
 
+  struct FunctionDeclarationWithKeywords {
+std::string Name;
+std::vector Keywords;
+
+bool operator==(const FunctionDeclarationWithKeywords &Other) const {
+  return Name == Other.Name && Keywords == Other.Keywords;
+}
+  };
+
+  /// Allows to format function-line macros with keyworded parameters according
+  /// to the BinPackParameters setting, treating keywords as parameter
+  /// sepratators.
+  /// \version 21
+  ///
+  /// Q_PROPERTY is an example of such a macro:
+  /// \code
+  /// Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+  /// \endcode
+  ///
+  /// With BinPackParameters set to OnePerLine (or AlwaysOnePerLine) and
+  /// \code
+  /// FunctionDeclarationsWithKeywords:
+  /// - Name: "Q_PROPERTY"
+  ///   Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+  /// \endcode
+  /// the line above will be split on these keywords:
+  /// \code
+  /// Q_PROPERTY(
+  /// int name
+  /// READ name
+  /// WRITE setName
+  /// NOTIFY nameChanged)
+  /// \endcode
+  std::vector 
FunctionDeclarationsWithKeywords;
+
   bool operator==(const FormatStyle &R) const {
 return AccessModifierOffset == R.AccessModifierOffset &&
AlignAfterOpenBracket == R.AlignAfterOpenBracket &&
@@ -5435,7 +5470,10 @@ struct FormatStyle {
VerilogBreakBetweenInstancePorts ==
R.VerilogBreakBetweenInstancePorts &&
WhitespaceSensitiveMacros == R.WhitespaceSensitiveMacros &&
-   WrapNamespaceBodyWithEmptyLines == 
R.WrapNamespaceBodyWithEmptyLines;
+   WrapNamespaceBodyWithEmptyLines ==
+   R.WrapNamespaceBodyWithEmptyLines &&
+   FunctionDeclarationsWithKeywords ==
+   R.FunctionDeclarationsWithKeywords;
   }
 
   std::optional GetLanguageStyle(LanguageKind Language) const;
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 1969f4297b211..37fd70a0fd721 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -349,6 +349,10 @@ bool ContinuationIndenter::canBreak(const LineState 
&State) {
 }
   }
 
+  // Don't break between function parameter keywords and parameter names
+  if (Previous.is(TT_FunctionParameterKeyword) && Current.is(TT_StartOfName))
+return false;
+
   // Don't allow breaking before a closing brace of a block-indented braced 
list
   // initializer if there isn't already a break.
   if (Current.is(tok::r_brace) && Current.MatchingParen &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index c67db4752e87b..14690a28970fa 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -29,6 +29,7 @@
 using clang::format::FormatStyle;
 
 LLVM_YAML_IS_SEQUENCE_VECTOR(FormatStyle::RawStringFormat)
+LLVM_YAML_IS_SEQUENCE_VECTOR(FormatStyle::FunctionDeclarationWithKeywords)
 
 namespace llvm {
 namespace yaml {
@@ -852,6 +853,14 @@ struct ScalarEnumerationTraits<
   }
 };
 
+template <> struct MappingTraits 
{
+  static void mapping(IO &IO,
+  FormatStyle::FunctionDeclarationWithKeywords &Function) {
+IO.mapOptional("Name", Function.Name);
+IO.mapOptional("Keywords", Function.Keywords);
+  }
+};
+
 template <> struct MappingTraits {
   static void mapping(IO &IO, FormatStyle &Style) {
 // When reading, read the language first, we need it for 
getPredefinedStyle.
@@ -1192,6 +1201,8 @@ template <> struct MappingTraits {
Style.WhitespaceSensitiveMacros);
 IO.mapOptional("WrapNamespaceBodyWithEmptyLines",
Style.WrapNamespaceBody

[clang] [clang-format] add option to bin-pack keyworded parameters (PR #131605)

2025-03-17 Thread Eugene Shalygin via cfe-commits

https://github.com/zeule created 
https://github.com/llvm/llvm-project/pull/131605

The Q_PROPERTY declaration is almost like a function declaration, but uses 
keywords as parameter separators. This allows users to provide list of those 
keywords to be used to control bin-packing of the macro parameters.

>From 3cffb6a3c8a4bda050b56900d0333aed1cbe0216 Mon Sep 17 00:00:00 2001
From: Eugene Shalygin 
Date: Mon, 17 Mar 2025 11:23:35 +0100
Subject: [PATCH] [clang-format] add option to bin-pack keyworded parameters

The Q_PROPERTY declaration is almost like a function declaration, but
uses keywords as parameter separators. This allows users to provide list
of those keywords to be used to control bin-packing of the macro
parameters.
---
 clang/include/clang/Format/Format.h   | 40 -
 clang/lib/Format/ContinuationIndenter.cpp |  4 ++
 clang/lib/Format/Format.cpp   | 11 +
 clang/lib/Format/FormatToken.cpp  |  2 +
 clang/lib/Format/FormatToken.h|  1 +
 clang/lib/Format/TokenAnnotator.cpp   | 54 +--
 clang/unittests/Format/FormatTest.cpp | 52 ++
 7 files changed, 159 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index fec47a248abb4..22c385d231a1e 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -5247,6 +5247,41 @@ struct FormatStyle {
   /// \version 20
   WrapNamespaceBodyWithEmptyLinesStyle WrapNamespaceBodyWithEmptyLines;
 
+  struct FunctionDeclarationWithKeywords {
+std::string Name;
+std::vector Keywords;
+
+bool operator==(const FunctionDeclarationWithKeywords &Other) const {
+  return Name == Other.Name && Keywords == Other.Keywords;
+}
+  };
+
+  /// Allows to format function-line macros with keyworded parameters according
+  /// to the BinPackParameters setting, treating keywords as parameter
+  /// sepratators.
+  /// \version 21
+  ///
+  /// Q_PROPERTY is an example of such a macro:
+  /// \code
+  /// Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+  /// \endcode
+  ///
+  /// With BinPackParameters set to OnePerLine (or AlwaysOnePerLine) and
+  /// \code
+  /// FunctionDeclarationsWithKeywords:
+  /// - Name: "Q_PROPERTY"
+  ///   Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+  /// \endcode
+  /// the line above will be split on these keywords:
+  /// \code
+  /// Q_PROPERTY(
+  /// int name
+  /// READ name
+  /// WRITE setName
+  /// NOTIFY nameChanged)
+  /// \endcode
+  std::vector 
FunctionDeclarationsWithKeywords;
+
   bool operator==(const FormatStyle &R) const {
 return AccessModifierOffset == R.AccessModifierOffset &&
AlignAfterOpenBracket == R.AlignAfterOpenBracket &&
@@ -5435,7 +5470,10 @@ struct FormatStyle {
VerilogBreakBetweenInstancePorts ==
R.VerilogBreakBetweenInstancePorts &&
WhitespaceSensitiveMacros == R.WhitespaceSensitiveMacros &&
-   WrapNamespaceBodyWithEmptyLines == 
R.WrapNamespaceBodyWithEmptyLines;
+   WrapNamespaceBodyWithEmptyLines ==
+   R.WrapNamespaceBodyWithEmptyLines &&
+   FunctionDeclarationsWithKeywords ==
+   R.FunctionDeclarationsWithKeywords;
   }
 
   std::optional GetLanguageStyle(LanguageKind Language) const;
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 1969f4297b211..37fd70a0fd721 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -349,6 +349,10 @@ bool ContinuationIndenter::canBreak(const LineState 
&State) {
 }
   }
 
+  // Don't break between function parameter keywords and parameter names
+  if (Previous.is(TT_FunctionParameterKeyword) && Current.is(TT_StartOfName))
+return false;
+
   // Don't allow breaking before a closing brace of a block-indented braced 
list
   // initializer if there isn't already a break.
   if (Current.is(tok::r_brace) && Current.MatchingParen &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index c67db4752e87b..14690a28970fa 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -29,6 +29,7 @@
 using clang::format::FormatStyle;
 
 LLVM_YAML_IS_SEQUENCE_VECTOR(FormatStyle::RawStringFormat)
+LLVM_YAML_IS_SEQUENCE_VECTOR(FormatStyle::FunctionDeclarationWithKeywords)
 
 namespace llvm {
 namespace yaml {
@@ -852,6 +853,14 @@ struct ScalarEnumerationTraits<
   }
 };
 
+template <> struct MappingTraits 
{
+  static void mapping(IO &IO,
+  FormatStyle::FunctionDeclarationWithKeywords &Function) {
+IO.mapOptional("Name", Function.Name);
+IO.mapOptional("Keywords", Function.Keywords);
+  }
+};
+
 template <> struct MappingTraits {
   static void mapping(IO &IO, FormatStyle &Style) {
 // When reading, read the language first, we need it for 
getPredefin

[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-03-20 Thread Eugene Shalygin via cfe-commits


@@ -148,6 +160,24 @@ class AnnotatingParser {
 }
   }
 
+  const FormatStyle::FunctionDeclarationWithKeywords *
+  isInsideFunctionWithKeywordedParameters(const FormatToken &Token) const {
+const FormatToken *Previous = &Token;
+while (auto Prev = Previous->getPreviousNonComment())
+  Previous = Prev;

zeule wrote:

Thanks! Then can I look for the first `tok::l_paren` in the `Line` and take 
previous non-comment from that?

https://github.com/llvm/llvm-project/pull/131605
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-03-19 Thread Eugene Shalygin via cfe-commits

https://github.com/zeule updated 
https://github.com/llvm/llvm-project/pull/131605

>From 3f9cd2caa38d1b004b723049c22f4a19283d4d05 Mon Sep 17 00:00:00 2001
From: Eugene Shalygin 
Date: Mon, 17 Mar 2025 11:23:35 +0100
Subject: [PATCH] [clang-format] option to control bin-packing keyworded
 parameters

The Q_PROPERTY declaration is almost like a function declaration, but
uses keywords as parameter separators. This allows users to provide list
of those keywords to be used to control bin-packing of the macro
parameters.
---
 clang/docs/ClangFormatStyleOptions.rst| 32 ++
 clang/docs/tools/dump_format_style.py |  1 +
 clang/docs/tools/plurals.txt  |  1 +
 clang/include/clang/Format/Format.h   | 41 +
 clang/lib/Format/ContinuationIndenter.cpp |  4 ++
 clang/lib/Format/Format.cpp   | 11 
 clang/lib/Format/FormatToken.cpp  |  2 +
 clang/lib/Format/FormatToken.h|  1 +
 clang/lib/Format/TokenAnnotator.cpp   | 51 ++--
 clang/unittests/Format/ConfigParseTest.cpp| 10 +++
 clang/unittests/Format/FormatTest.cpp | 61 +++
 clang/unittests/Format/TokenAnnotatorTest.cpp | 33 ++
 12 files changed, 244 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 9ecac68ae72bf..8932c40402a5c 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4032,6 +4032,38 @@ the configuration (without a prefix: ``Auto``).
 
   For example: BOOST_FOREACH.
 
+.. _FunctionDeclarationsWithKeywords:
+
+**FunctionDeclarationsWithKeywords** (``List of 
FunctionDeclarationWithKeywordes``) :versionbadge:`clang-format 21` :ref:`¶ 
`
+  Allows to format function-like macros with keyworded parameters according
+  to the BinPackParameters setting, treating keywords as parameter
+  sepratators.
+
+  Q_PROPERTY is an example of such a macro:
+
+  .. code-block:: c++
+
+Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+
+  With ``BinPackParameters``  set to ``OnePerLine`` (or
+  ``AlwaysOnePerLine``) and
+
+  .. code-block:: yaml
+
+FunctionDeclarationsWithKeywords:
+- Name: "Q_PROPERTY"
+  Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+
+  the line above will be split on these keywords:
+
+  .. code-block:: c++
+
+Q_PROPERTY(
+int name
+READ name
+WRITE setName
+NOTIFY nameChanged)
+
 .. _IfMacros:
 
 **IfMacros** (``List of Strings``) :versionbadge:`clang-format 13` :ref:`¶ 
`
diff --git a/clang/docs/tools/dump_format_style.py 
b/clang/docs/tools/dump_format_style.py
index f035143f6b3d1..ef0763b0d13f1 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -461,6 +461,7 @@ class State:
 "int",
 "std::string",
 "std::vector",
+"std::vector",
 "std::vector",
 "std::vector",
 "std::optional",
diff --git a/clang/docs/tools/plurals.txt b/clang/docs/tools/plurals.txt
index e20b7f970ba43..445b5b2dc0f92 100644
--- a/clang/docs/tools/plurals.txt
+++ b/clang/docs/tools/plurals.txt
@@ -1,3 +1,4 @@
 Strings
+FunctionDeclarationWithKeywordes
 IncludeCategories
 RawStringFormats
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index fec47a248abb4..323dd189d0dc4 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2753,6 +2753,45 @@ struct FormatStyle {
   /// \version 3.7
   std::vector ForEachMacros;
 
+  /// Function-like declaration with keyworded parameters.
+  /// Lists possible keywords for a named macro-like function
+  struct FunctionDeclarationWithKeywords {
+std::string Name;
+std::vector Keywords;
+
+bool operator==(const FunctionDeclarationWithKeywords &Other) const {
+  return Name == Other.Name && Keywords == Other.Keywords;
+}
+  };
+
+  /// Allows to format function-like macros with keyworded parameters according
+  /// to the BinPackParameters setting, treating keywords as parameter
+  /// sepratators.
+  ///
+  /// Q_PROPERTY is an example of such a macro:
+  /// \code
+  ///   Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+  /// \endcode
+  ///
+  /// With ``BinPackParameters``  set to ``OnePerLine`` (or
+  /// ``AlwaysOnePerLine``) and
+  /// \code{.yaml}
+  ///   FunctionDeclarationsWithKeywords:
+  ///   - Name: "Q_PROPERTY"
+  /// Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+  /// \endcode
+  ///
+  /// the line above will be split on these keywords:
+  /// \code
+  ///   Q_PROPERTY(
+  ///   int name
+  ///   READ name
+  ///   WRITE setName
+  ///   NOTIFY nameChanged)
+  /// \endcode
+  /// \version 21
+  std::vector 
FunctionDeclarationsWithKeywords;
+
   tooling::IncludeStyle Include

[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-03-19 Thread Eugene Shalygin via cfe-commits


@@ -148,6 +160,24 @@ class AnnotatingParser {
 }
   }
 
+  const FormatStyle::FunctionDeclarationWithKeywords *
+  isInsideFunctionWithKeywordedParameters(const FormatToken &Token) const {
+const FormatToken *Previous = &Token;
+while (auto Prev = Previous->getPreviousNonComment())
+  Previous = Prev;

zeule wrote:

Ah, so `AnnotatedLine` contains a single statement only?

https://github.com/llvm/llvm-project/pull/131605
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-03-18 Thread Eugene Shalygin via cfe-commits

https://github.com/zeule updated 
https://github.com/llvm/llvm-project/pull/131605

>From 4f0c149795c35789bfb88e5e77c9aaa799c7b592 Mon Sep 17 00:00:00 2001
From: Eugene Shalygin 
Date: Mon, 17 Mar 2025 11:23:35 +0100
Subject: [PATCH] [clang-format] option to control bin-packing keyworded
 parameters

The Q_PROPERTY declaration is almost like a function declaration, but
uses keywords as parameter separators. This allows users to provide list
of those keywords to be used to control bin-packing of the macro
parameters.
---
 clang/include/clang/Format/Format.h   | 37 
 clang/lib/Format/ContinuationIndenter.cpp |  4 ++
 clang/lib/Format/Format.cpp   | 11 
 clang/lib/Format/FormatToken.cpp  |  2 +
 clang/lib/Format/FormatToken.h|  1 +
 clang/lib/Format/TokenAnnotator.cpp   | 54 --
 clang/unittests/Format/ConfigParseTest.cpp| 10 
 clang/unittests/Format/FormatTest.cpp | 57 +++
 clang/unittests/Format/TokenAnnotatorTest.cpp | 33 +++
 9 files changed, 205 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index fec47a248abb4..b5f226e4389b6 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2753,6 +2753,41 @@ struct FormatStyle {
   /// \version 3.7
   std::vector ForEachMacros;
 
+  struct FunctionDeclarationWithKeywords {
+std::string Name;
+std::vector Keywords;
+
+bool operator==(const FunctionDeclarationWithKeywords &Other) const {
+  return Name == Other.Name && Keywords == Other.Keywords;
+}
+  };
+
+  /// Allows to format function-line macros with keyworded parameters according
+  /// to the BinPackParameters setting, treating keywords as parameter
+  /// sepratators.
+  /// \version 21
+  ///
+  /// Q_PROPERTY is an example of such a macro:
+  /// \code
+  /// Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+  /// \endcode
+  ///
+  /// With BinPackParameters set to OnePerLine (or AlwaysOnePerLine) and
+  /// \code{.yaml}
+  /// FunctionDeclarationsWithKeywords:
+  /// - Name: "Q_PROPERTY"
+  ///   Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+  /// \endcode
+  /// the line above will be split on these keywords:
+  /// \code
+  /// Q_PROPERTY(
+  /// int name
+  /// READ name
+  /// WRITE setName
+  /// NOTIFY nameChanged)
+  /// \endcode
+  std::vector 
FunctionDeclarationsWithKeywords;
+
   tooling::IncludeStyle IncludeStyle;
 
   /// A vector of macros that should be interpreted as conditionals
@@ -5327,6 +5362,8 @@ struct FormatStyle {
R.ExperimentalAutoDetectBinPacking &&
FixNamespaceComments == R.FixNamespaceComments &&
ForEachMacros == R.ForEachMacros &&
+   FunctionDeclarationsWithKeywords ==
+   R.FunctionDeclarationsWithKeywords &&
IncludeStyle.IncludeBlocks == R.IncludeStyle.IncludeBlocks &&
IncludeStyle.IncludeCategories == R.IncludeStyle.IncludeCategories 
&&
IncludeStyle.IncludeIsMainRegex ==
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 1969f4297b211..dd4297de73ac0 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -349,6 +349,10 @@ bool ContinuationIndenter::canBreak(const LineState 
&State) {
 }
   }
 
+  // Don't break between function parameter keywords and parameter names.
+  if (Previous.is(TT_FunctionParameterKeyword) && Current.is(TT_StartOfName))
+return false;
+
   // Don't allow breaking before a closing brace of a block-indented braced 
list
   // initializer if there isn't already a break.
   if (Current.is(tok::r_brace) && Current.MatchingParen &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index c67db4752e87b..1a7b2871531b9 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -29,6 +29,7 @@
 using clang::format::FormatStyle;
 
 LLVM_YAML_IS_SEQUENCE_VECTOR(FormatStyle::RawStringFormat)
+LLVM_YAML_IS_SEQUENCE_VECTOR(FormatStyle::FunctionDeclarationWithKeywords)
 
 namespace llvm {
 namespace yaml {
@@ -852,6 +853,14 @@ struct ScalarEnumerationTraits<
   }
 };
 
+template <> struct MappingTraits 
{
+  static void mapping(IO &IO,
+  FormatStyle::FunctionDeclarationWithKeywords &Function) {
+IO.mapOptional("Name", Function.Name);
+IO.mapOptional("Keywords", Function.Keywords);
+  }
+};
+
 template <> struct MappingTraits {
   static void mapping(IO &IO, FormatStyle &Style) {
 // When reading, read the language first, we need it for 
getPredefinedStyle.
@@ -1046,6 +1055,8 @@ template <> struct MappingTraits {
Style.ExperimentalAutoDetectBinPacking);
 IO.mapOptional("FixNamespaceComments", Style.FixNamespaceComments);
 IO.mapOptional("ForEachMacros", S

[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-03-20 Thread Eugene Shalygin via cfe-commits

https://github.com/zeule updated 
https://github.com/llvm/llvm-project/pull/131605

>From 833157960f14ff354f4c1b2121029353ee55de84 Mon Sep 17 00:00:00 2001
From: Eugene Shalygin 
Date: Mon, 17 Mar 2025 11:23:35 +0100
Subject: [PATCH] [clang-format] option to control bin-packing keyworded
 parameters

The Q_PROPERTY declaration is almost like a function declaration, but
uses keywords as parameter separators. This allows users to provide list
of those keywords to be used to control bin-packing of the macro
parameters.
---
 clang/docs/ClangFormatStyleOptions.rst| 32 ++
 clang/docs/tools/dump_format_style.py |  1 +
 clang/docs/tools/plurals.txt  |  1 +
 clang/include/clang/Format/Format.h   | 41 +
 clang/lib/Format/ContinuationIndenter.cpp |  4 ++
 clang/lib/Format/Format.cpp   | 11 
 clang/lib/Format/FormatToken.cpp  |  2 +
 clang/lib/Format/FormatToken.h|  1 +
 clang/lib/Format/TokenAnnotator.cpp   | 59 +--
 clang/unittests/Format/ConfigParseTest.cpp| 10 
 clang/unittests/Format/FormatTest.cpp | 59 +++
 clang/unittests/Format/TokenAnnotatorTest.cpp | 33 +++
 12 files changed, 250 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 9ecac68ae72bf..8932c40402a5c 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4032,6 +4032,38 @@ the configuration (without a prefix: ``Auto``).
 
   For example: BOOST_FOREACH.
 
+.. _FunctionDeclarationsWithKeywords:
+
+**FunctionDeclarationsWithKeywords** (``List of 
FunctionDeclarationWithKeywordes``) :versionbadge:`clang-format 21` :ref:`¶ 
`
+  Allows to format function-like macros with keyworded parameters according
+  to the BinPackParameters setting, treating keywords as parameter
+  sepratators.
+
+  Q_PROPERTY is an example of such a macro:
+
+  .. code-block:: c++
+
+Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+
+  With ``BinPackParameters``  set to ``OnePerLine`` (or
+  ``AlwaysOnePerLine``) and
+
+  .. code-block:: yaml
+
+FunctionDeclarationsWithKeywords:
+- Name: "Q_PROPERTY"
+  Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+
+  the line above will be split on these keywords:
+
+  .. code-block:: c++
+
+Q_PROPERTY(
+int name
+READ name
+WRITE setName
+NOTIFY nameChanged)
+
 .. _IfMacros:
 
 **IfMacros** (``List of Strings``) :versionbadge:`clang-format 13` :ref:`¶ 
`
diff --git a/clang/docs/tools/dump_format_style.py 
b/clang/docs/tools/dump_format_style.py
index f035143f6b3d1..ef0763b0d13f1 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -461,6 +461,7 @@ class State:
 "int",
 "std::string",
 "std::vector",
+"std::vector",
 "std::vector",
 "std::vector",
 "std::optional",
diff --git a/clang/docs/tools/plurals.txt b/clang/docs/tools/plurals.txt
index e20b7f970ba43..445b5b2dc0f92 100644
--- a/clang/docs/tools/plurals.txt
+++ b/clang/docs/tools/plurals.txt
@@ -1,3 +1,4 @@
 Strings
+FunctionDeclarationWithKeywordes
 IncludeCategories
 RawStringFormats
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index fec47a248abb4..323dd189d0dc4 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2753,6 +2753,45 @@ struct FormatStyle {
   /// \version 3.7
   std::vector ForEachMacros;
 
+  /// Function-like declaration with keyworded parameters.
+  /// Lists possible keywords for a named macro-like function
+  struct FunctionDeclarationWithKeywords {
+std::string Name;
+std::vector Keywords;
+
+bool operator==(const FunctionDeclarationWithKeywords &Other) const {
+  return Name == Other.Name && Keywords == Other.Keywords;
+}
+  };
+
+  /// Allows to format function-like macros with keyworded parameters according
+  /// to the BinPackParameters setting, treating keywords as parameter
+  /// sepratators.
+  ///
+  /// Q_PROPERTY is an example of such a macro:
+  /// \code
+  ///   Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+  /// \endcode
+  ///
+  /// With ``BinPackParameters``  set to ``OnePerLine`` (or
+  /// ``AlwaysOnePerLine``) and
+  /// \code{.yaml}
+  ///   FunctionDeclarationsWithKeywords:
+  ///   - Name: "Q_PROPERTY"
+  /// Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+  /// \endcode
+  ///
+  /// the line above will be split on these keywords:
+  /// \code
+  ///   Q_PROPERTY(
+  ///   int name
+  ///   READ name
+  ///   WRITE setName
+  ///   NOTIFY nameChanged)
+  /// \endcode
+  /// \version 21
+  std::vector 
FunctionDeclarationsWithKeywords;
+
   tooling::IncludeStyle In

[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-03-20 Thread Eugene Shalygin via cfe-commits

https://github.com/zeule updated 
https://github.com/llvm/llvm-project/pull/131605

>From 2c9a7417287aeb7931ee012914448c8c6fcae06a Mon Sep 17 00:00:00 2001
From: Eugene Shalygin 
Date: Mon, 17 Mar 2025 11:23:35 +0100
Subject: [PATCH] [clang-format] option to control bin-packing keyworded
 parameters

The Q_PROPERTY declaration is almost like a function declaration, but
uses keywords as parameter separators. This allows users to provide list
of those keywords to be used to control bin-packing of the macro
parameters.
---
 clang/docs/ClangFormatStyleOptions.rst| 32 +++
 clang/docs/tools/dump_format_style.py |  1 +
 clang/docs/tools/plurals.txt  |  1 +
 clang/include/clang/Format/Format.h   | 41 ++
 clang/lib/Format/ContinuationIndenter.cpp |  4 ++
 clang/lib/Format/Format.cpp   | 11 
 clang/lib/Format/FormatToken.cpp  |  2 +
 clang/lib/Format/FormatToken.h|  1 +
 clang/lib/Format/TokenAnnotator.cpp   | 51 --
 clang/unittests/Format/ConfigParseTest.cpp| 10 
 clang/unittests/Format/FormatTest.cpp | 54 +++
 clang/unittests/Format/TokenAnnotatorTest.cpp | 33 
 12 files changed, 237 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 9ecac68ae72bf..8932c40402a5c 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4032,6 +4032,38 @@ the configuration (without a prefix: ``Auto``).
 
   For example: BOOST_FOREACH.
 
+.. _FunctionDeclarationsWithKeywords:
+
+**FunctionDeclarationsWithKeywords** (``List of 
FunctionDeclarationWithKeywordes``) :versionbadge:`clang-format 21` :ref:`¶ 
`
+  Allows to format function-like macros with keyworded parameters according
+  to the BinPackParameters setting, treating keywords as parameter
+  sepratators.
+
+  Q_PROPERTY is an example of such a macro:
+
+  .. code-block:: c++
+
+Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+
+  With ``BinPackParameters``  set to ``OnePerLine`` (or
+  ``AlwaysOnePerLine``) and
+
+  .. code-block:: yaml
+
+FunctionDeclarationsWithKeywords:
+- Name: "Q_PROPERTY"
+  Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+
+  the line above will be split on these keywords:
+
+  .. code-block:: c++
+
+Q_PROPERTY(
+int name
+READ name
+WRITE setName
+NOTIFY nameChanged)
+
 .. _IfMacros:
 
 **IfMacros** (``List of Strings``) :versionbadge:`clang-format 13` :ref:`¶ 
`
diff --git a/clang/docs/tools/dump_format_style.py 
b/clang/docs/tools/dump_format_style.py
index f035143f6b3d1..ef0763b0d13f1 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -461,6 +461,7 @@ class State:
 "int",
 "std::string",
 "std::vector",
+"std::vector",
 "std::vector",
 "std::vector",
 "std::optional",
diff --git a/clang/docs/tools/plurals.txt b/clang/docs/tools/plurals.txt
index e20b7f970ba43..445b5b2dc0f92 100644
--- a/clang/docs/tools/plurals.txt
+++ b/clang/docs/tools/plurals.txt
@@ -1,3 +1,4 @@
 Strings
+FunctionDeclarationWithKeywordes
 IncludeCategories
 RawStringFormats
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index fec47a248abb4..323dd189d0dc4 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2753,6 +2753,45 @@ struct FormatStyle {
   /// \version 3.7
   std::vector ForEachMacros;
 
+  /// Function-like declaration with keyworded parameters.
+  /// Lists possible keywords for a named macro-like function
+  struct FunctionDeclarationWithKeywords {
+std::string Name;
+std::vector Keywords;
+
+bool operator==(const FunctionDeclarationWithKeywords &Other) const {
+  return Name == Other.Name && Keywords == Other.Keywords;
+}
+  };
+
+  /// Allows to format function-like macros with keyworded parameters according
+  /// to the BinPackParameters setting, treating keywords as parameter
+  /// sepratators.
+  ///
+  /// Q_PROPERTY is an example of such a macro:
+  /// \code
+  ///   Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+  /// \endcode
+  ///
+  /// With ``BinPackParameters``  set to ``OnePerLine`` (or
+  /// ``AlwaysOnePerLine``) and
+  /// \code{.yaml}
+  ///   FunctionDeclarationsWithKeywords:
+  ///   - Name: "Q_PROPERTY"
+  /// Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+  /// \endcode
+  ///
+  /// the line above will be split on these keywords:
+  /// \code
+  ///   Q_PROPERTY(
+  ///   int name
+  ///   READ name
+  ///   WRITE setName
+  ///   NOTIFY nameChanged)
+  /// \endcode
+  /// \version 21
+  std::vector 
FunctionDeclarationsWithKeywords;
+
   tooling::IncludeStyle 

[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-03-25 Thread Eugene Shalygin via cfe-commits

zeule wrote:

> Please fix the spellings

I guess the simplest way would be to rename "FunctionDeclarationWithKeywords" 
(e.g. "KeywordedFunctionDeclaration")? Otherwise I would have to extend the 
logic in `pluralize()` inside `clang/docs/tools/dump_format_style.py`?

https://github.com/llvm/llvm-project/pull/131605
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-03-25 Thread Eugene Shalygin via cfe-commits


@@ -1,3 +1,4 @@
 Strings
+FunctionDeclarationWithKeywordes

zeule wrote:

Running `clang/docs/tools/dump_format_style.py` generates that entry, I guess 
because of 
[this](https://github.com/llvm/llvm-project/blob/65ad02b882ba545dafbfc195a78e204c218e93ed/clang/docs/tools/dump_format_style.py#L59)
 function.

https://github.com/llvm/llvm-project/pull/131605
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-03-31 Thread Eugene Shalygin via cfe-commits


@@ -3783,10 +3823,20 @@ void TokenAnnotator::annotate(AnnotatedLine &Line) {
 static bool isFunctionDeclarationName(const LangOptions &LangOpts,
   const FormatToken &Current,
   const AnnotatedLine &Line,
+  const FormatStyle &Style,
   FormatToken *&ClosingParen) {
   if (Current.is(TT_FunctionDeclarationName))
 return true;
 
+  if (Current.is(TT_FunctionLikeOrFreestandingMacro) &&
+  std::find_if(
+  Style.KeywordedFunctionLikeMacros.begin(),
+  Style.KeywordedFunctionLikeMacros.end(),
+  [&Current](const FormatStyle::KeywordedFunctionLikeMacro &Decl) {
+return Current.TokenText == Decl.Name;
+  }) != Style.KeywordedFunctionLikeMacros.end()) {
+return true;
+  }

zeule wrote:

It is not necessary; undone. Thank you!

https://github.com/llvm/llvm-project/pull/131605
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-03-31 Thread Eugene Shalygin via cfe-commits

https://github.com/zeule updated 
https://github.com/llvm/llvm-project/pull/131605

>From e2db7bd178a2c466b066787f235578b624a23644 Mon Sep 17 00:00:00 2001
From: Eugene Shalygin 
Date: Mon, 17 Mar 2025 11:23:35 +0100
Subject: [PATCH] [clang-format] option to control bin-packing keyworded
 parameters

The Q_PROPERTY declaration is almost like a function declaration, but
uses keywords as parameter separators. This allows users to provide list
of those keywords to be used to control bin-packing of the macro
parameters.
---
 clang/docs/ClangFormatStyleOptions.rst| 32 ++
 clang/docs/tools/dump_format_style.py |  1 +
 clang/docs/tools/plurals.txt  |  1 +
 clang/include/clang/Format/Format.h   | 40 +
 clang/lib/Format/ContinuationIndenter.cpp |  4 ++
 clang/lib/Format/Format.cpp   | 11 
 clang/lib/Format/FormatToken.cpp  |  2 +
 clang/lib/Format/FormatToken.h|  1 +
 clang/lib/Format/TokenAnnotator.cpp   | 50 ++--
 clang/unittests/Format/ConfigParseTest.cpp| 10 
 clang/unittests/Format/FormatTest.cpp | 59 +++
 clang/unittests/Format/TokenAnnotatorTest.cpp | 33 +++
 12 files changed, 240 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 9ecac68ae72bf..d318fc3295c32 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4740,6 +4740,38 @@ the configuration (without a prefix: ``Auto``).
   replaced with a single newline and form feed followed by the remaining
   newlines.
 
+.. _KeywordedFunctionLikeMacros:
+
+**KeywordedFunctionLikeMacros** (``List of KeywordedFunctionLikeMacros``) 
:versionbadge:`clang-format 21` :ref:`¶ `
+  Allows to format function-like macros with keyworded parameters according
+  to the BinPackParameters setting, treating keywords as parameter
+  sepratators.
+
+  Q_PROPERTY is an example of such a macro:
+
+  .. code-block:: c++
+
+Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+
+  With ``BinPackParameters``  set to ``OnePerLine`` (or
+  ``AlwaysOnePerLine``) and
+
+  .. code-block:: yaml
+
+KeywordedFunctionLikeMacros:
+- Name: "Q_PROPERTY"
+  Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+
+  the line above will be split on these keywords:
+
+  .. code-block:: c++
+
+Q_PROPERTY(
+int name
+READ name
+WRITE setName
+NOTIFY nameChanged)
+
 .. _LambdaBodyIndentation:
 
 **LambdaBodyIndentation** (``LambdaBodyIndentationKind``) 
:versionbadge:`clang-format 13` :ref:`¶ `
diff --git a/clang/docs/tools/dump_format_style.py 
b/clang/docs/tools/dump_format_style.py
index f035143f6b3d1..85732af8e0a60 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -462,6 +462,7 @@ class State:
 "std::string",
 "std::vector",
 "std::vector",
+"std::vector",
 "std::vector",
 "std::optional",
 "deprecated",
diff --git a/clang/docs/tools/plurals.txt b/clang/docs/tools/plurals.txt
index e20b7f970ba43..bd08c65df1c52 100644
--- a/clang/docs/tools/plurals.txt
+++ b/clang/docs/tools/plurals.txt
@@ -1,3 +1,4 @@
 Strings
 IncludeCategories
+KeywordedFunctionLikeMacros
 RawStringFormats
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index fec47a248abb4..5ba27adb053a3 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3276,6 +3276,45 @@ struct FormatStyle {
   /// \version 20
   bool KeepFormFeed;
 
+  /// Function-like declaration with keyworded parameters.
+  /// Lists possible keywords for a named function-like macro.
+  struct KeywordedFunctionLikeMacro {
+std::string Name;
+std::vector Keywords;
+
+bool operator==(const KeywordedFunctionLikeMacro &Other) const {
+  return Name == Other.Name && Keywords == Other.Keywords;
+}
+  };
+
+  /// Allows to format function-like macros with keyworded parameters according
+  /// to the BinPackParameters setting, treating keywords as parameter
+  /// separators.
+  ///
+  /// Q_PROPERTY is an example of such a macro:
+  /// \code
+  ///   Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+  /// \endcode
+  ///
+  /// With ``BinPackParameters``  set to ``OnePerLine`` (or
+  /// ``AlwaysOnePerLine``) and
+  /// \code{.yaml}
+  ///   KeywordedFunctionLikeMacros:
+  ///   - Name: "Q_PROPERTY"
+  /// Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+  /// \endcode
+  ///
+  /// the line above will be split on these keywords:
+  /// \code
+  ///   Q_PROPERTY(
+  ///   int name
+  ///   READ name
+  ///   WRITE setName
+  ///   NOTIFY nameChanged)
+  /// \endcode
+  /// \version 21
+  std::vector KeywordedFunctionLik

[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-03-31 Thread Eugene Shalygin via cfe-commits

https://github.com/zeule updated 
https://github.com/llvm/llvm-project/pull/131605

>From 7642499ca3bd2929c7392b7d619980b3cf9e648c Mon Sep 17 00:00:00 2001
From: Eugene Shalygin 
Date: Mon, 17 Mar 2025 11:23:35 +0100
Subject: [PATCH] [clang-format] option to control bin-packing keyworded
 parameters

The Q_PROPERTY declaration is almost like a function declaration, but
uses keywords as parameter separators. This allows users to provide list
of those keywords to be used to control bin-packing of the macro
parameters.
---
 clang/docs/ClangFormatStyleOptions.rst| 32 ++
 clang/docs/tools/dump_format_style.py |  1 +
 clang/docs/tools/plurals.txt  |  1 +
 clang/include/clang/Format/Format.h   | 40 +
 clang/lib/Format/ContinuationIndenter.cpp |  4 ++
 clang/lib/Format/Format.cpp   | 11 
 clang/lib/Format/FormatToken.cpp  |  2 +
 clang/lib/Format/FormatToken.h|  1 +
 clang/lib/Format/TokenAnnotator.cpp   | 47 ++-
 clang/unittests/Format/ConfigParseTest.cpp| 10 
 clang/unittests/Format/FormatTest.cpp | 59 +++
 clang/unittests/Format/TokenAnnotatorTest.cpp | 33 +++
 12 files changed, 238 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 9ecac68ae72bf..d318fc3295c32 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4740,6 +4740,38 @@ the configuration (without a prefix: ``Auto``).
   replaced with a single newline and form feed followed by the remaining
   newlines.
 
+.. _KeywordedFunctionLikeMacros:
+
+**KeywordedFunctionLikeMacros** (``List of KeywordedFunctionLikeMacros``) 
:versionbadge:`clang-format 21` :ref:`¶ `
+  Allows to format function-like macros with keyworded parameters according
+  to the BinPackParameters setting, treating keywords as parameter
+  sepratators.
+
+  Q_PROPERTY is an example of such a macro:
+
+  .. code-block:: c++
+
+Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+
+  With ``BinPackParameters``  set to ``OnePerLine`` (or
+  ``AlwaysOnePerLine``) and
+
+  .. code-block:: yaml
+
+KeywordedFunctionLikeMacros:
+- Name: "Q_PROPERTY"
+  Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+
+  the line above will be split on these keywords:
+
+  .. code-block:: c++
+
+Q_PROPERTY(
+int name
+READ name
+WRITE setName
+NOTIFY nameChanged)
+
 .. _LambdaBodyIndentation:
 
 **LambdaBodyIndentation** (``LambdaBodyIndentationKind``) 
:versionbadge:`clang-format 13` :ref:`¶ `
diff --git a/clang/docs/tools/dump_format_style.py 
b/clang/docs/tools/dump_format_style.py
index f035143f6b3d1..85732af8e0a60 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -462,6 +462,7 @@ class State:
 "std::string",
 "std::vector",
 "std::vector",
+"std::vector",
 "std::vector",
 "std::optional",
 "deprecated",
diff --git a/clang/docs/tools/plurals.txt b/clang/docs/tools/plurals.txt
index e20b7f970ba43..bd08c65df1c52 100644
--- a/clang/docs/tools/plurals.txt
+++ b/clang/docs/tools/plurals.txt
@@ -1,3 +1,4 @@
 Strings
 IncludeCategories
+KeywordedFunctionLikeMacros
 RawStringFormats
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index fec47a248abb4..5ba27adb053a3 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3276,6 +3276,45 @@ struct FormatStyle {
   /// \version 20
   bool KeepFormFeed;
 
+  /// Function-like declaration with keyworded parameters.
+  /// Lists possible keywords for a named function-like macro.
+  struct KeywordedFunctionLikeMacro {
+std::string Name;
+std::vector Keywords;
+
+bool operator==(const KeywordedFunctionLikeMacro &Other) const {
+  return Name == Other.Name && Keywords == Other.Keywords;
+}
+  };
+
+  /// Allows to format function-like macros with keyworded parameters according
+  /// to the BinPackParameters setting, treating keywords as parameter
+  /// separators.
+  ///
+  /// Q_PROPERTY is an example of such a macro:
+  /// \code
+  ///   Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+  /// \endcode
+  ///
+  /// With ``BinPackParameters``  set to ``OnePerLine`` (or
+  /// ``AlwaysOnePerLine``) and
+  /// \code{.yaml}
+  ///   KeywordedFunctionLikeMacros:
+  ///   - Name: "Q_PROPERTY"
+  /// Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+  /// \endcode
+  ///
+  /// the line above will be split on these keywords:
+  /// \code
+  ///   Q_PROPERTY(
+  ///   int name
+  ///   READ name
+  ///   WRITE setName
+  ///   NOTIFY nameChanged)
+  /// \endcode
+  /// \version 21
+  std::vector KeywordedFunctionLike

[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-03-28 Thread Eugene Shalygin via cfe-commits

https://github.com/zeule updated 
https://github.com/llvm/llvm-project/pull/131605

>From 849636c372580082b8c67d7d66728788d284ebee Mon Sep 17 00:00:00 2001
From: Eugene Shalygin 
Date: Mon, 17 Mar 2025 11:23:35 +0100
Subject: [PATCH] [clang-format] option to control bin-packing keyworded
 parameters

The Q_PROPERTY declaration is almost like a function declaration, but
uses keywords as parameter separators. This allows users to provide list
of those keywords to be used to control bin-packing of the macro
parameters.
---
 clang/docs/ClangFormatStyleOptions.rst| 32 ++
 clang/docs/tools/dump_format_style.py |  1 +
 clang/docs/tools/plurals.txt  |  1 +
 clang/include/clang/Format/Format.h   | 40 +
 clang/lib/Format/ContinuationIndenter.cpp |  4 ++
 clang/lib/Format/Format.cpp   | 11 
 clang/lib/Format/FormatToken.cpp  |  2 +
 clang/lib/Format/FormatToken.h|  1 +
 clang/lib/Format/TokenAnnotator.cpp   | 59 +--
 clang/unittests/Format/ConfigParseTest.cpp| 10 
 clang/unittests/Format/FormatTest.cpp | 59 +++
 clang/unittests/Format/TokenAnnotatorTest.cpp | 33 +++
 12 files changed, 249 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 9ecac68ae72bf..8723458e7b986 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4740,6 +4740,38 @@ the configuration (without a prefix: ``Auto``).
   replaced with a single newline and form feed followed by the remaining
   newlines.
 
+.. _KeywordedFunctionLikeMacros:
+
+**KeywordedFunctionLikeMacros** (``List of KeywordedFunctionLikeMacros``) 
:versionbadge:`clang-format 21` :ref:`¶ `
+  Allows to format function-like macros with keyworded parameters according
+  to the BinPackParameters setting, treating keywords as parameter
+  separators.
+
+  Q_PROPERTY is an example of such a macro:
+
+  .. code-block:: c++
+
+Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+
+  With ``BinPackParameters``  set to ``OnePerLine`` (or
+  ``AlwaysOnePerLine``) and
+
+  .. code-block:: yaml
+
+KeywordedFunctionLikeMacros:
+- Name: "Q_PROPERTY"
+  Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+
+  the line above will be split on these keywords:
+
+  .. code-block:: c++
+
+Q_PROPERTY(
+int name
+READ name
+WRITE setName
+NOTIFY nameChanged)
+
 .. _LambdaBodyIndentation:
 
 **LambdaBodyIndentation** (``LambdaBodyIndentationKind``) 
:versionbadge:`clang-format 13` :ref:`¶ `
diff --git a/clang/docs/tools/dump_format_style.py 
b/clang/docs/tools/dump_format_style.py
index f035143f6b3d1..85732af8e0a60 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -462,6 +462,7 @@ class State:
 "std::string",
 "std::vector",
 "std::vector",
+"std::vector",
 "std::vector",
 "std::optional",
 "deprecated",
diff --git a/clang/docs/tools/plurals.txt b/clang/docs/tools/plurals.txt
index e20b7f970ba43..bd08c65df1c52 100644
--- a/clang/docs/tools/plurals.txt
+++ b/clang/docs/tools/plurals.txt
@@ -1,3 +1,4 @@
 Strings
 IncludeCategories
+KeywordedFunctionLikeMacros
 RawStringFormats
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index fec47a248abb4..5ba27adb053a3 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3276,6 +3276,45 @@ struct FormatStyle {
   /// \version 20
   bool KeepFormFeed;
 
+  /// Function-like declaration with keyworded parameters.
+  /// Lists possible keywords for a named function-like macro.
+  struct KeywordedFunctionLikeMacro {
+std::string Name;
+std::vector Keywords;
+
+bool operator==(const KeywordedFunctionLikeMacro &Other) const {
+  return Name == Other.Name && Keywords == Other.Keywords;
+}
+  };
+
+  /// Allows to format function-like macros with keyworded parameters according
+  /// to the BinPackParameters setting, treating keywords as parameter
+  /// separators.
+  ///
+  /// Q_PROPERTY is an example of such a macro:
+  /// \code
+  ///   Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+  /// \endcode
+  ///
+  /// With ``BinPackParameters``  set to ``OnePerLine`` (or
+  /// ``AlwaysOnePerLine``) and
+  /// \code{.yaml}
+  ///   KeywordedFunctionLikeMacros:
+  ///   - Name: "Q_PROPERTY"
+  /// Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+  /// \endcode
+  ///
+  /// the line above will be split on these keywords:
+  /// \code
+  ///   Q_PROPERTY(
+  ///   int name
+  ///   READ name
+  ///   WRITE setName
+  ///   NOTIFY nameChanged)
+  /// \endcode
+  /// \version 21
+  std::vector KeywordedFunctionL

[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-03-28 Thread Eugene Shalygin via cfe-commits

https://github.com/zeule updated 
https://github.com/llvm/llvm-project/pull/131605

>From ab0165b868ffcdbf9330d0e0eab274117eb99c80 Mon Sep 17 00:00:00 2001
From: Eugene Shalygin 
Date: Mon, 17 Mar 2025 11:23:35 +0100
Subject: [PATCH] [clang-format] option to control bin-packing keyworded
 parameters

The Q_PROPERTY declaration is almost like a function declaration, but
uses keywords as parameter separators. This allows users to provide list
of those keywords to be used to control bin-packing of the macro
parameters.
---
 clang/docs/ClangFormatStyleOptions.rst| 32 ++
 clang/docs/tools/dump_format_style.py |  1 +
 clang/docs/tools/plurals.txt  |  1 +
 clang/include/clang/Format/Format.h   | 40 +
 clang/lib/Format/ContinuationIndenter.cpp |  4 ++
 clang/lib/Format/Format.cpp   | 11 
 clang/lib/Format/FormatToken.cpp  |  2 +
 clang/lib/Format/FormatToken.h|  1 +
 clang/lib/Format/TokenAnnotator.cpp   | 59 +--
 clang/unittests/Format/ConfigParseTest.cpp| 10 
 clang/unittests/Format/FormatTest.cpp | 59 +++
 clang/unittests/Format/TokenAnnotatorTest.cpp | 33 +++
 12 files changed, 249 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 9ecac68ae72bf..809ad3791a03b 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4740,6 +4740,38 @@ the configuration (without a prefix: ``Auto``).
   replaced with a single newline and form feed followed by the remaining
   newlines.
 
+.. _KeywordedFunctionLikeMacros:
+
+**KeywordedFunctionLikeMacros** (``List of KeywordedFunctionLikeMacros``) 
:versionbadge:`clang-format 21` :ref:`¶ `
+  Allows to format function-like macros with keyworded parameters according
+  to the BinPackParameters setting, treating keywords as parameter
+  sepratators.
+
+  Q_PROPERTY is an example of such a macro:
+
+  .. code-block:: c++
+
+Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+
+  With ``BinPackParameters``  set to ``OnePerLine`` (or
+  ``AlwaysOnePerLine``) and
+
+  .. code-block:: yaml
+
+FunctionDeclarationsWithKeywords:
+- Name: "Q_PROPERTY"
+  Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+
+  the line above will be split on these keywords:
+
+  .. code-block:: c++
+
+Q_PROPERTY(
+int name
+READ name
+WRITE setName
+NOTIFY nameChanged)
+
 .. _LambdaBodyIndentation:
 
 **LambdaBodyIndentation** (``LambdaBodyIndentationKind``) 
:versionbadge:`clang-format 13` :ref:`¶ `
diff --git a/clang/docs/tools/dump_format_style.py 
b/clang/docs/tools/dump_format_style.py
index f035143f6b3d1..85732af8e0a60 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -462,6 +462,7 @@ class State:
 "std::string",
 "std::vector",
 "std::vector",
+"std::vector",
 "std::vector",
 "std::optional",
 "deprecated",
diff --git a/clang/docs/tools/plurals.txt b/clang/docs/tools/plurals.txt
index e20b7f970ba43..bd08c65df1c52 100644
--- a/clang/docs/tools/plurals.txt
+++ b/clang/docs/tools/plurals.txt
@@ -1,3 +1,4 @@
 Strings
 IncludeCategories
+KeywordedFunctionLikeMacros
 RawStringFormats
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index fec47a248abb4..c36317e8ffcaf 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3276,6 +3276,45 @@ struct FormatStyle {
   /// \version 20
   bool KeepFormFeed;
 
+  /// Function-like declaration with keyworded parameters.
+  /// Lists possible keywords for a named function-like macro.
+  struct KeywordedFunctionLikeMacro {
+std::string Name;
+std::vector Keywords;
+
+bool operator==(const KeywordedFunctionLikeMacro &Other) const {
+  return Name == Other.Name && Keywords == Other.Keywords;
+}
+  };
+
+  /// Allows to format function-like macros with keyworded parameters according
+  /// to the BinPackParameters setting, treating keywords as parameter
+  /// sepratators.
+  ///
+  /// Q_PROPERTY is an example of such a macro:
+  /// \code
+  ///   Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+  /// \endcode
+  ///
+  /// With ``BinPackParameters``  set to ``OnePerLine`` (or
+  /// ``AlwaysOnePerLine``) and
+  /// \code{.yaml}
+  ///   KeywordedFunctionLikeMacros:
+  ///   - Name: "Q_PROPERTY"
+  /// Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+  /// \endcode
+  ///
+  /// the line above will be split on these keywords:
+  /// \code
+  ///   Q_PROPERTY(
+  ///   int name
+  ///   READ name
+  ///   WRITE setName
+  ///   NOTIFY nameChanged)
+  /// \endcode
+  /// \version 21
+  std::vector KeywordedFu

[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-03-28 Thread Eugene Shalygin via cfe-commits


@@ -29102,6 +29102,65 @@ TEST_F(FormatTest, BreakBeforeClassName) {
"ArenaSafeUniquePtr {};");
 }
 
+TEST_F(FormatTest, FunctionDeclarationWithKeywords) {

zeule wrote:

Done, thanks.

https://github.com/llvm/llvm-project/pull/131605
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-04-04 Thread Eugene Shalygin via cfe-commits

https://github.com/zeule updated 
https://github.com/llvm/llvm-project/pull/131605

>From 5a1ed72f4be5ddd426a03ce1d1fb9cefc233942a Mon Sep 17 00:00:00 2001
From: Eugene Shalygin 
Date: Mon, 17 Mar 2025 11:23:35 +0100
Subject: [PATCH] [clang-format] option to control bin-packing keyworded
 parameters

The Q_PROPERTY declaration is almost like a function declaration, but
uses keywords as parameter separators. This allows users to provide list
of those keywords to be used to control bin-packing of the macro
parameters.
---
 clang/docs/ClangFormatStyleOptions.rst| 32 ++
 clang/docs/ReleaseNotes.rst   |  2 +
 clang/docs/tools/dump_format_style.py |  1 +
 clang/docs/tools/plurals.txt  |  1 +
 clang/include/clang/Format/Format.h   | 40 +
 clang/lib/Format/ContinuationIndenter.cpp |  4 ++
 clang/lib/Format/Format.cpp   | 11 
 clang/lib/Format/FormatToken.cpp  |  2 +
 clang/lib/Format/FormatToken.h|  1 +
 clang/lib/Format/TokenAnnotator.cpp   | 47 ++-
 clang/unittests/Format/ConfigParseTest.cpp| 10 
 clang/unittests/Format/FormatTest.cpp | 59 +++
 clang/unittests/Format/TokenAnnotatorTest.cpp | 33 +++
 13 files changed, 240 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 3f8a5f49313b2..d61bafc1b4dd0 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4781,6 +4781,38 @@ the configuration (without a prefix: ``Auto``).
   replaced with a single newline and form feed followed by the remaining
   newlines.
 
+.. _KeywordedFunctionLikeMacros:
+
+**KeywordedFunctionLikeMacros** (``List of KeywordedFunctionLikeMacros``) 
:versionbadge:`clang-format 21` :ref:`¶ `
+  Allows to format function-like macros with keyworded parameters according
+  to the BinPackParameters setting, treating keywords as parameter
+  separators.
+
+  Q_PROPERTY is an example of such a macro:
+
+  .. code-block:: c++
+
+Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+
+  With ``BinPackParameters``  set to ``OnePerLine`` (or
+  ``AlwaysOnePerLine``) and
+
+  .. code-block:: yaml
+
+KeywordedFunctionLikeMacros:
+- Name: "Q_PROPERTY"
+  Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+
+  the line above will be split on these keywords:
+
+  .. code-block:: c++
+
+Q_PROPERTY(
+int name
+READ name
+WRITE setName
+NOTIFY nameChanged)
+
 .. _LambdaBodyIndentation:
 
 **LambdaBodyIndentation** (``LambdaBodyIndentationKind``) 
:versionbadge:`clang-format 13` :ref:`¶ `
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index daad01919ecd4..9c2e79da722d5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -498,6 +498,8 @@ clang-format
   top of the file.
 - Add ``EnumTrailingComma`` option for inserting/removing commas at the end of
   ``enum`` enumerator lists.
+- Allow to apply parameters bin-packing options to function-like macros that
+  use keywords to delimit parameters (e.g. Q_OBJECT).
 
 libclang
 
diff --git a/clang/docs/tools/dump_format_style.py 
b/clang/docs/tools/dump_format_style.py
index f035143f6b3d1..85732af8e0a60 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -462,6 +462,7 @@ class State:
 "std::string",
 "std::vector",
 "std::vector",
+"std::vector",
 "std::vector",
 "std::optional",
 "deprecated",
diff --git a/clang/docs/tools/plurals.txt b/clang/docs/tools/plurals.txt
index e20b7f970ba43..bd08c65df1c52 100644
--- a/clang/docs/tools/plurals.txt
+++ b/clang/docs/tools/plurals.txt
@@ -1,3 +1,4 @@
 Strings
 IncludeCategories
+KeywordedFunctionLikeMacros
 RawStringFormats
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index cea5e257659d6..846e5a8f7f94b 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3309,6 +3309,45 @@ struct FormatStyle {
   /// \version 20
   bool KeepFormFeed;
 
+  /// Function-like declaration with keyworded parameters.
+  /// Lists possible keywords for a named function-like macro.
+  struct KeywordedFunctionLikeMacro {
+std::string Name;
+std::vector Keywords;
+
+bool operator==(const KeywordedFunctionLikeMacro &Other) const {
+  return Name == Other.Name && Keywords == Other.Keywords;
+}
+  };
+
+  /// Allows to format function-like macros with keyworded parameters according
+  /// to the BinPackParameters setting, treating keywords as parameter
+  /// separators.
+  ///
+  /// Q_PROPERTY is an example of such a macro:
+  /// \code
+  ///   Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+  /// \e

[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-03-28 Thread Eugene Shalygin via cfe-commits


@@ -3146,6 +3146,45 @@ struct FormatStyle {
   /// \version 16
   IntegerLiteralSeparatorStyle IntegerLiteralSeparator;
 
+  /// Function-like declaration with keyworded parameters.
+  /// Lists possible keywords for a named macro-like function
+  struct KeywordedFunctionLikeMacro {
+std::string Name;
+std::vector Keywords;
+
+bool operator==(const KeywordedFunctionLikeMacro &Other) const {
+  return Name == Other.Name && Keywords == Other.Keywords;
+}
+  };
+
+  /// Allows to format function-like macros with keyworded parameters according
+  /// to the BinPackParameters setting, treating keywords as parameter
+  /// sepratators.
+  ///
+  /// Q_PROPERTY is an example of such a macro:
+  /// \code
+  ///   Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+  /// \endcode
+  ///
+  /// With ``BinPackParameters``  set to ``OnePerLine`` (or
+  /// ``AlwaysOnePerLine``) and
+  /// \code{.yaml}
+  ///   FunctionDeclarationsWithKeywords:
+  ///   - Name: "Q_PROPERTY"
+  /// Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+  /// \endcode
+  ///
+  /// the line above will be split on these keywords:
+  /// \code
+  ///   Q_PROPERTY(
+  ///   int name
+  ///   READ name
+  ///   WRITE setName
+  ///   NOTIFY nameChanged)
+  /// \endcode
+  /// \version 21
+  std::vector KeywordedFunctionLikeMacros;

zeule wrote:

Of course, thanks!

https://github.com/llvm/llvm-project/pull/131605
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-03-28 Thread Eugene Shalygin via cfe-commits


@@ -3146,6 +3146,45 @@ struct FormatStyle {
   /// \version 16
   IntegerLiteralSeparatorStyle IntegerLiteralSeparator;
 
+  /// Function-like declaration with keyworded parameters.
+  /// Lists possible keywords for a named macro-like function

zeule wrote:

Lists possible keywords for a named function-like macro.

https://github.com/llvm/llvm-project/pull/131605
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-04-03 Thread Eugene Shalygin via cfe-commits

zeule wrote:

Of course it is only because of the Qt popularity I submit this changeset  to 
the mainline.

The keywords are natural delimiters in those declarations,  so I can't see the 
proposed solution to use them as delimiters to be unsuitable to an any 
significant group of Qt users. In the defense of the generic approach I want to 
remind that Qt's moc expands macros, thus one can replace the standard keywords 
(and, I guess, the "Q_PROPERTY" itself) with anything else.

I can try to use contexts in the implementation, but I still oppose targeting 
`Q_PROPERTY` literal in the source code.

https://github.com/llvm/llvm-project/pull/131605
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-03-25 Thread Eugene Shalygin via cfe-commits


@@ -148,6 +158,32 @@ class AnnotatingParser {
 }
   }
 
+  const FormatStyle::FunctionDeclarationWithKeywords *
+  findFunctionWithKeywordedParameters() const {
+const FormatToken *TokBeforeFirstLParent{};
+for (const FormatToken *T = Line.First; T != Line.Last; T = T->Next) {
+  if (T->TokenText == StringRef("(", 1)) {

zeule wrote:

I have to check `T->Tok`, which `Kind` is `tok::l_paren`, rather than `T` 
itself. Thank you!

https://github.com/llvm/llvm-project/pull/131605
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-04-04 Thread Eugene Shalygin via cfe-commits

https://github.com/zeule updated 
https://github.com/llvm/llvm-project/pull/131605

>From b6d53143b5f3fd6db9f6b76df9dd49425d9038a8 Mon Sep 17 00:00:00 2001
From: Eugene Shalygin 
Date: Mon, 17 Mar 2025 11:23:35 +0100
Subject: [PATCH] [clang-format] add option to bin-pack keyworded parameters

The Q_PROPERTY declaration is almost like a function declaration, but
uses keywords as parameter separators. This allows users to provide list
of those keywords to be used to control bin-packing of the macro
parameters.
---
 clang/include/clang/Format/Format.h   | 37 
 clang/lib/Format/ContinuationIndenter.cpp |  4 ++
 clang/lib/Format/Format.cpp   | 11 
 clang/lib/Format/FormatToken.cpp  |  2 +
 clang/lib/Format/FormatToken.h|  1 +
 clang/lib/Format/TokenAnnotator.cpp   | 54 --
 clang/unittests/Format/ConfigParseTest.cpp| 10 
 clang/unittests/Format/FormatTest.cpp | 57 +++
 clang/unittests/Format/TokenAnnotatorTest.cpp | 33 +++
 9 files changed, 205 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index fec47a248abb4..b5f226e4389b6 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2753,6 +2753,41 @@ struct FormatStyle {
   /// \version 3.7
   std::vector ForEachMacros;
 
+  struct FunctionDeclarationWithKeywords {
+std::string Name;
+std::vector Keywords;
+
+bool operator==(const FunctionDeclarationWithKeywords &Other) const {
+  return Name == Other.Name && Keywords == Other.Keywords;
+}
+  };
+
+  /// Allows to format function-line macros with keyworded parameters according
+  /// to the BinPackParameters setting, treating keywords as parameter
+  /// sepratators.
+  /// \version 21
+  ///
+  /// Q_PROPERTY is an example of such a macro:
+  /// \code
+  /// Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+  /// \endcode
+  ///
+  /// With BinPackParameters set to OnePerLine (or AlwaysOnePerLine) and
+  /// \code{.yaml}
+  /// FunctionDeclarationsWithKeywords:
+  /// - Name: "Q_PROPERTY"
+  ///   Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+  /// \endcode
+  /// the line above will be split on these keywords:
+  /// \code
+  /// Q_PROPERTY(
+  /// int name
+  /// READ name
+  /// WRITE setName
+  /// NOTIFY nameChanged)
+  /// \endcode
+  std::vector 
FunctionDeclarationsWithKeywords;
+
   tooling::IncludeStyle IncludeStyle;
 
   /// A vector of macros that should be interpreted as conditionals
@@ -5327,6 +5362,8 @@ struct FormatStyle {
R.ExperimentalAutoDetectBinPacking &&
FixNamespaceComments == R.FixNamespaceComments &&
ForEachMacros == R.ForEachMacros &&
+   FunctionDeclarationsWithKeywords ==
+   R.FunctionDeclarationsWithKeywords &&
IncludeStyle.IncludeBlocks == R.IncludeStyle.IncludeBlocks &&
IncludeStyle.IncludeCategories == R.IncludeStyle.IncludeCategories 
&&
IncludeStyle.IncludeIsMainRegex ==
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 1969f4297b211..dd4297de73ac0 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -349,6 +349,10 @@ bool ContinuationIndenter::canBreak(const LineState 
&State) {
 }
   }
 
+  // Don't break between function parameter keywords and parameter names.
+  if (Previous.is(TT_FunctionParameterKeyword) && Current.is(TT_StartOfName))
+return false;
+
   // Don't allow breaking before a closing brace of a block-indented braced 
list
   // initializer if there isn't already a break.
   if (Current.is(tok::r_brace) && Current.MatchingParen &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index c67db4752e87b..1a7b2871531b9 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -29,6 +29,7 @@
 using clang::format::FormatStyle;
 
 LLVM_YAML_IS_SEQUENCE_VECTOR(FormatStyle::RawStringFormat)
+LLVM_YAML_IS_SEQUENCE_VECTOR(FormatStyle::FunctionDeclarationWithKeywords)
 
 namespace llvm {
 namespace yaml {
@@ -852,6 +853,14 @@ struct ScalarEnumerationTraits<
   }
 };
 
+template <> struct MappingTraits 
{
+  static void mapping(IO &IO,
+  FormatStyle::FunctionDeclarationWithKeywords &Function) {
+IO.mapOptional("Name", Function.Name);
+IO.mapOptional("Keywords", Function.Keywords);
+  }
+};
+
 template <> struct MappingTraits {
   static void mapping(IO &IO, FormatStyle &Style) {
 // When reading, read the language first, we need it for 
getPredefinedStyle.
@@ -1046,6 +1055,8 @@ template <> struct MappingTraits {
Style.ExperimentalAutoDetectBinPacking);
 IO.mapOptional("FixNamespaceComments", Style.FixNamespaceComments);
 IO.mapOptional("ForEachMacros", Style.For

[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-03-27 Thread Eugene Shalygin via cfe-commits

https://github.com/zeule updated 
https://github.com/llvm/llvm-project/pull/131605

>From 4d687d4eabd8e0b5e31f829608d01d390e040630 Mon Sep 17 00:00:00 2001
From: Eugene Shalygin 
Date: Mon, 17 Mar 2025 11:23:35 +0100
Subject: [PATCH] [clang-format] option to control bin-packing keyworded
 parameters

The Q_PROPERTY declaration is almost like a function declaration, but
uses keywords as parameter separators. This allows users to provide list
of those keywords to be used to control bin-packing of the macro
parameters.
---
 clang/docs/ClangFormatStyleOptions.rst| 32 ++
 clang/docs/tools/dump_format_style.py |  1 +
 clang/docs/tools/plurals.txt  |  1 +
 clang/include/clang/Format/Format.h   | 40 +
 clang/lib/Format/ContinuationIndenter.cpp |  4 ++
 clang/lib/Format/Format.cpp   | 11 
 clang/lib/Format/FormatToken.cpp  |  2 +
 clang/lib/Format/FormatToken.h|  1 +
 clang/lib/Format/TokenAnnotator.cpp   | 59 +--
 clang/unittests/Format/ConfigParseTest.cpp| 10 
 clang/unittests/Format/FormatTest.cpp | 59 +++
 clang/unittests/Format/TokenAnnotatorTest.cpp | 33 +++
 12 files changed, 249 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 9ecac68ae72bf..809ad3791a03b 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4740,6 +4740,38 @@ the configuration (without a prefix: ``Auto``).
   replaced with a single newline and form feed followed by the remaining
   newlines.
 
+.. _KeywordedFunctionLikeMacros:
+
+**KeywordedFunctionLikeMacros** (``List of KeywordedFunctionLikeMacros``) 
:versionbadge:`clang-format 21` :ref:`¶ `
+  Allows to format function-like macros with keyworded parameters according
+  to the BinPackParameters setting, treating keywords as parameter
+  sepratators.
+
+  Q_PROPERTY is an example of such a macro:
+
+  .. code-block:: c++
+
+Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+
+  With ``BinPackParameters``  set to ``OnePerLine`` (or
+  ``AlwaysOnePerLine``) and
+
+  .. code-block:: yaml
+
+FunctionDeclarationsWithKeywords:
+- Name: "Q_PROPERTY"
+  Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+
+  the line above will be split on these keywords:
+
+  .. code-block:: c++
+
+Q_PROPERTY(
+int name
+READ name
+WRITE setName
+NOTIFY nameChanged)
+
 .. _LambdaBodyIndentation:
 
 **LambdaBodyIndentation** (``LambdaBodyIndentationKind``) 
:versionbadge:`clang-format 13` :ref:`¶ `
diff --git a/clang/docs/tools/dump_format_style.py 
b/clang/docs/tools/dump_format_style.py
index f035143f6b3d1..85732af8e0a60 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -462,6 +462,7 @@ class State:
 "std::string",
 "std::vector",
 "std::vector",
+"std::vector",
 "std::vector",
 "std::optional",
 "deprecated",
diff --git a/clang/docs/tools/plurals.txt b/clang/docs/tools/plurals.txt
index e20b7f970ba43..bd08c65df1c52 100644
--- a/clang/docs/tools/plurals.txt
+++ b/clang/docs/tools/plurals.txt
@@ -1,3 +1,4 @@
 Strings
 IncludeCategories
+KeywordedFunctionLikeMacros
 RawStringFormats
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index fec47a248abb4..8a8612f6c1c4b 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3146,6 +3146,45 @@ struct FormatStyle {
   /// \version 16
   IntegerLiteralSeparatorStyle IntegerLiteralSeparator;
 
+  /// Function-like declaration with keyworded parameters.
+  /// Lists possible keywords for a named macro-like function
+  struct KeywordedFunctionLikeMacro {
+std::string Name;
+std::vector Keywords;
+
+bool operator==(const KeywordedFunctionLikeMacro &Other) const {
+  return Name == Other.Name && Keywords == Other.Keywords;
+}
+  };
+
+  /// Allows to format function-like macros with keyworded parameters according
+  /// to the BinPackParameters setting, treating keywords as parameter
+  /// sepratators.
+  ///
+  /// Q_PROPERTY is an example of such a macro:
+  /// \code
+  ///   Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+  /// \endcode
+  ///
+  /// With ``BinPackParameters``  set to ``OnePerLine`` (or
+  /// ``AlwaysOnePerLine``) and
+  /// \code{.yaml}
+  ///   FunctionDeclarationsWithKeywords:
+  ///   - Name: "Q_PROPERTY"
+  /// Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+  /// \endcode
+  ///
+  /// the line above will be split on these keywords:
+  /// \code
+  ///   Q_PROPERTY(
+  ///   int name
+  ///   READ name
+  ///   WRITE setName
+  ///   NOTIFY nameChanged)
+  /// \endcode
+  ///

[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-03-27 Thread Eugene Shalygin via cfe-commits

zeule wrote:

I renamed the thing so that it ends with a singular noun, which allows the 
exiting machinery in dump_format_style.py to work, and I like the new name 
better.

https://github.com/llvm/llvm-project/pull/131605
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-03-28 Thread Eugene Shalygin via cfe-commits

zeule wrote:

Thank you, @HazardyKnusperkeks !

https://github.com/llvm/llvm-project/pull/131605
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-03-28 Thread Eugene Shalygin via cfe-commits

https://github.com/zeule updated 
https://github.com/llvm/llvm-project/pull/131605

>From a4b958d62f92616a00449fab04294c91e45aa531 Mon Sep 17 00:00:00 2001
From: Eugene Shalygin 
Date: Mon, 17 Mar 2025 11:23:35 +0100
Subject: [PATCH] [clang-format] option to control bin-packing keyworded
 parameters

The Q_PROPERTY declaration is almost like a function declaration, but
uses keywords as parameter separators. This allows users to provide list
of those keywords to be used to control bin-packing of the macro
parameters.
---
 clang/docs/ClangFormatStyleOptions.rst| 32 ++
 clang/docs/tools/dump_format_style.py |  1 +
 clang/docs/tools/plurals.txt  |  1 +
 clang/include/clang/Format/Format.h   | 40 +
 clang/lib/Format/ContinuationIndenter.cpp |  4 ++
 clang/lib/Format/Format.cpp   | 11 
 clang/lib/Format/FormatToken.cpp  |  2 +
 clang/lib/Format/FormatToken.h|  1 +
 clang/lib/Format/TokenAnnotator.cpp   | 59 +--
 clang/unittests/Format/ConfigParseTest.cpp| 10 
 clang/unittests/Format/FormatTest.cpp | 59 +++
 clang/unittests/Format/TokenAnnotatorTest.cpp | 33 +++
 12 files changed, 249 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 9ecac68ae72bf..d318fc3295c32 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4740,6 +4740,38 @@ the configuration (without a prefix: ``Auto``).
   replaced with a single newline and form feed followed by the remaining
   newlines.
 
+.. _KeywordedFunctionLikeMacros:
+
+**KeywordedFunctionLikeMacros** (``List of KeywordedFunctionLikeMacros``) 
:versionbadge:`clang-format 21` :ref:`¶ `
+  Allows to format function-like macros with keyworded parameters according
+  to the BinPackParameters setting, treating keywords as parameter
+  sepratators.
+
+  Q_PROPERTY is an example of such a macro:
+
+  .. code-block:: c++
+
+Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+
+  With ``BinPackParameters``  set to ``OnePerLine`` (or
+  ``AlwaysOnePerLine``) and
+
+  .. code-block:: yaml
+
+KeywordedFunctionLikeMacros:
+- Name: "Q_PROPERTY"
+  Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+
+  the line above will be split on these keywords:
+
+  .. code-block:: c++
+
+Q_PROPERTY(
+int name
+READ name
+WRITE setName
+NOTIFY nameChanged)
+
 .. _LambdaBodyIndentation:
 
 **LambdaBodyIndentation** (``LambdaBodyIndentationKind``) 
:versionbadge:`clang-format 13` :ref:`¶ `
diff --git a/clang/docs/tools/dump_format_style.py 
b/clang/docs/tools/dump_format_style.py
index f035143f6b3d1..85732af8e0a60 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -462,6 +462,7 @@ class State:
 "std::string",
 "std::vector",
 "std::vector",
+"std::vector",
 "std::vector",
 "std::optional",
 "deprecated",
diff --git a/clang/docs/tools/plurals.txt b/clang/docs/tools/plurals.txt
index e20b7f970ba43..bd08c65df1c52 100644
--- a/clang/docs/tools/plurals.txt
+++ b/clang/docs/tools/plurals.txt
@@ -1,3 +1,4 @@
 Strings
 IncludeCategories
+KeywordedFunctionLikeMacros
 RawStringFormats
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index fec47a248abb4..c36317e8ffcaf 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3276,6 +3276,45 @@ struct FormatStyle {
   /// \version 20
   bool KeepFormFeed;
 
+  /// Function-like declaration with keyworded parameters.
+  /// Lists possible keywords for a named function-like macro.
+  struct KeywordedFunctionLikeMacro {
+std::string Name;
+std::vector Keywords;
+
+bool operator==(const KeywordedFunctionLikeMacro &Other) const {
+  return Name == Other.Name && Keywords == Other.Keywords;
+}
+  };
+
+  /// Allows to format function-like macros with keyworded parameters according
+  /// to the BinPackParameters setting, treating keywords as parameter
+  /// sepratators.
+  ///
+  /// Q_PROPERTY is an example of such a macro:
+  /// \code
+  ///   Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+  /// \endcode
+  ///
+  /// With ``BinPackParameters``  set to ``OnePerLine`` (or
+  /// ``AlwaysOnePerLine``) and
+  /// \code{.yaml}
+  ///   KeywordedFunctionLikeMacros:
+  ///   - Name: "Q_PROPERTY"
+  /// Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+  /// \endcode
+  ///
+  /// the line above will be split on these keywords:
+  /// \code
+  ///   Q_PROPERTY(
+  ///   int name
+  ///   READ name
+  ///   WRITE setName
+  ///   NOTIFY nameChanged)
+  /// \endcode
+  /// \version 21
+  std::vector KeywordedFunctio

[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-03-28 Thread Eugene Shalygin via cfe-commits

https://github.com/zeule updated 
https://github.com/llvm/llvm-project/pull/131605

>From 0402a25b38adab644b4fdb8d7309593940702402 Mon Sep 17 00:00:00 2001
From: Eugene Shalygin 
Date: Mon, 17 Mar 2025 11:23:35 +0100
Subject: [PATCH] [clang-format] option to control bin-packing keyworded
 parameters

The Q_PROPERTY declaration is almost like a function declaration, but
uses keywords as parameter separators. This allows users to provide list
of those keywords to be used to control bin-packing of the macro
parameters.
---
 clang/docs/ClangFormatStyleOptions.rst| 32 ++
 clang/docs/tools/dump_format_style.py |  1 +
 clang/docs/tools/plurals.txt  |  1 +
 clang/include/clang/Format/Format.h   | 40 +
 clang/lib/Format/ContinuationIndenter.cpp |  4 ++
 clang/lib/Format/Format.cpp   | 11 
 clang/lib/Format/FormatToken.cpp  |  2 +
 clang/lib/Format/FormatToken.h|  1 +
 clang/lib/Format/TokenAnnotator.cpp   | 59 +--
 clang/unittests/Format/ConfigParseTest.cpp| 10 
 clang/unittests/Format/FormatTest.cpp | 59 +++
 clang/unittests/Format/TokenAnnotatorTest.cpp | 33 +++
 12 files changed, 249 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 9ecac68ae72bf..d318fc3295c32 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4740,6 +4740,38 @@ the configuration (without a prefix: ``Auto``).
   replaced with a single newline and form feed followed by the remaining
   newlines.
 
+.. _KeywordedFunctionLikeMacros:
+
+**KeywordedFunctionLikeMacros** (``List of KeywordedFunctionLikeMacros``) 
:versionbadge:`clang-format 21` :ref:`¶ `
+  Allows to format function-like macros with keyworded parameters according
+  to the BinPackParameters setting, treating keywords as parameter
+  sepratators.
+
+  Q_PROPERTY is an example of such a macro:
+
+  .. code-block:: c++
+
+Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+
+  With ``BinPackParameters``  set to ``OnePerLine`` (or
+  ``AlwaysOnePerLine``) and
+
+  .. code-block:: yaml
+
+KeywordedFunctionLikeMacros:
+- Name: "Q_PROPERTY"
+  Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+
+  the line above will be split on these keywords:
+
+  .. code-block:: c++
+
+Q_PROPERTY(
+int name
+READ name
+WRITE setName
+NOTIFY nameChanged)
+
 .. _LambdaBodyIndentation:
 
 **LambdaBodyIndentation** (``LambdaBodyIndentationKind``) 
:versionbadge:`clang-format 13` :ref:`¶ `
diff --git a/clang/docs/tools/dump_format_style.py 
b/clang/docs/tools/dump_format_style.py
index f035143f6b3d1..85732af8e0a60 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -462,6 +462,7 @@ class State:
 "std::string",
 "std::vector",
 "std::vector",
+"std::vector",
 "std::vector",
 "std::optional",
 "deprecated",
diff --git a/clang/docs/tools/plurals.txt b/clang/docs/tools/plurals.txt
index e20b7f970ba43..bd08c65df1c52 100644
--- a/clang/docs/tools/plurals.txt
+++ b/clang/docs/tools/plurals.txt
@@ -1,3 +1,4 @@
 Strings
 IncludeCategories
+KeywordedFunctionLikeMacros
 RawStringFormats
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index fec47a248abb4..5ba27adb053a3 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3276,6 +3276,45 @@ struct FormatStyle {
   /// \version 20
   bool KeepFormFeed;
 
+  /// Function-like declaration with keyworded parameters.
+  /// Lists possible keywords for a named function-like macro.
+  struct KeywordedFunctionLikeMacro {
+std::string Name;
+std::vector Keywords;
+
+bool operator==(const KeywordedFunctionLikeMacro &Other) const {
+  return Name == Other.Name && Keywords == Other.Keywords;
+}
+  };
+
+  /// Allows to format function-like macros with keyworded parameters according
+  /// to the BinPackParameters setting, treating keywords as parameter
+  /// separators.
+  ///
+  /// Q_PROPERTY is an example of such a macro:
+  /// \code
+  ///   Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+  /// \endcode
+  ///
+  /// With ``BinPackParameters``  set to ``OnePerLine`` (or
+  /// ``AlwaysOnePerLine``) and
+  /// \code{.yaml}
+  ///   KeywordedFunctionLikeMacros:
+  ///   - Name: "Q_PROPERTY"
+  /// Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+  /// \endcode
+  ///
+  /// the line above will be split on these keywords:
+  /// \code
+  ///   Q_PROPERTY(
+  ///   int name
+  ///   READ name
+  ///   WRITE setName
+  ///   NOTIFY nameChanged)
+  /// \endcode
+  /// \version 21
+  std::vector KeywordedFunction

[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-03-28 Thread Eugene Shalygin via cfe-commits

zeule wrote:

I hope it is clean now.

https://github.com/llvm/llvm-project/pull/131605
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-03-31 Thread Eugene Shalygin via cfe-commits

https://github.com/zeule updated 
https://github.com/llvm/llvm-project/pull/131605

>From 58eb85b45f56142f36686d2a1499deb2e7736eb6 Mon Sep 17 00:00:00 2001
From: Eugene Shalygin 
Date: Mon, 17 Mar 2025 11:23:35 +0100
Subject: [PATCH] [clang-format] option to control bin-packing keyworded
 parameters

The Q_PROPERTY declaration is almost like a function declaration, but
uses keywords as parameter separators. This allows users to provide list
of those keywords to be used to control bin-packing of the macro
parameters.
---
 clang/docs/ClangFormatStyleOptions.rst| 32 ++
 clang/docs/ReleaseNotes.rst   |  2 +
 clang/docs/tools/dump_format_style.py |  1 +
 clang/docs/tools/plurals.txt  |  1 +
 clang/include/clang/Format/Format.h   | 40 +
 clang/lib/Format/ContinuationIndenter.cpp |  4 ++
 clang/lib/Format/Format.cpp   | 11 
 clang/lib/Format/FormatToken.cpp  |  2 +
 clang/lib/Format/FormatToken.h|  1 +
 clang/lib/Format/TokenAnnotator.cpp   | 47 ++-
 clang/unittests/Format/ConfigParseTest.cpp| 10 
 clang/unittests/Format/FormatTest.cpp | 59 +++
 clang/unittests/Format/TokenAnnotatorTest.cpp | 34 +++
 13 files changed, 241 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 3f8a5f49313b2..d61bafc1b4dd0 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4781,6 +4781,38 @@ the configuration (without a prefix: ``Auto``).
   replaced with a single newline and form feed followed by the remaining
   newlines.
 
+.. _KeywordedFunctionLikeMacros:
+
+**KeywordedFunctionLikeMacros** (``List of KeywordedFunctionLikeMacros``) 
:versionbadge:`clang-format 21` :ref:`¶ `
+  Allows to format function-like macros with keyworded parameters according
+  to the BinPackParameters setting, treating keywords as parameter
+  separators.
+
+  Q_PROPERTY is an example of such a macro:
+
+  .. code-block:: c++
+
+Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+
+  With ``BinPackParameters``  set to ``OnePerLine`` (or
+  ``AlwaysOnePerLine``) and
+
+  .. code-block:: yaml
+
+KeywordedFunctionLikeMacros:
+- Name: "Q_PROPERTY"
+  Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+
+  the line above will be split on these keywords:
+
+  .. code-block:: c++
+
+Q_PROPERTY(
+int name
+READ name
+WRITE setName
+NOTIFY nameChanged)
+
 .. _LambdaBodyIndentation:
 
 **LambdaBodyIndentation** (``LambdaBodyIndentationKind``) 
:versionbadge:`clang-format 13` :ref:`¶ `
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index daad01919ecd4..cce9c6d128089 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -498,6 +498,8 @@ clang-format
   top of the file.
 - Add ``EnumTrailingComma`` option for inserting/removing commas at the end of
   ``enum`` enumerator lists.
+- Allow to apply parameters bin-packing options to function-like macros that
+  use keywords to delimit parameters (e.g. Q_PROPERTY).
 
 libclang
 
diff --git a/clang/docs/tools/dump_format_style.py 
b/clang/docs/tools/dump_format_style.py
index f035143f6b3d1..85732af8e0a60 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -462,6 +462,7 @@ class State:
 "std::string",
 "std::vector",
 "std::vector",
+"std::vector",
 "std::vector",
 "std::optional",
 "deprecated",
diff --git a/clang/docs/tools/plurals.txt b/clang/docs/tools/plurals.txt
index e20b7f970ba43..bd08c65df1c52 100644
--- a/clang/docs/tools/plurals.txt
+++ b/clang/docs/tools/plurals.txt
@@ -1,3 +1,4 @@
 Strings
 IncludeCategories
+KeywordedFunctionLikeMacros
 RawStringFormats
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index cea5e257659d6..846e5a8f7f94b 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3309,6 +3309,45 @@ struct FormatStyle {
   /// \version 20
   bool KeepFormFeed;
 
+  /// Function-like declaration with keyworded parameters.
+  /// Lists possible keywords for a named function-like macro.
+  struct KeywordedFunctionLikeMacro {
+std::string Name;
+std::vector Keywords;
+
+bool operator==(const KeywordedFunctionLikeMacro &Other) const {
+  return Name == Other.Name && Keywords == Other.Keywords;
+}
+  };
+
+  /// Allows to format function-like macros with keyworded parameters according
+  /// to the BinPackParameters setting, treating keywords as parameter
+  /// separators.
+  ///
+  /// Q_PROPERTY is an example of such a macro:
+  /// \code
+  ///   Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+  /// 

[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-04-05 Thread Eugene Shalygin via cfe-commits

https://github.com/zeule updated 
https://github.com/llvm/llvm-project/pull/131605

>From 352742af34d52dd265cc01ff47ca73047aa423e5 Mon Sep 17 00:00:00 2001
From: Eugene Shalygin 
Date: Mon, 17 Mar 2025 11:23:35 +0100
Subject: [PATCH] [clang-format] option to control bin-packing keyworded
 parameters

The Q_PROPERTY declaration is almost like a function declaration, but
uses keywords as parameter separators. This allows users to provide list
of those keywords to be used to control bin-packing of the macro
parameters.
---
 clang/docs/ClangFormatStyleOptions.rst| 32 ++
 clang/docs/ReleaseNotes.rst   |  2 +
 clang/docs/tools/dump_format_style.py |  1 +
 clang/docs/tools/plurals.txt  |  1 +
 clang/include/clang/Format/Format.h   | 40 +
 clang/lib/Format/ContinuationIndenter.cpp |  4 ++
 clang/lib/Format/Format.cpp   | 11 
 clang/lib/Format/FormatToken.cpp  |  2 +
 clang/lib/Format/FormatToken.h|  1 +
 clang/lib/Format/TokenAnnotator.cpp   | 47 ++-
 clang/unittests/Format/ConfigParseTest.cpp| 10 
 clang/unittests/Format/FormatTest.cpp | 59 +++
 clang/unittests/Format/TokenAnnotatorTest.cpp | 33 +++
 13 files changed, 240 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 3f8a5f49313b2..d61bafc1b4dd0 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4781,6 +4781,38 @@ the configuration (without a prefix: ``Auto``).
   replaced with a single newline and form feed followed by the remaining
   newlines.
 
+.. _KeywordedFunctionLikeMacros:
+
+**KeywordedFunctionLikeMacros** (``List of KeywordedFunctionLikeMacros``) 
:versionbadge:`clang-format 21` :ref:`¶ `
+  Allows to format function-like macros with keyworded parameters according
+  to the BinPackParameters setting, treating keywords as parameter
+  separators.
+
+  Q_PROPERTY is an example of such a macro:
+
+  .. code-block:: c++
+
+Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+
+  With ``BinPackParameters``  set to ``OnePerLine`` (or
+  ``AlwaysOnePerLine``) and
+
+  .. code-block:: yaml
+
+KeywordedFunctionLikeMacros:
+- Name: "Q_PROPERTY"
+  Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+
+  the line above will be split on these keywords:
+
+  .. code-block:: c++
+
+Q_PROPERTY(
+int name
+READ name
+WRITE setName
+NOTIFY nameChanged)
+
 .. _LambdaBodyIndentation:
 
 **LambdaBodyIndentation** (``LambdaBodyIndentationKind``) 
:versionbadge:`clang-format 13` :ref:`¶ `
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c4e82678949ff..3b9c584410864 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -515,6 +515,8 @@ clang-format
   top of the file.
 - Add ``EnumTrailingComma`` option for inserting/removing commas at the end of
   ``enum`` enumerator lists.
+- Allow to apply parameters bin-packing options to function-like macros that
+  use keywords to delimit parameters (e.g. Q_PROPERTY).
 
 libclang
 
diff --git a/clang/docs/tools/dump_format_style.py 
b/clang/docs/tools/dump_format_style.py
index f035143f6b3d1..85732af8e0a60 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -462,6 +462,7 @@ class State:
 "std::string",
 "std::vector",
 "std::vector",
+"std::vector",
 "std::vector",
 "std::optional",
 "deprecated",
diff --git a/clang/docs/tools/plurals.txt b/clang/docs/tools/plurals.txt
index e20b7f970ba43..bd08c65df1c52 100644
--- a/clang/docs/tools/plurals.txt
+++ b/clang/docs/tools/plurals.txt
@@ -1,3 +1,4 @@
 Strings
 IncludeCategories
+KeywordedFunctionLikeMacros
 RawStringFormats
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index cea5e257659d6..846e5a8f7f94b 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3309,6 +3309,45 @@ struct FormatStyle {
   /// \version 20
   bool KeepFormFeed;
 
+  /// Function-like declaration with keyworded parameters.
+  /// Lists possible keywords for a named function-like macro.
+  struct KeywordedFunctionLikeMacro {
+std::string Name;
+std::vector Keywords;
+
+bool operator==(const KeywordedFunctionLikeMacro &Other) const {
+  return Name == Other.Name && Keywords == Other.Keywords;
+}
+  };
+
+  /// Allows to format function-like macros with keyworded parameters according
+  /// to the BinPackParameters setting, treating keywords as parameter
+  /// separators.
+  ///
+  /// Q_PROPERTY is an example of such a macro:
+  /// \code
+  ///   Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+  /// 

[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-04-05 Thread Eugene Shalygin via cfe-commits

https://github.com/zeule updated 
https://github.com/llvm/llvm-project/pull/131605

>From 7d79e05ec1a6086c85f73d087ac1667fc0246d22 Mon Sep 17 00:00:00 2001
From: Eugene Shalygin 
Date: Mon, 17 Mar 2025 11:23:35 +0100
Subject: [PATCH] [clang-format] option to control bin-packing keyworded
 parameters

The Q_PROPERTY declaration is almost like a function declaration, but
uses keywords as parameter separators. This allows users to provide list
of those keywords to be used to control bin-packing of the macro
parameters.
---
 clang/docs/ClangFormatStyleOptions.rst| 32 ++
 clang/docs/tools/dump_format_style.py |  1 +
 clang/docs/tools/plurals.txt  |  1 +
 clang/include/clang/Format/Format.h   | 40 +
 clang/lib/Format/ContinuationIndenter.cpp |  4 ++
 clang/lib/Format/Format.cpp   | 11 
 clang/lib/Format/FormatToken.cpp  |  2 +
 clang/lib/Format/FormatToken.h|  1 +
 clang/lib/Format/TokenAnnotator.cpp   | 47 ++-
 clang/unittests/Format/ConfigParseTest.cpp| 10 
 clang/unittests/Format/FormatTest.cpp | 59 +++
 clang/unittests/Format/TokenAnnotatorTest.cpp | 33 +++
 12 files changed, 238 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 9ecac68ae72bf..8723458e7b986 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4740,6 +4740,38 @@ the configuration (without a prefix: ``Auto``).
   replaced with a single newline and form feed followed by the remaining
   newlines.
 
+.. _KeywordedFunctionLikeMacros:
+
+**KeywordedFunctionLikeMacros** (``List of KeywordedFunctionLikeMacros``) 
:versionbadge:`clang-format 21` :ref:`¶ `
+  Allows to format function-like macros with keyworded parameters according
+  to the BinPackParameters setting, treating keywords as parameter
+  separators.
+
+  Q_PROPERTY is an example of such a macro:
+
+  .. code-block:: c++
+
+Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+
+  With ``BinPackParameters``  set to ``OnePerLine`` (or
+  ``AlwaysOnePerLine``) and
+
+  .. code-block:: yaml
+
+KeywordedFunctionLikeMacros:
+- Name: "Q_PROPERTY"
+  Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+
+  the line above will be split on these keywords:
+
+  .. code-block:: c++
+
+Q_PROPERTY(
+int name
+READ name
+WRITE setName
+NOTIFY nameChanged)
+
 .. _LambdaBodyIndentation:
 
 **LambdaBodyIndentation** (``LambdaBodyIndentationKind``) 
:versionbadge:`clang-format 13` :ref:`¶ `
diff --git a/clang/docs/tools/dump_format_style.py 
b/clang/docs/tools/dump_format_style.py
index f035143f6b3d1..85732af8e0a60 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -462,6 +462,7 @@ class State:
 "std::string",
 "std::vector",
 "std::vector",
+"std::vector",
 "std::vector",
 "std::optional",
 "deprecated",
diff --git a/clang/docs/tools/plurals.txt b/clang/docs/tools/plurals.txt
index e20b7f970ba43..bd08c65df1c52 100644
--- a/clang/docs/tools/plurals.txt
+++ b/clang/docs/tools/plurals.txt
@@ -1,3 +1,4 @@
 Strings
 IncludeCategories
+KeywordedFunctionLikeMacros
 RawStringFormats
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index fec47a248abb4..5ba27adb053a3 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3276,6 +3276,45 @@ struct FormatStyle {
   /// \version 20
   bool KeepFormFeed;
 
+  /// Function-like declaration with keyworded parameters.
+  /// Lists possible keywords for a named function-like macro.
+  struct KeywordedFunctionLikeMacro {
+std::string Name;
+std::vector Keywords;
+
+bool operator==(const KeywordedFunctionLikeMacro &Other) const {
+  return Name == Other.Name && Keywords == Other.Keywords;
+}
+  };
+
+  /// Allows to format function-like macros with keyworded parameters according
+  /// to the BinPackParameters setting, treating keywords as parameter
+  /// separators.
+  ///
+  /// Q_PROPERTY is an example of such a macro:
+  /// \code
+  ///   Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+  /// \endcode
+  ///
+  /// With ``BinPackParameters``  set to ``OnePerLine`` (or
+  /// ``AlwaysOnePerLine``) and
+  /// \code{.yaml}
+  ///   KeywordedFunctionLikeMacros:
+  ///   - Name: "Q_PROPERTY"
+  /// Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+  /// \endcode
+  ///
+  /// the line above will be split on these keywords:
+  /// \code
+  ///   Q_PROPERTY(
+  ///   int name
+  ///   READ name
+  ///   WRITE setName
+  ///   NOTIFY nameChanged)
+  /// \endcode
+  /// \version 21
+  std::vector KeywordedFunctionLikeM

[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-04-05 Thread Eugene Shalygin via cfe-commits

https://github.com/zeule edited https://github.com/llvm/llvm-project/pull/131605
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-04-05 Thread Eugene Shalygin via cfe-commits


@@ -498,6 +498,8 @@ clang-format
   top of the file.
 - Add ``EnumTrailingComma`` option for inserting/removing commas at the end of
   ``enum`` enumerator lists.
+- Allow to apply parameters bin-packing options to function-like macros that
+  use keywords to delimit parameters (e.g. Q_OBJECT).

zeule wrote:

Thanks!

https://github.com/llvm/llvm-project/pull/131605
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-04-05 Thread Eugene Shalygin via cfe-commits

zeule wrote:

>  IMO, a boolean option, e.g. `AllowBreakBeforeQPropertyKeyword` should 
> suffice.

I don't like to hardcode neither the macro name nor the keywords, which depend 
on Qt version. Implementation would not differ save for the source we fetch 
keywords from.


https://github.com/llvm/llvm-project/pull/131605
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits