Skip to content

Commit 4c8bc86

Browse files
committed
[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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306093 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 8864382 commit 4c8bc86

File tree

2 files changed

+108
-107
lines changed

2 files changed

+108
-107
lines changed

docs/ClangFormatStyleOptions.rst

+102-102
Original file line numberDiff line numberDiff line change
@@ -538,158 +538,158 @@ the configuration (without a prefix: ``Auto``).
538538

539539
* ``bool AfterClass`` Wrap class definitions.
540540

541-
.. code-block:: c++
541+
.. code-block:: c++
542542

543-
true:
544-
class foo {};
543+
true:
544+
class foo {};
545545

546-
false:
547-
class foo
548-
{};
546+
false:
547+
class foo
548+
{};
549549

550550
* ``bool AfterControlStatement`` Wrap control statements (``if``/``for``/``while``/``switch``/..).
551551

552-
.. code-block:: c++
552+
.. code-block:: c++
553553

554-
true:
555-
if (foo())
556-
{
557-
} else
558-
{}
559-
for (int i = 0; i < 10; ++i)
560-
{}
554+
true:
555+
if (foo())
556+
{
557+
} else
558+
{}
559+
for (int i = 0; i < 10; ++i)
560+
{}
561561

562-
false:
563-
if (foo()) {
564-
} else {
565-
}
566-
for (int i = 0; i < 10; ++i) {
567-
}
562+
false:
563+
if (foo()) {
564+
} else {
565+
}
566+
for (int i = 0; i < 10; ++i) {
567+
}
568568

569569
* ``bool AfterEnum`` Wrap enum definitions.
570570

571-
.. code-block:: c++
571+
.. code-block:: c++
572572

573-
true:
574-
enum X : int
575-
{
576-
B
577-
};
573+
true:
574+
enum X : int
575+
{
576+
B
577+
};
578578

579-
false:
580-
enum X : int { B };
579+
false:
580+
enum X : int { B };
581581

582582
* ``bool AfterFunction`` Wrap function definitions.
583583

584-
.. code-block:: c++
584+
.. code-block:: c++
585585

586-
true:
587-
void foo()
588-
{
589-
bar();
590-
bar2();
591-
}
586+
true:
587+
void foo()
588+
{
589+
bar();
590+
bar2();
591+
}
592592

593-
false:
594-
void foo() {
595-
bar();
596-
bar2();
597-
}
593+
false:
594+
void foo() {
595+
bar();
596+
bar2();
597+
}
598598

599599
* ``bool AfterNamespace`` Wrap namespace definitions.
600600

601-
.. code-block:: c++
601+
.. code-block:: c++
602602

603-
true:
604-
namespace
605-
{
606-
int foo();
607-
int bar();
608-
}
603+
true:
604+
namespace
605+
{
606+
int foo();
607+
int bar();
608+
}
609609

610-
false:
611-
namespace {
612-
int foo();
613-
int bar();
614-
}
610+
false:
611+
namespace {
612+
int foo();
613+
int bar();
614+
}
615615

616616
* ``bool AfterObjCDeclaration`` Wrap ObjC definitions (``@autoreleasepool``, interfaces, ..).
617617

618618
* ``bool AfterStruct`` Wrap struct definitions.
619619

620-
.. code-block:: c++
620+
.. code-block:: c++
621621

622-
true:
623-
struct foo
624-
{
625-
int x;
626-
};
622+
true:
623+
struct foo
624+
{
625+
int x;
626+
};
627627

628-
false:
629-
struct foo {
630-
int x;
631-
};
628+
false:
629+
struct foo {
630+
int x;
631+
};
632632

633633
* ``bool AfterUnion`` Wrap union definitions.
634634

635-
.. code-block:: c++
635+
.. code-block:: c++
636636

637-
true:
638-
union foo
639-
{
640-
int x;
641-
}
637+
true:
638+
union foo
639+
{
640+
int x;
641+
}
642642

643-
false:
644-
union foo {
645-
int x;
646-
}
643+
false:
644+
union foo {
645+
int x;
646+
}
647647

648648
* ``bool BeforeCatch`` Wrap before ``catch``.
649649

650-
.. code-block:: c++
650+
.. code-block:: c++
651651

652-
true:
653-
try {
654-
foo();
655-
}
656-
catch () {
657-
}
652+
true:
653+
try {
654+
foo();
655+
}
656+
catch () {
657+
}
658658

659-
false:
660-
try {
661-
foo();
662-
} catch () {
663-
}
659+
false:
660+
try {
661+
foo();
662+
} catch () {
663+
}
664664

665665
* ``bool BeforeElse`` Wrap before ``else``.
666666

667-
.. code-block:: c++
667+
.. code-block:: c++
668668

669-
true:
670-
if (foo()) {
671-
}
672-
else {
673-
}
669+
true:
670+
if (foo()) {
671+
}
672+
else {
673+
}
674674

675-
false:
676-
if (foo()) {
677-
} else {
678-
}
675+
false:
676+
if (foo()) {
677+
} else {
678+
}
679679

680680
* ``bool IndentBraces`` Indent the wrapped braces themselves.
681681

682682
* ``bool SplitEmptyFunctionBody`` If ``false``, empty function body can be put on a single line.
683-
This option is used only if the opening brace of the function has
684-
already been wrapped, i.e. the `AfterFunction` brace wrapping mode is
685-
set, and the function could/should not be put on a single line (as per
686-
`AllowShortFunctionsOnASingleLine` and constructor formatting options).
683+
This option is used only if the opening brace of the function has
684+
already been wrapped, i.e. the `AfterFunction` brace wrapping mode is
685+
set, and the function could/should not be put on a single line (as per
686+
`AllowShortFunctionsOnASingleLine` and constructor formatting options).
687687

688-
.. code-block:: c++
688+
.. code-block:: c++
689689

690-
int f() vs. inf f()
691-
{} {
692-
}
690+
int f() vs. inf f()
691+
{} {
692+
}
693693

694694

695695
**BreakAfterJavaFieldAnnotations** (``bool``)

docs/tools/dump_format_style.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ def doxygen2rst(text):
2424
text = re.sub(r'\\\w+ ', '', text)
2525
return text
2626

27-
def indent(text, columns):
27+
def indent(text, columns, indent_first_line=True):
2828
indent = ' ' * columns
2929
s = re.sub(r'\n([^\n])', '\n' + indent + '\\1', text, flags=re.S)
30-
if s.startswith('\n'):
30+
if not indent_first_line or s.startswith('\n'):
3131
return s
3232
return indent + s
3333

@@ -64,7 +64,9 @@ def __init__(self, name, comment):
6464
self.comment = comment.strip()
6565

6666
def __str__(self):
67-
return '\n* ``%s`` %s' % (self.name, doxygen2rst(self.comment))
67+
return '\n* ``%s`` %s' % (
68+
self.name,
69+
doxygen2rst(indent(self.comment, 2, indent_first_line=False)))
6870

6971
class Enum:
7072
def __init__(self, name, comment):
@@ -179,7 +181,7 @@ class State:
179181
if enums.has_key(option.type):
180182
option.enum = enums[option.type]
181183
elif nested_structs.has_key(option.type):
182-
option.nested_struct = nested_structs[option.type];
184+
option.nested_struct = nested_structs[option.type]
183185
else:
184186
raise Exception('Unknown type: %s' % option.type)
185187
return options
@@ -195,4 +197,3 @@ class State:
195197

196198
with open(DOC_FILE, 'wb') as output:
197199
output.write(contents)
198-

0 commit comments

Comments
 (0)