mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #8207 from jakobandersen/c_alias_recursive
C, recursive alias declarations
This commit is contained in:
commit
008d0201e1
2
CHANGES
2
CHANGES
@ -15,6 +15,8 @@ Features added
|
|||||||
|
|
||||||
* #8100: html: Show a better error message for failures on copying
|
* #8100: html: Show a better error message for failures on copying
|
||||||
html_static_files
|
html_static_files
|
||||||
|
* #8141: C: added a ``maxdepth`` option to :rst:dir:`c:alias` to insert
|
||||||
|
nested declarations.
|
||||||
|
|
||||||
Bugs fixed
|
Bugs fixed
|
||||||
----------
|
----------
|
||||||
|
@ -744,6 +744,18 @@ The following directive can be used for this purpose.
|
|||||||
|
|
||||||
.. versionadded:: 3.2
|
.. versionadded:: 3.2
|
||||||
|
|
||||||
|
|
||||||
|
.. rubric:: Options
|
||||||
|
|
||||||
|
.. rst:directive:option:: maxdepth: int
|
||||||
|
|
||||||
|
Insert nested declarations as well, up to the total depth given.
|
||||||
|
Use 0 for infinite depth and 1 for just the mentioned declaration.
|
||||||
|
Defaults to 1.
|
||||||
|
|
||||||
|
.. versionadded:: 3.3
|
||||||
|
|
||||||
|
|
||||||
.. c:namespace-pop::
|
.. c:namespace-pop::
|
||||||
|
|
||||||
|
|
||||||
|
@ -136,8 +136,8 @@ class ASTIdentifier(ASTBaseBase):
|
|||||||
reftype='identifier',
|
reftype='identifier',
|
||||||
reftarget=targetText, modname=None,
|
reftarget=targetText, modname=None,
|
||||||
classname=None)
|
classname=None)
|
||||||
# key = symbol.get_lookup_key()
|
key = symbol.get_lookup_key()
|
||||||
# pnode['c:parent_key'] = key
|
pnode['c:parent_key'] = key
|
||||||
if self.is_anon():
|
if self.is_anon():
|
||||||
pnode += nodes.strong(text="[anonymous]")
|
pnode += nodes.strong(text="[anonymous]")
|
||||||
else:
|
else:
|
||||||
@ -1562,6 +1562,11 @@ class Symbol:
|
|||||||
for s in sChild.get_all_symbols():
|
for s in sChild.get_all_symbols():
|
||||||
yield s
|
yield s
|
||||||
|
|
||||||
|
@property
|
||||||
|
def children(self) -> Iterator["Symbol"]:
|
||||||
|
for c in self._children:
|
||||||
|
yield c
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def children_recurse_anon(self) -> Iterator["Symbol"]:
|
def children_recurse_anon(self) -> Iterator["Symbol"]:
|
||||||
for c in self._children:
|
for c in self._children:
|
||||||
@ -3408,10 +3413,13 @@ class CNamespacePopObject(SphinxDirective):
|
|||||||
|
|
||||||
|
|
||||||
class AliasNode(nodes.Element):
|
class AliasNode(nodes.Element):
|
||||||
def __init__(self, sig: str, env: "BuildEnvironment" = None,
|
def __init__(self, sig: str, maxdepth: int, document: Any, env: "BuildEnvironment" = None,
|
||||||
parentKey: LookupKey = None) -> None:
|
parentKey: LookupKey = None) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.sig = sig
|
self.sig = sig
|
||||||
|
self.maxdepth = maxdepth
|
||||||
|
assert maxdepth >= 0
|
||||||
|
self.document = document
|
||||||
if env is not None:
|
if env is not None:
|
||||||
if 'c:parent_symbol' not in env.temp_data:
|
if 'c:parent_symbol' not in env.temp_data:
|
||||||
root = env.domaindata['c']['root_symbol']
|
root = env.domaindata['c']['root_symbol']
|
||||||
@ -3428,6 +3436,37 @@ class AliasNode(nodes.Element):
|
|||||||
class AliasTransform(SphinxTransform):
|
class AliasTransform(SphinxTransform):
|
||||||
default_priority = ReferencesResolver.default_priority - 1
|
default_priority = ReferencesResolver.default_priority - 1
|
||||||
|
|
||||||
|
def _render_symbol(self, s: Symbol, maxdepth: int, document: Any) -> List[Node]:
|
||||||
|
nodes = [] # type: List[Node]
|
||||||
|
options = dict() # type: ignore
|
||||||
|
signode = addnodes.desc_signature('', '')
|
||||||
|
nodes.append(signode)
|
||||||
|
s.declaration.describe_signature(signode, 'markName', self.env, options)
|
||||||
|
if maxdepth == 0:
|
||||||
|
recurse = True
|
||||||
|
elif maxdepth == 1:
|
||||||
|
recurse = False
|
||||||
|
else:
|
||||||
|
maxdepth -= 1
|
||||||
|
recurse = True
|
||||||
|
if recurse:
|
||||||
|
content = addnodes.desc_content()
|
||||||
|
desc = addnodes.desc()
|
||||||
|
content.append(desc)
|
||||||
|
desc.document = document
|
||||||
|
desc['domain'] = 'c'
|
||||||
|
# 'desctype' is a backwards compatible attribute
|
||||||
|
desc['objtype'] = desc['desctype'] = 'alias'
|
||||||
|
desc['noindex'] = True
|
||||||
|
|
||||||
|
for sChild in s.children:
|
||||||
|
childNodes = self._render_symbol(sChild, maxdepth, document)
|
||||||
|
desc.extend(childNodes)
|
||||||
|
|
||||||
|
if len(desc.children) != 0:
|
||||||
|
nodes.append(content)
|
||||||
|
return nodes
|
||||||
|
|
||||||
def apply(self, **kwargs: Any) -> None:
|
def apply(self, **kwargs: Any) -> None:
|
||||||
for node in self.document.traverse(AliasNode):
|
for node in self.document.traverse(AliasNode):
|
||||||
sig = node.sig
|
sig = node.sig
|
||||||
@ -3468,17 +3507,16 @@ class AliasTransform(SphinxTransform):
|
|||||||
logger.warning("Could not find C declaration for alias '%s'." % name,
|
logger.warning("Could not find C declaration for alias '%s'." % name,
|
||||||
location=node)
|
location=node)
|
||||||
node.replace_self(signode)
|
node.replace_self(signode)
|
||||||
else:
|
continue
|
||||||
nodes = []
|
|
||||||
options = dict() # type: ignore
|
nodes = self._render_symbol(s, maxdepth=node.maxdepth, document=node.document)
|
||||||
signode = addnodes.desc_signature(sig, '')
|
node.replace_self(nodes)
|
||||||
nodes.append(signode)
|
|
||||||
s.declaration.describe_signature(signode, 'markName', self.env, options)
|
|
||||||
node.replace_self(nodes)
|
|
||||||
|
|
||||||
|
|
||||||
class CAliasObject(ObjectDescription):
|
class CAliasObject(ObjectDescription):
|
||||||
option_spec = {} # type: Dict
|
option_spec = {
|
||||||
|
'maxdepth': directives.nonnegative_int
|
||||||
|
} # type: Dict
|
||||||
|
|
||||||
def run(self) -> List[Node]:
|
def run(self) -> List[Node]:
|
||||||
if ':' in self.name:
|
if ':' in self.name:
|
||||||
@ -3494,16 +3532,10 @@ class CAliasObject(ObjectDescription):
|
|||||||
node['noindex'] = True
|
node['noindex'] = True
|
||||||
|
|
||||||
self.names = [] # type: List[str]
|
self.names = [] # type: List[str]
|
||||||
|
maxdepth = self.options.get('maxdepth', 1)
|
||||||
signatures = self.get_signatures()
|
signatures = self.get_signatures()
|
||||||
for i, sig in enumerate(signatures):
|
for i, sig in enumerate(signatures):
|
||||||
node.append(AliasNode(sig, env=self.env))
|
node.append(AliasNode(sig, maxdepth, self.state.document, env=self.env))
|
||||||
|
|
||||||
contentnode = addnodes.desc_content()
|
|
||||||
node.append(contentnode)
|
|
||||||
self.before_content()
|
|
||||||
self.state.nested_parse(self.content, self.content_offset, contentnode)
|
|
||||||
self.env.temp_data['object'] = None
|
|
||||||
self.after_content()
|
|
||||||
return [node]
|
return [node]
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user