[clang-format] Update dump_format_style.py to indent nested fields

Summary:
This updates the format options documentation script to indent the
documentation of nested fields. The previous format caused some problems,
as when a bulleted list ends with a multiline comment. See the buildbot failure
http://lab.llvm.org:8011/builders/clang-sphinx-docs/builds/10020/steps/docs-clang-html/logs/stdio

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits

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

llvm-svn: 306093
This commit is contained in:
Krasimir Georgiev 2017-06-23 11:29:40 +00:00
parent 5d3d716815
commit 90b4ce38cb
2 changed files with 108 additions and 107 deletions

View File

@ -538,158 +538,158 @@ the configuration (without a prefix: ``Auto``).
* ``bool AfterClass`` Wrap class definitions.
.. code-block:: c++
.. code-block:: c++
true:
class foo {};
true:
class foo {};
false:
class foo
{};
false:
class foo
{};
* ``bool AfterControlStatement`` Wrap control statements (``if``/``for``/``while``/``switch``/..).
.. code-block:: c++
.. code-block:: c++
true:
if (foo())
{
} else
{}
for (int i = 0; i < 10; ++i)
{}
true:
if (foo())
{
} else
{}
for (int i = 0; i < 10; ++i)
{}
false:
if (foo()) {
} else {
}
for (int i = 0; i < 10; ++i) {
}
false:
if (foo()) {
} else {
}
for (int i = 0; i < 10; ++i) {
}
* ``bool AfterEnum`` Wrap enum definitions.
.. code-block:: c++
.. code-block:: c++
true:
enum X : int
{
B
};
true:
enum X : int
{
B
};
false:
enum X : int { B };
false:
enum X : int { B };
* ``bool AfterFunction`` Wrap function definitions.
.. code-block:: c++
.. code-block:: c++
true:
void foo()
{
bar();
bar2();
}
true:
void foo()
{
bar();
bar2();
}
false:
void foo() {
bar();
bar2();
}
false:
void foo() {
bar();
bar2();
}
* ``bool AfterNamespace`` Wrap namespace definitions.
.. code-block:: c++
.. code-block:: c++
true:
namespace
{
int foo();
int bar();
}
true:
namespace
{
int foo();
int bar();
}
false:
namespace {
int foo();
int bar();
}
false:
namespace {
int foo();
int bar();
}
* ``bool AfterObjCDeclaration`` Wrap ObjC definitions (``@autoreleasepool``, interfaces, ..).
* ``bool AfterStruct`` Wrap struct definitions.
.. code-block:: c++
.. code-block:: c++
true:
struct foo
{
int x;
};
true:
struct foo
{
int x;
};
false:
struct foo {
int x;
};
false:
struct foo {
int x;
};
* ``bool AfterUnion`` Wrap union definitions.
.. code-block:: c++
.. code-block:: c++
true:
union foo
{
int x;
}
true:
union foo
{
int x;
}
false:
union foo {
int x;
}
false:
union foo {
int x;
}
* ``bool BeforeCatch`` Wrap before ``catch``.
.. code-block:: c++
.. code-block:: c++
true:
try {
foo();
}
catch () {
}
true:
try {
foo();
}
catch () {
}
false:
try {
foo();
} catch () {
}
false:
try {
foo();
} catch () {
}
* ``bool BeforeElse`` Wrap before ``else``.
.. code-block:: c++
.. code-block:: c++
true:
if (foo()) {
}
else {
}
true:
if (foo()) {
}
else {
}
false:
if (foo()) {
} else {
}
false:
if (foo()) {
} else {
}
* ``bool IndentBraces`` Indent the wrapped braces themselves.
* ``bool SplitEmptyFunctionBody`` If ``false``, empty function body can be put on a single line.
This option is used only if the opening brace of the function has
already been wrapped, i.e. the `AfterFunction` brace wrapping mode is
set, and the function could/should not be put on a single line (as per
`AllowShortFunctionsOnASingleLine` and constructor formatting options).
This option is used only if the opening brace of the function has
already been wrapped, i.e. the `AfterFunction` brace wrapping mode is
set, and the function could/should not be put on a single line (as per
`AllowShortFunctionsOnASingleLine` and constructor formatting options).
.. code-block:: c++
.. code-block:: c++
int f() vs. inf f()
{} {
}
int f() vs. inf f()
{} {
}
**BreakAfterJavaFieldAnnotations** (``bool``)

View File

@ -24,10 +24,10 @@ def doxygen2rst(text):
text = re.sub(r'\\\w+ ', '', text)
return text
def indent(text, columns):
def indent(text, columns, indent_first_line=True):
indent = ' ' * columns
s = re.sub(r'\n([^\n])', '\n' + indent + '\\1', text, flags=re.S)
if s.startswith('\n'):
if not indent_first_line or s.startswith('\n'):
return s
return indent + s
@ -64,7 +64,9 @@ class NestedField:
self.comment = comment.strip()
def __str__(self):
return '\n* ``%s`` %s' % (self.name, doxygen2rst(self.comment))
return '\n* ``%s`` %s' % (
self.name,
doxygen2rst(indent(self.comment, 2, indent_first_line=False)))
class Enum:
def __init__(self, name, comment):
@ -179,7 +181,7 @@ def read_options(header):
if enums.has_key(option.type):
option.enum = enums[option.type]
elif nested_structs.has_key(option.type):
option.nested_struct = nested_structs[option.type];
option.nested_struct = nested_structs[option.type]
else:
raise Exception('Unknown type: %s' % option.type)
return options
@ -195,4 +197,3 @@ contents = substitute(contents, 'FORMAT_STYLE_OPTIONS', options_text)
with open(DOC_FILE, 'wb') as output:
output.write(contents)