[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
gedare wrote: Review comments addressed. Nice splitting of the test case. https://github.com/llvm/llvm-project/pull/112482 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
https://github.com/gedare updated
https://github.com/llvm/llvm-project/pull/112482
>From 8282f754ae40b64a88e2d22a6cb21e7028da8371 Mon Sep 17 00:00:00 2001
From: Gedare Bloom
Date: Tue, 15 Oct 2024 23:55:49 -0600
Subject: [PATCH 1/7] [clang-format] add BinPackLongBracedList style option
The use of Cpp11BracedListStyle with BinPackParameters=False
avoids bin packing until reaching a hard-coded limit of 20 items.
This is an arbitrary choice. Introduce a new style option to
allow disabling this limit.
---
clang/include/clang/Format/Format.h| 20 +
clang/lib/Format/Format.cpp| 2 ++
clang/lib/Format/FormatToken.cpp | 2 +-
clang/unittests/Format/ConfigParseTest.cpp | 1 +
clang/unittests/Format/FormatTest.cpp | 26 ++
5 files changed, 50 insertions(+), 1 deletion(-)
diff --git a/clang/include/clang/Format/Format.h
b/clang/include/clang/Format/Format.h
index fbc9291ae950d41..476d9d4cf4ba1cb 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1212,6 +1212,22 @@ struct FormatStyle {
/// \version 3.7
bool BinPackArguments;
+ /// If ``BinPackLongBracedLists`` is ``true`` it overrides
+ /// ``BinPackArguments`` if there are 20 or more items in a braced
+ /// initializer list.
+ /// \code
+ ///BinPackLongBracedLists: false vs. BinPackLongBracedLists: true
+ ///vector x{ vector x{1, 2, ...,
+ /// 20, 21};
+ ///1,
+ ///2,
+ ///...,
+ ///20,
+ ///21};
+ /// \endcode
+ /// \version 21
+ bool BinPackLongBracedLists;
+
/// Different way to try to fit all parameters on a line.
enum BinPackParametersStyle : int8_t {
/// Bin-pack parameters.
@@ -2547,6 +2563,9 @@ struct FormatStyle {
/// (e.g. a type or variable name), clang-format formats as if the ``{}``
were
/// the parentheses of a function call with that name. If there is no name,
/// a zero-length name is assumed.
+ ///
+ /// ``BinPackArguments`` may be forced to true for initializer lists with
+ /// more than 20 items if ``BinPackLongBracedLists`` is true.
/// \code
///true: false:
///vector x{1, 2, 3, 4}; vs. vector x{ 1, 2, 3, 4 };
@@ -5266,6 +5285,7 @@ struct FormatStyle {
R.AlwaysBreakBeforeMultilineStrings &&
AttributeMacros == R.AttributeMacros &&
BinPackArguments == R.BinPackArguments &&
+ BinPackLongBracedLists == R.BinPackLongBracedLists &&
BinPackParameters == R.BinPackParameters &&
BitFieldColonSpacing == R.BitFieldColonSpacing &&
BracedInitializerIndentWidth == R.BracedInitializerIndentWidth &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 387daad934f67ac..b9dd541a3dda2a6 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -995,6 +995,7 @@ template <> struct MappingTraits {
Style.AlwaysBreakBeforeMultilineStrings);
IO.mapOptional("AttributeMacros", Style.AttributeMacros);
IO.mapOptional("BinPackArguments", Style.BinPackArguments);
+IO.mapOptional("BinPackLongBracedLists", Style.BinPackLongBracedLists);
IO.mapOptional("BinPackParameters", Style.BinPackParameters);
IO.mapOptional("BitFieldColonSpacing", Style.BitFieldColonSpacing);
IO.mapOptional("BracedInitializerIndentWidth",
@@ -1507,6 +1508,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind
Language) {
LLVMStyle.AlwaysBreakBeforeMultilineStrings = false;
LLVMStyle.AttributeMacros.push_back("__capability");
LLVMStyle.BinPackArguments = true;
+ LLVMStyle.BinPackLongBracedLists = true;
LLVMStyle.BinPackParameters = FormatStyle::BPPS_BinPack;
LLVMStyle.BitFieldColonSpacing = FormatStyle::BFCS_Both;
LLVMStyle.BracedInitializerIndentWidth = std::nullopt;
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 99bce1f5f09851e..239781129d7b96f 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -175,7 +175,7 @@ void CommaSeparatedList::precomputeFormattingInfos(const
FormatToken *Token) {
// have many items (20 or more) or we allow bin-packing of function call
// arguments.
if (Style.Cpp11BracedListStyle && !Style.BinPackArguments &&
- Commas.size() < 19) {
+ (Commas.size() < 19 || !Style.BinPackLongBracedLists)) {
return;
}
diff --git a/clang/unittests/Format/ConfigParseTest.cpp
b/clang/unittests/Format/ConfigParseTest.cpp
index 0cb2a1288bfd7ec..1ebc1ac2faa817a 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -168,6 +168,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
CHECK_PARSE_BOOL(AllowShortLoopsOnASingleLine);
CHECK_PARSE_BOOL(AllowSho
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
https://github.com/gedare updated
https://github.com/llvm/llvm-project/pull/112482
>From 8282f754ae40b64a88e2d22a6cb21e7028da8371 Mon Sep 17 00:00:00 2001
From: Gedare Bloom
Date: Tue, 15 Oct 2024 23:55:49 -0600
Subject: [PATCH 1/6] [clang-format] add BinPackLongBracedList style option
The use of Cpp11BracedListStyle with BinPackParameters=False
avoids bin packing until reaching a hard-coded limit of 20 items.
This is an arbitrary choice. Introduce a new style option to
allow disabling this limit.
---
clang/include/clang/Format/Format.h| 20 +
clang/lib/Format/Format.cpp| 2 ++
clang/lib/Format/FormatToken.cpp | 2 +-
clang/unittests/Format/ConfigParseTest.cpp | 1 +
clang/unittests/Format/FormatTest.cpp | 26 ++
5 files changed, 50 insertions(+), 1 deletion(-)
diff --git a/clang/include/clang/Format/Format.h
b/clang/include/clang/Format/Format.h
index fbc9291ae950d41..476d9d4cf4ba1cb 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1212,6 +1212,22 @@ struct FormatStyle {
/// \version 3.7
bool BinPackArguments;
+ /// If ``BinPackLongBracedLists`` is ``true`` it overrides
+ /// ``BinPackArguments`` if there are 20 or more items in a braced
+ /// initializer list.
+ /// \code
+ ///BinPackLongBracedLists: false vs. BinPackLongBracedLists: true
+ ///vector x{ vector x{1, 2, ...,
+ /// 20, 21};
+ ///1,
+ ///2,
+ ///...,
+ ///20,
+ ///21};
+ /// \endcode
+ /// \version 21
+ bool BinPackLongBracedLists;
+
/// Different way to try to fit all parameters on a line.
enum BinPackParametersStyle : int8_t {
/// Bin-pack parameters.
@@ -2547,6 +2563,9 @@ struct FormatStyle {
/// (e.g. a type or variable name), clang-format formats as if the ``{}``
were
/// the parentheses of a function call with that name. If there is no name,
/// a zero-length name is assumed.
+ ///
+ /// ``BinPackArguments`` may be forced to true for initializer lists with
+ /// more than 20 items if ``BinPackLongBracedLists`` is true.
/// \code
///true: false:
///vector x{1, 2, 3, 4}; vs. vector x{ 1, 2, 3, 4 };
@@ -5266,6 +5285,7 @@ struct FormatStyle {
R.AlwaysBreakBeforeMultilineStrings &&
AttributeMacros == R.AttributeMacros &&
BinPackArguments == R.BinPackArguments &&
+ BinPackLongBracedLists == R.BinPackLongBracedLists &&
BinPackParameters == R.BinPackParameters &&
BitFieldColonSpacing == R.BitFieldColonSpacing &&
BracedInitializerIndentWidth == R.BracedInitializerIndentWidth &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 387daad934f67ac..b9dd541a3dda2a6 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -995,6 +995,7 @@ template <> struct MappingTraits {
Style.AlwaysBreakBeforeMultilineStrings);
IO.mapOptional("AttributeMacros", Style.AttributeMacros);
IO.mapOptional("BinPackArguments", Style.BinPackArguments);
+IO.mapOptional("BinPackLongBracedLists", Style.BinPackLongBracedLists);
IO.mapOptional("BinPackParameters", Style.BinPackParameters);
IO.mapOptional("BitFieldColonSpacing", Style.BitFieldColonSpacing);
IO.mapOptional("BracedInitializerIndentWidth",
@@ -1507,6 +1508,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind
Language) {
LLVMStyle.AlwaysBreakBeforeMultilineStrings = false;
LLVMStyle.AttributeMacros.push_back("__capability");
LLVMStyle.BinPackArguments = true;
+ LLVMStyle.BinPackLongBracedLists = true;
LLVMStyle.BinPackParameters = FormatStyle::BPPS_BinPack;
LLVMStyle.BitFieldColonSpacing = FormatStyle::BFCS_Both;
LLVMStyle.BracedInitializerIndentWidth = std::nullopt;
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 99bce1f5f09851e..239781129d7b96f 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -175,7 +175,7 @@ void CommaSeparatedList::precomputeFormattingInfos(const
FormatToken *Token) {
// have many items (20 or more) or we allow bin-packing of function call
// arguments.
if (Style.Cpp11BracedListStyle && !Style.BinPackArguments &&
- Commas.size() < 19) {
+ (Commas.size() < 19 || !Style.BinPackLongBracedLists)) {
return;
}
diff --git a/clang/unittests/Format/ConfigParseTest.cpp
b/clang/unittests/Format/ConfigParseTest.cpp
index 0cb2a1288bfd7ec..1ebc1ac2faa817a 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -168,6 +168,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
CHECK_PARSE_BOOL(AllowShortLoopsOnASingleLine);
CHECK_PARSE_BOOL(AllowSho
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
https://github.com/gedare updated
https://github.com/llvm/llvm-project/pull/112482
>From 8282f754ae40b64a88e2d22a6cb21e7028da8371 Mon Sep 17 00:00:00 2001
From: Gedare Bloom
Date: Tue, 15 Oct 2024 23:55:49 -0600
Subject: [PATCH 1/4] [clang-format] add BinPackLongBracedList style option
The use of Cpp11BracedListStyle with BinPackParameters=False
avoids bin packing until reaching a hard-coded limit of 20 items.
This is an arbitrary choice. Introduce a new style option to
allow disabling this limit.
---
clang/include/clang/Format/Format.h| 20 +
clang/lib/Format/Format.cpp| 2 ++
clang/lib/Format/FormatToken.cpp | 2 +-
clang/unittests/Format/ConfigParseTest.cpp | 1 +
clang/unittests/Format/FormatTest.cpp | 26 ++
5 files changed, 50 insertions(+), 1 deletion(-)
diff --git a/clang/include/clang/Format/Format.h
b/clang/include/clang/Format/Format.h
index fbc9291ae950d41..476d9d4cf4ba1cb 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1212,6 +1212,22 @@ struct FormatStyle {
/// \version 3.7
bool BinPackArguments;
+ /// If ``BinPackLongBracedLists`` is ``true`` it overrides
+ /// ``BinPackArguments`` if there are 20 or more items in a braced
+ /// initializer list.
+ /// \code
+ ///BinPackLongBracedLists: false vs. BinPackLongBracedLists: true
+ ///vector x{ vector x{1, 2, ...,
+ /// 20, 21};
+ ///1,
+ ///2,
+ ///...,
+ ///20,
+ ///21};
+ /// \endcode
+ /// \version 21
+ bool BinPackLongBracedLists;
+
/// Different way to try to fit all parameters on a line.
enum BinPackParametersStyle : int8_t {
/// Bin-pack parameters.
@@ -2547,6 +2563,9 @@ struct FormatStyle {
/// (e.g. a type or variable name), clang-format formats as if the ``{}``
were
/// the parentheses of a function call with that name. If there is no name,
/// a zero-length name is assumed.
+ ///
+ /// ``BinPackArguments`` may be forced to true for initializer lists with
+ /// more than 20 items if ``BinPackLongBracedLists`` is true.
/// \code
///true: false:
///vector x{1, 2, 3, 4}; vs. vector x{ 1, 2, 3, 4 };
@@ -5266,6 +5285,7 @@ struct FormatStyle {
R.AlwaysBreakBeforeMultilineStrings &&
AttributeMacros == R.AttributeMacros &&
BinPackArguments == R.BinPackArguments &&
+ BinPackLongBracedLists == R.BinPackLongBracedLists &&
BinPackParameters == R.BinPackParameters &&
BitFieldColonSpacing == R.BitFieldColonSpacing &&
BracedInitializerIndentWidth == R.BracedInitializerIndentWidth &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 387daad934f67ac..b9dd541a3dda2a6 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -995,6 +995,7 @@ template <> struct MappingTraits {
Style.AlwaysBreakBeforeMultilineStrings);
IO.mapOptional("AttributeMacros", Style.AttributeMacros);
IO.mapOptional("BinPackArguments", Style.BinPackArguments);
+IO.mapOptional("BinPackLongBracedLists", Style.BinPackLongBracedLists);
IO.mapOptional("BinPackParameters", Style.BinPackParameters);
IO.mapOptional("BitFieldColonSpacing", Style.BitFieldColonSpacing);
IO.mapOptional("BracedInitializerIndentWidth",
@@ -1507,6 +1508,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind
Language) {
LLVMStyle.AlwaysBreakBeforeMultilineStrings = false;
LLVMStyle.AttributeMacros.push_back("__capability");
LLVMStyle.BinPackArguments = true;
+ LLVMStyle.BinPackLongBracedLists = true;
LLVMStyle.BinPackParameters = FormatStyle::BPPS_BinPack;
LLVMStyle.BitFieldColonSpacing = FormatStyle::BFCS_Both;
LLVMStyle.BracedInitializerIndentWidth = std::nullopt;
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 99bce1f5f09851e..239781129d7b96f 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -175,7 +175,7 @@ void CommaSeparatedList::precomputeFormattingInfos(const
FormatToken *Token) {
// have many items (20 or more) or we allow bin-packing of function call
// arguments.
if (Style.Cpp11BracedListStyle && !Style.BinPackArguments &&
- Commas.size() < 19) {
+ (Commas.size() < 19 || !Style.BinPackLongBracedLists)) {
return;
}
diff --git a/clang/unittests/Format/ConfigParseTest.cpp
b/clang/unittests/Format/ConfigParseTest.cpp
index 0cb2a1288bfd7ec..1ebc1ac2faa817a 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -168,6 +168,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
CHECK_PARSE_BOOL(AllowShortLoopsOnASingleLine);
CHECK_PARSE_BOOL(AllowSho
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
@@ -14185,6 +14185,32 @@ TEST_F(FormatTest, LayoutCxx11BraceInitializers) {
"ff, g, hh, ii, jj, kk,\n"
"};",
NoBinPacking);
+ NoBinPacking.BinPackLongBracedLists = false;
+ verifyFormat("const Aa a = {\n"
+ "a,\n"
+ "b,\n"
+ "c,\n"
+ "d,\n"
+ "e,\n"
+ "ff,\n"
+ "g,\n"
+ "hh,\n"
+ "ii,\n"
+ "jj,\n"
+ "kk,\n"
+ "a,\n"
+ "b,\n"
+ "c,\n"
+ "d,\n"
+ "e,\n"
+ "ff,\n"
+ "g,\n"
+ "hh,\n"
+ "ii,\n"
+ "jj,\n"
+ "kk,\n"
+ "};",
+ NoBinPacking);
owenca wrote:
```suggestion
verifyFormat("const Aa a = {a,\n"
" b,\n"
" c,\n"
" d,\n"
" e,\n"
" ff,\n"
" g,\n"
" hh,\n"
" ii,\n"
" jj,\n"
" kk,\n"
" a,\n"
" b,\n"
" c,\n"
" d,\n"
" e,\n"
" ff,\n"
" g,\n"
" hh,\n"
" ii};",
NoBinPacking);
```
https://github.com/llvm/llvm-project/pull/112482
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
@@ -14185,6 +14185,32 @@ TEST_F(FormatTest, LayoutCxx11BraceInitializers) {
"ff, g, hh, ii, jj, kk,\n"
"};",
NoBinPacking);
+ NoBinPacking.BinPackLongBracedLists = false;
+ verifyFormat("const Aa a = {\n"
+ "a,\n"
+ "b,\n"
+ "c,\n"
+ "d,\n"
+ "e,\n"
+ "ff,\n"
+ "g,\n"
+ "hh,\n"
+ "ii,\n"
+ "jj,\n"
+ "kk,\n"
+ "a,\n"
+ "b,\n"
+ "c,\n"
+ "d,\n"
+ "e,\n"
+ "ff,\n"
+ "g,\n"
+ "hh,\n"
+ "ii,\n"
+ "jj,\n"
+ "kk,\n"
owenca wrote:
```suggestion
```
https://github.com/llvm/llvm-project/pull/112482
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
@@ -1212,6 +1212,22 @@ struct FormatStyle {
/// \version 3.7
bool BinPackArguments;
+ /// If ``BinPackLongBracedLists`` is ``true`` it overrides
+ /// ``BinPackArguments`` if there are 20 or more items in a braced
+ /// initializer list.
+ /// \code
+ ///BinPackLongBracedLists: false vs. BinPackLongBracedLists: true
+ ///vector x{ vector x{1, 2, ...,
+ /// 20, 21};
+ ///1,
+ ///2,
+ ///...,
+ ///20,
+ ///21};
+ /// \endcode
+ /// \version 21
+ bool BinPackLongBracedLists;
owenca wrote:
```suggestion
bool BinPackLongBracedList;
```
https://github.com/llvm/llvm-project/pull/112482
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
@@ -14185,6 +14185,32 @@ TEST_F(FormatTest, LayoutCxx11BraceInitializers) {
"ff, g, hh, ii, jj, kk,\n"
"};",
NoBinPacking);
+ NoBinPacking.BinPackLongBracedLists = false;
owenca wrote:
```suggestion
NoBinPacking.BinPackLongBracedLists = false;
```
https://github.com/llvm/llvm-project/pull/112482
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
@@ -2520,6 +2536,9 @@ struct FormatStyle {
/// (e.g. a type or variable name), clang-format formats as if the ``{}``
were
/// the parentheses of a function call with that name. If there is no name,
/// a zero-length name is assumed.
+ ///
+ /// ``BinPackArguments`` may be forced to true for initializer lists with
+ /// more than 20 items if ``BinPackLongBracedLists`` is true.
owenca wrote:
```suggestion
```
IMO, it only adds to the confusion.
https://github.com/llvm/llvm-project/pull/112482
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
gedare wrote: > What about changing it to an option (e.g. `BinPackBracedListThreshold`) with > a default value of about 20? If the number of elements in the list is more > than the threshold, they will be bin packed even if `BinPackArguments` is set > to false. That was my original approach, but it is (marginally) more complex without a lot of obvious benefit to me, and it doesn't work well for small values, see https://github.com/llvm/llvm-project/pull/112482#issuecomment-2439664106 Since I did not find an open Issue about this topic, I leaned toward the less complex way of just allowing to enable/disable the currently hard-coded limit. I can make it a threshold instead, but I don't really want to find and fix the bugs that reveals. https://github.com/llvm/llvm-project/pull/112482 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
owenca wrote: What about changing it to an option (e.g. `BinPackBracedListThreshold`) with a default value of about 20? If the number of elements in the list is more than the threshold, they will be bin packed even if `BinPackArguments` is set to false. https://github.com/llvm/llvm-project/pull/112482 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
https://github.com/gedare updated
https://github.com/llvm/llvm-project/pull/112482
>From a01d46f6dfe7f383557b7e98df01b73a4f238cdf Mon Sep 17 00:00:00 2001
From: Gedare Bloom
Date: Tue, 15 Oct 2024 23:55:49 -0600
Subject: [PATCH 1/5] [clang-format] add BinPackLongBracedLists style option
The use of Cpp11BracedListStyle with BinPackParameters=False
avoids bin packing until reaching a hard-coded limit of 20 items.
This is an arbitrary choice. Introduce a new style option to
allow disabling this limit.
---
clang/include/clang/Format/Format.h| 20 +
clang/lib/Format/Format.cpp| 2 ++
clang/lib/Format/FormatToken.cpp | 2 +-
clang/unittests/Format/ConfigParseTest.cpp | 1 +
clang/unittests/Format/FormatTest.cpp | 26 ++
5 files changed, 50 insertions(+), 1 deletion(-)
diff --git a/clang/include/clang/Format/Format.h
b/clang/include/clang/Format/Format.h
index 6f432d1d5031542..31761c3311c34e5 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1212,6 +1212,22 @@ struct FormatStyle {
/// \version 3.7
bool BinPackArguments;
+ /// If ``BinPackLongBracedLists`` is ``true`` it overrides
+ /// ``BinPackArguments`` if there are 20 or more items in a braced
+ /// initializer list.
+ /// \code
+ ///BinPackLongBracedLists: false vs. BinPackLongBracedLists: true
+ ///vector x{ vector x{1, 2, ...,
+ /// 20, 21};
+ ///1,
+ ///2,
+ ///...,
+ ///20,
+ ///21};
+ /// \endcode
+ /// \version 20
+ bool BinPackLongBracedLists;
+
/// Different way to try to fit all parameters on a line.
enum BinPackParametersStyle : int8_t {
/// Bin-pack parameters.
@@ -2520,6 +2536,9 @@ struct FormatStyle {
/// (e.g. a type or variable name), clang-format formats as if the ``{}``
were
/// the parentheses of a function call with that name. If there is no name,
/// a zero-length name is assumed.
+ ///
+ /// ``BinPackArguments`` may be forced to true for initializer lists with
+ /// more than 20 items if ``BinPackLongBracedLists`` is true.
/// \code
///true: false:
///vector x{1, 2, 3, 4}; vs. vector x{ 1, 2, 3, 4 };
@@ -5239,6 +5258,7 @@ struct FormatStyle {
R.AlwaysBreakBeforeMultilineStrings &&
AttributeMacros == R.AttributeMacros &&
BinPackArguments == R.BinPackArguments &&
+ BinPackLongBracedLists == R.BinPackLongBracedLists &&
BinPackParameters == R.BinPackParameters &&
BitFieldColonSpacing == R.BitFieldColonSpacing &&
BracedInitializerIndentWidth == R.BracedInitializerIndentWidth &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index f02bf95cfeed7ea..4c52e92def43a37 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -995,6 +995,7 @@ template <> struct MappingTraits {
Style.AlwaysBreakBeforeMultilineStrings);
IO.mapOptional("AttributeMacros", Style.AttributeMacros);
IO.mapOptional("BinPackArguments", Style.BinPackArguments);
+IO.mapOptional("BinPackLongBracedLists", Style.BinPackLongBracedLists);
IO.mapOptional("BinPackParameters", Style.BinPackParameters);
IO.mapOptional("BitFieldColonSpacing", Style.BitFieldColonSpacing);
IO.mapOptional("BracedInitializerIndentWidth",
@@ -1505,6 +1506,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind
Language) {
LLVMStyle.AlwaysBreakBeforeMultilineStrings = false;
LLVMStyle.AttributeMacros.push_back("__capability");
LLVMStyle.BinPackArguments = true;
+ LLVMStyle.BinPackLongBracedLists = true;
LLVMStyle.BinPackParameters = FormatStyle::BPPS_BinPack;
LLVMStyle.BitFieldColonSpacing = FormatStyle::BFCS_Both;
LLVMStyle.BracedInitializerIndentWidth = std::nullopt;
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 963e8f87793fa09..a56a13bd58a5192 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -174,7 +174,7 @@ void CommaSeparatedList::precomputeFormattingInfos(const
FormatToken *Token) {
// have many items (20 or more) or we allow bin-packing of function call
// arguments.
if (Style.Cpp11BracedListStyle && !Style.BinPackArguments &&
- Commas.size() < 19) {
+ (Commas.size() < 19 || !Style.BinPackLongBracedLists)) {
return;
}
diff --git a/clang/unittests/Format/ConfigParseTest.cpp
b/clang/unittests/Format/ConfigParseTest.cpp
index 5bb1c00ab0bb239..7fec20723089fbb 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -168,6 +168,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
CHECK_PARSE_BOOL(AllowShortLoopsOnASingleLine);
CHECK_PARSE_BOOL(AllowSh
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
https://github.com/gedare updated
https://github.com/llvm/llvm-project/pull/112482
>From a01d46f6dfe7f383557b7e98df01b73a4f238cdf Mon Sep 17 00:00:00 2001
From: Gedare Bloom
Date: Tue, 15 Oct 2024 23:55:49 -0600
Subject: [PATCH 1/3] [clang-format] add BinPackLongBracedLists style option
The use of Cpp11BracedListStyle with BinPackParameters=False
avoids bin packing until reaching a hard-coded limit of 20 items.
This is an arbitrary choice. Introduce a new style option to
allow disabling this limit.
---
clang/include/clang/Format/Format.h| 20 +
clang/lib/Format/Format.cpp| 2 ++
clang/lib/Format/FormatToken.cpp | 2 +-
clang/unittests/Format/ConfigParseTest.cpp | 1 +
clang/unittests/Format/FormatTest.cpp | 26 ++
5 files changed, 50 insertions(+), 1 deletion(-)
diff --git a/clang/include/clang/Format/Format.h
b/clang/include/clang/Format/Format.h
index 6f432d1d503154..31761c3311c34e 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1212,6 +1212,22 @@ struct FormatStyle {
/// \version 3.7
bool BinPackArguments;
+ /// If ``BinPackLongBracedLists`` is ``true`` it overrides
+ /// ``BinPackArguments`` if there are 20 or more items in a braced
+ /// initializer list.
+ /// \code
+ ///BinPackLongBracedLists: false vs. BinPackLongBracedLists: true
+ ///vector x{ vector x{1, 2, ...,
+ /// 20, 21};
+ ///1,
+ ///2,
+ ///...,
+ ///20,
+ ///21};
+ /// \endcode
+ /// \version 20
+ bool BinPackLongBracedLists;
+
/// Different way to try to fit all parameters on a line.
enum BinPackParametersStyle : int8_t {
/// Bin-pack parameters.
@@ -2520,6 +2536,9 @@ struct FormatStyle {
/// (e.g. a type or variable name), clang-format formats as if the ``{}``
were
/// the parentheses of a function call with that name. If there is no name,
/// a zero-length name is assumed.
+ ///
+ /// ``BinPackArguments`` may be forced to true for initializer lists with
+ /// more than 20 items if ``BinPackLongBracedLists`` is true.
/// \code
///true: false:
///vector x{1, 2, 3, 4}; vs. vector x{ 1, 2, 3, 4 };
@@ -5239,6 +5258,7 @@ struct FormatStyle {
R.AlwaysBreakBeforeMultilineStrings &&
AttributeMacros == R.AttributeMacros &&
BinPackArguments == R.BinPackArguments &&
+ BinPackLongBracedLists == R.BinPackLongBracedLists &&
BinPackParameters == R.BinPackParameters &&
BitFieldColonSpacing == R.BitFieldColonSpacing &&
BracedInitializerIndentWidth == R.BracedInitializerIndentWidth &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index f02bf95cfeed7e..4c52e92def43a3 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -995,6 +995,7 @@ template <> struct MappingTraits {
Style.AlwaysBreakBeforeMultilineStrings);
IO.mapOptional("AttributeMacros", Style.AttributeMacros);
IO.mapOptional("BinPackArguments", Style.BinPackArguments);
+IO.mapOptional("BinPackLongBracedLists", Style.BinPackLongBracedLists);
IO.mapOptional("BinPackParameters", Style.BinPackParameters);
IO.mapOptional("BitFieldColonSpacing", Style.BitFieldColonSpacing);
IO.mapOptional("BracedInitializerIndentWidth",
@@ -1505,6 +1506,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind
Language) {
LLVMStyle.AlwaysBreakBeforeMultilineStrings = false;
LLVMStyle.AttributeMacros.push_back("__capability");
LLVMStyle.BinPackArguments = true;
+ LLVMStyle.BinPackLongBracedLists = true;
LLVMStyle.BinPackParameters = FormatStyle::BPPS_BinPack;
LLVMStyle.BitFieldColonSpacing = FormatStyle::BFCS_Both;
LLVMStyle.BracedInitializerIndentWidth = std::nullopt;
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 963e8f87793fa0..a56a13bd58a519 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -174,7 +174,7 @@ void CommaSeparatedList::precomputeFormattingInfos(const
FormatToken *Token) {
// have many items (20 or more) or we allow bin-packing of function call
// arguments.
if (Style.Cpp11BracedListStyle && !Style.BinPackArguments &&
- Commas.size() < 19) {
+ (Commas.size() < 19 || !Style.BinPackLongBracedLists)) {
return;
}
diff --git a/clang/unittests/Format/ConfigParseTest.cpp
b/clang/unittests/Format/ConfigParseTest.cpp
index 5bb1c00ab0bb23..7fec20723089fb 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -168,6 +168,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
CHECK_PARSE_BOOL(AllowShortLoopsOnASingleLine);
CHECK_PARSE_BOOL(AllowShortNames
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
gedare wrote: @owenca if you could take another look at this PR I'd appreciate it. https://github.com/llvm/llvm-project/pull/112482 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
https://github.com/gedare updated
https://github.com/llvm/llvm-project/pull/112482
>From eb789f3dd6aab070865fc92270aa20f872f30dab Mon Sep 17 00:00:00 2001
From: Gedare Bloom
Date: Tue, 15 Oct 2024 23:55:49 -0600
Subject: [PATCH 1/3] [clang-format] add BinPackLongBracedLists style option
The use of Cpp11BracedListStyle with BinPackParameters=False
avoids bin packing until reaching a hard-coded limit of 20 items.
This is an arbitrary choice. Introduce a new style option to
allow disabling this limit.
---
clang/include/clang/Format/Format.h| 20 +
clang/lib/Format/Format.cpp| 2 ++
clang/lib/Format/FormatToken.cpp | 2 +-
clang/unittests/Format/ConfigParseTest.cpp | 1 +
clang/unittests/Format/FormatTest.cpp | 26 ++
5 files changed, 50 insertions(+), 1 deletion(-)
diff --git a/clang/include/clang/Format/Format.h
b/clang/include/clang/Format/Format.h
index fd526f189ec833..00b4d1977f6d45 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1212,6 +1212,22 @@ struct FormatStyle {
/// \version 3.7
bool BinPackArguments;
+ /// If ``BinPackLongBracedLists`` is ``true`` it overrides
+ /// ``BinPackArguments`` if there are 20 or more items in a braced
+ /// initializer list.
+ /// \code
+ ///BinPackLongBracedLists: false vs. BinPackLongBracedLists: true
+ ///vector x{ vector x{1, 2, ...,
+ /// 20, 21};
+ ///1,
+ ///2,
+ ///...,
+ ///20,
+ ///21};
+ /// \endcode
+ /// \version 20
+ bool BinPackLongBracedLists;
+
/// Different way to try to fit all parameters on a line.
enum BinPackParametersStyle : int8_t {
/// Bin-pack parameters.
@@ -2520,6 +2536,9 @@ struct FormatStyle {
/// (e.g. a type or variable name), clang-format formats as if the ``{}``
were
/// the parentheses of a function call with that name. If there is no name,
/// a zero-length name is assumed.
+ ///
+ /// ``BinPackArguments`` may be forced to true for initializer lists with
+ /// more than 20 items if ``BinPackLongBracedLists`` is true.
/// \code
///true: false:
///vector x{1, 2, 3, 4}; vs. vector x{ 1, 2, 3, 4 };
@@ -5235,6 +5254,7 @@ struct FormatStyle {
R.AlwaysBreakBeforeMultilineStrings &&
AttributeMacros == R.AttributeMacros &&
BinPackArguments == R.BinPackArguments &&
+ BinPackLongBracedLists == R.BinPackLongBracedLists &&
BinPackParameters == R.BinPackParameters &&
BitFieldColonSpacing == R.BitFieldColonSpacing &&
BracedInitializerIndentWidth == R.BracedInitializerIndentWidth &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index c25d9bf7c22519..603ad9979e8770 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -995,6 +995,7 @@ template <> struct MappingTraits {
Style.AlwaysBreakBeforeMultilineStrings);
IO.mapOptional("AttributeMacros", Style.AttributeMacros);
IO.mapOptional("BinPackArguments", Style.BinPackArguments);
+IO.mapOptional("BinPackLongBracedLists", Style.BinPackLongBracedLists);
IO.mapOptional("BinPackParameters", Style.BinPackParameters);
IO.mapOptional("BitFieldColonSpacing", Style.BitFieldColonSpacing);
IO.mapOptional("BracedInitializerIndentWidth",
@@ -1503,6 +1504,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind
Language) {
LLVMStyle.AlwaysBreakBeforeMultilineStrings = false;
LLVMStyle.AttributeMacros.push_back("__capability");
LLVMStyle.BinPackArguments = true;
+ LLVMStyle.BinPackLongBracedLists = true;
LLVMStyle.BinPackParameters = FormatStyle::BPPS_BinPack;
LLVMStyle.BitFieldColonSpacing = FormatStyle::BFCS_Both;
LLVMStyle.BracedInitializerIndentWidth = std::nullopt;
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 963e8f87793fa0..a56a13bd58a519 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -174,7 +174,7 @@ void CommaSeparatedList::precomputeFormattingInfos(const
FormatToken *Token) {
// have many items (20 or more) or we allow bin-packing of function call
// arguments.
if (Style.Cpp11BracedListStyle && !Style.BinPackArguments &&
- Commas.size() < 19) {
+ (Commas.size() < 19 || !Style.BinPackLongBracedLists)) {
return;
}
diff --git a/clang/unittests/Format/ConfigParseTest.cpp
b/clang/unittests/Format/ConfigParseTest.cpp
index 9746aa35478465..bba64d549db623 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -164,6 +164,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
CHECK_PARSE_BOOL(AllowShortLoopsOnASingleLine);
CHECK_PARSE_BOOL(AllowShortNames
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/112482 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
HazardyKnusperkeks wrote: > > I think it should be merges with `BinPackArguments` to get an enum > > > > * Never > > * TwentyOrAbove (name is debatable) > > * Always > > * (Leave?) > > Currently the 20 item limit is only enforced on C++ initializer lists. Making > it part of the `BinPackArguments` means it has to apply to any bin packing > situation, so the scope of the style option increases. I'm not convinced it > is worth doing. Fair enough. https://github.com/llvm/llvm-project/pull/112482 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
gedare wrote: > I think it should be merges with `BinPackArguments` to get an enum > > * Never > * TwentyOrAbove (name is debatable) > * Always > * (Leave?) Currently the 20 item limit is only enforced on C++ initializer lists. Making it part of the `BinPackArguments` means it has to apply to any bin packing situation, so the scope of the style option increases. I'm not convinced it is worth doing. https://github.com/llvm/llvm-project/pull/112482 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
@@ -1208,6 +1208,21 @@ struct FormatStyle {
/// \version 3.7
bool BinPackArguments;
+ /// If ``BinPackArguments`` is ``false`` this option can override it if
+ /// ``true`` when 20 or more items are in a braced initializer list.
gedare wrote:
I rewrote it similar to your suggestion.
https://github.com/llvm/llvm-project/pull/112482
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
https://github.com/gedare updated
https://github.com/llvm/llvm-project/pull/112482
>From d625f811a615155b15a007ec3afc9874c52d06c4 Mon Sep 17 00:00:00 2001
From: Gedare Bloom
Date: Tue, 15 Oct 2024 23:55:49 -0600
Subject: [PATCH 1/3] [clang-format] add BinPackLongBracedLists style option
The use of Cpp11BracedListStyle with BinPackParameters=False
avoids bin packing until reaching a hard-coded limit of 20 items.
This is an arbitrary choice. Introduce a new style option to
allow disabling this limit.
---
clang/include/clang/Format/Format.h| 20 +
clang/lib/Format/Format.cpp| 2 ++
clang/lib/Format/FormatToken.cpp | 2 +-
clang/unittests/Format/ConfigParseTest.cpp | 1 +
clang/unittests/Format/FormatTest.cpp | 26 ++
5 files changed, 50 insertions(+), 1 deletion(-)
diff --git a/clang/include/clang/Format/Format.h
b/clang/include/clang/Format/Format.h
index 6383934afa2c40..cfac20e2d5d55b 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1208,6 +1208,22 @@ struct FormatStyle {
/// \version 3.7
bool BinPackArguments;
+ /// If ``BinPackLongBracedLists`` is ``true`` it overrides
+ /// ``BinPackArguments`` if there are 20 or more items in a braced
+ /// initializer list.
+ /// \code
+ ///BinPackLongBracedLists: false vs. BinPackLongBracedLists: true
+ ///vector x{ vector x{1, 2, ...,
+ /// 20, 21};
+ ///1,
+ ///2,
+ ///...,
+ ///20,
+ ///21};
+ /// \endcode
+ /// \version 20
+ bool BinPackLongBracedLists;
+
/// Different way to try to fit all parameters on a line.
enum BinPackParametersStyle : int8_t {
/// Bin-pack parameters.
@@ -2515,6 +2531,9 @@ struct FormatStyle {
/// (e.g. a type or variable name), clang-format formats as if the ``{}``
were
/// the parentheses of a function call with that name. If there is no name,
/// a zero-length name is assumed.
+ ///
+ /// ``BinPackArguments`` may be forced to true for initializer lists with
+ /// more than 20 items if ``BinPackLongBracedLists`` is true.
/// \code
///true: false:
///vector x{1, 2, 3, 4}; vs. vector x{ 1, 2, 3, 4 };
@@ -5172,6 +5191,7 @@ struct FormatStyle {
R.AlwaysBreakBeforeMultilineStrings &&
AttributeMacros == R.AttributeMacros &&
BinPackArguments == R.BinPackArguments &&
+ BinPackLongBracedLists == R.BinPackLongBracedLists &&
BinPackParameters == R.BinPackParameters &&
BitFieldColonSpacing == R.BitFieldColonSpacing &&
BracedInitializerIndentWidth == R.BracedInitializerIndentWidth &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index dcaac4b0d42cc5..559ffe56a30afe 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -981,6 +981,7 @@ template <> struct MappingTraits {
Style.AlwaysBreakBeforeMultilineStrings);
IO.mapOptional("AttributeMacros", Style.AttributeMacros);
IO.mapOptional("BinPackArguments", Style.BinPackArguments);
+IO.mapOptional("BinPackLongBracedLists", Style.BinPackLongBracedLists);
IO.mapOptional("BinPackParameters", Style.BinPackParameters);
IO.mapOptional("BitFieldColonSpacing", Style.BitFieldColonSpacing);
IO.mapOptional("BracedInitializerIndentWidth",
@@ -1484,6 +1485,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind
Language) {
LLVMStyle.AlwaysBreakBeforeMultilineStrings = false;
LLVMStyle.AttributeMacros.push_back("__capability");
LLVMStyle.BinPackArguments = true;
+ LLVMStyle.BinPackLongBracedLists = true;
LLVMStyle.BinPackParameters = FormatStyle::BPPS_BinPack;
LLVMStyle.BitFieldColonSpacing = FormatStyle::BFCS_Both;
LLVMStyle.BracedInitializerIndentWidth = std::nullopt;
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 963e8f87793fa0..a56a13bd58a519 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -174,7 +174,7 @@ void CommaSeparatedList::precomputeFormattingInfos(const
FormatToken *Token) {
// have many items (20 or more) or we allow bin-packing of function call
// arguments.
if (Style.Cpp11BracedListStyle && !Style.BinPackArguments &&
- Commas.size() < 19) {
+ (Commas.size() < 19 || !Style.BinPackLongBracedLists)) {
return;
}
diff --git a/clang/unittests/Format/ConfigParseTest.cpp
b/clang/unittests/Format/ConfigParseTest.cpp
index 7fc7492271668b..9c29cd3f57273f 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -160,6 +160,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
CHECK_PARSE_BOOL(AllowShortEnumsOnASingleLine);
CHECK_PARSE_BOOL(AllowShortLoops
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
https://github.com/HazardyKnusperkeks edited https://github.com/llvm/llvm-project/pull/112482 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
https://github.com/HazardyKnusperkeks commented: I think it should be merges with `BinPackArguments` to get an enum * Never * TwentyOrAbove (name is debatable) * Always * (Leave?) https://github.com/llvm/llvm-project/pull/112482 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
@@ -1208,6 +1208,21 @@ struct FormatStyle {
/// \version 3.7
bool BinPackArguments;
+ /// If ``BinPackArguments`` is ``false`` this option can override it if
+ /// ``true`` when 20 or more items are in a braced initializer list.
HazardyKnusperkeks wrote:
```suggestion
/// If ``BinPackLongBracedLists`` is set it overrides ``BinPackArguments``,
if there are 20 or more items are in a braced initializer list.
```
How about that? The current sentence is hard to read.
https://github.com/llvm/llvm-project/pull/112482
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
https://github.com/gedare updated
https://github.com/llvm/llvm-project/pull/112482
>From b61cb81d93e6fb137af282a4f2f0ebf151c2543c Mon Sep 17 00:00:00 2001
From: Gedare Bloom
Date: Tue, 15 Oct 2024 23:55:49 -0600
Subject: [PATCH 1/3] [clang-format] add BinPackLongBracedLists style option
The use of Cpp11BracedListStyle with BinPackParameters=False
avoids bin packing until reaching a hard-coded limit of 20 items.
This is an arbitrary choice. Introduce a new style option to
allow disabling this limit.
---
clang/include/clang/Format/Format.h| 19
clang/lib/Format/Format.cpp| 2 ++
clang/lib/Format/FormatToken.cpp | 2 +-
clang/unittests/Format/ConfigParseTest.cpp | 1 +
clang/unittests/Format/FormatTest.cpp | 26 ++
5 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/clang/include/clang/Format/Format.h
b/clang/include/clang/Format/Format.h
index 6383934afa2c40..00af4ca7c94bed 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1208,6 +1208,21 @@ struct FormatStyle {
/// \version 3.7
bool BinPackArguments;
+ /// If ``BinPackArguments`` is ``false`` this option can override it if
+ /// ``true`` when 20 or more items are in a braced initializer list.
+ /// \code
+ ///BinPackLongBracedLists: false vs. BinPackLongBracedLists: true
+ ///vector x{ vector x{1, 2, ...,
+ /// 20, 21};
+ ///1,
+ ///2,
+ ///...,
+ ///20,
+ ///21};
+ /// \endcode
+ /// \version 20
+ bool BinPackLongBracedLists;
+
/// Different way to try to fit all parameters on a line.
enum BinPackParametersStyle : int8_t {
/// Bin-pack parameters.
@@ -2515,6 +2530,9 @@ struct FormatStyle {
/// (e.g. a type or variable name), clang-format formats as if the ``{}``
were
/// the parentheses of a function call with that name. If there is no name,
/// a zero-length name is assumed.
+ ///
+ /// ``BinPackArguments`` may be forced to true for initializer lists with
+ /// more than 20 items if ``BinPackLongBracedLists`` is true.
/// \code
///true: false:
///vector x{1, 2, 3, 4}; vs. vector x{ 1, 2, 3, 4 };
@@ -5234,6 +5252,7 @@ struct FormatStyle {
LineEnding == R.LineEnding && MacroBlockBegin == R.MacroBlockBegin
&&
MacroBlockEnd == R.MacroBlockEnd && Macros == R.Macros &&
MaxEmptyLinesToKeep == R.MaxEmptyLinesToKeep &&
+ BinPackLongBracedLists == R.BinPackLongBracedLists &&
NamespaceIndentation == R.NamespaceIndentation &&
NamespaceMacros == R.NamespaceMacros &&
ObjCBinPackProtocolList == R.ObjCBinPackProtocolList &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index ee52972ce66f4a..39082da13c3051 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1060,6 +1060,7 @@ template <> struct MappingTraits {
IO.mapOptional("Macros", Style.Macros);
IO.mapOptional("MainIncludeChar", Style.IncludeStyle.MainIncludeChar);
IO.mapOptional("MaxEmptyLinesToKeep", Style.MaxEmptyLinesToKeep);
+IO.mapOptional("BinPackLongBracedLists", Style.BinPackLongBracedLists);
IO.mapOptional("NamespaceIndentation", Style.NamespaceIndentation);
IO.mapOptional("NamespaceMacros", Style.NamespaceMacros);
IO.mapOptional("ObjCBinPackProtocolList", Style.ObjCBinPackProtocolList);
@@ -1573,6 +1574,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind
Language) {
LLVMStyle.Language = Language;
LLVMStyle.LineEnding = FormatStyle::LE_DeriveLF;
LLVMStyle.MaxEmptyLinesToKeep = 1;
+ LLVMStyle.BinPackLongBracedLists = true;
LLVMStyle.NamespaceIndentation = FormatStyle::NI_None;
LLVMStyle.ObjCBinPackProtocolList = FormatStyle::BPS_Auto;
LLVMStyle.ObjCBlockIndentWidth = 2;
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 963e8f87793fa0..a56a13bd58a519 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -174,7 +174,7 @@ void CommaSeparatedList::precomputeFormattingInfos(const
FormatToken *Token) {
// have many items (20 or more) or we allow bin-packing of function call
// arguments.
if (Style.Cpp11BracedListStyle && !Style.BinPackArguments &&
- Commas.size() < 19) {
+ (Commas.size() < 19 || !Style.BinPackLongBracedLists)) {
return;
}
diff --git a/clang/unittests/Format/ConfigParseTest.cpp
b/clang/unittests/Format/ConfigParseTest.cpp
index 7fc7492271668b..9c29cd3f57273f 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -160,6 +160,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
CHECK_PARSE_BOOL(AllowShortEnumsOnASingleLine);
CHECK_PARSE_BOOL(AllowS
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
https://github.com/gedare updated
https://github.com/llvm/llvm-project/pull/112482
>From 59770d0e915b2cb50b89c2c98ed20f7d9170d744 Mon Sep 17 00:00:00 2001
From: Gedare Bloom
Date: Tue, 15 Oct 2024 23:55:49 -0600
Subject: [PATCH 1/3] [clang-format] add BinPackLongBracedLists style option
The use of Cpp11BracedListStyle with BinPackParameters=False
avoids bin packing until reaching a hard-coded limit of 20 items.
This is an arbitrary choice. Introduce a new style option to
allow disabling this limit.
---
clang/include/clang/Format/Format.h| 19
clang/lib/Format/Format.cpp| 2 ++
clang/lib/Format/FormatToken.cpp | 2 +-
clang/unittests/Format/ConfigParseTest.cpp | 1 +
clang/unittests/Format/FormatTest.cpp | 26 ++
5 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/clang/include/clang/Format/Format.h
b/clang/include/clang/Format/Format.h
index 6383934afa2c40..52eedce8e9d397 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1208,6 +1208,21 @@ struct FormatStyle {
/// \version 3.7
bool BinPackArguments;
+ /// If ``BinPackArguments`` is ``false`` this option can override it if
+ /// ``true`` when 20 or more items are in a braced initializer list.
+ /// \code
+ ///BinPackLongBracedLists: false vs. BinPackLongBracedLists: true
+ ///vector x{ vector x{1, 2, ...,
+ /// 20, 21};
+ ///1,
+ ///2,
+ ///...,
+ ///20,
+ ///21};
+ /// \endcode
+ /// \version 20
+ bool BinPackLongBracedLists;
+
/// Different way to try to fit all parameters on a line.
enum BinPackParametersStyle : int8_t {
/// Bin-pack parameters.
@@ -2515,6 +2530,9 @@ struct FormatStyle {
/// (e.g. a type or variable name), clang-format formats as if the ``{}``
were
/// the parentheses of a function call with that name. If there is no name,
/// a zero-length name is assumed.
+ ///
+ /// ``BinPackArguments`` may be forced to true for initializer lists with
+ /// more than 20 items if ``BinPackLongBracedLists`` is true.
/// \code
///true: false:
///vector x{1, 2, 3, 4}; vs. vector x{ 1, 2, 3, 4 };
@@ -5172,6 +5190,7 @@ struct FormatStyle {
R.AlwaysBreakBeforeMultilineStrings &&
AttributeMacros == R.AttributeMacros &&
BinPackArguments == R.BinPackArguments &&
+ BinPackLongBracedLists == R.BinPackLongBracedLists &&
BinPackParameters == R.BinPackParameters &&
BitFieldColonSpacing == R.BitFieldColonSpacing &&
BracedInitializerIndentWidth == R.BracedInitializerIndentWidth &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index dcaac4b0d42cc5..559ffe56a30afe 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -981,6 +981,7 @@ template <> struct MappingTraits {
Style.AlwaysBreakBeforeMultilineStrings);
IO.mapOptional("AttributeMacros", Style.AttributeMacros);
IO.mapOptional("BinPackArguments", Style.BinPackArguments);
+IO.mapOptional("BinPackLongBracedLists", Style.BinPackLongBracedLists);
IO.mapOptional("BinPackParameters", Style.BinPackParameters);
IO.mapOptional("BitFieldColonSpacing", Style.BitFieldColonSpacing);
IO.mapOptional("BracedInitializerIndentWidth",
@@ -1484,6 +1485,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind
Language) {
LLVMStyle.AlwaysBreakBeforeMultilineStrings = false;
LLVMStyle.AttributeMacros.push_back("__capability");
LLVMStyle.BinPackArguments = true;
+ LLVMStyle.BinPackLongBracedLists = true;
LLVMStyle.BinPackParameters = FormatStyle::BPPS_BinPack;
LLVMStyle.BitFieldColonSpacing = FormatStyle::BFCS_Both;
LLVMStyle.BracedInitializerIndentWidth = std::nullopt;
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 963e8f87793fa0..a56a13bd58a519 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -174,7 +174,7 @@ void CommaSeparatedList::precomputeFormattingInfos(const
FormatToken *Token) {
// have many items (20 or more) or we allow bin-packing of function call
// arguments.
if (Style.Cpp11BracedListStyle && !Style.BinPackArguments &&
- Commas.size() < 19) {
+ (Commas.size() < 19 || !Style.BinPackLongBracedLists)) {
return;
}
diff --git a/clang/unittests/Format/ConfigParseTest.cpp
b/clang/unittests/Format/ConfigParseTest.cpp
index 7fc7492271668b..9c29cd3f57273f 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -160,6 +160,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
CHECK_PARSE_BOOL(AllowShortEnumsOnASingleLine);
CHECK_PARSE_BOOL(AllowShortLoopsOnASingleLi
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
https://github.com/gedare updated
https://github.com/llvm/llvm-project/pull/112482
>From 9fb82b16dfea2115431219bd9915d18eff081805 Mon Sep 17 00:00:00 2001
From: Gedare Bloom
Date: Tue, 15 Oct 2024 23:55:49 -0600
Subject: [PATCH 1/3] [clang-format] add BinPackLongBracedLists style option
The use of Cpp11BracedListStyle with BinPackParameters=False
avoids bin packing until reaching a hard-coded limit of 20 items.
This is an arbitrary choice. Introduce a new style option to
allow disabling this limit.
---
clang/include/clang/Format/Format.h| 19
clang/lib/Format/Format.cpp| 2 ++
clang/lib/Format/FormatToken.cpp | 2 +-
clang/unittests/Format/ConfigParseTest.cpp | 1 +
clang/unittests/Format/FormatTest.cpp | 26 ++
5 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/clang/include/clang/Format/Format.h
b/clang/include/clang/Format/Format.h
index 6383934afa2c40..52eedce8e9d397 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1208,6 +1208,21 @@ struct FormatStyle {
/// \version 3.7
bool BinPackArguments;
+ /// If ``BinPackArguments`` is ``false`` this option can override it if
+ /// ``true`` when 20 or more items are in a braced initializer list.
+ /// \code
+ ///BinPackLongBracedLists: false vs. BinPackLongBracedLists: true
+ ///vector x{ vector x{1, 2, ...,
+ /// 20, 21};
+ ///1,
+ ///2,
+ ///...,
+ ///20,
+ ///21};
+ /// \endcode
+ /// \version 20
+ bool BinPackLongBracedLists;
+
/// Different way to try to fit all parameters on a line.
enum BinPackParametersStyle : int8_t {
/// Bin-pack parameters.
@@ -2515,6 +2530,9 @@ struct FormatStyle {
/// (e.g. a type or variable name), clang-format formats as if the ``{}``
were
/// the parentheses of a function call with that name. If there is no name,
/// a zero-length name is assumed.
+ ///
+ /// ``BinPackArguments`` may be forced to true for initializer lists with
+ /// more than 20 items if ``BinPackLongBracedLists`` is true.
/// \code
///true: false:
///vector x{1, 2, 3, 4}; vs. vector x{ 1, 2, 3, 4 };
@@ -5172,6 +5190,7 @@ struct FormatStyle {
R.AlwaysBreakBeforeMultilineStrings &&
AttributeMacros == R.AttributeMacros &&
BinPackArguments == R.BinPackArguments &&
+ BinPackLongBracedLists == R.BinPackLongBracedLists &&
BinPackParameters == R.BinPackParameters &&
BitFieldColonSpacing == R.BitFieldColonSpacing &&
BracedInitializerIndentWidth == R.BracedInitializerIndentWidth &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index ee52972ce66f4a..72106945214207 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -981,6 +981,7 @@ template <> struct MappingTraits {
Style.AlwaysBreakBeforeMultilineStrings);
IO.mapOptional("AttributeMacros", Style.AttributeMacros);
IO.mapOptional("BinPackArguments", Style.BinPackArguments);
+IO.mapOptional("BinPackLongBracedLists", Style.BinPackLongBracedLists);
IO.mapOptional("BinPackParameters", Style.BinPackParameters);
IO.mapOptional("BitFieldColonSpacing", Style.BitFieldColonSpacing);
IO.mapOptional("BracedInitializerIndentWidth",
@@ -1484,6 +1485,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind
Language) {
LLVMStyle.AlwaysBreakBeforeMultilineStrings = false;
LLVMStyle.AttributeMacros.push_back("__capability");
LLVMStyle.BinPackArguments = true;
+ LLVMStyle.BinPackLongBracedLists = true;
LLVMStyle.BinPackParameters = FormatStyle::BPPS_BinPack;
LLVMStyle.BitFieldColonSpacing = FormatStyle::BFCS_Both;
LLVMStyle.BracedInitializerIndentWidth = std::nullopt;
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 963e8f87793fa0..a56a13bd58a519 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -174,7 +174,7 @@ void CommaSeparatedList::precomputeFormattingInfos(const
FormatToken *Token) {
// have many items (20 or more) or we allow bin-packing of function call
// arguments.
if (Style.Cpp11BracedListStyle && !Style.BinPackArguments &&
- Commas.size() < 19) {
+ (Commas.size() < 19 || !Style.BinPackLongBracedLists)) {
return;
}
diff --git a/clang/unittests/Format/ConfigParseTest.cpp
b/clang/unittests/Format/ConfigParseTest.cpp
index 7fc7492271668b..9c29cd3f57273f 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -160,6 +160,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
CHECK_PARSE_BOOL(AllowShortEnumsOnASingleLine);
CHECK_PARSE_BOOL(AllowShortLoopsOnASingleLi
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
@@ -3398,6 +3401,21 @@ struct FormatStyle {
/// \version 3.7
unsigned MaxEmptyLinesToKeep;
+ /// If ``BinPackArguments`` is ``false`` this option can override it if
+ /// ``true`` when 20 or more items are in a braced initializer list.
+ /// \code
+ ///BinPackLongBracedLists: false vs. BinPackLongBracedLists: true
+ ///vector x{ vector x{1, 2, ...,
+ /// 20, 21};
+ ///1,
+ ///2,
+ ///...,
+ ///20,
+ ///21};
+ /// \endcode
+ /// \version 20
+ bool BinPackLongBracedLists;
gedare wrote:
done.
https://github.com/llvm/llvm-project/pull/112482
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
@@ -3398,6 +3401,21 @@ struct FormatStyle {
/// \version 3.7
unsigned MaxEmptyLinesToKeep;
+ /// If ``BinPackArguments`` is ``false`` this option can override it if
+ /// ``true`` when 20 or more items are in a braced initializer list.
+ /// \code
+ ///BinPackLongBracedLists: false vs. BinPackLongBracedLists: true
+ ///vector x{ vector x{1, 2, ...,
+ /// 20, 21};
+ ///1,
+ ///2,
+ ///...,
+ ///20,
+ ///21};
+ /// \endcode
+ /// \version 20
+ bool BinPackLongBracedLists;
HazardyKnusperkeks wrote:
Please resort.
https://github.com/llvm/llvm-project/pull/112482
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
gedare wrote: I'm content with this solution. https://github.com/llvm/llvm-project/pull/112482 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
https://github.com/gedare updated
https://github.com/llvm/llvm-project/pull/112482
>From c03df35a47e9486fb2117ea8f00fedaf445696c6 Mon Sep 17 00:00:00 2001
From: Gedare Bloom
Date: Tue, 15 Oct 2024 23:55:49 -0600
Subject: [PATCH 1/3] [clang-format] add BinPackLongBracedLists style option
The use of Cpp11BracedListStyle with BinPackParameters=False
avoids bin packing until reaching a hard-coded limit of 20 items.
This is an arbitrary choice. Introduce a new style option to
allow disabling this limit.
---
clang/include/clang/Format/Format.h| 19
clang/lib/Format/Format.cpp| 2 ++
clang/lib/Format/FormatToken.cpp | 2 +-
clang/unittests/Format/ConfigParseTest.cpp | 1 +
clang/unittests/Format/FormatTest.cpp | 26 ++
5 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/clang/include/clang/Format/Format.h
b/clang/include/clang/Format/Format.h
index 6383934afa2c40..6e5deed2f71d5a 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2515,6 +2515,9 @@ struct FormatStyle {
/// (e.g. a type or variable name), clang-format formats as if the ``{}``
were
/// the parentheses of a function call with that name. If there is no name,
/// a zero-length name is assumed.
+ ///
+ /// ``BinPackArguments`` may be forced to true for initializer lists with
+ /// more than 20 items if ``BinPackLongBracedLists`` is true.
/// \code
///true: false:
///vector x{1, 2, 3, 4}; vs. vector x{ 1, 2, 3, 4 };
@@ -3398,6 +3401,21 @@ struct FormatStyle {
/// \version 3.7
unsigned MaxEmptyLinesToKeep;
+ /// If ``BinPackArguments`` is ``false`` this option can override it if
+ /// ``true`` when 20 or more items are in a braced initializer list.
+ /// \code
+ ///BinPackLongBracedLists: false vs. BinPackLongBracedLists: true
+ ///vector x{ vector x{1, 2, ...,
+ /// 20, 21};
+ ///1,
+ ///2,
+ ///...,
+ ///20,
+ ///21};
+ /// \endcode
+ /// \version 20
+ bool BinPackLongBracedLists;
+
/// Different ways to indent namespace contents.
enum NamespaceIndentationKind : int8_t {
/// Don't indent in namespaces.
@@ -5234,6 +5252,7 @@ struct FormatStyle {
LineEnding == R.LineEnding && MacroBlockBegin == R.MacroBlockBegin
&&
MacroBlockEnd == R.MacroBlockEnd && Macros == R.Macros &&
MaxEmptyLinesToKeep == R.MaxEmptyLinesToKeep &&
+ BinPackLongBracedLists == R.BinPackLongBracedLists &&
NamespaceIndentation == R.NamespaceIndentation &&
NamespaceMacros == R.NamespaceMacros &&
ObjCBinPackProtocolList == R.ObjCBinPackProtocolList &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index ee52972ce66f4a..39082da13c3051 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1060,6 +1060,7 @@ template <> struct MappingTraits {
IO.mapOptional("Macros", Style.Macros);
IO.mapOptional("MainIncludeChar", Style.IncludeStyle.MainIncludeChar);
IO.mapOptional("MaxEmptyLinesToKeep", Style.MaxEmptyLinesToKeep);
+IO.mapOptional("BinPackLongBracedLists", Style.BinPackLongBracedLists);
IO.mapOptional("NamespaceIndentation", Style.NamespaceIndentation);
IO.mapOptional("NamespaceMacros", Style.NamespaceMacros);
IO.mapOptional("ObjCBinPackProtocolList", Style.ObjCBinPackProtocolList);
@@ -1573,6 +1574,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind
Language) {
LLVMStyle.Language = Language;
LLVMStyle.LineEnding = FormatStyle::LE_DeriveLF;
LLVMStyle.MaxEmptyLinesToKeep = 1;
+ LLVMStyle.BinPackLongBracedLists = true;
LLVMStyle.NamespaceIndentation = FormatStyle::NI_None;
LLVMStyle.ObjCBinPackProtocolList = FormatStyle::BPS_Auto;
LLVMStyle.ObjCBlockIndentWidth = 2;
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 963e8f87793fa0..a56a13bd58a519 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -174,7 +174,7 @@ void CommaSeparatedList::precomputeFormattingInfos(const
FormatToken *Token) {
// have many items (20 or more) or we allow bin-packing of function call
// arguments.
if (Style.Cpp11BracedListStyle && !Style.BinPackArguments &&
- Commas.size() < 19) {
+ (Commas.size() < 19 || !Style.BinPackLongBracedLists)) {
return;
}
diff --git a/clang/unittests/Format/ConfigParseTest.cpp
b/clang/unittests/Format/ConfigParseTest.cpp
index 7fc7492271668b..9c29cd3f57273f 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -160,6 +160,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
CHECK_PARSE_BOOL(AllowShortEnumsOnASingleLine);
CHECK_PARSE_BOOL
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
https://github.com/gedare updated
https://github.com/llvm/llvm-project/pull/112482
>From 5f868e9ce386923052f1b14936f04b129c7d6c00 Mon Sep 17 00:00:00 2001
From: Gedare Bloom
Date: Tue, 15 Oct 2024 23:55:49 -0600
Subject: [PATCH 1/4] [clang-format] add BinPackLongBracedLists style option
The use of Cpp11BracedListStyle with BinPackParameters=False
avoids bin packing until reaching a hard-coded limit of 20 items.
This is an arbitrary choice. Introduce a new style option to
allow disabling this limit.
---
clang/include/clang/Format/Format.h | 19 +++
clang/lib/Format/Format.cpp | 3 +++
clang/lib/Format/FormatToken.cpp | 2 +-
clang/unittests/Format/FormatTest.cpp | 26 ++
4 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/clang/include/clang/Format/Format.h
b/clang/include/clang/Format/Format.h
index 6383934afa2c40..6e5deed2f71d5a 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2515,6 +2515,9 @@ struct FormatStyle {
/// (e.g. a type or variable name), clang-format formats as if the ``{}``
were
/// the parentheses of a function call with that name. If there is no name,
/// a zero-length name is assumed.
+ ///
+ /// ``BinPackArguments`` may be forced to true for initializer lists with
+ /// more than 20 items if ``BinPackLongBracedLists`` is true.
/// \code
///true: false:
///vector x{1, 2, 3, 4}; vs. vector x{ 1, 2, 3, 4 };
@@ -3398,6 +3401,21 @@ struct FormatStyle {
/// \version 3.7
unsigned MaxEmptyLinesToKeep;
+ /// If ``BinPackArguments`` is ``false`` this option can override it if
+ /// ``true`` when 20 or more items are in a braced initializer list.
+ /// \code
+ ///BinPackLongBracedLists: false vs. BinPackLongBracedLists: true
+ ///vector x{ vector x{1, 2, ...,
+ /// 20, 21};
+ ///1,
+ ///2,
+ ///...,
+ ///20,
+ ///21};
+ /// \endcode
+ /// \version 20
+ bool BinPackLongBracedLists;
+
/// Different ways to indent namespace contents.
enum NamespaceIndentationKind : int8_t {
/// Don't indent in namespaces.
@@ -5234,6 +5252,7 @@ struct FormatStyle {
LineEnding == R.LineEnding && MacroBlockBegin == R.MacroBlockBegin
&&
MacroBlockEnd == R.MacroBlockEnd && Macros == R.Macros &&
MaxEmptyLinesToKeep == R.MaxEmptyLinesToKeep &&
+ BinPackLongBracedLists == R.BinPackLongBracedLists &&
NamespaceIndentation == R.NamespaceIndentation &&
NamespaceMacros == R.NamespaceMacros &&
ObjCBinPackProtocolList == R.ObjCBinPackProtocolList &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index ee52972ce66f4a..fadfbdb51dc5a2 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1060,6 +1060,8 @@ template <> struct MappingTraits {
IO.mapOptional("Macros", Style.Macros);
IO.mapOptional("MainIncludeChar", Style.IncludeStyle.MainIncludeChar);
IO.mapOptional("MaxEmptyLinesToKeep", Style.MaxEmptyLinesToKeep);
+IO.mapOptional("BinPackLongBracedLists",
+ Style.BinPackLongBracedLists);
IO.mapOptional("NamespaceIndentation", Style.NamespaceIndentation);
IO.mapOptional("NamespaceMacros", Style.NamespaceMacros);
IO.mapOptional("ObjCBinPackProtocolList", Style.ObjCBinPackProtocolList);
@@ -1573,6 +1575,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind
Language) {
LLVMStyle.Language = Language;
LLVMStyle.LineEnding = FormatStyle::LE_DeriveLF;
LLVMStyle.MaxEmptyLinesToKeep = 1;
+ LLVMStyle.BinPackLongBracedLists = true;
LLVMStyle.NamespaceIndentation = FormatStyle::NI_None;
LLVMStyle.ObjCBinPackProtocolList = FormatStyle::BPS_Auto;
LLVMStyle.ObjCBlockIndentWidth = 2;
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 963e8f87793fa0..a56a13bd58a519 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -174,7 +174,7 @@ void CommaSeparatedList::precomputeFormattingInfos(const
FormatToken *Token) {
// have many items (20 or more) or we allow bin-packing of function call
// arguments.
if (Style.Cpp11BracedListStyle && !Style.BinPackArguments &&
- Commas.size() < 19) {
+ (Commas.size() < 19 || !Style.BinPackLongBracedLists)) {
return;
}
diff --git a/clang/unittests/Format/FormatTest.cpp
b/clang/unittests/Format/FormatTest.cpp
index 250e51b5421664..fe8193ca2ea124 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -14038,6 +14038,32 @@ TEST_F(FormatTest, LayoutCxx11BraceInitializers) {
"ff, g, hh, ii, jj, kk,\n"
"};",
NoBinPacking);
+ NoBinPacking.BinPackLongBr
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
github-actions[bot] wrote:
:warning: C/C++ code formatter, clang-format found issues in your code.
:warning:
You can test this locally with the following command:
``bash
git-clang-format --diff 3d437893c3b8431a35f5edb65409f0d0fb0e2d95
c667d874ccd1e4aa23348c8f5a78fab834ecbbc1 --extensions h,cpp --
clang/include/clang/Format/Format.h clang/lib/Format/Format.cpp
clang/lib/Format/FormatToken.cpp clang/unittests/Format/FormatTest.cpp
``
View the diff from clang-format here.
``diff
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index fadfbdb51d..39082da13c 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1060,8 +1060,7 @@ template <> struct MappingTraits {
IO.mapOptional("Macros", Style.Macros);
IO.mapOptional("MainIncludeChar", Style.IncludeStyle.MainIncludeChar);
IO.mapOptional("MaxEmptyLinesToKeep", Style.MaxEmptyLinesToKeep);
-IO.mapOptional("BinPackLongBracedLists",
- Style.BinPackLongBracedLists);
+IO.mapOptional("BinPackLongBracedLists", Style.BinPackLongBracedLists);
IO.mapOptional("NamespaceIndentation", Style.NamespaceIndentation);
IO.mapOptional("NamespaceMacros", Style.NamespaceMacros);
IO.mapOptional("ObjCBinPackProtocolList", Style.ObjCBinPackProtocolList);
``
https://github.com/llvm/llvm-project/pull/112482
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
gedare wrote: I decided to go the simpler route and create a boolean option that can be used to disable the hard-coded limit of 20 items. https://github.com/llvm/llvm-project/pull/112482 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
https://github.com/gedare edited https://github.com/llvm/llvm-project/pull/112482 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
https://github.com/gedare edited https://github.com/llvm/llvm-project/pull/112482 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
