C++, update docs and enums. Fixes sphinx-doc/sphinx#772.

This commit is contained in:
Jakob Lykke Andersen 2015-02-08 23:09:44 +01:00
parent fd84a3d602
commit 44ee988981
2 changed files with 50 additions and 33 deletions

View File

@ -520,8 +520,8 @@ The C++ Domain
The C++ domain (name **cpp**) supports documenting C++ projects.
The following directives are available. All declarations except for enumerators
can start with a visibility statement (``public``, ``private`` or ``protected``).
The following directives are available. All declarations can start with
a visibility statement (``public``, ``private`` or ``protected``).
.. rst:directive:: .. cpp:class:: class speicifer
@ -578,10 +578,11 @@ can start with a visibility statement (``public``, ``private`` or ``protected``)
Declaration of a type alias with unspecified type.
.. rst:directive:: .. cpp:enum:: enum declaration
.. rst:directive:: .. cpp:enum:: unscoped enum declaration
.. cpp:enum-struct:: scoped enum declaration
.. cpp:enum-class:: scoped enum declaration
Describe a (scoped) enum, possibly with the underlying type specified. Note that for scoped
enums the ``struct``/``class`` keyword must come before the optional visibility specifier.
Describe a (scoped) enum, possibly with the underlying type specified.
Any enumerators declared inside an unscoped enum will be declared both in the enum scope
and in the parent scope.
Examples:
@ -594,11 +595,11 @@ can start with a visibility statement (``public``, ``private`` or ``protected``)
An unscoped enum with specified underlying type.
.. cpp:enum:: class MyScopedEnum
.. cpp:enum-class:: MyScopedEnum
A scoped enum.
.. cpp:enum:: struct protected MyScopedVisibilityEnum : std::underlying_type<MySpecificEnum>::type
.. cpp:enum-struct:: protected MyScopedVisibilityEnum : std::underlying_type<MySpecificEnum>::type
A scoped enum with non-default visibility, and with a specified underlying type.
@ -609,27 +610,31 @@ can start with a visibility statement (``public``, ``private`` or ``protected``)
.. rst:directive:: .. cpp:namespace:: namespace
Select the current namespace for the following objects. Note that the namespace
Select the current namespace for the subsequent objects. Note that the namespace
does not need to correspond to C++ namespaces, but can end in names of classes, e.g.,::
.. cpp:namespace:: Namespace1::Namespace2::SomeClass::AnInnerClass
All following objects will be defined as if their name were declared with the namespace
prepended. The following cross-references will be search for by both their specified name
All subsequent objects will be defined as if their name were declared with the namespace
prepended. The subsequent cross-references will be searched for by both their specified name
and with the namespace prepended.
Using ``NULL``, ``0``, or ``nullptr`` as the namespace will reset it to the global namespace.
.. _cpp-roles:
These roles link to the given object types:
.. rst:role:: cpp:class
cpp:func
cpp:member
cpp:type
cpp:func
cpp:member
cpp:type
cpp:enum
cpp:enumerator
Reference a C++ object. You can give the full specification (and need to, for
overloaded functions.)
Reference a C++ object by name. The name must be properly qualified relative to the
position of the link.
.. note::

View File

@ -2016,12 +2016,8 @@ class DefinitionParser(object):
return ASTClass(name, classVisibility, bases)
def _parse_enum(self):
scoped = None
scoped = None # is set by CPPEnumObject
self.skip_ws()
if self.skip_word_and_ws('class'):
scoped = 'class'
elif self.skip_word_and_ws('struct'):
scoped = 'struct'
visibility = 'public'
if self.match(_visibility_re):
visibility = self.matched_text
@ -2219,12 +2215,14 @@ class CPPClassObject(CPPObject):
return _('%s (C++ class)') % name
def before_content(self):
lastname = self.env.ref_context['cpp:lastname']
assert lastname
if 'cpp:parent' in self.env.ref_context:
self.env.ref_context['cpp:parent'].append(lastname)
else:
self.env.ref_context['cpp:parent'] = [lastname]
# lastname may not be set if there was an error
if 'cpp:lastname' in self.env.ref_context:
lastname = self.env.ref_context['cpp:lastname']
assert lastname
if 'cpp:parent' in self.env.ref_context:
self.env.ref_context['cpp:parent'].append(lastname)
else:
self.env.ref_context['cpp:parent'] = [lastname]
def after_content(self):
self.env.ref_context['cpp:parent'].pop()
@ -2242,18 +2240,30 @@ class CPPEnumObject(CPPObject):
return _('%s (C++ enum)') % name
def before_content(self):
lastname = self.env.ref_context['cpp:lastname']
assert lastname
if 'cpp:parent' in self.env.ref_context:
self.env.ref_context['cpp:parent'].append(lastname)
else:
self.env.ref_context['cpp:parent'] = [lastname]
# lastname may not be set if there was an error
if 'cpp:lastname' in self.env.ref_context:
lastname = self.env.ref_context['cpp:lastname']
assert lastname
if 'cpp:parent' in self.env.ref_context:
self.env.ref_context['cpp:parent'].append(lastname)
else:
self.env.ref_context['cpp:parent'] = [lastname]
def after_content(self):
self.env.ref_context['cpp:parent'].pop()
def parse_definition(self, parser):
return parser.parse_enum_object()
ast = parser.parse_enum_object()
# self.objtype is set by ObjectDescription in run()
if self.objtype == "enum":
ast.scoped = None
elif self.objtype == "enum-struct":
ast.scoped = "struct"
elif self.objtype == "enum-class":
ast.scoped = "class"
else:
assert False
return ast
def describe_signature(self, signode, ast):
prefix = 'enum '
@ -2340,6 +2350,8 @@ class CPPDomain(Domain):
'member': CPPMemberObject,
'type': CPPTypeObject,
'enum': CPPEnumObject,
'enum-struct': CPPEnumObject,
'enum-class': CPPEnumObject,
'enumerator': CPPEnumeratorObject,
'namespace': CPPNamespaceObject
}