mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
C++, support for unions.
This commit is contained in:
parent
f592483156
commit
6d52b63eee
1
CHANGES
1
CHANGES
@ -117,6 +117,7 @@ Features added
|
|||||||
* #4927: Display a warning when invalid values are passed to linenothreshold
|
* #4927: Display a warning when invalid values are passed to linenothreshold
|
||||||
option of highlight directive
|
option of highlight directive
|
||||||
* C++, add a ``cpp:texpr`` role as a sibling to ``cpp:expr``.
|
* C++, add a ``cpp:texpr`` role as a sibling to ``cpp:expr``.
|
||||||
|
* C++, add support for unions.
|
||||||
|
|
||||||
Bugs fixed
|
Bugs fixed
|
||||||
----------
|
----------
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
# You can set these variables from the command line.
|
# You can set these variables from the command line.
|
||||||
SPHINXOPTS =
|
SPHINXOPTS =
|
||||||
SPHINXBUILD = python ../sphinx/cmd/build.py
|
SPHINXBUILD = python3 ../sphinx/cmd/build.py
|
||||||
SPHINXPROJ = sphinx
|
SPHINXPROJ = sphinx
|
||||||
SOURCEDIR = .
|
SOURCEDIR = .
|
||||||
BUILDDIR = _build
|
BUILDDIR = _build
|
||||||
|
@ -702,6 +702,10 @@ visibility statement (``public``, ``private`` or ``protected``).
|
|||||||
|
|
||||||
.. cpp:enumerator:: MyEnum::myOtherEnumerator = 42
|
.. cpp:enumerator:: MyEnum::myOtherEnumerator = 42
|
||||||
|
|
||||||
|
.. rst:directive:: .. cpp:union:: name
|
||||||
|
|
||||||
|
Describe a union.
|
||||||
|
|
||||||
.. rst:directive:: .. cpp:concept:: template-parameter-list name
|
.. rst:directive:: .. cpp:concept:: template-parameter-list name
|
||||||
|
|
||||||
.. warning:: The support for concepts is experimental. It is based on the
|
.. warning:: The support for concepts is experimental. It is based on the
|
||||||
|
@ -3196,6 +3196,27 @@ class ASTClass(ASTBase):
|
|||||||
signode.pop()
|
signode.pop()
|
||||||
|
|
||||||
|
|
||||||
|
class ASTUnion(ASTBase):
|
||||||
|
def __init__(self, name):
|
||||||
|
# type: (Any) -> None
|
||||||
|
self.name = name
|
||||||
|
|
||||||
|
def get_id(self, version, objectType, symbol):
|
||||||
|
# type: (int, unicode, Symbol) -> unicode
|
||||||
|
if version == 1:
|
||||||
|
raise NoOldIdError()
|
||||||
|
return symbol.get_full_nested_name().get_id(version)
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
# type: () -> unicode
|
||||||
|
return text_type(self.name)
|
||||||
|
|
||||||
|
def describe_signature(self, signode, mode, env, symbol):
|
||||||
|
# type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None
|
||||||
|
_verify_description_mode(mode)
|
||||||
|
self.name.describe_signature(signode, mode, env, symbol=symbol)
|
||||||
|
|
||||||
|
|
||||||
class ASTEnum(ASTBase):
|
class ASTEnum(ASTBase):
|
||||||
def __init__(self, name, scoped, underlyingType):
|
def __init__(self, name, scoped, underlyingType):
|
||||||
# type: (Any, unicode, Any) -> None
|
# type: (Any, unicode, Any) -> None
|
||||||
@ -3361,6 +3382,8 @@ class ASTDeclaration(ASTBase):
|
|||||||
pass
|
pass
|
||||||
elif self.objectType == 'class':
|
elif self.objectType == 'class':
|
||||||
mainDeclNode += addnodes.desc_annotation('class ', 'class ')
|
mainDeclNode += addnodes.desc_annotation('class ', 'class ')
|
||||||
|
elif self.objectType == 'union':
|
||||||
|
mainDeclNode += addnodes.desc_annotation('union ', 'union ')
|
||||||
elif self.objectType == 'enum':
|
elif self.objectType == 'enum':
|
||||||
prefix = 'enum '
|
prefix = 'enum '
|
||||||
if self.scoped: # type: ignore
|
if self.scoped: # type: ignore
|
||||||
@ -5259,6 +5282,11 @@ class DefinitionParser(object):
|
|||||||
break
|
break
|
||||||
return ASTClass(name, final, bases)
|
return ASTClass(name, final, bases)
|
||||||
|
|
||||||
|
def _parse_union(self):
|
||||||
|
# type: () -> ASTUnion
|
||||||
|
name = self._parse_nested_name()
|
||||||
|
return ASTUnion(name)
|
||||||
|
|
||||||
def _parse_enum(self):
|
def _parse_enum(self):
|
||||||
# type: () -> ASTEnum
|
# type: () -> ASTEnum
|
||||||
scoped = None # type: unicode # is set by CPPEnumObject
|
scoped = None # type: unicode # is set by CPPEnumObject
|
||||||
@ -5466,7 +5494,7 @@ class DefinitionParser(object):
|
|||||||
def parse_declaration(self, objectType):
|
def parse_declaration(self, objectType):
|
||||||
# type: (unicode) -> ASTDeclaration
|
# type: (unicode) -> ASTDeclaration
|
||||||
if objectType not in ('type', 'concept', 'member',
|
if objectType not in ('type', 'concept', 'member',
|
||||||
'function', 'class', 'enum', 'enumerator'):
|
'function', 'class', 'union', 'enum', 'enumerator'):
|
||||||
raise Exception('Internal error, unknown objectType "%s".' % objectType)
|
raise Exception('Internal error, unknown objectType "%s".' % objectType)
|
||||||
visibility = None
|
visibility = None
|
||||||
templatePrefix = None
|
templatePrefix = None
|
||||||
@ -5505,6 +5533,8 @@ class DefinitionParser(object):
|
|||||||
declaration = self._parse_type(named=True, outer='function')
|
declaration = self._parse_type(named=True, outer='function')
|
||||||
elif objectType == 'class':
|
elif objectType == 'class':
|
||||||
declaration = self._parse_class()
|
declaration = self._parse_class()
|
||||||
|
elif objectType == 'union':
|
||||||
|
declaration = self._parse_union()
|
||||||
elif objectType == 'enum':
|
elif objectType == 'enum':
|
||||||
declaration = self._parse_enum()
|
declaration = self._parse_enum()
|
||||||
elif objectType == 'enumerator':
|
elif objectType == 'enumerator':
|
||||||
@ -5807,6 +5837,16 @@ class CPPClassObject(CPPObject):
|
|||||||
return parser.parse_declaration("class")
|
return parser.parse_declaration("class")
|
||||||
|
|
||||||
|
|
||||||
|
class CPPUnionObject(CPPObject):
|
||||||
|
def get_index_text(self, name):
|
||||||
|
# type: (unicode) -> unicode
|
||||||
|
return _('%s (C++ union)') % name
|
||||||
|
|
||||||
|
def parse_definition(self, parser):
|
||||||
|
# type: (Any) -> Any
|
||||||
|
return parser.parse_declaration("union")
|
||||||
|
|
||||||
|
|
||||||
class CPPEnumObject(CPPObject):
|
class CPPEnumObject(CPPObject):
|
||||||
def get_index_text(self, name):
|
def get_index_text(self, name):
|
||||||
# type: (unicode) -> unicode
|
# type: (unicode) -> unicode
|
||||||
@ -6007,6 +6047,7 @@ class CPPDomain(Domain):
|
|||||||
label = 'C++'
|
label = 'C++'
|
||||||
object_types = {
|
object_types = {
|
||||||
'class': ObjType(_('class'), 'class', 'type', 'identifier'),
|
'class': ObjType(_('class'), 'class', 'type', 'identifier'),
|
||||||
|
'union': ObjType(_('union'), 'union', 'type', 'identifier'),
|
||||||
'function': ObjType(_('function'), 'function', 'func', 'type', 'identifier'),
|
'function': ObjType(_('function'), 'function', 'func', 'type', 'identifier'),
|
||||||
'member': ObjType(_('member'), 'member', 'var'),
|
'member': ObjType(_('member'), 'member', 'var'),
|
||||||
'type': ObjType(_('type'), 'type', 'identifier'),
|
'type': ObjType(_('type'), 'type', 'identifier'),
|
||||||
@ -6017,6 +6058,7 @@ class CPPDomain(Domain):
|
|||||||
|
|
||||||
directives = {
|
directives = {
|
||||||
'class': CPPClassObject,
|
'class': CPPClassObject,
|
||||||
|
'union': CPPUnionObject,
|
||||||
'function': CPPFunctionObject,
|
'function': CPPFunctionObject,
|
||||||
'member': CPPMemberObject,
|
'member': CPPMemberObject,
|
||||||
'var': CPPMemberObject,
|
'var': CPPMemberObject,
|
||||||
@ -6033,6 +6075,7 @@ class CPPDomain(Domain):
|
|||||||
roles = {
|
roles = {
|
||||||
'any': CPPXRefRole(),
|
'any': CPPXRefRole(),
|
||||||
'class': CPPXRefRole(),
|
'class': CPPXRefRole(),
|
||||||
|
'union': CPPXRefRole(),
|
||||||
'func': CPPXRefRole(fix_parens=True),
|
'func': CPPXRefRole(fix_parens=True),
|
||||||
'member': CPPXRefRole(),
|
'member': CPPXRefRole(),
|
||||||
'var': CPPXRefRole(),
|
'var': CPPXRefRole(),
|
||||||
|
@ -491,6 +491,10 @@ def test_class_definitions():
|
|||||||
{2: 'I0E7has_varI1TNSt6void_tIDTadN1T3varEEEEE'})
|
{2: 'I0E7has_varI1TNSt6void_tIDTadN1T3varEEEEE'})
|
||||||
|
|
||||||
|
|
||||||
|
def test_union_definitions():
|
||||||
|
check('union', 'A', {2: "1A"})
|
||||||
|
|
||||||
|
|
||||||
def test_enum_definitions():
|
def test_enum_definitions():
|
||||||
check('enum', 'A', {2: "1A"})
|
check('enum', 'A', {2: "1A"})
|
||||||
check('enum', 'A : std::underlying_type<B>::type', {2: "1A"})
|
check('enum', 'A : std::underlying_type<B>::type', {2: "1A"})
|
||||||
|
Loading…
Reference in New Issue
Block a user