forked from OSchip/llvm-project
[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
This commit is contained in:
parent
b5913e6d2f
commit
eadb65f273
|
@ -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
|
||||
|
|
|
@ -78,14 +78,15 @@ class Enum(object):
|
|||
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 @@ def read_options(header):
|
|||
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')
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue