[PATCH] D129443: [clang-format] Add option for aligning requires clause body

2022-07-10 Thread Danil Sidoruk via Phabricator via cfe-commits
eoanermine created this revision.
eoanermine added projects: clang, clang-format.
Herald added a project: All.
eoanermine requested review of this revision.
Herald added a subscriber: cfe-commits.

- Add an option whether requires clause body should be aligned with `requires` 
keyword

Fixes https://github.com/llvm/llvm-project/issues/56283


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129443

Files:
  clang/include/clang/Format/Format.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/Format.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -20033,6 +20033,7 @@
 TEST_F(FormatTest, ParsesConfigurationBools) {
   FormatStyle Style = {};
   Style.Language = FormatStyle::LK_Cpp;
+  CHECK_PARSE_BOOL(AlignRequiresClauseBody);
   CHECK_PARSE_BOOL(AlignTrailingComments);
   CHECK_PARSE_BOOL(AllowAllArgumentsOnNextLine);
   CHECK_PARSE_BOOL(AllowAllParametersOfDeclarationOnNextLine);
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -646,6 +646,7 @@
 IO.mapOptional("AlignConsecutiveMacros", Style.AlignConsecutiveMacros);
 IO.mapOptional("AlignEscapedNewlines", Style.AlignEscapedNewlines);
 IO.mapOptional("AlignOperands", Style.AlignOperands);
+IO.mapOptional("AlignRequiresClauseBody", Style.AlignRequiresClauseBody);
 IO.mapOptional("AlignTrailingComments", Style.AlignTrailingComments);
 IO.mapOptional("AllowAllArgumentsOnNextLine",
Style.AllowAllArgumentsOnNextLine);
@@ -1181,6 +1182,7 @@
   LLVMStyle.AlignAfterOpenBracket = FormatStyle::BAS_Align;
   LLVMStyle.AlignArrayOfStructures = FormatStyle::AIAS_None;
   LLVMStyle.AlignOperands = FormatStyle::OAS_Align;
+  LLVMStyle.AlignRequiresClauseBody = true;
   LLVMStyle.AlignTrailingComments = true;
   LLVMStyle.AlignConsecutiveAssignments = {};
   LLVMStyle.AlignConsecutiveAssignments.Enabled = false;
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -1398,7 +1398,7 @@
 CurrentState.NestedBlockIndent = State.Column + Current.ColumnWidth + 1;
   if (Current.isOneOf(TT_LambdaLSquare, TT_LambdaArrow))
 CurrentState.LastSpace = State.Column;
-  if (Current.is(TT_RequiresExpression))
+  if (Current.is(TT_RequiresExpression) && Style.AlignRequiresClauseBody)
 CurrentState.NestedBlockIndent = State.Column;
 
   // Insert scopes created by fake parenthesis.
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -369,6 +369,17 @@
   /// \version 3.5
   OperandAlignmentStyle AlignOperands;
 
+  /// If ``true``, aligns requires clause bodies with `requires` keyword.
+  /// \code
+  ///   true:   false:
+  ///   templatetemplate 
+  ///   concept C = requires(T t) {  vs.concept C = requires(T t) {
+  /// ... ...
+  ///   }   }
+  /// \endcode
+  /// \version 15
+  bool AlignRequiresClauseBody;
+
   /// If ``true``, aligns trailing comments.
   /// \code
   ///   true:   false:
@@ -3856,6 +3867,7 @@
AlignConsecutiveMacros == R.AlignConsecutiveMacros &&
AlignEscapedNewlines == R.AlignEscapedNewlines &&
AlignOperands == R.AlignOperands &&
+   AlignRequiresClauseBody == R.AlignRequiresClauseBody &&
AlignTrailingComments == R.AlignTrailingComments &&
AllowAllArgumentsOnNextLine == R.AllowAllArgumentsOnNextLine &&
AllowAllParametersOfDeclarationOnNextLine ==


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -20033,6 +20033,7 @@
 TEST_F(FormatTest, ParsesConfigurationBools) {
   FormatStyle Style = {};
   Style.Language = FormatStyle::LK_Cpp;
+  CHECK_PARSE_BOOL(AlignRequiresClauseBody);
   CHECK_PARSE_BOOL(AlignTrailingComments);
   CHECK_PARSE_BOOL(AllowAllArgumentsOnNextLine);
   CHECK_PARSE_BOOL(AllowAllParametersOfDeclarationOnNextLine);
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -646,6 +646,7 @@
 IO.mapOptional("AlignConsecutiveMacros", Style.AlignConsecutiveMacros);
 IO.mapOptional("AlignEscapedNewlines", Style.AlignEscapedNewlines);
 IO.mapOptional("Ali

[PATCH] D129443: [clang-format] Add option for aligning requires clause body

2022-07-12 Thread Danil Sidoruk via Phabricator via cfe-commits
eoanermine added a comment.

In D129443#3641571 , @curdeius wrote:

> Haven't you forgotten to add formatting tests? :)

Yes, I have. Thank you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129443

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


[PATCH] D129443: [clang-format] Add option for aligning requires clause body

2022-07-12 Thread Danil Sidoruk via Phabricator via cfe-commits
eoanermine updated this revision to Diff 443895.
eoanermine added a comment.

Add tests for AlignRequiresClauseBody option


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129443

Files:
  clang/include/clang/Format/Format.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/Format.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -20033,6 +20033,7 @@
 TEST_F(FormatTest, ParsesConfigurationBools) {
   FormatStyle Style = {};
   Style.Language = FormatStyle::LK_Cpp;
+  CHECK_PARSE_BOOL(AlignRequiresClauseBody);
   CHECK_PARSE_BOOL(AlignTrailingComments);
   CHECK_PARSE_BOOL(AllowAllArgumentsOnNextLine);
   CHECK_PARSE_BOOL(AllowAllParametersOfDeclarationOnNextLine);
@@ -24719,6 +24720,74 @@
"bar(requires);");
 }
 
+TEST_F(FormatTest, AlignRequiresClauseBody) {
+  auto Style = getLLVMStyle();
+  EXPECT_EQ(Style.AlignRequiresClauseBody, true);
+
+  verifyFormat("template \n"
+   "concept C = requires(T t) {\n"
+   "  typename T::value;\n"
+   "  requires requires(typename T::value v) {\n"
+   " { t == v } -> std::same_as;\n"
+   "   };\n"
+   "};",
+   Style);
+
+  verifyFormat(
+  "template \n"
+  "void bar(T)\n"
+  "  requires Foo && requires(T t) {\n"
+  "   { t.foo() } -> std::same_as;\n"
+  " } && requires(T t) {\n"
+  "{ t.bar() } -> std::same_as;\n"
+  "--t;\n"
+  "  };",
+  Style);
+
+  verifyFormat("template \n"
+   "  requires Foo &&\n"
+   "   requires(T t) {\n"
+   " { t.foo() } -> std::same_as;\n"
+   "   } && requires(T t) {\n"
+   "  { t.bar() } -> std::same_as;\n"
+   "  --t;\n"
+   "}\n"
+   "void bar(T);",
+   Style);
+
+  Style.AlignRequiresClauseBody = false;
+
+  verifyFormat("template \n"
+   "concept C = requires(T t) {\n"
+   "  typename T::value;\n"
+   "  requires requires(typename T::value v) {\n"
+   "{ t == v } -> std::same_as;\n"
+   "  };\n"
+   "};",
+   Style);
+
+  verifyFormat("template \n"
+   "void bar(T)\n"
+   "  requires Foo && requires(T t) {\n"
+   "{ t.foo() } -> std::same_as;\n"
+   "  } && requires(T t) {\n"
+   "{ t.bar() } -> std::same_as;\n"
+   "--t;\n"
+   "  };",
+   Style);
+
+  verifyFormat("template \n"
+   "  requires Foo &&\n"
+   "   requires(T t) {\n"
+   " { t.foo() } -> std::same_as;\n"
+   "   } && requires(T t) {\n"
+   " { t.bar() } -> std::same_as;\n"
+   " --t;\n"
+   "   }\n"
+   "void bar(T);",
+   Style);
+}
+
 TEST_F(FormatTest, StatementAttributeLikeMacros) {
   FormatStyle Style = getLLVMStyle();
   StringRef Source = "void Foo::slot() {\n"
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -646,6 +646,7 @@
 IO.mapOptional("AlignConsecutiveMacros", Style.AlignConsecutiveMacros);
 IO.mapOptional("AlignEscapedNewlines", Style.AlignEscapedNewlines);
 IO.mapOptional("AlignOperands", Style.AlignOperands);
+IO.mapOptional("AlignRequiresClauseBody", Style.AlignRequiresClauseBody);
 IO.mapOptional("AlignTrailingComments", Style.AlignTrailingComments);
 IO.mapOptional("AllowAllArgumentsOnNextLine",
Style.AllowAllArgumentsOnNextLine);
@@ -1181,6 +1182,7 @@
   LLVMStyle.AlignAfterOpenBracket = FormatStyle::BAS_Align;
   LLVMStyle.AlignArrayOfStructures = FormatStyle::AIAS_None;
   LLVMStyle.AlignOperands = FormatStyle::OAS_Align;
+  LLVMStyle.AlignRequiresClauseBody = true;
   LLVMStyle.AlignTrailingComments = true;
   LLVMStyle.AlignConsecutiveAssignments = {};
   LLVMStyle.AlignConsecutiveAssignments.Enabled = false;
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -1398,7 +1398,7 @@
 CurrentState.NestedBlockIndent = State.Column + Current.ColumnWidth + 1;
   if (Current.

[PATCH] D129443: [clang-format] Add option for aligning requires clause body

2022-07-12 Thread Danil Sidoruk via Phabricator via cfe-commits
eoanermine added a comment.

In D129443#3644795 , @eoanermine 
wrote:

> Add tests for AlignRequiresClauseBody option

Are these tests fine?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129443

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


[PATCH] D129628: Fix aligning of java-style declarations

2022-07-13 Thread Danil Sidoruk via Phabricator via cfe-commits
eoanermine created this revision.
eoanermine added reviewers: MyDeveloperDay, owenpan, HazardyKnusperkeks, 
curdeius.
eoanermine added projects: clang, clang-format.
Herald added a project: All.
eoanermine requested review of this revision.
Herald added a subscriber: cfe-commits.

- Modify TokenAnnotator to work fine with java-style array declarations
- Add test for aligning of java declarations


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129628

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


Index: clang/unittests/Format/FormatTestJava.cpp
===
--- clang/unittests/Format/FormatTestJava.cpp
+++ clang/unittests/Format/FormatTestJava.cpp
@@ -584,6 +584,17 @@
"  void f() {}"));
 }
 
+TEST_F(FormatTestJava, AlignDeclarations) {
+  FormatStyle Style = getLLVMStyle(FormatStyle::LK_Java);
+  Style.AlignConsecutiveDeclarations.Enabled = true;
+  verifyFormat("private final String[]   args;\n"
+   "private final A_ParserHelper parserHelper;\n"
+   "private final intnumOfCmdArgs;\n"
+   "private int  numOfCmdArgs;\n"
+   "private String[] args;",
+   Style);
+}
+
 TEST_F(FormatTestJava, KeepsDelimitersOnOwnLineInJavaDocComments) {
   EXPECT_EQ("/**\n"
 " * javadoc line 1\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2028,6 +2028,11 @@
 if (PreviousNotConst->isSimpleTypeSpecifier())
   return true;
 
+// type[] a in Java
+if (Style.Language == FormatStyle::LK_Java &&
+PreviousNotConst->is(tok::r_square))
+  return true;
+
 // const a = in JavaScript.
 return Style.isJavaScript() && PreviousNotConst->is(tok::kw_const);
   }


Index: clang/unittests/Format/FormatTestJava.cpp
===
--- clang/unittests/Format/FormatTestJava.cpp
+++ clang/unittests/Format/FormatTestJava.cpp
@@ -584,6 +584,17 @@
"  void f() {}"));
 }
 
+TEST_F(FormatTestJava, AlignDeclarations) {
+  FormatStyle Style = getLLVMStyle(FormatStyle::LK_Java);
+  Style.AlignConsecutiveDeclarations.Enabled = true;
+  verifyFormat("private final String[]   args;\n"
+   "private final A_ParserHelper parserHelper;\n"
+   "private final intnumOfCmdArgs;\n"
+   "private int  numOfCmdArgs;\n"
+   "private String[] args;",
+   Style);
+}
+
 TEST_F(FormatTestJava, KeepsDelimitersOnOwnLineInJavaDocComments) {
   EXPECT_EQ("/**\n"
 " * javadoc line 1\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2028,6 +2028,11 @@
 if (PreviousNotConst->isSimpleTypeSpecifier())
   return true;
 
+// type[] a in Java
+if (Style.Language == FormatStyle::LK_Java &&
+PreviousNotConst->is(tok::r_square))
+  return true;
+
 // const a = in JavaScript.
 return Style.isJavaScript() && PreviousNotConst->is(tok::kw_const);
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129628: Fix aligning of java-style declarations

2022-07-13 Thread Danil Sidoruk via Phabricator via cfe-commits
eoanermine added a comment.

I found that the problem was that `TokenAnnotator` doesn't handle Java-style 
array declarations fine. It doesn't consider identifier after square brackets 
as a StartOfName.

I fixed it, it seems valid, but I'm not a hundred percent sure about it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129628

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


[PATCH] D129443: [clang-format] Add option for aligning requires clause body

2022-07-14 Thread Danil Sidoruk via Phabricator via cfe-commits
eoanermine updated this revision to Diff 444556.
eoanermine edited the summary of this revision.
eoanermine added a comment.

- Rename AlignRequiresClauseBody to RequiresExpressionIndentation
- Introduce RequiresExpressionIndentationKind as a type of 
RequiresExpressionIndentation
- Add more tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129443

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -24719,6 +24719,106 @@
"bar(requires);");
 }
 
+TEST_F(FormatTest, RequiresExpressionIndentation) {
+  auto Style = getLLVMStyle();
+  EXPECT_EQ(Style.RequiresExpressionIndentation, FormatStyle::REI_Keyword);
+
+  verifyFormat("template \n"
+   "concept C = requires(T t) {\n"
+   "  typename T::value;\n"
+   "  requires requires(typename T::value v) {\n"
+   " { t == v } -> std::same_as;\n"
+   "   };\n"
+   "};",
+   Style);
+
+  verifyFormat(
+  "template \n"
+  "void bar(T)\n"
+  "  requires Foo && requires(T t) {\n"
+  "   { t.foo() } -> std::same_as;\n"
+  " } && requires(T t) {\n"
+  "{ t.bar() } -> std::same_as;\n"
+  "--t;\n"
+  "  };",
+  Style);
+
+  verifyFormat("template \n"
+   "  requires Foo &&\n"
+   "   requires(T t) {\n"
+   " { t.foo() } -> std::same_as;\n"
+   "   } && requires(T t) {\n"
+   "  { t.bar() } -> std::same_as;\n"
+   "  --t;\n"
+   "}\n"
+   "void bar(T);",
+   Style);
+
+  verifyFormat("template  void f() {\n"
+   "  if constexpr (requires(T t) {\n"
+   "  { t.bar() } -> std::same_as;\n"
+   "}) {\n"
+   "  }\n"
+   "}",
+   Style);
+
+  verifyFormat("template  struct C {\n"
+   "  void f()\n"
+   "requires requires(T t) {\n"
+   "   { t.bar() } -> std::same_as;\n"
+   " };\n"
+   "};",
+   Style);
+
+  Style.RequiresExpressionIndentation = FormatStyle::REI_OuterScope;
+
+  verifyFormat("template \n"
+   "concept C = requires(T t) {\n"
+   "  typename T::value;\n"
+   "  requires requires(typename T::value v) {\n"
+   "{ t == v } -> std::same_as;\n"
+   "  };\n"
+   "};",
+   Style);
+
+  verifyFormat("template \n"
+   "void bar(T)\n"
+   "  requires Foo && requires(T t) {\n"
+   "{ t.foo() } -> std::same_as;\n"
+   "  } && requires(T t) {\n"
+   "{ t.bar() } -> std::same_as;\n"
+   "--t;\n"
+   "  };",
+   Style);
+
+  verifyFormat("template \n"
+   "  requires Foo &&\n"
+   "   requires(T t) {\n"
+   " { t.foo() } -> std::same_as;\n"
+   "   } && requires(T t) {\n"
+   " { t.bar() } -> std::same_as;\n"
+   " --t;\n"
+   "   }\n"
+   "void bar(T);",
+   Style);
+
+  verifyFormat("template  void f() {\n"
+   "  if constexpr (requires(T t) {\n"
+   "  { t.bar() } -> std::same_as;\n"
+   "}) {\n"
+   "  }\n"
+   "}",
+   Style);
+
+  verifyFormat("template  struct C {\n"
+   "  void f()\n"
+   "requires requires(T t) {\n"
+   "  { t.bar() } -> std::same_as;\n"
+   "};\n"
+   "};",
+   Style);
+}
+
 TEST_F(FormatTest, StatementAttributeLikeMacros) {
   FormatStyle Style = getLLVMStyle();
   StringRef Source = "void Foo::slot() {\n"
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -99,6 +99,15 @@
   }
 };
 
+template <>
+struct ScalarEnumerationTraits {
+  static void
+  enumeration(IO &IO, FormatStyle::RequiresExpressionIndentationKind &Value) {
+IO.enumCase(Value, "Keyword", 

[PATCH] D129845: Allow custom attributes in access specifiers

2022-07-15 Thread Danil Sidoruk via Phabricator via cfe-commits
eoanermine created this revision.
eoanermine added reviewers: owenpan, HazardyKnusperkeks, curdeius.
eoanermine added projects: clang, clang-format.
Herald added a project: All.
eoanermine requested review of this revision.
Herald added a subscriber: cfe-commits.

- Allow custom attributes in access specifiers
- Add tests for custom attributes in access specifiers
- Add more tests for correct handling of Qt's signals and slots


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129845

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -3300,8 +3300,19 @@
"Q_SIGNALS:\n"
"  void g2();\n"
"};");
+  verifyFormat("class A {\n"
+   "public ATTR:\n"
+   "  void f1() {}\n"
+   "protected ATTR:\n"
+   "  void f2() {}\n"
+   "private ATTR:\n"
+   "  void f3() {}\n"
+   "};");
 
   // Don't interpret 'signals' the wrong way.
+  verifyFormat("struct Bitfields {\n"
+   "  unsigned signals : 1;\n"
+   "};");
   verifyFormat("signals.set();");
   verifyFormat("for (Signals signals : f()) {\n}");
   verifyFormat("{\n"
@@ -3311,6 +3322,21 @@
"label:\n"
"  signals.baz();\n"
"}");
+
+  // Don't interpret 'slots' the wrong way.
+  verifyFormat("struct Bitfields {\n"
+   "  unsigned slots : 1;\n"
+   "};");
+  verifyFormat("slots.set();");
+  verifyFormat("for (Signals slots : f()) {\n}");
+  verifyFormat("{\n"
+   "  slots.set(); // This needs indentation.\n"
+   "}");
+  verifyFormat("void f() {\n"
+   "label:\n"
+   "  slots.baz();\n"
+   "}");
+
   verifyFormat("private[1];");
   verifyFormat("testArray[public] = 1;");
   verifyFormat("public();");
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -3087,6 +3087,10 @@
   // Understand Qt's slots.
   if (FormatTok->isOneOf(Keywords.kw_slots, Keywords.kw_qslots))
 nextToken();
+  // Handle custom attributes.
+  if (FormatTok->is(tok::identifier) && 
Tokens->peekNextToken()->is(tok::colon))
+nextToken();
+
   // Otherwise, we don't know what it is, and we'd better keep the next token.
   if (FormatTok->is(tok::colon)) {
 nextToken();
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -113,13 +113,14 @@
   } else if (RootToken.isObjCAccessSpecifier()) {
 return true;
   }
-  // Handle Qt signals.
-  else if ((RootToken.isOneOf(Keywords.kw_signals, Keywords.kw_qsignals) &&
-RootToken.Next && RootToken.Next->is(tok::colon))) {
+  // Handle Qt signals and custom attributes.
+  else if (RootToken.isOneOf(Keywords.kw_signals, Keywords.kw_qsignals) &&
+   RootToken.Next && RootToken.Next->is(tok::colon)) {
 return true;
-  } else if (RootToken.Next &&
- RootToken.Next->isOneOf(Keywords.kw_slots,
- Keywords.kw_qslots) &&
+  } else if (RootToken.isAccessSpecifier(/*colonRequired=*/false) &&
+ RootToken.Next &&
+ RootToken.Next->isOneOf(Keywords.kw_slots, Keywords.kw_qslots,
+ tok::identifier) &&
  RootToken.Next->Next && RootToken.Next->Next->is(tok::colon)) 
{
 return true;
   }


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -3300,8 +3300,19 @@
"Q_SIGNALS:\n"
"  void g2();\n"
"};");
+  verifyFormat("class A {\n"
+   "public ATTR:\n"
+   "  void f1() {}\n"
+   "protected ATTR:\n"
+   "  void f2() {}\n"
+   "private ATTR:\n"
+   "  void f3() {}\n"
+   "};");
 
   // Don't interpret 'signals' the wrong way.
+  verifyFormat("struct Bitfields {\n"
+   "  unsigned signals : 1;\n"
+   "};");
   verifyFormat("signals.set();");
   verifyFormat("for (Signals signals : f()) {\n}");
   verifyFormat("{\n"
@@ -3311,6 +3322,21 @@
"label:\n"
"  signals.baz();\n"
"}");
+
+  // Don't interpret 'slots' the wrong 

[PATCH] D129892: Fix aligning of trailing comments after comment at the end of a namespace

2022-07-15 Thread Danil Sidoruk via Phabricator via cfe-commits
eoanermine created this revision.
eoanermine added reviewers: owenpan, HazardyKnusperkeks, curdeius, 
MyDeveloperDay.
eoanermine added projects: clang, clang-format.
Herald added a project: All.
eoanermine requested review of this revision.
Herald added a subscriber: cfe-commits.

- Fix aligning of trailing comments after comment at the end of a namespace
- Add tests for aligning of trailing comments after comment that documents the 
closing of a namespace


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129892

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -17458,6 +17458,40 @@
Alignment);
 }
 
+TEST_F(FormatTest, AlignTrailingComments) {
+  FormatStyle Style = getLLVMStyle();
+  EXPECT_EQ(Style.AlignTrailingComments, true);
+
+  verifyFormat("namespace test {\n"
+   "class C;\n"
+   "} // namespace test\n"
+   "// Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
+   "Nullam cursus nunc\n"
+   "// non",
+   Style);
+  verifyFormat("namespace test {\n"
+   "class C;\n"
+   "} // namespace test\n"
+   "// Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
+   "Nullam cursus nunc\n"
+   "// non\n",
+   Style);
+  verifyFormat("namespace test {\n"
+   "class C;\n"
+   "} // namespace test\n"
+   "// Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
+   "Nullam cursus nunc\n"
+   "// non other text",
+   Style);
+  verifyFormat("namespace test {\n"
+   "class C;\n"
+   "} // namespace test\n"
+   "// Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
+   "Nullam cursus nunc\n"
+   "// non other text\n",
+   Style);
+}
+
 TEST_F(FormatTest, AlignConsecutiveBitFields) {
   FormatStyle Alignment = getLLVMStyle();
   Alignment.AlignConsecutiveBitFields.Enabled = true;
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -966,6 +966,10 @@
 
 unsigned NextColumn = SourceMgr.getSpellingColumnNumber(
 Changes[j].OriginalWhitespaceRange.getEnd());
+// Handle files without newline before the end of file correct
+if (Changes[j].Tok->is(tok::eof))
+  NextColumn = 1;
+
 // The start of the next token was previously aligned with the
 // start of this comment.
 WasAlignedWithStartOfNextLine =


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -17458,6 +17458,40 @@
Alignment);
 }
 
+TEST_F(FormatTest, AlignTrailingComments) {
+  FormatStyle Style = getLLVMStyle();
+  EXPECT_EQ(Style.AlignTrailingComments, true);
+
+  verifyFormat("namespace test {\n"
+   "class C;\n"
+   "} // namespace test\n"
+   "// Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
+   "Nullam cursus nunc\n"
+   "// non",
+   Style);
+  verifyFormat("namespace test {\n"
+   "class C;\n"
+   "} // namespace test\n"
+   "// Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
+   "Nullam cursus nunc\n"
+   "// non\n",
+   Style);
+  verifyFormat("namespace test {\n"
+   "class C;\n"
+   "} // namespace test\n"
+   "// Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
+   "Nullam cursus nunc\n"
+   "// non other text",
+   Style);
+  verifyFormat("namespace test {\n"
+   "class C;\n"
+   "} // namespace test\n"
+   "// Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
+   "Nullam cursus nunc\n"
+   "// non other text\n",
+   Style);
+}
+
 TEST_F(FormatTest, AlignConsecutiveBitFields) {
   FormatStyle Alignment = getLLVMStyle();
   Alignment.AlignConsecutiveBitFields.Enabled = true;
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -966,6 +966,10 @@
 
 unsigned NextColumn = SourceMgr.getSpellingColumnNumber(
 Changes[j].OriginalWhitespaceRange.getEnd());
+// Handle files without newline before the end

[PATCH] D129926: [clang-format] Handle constructor invocations after new operator in C# correct

2022-07-16 Thread Danil Sidoruk via Phabricator via cfe-commits
eoanermine created this revision.
eoanermine added reviewers: owenpan, HazardyKnusperkeks, MyDeveloperDay.
eoanermine added projects: clang, clang-format.
Herald added a project: All.
eoanermine requested review of this revision.
Herald added a subscriber: cfe-commits.

- Handle constructor invocations after new operator in C# correct
- Add test for the case with lambda in constructor arguments after new operator

Closes https://github.com/llvm/llvm-project/issues/56549


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129926

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTestCSharp.cpp


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -616,6 +616,24 @@
   EXPECT_EQ(Code, format(Code, Style));
 }
 
+TEST_F(FormatTestCSharp, CSharpNewOperator) {
+  FormatStyle Style = getLLVMStyle(FormatStyle::LK_CSharp);
+
+  verifyFormat("public void F() {\n"
+   "  var v = new C(() => { var t = 5; });\n"
+   "}",
+   Style);
+  verifyFormat("public void F() {\n"
+   "  var v = new C(() => {\n"
+   "try {\n"
+   "} catch {\n"
+   "  var t = 5;\n"
+   "}\n"
+   "  });\n"
+   "}",
+   Style);
+}
+
 TEST_F(FormatTestCSharp, CSharpLambdas) {
   FormatStyle GoogleStyle = getGoogleStyle(FormatStyle::LK_CSharp);
   FormatStyle MicrosoftStyle = getMicrosoftStyle(FormatStyle::LK_CSharp);
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2861,6 +2861,11 @@
 
   if (Style.isCSharp()) {
 do {
+  // Handle constructor invocation
+  if (FormatTok->is(tok::l_paren))
+parseParens();
+
+  // Handle array initialization syntax
   if (FormatTok->is(tok::l_brace))
 parseBracedList();
 


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -616,6 +616,24 @@
   EXPECT_EQ(Code, format(Code, Style));
 }
 
+TEST_F(FormatTestCSharp, CSharpNewOperator) {
+  FormatStyle Style = getLLVMStyle(FormatStyle::LK_CSharp);
+
+  verifyFormat("public void F() {\n"
+   "  var v = new C(() => { var t = 5; });\n"
+   "}",
+   Style);
+  verifyFormat("public void F() {\n"
+   "  var v = new C(() => {\n"
+   "try {\n"
+   "} catch {\n"
+   "  var t = 5;\n"
+   "}\n"
+   "  });\n"
+   "}",
+   Style);
+}
+
 TEST_F(FormatTestCSharp, CSharpLambdas) {
   FormatStyle GoogleStyle = getGoogleStyle(FormatStyle::LK_CSharp);
   FormatStyle MicrosoftStyle = getMicrosoftStyle(FormatStyle::LK_CSharp);
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2861,6 +2861,11 @@
 
   if (Style.isCSharp()) {
 do {
+  // Handle constructor invocation
+  if (FormatTok->is(tok::l_paren))
+parseParens();
+
+  // Handle array initialization syntax
   if (FormatTok->is(tok::l_brace))
 parseBracedList();
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131789: [clang-tools-extra] Rewrite prints in python3 compatible way

2022-08-12 Thread Danil Sidoruk via Phabricator via cfe-commits
eoanermine created this revision.
eoanermine added reviewers: klimek, HazardyKnusperkeks.
eoanermine added a project: clang-tools-extra.
Herald added a project: All.
eoanermine requested review of this revision.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131789

Files:
  
clang-tools-extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py


Index: 
clang-tools-extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py
===
--- 
clang-tools-extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py
+++ 
clang-tools-extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py
@@ -39,7 +39,7 @@
   result = './'
   while not os.path.isfile(os.path.join(result, path)):
 if os.path.realpath(result) == '/':
-  print 'Error: could not find compilation database.'
+  print('Error: could not find compilation database.')
   sys.exit(1)
 result += '../'
   return os.path.realpath(result)
@@ -49,7 +49,7 @@
   """Merge all symbol files (yaml) in a given directory into a single file."""
   invocation = [args.binary, '-merge-dir='+directory, args.saving_path]
   subprocess.call(invocation)
-  print 'Merge is finished. Saving results in ' + args.saving_path
+  print('Merge is finished. Saving results in ' + args.saving_path)
 
 
 def run_find_all_symbols(args, tmpdir, build_path, queue):
@@ -118,7 +118,7 @@
   except KeyboardInterrupt:
 # This is a sad hack. Unfortunately subprocess goes
 # bonkers with ctrl-c and we start forking merrily.
-print '\nCtrl-C detected, goodbye.'
+print('\nCtrl-C detected, goodbye.')
 os.kill(0, 9)
 
 


Index: clang-tools-extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py
===
--- clang-tools-extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py
+++ clang-tools-extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py
@@ -39,7 +39,7 @@
   result = './'
   while not os.path.isfile(os.path.join(result, path)):
 if os.path.realpath(result) == '/':
-  print 'Error: could not find compilation database.'
+  print('Error: could not find compilation database.')
   sys.exit(1)
 result += '../'
   return os.path.realpath(result)
@@ -49,7 +49,7 @@
   """Merge all symbol files (yaml) in a given directory into a single file."""
   invocation = [args.binary, '-merge-dir='+directory, args.saving_path]
   subprocess.call(invocation)
-  print 'Merge is finished. Saving results in ' + args.saving_path
+  print('Merge is finished. Saving results in ' + args.saving_path)
 
 
 def run_find_all_symbols(args, tmpdir, build_path, queue):
@@ -118,7 +118,7 @@
   except KeyboardInterrupt:
 # This is a sad hack. Unfortunately subprocess goes
 # bonkers with ctrl-c and we start forking merrily.
-print '\nCtrl-C detected, goodbye.'
+print('\nCtrl-C detected, goodbye.')
 os.kill(0, 9)
 
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129926: [clang-format] Handle constructor invocations after new operator in C# correct

2022-08-14 Thread Danil Sidoruk via Phabricator via cfe-commits
eoanermine added a comment.

In D129926#3705342 , @MyDeveloperDay 
wrote:

> Can we land this for you?

Yes




Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2869-2870
+  // Handle array initialization syntax
   if (FormatTok->is(tok::l_brace))
 parseBracedList();
 

Before the patch, this code mistook lambdas in a constructor call for an 
initialization list.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129926

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


[PATCH] D129628: [clang-format] Fix aligning of java-style declarations

2022-08-14 Thread Danil Sidoruk via Phabricator via cfe-commits
eoanermine added a comment.

I don't have an access to commit the patch by myself.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129628

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


[PATCH] D129926: [clang-format] Handle constructor invocations after new operator in C# correct

2022-08-14 Thread Danil Sidoruk via Phabricator via cfe-commits
eoanermine updated this revision to Diff 452513.
eoanermine added a comment.

- Add examples to comments
- Reformat comments right


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129926

Files:
  clang/lib/Format/UnwrappedLineParser.cpp


Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2861,11 +2861,11 @@
 
   if (Style.isCSharp()) {
 do {
-  // Handle constructor invocation
+  // Handle constructor invocation, e.g. `new(field: value)`.
   if (FormatTok->is(tok::l_paren))
 parseParens();
 
-  // Handle array initialization syntax
+  // Handle array initialization syntax, e.g. `new[] {10, 20, 30}`.
   if (FormatTok->is(tok::l_brace))
 parseBracedList();
 


Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2861,11 +2861,11 @@
 
   if (Style.isCSharp()) {
 do {
-  // Handle constructor invocation
+  // Handle constructor invocation, e.g. `new(field: value)`.
   if (FormatTok->is(tok::l_paren))
 parseParens();
 
-  // Handle array initialization syntax
+  // Handle array initialization syntax, e.g. `new[] {10, 20, 30}`.
   if (FormatTok->is(tok::l_brace))
 parseBracedList();
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131789: [clang-tools-extra][NFC] Rewrite prints in python3 compatible way

2022-08-15 Thread Danil Sidoruk via Phabricator via cfe-commits
eoanermine added a comment.

Please, commit this patch for me

I don't have an access to commit the patch by myself.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131789

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