mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #6141 from jakobandersen/cpp-alias-fix
C++, fix alias declarations, causing problems in Latex and singlehtml
This commit is contained in:
commit
24ce4e72e6
1
CHANGES
1
CHANGES
@ -26,6 +26,7 @@ Bugs fixed
|
|||||||
* texinfo: ``make install-info`` fails on macOS
|
* texinfo: ``make install-info`` fails on macOS
|
||||||
* #3079: texinfo: image files are not copied on ``make install-info``
|
* #3079: texinfo: image files are not copied on ``make install-info``
|
||||||
* #5391: A cross reference in heading is rendered as literal
|
* #5391: A cross reference in heading is rendered as literal
|
||||||
|
* #5946: C++, fix ``cpp:alias`` problems in LaTeX (and singlehtml)
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
--------
|
--------
|
||||||
|
@ -6734,27 +6734,20 @@ class CPPNamespacePopObject(SphinxDirective):
|
|||||||
|
|
||||||
|
|
||||||
class AliasNode(nodes.Element):
|
class AliasNode(nodes.Element):
|
||||||
def __init__(self, sig, warnEnv):
|
def __init__(self, sig, env=None, parentKey=None):
|
||||||
"""
|
|
||||||
:param sig: The name or function signature to alias.
|
|
||||||
:param warnEnv: An object which must have the following attributes:
|
|
||||||
env: a Sphinx environment
|
|
||||||
whatever DefinitionParser requires of warnEnv
|
|
||||||
"""
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.sig = sig
|
self.sig = sig
|
||||||
env = warnEnv.env
|
if env is not None:
|
||||||
if 'cpp:parent_symbol' not in env.temp_data:
|
if 'cpp:parent_symbol' not in env.temp_data:
|
||||||
root = env.domaindata['cpp']['root_symbol']
|
root = env.domaindata['cpp']['root_symbol']
|
||||||
env.temp_data['cpp:parent_symbol'] = root
|
env.temp_data['cpp:parent_symbol'] = root
|
||||||
self.parentKey = env.temp_data['cpp:parent_symbol'].get_lookup_key()
|
self.parentKey = env.temp_data['cpp:parent_symbol'].get_lookup_key()
|
||||||
try:
|
else:
|
||||||
parser = DefinitionParser(sig, warnEnv, warnEnv.env.config)
|
assert parentKey is not None
|
||||||
self.ast, self.isShorthand = parser.parse_xref_object()
|
self.parentKey = parentKey
|
||||||
parser.assert_end()
|
|
||||||
except DefinitionError as e:
|
def copy(self):
|
||||||
warnEnv.warn(e)
|
return self.__class__(self.sig, env=None, parentKey=self.parentKey)
|
||||||
self.ast = None
|
|
||||||
|
|
||||||
|
|
||||||
class AliasTransform(SphinxTransform):
|
class AliasTransform(SphinxTransform):
|
||||||
@ -6763,8 +6756,20 @@ class AliasTransform(SphinxTransform):
|
|||||||
def apply(self, **kwargs):
|
def apply(self, **kwargs):
|
||||||
# type: (Any) -> None
|
# type: (Any) -> None
|
||||||
for node in self.document.traverse(AliasNode):
|
for node in self.document.traverse(AliasNode):
|
||||||
|
class Warner:
|
||||||
|
def warn(self, msg):
|
||||||
|
logger.warning(msg, location=node)
|
||||||
|
warner = Warner()
|
||||||
sig = node.sig
|
sig = node.sig
|
||||||
ast = node.ast
|
parentKey = node.parentKey
|
||||||
|
try:
|
||||||
|
parser = DefinitionParser(sig, warner, self.env.config)
|
||||||
|
ast, isShorthand = parser.parse_xref_object()
|
||||||
|
parser.assert_end()
|
||||||
|
except DefinitionError as e:
|
||||||
|
warner.warn(e)
|
||||||
|
ast, isShorthand = None, None
|
||||||
|
|
||||||
if ast is None:
|
if ast is None:
|
||||||
# could not be parsed, so stop here
|
# could not be parsed, so stop here
|
||||||
signode = addnodes.desc_signature(sig, '')
|
signode = addnodes.desc_signature(sig, '')
|
||||||
@ -6774,8 +6779,6 @@ class AliasTransform(SphinxTransform):
|
|||||||
node.replace_self(signode)
|
node.replace_self(signode)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
isShorthand = node.isShorthand
|
|
||||||
parentKey = node.parentKey
|
|
||||||
rootSymbol = self.env.domains['cpp'].data['root_symbol']
|
rootSymbol = self.env.domains['cpp'].data['root_symbol']
|
||||||
parentSymbol = rootSymbol.direct_lookup(parentKey)
|
parentSymbol = rootSymbol.direct_lookup(parentKey)
|
||||||
if not parentSymbol:
|
if not parentSymbol:
|
||||||
@ -6833,10 +6836,6 @@ class AliasTransform(SphinxTransform):
|
|||||||
class CPPAliasObject(ObjectDescription):
|
class CPPAliasObject(ObjectDescription):
|
||||||
option_spec = {} # type: Dict
|
option_spec = {} # type: Dict
|
||||||
|
|
||||||
def warn(self, msg):
|
|
||||||
# type: (Union[str, Exception]) -> None
|
|
||||||
self.state_machine.reporter.warning(msg, line=self.lineno)
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
# type: () -> List[nodes.Node]
|
# type: () -> List[nodes.Node]
|
||||||
"""
|
"""
|
||||||
@ -6859,7 +6858,7 @@ class CPPAliasObject(ObjectDescription):
|
|||||||
self.names = [] # type: List[str]
|
self.names = [] # type: List[str]
|
||||||
signatures = self.get_signatures()
|
signatures = self.get_signatures()
|
||||||
for i, sig in enumerate(signatures):
|
for i, sig in enumerate(signatures):
|
||||||
node.append(AliasNode(sig, self))
|
node.append(AliasNode(sig, env=self.env))
|
||||||
|
|
||||||
contentnode = addnodes.desc_content()
|
contentnode = addnodes.desc_content()
|
||||||
node.append(contentnode)
|
node.append(contentnode)
|
||||||
|
Loading…
Reference in New Issue
Block a user