Added TOC object entry support for the C++ domain (#11221)

When ``toc_object_entries_show_parents = 'domain'`` in the config,
the TOC entries omit the namespaces added by the ``cpp:namespace`` and ``cpp:namespace-push`` directives.

Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
This commit is contained in:
Rouslan Korneychuk 2023-07-28 15:14:49 -04:00 committed by GitHub
parent 97d2c5da2f
commit d1b09b04c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 0 deletions

View File

@ -32,6 +32,8 @@ Features added
* #9662: Add the ``:no-typesetting:`` option to suppress textual output * #9662: Add the ``:no-typesetting:`` option to suppress textual output
and only create a linkable anchor. and only create a linkable anchor.
Patch by Latosha Maltba. Patch by Latosha Maltba.
* #11221: C++: Support domain objects in the table of contents.
Patch by Rouslan Korneychuk.
Bugs fixed Bugs fixed
---------- ----------

View File

@ -613,6 +613,9 @@ class ASTIdentifier(ASTBase):
assert len(identifier) != 0 assert len(identifier) != 0
self.identifier = identifier self.identifier = identifier
def _stringify(self, transform: StringifyTransform) -> str:
return transform(self.identifier)
def is_anon(self) -> bool: def is_anon(self) -> bool:
return self.identifier[0] == '@' return self.identifier[0] == '@'
@ -7432,10 +7435,38 @@ class CPPObject(ObjectDescription[ASTDeclaration]):
self.oldParentKey: LookupKey = self.env.ref_context['cpp:parent_key'] self.oldParentKey: LookupKey = self.env.ref_context['cpp:parent_key']
self.env.temp_data['cpp:parent_symbol'] = lastSymbol self.env.temp_data['cpp:parent_symbol'] = lastSymbol
self.env.ref_context['cpp:parent_key'] = lastSymbol.get_lookup_key() self.env.ref_context['cpp:parent_key'] = lastSymbol.get_lookup_key()
self.env.temp_data['cpp:domain_name'] = (
*self.env.temp_data.get('cpp:domain_name', ()),
lastSymbol.identOrOp._stringify(str),
)
def after_content(self) -> None: def after_content(self) -> None:
self.env.temp_data['cpp:parent_symbol'] = self.oldParentSymbol self.env.temp_data['cpp:parent_symbol'] = self.oldParentSymbol
self.env.ref_context['cpp:parent_key'] = self.oldParentKey self.env.ref_context['cpp:parent_key'] = self.oldParentKey
self.env.temp_data['cpp:domain_name'] = self.env.temp_data['cpp:domain_name'][:-1]
def _object_hierarchy_parts(self, sig_node: desc_signature) -> tuple[str, ...]:
return tuple(s.identOrOp._stringify(str) for s in
self.env.temp_data['cpp:last_symbol'].get_full_nested_name().names)
def _toc_entry_name(self, sig_node: desc_signature) -> str:
if not sig_node.get('_toc_parts'):
return ''
config = self.env.app.config
objtype = sig_node.parent.get('objtype')
if config.add_function_parentheses and objtype in {'function', 'method'}:
parens = '()'
else:
parens = ''
*parents, name = sig_node['_toc_parts']
if config.toc_object_entries_show_parents == 'domain':
return '::'.join((*self.env.temp_data.get('cpp:domain_name', ()), name + parens))
if config.toc_object_entries_show_parents == 'hide':
return name + parens
if config.toc_object_entries_show_parents == 'all':
return '::'.join(parents + [name + parens])
return ''
class CPPTypeObject(CPPObject): class CPPTypeObject(CPPObject):