[clang] eadb65f - [clang-format] [NFC] update the documentation in Format.h to allow dump_format_style.py to get a little closer to being correct. (part 2)

via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 6 12:03:28 PST 2019


Author: paulhoad
Date: 2019-11-06T20:03:05Z
New Revision: eadb65f273c076c4997b28a51f086eea505c3e78

URL: https://github.com/llvm/llvm-project/commit/eadb65f273c076c4997b28a51f086eea505c3e78
DIFF: https://github.com/llvm/llvm-project/commit/eadb65f273c076c4997b28a51f086eea505c3e78.diff

LOG: [clang-format] [NFC] update the documentation in Format.h to allow dump_format_style.py to get a little closer to being correct. (part 2)

Summary:
a change {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)

Reviewers: klimek, mitchell-stellar, sammccall

Reviewed By: mitchell-stellar, sammccall

Subscribers: mrexodia, cfe-commits

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D69433

Added: 
    

Modified: 
    clang/docs/ClangFormatStyleOptions.rst
    clang/docs/tools/dump_format_style.py
    clang/include/clang/Format/Format.h

Removed: 
    


################################################################################
diff  --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst
index cadb6d4f4919..1f915c346887 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2312,8 +2312,8 @@ the configuration (without a prefix: ``Auto``).
 
 **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++
 
@@ -2332,29 +2332,29 @@ the configuration (without a prefix: ``Auto``).
   Possible values:
 
   * ``LS_Cpp03`` (in configuration: ``c++03``)
-    Use C++03-compatible syntax.
+    Parse and format as C++03.
+    ``Cpp03`` is a deprecated alias for ``c++03``
 
   * ``LS_Cpp11`` (in configuration: ``c++11``)
-    Use C++11-compatible syntax.
+    Parse and format as C++11.
 
   * ``LS_Cpp14`` (in configuration: ``c++14``)
-    Use C++14-compatible syntax.
+    Parse and format as C++14.
 
   * ``LS_Cpp17`` (in configuration: ``c++17``)
-    Use C++17-compatible syntax.
+    Parse and format as C++17.
 
   * ``LS_Cpp20`` (in configuration: ``c++20``)
-    Use C++20-compatible syntax.
+    Parse and format as C++20.
 
   * ``LS_Latest`` (in configuration: ``Latest``)
     Parse and format using the latest supported language version.
+    ``Cpp11`` is a deprecated alias for ``Latest``
 
   * ``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

diff  --git a/clang/docs/tools/dump_format_style.py b/clang/docs/tools/dump_format_style.py
index 5feb793a4d70..db65e6e65b1c 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -78,14 +78,15 @@ def __str__(self):
     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 @@ class State(object):
         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')
 

diff  --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h
index b38d1f7d9402..70e82de28847 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -708,7 +708,7 @@ struct FormatStyle {
     BS_Allman,
     /// Like ``Allman`` but always indent braces and line up code with braces.
     /// \code
-    ///    try
+    ///   try
     ///     {
     ///     foo();
     ///     }
@@ -850,6 +850,7 @@ struct FormatStyle {
     ///   {};
     /// \endcode
     bool AfterClass;
+
     /// Wrap control statements (``if``/``for``/``while``/``switch``/..).
     BraceWrappingAfterControlStatementStyle AfterControlStatement;
     /// Wrap enum definitions.
@@ -1965,7 +1966,8 @@ struct FormatStyle {
   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 @@ struct FormatStyle {
   /// 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.
+    /// Parse and format as C++03.
+    /// ``Cpp03`` is a deprecated alias for ``c++03``
+    LS_Cpp03, // c++03
+    /// Parse and format as C++11.
+    LS_Cpp11, // c++11
+    /// Parse and format as C++14.
+    LS_Cpp14, // c++14
+    /// Parse and format as C++17.
+    LS_Cpp17, // c++17
+    /// Parse and format as C++20.
+    LS_Cpp20, // c++20
+    /// Parse and format using the latest supported language version.
+    /// ``Cpp11`` is a deprecated alias for ``Latest``
     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.


        


More information about the cfe-commits mailing list