Skip to content

Commit eadb65f

Browse files
[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
1 parent b5913e6 commit eadb65f

File tree

3 files changed

+43
-30
lines changed

3 files changed

+43
-30
lines changed

clang/docs/ClangFormatStyleOptions.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2312,8 +2312,8 @@ the configuration (without a prefix: ``Auto``).
23122312

23132313
**SpacesInSquareBrackets** (``bool``)
23142314
If ``true``, spaces will be inserted after ``[`` and before ``]``.
2315-
Lambdas without arguments or unspecified size array declarations will not be
2316-
affected.
2315+
Lambdas without arguments or unspecified size array declarations will not
2316+
be affected.
23172317

23182318
.. code-block:: c++
23192319

@@ -2332,29 +2332,29 @@ the configuration (without a prefix: ``Auto``).
23322332
Possible values:
23332333

23342334
* ``LS_Cpp03`` (in configuration: ``c++03``)
2335-
Use C++03-compatible syntax.
2335+
Parse and format as C++03.
2336+
``Cpp03`` is a deprecated alias for ``c++03``
23362337

23372338
* ``LS_Cpp11`` (in configuration: ``c++11``)
2338-
Use C++11-compatible syntax.
2339+
Parse and format as C++11.
23392340

23402341
* ``LS_Cpp14`` (in configuration: ``c++14``)
2341-
Use C++14-compatible syntax.
2342+
Parse and format as C++14.
23422343

23432344
* ``LS_Cpp17`` (in configuration: ``c++17``)
2344-
Use C++17-compatible syntax.
2345+
Parse and format as C++17.
23452346

23462347
* ``LS_Cpp20`` (in configuration: ``c++20``)
2347-
Use C++20-compatible syntax.
2348+
Parse and format as C++20.
23482349

23492350
* ``LS_Latest`` (in configuration: ``Latest``)
23502351
Parse and format using the latest supported language version.
2352+
``Cpp11`` is a deprecated alias for ``Latest``
23512353

23522354
* ``LS_Auto`` (in configuration: ``Auto``)
23532355
Automatic detection based on the input.
23542356

2355-
* ``Cpp03``: deprecated alias for ``c++03``
23562357

2357-
* ``Cpp11``: deprecated alias for ``Latest``
23582358

23592359
**StatementMacros** (``std::vector<std::string>``)
23602360
A vector of macros that should be interpreted as complete

clang/docs/tools/dump_format_style.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,15 @@ def __str__(self):
7878
return '\n'.join(map(str, self.values))
7979

8080
class EnumValue(object):
81-
def __init__(self, name, comment):
81+
def __init__(self, name, comment, config):
8282
self.name = name
8383
self.comment = comment
84+
self.config = config
8485

8586
def __str__(self):
8687
return '* ``%s`` (in configuration: ``%s``)\n%s' % (
8788
self.name,
88-
re.sub('.*_', '', self.name),
89+
re.sub('.*_', '', self.config),
8990
doxygen2rst(indent(self.comment, 2)))
9091

9192
def clean_comment_line(line):
@@ -170,7 +171,14 @@ class State(object):
170171
comment += clean_comment_line(line)
171172
else:
172173
state = State.InEnum
173-
enum.values.append(EnumValue(line.replace(',', ''), comment))
174+
val = line.replace(',', '')
175+
pos = val.find(" // ")
176+
if (pos != -1):
177+
config = val[pos+4:]
178+
val = val[:pos]
179+
else:
180+
config = val;
181+
enum.values.append(EnumValue(val, comment,config))
174182
if state != State.Finished:
175183
raise Exception('Not finished by the end of file')
176184

clang/include/clang/Format/Format.h

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ struct FormatStyle {
708708
BS_Allman,
709709
/// Like ``Allman`` but always indent braces and line up code with braces.
710710
/// \code
711-
/// try
711+
/// try
712712
/// {
713713
/// foo();
714714
/// }
@@ -850,6 +850,7 @@ struct FormatStyle {
850850
/// {};
851851
/// \endcode
852852
bool AfterClass;
853+
853854
/// Wrap control statements (``if``/``for``/``while``/``switch``/..).
854855
BraceWrappingAfterControlStatementStyle AfterControlStatement;
855856
/// Wrap enum definitions.
@@ -1965,7 +1966,8 @@ struct FormatStyle {
19651966
bool SpacesInParentheses;
19661967

19671968
/// If ``true``, spaces will be inserted after ``[`` and before ``]``.
1968-
/// Lambdas or unspecified size array declarations will not be affected.
1969+
/// Lambdas without arguments or unspecified size array declarations will not
1970+
/// be affected.
19691971
/// \code
19701972
/// true: false:
19711973
/// int a[ 5 ]; vs. int a[5];
@@ -1982,26 +1984,29 @@ struct FormatStyle {
19821984
/// The correct way to spell a specific language version is e.g. ``c++11``.
19831985
/// The historical aliases ``Cpp03`` and ``Cpp11`` are deprecated.
19841986
enum LanguageStandard {
1985-
/// c++03: Parse and format as C++03.
1986-
LS_Cpp03,
1987-
/// c++11: Parse and format as C++11.
1988-
LS_Cpp11,
1989-
/// c++14: Parse and format as C++14.
1990-
LS_Cpp14,
1991-
/// c++17: Parse and format as C++17.
1992-
LS_Cpp17,
1993-
/// c++20: Parse and format as C++20.
1994-
LS_Cpp20,
1995-
/// Latest: Parse and format using the latest supported language version.
1996-
/// 'Cpp11' is an alias for LS_Latest for historical reasons.
1987+
/// Parse and format as C++03.
1988+
/// ``Cpp03`` is a deprecated alias for ``c++03``
1989+
LS_Cpp03, // c++03
1990+
/// Parse and format as C++11.
1991+
LS_Cpp11, // c++11
1992+
/// Parse and format as C++14.
1993+
LS_Cpp14, // c++14
1994+
/// Parse and format as C++17.
1995+
LS_Cpp17, // c++17
1996+
/// Parse and format as C++20.
1997+
LS_Cpp20, // c++20
1998+
/// Parse and format using the latest supported language version.
1999+
/// ``Cpp11`` is a deprecated alias for ``Latest``
19972000
LS_Latest,
1998-
/// Auto: Automatic detection based on the input.
1999-
/// Parse using the latest language version. Format based on detected input.
2001+
/// Automatic detection based on the input.
20002002
LS_Auto,
20012003
};
20022004

2003-
/// Format compatible with this standard, e.g. use ``A<A<int> >``
2004-
/// instead of ``A<A<int>>`` for ``LS_Cpp03``.
2005+
/// Parse and format C++ constructs compatible with this standard.
2006+
/// \code
2007+
/// c++03: latest:
2008+
/// vector<set<int> > x; vs. vector<set<int>> x;
2009+
/// \endcode
20052010
LanguageStandard Standard;
20062011

20072012
/// The number of columns used for tab stops.

0 commit comments

Comments
 (0)