[PATCH] D140843: [clang-format] fix template closer followed by >

2023-01-02 Thread Zhikai Zeng via Phabricator via cfe-commits
Backl1ght created this revision.
Backl1ght added reviewers: HazardyKnusperkeks, MyDeveloperDay.
Backl1ght added a project: clang-format.
Herald added a project: All.
Backl1ght requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch is to fix https://github.com/llvm/llvm-project/issues/59785.

related patches: https://reviews.llvm.org/D86581 and 
https://reviews.llvm.org/D100778.

I think the condition added in D100778  is 
enough to judge shifts within conditions, the condition added in D86581 
 is unnecessary and will cause template 
opener/closer parsed as binary operator, so I simply remove the condition added 
in D86581 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140843

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -10341,6 +10341,8 @@
   verifyFormat("bool_constant");
   verifyFormat("bool_constant");
 
+  verifyFormat("if (std::tuple_size_v > 0)");
+
   // Not template parameters.
   verifyFormat("return a < b && c > d;");
   verifyFormat("void f() {\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -166,10 +166,9 @@
 // parameter cases, but should not alter program semantics.
 if (CurrentToken->Next && CurrentToken->Next->is(tok::greater) &&
 Left->ParentBracket != tok::less &&
-(isKeywordWithCondition(*Line.First) ||
- CurrentToken->getStartOfNonWhitespace() ==
- 
CurrentToken->Next->getStartOfNonWhitespace().getLocWithOffset(
- -1))) {
+CurrentToken->getStartOfNonWhitespace() ==
+CurrentToken->Next->getStartOfNonWhitespace().getLocWithOffset(
+-1)) {
   return false;
 }
 Left->MatchingParen = CurrentToken;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -10341,6 +10341,8 @@
   verifyFormat("bool_constant");
   verifyFormat("bool_constant");
 
+  verifyFormat("if (std::tuple_size_v > 0)");
+
   // Not template parameters.
   verifyFormat("return a < b && c > d;");
   verifyFormat("void f() {\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -166,10 +166,9 @@
 // parameter cases, but should not alter program semantics.
 if (CurrentToken->Next && CurrentToken->Next->is(tok::greater) &&
 Left->ParentBracket != tok::less &&
-(isKeywordWithCondition(*Line.First) ||
- CurrentToken->getStartOfNonWhitespace() ==
- CurrentToken->Next->getStartOfNonWhitespace().getLocWithOffset(
- -1))) {
+CurrentToken->getStartOfNonWhitespace() ==
+CurrentToken->Next->getStartOfNonWhitespace().getLocWithOffset(
+-1)) {
   return false;
 }
 Left->MatchingParen = CurrentToken;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140843: [clang-format] fix template closer followed by >

2023-01-03 Thread Zhikai Zeng via Phabricator via cfe-commits
Backl1ght added a comment.

In D140843#4022673 , @MyDeveloperDay 
wrote:

> I'm good with this but I'd be interesting in @owenpan  and 
> @HazardyKnusperkeks opinion.

Yes, this is what I understand.

And I will add an annotator test later.

This patch is just a temporary solution I think, there are further things to do 
with such case, maybe I should add a TODO or FIXME?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140843/new/

https://reviews.llvm.org/D140843

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140843: [clang-format] fix template closer followed by >

2023-01-04 Thread Zhikai Zeng via Phabricator via cfe-commits
Backl1ght updated this revision to Diff 486248.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140843/new/

https://reviews.llvm.org/D140843

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -339,6 +339,14 @@
   EXPECT_TOKEN(Tokens[19], tok::greater, TT_TemplateCloser);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsGreaterAfterTemplateCloser) {
+  auto Tokens = annotate("if (std::tuple_size_v > 0)");
+  ASSERT_EQ(Tokens.size(), 12u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[7], tok::greater, TT_TemplateCloser);
+  EXPECT_TOKEN(Tokens[8], tok::greater, TT_BinaryOperator);
+}
+
 TEST_F(TokenAnnotatorTest, UnderstandsWhitespaceSensitiveMacros) {
   FormatStyle Style = getLLVMStyle();
   Style.WhitespaceSensitiveMacros.push_back("FOO");
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -10341,6 +10341,8 @@
   verifyFormat("bool_constant");
   verifyFormat("bool_constant");
 
+  verifyFormat("if (std::tuple_size_v > 0)");
+
   // Not template parameters.
   verifyFormat("return a < b && c > d;");
   verifyFormat("void f() {\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -166,10 +166,9 @@
 // parameter cases, but should not alter program semantics.
 if (CurrentToken->Next && CurrentToken->Next->is(tok::greater) &&
 Left->ParentBracket != tok::less &&
-(isKeywordWithCondition(*Line.First) ||
- CurrentToken->getStartOfNonWhitespace() ==
- 
CurrentToken->Next->getStartOfNonWhitespace().getLocWithOffset(
- -1))) {
+CurrentToken->getStartOfNonWhitespace() ==
+CurrentToken->Next->getStartOfNonWhitespace().getLocWithOffset(
+-1)) {
   return false;
 }
 Left->MatchingParen = CurrentToken;


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -339,6 +339,14 @@
   EXPECT_TOKEN(Tokens[19], tok::greater, TT_TemplateCloser);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsGreaterAfterTemplateCloser) {
+  auto Tokens = annotate("if (std::tuple_size_v > 0)");
+  ASSERT_EQ(Tokens.size(), 12u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[7], tok::greater, TT_TemplateCloser);
+  EXPECT_TOKEN(Tokens[8], tok::greater, TT_BinaryOperator);
+}
+
 TEST_F(TokenAnnotatorTest, UnderstandsWhitespaceSensitiveMacros) {
   FormatStyle Style = getLLVMStyle();
   Style.WhitespaceSensitiveMacros.push_back("FOO");
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -10341,6 +10341,8 @@
   verifyFormat("bool_constant");
   verifyFormat("bool_constant");
 
+  verifyFormat("if (std::tuple_size_v > 0)");
+
   // Not template parameters.
   verifyFormat("return a < b && c > d;");
   verifyFormat("void f() {\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -166,10 +166,9 @@
 // parameter cases, but should not alter program semantics.
 if (CurrentToken->Next && CurrentToken->Next->is(tok::greater) &&
 Left->ParentBracket != tok::less &&
-(isKeywordWithCondition(*Line.First) ||
- CurrentToken->getStartOfNonWhitespace() ==
- CurrentToken->Next->getStartOfNonWhitespace().getLocWithOffset(
- -1))) {
+CurrentToken->getStartOfNonWhitespace() ==
+CurrentToken->Next->getStartOfNonWhitespace().getLocWithOffset(
+-1)) {
   return false;
 }
 Left->MatchingParen = CurrentToken;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140843: [clang-format] fix template closer followed by >

2023-01-04 Thread Zhikai Zeng via Phabricator via cfe-commits
Backl1ght added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:169-171
+CurrentToken->getStartOfNonWhitespace() ==
+CurrentToken->Next->getStartOfNonWhitespace().getLocWithOffset(
+-1)) {

MyDeveloperDay wrote:
> I was wondering this is actually saying   
> 
> I think its saying... 2 tokens are next to each other ">>"  its not so much 
> formatting but ensuring the existing formatting is maintained, is that what 
> you understand?
> 
> Whilst this works it won't correct the case where the whitespace is wrong
> 
> i.e. I don't think
> 
> ```
> if (std::tuple_size_v < T >> 0) {
> }
> ```
> 
> will be corrected to be
> 
> ```
> if (std::tuple_size_v > 0) {
> }
> ```
> 
> I'm a little wary of rules that use the existing whitespace, but I tend to 
> agree that it might be ok without the extra check. 
> 
> It would be good to capture this as an annotator test (I like the 
> verifyformat one you put in) but the annotator tests we can assert that its 
> actually a templatecloser and binary operatror
> 
> 
> 
I think there should be more infomation to make the correction.

So far, we only know that `tuple_size_v` is an identifier, but the exact type 
of `tuple_size_v` is unknown. Maybe `tuple_size_v` is a type trait and in this 
case we should make the correction. Maybe `tuple_size_v` is an interger and in 
this case we should not make the correction.

To make the correction, we need at least one of:
1. is `tuple_size_v` a type trait?
2. is `T` a typename?
3. is `>>` a right shift?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140843/new/

https://reviews.llvm.org/D140843

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140843: [clang-format] fix template closer followed by >

2023-01-06 Thread Zhikai Zeng via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb62906b0d10f: [clang-format] fix template closer followed by 
> (authored by Backl1ght).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140843/new/

https://reviews.llvm.org/D140843

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -339,6 +339,14 @@
   EXPECT_TOKEN(Tokens[19], tok::greater, TT_TemplateCloser);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsGreaterAfterTemplateCloser) {
+  auto Tokens = annotate("if (std::tuple_size_v > 0)");
+  ASSERT_EQ(Tokens.size(), 12u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[7], tok::greater, TT_TemplateCloser);
+  EXPECT_TOKEN(Tokens[8], tok::greater, TT_BinaryOperator);
+}
+
 TEST_F(TokenAnnotatorTest, UnderstandsWhitespaceSensitiveMacros) {
   FormatStyle Style = getLLVMStyle();
   Style.WhitespaceSensitiveMacros.push_back("FOO");
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -10341,6 +10341,8 @@
   verifyFormat("bool_constant");
   verifyFormat("bool_constant");
 
+  verifyFormat("if (std::tuple_size_v > 0)");
+
   // Not template parameters.
   verifyFormat("return a < b && c > d;");
   verifyFormat("void f() {\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -166,10 +166,9 @@
 // parameter cases, but should not alter program semantics.
 if (CurrentToken->Next && CurrentToken->Next->is(tok::greater) &&
 Left->ParentBracket != tok::less &&
-(isKeywordWithCondition(*Line.First) ||
- CurrentToken->getStartOfNonWhitespace() ==
- 
CurrentToken->Next->getStartOfNonWhitespace().getLocWithOffset(
- -1))) {
+CurrentToken->getStartOfNonWhitespace() ==
+CurrentToken->Next->getStartOfNonWhitespace().getLocWithOffset(
+-1)) {
   return false;
 }
 Left->MatchingParen = CurrentToken;


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -339,6 +339,14 @@
   EXPECT_TOKEN(Tokens[19], tok::greater, TT_TemplateCloser);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsGreaterAfterTemplateCloser) {
+  auto Tokens = annotate("if (std::tuple_size_v > 0)");
+  ASSERT_EQ(Tokens.size(), 12u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[7], tok::greater, TT_TemplateCloser);
+  EXPECT_TOKEN(Tokens[8], tok::greater, TT_BinaryOperator);
+}
+
 TEST_F(TokenAnnotatorTest, UnderstandsWhitespaceSensitiveMacros) {
   FormatStyle Style = getLLVMStyle();
   Style.WhitespaceSensitiveMacros.push_back("FOO");
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -10341,6 +10341,8 @@
   verifyFormat("bool_constant");
   verifyFormat("bool_constant");
 
+  verifyFormat("if (std::tuple_size_v > 0)");
+
   // Not template parameters.
   verifyFormat("return a < b && c > d;");
   verifyFormat("void f() {\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -166,10 +166,9 @@
 // parameter cases, but should not alter program semantics.
 if (CurrentToken->Next && CurrentToken->Next->is(tok::greater) &&
 Left->ParentBracket != tok::less &&
-(isKeywordWithCondition(*Line.First) ||
- CurrentToken->getStartOfNonWhitespace() ==
- CurrentToken->Next->getStartOfNonWhitespace().getLocWithOffset(
- -1))) {
+CurrentToken->getStartOfNonWhitespace() ==
+CurrentToken->Next->getStartOfNonWhitespace().getLocWithOffset(
+-1)) {
   return false;
 }
 Left->MatchingParen = CurrentToken;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D143091: https://github.com/llvm/llvm-project/issues/60241

2023-02-01 Thread Zhikai Zeng via Phabricator via cfe-commits
Backl1ght created this revision.
Backl1ght added reviewers: HazardyKnusperkeks, MyDeveloperDay, owenpan.
Backl1ght added a project: clang-format.
Herald added a project: All.
Backl1ght requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

fixes https://github.com/llvm/llvm-project/issues/60241


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143091

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -7289,6 +7289,14 @@
  Style);
 verifyFormat("Constructor() : a(a), b(b) {}", Style);
 
+Style.PackConstructorInitializers = FormatStyle::PCIS_OnlyNextLine;
+verifyFormat("Constructor()\n"
+ ": (a), b(b) {}",
+ Style);
+verifyFormat("Constructor()\n"
+ ": a(a), b(b) {}",
+ Style);
+
 Style.BreakConstructorInitializers = FormatStyle::BCIS_BeforeColon;
 Style.PackConstructorInitializers = FormatStyle::PCIS_NextLine;
 verifyFormat("Constructor()\n"
@@ -7301,6 +7309,11 @@
  "  b(b) {}",
  Style);
 
+Style.PackConstructorInitializers = FormatStyle::PCIS_OnlyNextLine;
+verifyFormat("Constructor()\n"
+ ": (a), b(b) {}",
+ Style);
+
 Style.BreakConstructorInitializers = FormatStyle::BCIS_AfterColon;
 Style.PackConstructorInitializers = FormatStyle::PCIS_NextLine;
 verifyFormat("Constructor() :\n"
@@ -7312,6 +7325,11 @@
  "aa(a),\n"
  "b(b) {}",
  Style);
+
+Style.PackConstructorInitializers = FormatStyle::PCIS_OnlyNextLine;
+verifyFormat("Constructor() :\n"
+ "aa(a), b(b) {}",
+ Style);
   }
 
   // Test interactions between AllowAllParametersOfDeclarationOnNextLine and
@@ -7319,6 +7337,7 @@
   // BreakConstructorInitializers modes
   Style.BreakConstructorInitializers = FormatStyle::BCIS_BeforeComma;
   Style.AllowAllParametersOfDeclarationOnNextLine = true;
+  Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
   verifyFormat("SomeClassWithALongName::Constructor(\n"
"int , int b)\n"
": (a)\n"
@@ -7333,6 +7352,14 @@
": (a), b(b) {}",
Style);
 
+  Style.PackConstructorInitializers = FormatStyle::PCIS_OnlyNextLine;
+  verifyFormat("SomeClassWithALongName::Constructor(\n"
+   "int ,\n"
+   "int b,\n"
+   "int )\n"
+   ": (a), b(b) {}",
+   Style);
+
   Style.AllowAllParametersOfDeclarationOnNextLine = false;
   Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
   verifyFormat("SomeClassWithALongName::Constructor(\n"
@@ -7359,6 +7386,14 @@
": (a), b(b) {}",
Style);
 
+  Style.PackConstructorInitializers = FormatStyle::PCIS_OnlyNextLine;
+  verifyFormat("SomeClassWithALongName::Constructor(\n"
+   "int ,\n"
+   "int b,\n"
+   "int )\n"
+   ": (a), b(b) {}",
+   Style);
+
   Style.AllowAllParametersOfDeclarationOnNextLine = false;
   Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
   verifyFormat("SomeClassWithALongName::Constructor(\n"
@@ -7384,6 +7419,14 @@
"(a), b(b) {}",
Style);
 
+  Style.PackConstructorInitializers = FormatStyle::PCIS_OnlyNextLine;
+  verifyFormat("SomeClassWithALongName::Constructor(\n"
+   "int ,\n"
+   "int b,\n"
+   "int ) :\n"
+   "(a), b(b) {}",
+   Style);
+
   Style.AllowAllParametersOfDeclarationOnNextLine = false;
   Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
   verifyFormat("SomeClassWithALongName::Constructor(\n"
@@ -7587,6 +7630,16 @@
   

[PATCH] D143091: [clang-format] PackConstructorInitializers support PCIS_OnlyNextLine

2023-02-02 Thread Zhikai Zeng via Phabricator via cfe-commits
Backl1ght updated this revision to Diff 494281.
Backl1ght added a comment.

adapt suggestion


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143091/new/

https://reviews.llvm.org/D143091

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -7289,6 +7289,14 @@
  Style);
 verifyFormat("Constructor() : a(a), b(b) {}", Style);
 
+Style.PackConstructorInitializers = FormatStyle::PCIS_OnlyNextLine;
+verifyFormat("Constructor()\n"
+ ": (a), b(b) {}",
+ Style);
+verifyFormat("Constructor()\n"
+ ": a(a), b(b) {}",
+ Style);
+
 Style.BreakConstructorInitializers = FormatStyle::BCIS_BeforeColon;
 Style.PackConstructorInitializers = FormatStyle::PCIS_NextLine;
 verifyFormat("Constructor()\n"
@@ -7301,6 +7309,11 @@
  "  b(b) {}",
  Style);
 
+Style.PackConstructorInitializers = FormatStyle::PCIS_OnlyNextLine;
+verifyFormat("Constructor()\n"
+ ": (a), b(b) {}",
+ Style);
+
 Style.BreakConstructorInitializers = FormatStyle::BCIS_AfterColon;
 Style.PackConstructorInitializers = FormatStyle::PCIS_NextLine;
 verifyFormat("Constructor() :\n"
@@ -7312,6 +7325,11 @@
  "aa(a),\n"
  "b(b) {}",
  Style);
+
+Style.PackConstructorInitializers = FormatStyle::PCIS_OnlyNextLine;
+verifyFormat("Constructor() :\n"
+ "aa(a), b(b) {}",
+ Style);
   }
 
   // Test interactions between AllowAllParametersOfDeclarationOnNextLine and
@@ -7319,6 +7337,7 @@
   // BreakConstructorInitializers modes
   Style.BreakConstructorInitializers = FormatStyle::BCIS_BeforeComma;
   Style.AllowAllParametersOfDeclarationOnNextLine = true;
+  Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
   verifyFormat("SomeClassWithALongName::Constructor(\n"
"int , int b)\n"
": (a)\n"
@@ -7333,6 +7352,14 @@
": (a), b(b) {}",
Style);
 
+  Style.PackConstructorInitializers = FormatStyle::PCIS_OnlyNextLine;
+  verifyFormat("SomeClassWithALongName::Constructor(\n"
+   "int ,\n"
+   "int b,\n"
+   "int )\n"
+   ": (a), b(b) {}",
+   Style);
+
   Style.AllowAllParametersOfDeclarationOnNextLine = false;
   Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
   verifyFormat("SomeClassWithALongName::Constructor(\n"
@@ -7359,6 +7386,14 @@
": (a), b(b) {}",
Style);
 
+  Style.PackConstructorInitializers = FormatStyle::PCIS_OnlyNextLine;
+  verifyFormat("SomeClassWithALongName::Constructor(\n"
+   "int ,\n"
+   "int b,\n"
+   "int )\n"
+   ": (a), b(b) {}",
+   Style);
+
   Style.AllowAllParametersOfDeclarationOnNextLine = false;
   Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
   verifyFormat("SomeClassWithALongName::Constructor(\n"
@@ -7384,6 +7419,14 @@
"(a), b(b) {}",
Style);
 
+  Style.PackConstructorInitializers = FormatStyle::PCIS_OnlyNextLine;
+  verifyFormat("SomeClassWithALongName::Constructor(\n"
+   "int ,\n"
+   "int b,\n"
+   "int ) :\n"
+   "(a), b(b) {}",
+   Style);
+
   Style.AllowAllParametersOfDeclarationOnNextLine = false;
   Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
   verifyFormat("SomeClassWithALongName::Constructor(\n"
@@ -7587,6 +7630,16 @@
   "a(aa), aaa() {}",
   Style);
 
+  Style.PackConstructorInitializers = FormatStyle::PCIS_OnlyNextLine;
+  verifyFormat(
+  "SomeClass::Constructor() :\n"
+  " 

[PATCH] D143091: [clang-format] PackConstructorInitializers support PCIS_OnlyNextLine

2023-02-02 Thread Zhikai Zeng via Phabricator via cfe-commits
Backl1ght marked an inline comment as done.
Backl1ght added a comment.

In D143091#4097534 , 
@HazardyKnusperkeks wrote:

> An entry in the changelog would be nice.

It is already added I think.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143091/new/

https://reviews.llvm.org/D143091

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D143091: [clang-format] PackConstructorInitializers support PCIS_OnlyNextLine

2023-02-03 Thread Zhikai Zeng via Phabricator via cfe-commits
Backl1ght added inline comments.



Comment at: clang/docs/ClangFormatStyleOptions.rst:3891
 
+  * ``PCIS_OnlyNextLine`` (in configuration: ``OnlyNextLine``)
+Put all constructor initializers on the next line if they fit.

@HazardyKnusperkeks Maybe I misunderstand something, I think I already add 
an entry here by running `clang/docs/tools/dump_format_style.py`.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143091/new/

https://reviews.llvm.org/D143091

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D143091: [clang-format] PackConstructorInitializers support PCIS_OnlyNextLine

2023-02-04 Thread Zhikai Zeng via Phabricator via cfe-commits
Backl1ght updated this revision to Diff 494821.
Backl1ght added a comment.

add more unittest


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143091/new/

https://reviews.llvm.org/D143091

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -7289,6 +7289,19 @@
  Style);
 verifyFormat("Constructor() : a(a), b(b) {}", Style);
 
+Style.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+verifyFormat("Constructor()\n"
+ ": (a), b(b) {}",
+ Style);
+verifyFormat("Constructor()\n"
+ ": a(a), b(b) {}",
+ Style);
+verifyFormat("Constructor()\n"
+ ": (a)\n"
+ ", b(b)\n"
+ ", cc(c) {}",
+ Style);
+
 Style.BreakConstructorInitializers = FormatStyle::BCIS_BeforeColon;
 Style.PackConstructorInitializers = FormatStyle::PCIS_NextLine;
 verifyFormat("Constructor()\n"
@@ -7301,6 +7314,19 @@
  "  b(b) {}",
  Style);
 
+Style.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+verifyFormat("Constructor()\n"
+ ": (a), b(b) {}",
+ Style);
+verifyFormat("Constructor()\n"
+ ": a(a), b(b) {}",
+ Style);
+verifyFormat("Constructor()\n"
+ ": (a),\n"
+ "  b(b),\n"
+ "  cc(c) {}",
+ Style);
+
 Style.BreakConstructorInitializers = FormatStyle::BCIS_AfterColon;
 Style.PackConstructorInitializers = FormatStyle::PCIS_NextLine;
 verifyFormat("Constructor() :\n"
@@ -7312,6 +7338,19 @@
  "aa(a),\n"
  "b(b) {}",
  Style);
+
+Style.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+verifyFormat("Constructor() :\n"
+ "aa(a), b(b) {}",
+ Style);
+verifyFormat("Constructor() :\n"
+ "a(a), b(b) {}",
+ Style);
+verifyFormat("Constructor() :\n"
+ "(a),\n"
+ "b(b),\n"
+ "cc(c) {}",
+ Style);
   }
 
   // Test interactions between AllowAllParametersOfDeclarationOnNextLine and
@@ -7319,6 +7358,7 @@
   // BreakConstructorInitializers modes
   Style.BreakConstructorInitializers = FormatStyle::BCIS_BeforeComma;
   Style.AllowAllParametersOfDeclarationOnNextLine = true;
+  Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
   verifyFormat("SomeClassWithALongName::Constructor(\n"
"int , int b)\n"
": (a)\n"
@@ -7333,6 +7373,14 @@
": (a), b(b) {}",
Style);
 
+  Style.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+  verifyFormat("SomeClassWithALongName::Constructor(\n"
+   "int ,\n"
+   "int b,\n"
+   "int )\n"
+   ": (a), b(b) {}",
+   Style);
+
   Style.AllowAllParametersOfDeclarationOnNextLine = false;
   Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
   verifyFormat("SomeClassWithALongName::Constructor(\n"
@@ -7359,6 +7407,14 @@
": (a), b(b) {}",
Style);
 
+  Style.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+  verifyFormat("SomeClassWithALongName::Constructor(\n"
+   "int ,\n"
+   "int b,\n"
+   "int )\n"
+   ": (a), b(b) {}",
+   Style);
+
   Style.AllowAllParametersOfDeclarationOnNextLine = false;
   Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
   verifyFormat("SomeClassWithALongName::Constructor(\n"
@@ -7384,6 +7440,14 @@
"

[PATCH] D143091: [clang-format] PackConstructorInitializers support PCIS_NextLineOnly

2023-02-05 Thread Zhikai Zeng via Phabricator via cfe-commits
Backl1ght updated this revision to Diff 494903.
Backl1ght added a comment.

fix typo and add release note


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143091/new/

https://reviews.llvm.org/D143091

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -7289,6 +7289,19 @@
  Style);
 verifyFormat("Constructor() : a(a), b(b) {}", Style);
 
+Style.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+verifyFormat("Constructor()\n"
+ ": (a), b(b) {}",
+ Style);
+verifyFormat("Constructor()\n"
+ ": a(a), b(b) {}",
+ Style);
+verifyFormat("Constructor()\n"
+ ": (a)\n"
+ ", b(b)\n"
+ ", cc(c) {}",
+ Style);
+
 Style.BreakConstructorInitializers = FormatStyle::BCIS_BeforeColon;
 Style.PackConstructorInitializers = FormatStyle::PCIS_NextLine;
 verifyFormat("Constructor()\n"
@@ -7301,6 +7314,19 @@
  "  b(b) {}",
  Style);
 
+Style.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+verifyFormat("Constructor()\n"
+ ": (a), b(b) {}",
+ Style);
+verifyFormat("Constructor()\n"
+ ": a(a), b(b) {}",
+ Style);
+verifyFormat("Constructor()\n"
+ ": (a),\n"
+ "  b(b),\n"
+ "  cc(c) {}",
+ Style);
+
 Style.BreakConstructorInitializers = FormatStyle::BCIS_AfterColon;
 Style.PackConstructorInitializers = FormatStyle::PCIS_NextLine;
 verifyFormat("Constructor() :\n"
@@ -7312,6 +7338,19 @@
  "aa(a),\n"
  "b(b) {}",
  Style);
+
+Style.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+verifyFormat("Constructor() :\n"
+ "aa(a), b(b) {}",
+ Style);
+verifyFormat("Constructor() :\n"
+ "a(a), b(b) {}",
+ Style);
+verifyFormat("Constructor() :\n"
+ "(a),\n"
+ "b(b),\n"
+ "cc(c) {}",
+ Style);
   }
 
   // Test interactions between AllowAllParametersOfDeclarationOnNextLine and
@@ -7319,6 +7358,7 @@
   // BreakConstructorInitializers modes
   Style.BreakConstructorInitializers = FormatStyle::BCIS_BeforeComma;
   Style.AllowAllParametersOfDeclarationOnNextLine = true;
+  Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
   verifyFormat("SomeClassWithALongName::Constructor(\n"
"int , int b)\n"
": (a)\n"
@@ -7333,6 +7373,14 @@
": (a), b(b) {}",
Style);
 
+  Style.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+  verifyFormat("SomeClassWithALongName::Constructor(\n"
+   "int ,\n"
+   "int b,\n"
+   "int )\n"
+   ": (a), b(b) {}",
+   Style);
+
   Style.AllowAllParametersOfDeclarationOnNextLine = false;
   Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
   verifyFormat("SomeClassWithALongName::Constructor(\n"
@@ -7359,6 +7407,14 @@
": (a), b(b) {}",
Style);
 
+  Style.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+  verifyFormat("SomeClassWithALongName::Constructor(\n"
+   "int ,\n"
+   "int b,\n"
+   "int )\n"
+   ": (a), b(b) {}",
+   Style);
+
   Style.AllowAllParametersOfDeclarationOnNextLine = false;
   Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
   verifyFormat("SomeClassWithALongName::Constructor(\n"
@@ -7384,6 +7440,14 @@

[PATCH] D143091: [clang-format] PackConstructorInitializers support PCIS_NextLineOnly

2023-02-06 Thread Zhikai Zeng via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc24cdd58a144: [clang-format] PackConstructorInitializers 
support PCIS_OnlyNextLine (authored by Backl1ght).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143091/new/

https://reviews.llvm.org/D143091

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -7289,6 +7289,19 @@
  Style);
 verifyFormat("Constructor() : a(a), b(b) {}", Style);
 
+Style.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+verifyFormat("Constructor()\n"
+ ": (a), b(b) {}",
+ Style);
+verifyFormat("Constructor()\n"
+ ": a(a), b(b) {}",
+ Style);
+verifyFormat("Constructor()\n"
+ ": (a)\n"
+ ", b(b)\n"
+ ", cc(c) {}",
+ Style);
+
 Style.BreakConstructorInitializers = FormatStyle::BCIS_BeforeColon;
 Style.PackConstructorInitializers = FormatStyle::PCIS_NextLine;
 verifyFormat("Constructor()\n"
@@ -7301,6 +7314,19 @@
  "  b(b) {}",
  Style);
 
+Style.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+verifyFormat("Constructor()\n"
+ ": (a), b(b) {}",
+ Style);
+verifyFormat("Constructor()\n"
+ ": a(a), b(b) {}",
+ Style);
+verifyFormat("Constructor()\n"
+ ": (a),\n"
+ "  b(b),\n"
+ "  cc(c) {}",
+ Style);
+
 Style.BreakConstructorInitializers = FormatStyle::BCIS_AfterColon;
 Style.PackConstructorInitializers = FormatStyle::PCIS_NextLine;
 verifyFormat("Constructor() :\n"
@@ -7312,6 +7338,19 @@
  "aa(a),\n"
  "b(b) {}",
  Style);
+
+Style.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+verifyFormat("Constructor() :\n"
+ "aa(a), b(b) {}",
+ Style);
+verifyFormat("Constructor() :\n"
+ "a(a), b(b) {}",
+ Style);
+verifyFormat("Constructor() :\n"
+ "(a),\n"
+ "b(b),\n"
+ "cc(c) {}",
+ Style);
   }
 
   // Test interactions between AllowAllParametersOfDeclarationOnNextLine and
@@ -7319,6 +7358,7 @@
   // BreakConstructorInitializers modes
   Style.BreakConstructorInitializers = FormatStyle::BCIS_BeforeComma;
   Style.AllowAllParametersOfDeclarationOnNextLine = true;
+  Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
   verifyFormat("SomeClassWithALongName::Constructor(\n"
"int , int b)\n"
": (a)\n"
@@ -7333,6 +7373,14 @@
": (a), b(b) {}",
Style);
 
+  Style.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+  verifyFormat("SomeClassWithALongName::Constructor(\n"
+   "int ,\n"
+   "int b,\n"
+   "int )\n"
+   ": (a), b(b) {}",
+   Style);
+
   Style.AllowAllParametersOfDeclarationOnNextLine = false;
   Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
   verifyFormat("SomeClassWithALongName::Constructor(\n"
@@ -7359,6 +7407,14 @@
": (a), b(b) {}",
Style);
 
+  Style.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+  verifyFormat("SomeClassWithALongName::Constructor(\n"
+   "int ,\n"
+   "int b,\n"
+   "int )\n"
+   ": (a), b(b) {}",
+   Style);
+
   Style.AllowAllPa

[PATCH] D141694: [clang-format] SortUsingDeclarations support lexicographic order

2023-01-13 Thread Zhikai Zeng via Phabricator via cfe-commits
Backl1ght created this revision.
Backl1ght added reviewers: MyDeveloperDay, rymiel.
Backl1ght added a project: clang-format.
Herald added a project: All.
Backl1ght requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

fix https://github.com/llvm/llvm-project/issues/59930


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141694

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/UsingDeclarationsSorter.cpp
  clang/unittests/Format/ConfigParseTest.cpp
  clang/unittests/Format/UsingDeclarationsSorterTest.cpp

Index: clang/unittests/Format/UsingDeclarationsSorterTest.cpp
===
--- clang/unittests/Format/UsingDeclarationsSorterTest.cpp
+++ clang/unittests/Format/UsingDeclarationsSorterTest.cpp
@@ -41,88 +41,162 @@
 };
 
 TEST_F(UsingDeclarationsSorterTest, SwapsTwoConsecutiveUsingDeclarations) {
+  FormatStyle Style = getLLVMStyle();
+  EXPECT_EQ(FormatStyle::SUD_LexicographicNumeric, Style.SortUsingDeclarations);
   EXPECT_EQ("using a;\n"
 "using b;",
 sortUsingDeclarations("using a;\n"
-  "using b;"));
+  "using b;",
+  Style));
   EXPECT_EQ("using a;\n"
 "using aa;",
 sortUsingDeclarations("using aa;\n"
-  "using a;"));
+  "using a;",
+  Style));
   EXPECT_EQ("using a;\n"
 "using ::a;",
 sortUsingDeclarations("using a;\n"
-  "using ::a;"));
+  "using ::a;",
+  Style));
 
   EXPECT_EQ("using a::bcd;\n"
 "using a::cd;",
 sortUsingDeclarations("using a::cd;\n"
-  "using a::bcd;"));
+  "using a::bcd;",
+  Style));
 
   EXPECT_EQ("using a;\n"
 "using a::a;",
 sortUsingDeclarations("using a::a;\n"
-  "using a;"));
+  "using a;",
+  Style));
 
   EXPECT_EQ("using a::ba::aa;\n"
 "using a::bb::ccc;",
 sortUsingDeclarations("using a::bb::ccc;\n"
-  "using a::ba::aa;"));
+  "using a::ba::aa;",
+  Style));
 
   EXPECT_EQ("using a;\n"
 "using typename a;",
 sortUsingDeclarations("using typename a;\n"
-  "using a;"));
+  "using a;",
+  Style));
 
   EXPECT_EQ("using typename z;\n"
 "using typenamea;",
 sortUsingDeclarations("using typenamea;\n"
-  "using typename z;"));
+  "using typename z;",
+  Style));
 
   EXPECT_EQ("using a, b;\n"
 "using aa;",
 sortUsingDeclarations("using aa;\n"
-  "using a, b;"));
+  "using a, b;",
+  Style));
+
+  Style.SortUsingDeclarations = FormatStyle::SUD_Lexicographic;
+  EXPECT_EQ("using a;\n"
+"using b;",
+sortUsingDeclarations("using a;\n"
+  "using b;",
+  Style));
+  EXPECT_EQ("using a;\n"
+"using aa;",
+sortUsingDeclarations("using aa;\n"
+  "using a;",
+  Style));
+  EXPECT_EQ("using a;\n"
+"using ::a;",
+sortUsingDeclarations("using a;\n"
+  "using ::a;",
+  Style));
+
+  EXPECT_EQ("using a::bcd;\n"
+"using a::cd;",
+sortUsingDeclarations("using a::cd;\n"
+  "using a::bcd;",
+  Style));
+
+  EXPECT_EQ("using a;\n"
+"using a::a;",
+sortUsingDeclarations("using a::a;\n"
+  "using a;",
+  Style));
+
+  EXPECT_EQ("using a::ba::aa;\n"
+"using a::bb::ccc;",
+sortUsingDeclarations("using a::bb::ccc;\n"
+  "using a::ba::aa;",
+  Style));
+
+  EXPECT_EQ("using a;\n"
+"using typename a;",
+sortUsingDeclarations("using typename a;\n"
+  "using a;",
+  Style));
+
+  EXPECT_EQ("using typename z;\n"
+"using ty

[PATCH] D141694: [clang-format] SortUsingDeclarations support lexicographic order

2023-01-13 Thread Zhikai Zeng via Phabricator via cfe-commits
Backl1ght updated this revision to Diff 489193.
Backl1ght added a comment.

1. Update example for SUD_Never
2. Use capital letters for variables and arguments.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141694/new/

https://reviews.llvm.org/D141694

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/UsingDeclarationsSorter.cpp
  clang/unittests/Format/ConfigParseTest.cpp
  clang/unittests/Format/UsingDeclarationsSorterTest.cpp

Index: clang/unittests/Format/UsingDeclarationsSorterTest.cpp
===
--- clang/unittests/Format/UsingDeclarationsSorterTest.cpp
+++ clang/unittests/Format/UsingDeclarationsSorterTest.cpp
@@ -41,88 +41,162 @@
 };
 
 TEST_F(UsingDeclarationsSorterTest, SwapsTwoConsecutiveUsingDeclarations) {
+  FormatStyle Style = getLLVMStyle();
+  EXPECT_EQ(FormatStyle::SUD_LexicographicNumeric, Style.SortUsingDeclarations);
   EXPECT_EQ("using a;\n"
 "using b;",
 sortUsingDeclarations("using a;\n"
-  "using b;"));
+  "using b;",
+  Style));
   EXPECT_EQ("using a;\n"
 "using aa;",
 sortUsingDeclarations("using aa;\n"
-  "using a;"));
+  "using a;",
+  Style));
   EXPECT_EQ("using a;\n"
 "using ::a;",
 sortUsingDeclarations("using a;\n"
-  "using ::a;"));
+  "using ::a;",
+  Style));
 
   EXPECT_EQ("using a::bcd;\n"
 "using a::cd;",
 sortUsingDeclarations("using a::cd;\n"
-  "using a::bcd;"));
+  "using a::bcd;",
+  Style));
 
   EXPECT_EQ("using a;\n"
 "using a::a;",
 sortUsingDeclarations("using a::a;\n"
-  "using a;"));
+  "using a;",
+  Style));
 
   EXPECT_EQ("using a::ba::aa;\n"
 "using a::bb::ccc;",
 sortUsingDeclarations("using a::bb::ccc;\n"
-  "using a::ba::aa;"));
+  "using a::ba::aa;",
+  Style));
 
   EXPECT_EQ("using a;\n"
 "using typename a;",
 sortUsingDeclarations("using typename a;\n"
-  "using a;"));
+  "using a;",
+  Style));
 
   EXPECT_EQ("using typename z;\n"
 "using typenamea;",
 sortUsingDeclarations("using typenamea;\n"
-  "using typename z;"));
+  "using typename z;",
+  Style));
 
   EXPECT_EQ("using a, b;\n"
 "using aa;",
 sortUsingDeclarations("using aa;\n"
-  "using a, b;"));
+  "using a, b;",
+  Style));
+
+  Style.SortUsingDeclarations = FormatStyle::SUD_Lexicographic;
+  EXPECT_EQ("using a;\n"
+"using b;",
+sortUsingDeclarations("using a;\n"
+  "using b;",
+  Style));
+  EXPECT_EQ("using a;\n"
+"using aa;",
+sortUsingDeclarations("using aa;\n"
+  "using a;",
+  Style));
+  EXPECT_EQ("using a;\n"
+"using ::a;",
+sortUsingDeclarations("using a;\n"
+  "using ::a;",
+  Style));
+
+  EXPECT_EQ("using a::bcd;\n"
+"using a::cd;",
+sortUsingDeclarations("using a::cd;\n"
+  "using a::bcd;",
+  Style));
+
+  EXPECT_EQ("using a;\n"
+"using a::a;",
+sortUsingDeclarations("using a::a;\n"
+  "using a;",
+  Style));
+
+  EXPECT_EQ("using a::ba::aa;\n"
+"using a::bb::ccc;",
+sortUsingDeclarations("using a::bb::ccc;\n"
+  "using a::ba::aa;",
+  Style));
+
+  EXPECT_EQ("using a;\n"
+"using typename a;",
+sortUsingDeclarations("using typename a;\n"
+  "using a;",
+  Style));
+
+  EXPECT_EQ("using typename z;\n"
+"using typenamea;",
+sortUsingDeclarations("using typenamea;\n"
+  "using typename z;",
+ 

[PATCH] D141694: [clang-format] SortUsingDeclarations support lexicographic order

2023-01-17 Thread Zhikai Zeng via Phabricator via cfe-commits
Backl1ght added a comment.

ping


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141694/new/

https://reviews.llvm.org/D141694

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141694: [clang-format] SortUsingDeclarations support lexicographic order

2023-01-20 Thread Zhikai Zeng via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG58751f943f2f: [clang-format] SortUsingDeclarations support 
lexicographic order (authored by Backl1ght).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141694/new/

https://reviews.llvm.org/D141694

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/UsingDeclarationsSorter.cpp
  clang/unittests/Format/ConfigParseTest.cpp
  clang/unittests/Format/UsingDeclarationsSorterTest.cpp

Index: clang/unittests/Format/UsingDeclarationsSorterTest.cpp
===
--- clang/unittests/Format/UsingDeclarationsSorterTest.cpp
+++ clang/unittests/Format/UsingDeclarationsSorterTest.cpp
@@ -41,88 +41,162 @@
 };
 
 TEST_F(UsingDeclarationsSorterTest, SwapsTwoConsecutiveUsingDeclarations) {
+  FormatStyle Style = getLLVMStyle();
+  EXPECT_EQ(FormatStyle::SUD_LexicographicNumeric, Style.SortUsingDeclarations);
   EXPECT_EQ("using a;\n"
 "using b;",
 sortUsingDeclarations("using a;\n"
-  "using b;"));
+  "using b;",
+  Style));
   EXPECT_EQ("using a;\n"
 "using aa;",
 sortUsingDeclarations("using aa;\n"
-  "using a;"));
+  "using a;",
+  Style));
   EXPECT_EQ("using a;\n"
 "using ::a;",
 sortUsingDeclarations("using a;\n"
-  "using ::a;"));
+  "using ::a;",
+  Style));
 
   EXPECT_EQ("using a::bcd;\n"
 "using a::cd;",
 sortUsingDeclarations("using a::cd;\n"
-  "using a::bcd;"));
+  "using a::bcd;",
+  Style));
 
   EXPECT_EQ("using a;\n"
 "using a::a;",
 sortUsingDeclarations("using a::a;\n"
-  "using a;"));
+  "using a;",
+  Style));
 
   EXPECT_EQ("using a::ba::aa;\n"
 "using a::bb::ccc;",
 sortUsingDeclarations("using a::bb::ccc;\n"
-  "using a::ba::aa;"));
+  "using a::ba::aa;",
+  Style));
 
   EXPECT_EQ("using a;\n"
 "using typename a;",
 sortUsingDeclarations("using typename a;\n"
-  "using a;"));
+  "using a;",
+  Style));
 
   EXPECT_EQ("using typename z;\n"
 "using typenamea;",
 sortUsingDeclarations("using typenamea;\n"
-  "using typename z;"));
+  "using typename z;",
+  Style));
 
   EXPECT_EQ("using a, b;\n"
 "using aa;",
 sortUsingDeclarations("using aa;\n"
-  "using a, b;"));
+  "using a, b;",
+  Style));
+
+  Style.SortUsingDeclarations = FormatStyle::SUD_Lexicographic;
+  EXPECT_EQ("using a;\n"
+"using b;",
+sortUsingDeclarations("using a;\n"
+  "using b;",
+  Style));
+  EXPECT_EQ("using a;\n"
+"using aa;",
+sortUsingDeclarations("using aa;\n"
+  "using a;",
+  Style));
+  EXPECT_EQ("using a;\n"
+"using ::a;",
+sortUsingDeclarations("using a;\n"
+  "using ::a;",
+  Style));
+
+  EXPECT_EQ("using a::bcd;\n"
+"using a::cd;",
+sortUsingDeclarations("using a::cd;\n"
+  "using a::bcd;",
+  Style));
+
+  EXPECT_EQ("using a;\n"
+"using a::a;",
+sortUsingDeclarations("using a::a;\n"
+  "using a;",
+  Style));
+
+  EXPECT_EQ("using a::ba::aa;\n"
+"using a::bb::ccc;",
+sortUsingDeclarations("using a::bb::ccc;\n"
+  "using a::ba::aa;",
+  Style));
+
+  EXPECT_EQ("using a;\n"
+"using typename a;",
+sortUsingDeclarations("using typename a;\n"
+  "using a;",
+  Style));
+
+  EXPECT_EQ("using typename z;\n"
+"using typenam

[PATCH] D139786: [clang-format] AllowShortRequiresExpressionOnASingleLine and AllowShortCompoundRequirementOnASingleLine

2022-12-11 Thread Zhikai Zeng via Phabricator via cfe-commits
Backl1ght created this revision.
Backl1ght added a reviewer: OwenCax.
Backl1ght added a project: clang-format.
Herald added a project: All.
Backl1ght requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

clang-format did not take requires into consideration, support 
AllowShortRequiresExpressionOnASingleLine and 
AllowShortCompoundRequirementOnASingleLine, add 
BrackWrapping.AfterRequiresExpression as TODO.

https://github.com/llvm/llvm-project/issues/59412


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139786

Files:
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/ConfigParseTest.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -2899,6 +2899,35 @@
Style);
 }
 
+TEST_F(FormatTest, ShortRequiresExpression) {
+  FormatStyle Style = getLLVMStyle();
+  EXPECT_TRUE(Style.AllowShortRequiresExpressionOnASingleLine);
+  verifyFormat("template \n"
+   "concept c = requires(T a, T b) { a + b; };");
+  Style.AllowShortRequiresExpressionOnASingleLine = false;
+  verifyFormat("template \n"
+   "concept c = requires(T a, T b) {\n"
+   "  a + b;\n"
+   "};");
+  // TODO: support BraceWrapping.AfterRequiresExpression.
+}
+
+TEST_F(FormatTest, ShortCompoundRequirements) {
+  FormatStyle Style = getLLVMStyle();
+  EXPECT_TRUE(Style.AllowShortCompoundRequirementOnASingleLine);
+  verifyFormat("template \n"
+   "concept c = requires(T x) {\n"
+   "  { x + 1 } -> std::same_as;\n"
+   "};");
+  Style.AllowShortCompoundRequirementOnASingleLine = false;
+  verifyFormat("template \n"
+   "concept c = requires(T x) {\n"
+   "  {\n"
+   "x + 1\n"
+   "  } -> std::same_as;\n"
+   "};");
+}
+
 TEST_F(FormatTest, ShortCaseLabels) {
   FormatStyle Style = getLLVMStyle();
   Style.AllowShortCaseLabelsOnASingleLine = true;
Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -148,6 +148,8 @@
   CHECK_PARSE_BOOL(AllowAllParametersOfDeclarationOnNextLine);
   CHECK_PARSE_BOOL(AllowShortCaseLabelsOnASingleLine);
   CHECK_PARSE_BOOL(AllowShortEnumsOnASingleLine);
+  CHECK_PARSE_BOOL(AllowShortRequiresExpressionOnASingleLine);
+  CHECK_PARSE_BOOL(AllowShortCompoundRequirementOnASingleLine);
   CHECK_PARSE_BOOL(AllowShortLoopsOnASingleLine);
   CHECK_PARSE_BOOL(BinPackArguments);
   CHECK_PARSE_BOOL(BinPackParameters);
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1085,6 +1085,12 @@
   FormatTok->setBlockKind(BK_Block);
   const FormatToken *OpeningBrace = FormatTok;
   nextToken();
+
+  if (NextLBracesType == TT_CompoundRequirementLBrace &&
+  !Style.AllowShortRequiresExpressionOnASingleLine) {
+addUnwrappedLine();
+  }
+
   {
 bool SkipIndent = (Style.isJavaScript() &&
(isGoogScope(*Line) || isIIFE(*Line, Keywords)));
@@ -1096,6 +1102,7 @@
 flushComments(isOnNewLine(*FormatTok));
 Line->Level -= SkipIndent ? 0 : 1;
   }
+
   nextToken();
 }
 
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -502,6 +502,10 @@
   // Try to merge records.
   if (TheLine->Last->is(TT_EnumLBrace)) {
 ShouldMerge = Style.AllowShortEnumsOnASingleLine;
+  } else if (TheLine->Last->is(TT_RequiresExpressionLBrace)) {
+ShouldMerge = Style.AllowShortRequiresExpressionOnASingleLine;
+  } else if (TheLine->Last->is(TT_CompoundRequirementLBrace)) {
+ShouldMerge = Style.AllowShortCompoundRequirementOnASingleLine;
   } else if (TheLine->Last->isOneOf(TT_ClassLBrace, TT_StructLBrace)) {
 // NOTE: We use AfterClass (whereas AfterStruct exists) for both classes
 // and structs, but it seems that wrapping is still handled correctly
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -808,6 +808,10 @@
Style.AllowShortCaseLabelsOnASingleLine);
 IO.mapOptional("AllowShortEnumsOnASingleLine",
Style.AllowShortEnumsOnASingleLine);
+IO.mapOptional("AllowShortRequiresExpressionOnAS

[PATCH] D139786: [clang-format] AllowShortRequiresExpressionOnASingleLine and AllowShortCompoundRequirementOnASingleLine

2022-12-11 Thread Zhikai Zeng via Phabricator via cfe-commits
Backl1ght updated this revision to Diff 481918.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139786/new/

https://reviews.llvm.org/D139786

Files:
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/ConfigParseTest.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -2899,6 +2899,35 @@
Style);
 }
 
+TEST_F(FormatTest, ShortRequiresExpression) {
+  FormatStyle Style = getLLVMStyle();
+  EXPECT_TRUE(Style.AllowShortRequiresExpressionOnASingleLine);
+  verifyFormat("template \n"
+   "concept c = requires(T a, T b) { a + b; };");
+  Style.AllowShortRequiresExpressionOnASingleLine = false;
+  verifyFormat("template \n"
+   "concept c = requires(T a, T b) {\n"
+   "  a + b;\n"
+   "};");
+  // TODO: support BraceWrapping.AfterRequiresExpression.
+}
+
+TEST_F(FormatTest, ShortCompoundRequirement) {
+  FormatStyle Style = getLLVMStyle();
+  EXPECT_TRUE(Style.AllowShortCompoundRequirementOnASingleLine);
+  verifyFormat("template \n"
+   "concept c = requires(T x) {\n"
+   "  { x + 1 } -> std::same_as;\n"
+   "};");
+  Style.AllowShortCompoundRequirementOnASingleLine = false;
+  verifyFormat("template \n"
+   "concept c = requires(T x) {\n"
+   "  {\n"
+   "x + 1\n"
+   "  } -> std::same_as;\n"
+   "};");
+}
+
 TEST_F(FormatTest, ShortCaseLabels) {
   FormatStyle Style = getLLVMStyle();
   Style.AllowShortCaseLabelsOnASingleLine = true;
Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -147,8 +147,10 @@
   CHECK_PARSE_BOOL(AllowAllArgumentsOnNextLine);
   CHECK_PARSE_BOOL(AllowAllParametersOfDeclarationOnNextLine);
   CHECK_PARSE_BOOL(AllowShortCaseLabelsOnASingleLine);
+  CHECK_PARSE_BOOL(AllowShortCompoundRequirementOnASingleLine);
   CHECK_PARSE_BOOL(AllowShortEnumsOnASingleLine);
   CHECK_PARSE_BOOL(AllowShortLoopsOnASingleLine);
+  CHECK_PARSE_BOOL(AllowShortRequiresExpressionOnASingleLine);
   CHECK_PARSE_BOOL(BinPackArguments);
   CHECK_PARSE_BOOL(BinPackParameters);
   CHECK_PARSE_BOOL(BreakAfterJavaFieldAnnotations);
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1085,6 +1085,12 @@
   FormatTok->setBlockKind(BK_Block);
   const FormatToken *OpeningBrace = FormatTok;
   nextToken();
+
+  if (NextLBracesType == TT_CompoundRequirementLBrace &&
+  !Style.AllowShortRequiresExpressionOnASingleLine) {
+addUnwrappedLine();
+  }
+
   {
 bool SkipIndent = (Style.isJavaScript() &&
(isGoogScope(*Line) || isIIFE(*Line, Keywords)));
@@ -1096,6 +1102,7 @@
 flushComments(isOnNewLine(*FormatTok));
 Line->Level -= SkipIndent ? 0 : 1;
   }
+
   nextToken();
 }
 
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -502,6 +502,10 @@
   // Try to merge records.
   if (TheLine->Last->is(TT_EnumLBrace)) {
 ShouldMerge = Style.AllowShortEnumsOnASingleLine;
+  } else if (TheLine->Last->is(TT_RequiresExpressionLBrace)) {
+ShouldMerge = Style.AllowShortRequiresExpressionOnASingleLine;
+  } else if (TheLine->Last->is(TT_CompoundRequirementLBrace)) {
+ShouldMerge = Style.AllowShortCompoundRequirementOnASingleLine;
   } else if (TheLine->Last->isOneOf(TT_ClassLBrace, TT_StructLBrace)) {
 // NOTE: We use AfterClass (whereas AfterStruct exists) for both classes
 // and structs, but it seems that wrapping is still handled correctly
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -806,6 +806,8 @@
Style.AllowShortBlocksOnASingleLine);
 IO.mapOptional("AllowShortCaseLabelsOnASingleLine",
Style.AllowShortCaseLabelsOnASingleLine);
+IO.mapOptional("AllowShortCompoundRequirementOnASingleLine",
+   Style.AllowShortCompoundRequirementOnASingleLine);
 IO.mapOptional("AllowShortEnumsOnASingleLine",
Style.AllowShortEnumsOnASingleLine);
 IO.mapOptional("AllowShortFunctionsOnASingleLine",
@@ -816,6 +818,8 @@
Style.AllowShortLambdasOnASingleLine);

[PATCH] D139786: [clang-format] AllowShortRequiresExpressionOnASingleLine

2022-12-12 Thread Zhikai Zeng via Phabricator via cfe-commits
Backl1ght updated this revision to Diff 482062.
Backl1ght retitled this revision from "[clang-format] 
AllowShortRequiresExpressionOnASingleLine and 
AllowShortCompoundRequirementOnASingleLine" to "[clang-format] 
AllowShortRequiresExpressionOnASingleLine".
Backl1ght edited the summary of this revision.
Backl1ght set the repository for this revision to rG LLVM Github Monorepo.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139786/new/

https://reviews.llvm.org/D139786

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/ConfigParseTest.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -2899,6 +2899,19 @@
Style);
 }
 
+TEST_F(FormatTest, ShortRequiresExpression) {
+  FormatStyle Style = getLLVMStyle();
+  EXPECT_TRUE(Style.AllowShortRequiresExpressionOnASingleLine);
+  verifyFormat("template \n"
+   "concept c = requires(T a, T b) { a + b; };");
+  Style.AllowShortRequiresExpressionOnASingleLine = false;
+  verifyFormat("template \n"
+   "concept c = requires(T a, T b) {\n"
+   "  a + b;\n"
+   "};");
+  // TODO: support BraceWrapping.AfterRequiresExpression.
+}
+
 TEST_F(FormatTest, ShortCaseLabels) {
   FormatStyle Style = getLLVMStyle();
   Style.AllowShortCaseLabelsOnASingleLine = true;
Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -149,6 +149,7 @@
   CHECK_PARSE_BOOL(AllowShortCaseLabelsOnASingleLine);
   CHECK_PARSE_BOOL(AllowShortEnumsOnASingleLine);
   CHECK_PARSE_BOOL(AllowShortLoopsOnASingleLine);
+  CHECK_PARSE_BOOL(AllowShortRequiresExpressionOnASingleLine);
   CHECK_PARSE_BOOL(BinPackArguments);
   CHECK_PARSE_BOOL(BinPackParameters);
   CHECK_PARSE_BOOL(BreakAfterJavaFieldAnnotations);
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1085,6 +1085,12 @@
   FormatTok->setBlockKind(BK_Block);
   const FormatToken *OpeningBrace = FormatTok;
   nextToken();
+
+  if (NextLBracesType == TT_CompoundRequirementLBrace &&
+  !Style.AllowShortRequiresExpressionOnASingleLine) {
+addUnwrappedLine();
+  }
+
   {
 bool SkipIndent = (Style.isJavaScript() &&
(isGoogScope(*Line) || isIIFE(*Line, Keywords)));
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -502,6 +502,8 @@
   // Try to merge records.
   if (TheLine->Last->is(TT_EnumLBrace)) {
 ShouldMerge = Style.AllowShortEnumsOnASingleLine;
+  } else if (TheLine->Last->is(TT_RequiresExpressionLBrace)) {
+ShouldMerge = Style.AllowShortRequiresExpressionOnASingleLine;
   } else if (TheLine->Last->isOneOf(TT_ClassLBrace, TT_StructLBrace)) {
 // NOTE: We use AfterClass (whereas AfterStruct exists) for both classes
 // and structs, but it seems that wrapping is still handled correctly
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -816,6 +816,8 @@
Style.AllowShortLambdasOnASingleLine);
 IO.mapOptional("AllowShortLoopsOnASingleLine",
Style.AllowShortLoopsOnASingleLine);
+IO.mapOptional("AllowShortRequiresExpressionOnASingleLine",
+   Style.AllowShortRequiresExpressionOnASingleLine);
 IO.mapOptional("AlwaysBreakAfterDefinitionReturnType",
Style.AlwaysBreakAfterDefinitionReturnType);
 IO.mapOptional("AlwaysBreakAfterReturnType",
@@ -1265,6 +1267,7 @@
   LLVMStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
   LLVMStyle.AllowShortLambdasOnASingleLine = FormatStyle::SLS_All;
   LLVMStyle.AllowShortLoopsOnASingleLine = false;
+  LLVMStyle.AllowShortRequiresExpressionOnASingleLine = true;
   LLVMStyle.AlwaysBreakAfterReturnType = FormatStyle::RTBS_None;
   LLVMStyle.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_None;
   LLVMStyle.AlwaysBreakBeforeMultilineStrings = false;
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -714,6 +714,21 @@
   //

[PATCH] D139786: [clang-format] AllowShortRequiresExpressionOnASingleLine

2022-12-12 Thread Zhikai Zeng via Phabricator via cfe-commits
Backl1ght updated this revision to Diff 482066.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139786/new/

https://reviews.llvm.org/D139786

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/ConfigParseTest.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -2899,6 +2899,20 @@
Style);
 }
 
+TEST_F(FormatTest, ShortRequiresExpression) {
+  FormatStyle Style = getLLVMStyle();
+  EXPECT_TRUE(Style.AllowShortRequiresExpressionOnASingleLine);
+  verifyFormat("template \n"
+   "concept c = requires(T a, T b) { a + b; };",
+   Style);
+  Style.AllowShortRequiresExpressionOnASingleLine = false;
+  verifyFormat("template \n"
+   "concept c = requires(T a, T b) {\n"
+   "  a + b;\n"
+   "};",
+   Style);
+}
+
 TEST_F(FormatTest, ShortCaseLabels) {
   FormatStyle Style = getLLVMStyle();
   Style.AllowShortCaseLabelsOnASingleLine = true;
Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -149,6 +149,7 @@
   CHECK_PARSE_BOOL(AllowShortCaseLabelsOnASingleLine);
   CHECK_PARSE_BOOL(AllowShortEnumsOnASingleLine);
   CHECK_PARSE_BOOL(AllowShortLoopsOnASingleLine);
+  CHECK_PARSE_BOOL(AllowShortRequiresExpressionOnASingleLine);
   CHECK_PARSE_BOOL(BinPackArguments);
   CHECK_PARSE_BOOL(BinPackParameters);
   CHECK_PARSE_BOOL(BreakAfterJavaFieldAnnotations);
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1085,6 +1085,12 @@
   FormatTok->setBlockKind(BK_Block);
   const FormatToken *OpeningBrace = FormatTok;
   nextToken();
+
+  if (NextLBracesType == TT_CompoundRequirementLBrace &&
+  !Style.AllowShortRequiresExpressionOnASingleLine) {
+addUnwrappedLine();
+  }
+
   {
 bool SkipIndent = (Style.isJavaScript() &&
(isGoogScope(*Line) || isIIFE(*Line, Keywords)));
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -502,6 +502,8 @@
   // Try to merge records.
   if (TheLine->Last->is(TT_EnumLBrace)) {
 ShouldMerge = Style.AllowShortEnumsOnASingleLine;
+  } else if (TheLine->Last->is(TT_RequiresExpressionLBrace)) {
+ShouldMerge = Style.AllowShortRequiresExpressionOnASingleLine;
   } else if (TheLine->Last->isOneOf(TT_ClassLBrace, TT_StructLBrace)) {
 // NOTE: We use AfterClass (whereas AfterStruct exists) for both classes
 // and structs, but it seems that wrapping is still handled correctly
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -816,6 +816,8 @@
Style.AllowShortLambdasOnASingleLine);
 IO.mapOptional("AllowShortLoopsOnASingleLine",
Style.AllowShortLoopsOnASingleLine);
+IO.mapOptional("AllowShortRequiresExpressionOnASingleLine",
+   Style.AllowShortRequiresExpressionOnASingleLine);
 IO.mapOptional("AlwaysBreakAfterDefinitionReturnType",
Style.AlwaysBreakAfterDefinitionReturnType);
 IO.mapOptional("AlwaysBreakAfterReturnType",
@@ -1265,6 +1267,7 @@
   LLVMStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
   LLVMStyle.AllowShortLambdasOnASingleLine = FormatStyle::SLS_All;
   LLVMStyle.AllowShortLoopsOnASingleLine = false;
+  LLVMStyle.AllowShortRequiresExpressionOnASingleLine = true;
   LLVMStyle.AlwaysBreakAfterReturnType = FormatStyle::RTBS_None;
   LLVMStyle.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_None;
   LLVMStyle.AlwaysBreakBeforeMultilineStrings = false;
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -714,6 +714,21 @@
   /// \version 3.7
   bool AllowShortLoopsOnASingleLine;
 
+  /// Allow short requires expression on a single line.
+  /// \code
+  ///   true:
+  ///   template 
+  ///   concept c = requires(T a, T b) { a + b; };
+  ///
+  ///   false:
+  ///   template 
+  ///   concept c = requires(T a, T b) {
+  /// a + b;
+  ///   };
+  /// \endcode
+  /// \version 16
+  bool AllowShortRequir

[PATCH] D139834: [clang-format] AllowShortCompoundRequirementOnASingleLine

2022-12-12 Thread Zhikai Zeng via Phabricator via cfe-commits
Backl1ght created this revision.
Backl1ght added reviewers: HazardyKnusperkeks, rymiel.
Backl1ght added a project: clang-format.
Herald added a project: All.
Backl1ght requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

clang-format brace wrapping did not take requires into consideration, compound 
requirements will be affected by BraceWrapping.AfterFunction.

I plan to add 3 options AllowShortRequiresExpressionOnASingleLine, 
AllowShortCompoundRequirementOnASingleLine and 
BraceWrapping.AfterRequiresExpression.

This patch is for AllowShortCompoundRequirementOnASingleLine.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139834

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -2899,6 +2899,40 @@
Style);
 }
 
+TEST_F(FormatTest, ShortCompoundRequirement) {
+  FormatStyle Style = getLLVMStyle();
+  EXPECT_TRUE(Style.AllowShortCompoundRequirementOnASingleLine);
+  verifyFormat("template \n"
+   "concept c = requires(T x) {\n"
+   "  { x + 1 } -> std::same_as;\n"
+   "};",
+   Style);
+  verifyFormat("template \n"
+   "concept c = requires(T x) {\n"
+   "  { x + 1 } -> std::same_as;\n"
+   "  { x + 2 } -> std::same_as;\n"
+   "};",
+   Style);
+  Style.AllowShortCompoundRequirementOnASingleLine = false;
+  verifyFormat("template \n"
+   "concept c = requires(T x) {\n"
+   "  {\n"
+   "x + 1\n"
+   "  } -> std::same_as;\n"
+   "};",
+   Style);
+  verifyFormat("template \n"
+   "concept c = requires(T x) {\n"
+   "  {\n"
+   "x + 1\n"
+   "  } -> std::same_as;\n"
+   "  {\n"
+   "x + 2\n"
+   "  } -> std::same_as;\n"
+   "};",
+   Style);
+}
+
 TEST_F(FormatTest, ShortCaseLabels) {
   FormatStyle Style = getLLVMStyle();
   Style.AllowShortCaseLabelsOnASingleLine = true;
Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -147,6 +147,7 @@
   CHECK_PARSE_BOOL(AllowAllArgumentsOnNextLine);
   CHECK_PARSE_BOOL(AllowAllParametersOfDeclarationOnNextLine);
   CHECK_PARSE_BOOL(AllowShortCaseLabelsOnASingleLine);
+  CHECK_PARSE_BOOL(AllowShortCompoundRequirementOnASingleLine);
   CHECK_PARSE_BOOL(AllowShortEnumsOnASingleLine);
   CHECK_PARSE_BOOL(AllowShortLoopsOnASingleLine);
   CHECK_PARSE_BOOL(BinPackArguments);
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -502,6 +502,8 @@
   // Try to merge records.
   if (TheLine->Last->is(TT_EnumLBrace)) {
 ShouldMerge = Style.AllowShortEnumsOnASingleLine;
+  } else if (TheLine->Last->is(TT_CompoundRequirementLBrace)) {
+ShouldMerge = Style.AllowShortCompoundRequirementOnASingleLine;
   } else if (TheLine->Last->isOneOf(TT_ClassLBrace, TT_StructLBrace)) {
 // NOTE: We use AfterClass (whereas AfterStruct exists) for both classes
 // and structs, but it seems that wrapping is still handled correctly
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -806,6 +806,8 @@
Style.AllowShortBlocksOnASingleLine);
 IO.mapOptional("AllowShortCaseLabelsOnASingleLine",
Style.AllowShortCaseLabelsOnASingleLine);
+IO.mapOptional("AllowShortCompoundRequirementOnASingleLine",
+   Style.AllowShortCompoundRequirementOnASingleLine);
 IO.mapOptional("AllowShortEnumsOnASingleLine",
Style.AllowShortEnumsOnASingleLine);
 IO.mapOptional("AllowShortFunctionsOnASingleLine",
@@ -1260,6 +1262,7 @@
   LLVMStyle.AllowAllParametersOfDeclarationOnNextLine = true;
   LLVMStyle.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Never;
   LLVMStyle.AllowShortCaseLabelsOnASingleLine = false;
+  LLVMStyle.AllowShortCompoundRequirementOnASingleLine = true;
   LLVMStyle.AllowShortEnumsOnASingleLine = true;
   LLVMStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All;
   LLVMStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
Index: clang/includ

[PATCH] D139786: [clang-format] AllowShortRequiresExpressionOnASingleLine

2022-12-12 Thread Zhikai Zeng via Phabricator via cfe-commits
Backl1ght added a comment.

I just find out I miss one case like below

  template
  concept c = requires(T x) { { x + 1 } -> std::same_as; };

Since I split AllowShortRequiresExpressionOnASingleLine and 
AllowShortCompoundRequirementOnASingleLine into two pathes, I can not fix this 
until AllowShortCompoundRequirementOnASingleLine got merged.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139786/new/

https://reviews.llvm.org/D139786

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139834: [clang-format] AllowShortCompoundRequirementOnASingleLine

2022-12-13 Thread Zhikai Zeng via Phabricator via cfe-commits
Backl1ght added inline comments.



Comment at: clang/lib/Format/Format.cpp:809
Style.AllowShortCaseLabelsOnASingleLine);
+IO.mapOptional("AllowShortCompoundRequirementOnASingleLine",
+   Style.AllowShortCompoundRequirementOnASingleLine);

MyDeveloperDay wrote:
> haven't we use "Requires" in other options? What is the definition of 
> Compound?
> 
> I might be tempted for this to be AllShortRequiresOnASingleLine but then it 
> be an enum with the following options
> 
> ```
> Leave
> Never
> Always
> Compound
> ```
There are some options related to requires like IndentRequiresClause, 
RequiresClausePosition, etc. But as for single line and brace wrapping, 
requires is not yet considered.

"Compound" is from Compound Requirements section in this page 
https://en.cppreference.com/w/cpp/language/requires

I think this is a better way, I would try implementing it.



Comment at: clang/lib/Format/Format.cpp:1265
   LLVMStyle.AllowShortCaseLabelsOnASingleLine = false;
+  LLVMStyle.AllowShortCompoundRequirementOnASingleLine = true;
   LLVMStyle.AllowShortEnumsOnASingleLine = true;

MyDeveloperDay wrote:
> why would the default be true, is that what happens today?
yes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139834/new/

https://reviews.llvm.org/D139834

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139937: [clang-format] fix typo in doc for SLS_Inline

2022-12-13 Thread Zhikai Zeng via Phabricator via cfe-commits
Backl1ght created this revision.
Backl1ght added reviewers: HazardyKnusperkeks, MyDeveloperDay.
Backl1ght added a project: clang-format.
Herald added a project: All.
Backl1ght requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139937

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h


Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -688,7 +688,7 @@
 ///   };
 /// \endcode
 SLS_Empty,
-/// Merge lambda into a single line if argument of a function.
+/// Merge lambda into a single line if argument of a function is empty.
 /// \code
 ///   auto lambda = [](int a) {
 ///   return a;
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -1191,7 +1191,7 @@
   };
 
   * ``SLS_Inline`` (in configuration: ``Inline``)
-Merge lambda into a single line if argument of a function.
+Merge lambda into a single line if argument of a function is empty.
 
 .. code-block:: c++
 


Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -688,7 +688,7 @@
 ///   };
 /// \endcode
 SLS_Empty,
-/// Merge lambda into a single line if argument of a function.
+/// Merge lambda into a single line if argument of a function is empty.
 /// \code
 ///   auto lambda = [](int a) {
 ///   return a;
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -1191,7 +1191,7 @@
   };
 
   * ``SLS_Inline`` (in configuration: ``Inline``)
-Merge lambda into a single line if argument of a function.
+Merge lambda into a single line if argument of a function is empty.
 
 .. code-block:: c++
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139937: [clang-format] fix typo in doc for SLS_Inline

2022-12-13 Thread Zhikai Zeng via Phabricator via cfe-commits
Backl1ght added a comment.

OMG! I just looked into git history and last edition of this line happened 
about 4 years ago. Am I doing it wrong?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139937/new/

https://reviews.llvm.org/D139937

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139937: [clang-format] fix typo in doc for SLS_Inline

2022-12-13 Thread Zhikai Zeng via Phabricator via cfe-commits
Backl1ght added a comment.

Seems like I have misunderstood it, after some test I'm sure that it means 
merge if its an argument of a function.

I think there are something todo to make the doc more clearly.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139937/new/

https://reviews.llvm.org/D139937

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139937: [clang-format] make doc for SLS_Inline more clearly

2022-12-13 Thread Zhikai Zeng via Phabricator via cfe-commits
Backl1ght updated this revision to Diff 482530.
Backl1ght retitled this revision from "[clang-format] fix typo in doc for 
SLS_Inline" to "[clang-format] make doc for SLS_Inline more clearly".

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139937/new/

https://reviews.llvm.org/D139937

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h


Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -688,12 +688,12 @@
 ///   };
 /// \endcode
 SLS_Empty,
-/// Merge lambda into a single line if argument of a function.
+/// Merge lambda into a single line if the lambda is argument of a 
function.
 /// \code
-///   auto lambda = [](int a) {
-///   return a;
+///   auto lambda = [](int x, int y) {
+///   return x < y;
 ///   };
-///   sort(a.begin(), a.end(), []() { return x < y; });
+///   sort(a.begin(), a.end(), [](int x, int y) { return x < y; });
 /// \endcode
 SLS_Inline,
 /// Merge all lambdas fitting on a single line.
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -1191,14 +1191,14 @@
   };
 
   * ``SLS_Inline`` (in configuration: ``Inline``)
-Merge lambda into a single line if argument of a function.
+Merge lambda into a single line if the lambda is argument of a function.
 
 .. code-block:: c++
 
-  auto lambda = [](int a) {
-  return a;
+  auto lambda = [](int x, int y) {
+  return x < y;
   };
-  sort(a.begin(), a.end(), []() { return x < y; });
+  sort(a.begin(), a.end(), [](int x, int y) { return x < y; });
 
   * ``SLS_All`` (in configuration: ``All``)
 Merge all lambdas fitting on a single line.


Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -688,12 +688,12 @@
 ///   };
 /// \endcode
 SLS_Empty,
-/// Merge lambda into a single line if argument of a function.
+/// Merge lambda into a single line if the lambda is argument of a function.
 /// \code
-///   auto lambda = [](int a) {
-///   return a;
+///   auto lambda = [](int x, int y) {
+///   return x < y;
 ///   };
-///   sort(a.begin(), a.end(), []() { return x < y; });
+///   sort(a.begin(), a.end(), [](int x, int y) { return x < y; });
 /// \endcode
 SLS_Inline,
 /// Merge all lambdas fitting on a single line.
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -1191,14 +1191,14 @@
   };
 
   * ``SLS_Inline`` (in configuration: ``Inline``)
-Merge lambda into a single line if argument of a function.
+Merge lambda into a single line if the lambda is argument of a function.
 
 .. code-block:: c++
 
-  auto lambda = [](int a) {
-  return a;
+  auto lambda = [](int x, int y) {
+  return x < y;
   };
-  sort(a.begin(), a.end(), []() { return x < y; });
+  sort(a.begin(), a.end(), [](int x, int y) { return x < y; });
 
   * ``SLS_All`` (in configuration: ``All``)
 Merge all lambdas fitting on a single line.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139937: [clang-format] make doc for SLS_Inline more clearly

2022-12-13 Thread Zhikai Zeng via Phabricator via cfe-commits
Backl1ght added a comment.

In D139937#3992987 , 
@HazardyKnusperkeks wrote:

> In D139937#3992098 , @Backl1ght 
> wrote:
>
>> OMG! I just looked into git history and last edition of this line happened 
>> about 4 years ago. Am I doing it wrong?
>
> Why? We have lambdas since C++11 so 11 years now.

Based on the git history 
,
 last edition of this line happened on a83e2db 
.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139937/new/

https://reviews.llvm.org/D139937

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139937: [clang-format] make doc for SLS_Inline more clearly

2022-12-14 Thread Zhikai Zeng via Phabricator via cfe-commits
Backl1ght added a comment.

In D139937#3994044 , 
@HazardyKnusperkeks wrote:

> In D139937#3993641 , @Backl1ght 
> wrote:
>
>> In D139937#3992987 , 
>> @HazardyKnusperkeks wrote:
>>
>>> In D139937#3992098 , @Backl1ght 
>>> wrote:
>>>
 OMG! I just looked into git history and last edition of this line happened 
 about 4 years ago. Am I doing it wrong?
>>>
>>> Why? We have lambdas since C++11 so 11 years now.
>>
>> Based on the git history 
>> ,
>>  last edition of this line happened on a83e2db 
>> .
>
> Let me rephrase it. Why should you think that you do it wrong?

I don't think such typo can exist for 4 years so I think maybe I understand it 
wrongly. And it turned out that I do understand it in the wrong way.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139937/new/

https://reviews.llvm.org/D139937

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139937: [clang-format] make doc for SLS_Inline more clearly

2022-12-14 Thread Zhikai Zeng via Phabricator via cfe-commits
Backl1ght added a comment.

In D139937#3994044 , 
@HazardyKnusperkeks wrote:

> In D139937#3993641 , @Backl1ght 
> wrote:
>
>> In D139937#3992987 , 
>> @HazardyKnusperkeks wrote:
>>
>>> In D139937#3992098 , @Backl1ght 
>>> wrote:
>>>
 OMG! I just looked into git history and last edition of this line happened 
 about 4 years ago. Am I doing it wrong?
>>>
>>> Why? We have lambdas since C++11 so 11 years now.
>>
>> Based on the git history 
>> ,
>>  last edition of this line happened on a83e2db 
>> .
>
> Let me rephrase it. Why should you think that you do it wrong?

For "Am I doing it wrong" I mean I am not sure if what I do in diff1 is correct.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139937/new/

https://reviews.llvm.org/D139937

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139937: [clang-format] make doc for SLS_Inline more clearly

2022-12-15 Thread Zhikai Zeng via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7b36538156b7: [clang-format] make doc for SLS_Inline more 
clearly (authored by Backl1ght).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139937/new/

https://reviews.llvm.org/D139937

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h


Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -688,12 +688,12 @@
 ///   };
 /// \endcode
 SLS_Empty,
-/// Merge lambda into a single line if argument of a function.
+/// Merge lambda into a single line if the lambda is argument of a 
function.
 /// \code
-///   auto lambda = [](int a) {
-///   return a;
+///   auto lambda = [](int x, int y) {
+///   return x < y;
 ///   };
-///   sort(a.begin(), a.end(), []() { return x < y; });
+///   sort(a.begin(), a.end(), [](int x, int y) { return x < y; });
 /// \endcode
 SLS_Inline,
 /// Merge all lambdas fitting on a single line.
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -1191,14 +1191,14 @@
   };
 
   * ``SLS_Inline`` (in configuration: ``Inline``)
-Merge lambda into a single line if argument of a function.
+Merge lambda into a single line if the lambda is argument of a function.
 
 .. code-block:: c++
 
-  auto lambda = [](int a) {
-  return a;
+  auto lambda = [](int x, int y) {
+  return x < y;
   };
-  sort(a.begin(), a.end(), []() { return x < y; });
+  sort(a.begin(), a.end(), [](int x, int y) { return x < y; });
 
   * ``SLS_All`` (in configuration: ``All``)
 Merge all lambdas fitting on a single line.


Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -688,12 +688,12 @@
 ///   };
 /// \endcode
 SLS_Empty,
-/// Merge lambda into a single line if argument of a function.
+/// Merge lambda into a single line if the lambda is argument of a function.
 /// \code
-///   auto lambda = [](int a) {
-///   return a;
+///   auto lambda = [](int x, int y) {
+///   return x < y;
 ///   };
-///   sort(a.begin(), a.end(), []() { return x < y; });
+///   sort(a.begin(), a.end(), [](int x, int y) { return x < y; });
 /// \endcode
 SLS_Inline,
 /// Merge all lambdas fitting on a single line.
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -1191,14 +1191,14 @@
   };
 
   * ``SLS_Inline`` (in configuration: ``Inline``)
-Merge lambda into a single line if argument of a function.
+Merge lambda into a single line if the lambda is argument of a function.
 
 .. code-block:: c++
 
-  auto lambda = [](int a) {
-  return a;
+  auto lambda = [](int x, int y) {
+  return x < y;
   };
-  sort(a.begin(), a.end(), []() { return x < y; });
+  sort(a.begin(), a.end(), [](int x, int y) { return x < y; });
 
   * ``SLS_All`` (in configuration: ``All``)
 Merge all lambdas fitting on a single line.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140105: [clang-format] add missing config parse test for short lambda

2022-12-15 Thread Zhikai Zeng via Phabricator via cfe-commits
Backl1ght created this revision.
Backl1ght added a project: clang-format.
Herald added a project: All.
Backl1ght requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140105

Files:
  clang/unittests/Format/ConfigParseTest.cpp


Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -533,6 +533,20 @@
   CHECK_PARSE("AllowShortFunctionsOnASingleLine: true",
   AllowShortFunctionsOnASingleLine, FormatStyle::SFS_All);
 
+  Style.AllowShortLambdasOnASingleLine = FormatStyle::SLS_All;
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: None",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_None);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: Empty",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_Empty);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: Inline",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_Inline);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: All",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_All);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: false",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_None);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: true",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_All);
+
   Style.SpaceAroundPointerQualifiers = FormatStyle::SAPQ_Both;
   CHECK_PARSE("SpaceAroundPointerQualifiers: Default",
   SpaceAroundPointerQualifiers, FormatStyle::SAPQ_Default);


Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -533,6 +533,20 @@
   CHECK_PARSE("AllowShortFunctionsOnASingleLine: true",
   AllowShortFunctionsOnASingleLine, FormatStyle::SFS_All);
 
+  Style.AllowShortLambdasOnASingleLine = FormatStyle::SLS_All;
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: None",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_None);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: Empty",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_Empty);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: Inline",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_Inline);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: All",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_All);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: false",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_None);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: true",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_All);
+
   Style.SpaceAroundPointerQualifiers = FormatStyle::SAPQ_Both;
   CHECK_PARSE("SpaceAroundPointerQualifiers: Default",
   SpaceAroundPointerQualifiers, FormatStyle::SAPQ_Default);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140105: [clang-format] add missing config parse test for short lambda

2022-12-16 Thread Zhikai Zeng via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG95c1a17433b9: [clang-format] add config parse test for short 
lambda (authored by Backl1ght).

Changed prior to commit:
  https://reviews.llvm.org/D140105?vs=483170&id=483503#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140105/new/

https://reviews.llvm.org/D140105

Files:
  clang/unittests/Format/ConfigParseTest.cpp


Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -533,6 +533,21 @@
   CHECK_PARSE("AllowShortFunctionsOnASingleLine: true",
   AllowShortFunctionsOnASingleLine, FormatStyle::SFS_All);
 
+  Style.AllowShortLambdasOnASingleLine = FormatStyle::SLS_All;
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: None",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_None);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: Empty",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_Empty);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: Inline",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_Inline);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: All",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_All);
+  // For backward compatibility:
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: false",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_None);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: true",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_All);
+
   Style.SpaceAroundPointerQualifiers = FormatStyle::SAPQ_Both;
   CHECK_PARSE("SpaceAroundPointerQualifiers: Default",
   SpaceAroundPointerQualifiers, FormatStyle::SAPQ_Default);


Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -533,6 +533,21 @@
   CHECK_PARSE("AllowShortFunctionsOnASingleLine: true",
   AllowShortFunctionsOnASingleLine, FormatStyle::SFS_All);
 
+  Style.AllowShortLambdasOnASingleLine = FormatStyle::SLS_All;
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: None",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_None);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: Empty",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_Empty);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: Inline",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_Inline);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: All",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_All);
+  // For backward compatibility:
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: false",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_None);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: true",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_All);
+
   Style.SpaceAroundPointerQualifiers = FormatStyle::SAPQ_Both;
   CHECK_PARSE("SpaceAroundPointerQualifiers: Default",
   SpaceAroundPointerQualifiers, FormatStyle::SAPQ_Default);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits