MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: klimek, mitchell-stellar, sammccall.
MyDeveloperDay added projects: clang, clang-format.

a change D67541: [ClangFormat] Future-proof Standard option, allow floating or 
pinning to arbitrary lang version <https://reviews.llvm.org/D67541> cause 
LanguageStandard to now be subtly different from all other clang-format 
options, in that the Enum value (less the prefix) is not always allowed as 
valid as the configuration option.

This caused the ClangFormatStyleOptions.rst and the Format.h to diverge so that 
the ClangFormatStyleOptions.rst could no longer be generated from the Format.h 
using dump_format_stlye.py

This fix tried to remedy that:

1. by allowing an additional comment (in Format.h) after the enum to be used as 
the `in configuration ( XXXX )`  text, and changing the dump_format_style.py to 
support that.

This makes the following code:

  enum {
  ...
  LS_Cpp03, // c++03
  LS_Cpp11, // c++11
  ...
  };

would render as:

  * ``LS_Cpp03`` (in configuration: ``c++03``)
  * ``LS_Cpp11`` (in configuration: ``c++11``)

And we also  move the deprecated alias into the text of the enum (otherwise it 
won't be added at the end as an option)

This patch includes a couple of other whitespace changes which help bring 
Format.h and ClangFormatStyleOptions.rst almost back into line and 
regeneratable...  (there is still one more)


Repository:
  rC Clang

https://reviews.llvm.org/D69433

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/tools/dump_format_style.py
  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
@@ -708,7 +708,7 @@
     BS_Allman,
     /// Like ``Allman`` but always indent braces and line up code with braces.
     /// \code
-    ///    try
+    ///   try
     ///     {
     ///     foo();
     ///     }
@@ -850,6 +850,7 @@
     ///   {};
     /// \endcode
     bool AfterClass;
+
     /// Wrap control statements (``if``/``for``/``while``/``switch``/..).
     BraceWrappingAfterControlStatementStyle AfterControlStatement;
     /// Wrap enum definitions.
@@ -1965,7 +1966,8 @@
   bool SpacesInParentheses;
 
   /// If ``true``, spaces will be inserted after ``[`` and before ``]``.
-  /// Lambdas or unspecified size array declarations will not be affected.
+  /// Lambdas without arguments or unspecified size array declarations will not
+  /// be affected.
   /// \code
   ///    true:                                  false:
   ///    int a[ 5 ];                    vs.     int a[5];
@@ -1982,26 +1984,29 @@
   /// The correct way to spell a specific language version is e.g. ``c++11``.
   /// The historical aliases ``Cpp03`` and ``Cpp11`` are deprecated.
   enum LanguageStandard {
-    /// c++03: Parse and format as C++03.
-    LS_Cpp03,
-    /// c++11: Parse and format as C++11.
-    LS_Cpp11,
-    /// c++14: Parse and format as C++14.
-    LS_Cpp14,
-    /// c++17: Parse and format as C++17.
-    LS_Cpp17,
-    /// c++20: Parse and format as C++20.
-    LS_Cpp20,
-    /// Latest: Parse and format using the latest supported language version.
-    /// 'Cpp11' is an alias for LS_Latest for historical reasons.
+    /// Use C++03-compatible syntax.
+    /// ``Cpp03``: deprecated alias for ``c++03``
+    LS_Cpp03, // c++03
+    /// Use C++11-compatible syntax.
+    LS_Cpp11, // c++11
+    /// Use C++14-compatible syntax.
+    /// ``Cpp11``: deprecated alias for ``Latest``
+    LS_Cpp14, // c++14
+    /// Use C++17-compatible syntax.
+    LS_Cpp17, // c++17
+    /// Use C++20-compatible syntax.
+    LS_Cpp20, // c++20
+    /// Parse and format using the latest supported language version.
     LS_Latest,
-    /// Auto: Automatic detection based on the input.
-    /// Parse using the latest language version. Format based on detected input.
+    /// Automatic detection based on the input.
     LS_Auto,
   };
 
-  /// Format compatible with this standard, e.g. use ``A<A<int> >``
-  /// instead of ``A<A<int>>`` for ``LS_Cpp03``.
+  /// Parse and Format C++ constructs compatible with this standard.
+  /// \code
+  ///    c++03:                                 latest:
+  ///    vector<set<int> > x;           vs.     vector<set<int>> x;
+  /// \endcode
   LanguageStandard Standard;
 
   /// The number of columns used for tab stops.
Index: clang/docs/tools/dump_format_style.py
===================================================================
--- clang/docs/tools/dump_format_style.py
+++ clang/docs/tools/dump_format_style.py
@@ -78,14 +78,15 @@
     return '\n'.join(map(str, self.values))
 
 class EnumValue(object):
-  def __init__(self, name, comment):
+  def __init__(self, name, comment, config):
     self.name = name
     self.comment = comment
+    self.config = config
 
   def __str__(self):
     return '* ``%s`` (in configuration: ``%s``)\n%s' % (
         self.name,
-        re.sub('.*_', '', self.name),
+        re.sub('.*_', '', self.config),
         doxygen2rst(indent(self.comment, 2)))
 
 def clean_comment_line(line):
@@ -170,7 +171,14 @@
         comment += clean_comment_line(line)
       else:
         state = State.InEnum
-        enum.values.append(EnumValue(line.replace(',', ''), comment))
+        val = line.replace(',', '')
+        pos = val.find(" // ")
+        if (pos != -1):
+            config = val[pos+4:]
+            val = val[:pos]
+        else:
+            config = val;
+        enum.values.append(EnumValue(val, comment,config))
   if state != State.Finished:
     raise Exception('Not finished by the end of file')
 
Index: clang/docs/ClangFormatStyleOptions.rst
===================================================================
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -2312,8 +2312,8 @@
 
 **SpacesInSquareBrackets** (``bool``)
   If ``true``, spaces will be inserted after ``[`` and before ``]``.
-  Lambdas without arguments or unspecified size array declarations will not be
-  affected.
+  Lambdas without arguments or unspecified size array declarations will not
+  be affected.
 
   .. code-block:: c++
 
@@ -2333,12 +2333,14 @@
 
   * ``LS_Cpp03`` (in configuration: ``c++03``)
     Use C++03-compatible syntax.
+    ``Cpp03``: deprecated alias for ``c++03``
 
   * ``LS_Cpp11`` (in configuration: ``c++11``)
     Use C++11-compatible syntax.
 
   * ``LS_Cpp14`` (in configuration: ``c++14``)
     Use C++14-compatible syntax.
+    ``Cpp11``: deprecated alias for ``Latest``
 
   * ``LS_Cpp17`` (in configuration: ``c++17``)
     Use C++17-compatible syntax.
@@ -2352,9 +2354,7 @@
   * ``LS_Auto`` (in configuration: ``Auto``)
     Automatic detection based on the input.
 
-  * ``Cpp03``: deprecated alias for ``c++03``
 
-  * ``Cpp11``: deprecated alias for ``Latest``
 
 **StatementMacros** (``std::vector<std::string>``)
   A vector of macros that should be interpreted as complete
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to