[PATCH] D103204: [Format] New BreakInheritanceList style AfterComma

2021-05-26 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray updated this revision to Diff 348164.
lichray added a comment.

Simplify implementation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103204

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp


Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3639,6 +3639,9 @@
   if (Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma &&
   Right.is(TT_InheritanceComma))
 return true;
+  if (Style.BreakInheritanceList == FormatStyle::BILS_AfterComma &&
+  Left.is(TT_InheritanceComma))
+return true;
   if (Right.is(tok::string_literal) && Right.TokenText.startswith("R\""))
 // Multiline raw string literals are special wrt. line breaks. The author
 // has made a deliberate choice and might have aligned the contents of the
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -240,6 +240,7 @@
 IO.enumCase(Value, "BeforeColon", FormatStyle::BILS_BeforeColon);
 IO.enumCase(Value, "BeforeComma", FormatStyle::BILS_BeforeComma);
 IO.enumCase(Value, "AfterColon", FormatStyle::BILS_AfterColon);
+IO.enumCase(Value, "AfterComma", FormatStyle::BILS_AfterComma);
   }
 };
 
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -1829,7 +1829,14 @@
 ///Base2
 ///{};
 /// \endcode
-BILS_AfterColon
+BILS_AfterColon,
+/// Break inheritance list only after the commas.
+/// \code
+///class Foo : Base1,
+///Base2
+///{};
+/// \endcode
+BILS_AfterComma
   };
 
   /// The inheritance list style to use.
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -1999,6 +1999,15 @@
Base2
{};
 
+  * ``BILS_AfterComma`` (in configuration: ``AfterComma``)
+Break inheritance list only after the commas.
+
+.. code-block:: c++
+
+   class Foo : Base1,
+   Base2
+   {};
+
 
 
 **BreakStringLiterals** (``bool``)


Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3639,6 +3639,9 @@
   if (Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma &&
   Right.is(TT_InheritanceComma))
 return true;
+  if (Style.BreakInheritanceList == FormatStyle::BILS_AfterComma &&
+  Left.is(TT_InheritanceComma))
+return true;
   if (Right.is(tok::string_literal) && Right.TokenText.startswith("R\""))
 // Multiline raw string literals are special wrt. line breaks. The author
 // has made a deliberate choice and might have aligned the contents of the
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -240,6 +240,7 @@
 IO.enumCase(Value, "BeforeColon", FormatStyle::BILS_BeforeColon);
 IO.enumCase(Value, "BeforeComma", FormatStyle::BILS_BeforeComma);
 IO.enumCase(Value, "AfterColon", FormatStyle::BILS_AfterColon);
+IO.enumCase(Value, "AfterComma", FormatStyle::BILS_AfterComma);
   }
 };
 
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -1829,7 +1829,14 @@
 ///Base2
 ///{};
 /// \endcode
-BILS_AfterColon
+BILS_AfterColon,
+/// Break inheritance list only after the commas.
+/// \code
+///class Foo : Base1,
+///Base2
+///{};
+/// \endcode
+BILS_AfterComma
   };
 
   /// The inheritance list style to use.
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -1999,6 +1999,15 @@
Base2
{};
 
+  * ``BILS_AfterComma`` (in configuration: ``AfterComma``)
+Break inheritance list only after the commas.
+
+.. code-block:: c++
+
+   class Foo : Base1,
+   Base2
+   {};
+
 
 
 **BreakStringLiterals** (``bool``)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cf

[PATCH] D103204: [Format] New BreakInheritanceList style AfterComma

2021-05-26 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray updated this revision to Diff 348092.
lichray added a comment.

Fix typo in docs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103204

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp


Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3639,6 +3639,9 @@
   if (Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma &&
   Right.is(TT_InheritanceComma))
 return true;
+  if (Style.BreakInheritanceList == FormatStyle::BILS_AfterComma &&
+  Left.is(TT_InheritanceComma))
+return true;
   if (Right.is(tok::string_literal) && Right.TokenText.startswith("R\""))
 // Multiline raw string literals are special wrt. line breaks. The author
 // has made a deliberate choice and might have aligned the contents of the
@@ -4058,12 +4061,18 @@
   if (Right.is(TT_CtorInitializerComma) &&
   Style.BreakConstructorInitializers == FormatStyle::BCIS_BeforeComma)
 return true;
-  if (Left.is(TT_InheritanceComma) &&
-  Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma)
-return false;
-  if (Right.is(TT_InheritanceComma) &&
-  Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma)
-return true;
+  if (Left.is(TT_InheritanceComma)) {
+if (Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma)
+  return false;
+else if (Style.BreakInheritanceList == FormatStyle::BILS_AfterComma)
+  return true;
+  }
+  if (Right.is(TT_InheritanceComma)) {
+if (Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma)
+  return true;
+else if (Style.BreakInheritanceList == FormatStyle::BILS_AfterComma)
+  return false;
+  }
   if ((Left.is(tok::greater) && Right.is(tok::greater)) ||
   (Left.is(tok::less) && Right.is(tok::less)))
 return false;
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -240,6 +240,7 @@
 IO.enumCase(Value, "BeforeColon", FormatStyle::BILS_BeforeColon);
 IO.enumCase(Value, "BeforeComma", FormatStyle::BILS_BeforeComma);
 IO.enumCase(Value, "AfterColon", FormatStyle::BILS_AfterColon);
+IO.enumCase(Value, "AfterComma", FormatStyle::BILS_AfterComma);
   }
 };
 
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -1829,7 +1829,14 @@
 ///Base2
 ///{};
 /// \endcode
-BILS_AfterColon
+BILS_AfterColon,
+/// Break inheritance list only after the commas.
+/// \code
+///class Foo : Base1,
+///Base2
+///{};
+/// \endcode
+BILS_AfterComma
   };
 
   /// The inheritance list style to use.
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -1999,6 +1999,15 @@
Base2
{};
 
+  * ``BILS_AfterComma`` (in configuration: ``AfterComma``)
+Break inheritance list only after the commas.
+
+.. code-block:: c++
+
+   class Foo : Base1,
+   Base2
+   {};
+
 
 
 **BreakStringLiterals** (``bool``)


Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3639,6 +3639,9 @@
   if (Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma &&
   Right.is(TT_InheritanceComma))
 return true;
+  if (Style.BreakInheritanceList == FormatStyle::BILS_AfterComma &&
+  Left.is(TT_InheritanceComma))
+return true;
   if (Right.is(tok::string_literal) && Right.TokenText.startswith("R\""))
 // Multiline raw string literals are special wrt. line breaks. The author
 // has made a deliberate choice and might have aligned the contents of the
@@ -4058,12 +4061,18 @@
   if (Right.is(TT_CtorInitializerComma) &&
   Style.BreakConstructorInitializers == FormatStyle::BCIS_BeforeComma)
 return true;
-  if (Left.is(TT_InheritanceComma) &&
-  Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma)
-return false;
-  if (Right.is(TT_InheritanceComma) &&
-  Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma)
-return true;
+  if (Left.is(TT_InheritanceComma)) {
+if (Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma)
+  return false;
+else if (Style.BreakInheritanceList == FormatStyle::BILS_AfterComma)
+  return true;
+  }
+  if (Right.is(TT_InheritanceComma)) {

[PATCH] D103204: [Format] New BreakInheritanceList style AfterComma

2021-05-26 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray created this revision.
lichray requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This inheritance list style has been widely adopted by Symantec,
a division of Broadcom Inc. It breaks after the commas that
separate the base-specifiers:

  class Derived : public Base1,
  private Base2
  {
  };


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103204

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp


Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3639,6 +3639,9 @@
   if (Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma &&
   Right.is(TT_InheritanceComma))
 return true;
+  if (Style.BreakInheritanceList == FormatStyle::BILS_AfterComma &&
+  Left.is(TT_InheritanceComma))
+return true;
   if (Right.is(tok::string_literal) && Right.TokenText.startswith("R\""))
 // Multiline raw string literals are special wrt. line breaks. The author
 // has made a deliberate choice and might have aligned the contents of the
@@ -4058,12 +4061,18 @@
   if (Right.is(TT_CtorInitializerComma) &&
   Style.BreakConstructorInitializers == FormatStyle::BCIS_BeforeComma)
 return true;
-  if (Left.is(TT_InheritanceComma) &&
-  Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma)
-return false;
-  if (Right.is(TT_InheritanceComma) &&
-  Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma)
-return true;
+  if (Left.is(TT_InheritanceComma)) {
+if (Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma)
+  return false;
+else if (Style.BreakInheritanceList == FormatStyle::BILS_AfterComma)
+  return true;
+  }
+  if (Right.is(TT_InheritanceComma)) {
+if (Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma)
+  return true;
+else if (Style.BreakInheritanceList == FormatStyle::BILS_AfterComma)
+  return false;
+  }
   if ((Left.is(tok::greater) && Right.is(tok::greater)) ||
   (Left.is(tok::less) && Right.is(tok::less)))
 return false;
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -240,6 +240,7 @@
 IO.enumCase(Value, "BeforeColon", FormatStyle::BILS_BeforeColon);
 IO.enumCase(Value, "BeforeComma", FormatStyle::BILS_BeforeComma);
 IO.enumCase(Value, "AfterColon", FormatStyle::BILS_AfterColon);
+IO.enumCase(Value, "AfterComma", FormatStyle::BILS_AfterComma);
   }
 };
 
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -1829,7 +1829,14 @@
 ///Base2
 ///{};
 /// \endcode
-BILS_AfterColon
+BILS_AfterColon,
+/// Break inheritance list only after the commas.
+/// \code
+///class Foo : Base1,
+///Base2
+///{};
+/// \endcode
+BILS_AfterComma
   };
 
   /// The inheritance list style to use.
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -1999,6 +1999,15 @@
Base2
{};
 
+  * ``BILS_AfterComma`` (in configuration: ``AfterComma``)
+Break inheritance list only after and commas.
+
+.. code-block:: c++
+
+   class Foo : Base1,
+   Base2
+   {};
+
 
 
 **BreakStringLiterals** (``bool``)


Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3639,6 +3639,9 @@
   if (Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma &&
   Right.is(TT_InheritanceComma))
 return true;
+  if (Style.BreakInheritanceList == FormatStyle::BILS_AfterComma &&
+  Left.is(TT_InheritanceComma))
+return true;
   if (Right.is(tok::string_literal) && Right.TokenText.startswith("R\""))
 // Multiline raw string literals are special wrt. line breaks. The author
 // has made a deliberate choice and might have aligned the contents of the
@@ -4058,12 +4061,18 @@
   if (Right.is(TT_CtorInitializerComma) &&
   Style.BreakConstructorInitializers == FormatStyle::BCIS_BeforeComma)
 return true;
-  if (Left.is(TT_InheritanceComma) &&
-  Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma)
-return false;
-  if (Right.is(TT_InheritanceComma) &&
-  Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma)
-return true;
+  if (Left.is(TT_InheritanceComma)) {
+if (St