[PATCH] D116283: [clang-format] Add an option to add a space between operator overloading and opening parentheses

2021-12-30 Thread Rajat Bajpai via Phabricator via cfe-commits
rajatbajpai added inline comments.



Comment at: clang/unittests/Format/FormatTest.cpp:14545
   verifyFormat("auto lambda = []() { return 0; };", SomeSpace2);
+
+  FormatStyle SpaceAfterOperatorOverloading = getLLVMStyle();

MyDeveloperDay wrote:
> There should be a PARSE unit test too please
I'm sorry if I misunderstood it, do you mean tests using CHECK_PARSE? I am 
confirming this because I didn't find any such test case for existing 
//SpaceBeforeParensOptions// options.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116283

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


[PATCH] D116283: [clang-format] Add an option to add a space between operator overloading and opening parentheses

2021-12-31 Thread Rajat Bajpai via Phabricator via cfe-commits
rajatbajpai added inline comments.



Comment at: clang/unittests/Format/FormatTest.cpp:14545
   verifyFormat("auto lambda = []() { return 0; };", SomeSpace2);
+
+  FormatStyle SpaceAfterOperatorOverloading = getLLVMStyle();

HazardyKnusperkeks wrote:
> rajatbajpai wrote:
> > MyDeveloperDay wrote:
> > > There should be a PARSE unit test too please
> > I'm sorry if I misunderstood it, do you mean tests using CHECK_PARSE? I am 
> > confirming this because I didn't find any such test case for existing 
> > //SpaceBeforeParensOptions// options.
> Than this has slipped through, but there should be a test for every parsing 
> aspect.
Thanks for confirming. 

Not an issue, I'll try to add a test case for existing options as well then.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116283

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


[PATCH] D116283: [clang-format] Add an option to add a space between operator overloading and opening parentheses

2022-01-02 Thread Rajat Bajpai via Phabricator via cfe-commits
rajatbajpai updated this revision to Diff 396922.
rajatbajpai added a comment.

Incorporated review comments.

1. Added Check Parse test case for //SpaceBeforeParensOptions//.
2. Renamed the option to //AfterOverloadedOperator//.
3. Added operator overloading instantiation scenario in the unit test as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116283

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  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
@@ -14542,6 +14542,24 @@
   // verifyFormat("X A::operator++ (T);", SomeSpace2);
   verifyFormat("int x = int (y);", SomeSpace2);
   verifyFormat("auto lambda = []() { return 0; };", SomeSpace2);
+
+  FormatStyle SpaceAfterOverloadedOperator = getLLVMStyle();
+  SpaceAfterOverloadedOperator.SpaceBeforeParens = FormatStyle::SBPO_Custom;
+  SpaceAfterOverloadedOperator.SpaceBeforeParensOptions
+  .AfterOverloadedOperator = true;
+
+  verifyFormat("auto operator++ () -> int;", SpaceAfterOverloadedOperator);
+  verifyFormat("X A::operator++ ();", SpaceAfterOverloadedOperator);
+  verifyFormat("some_object.operator++ ();", SpaceAfterOverloadedOperator);
+  verifyFormat("auto func() -> int;", SpaceAfterOverloadedOperator);
+
+  SpaceAfterOverloadedOperator.SpaceBeforeParensOptions
+  .AfterOverloadedOperator = false;
+
+  verifyFormat("auto operator++() -> int;", SpaceAfterOverloadedOperator);
+  verifyFormat("X A::operator++();", SpaceAfterOverloadedOperator);
+  verifyFormat("some_object.operator++();", SpaceAfterOverloadedOperator);
+  verifyFormat("auto func() -> int;", SpaceAfterOverloadedOperator);
 }
 
 TEST_F(FormatTest, SpaceAfterLogicalNot) {
@@ -18719,6 +18737,15 @@
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyFunction);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyRecord);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyNamespace);
+  CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterControlStatements);
+  CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterForeachMacros);
+  CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions,
+  AfterFunctionDeclarationName);
+  CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions,
+  AfterFunctionDefinitionName);
+  CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterIfMacros);
+  CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterOverloadedOperator);
+  CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, BeforeNonEmptyParentheses);
 }
 
 #undef CHECK_PARSE_BOOL
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2921,9 +2921,15 @@
 }
 
 bool TokenAnnotator::spaceRequiredBeforeParens(const FormatToken &Right) const {
-  return Style.SpaceBeforeParens == FormatStyle::SBPO_Always ||
- (Style.SpaceBeforeParensOptions.BeforeNonEmptyParentheses &&
-  Right.ParameterCount > 0);
+  if (Style.SpaceBeforeParens == FormatStyle::SBPO_Always)
+return true;
+  if (Right.is(TT_OverloadedOperatorLParen) &&
+  Style.SpaceBeforeParensOptions.AfterOverloadedOperator)
+return true;
+  if (Style.SpaceBeforeParensOptions.BeforeNonEmptyParentheses &&
+  Right.ParameterCount > 0)
+return true;
+  return false;
 }
 
 bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -855,6 +855,7 @@
 IO.mapOptional("AfterFunctionDeclarationName",
Spacing.AfterFunctionDeclarationName);
 IO.mapOptional("AfterIfMacros", Spacing.AfterIfMacros);
+IO.mapOptional("AfterOverloadedOperator", Spacing.AfterOverloadedOperator);
 IO.mapOptional("BeforeNonEmptyParentheses",
Spacing.BeforeNonEmptyParentheses);
   }
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -3368,6 +3368,13 @@
 ///   
 /// \endcode
 bool AfterIfMacros;
+/// If ``true``, put a space between operator overloading and opening
+/// parentheses.
+/// \code
+///true:  false:
+///void operator++ (int a);vs.void operator++(int a);
+/// \endcode
+bool AfterOverloadedOperator;
 /// If ``true``, put a space before opening parentheses only if the
 /// parentheses are not emp

[PATCH] D116283: [clang-format] Add an option to add a space between operator overloading and opening parentheses

2022-01-03 Thread Rajat Bajpai via Phabricator via cfe-commits
rajatbajpai added a comment.

In D116283#3216235 , @MyDeveloperDay 
wrote:

> LGTM, could you add a release note into docs/ReleaseNotes.rst?

Sure, will do.




Comment at: clang/docs/ClangFormatStyleOptions.rst:3760
+   true:  false:
+   void operator++ (int a);vs.void operator++(int a);
+

curdeius wrote:
> Please add operator call as well to the example (`object.operator++ (0)`).
Sure, will add.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116283

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


[PATCH] D116283: [clang-format] Add an option to add a space between operator overloading and opening parentheses

2022-01-03 Thread Rajat Bajpai via Phabricator via cfe-commits
rajatbajpai updated this revision to Diff 397112.
rajatbajpai added a comment.

Incorporated review comments.

Updated release note and example scenario.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116283

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  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
@@ -14529,6 +14529,24 @@
   // verifyFormat("X A::operator++ (T);", SomeSpace2);
   verifyFormat("int x = int (y);", SomeSpace2);
   verifyFormat("auto lambda = []() { return 0; };", SomeSpace2);
+
+  FormatStyle SpaceAfterOverloadedOperator = getLLVMStyle();
+  SpaceAfterOverloadedOperator.SpaceBeforeParens = FormatStyle::SBPO_Custom;
+  SpaceAfterOverloadedOperator.SpaceBeforeParensOptions
+  .AfterOverloadedOperator = true;
+
+  verifyFormat("auto operator++ () -> int;", SpaceAfterOverloadedOperator);
+  verifyFormat("X A::operator++ ();", SpaceAfterOverloadedOperator);
+  verifyFormat("some_object.operator++ ();", SpaceAfterOverloadedOperator);
+  verifyFormat("auto func() -> int;", SpaceAfterOverloadedOperator);
+
+  SpaceAfterOverloadedOperator.SpaceBeforeParensOptions
+  .AfterOverloadedOperator = false;
+
+  verifyFormat("auto operator++() -> int;", SpaceAfterOverloadedOperator);
+  verifyFormat("X A::operator++();", SpaceAfterOverloadedOperator);
+  verifyFormat("some_object.operator++();", SpaceAfterOverloadedOperator);
+  verifyFormat("auto func() -> int;", SpaceAfterOverloadedOperator);
 }
 
 TEST_F(FormatTest, SpaceAfterLogicalNot) {
@@ -18704,6 +18722,15 @@
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyFunction);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyRecord);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyNamespace);
+  CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterControlStatements);
+  CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterForeachMacros);
+  CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions,
+  AfterFunctionDeclarationName);
+  CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions,
+  AfterFunctionDefinitionName);
+  CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterIfMacros);
+  CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterOverloadedOperator);
+  CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, BeforeNonEmptyParentheses);
 }
 
 #undef CHECK_PARSE_BOOL
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2921,9 +2921,15 @@
 }
 
 bool TokenAnnotator::spaceRequiredBeforeParens(const FormatToken &Right) const {
-  return Style.SpaceBeforeParens == FormatStyle::SBPO_Always ||
- (Style.SpaceBeforeParensOptions.BeforeNonEmptyParentheses &&
-  Right.ParameterCount > 0);
+  if (Style.SpaceBeforeParens == FormatStyle::SBPO_Always)
+return true;
+  if (Right.is(TT_OverloadedOperatorLParen) &&
+  Style.SpaceBeforeParensOptions.AfterOverloadedOperator)
+return true;
+  if (Style.SpaceBeforeParensOptions.BeforeNonEmptyParentheses &&
+  Right.ParameterCount > 0)
+return true;
+  return false;
 }
 
 bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -855,6 +855,7 @@
 IO.mapOptional("AfterFunctionDeclarationName",
Spacing.AfterFunctionDeclarationName);
 IO.mapOptional("AfterIfMacros", Spacing.AfterIfMacros);
+IO.mapOptional("AfterOverloadedOperator", Spacing.AfterOverloadedOperator);
 IO.mapOptional("BeforeNonEmptyParentheses",
Spacing.BeforeNonEmptyParentheses);
   }
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -3368,6 +3368,14 @@
 ///   
 /// \endcode
 bool AfterIfMacros;
+/// If ``true``, put a space between operator overloading and opening
+/// parentheses.
+/// \code
+///true:  false:
+///void operator++ (int a);vs.void operator++(int a);
+///object.operator++ (10);object.operator++(10);
+/// \endcode
+bool AfterOverloadedOperator;
 /// If ``true``, put a space before opening parentheses only if the
 /// parentheses are not empty.
 /// \code
@@ -3381,7 +3389,7 @@
 :

[PATCH] D116283: [clang-format] Add an option to add a space between operator overloading and opening parentheses

2022-01-04 Thread Rajat Bajpai via Phabricator via cfe-commits
rajatbajpai added a comment.

In D116283#3218118 , 
@HazardyKnusperkeks wrote:

> Thanks for adding the parse checks.

Not an issue :)

In D116283#3218101 , @curdeius wrote:

> LGTM.
> If you need help landing this (if you don't have commit rights), just give 
> your name and email that you want to be used for the contribution and someone 
> will land it for you.
>
> See also https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access 
> if you think contributing more patches.

Thanks everyone for taking time to review this change.

Yes, I don't have commit rights. Please land this change for me (name : Rajat 
Bajpai and email: rb.mac...@gmail.com).

I will apply for commit access for future changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116283

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


[PATCH] D116283: Added an option to add a space between operator overloading and opening parentheses in clang-format

2021-12-26 Thread Rajat Bajpai via Phabricator via cfe-commits
rajatbajpai created this revision.
rajatbajpai added a reviewer: MyDeveloperDay.
rajatbajpai added a project: clang-format.
rajatbajpai requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This change adds an option AfterOperatorOverloading in SpaceBeforeParensOptions 
to add a space between operator overloading and opening parentheses in 
clang-format.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116283

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/test/Format/space-before-parens.cpp

Index: clang/test/Format/space-before-parens.cpp
===
--- /dev/null
+++ clang/test/Format/space-before-parens.cpp
@@ -0,0 +1,9 @@
+// RUN: clang-format -style="{SpaceBeforeParens: Custom, SpaceBeforeParensOptions: {AfterOperator: false}}" %s | FileCheck -strict-whitespace -check-prefix=CHECK1 %s
+// Test space between overloaded operator and left parentheses
+// RUN: clang-format -style="{SpaceBeforeParens: Custom, SpaceBeforeParensOptions: {AfterOperator: true}}" %s | FileCheck -strict-whitespace -check-prefix=CHECK2 %s
+class Test {
+  auto func() -> int;
+  // CHECK1: {{^\ \ auto\ operator\+\+\(int\)\ \-\>\ int;$}}
+  // CHECK2: {{^\ \ auto\ operator\+\+\ \(int\)\ \-\>\ int;$}}
+  auto operator++(int) -> int;
+};
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2921,9 +2921,15 @@
 }
 
 bool TokenAnnotator::spaceRequiredBeforeParens(const FormatToken &Right) const {
-  return Style.SpaceBeforeParens == FormatStyle::SBPO_Always ||
- (Style.SpaceBeforeParensOptions.BeforeNonEmptyParentheses &&
-  Right.ParameterCount > 0);
+  if (Style.SpaceBeforeParens == FormatStyle::SBPO_Always)
+return true;
+  if (Right.is(TT_OverloadedOperatorLParen) &&
+  Style.SpaceBeforeParensOptions.AfterOperatorOverloading)
+return true;
+  if (Style.SpaceBeforeParensOptions.BeforeNonEmptyParentheses &&
+  Right.ParameterCount > 0)
+return true;
+  return false;
 }
 
 bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -857,6 +857,8 @@
 IO.mapOptional("AfterIfMacros", Spacing.AfterIfMacros);
 IO.mapOptional("BeforeNonEmptyParentheses",
Spacing.BeforeNonEmptyParentheses);
+IO.mapOptional("AfterOperatorOverloading",
+   Spacing.AfterOperatorOverloading);
   }
 };
 
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -3376,12 +3376,20 @@
 ///f (a); f();
 /// \endcode
 bool BeforeNonEmptyParentheses;
+/// If ``true``, put a space between operator overloading and opening
+/// parentheses.
+/// \code
+///true:  false:
+///void operator++ (int a); vs.void operator++(int
+///a);
+/// \endcode
+bool AfterOperatorOverloading;
 
 SpaceBeforeParensCustom()
 : AfterControlStatements(false), AfterForeachMacros(false),
   AfterFunctionDeclarationName(false),
   AfterFunctionDefinitionName(false), AfterIfMacros(false),
-  BeforeNonEmptyParentheses(false) {}
+  BeforeNonEmptyParentheses(false), AfterOperatorOverloading(false) {}
 
 bool operator==(const SpaceBeforeParensCustom &Other) const {
   return AfterControlStatements == Other.AfterControlStatements &&
@@ -3390,7 +3398,8 @@
  Other.AfterFunctionDeclarationName &&
  AfterFunctionDefinitionName == Other.AfterFunctionDefinitionName &&
  AfterIfMacros == Other.AfterIfMacros &&
- BeforeNonEmptyParentheses == Other.BeforeNonEmptyParentheses;
+ BeforeNonEmptyParentheses == Other.BeforeNonEmptyParentheses &&
+ AfterOperatorOverloading == Other.AfterOperatorOverloading;
 }
   };
 
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -3761,6 +3761,13 @@
void f (int a); vs.void f();
f (a); f();
 
+  * ``bool AfterOperatorOverloading`` If ``true``, put a space between operator overloading and opening parentheses.
+
+.. code-block:: c++
+
+   true:  false:
+   void operator++ (int a); 

[PATCH] D116283: Added an option to add a space between operator overloading and opening parentheses in clang-format

2021-12-27 Thread Rajat Bajpai via Phabricator via cfe-commits
rajatbajpai updated this revision to Diff 396302.
rajatbajpai added a comment.

Incorporated review comments.

Changelog:

1. Using unit test case instead of lit test case.
2. Placed the option according to alphabetical order.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116283

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  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
@@ -14542,6 +14542,22 @@
   // verifyFormat("X A::operator++ (T);", SomeSpace2);
   verifyFormat("int x = int (y);", SomeSpace2);
   verifyFormat("auto lambda = []() { return 0; };", SomeSpace2);
+
+  FormatStyle SpaceAfterOperatorOverloading = getLLVMStyle();
+  SpaceAfterOperatorOverloading.SpaceBeforeParens = FormatStyle::SBPO_Custom;
+  SpaceAfterOperatorOverloading.SpaceBeforeParensOptions
+  .AfterOperatorOverloading = true;
+
+  verifyFormat("auto operator++ () -> int;", SpaceAfterOperatorOverloading);
+  verifyFormat("X A::operator++ ();", SpaceAfterOperatorOverloading);
+  verifyFormat("auto func() -> int;", SpaceAfterOperatorOverloading);
+
+  SpaceAfterOperatorOverloading.SpaceBeforeParensOptions
+  .AfterOperatorOverloading = false;
+
+  verifyFormat("auto operator++() -> int;", SpaceAfterOperatorOverloading);
+  verifyFormat("X A::operator++();", SpaceAfterOperatorOverloading);
+  verifyFormat("auto func() -> int;", SpaceAfterOperatorOverloading);
 }
 
 TEST_F(FormatTest, SpaceAfterLogicalNot) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2921,9 +2921,15 @@
 }
 
 bool TokenAnnotator::spaceRequiredBeforeParens(const FormatToken &Right) const {
-  return Style.SpaceBeforeParens == FormatStyle::SBPO_Always ||
- (Style.SpaceBeforeParensOptions.BeforeNonEmptyParentheses &&
-  Right.ParameterCount > 0);
+  if (Style.SpaceBeforeParens == FormatStyle::SBPO_Always)
+return true;
+  if (Right.is(TT_OverloadedOperatorLParen) &&
+  Style.SpaceBeforeParensOptions.AfterOperatorOverloading)
+return true;
+  if (Style.SpaceBeforeParensOptions.BeforeNonEmptyParentheses &&
+  Right.ParameterCount > 0)
+return true;
+  return false;
 }
 
 bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -855,10 +855,10 @@
 IO.mapOptional("AfterFunctionDeclarationName",
Spacing.AfterFunctionDeclarationName);
 IO.mapOptional("AfterIfMacros", Spacing.AfterIfMacros);
-IO.mapOptional("BeforeNonEmptyParentheses",
-   Spacing.BeforeNonEmptyParentheses);
 IO.mapOptional("AfterOperatorOverloading",
Spacing.AfterOperatorOverloading);
+IO.mapOptional("BeforeNonEmptyParentheses",
+   Spacing.BeforeNonEmptyParentheses);
   }
 };
 
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -3368,6 +3368,13 @@
 ///   
 /// \endcode
 bool AfterIfMacros;
+/// If ``true``, put a space between operator overloading and opening
+/// parentheses.
+/// \code
+///true:  false:
+///void operator++ (int a);vs.void operator++(int a);
+/// \endcode
+bool AfterOperatorOverloading;
 /// If ``true``, put a space before opening parentheses only if the
 /// parentheses are not empty.
 /// \code
@@ -3376,20 +3383,12 @@
 ///f (a); f();
 /// \endcode
 bool BeforeNonEmptyParentheses;
-/// If ``true``, put a space between operator overloading and opening
-/// parentheses.
-/// \code
-///true:  false:
-///void operator++ (int a); vs.void operator++(int
-///a);
-/// \endcode
-bool AfterOperatorOverloading;
 
 SpaceBeforeParensCustom()
 : AfterControlStatements(false), AfterForeachMacros(false),
   AfterFunctionDeclarationName(false),
   AfterFunctionDefinitionName(false), AfterIfMacros(false),
-  BeforeNonEmptyParentheses(false), AfterOperatorOverloading(false) {}
+  AfterOperatorOverloading(false), BeforeNonEmptyParentheses(false) {}
 
 bool operator==(const SpaceBeforeParensCustom &Other) const {
   re

[PATCH] D116283: Added an option to add a space between operator overloading and opening parentheses in clang-format

2021-12-27 Thread Rajat Bajpai via Phabricator via cfe-commits
rajatbajpai updated this revision to Diff 396314.
rajatbajpai added a comment.

Fixed the patch file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116283

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  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
@@ -14542,6 +14542,22 @@
   // verifyFormat("X A::operator++ (T);", SomeSpace2);
   verifyFormat("int x = int (y);", SomeSpace2);
   verifyFormat("auto lambda = []() { return 0; };", SomeSpace2);
+
+  FormatStyle SpaceAfterOperatorOverloading = getLLVMStyle();
+  SpaceAfterOperatorOverloading.SpaceBeforeParens = FormatStyle::SBPO_Custom;
+  SpaceAfterOperatorOverloading.SpaceBeforeParensOptions
+  .AfterOperatorOverloading = true;
+
+  verifyFormat("auto operator++ () -> int;", SpaceAfterOperatorOverloading);
+  verifyFormat("X A::operator++ ();", SpaceAfterOperatorOverloading);
+  verifyFormat("auto func() -> int;", SpaceAfterOperatorOverloading);
+
+  SpaceAfterOperatorOverloading.SpaceBeforeParensOptions
+  .AfterOperatorOverloading = false;
+
+  verifyFormat("auto operator++() -> int;", SpaceAfterOperatorOverloading);
+  verifyFormat("X A::operator++();", SpaceAfterOperatorOverloading);
+  verifyFormat("auto func() -> int;", SpaceAfterOperatorOverloading);
 }
 
 TEST_F(FormatTest, SpaceAfterLogicalNot) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2921,9 +2921,15 @@
 }
 
 bool TokenAnnotator::spaceRequiredBeforeParens(const FormatToken &Right) const {
-  return Style.SpaceBeforeParens == FormatStyle::SBPO_Always ||
- (Style.SpaceBeforeParensOptions.BeforeNonEmptyParentheses &&
-  Right.ParameterCount > 0);
+  if (Style.SpaceBeforeParens == FormatStyle::SBPO_Always)
+return true;
+  if (Right.is(TT_OverloadedOperatorLParen) &&
+  Style.SpaceBeforeParensOptions.AfterOperatorOverloading)
+return true;
+  if (Style.SpaceBeforeParensOptions.BeforeNonEmptyParentheses &&
+  Right.ParameterCount > 0)
+return true;
+  return false;
 }
 
 bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -855,6 +855,8 @@
 IO.mapOptional("AfterFunctionDeclarationName",
Spacing.AfterFunctionDeclarationName);
 IO.mapOptional("AfterIfMacros", Spacing.AfterIfMacros);
+IO.mapOptional("AfterOperatorOverloading",
+   Spacing.AfterOperatorOverloading);
 IO.mapOptional("BeforeNonEmptyParentheses",
Spacing.BeforeNonEmptyParentheses);
   }
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -3368,6 +3368,13 @@
 ///   
 /// \endcode
 bool AfterIfMacros;
+/// If ``true``, put a space between operator overloading and opening
+/// parentheses.
+/// \code
+///true:  false:
+///void operator++ (int a);vs.void operator++(int a);
+/// \endcode
+bool AfterOperatorOverloading;
 /// If ``true``, put a space before opening parentheses only if the
 /// parentheses are not empty.
 /// \code
@@ -3381,7 +3388,7 @@
 : AfterControlStatements(false), AfterForeachMacros(false),
   AfterFunctionDeclarationName(false),
   AfterFunctionDefinitionName(false), AfterIfMacros(false),
-  BeforeNonEmptyParentheses(false) {}
+  AfterOperatorOverloading(false), BeforeNonEmptyParentheses(false) {}
 
 bool operator==(const SpaceBeforeParensCustom &Other) const {
   return AfterControlStatements == Other.AfterControlStatements &&
@@ -3390,6 +3397,7 @@
  Other.AfterFunctionDeclarationName &&
  AfterFunctionDefinitionName == Other.AfterFunctionDefinitionName &&
  AfterIfMacros == Other.AfterIfMacros &&
+ AfterOperatorOverloading == Other.AfterOperatorOverloading &&
  BeforeNonEmptyParentheses == Other.BeforeNonEmptyParentheses;
 }
   };
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -3752,6 +3752,13 @@
IF (...)vs.IF(...)
 

[PATCH] D116283: [clang-format] Add an option to add a space between operator overloading and opening parentheses

2021-12-29 Thread Rajat Bajpai via Phabricator via cfe-commits
rajatbajpai added a comment.

In D116283#3211590 , 
@HazardyKnusperkeks wrote:

> Does it affect calling code? `a.operator++(5);` Should it? But please add 
> tests for that.

Yes, it does affect the calling code as well. However, I am not sure if we 
should separate the two. Sure, I'll add a test case for it.




Comment at: clang/docs/ClangFormatStyleOptions.rst:3755
 
+  * ``bool AfterOperatorOverloading`` If ``true``, put a space between 
operator overloading and opening parentheses.
+

MyDeveloperDay wrote:
> curdeius wrote:
> > I'm not fond of the current name, exactly the "Overloading" part (but have 
> > no better suggestion right now). It seems a bit misleading to me.
> > 
> > Maybe AfterOverloadedOperator(Name)??? At least it would match the token 
> > kind name.
> +1 here,  AfterOperator?
@MyDeveloperDay Initially, I thought about using //AfterOperator// but it also 
seems a bit misleading. However, @curdeius suggestion seems reasonable given it 
matches with the token kind.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116283

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