diff options
Diffstat (limited to 'sphinx/domains/cpp.py')
-rw-r--r-- | sphinx/domains/cpp.py | 82 |
1 files changed, 41 insertions, 41 deletions
diff --git a/sphinx/domains/cpp.py b/sphinx/domains/cpp.py index fe339b153..98eabb956 100644 --- a/sphinx/domains/cpp.py +++ b/sphinx/domains/cpp.py @@ -13,17 +13,18 @@ import re from copy import deepcopy from docutils import nodes -from docutils.parsers.rst import Directive, directives +from docutils.parsers.rst import directives from six import iteritems, text_type from sphinx import addnodes from sphinx.directives import ObjectDescription from sphinx.domains import Domain, ObjType from sphinx.environment import NoUri -from sphinx.locale import l_, _ +from sphinx.locale import _, __ from sphinx.roles import XRefRole from sphinx.util import logging from sphinx.util.docfields import Field, GroupedField +from sphinx.util.docutils import SphinxDirective from sphinx.util.nodes import make_refnode from sphinx.util.pycompat import UnicodeMixin @@ -48,7 +49,7 @@ logger = logging.getLogger(__name__) It is not the actual old code, but a replication of the behaviour. - v2: 1.3 <= version < now Standardised mangling scheme from - http://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling + https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling though not completely implemented. All versions are generated and attached to elements. The newest is used for the index. All of the versions should work as permalinks. @@ -615,6 +616,7 @@ class ASTBase(UnicodeMixin): raise NotImplementedError(repr(self)) def __repr__(self): + # type: () -> str return '<%s %s>' % (self.__class__.__name__, self) @@ -3655,8 +3657,8 @@ class Symbol(object): ourChild._fill_empty(otherChild.declaration, otherChild.docname) elif ourChild.docname != otherChild.docname: name = text_type(ourChild.declaration) - msg = "Duplicate declaration, also defined in '%s'.\n" - msg += "Declaration is '%s'." + msg = __("Duplicate declaration, also defined in '%s'.\n" + "Declaration is '%s'.") msg = msg % (ourChild.docname, name) logger.warning(msg, location=otherChild.docname) else: @@ -5562,16 +5564,16 @@ class CPPObject(ObjectDescription): """Description of a C++ language object.""" doc_field_types = [ - GroupedField('parameter', label=l_('Parameters'), + GroupedField('parameter', label=_('Parameters'), names=('param', 'parameter', 'arg', 'argument'), can_collapse=True), - GroupedField('template parameter', label=l_('Template Parameters'), + GroupedField('template parameter', label=_('Template Parameters'), names=('tparam', 'template parameter'), can_collapse=True), - GroupedField('exceptions', label=l_('Throws'), rolename='cpp:class', + GroupedField('exceptions', label=_('Throws'), rolename='cpp:class', names=('throws', 'throw', 'exception'), can_collapse=True), - Field('returnvalue', label=l_('Returns'), has_arg=False, + Field('returnvalue', label=_('Returns'), has_arg=False, names=('returns', 'return')), ] @@ -5827,7 +5829,7 @@ class CPPEnumeratorObject(CPPObject): return parser.parse_declaration("enumerator") -class CPPNamespaceObject(Directive): +class CPPNamespaceObject(SphinxDirective): """ This directive is just to tell Sphinx that we're documenting stuff in namespace foo. @@ -5845,13 +5847,12 @@ class CPPNamespaceObject(Directive): def run(self): # type: () -> List[nodes.Node] - env = self.state.document.settings.env - rootSymbol = env.domaindata['cpp']['root_symbol'] + rootSymbol = self.env.domaindata['cpp']['root_symbol'] if self.arguments[0].strip() in ('NULL', '0', 'nullptr'): symbol = rootSymbol stack = [] # type: List[Symbol] else: - parser = DefinitionParser(self.arguments[0], self, env.config) + parser = DefinitionParser(self.arguments[0], self, self.config) try: ast = parser.parse_namespace_object() parser.assert_end() @@ -5861,13 +5862,13 @@ class CPPNamespaceObject(Directive): ast = ASTNamespace(name, None) symbol = rootSymbol.add_name(ast.nestedName, ast.templatePrefix) stack = [symbol] - env.temp_data['cpp:parent_symbol'] = symbol - env.temp_data['cpp:namespace_stack'] = stack - env.ref_context['cpp:parent_key'] = symbol.get_lookup_key() + self.env.temp_data['cpp:parent_symbol'] = symbol + self.env.temp_data['cpp:namespace_stack'] = stack + self.env.ref_context['cpp:parent_key'] = symbol.get_lookup_key() return [] -class CPPNamespacePushObject(Directive): +class CPPNamespacePushObject(SphinxDirective): has_content = False required_arguments = 1 optional_arguments = 0 @@ -5880,10 +5881,9 @@ class CPPNamespacePushObject(Directive): def run(self): # type: () -> List[nodes.Node] - env = self.state.document.settings.env if self.arguments[0].strip() in ('NULL', '0', 'nullptr'): return [] - parser = DefinitionParser(self.arguments[0], self, env.config) + parser = DefinitionParser(self.arguments[0], self, self.config) try: ast = parser.parse_namespace_object() parser.assert_end() @@ -5891,19 +5891,19 @@ class CPPNamespacePushObject(Directive): self.warn(e.description) name = _make_phony_error_name() ast = ASTNamespace(name, None) - oldParent = env.temp_data.get('cpp:parent_symbol', None) + oldParent = self.env.temp_data.get('cpp:parent_symbol', None) if not oldParent: - oldParent = env.domaindata['cpp']['root_symbol'] + oldParent = self.env.domaindata['cpp']['root_symbol'] symbol = oldParent.add_name(ast.nestedName, ast.templatePrefix) - stack = env.temp_data.get('cpp:namespace_stack', []) + stack = self.env.temp_data.get('cpp:namespace_stack', []) stack.append(symbol) - env.temp_data['cpp:parent_symbol'] = symbol - env.temp_data['cpp:namespace_stack'] = stack - env.ref_context['cpp:parent_key'] = symbol.get_lookup_key() + self.env.temp_data['cpp:parent_symbol'] = symbol + self.env.temp_data['cpp:namespace_stack'] = stack + self.env.ref_context['cpp:parent_key'] = symbol.get_lookup_key() return [] -class CPPNamespacePopObject(Directive): +class CPPNamespacePopObject(SphinxDirective): has_content = False required_arguments = 0 optional_arguments = 0 @@ -5916,8 +5916,7 @@ class CPPNamespacePopObject(Directive): def run(self): # type: () -> List[nodes.Node] - env = self.state.document.settings.env - stack = env.temp_data.get('cpp:namespace_stack', None) + stack = self.env.temp_data.get('cpp:namespace_stack', None) if not stack or len(stack) == 0: self.warn("C++ namespace pop on empty stack. Defaulting to gobal scope.") stack = [] @@ -5926,10 +5925,10 @@ class CPPNamespacePopObject(Directive): if len(stack) > 0: symbol = stack[-1] else: - symbol = env.domaindata['cpp']['root_symbol'] - env.temp_data['cpp:parent_symbol'] = symbol - env.temp_data['cpp:namespace_stack'] = stack - env.ref_context['cpp:parent_key'] = symbol.get_lookup_key() + symbol = self.env.domaindata['cpp']['root_symbol'] + self.env.temp_data['cpp:parent_symbol'] = symbol + self.env.temp_data['cpp:namespace_stack'] = stack + self.env.ref_context['cpp:parent_key'] = symbol.get_lookup_key() return [] @@ -5984,13 +5983,13 @@ class CPPDomain(Domain): name = 'cpp' label = 'C++' object_types = { - 'class': ObjType(l_('class'), 'class', 'type', 'identifier'), - 'function': ObjType(l_('function'), 'function', 'func', 'type', 'identifier'), - 'member': ObjType(l_('member'), 'member', 'var'), - 'type': ObjType(l_('type'), 'type', 'identifier'), - 'concept': ObjType(l_('concept'), 'concept', 'identifier'), - 'enum': ObjType(l_('enum'), 'enum', 'type', 'identifier'), - 'enumerator': ObjType(l_('enumerator'), 'enumerator') + 'class': ObjType(_('class'), 'class', 'type', 'identifier'), + 'function': ObjType(_('function'), 'function', 'func', 'type', 'identifier'), + 'member': ObjType(_('member'), 'member', 'var'), + 'type': ObjType(_('type'), 'type', 'identifier'), + 'concept': ObjType(_('concept'), 'concept', 'identifier'), + 'enum': ObjType(_('enum'), 'enum', 'type', 'identifier'), + 'enumerator': ObjType(_('enumerator'), 'enumerator') } directives = { @@ -6052,8 +6051,8 @@ class CPPDomain(Domain): for name, docname in otherdata['names'].items(): if docname in docnames: if name in ourNames: - msg = "Duplicate declaration, also defined in '%s'.\n" - msg += "Name of declaration is '%s'." + msg = __("Duplicate declaration, also defined in '%s'.\n" + "Name of declaration is '%s'.") msg = msg % (ourNames[name], name) logger.warning(msg, location=docname) else: @@ -6223,6 +6222,7 @@ def setup(app): return { 'version': 'builtin', + 'env_version': 1, 'parallel_read_safe': True, 'parallel_write_safe': True, } |