mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
C++, properly look up any references.
Also, clean up use of temp_data and ref_context.
This commit is contained in:
parent
b48fed2aac
commit
1e4fc555d7
1
CHANGES
1
CHANGES
@ -108,6 +108,7 @@ Bugs fixed
|
|||||||
* #3506: Depart functions for all admonitions in HTML writer now properly pass ``node`` to ``depart_admonition``.
|
* #3506: Depart functions for all admonitions in HTML writer now properly pass ``node`` to ``depart_admonition``.
|
||||||
* #2693: Sphinx latex style file wrongly inhibits colours for section headings
|
* #2693: Sphinx latex style file wrongly inhibits colours for section headings
|
||||||
for latex+dvi(ps,pdf,pdfmx)
|
for latex+dvi(ps,pdf,pdfmx)
|
||||||
|
* C++, properly look up ``any`` references.
|
||||||
|
|
||||||
Deprecated
|
Deprecated
|
||||||
----------
|
----------
|
||||||
|
@ -4552,10 +4552,11 @@ class CPPObject(ObjectDescription):
|
|||||||
|
|
||||||
def handle_signature(self, sig, signode):
|
def handle_signature(self, sig, signode):
|
||||||
# type: (unicode, addnodes.desc_signature) -> Any
|
# type: (unicode, addnodes.desc_signature) -> Any
|
||||||
if 'cpp:parent_symbol' not in self.env.ref_context:
|
if 'cpp:parent_symbol' not in self.env.temp_data:
|
||||||
root = self.env.domaindata['cpp']['root_symbol']
|
root = self.env.domaindata['cpp']['root_symbol']
|
||||||
self.env.ref_context['cpp:parent_symbol'] = root
|
self.env.temp_data['cpp:parent_symbol'] = root
|
||||||
parentSymbol = self.env.ref_context['cpp:parent_symbol']
|
self.env.ref_context['cpp:parent_key'] = root.get_lookup_key()
|
||||||
|
parentSymbol = self.env.temp_data['cpp:parent_symbol']
|
||||||
|
|
||||||
parser = DefinitionParser(sig, self, self.env.config)
|
parser = DefinitionParser(sig, self, self.env.config)
|
||||||
try:
|
try:
|
||||||
@ -4567,16 +4568,16 @@ class CPPObject(ObjectDescription):
|
|||||||
# the possibly inner declarations.
|
# the possibly inner declarations.
|
||||||
name = _make_phony_error_name()
|
name = _make_phony_error_name()
|
||||||
symbol = parentSymbol.add_name(name)
|
symbol = parentSymbol.add_name(name)
|
||||||
self.env.ref_context['cpp:last_symbol'] = symbol
|
self.env.temp_data['cpp:last_symbol'] = symbol
|
||||||
raise ValueError
|
raise ValueError
|
||||||
|
|
||||||
try:
|
try:
|
||||||
symbol = parentSymbol.add_declaration(ast, docname=self.env.docname)
|
symbol = parentSymbol.add_declaration(ast, docname=self.env.docname)
|
||||||
self.env.ref_context['cpp:last_symbol'] = symbol
|
self.env.temp_data['cpp:last_symbol'] = symbol
|
||||||
except _DuplicateSymbolError as e:
|
except _DuplicateSymbolError as e:
|
||||||
# Assume we are actually in the old symbol,
|
# Assume we are actually in the old symbol,
|
||||||
# instead of the newly created duplicate.
|
# instead of the newly created duplicate.
|
||||||
self.env.ref_context['cpp:last_symbol'] = e.symbol
|
self.env.temp_data['cpp:last_symbol'] = e.symbol
|
||||||
|
|
||||||
if ast.objectType == 'enumerator':
|
if ast.objectType == 'enumerator':
|
||||||
self._add_enumerator_to_parent(ast)
|
self._add_enumerator_to_parent(ast)
|
||||||
@ -4587,14 +4588,17 @@ class CPPObject(ObjectDescription):
|
|||||||
|
|
||||||
def before_content(self):
|
def before_content(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
lastSymbol = self.env.ref_context['cpp:last_symbol']
|
lastSymbol = self.env.temp_data['cpp:last_symbol']
|
||||||
assert lastSymbol
|
assert lastSymbol
|
||||||
self.oldParentSymbol = self.env.ref_context['cpp:parent_symbol']
|
self.oldParentSymbol = self.env.temp_data['cpp:parent_symbol']
|
||||||
self.env.ref_context['cpp:parent_symbol'] = lastSymbol
|
self.oldParentKey = self.env.ref_context['cpp:parent_key']
|
||||||
|
self.env.temp_data['cpp:parent_symbol'] = lastSymbol
|
||||||
|
self.env.ref_context['cpp:parent_key'] = lastSymbol.get_lookup_key()
|
||||||
|
|
||||||
def after_content(self):
|
def after_content(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
self.env.ref_context['cpp:parent_symbol'] = self.oldParentSymbol
|
self.env.temp_data['cpp:parent_symbol'] = self.oldParentSymbol
|
||||||
|
self.env.ref_context['cpp:parent_key'] = self.oldParentKey
|
||||||
|
|
||||||
|
|
||||||
class CPPTypeObject(CPPObject):
|
class CPPTypeObject(CPPObject):
|
||||||
@ -4711,8 +4715,9 @@ class CPPNamespaceObject(Directive):
|
|||||||
ast = ASTNamespace(name, None)
|
ast = ASTNamespace(name, None)
|
||||||
symbol = rootSymbol.add_name(ast.nestedName, ast.templatePrefix)
|
symbol = rootSymbol.add_name(ast.nestedName, ast.templatePrefix)
|
||||||
stack = [symbol]
|
stack = [symbol]
|
||||||
env.ref_context['cpp:parent_symbol'] = symbol
|
env.temp_data['cpp:parent_symbol'] = symbol
|
||||||
env.temp_data['cpp:namespace_stack'] = stack
|
env.temp_data['cpp:namespace_stack'] = stack
|
||||||
|
env.ref_context['cpp:parent_key'] = symbol.get_lookup_key()
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
@ -4740,14 +4745,15 @@ class CPPNamespacePushObject(Directive):
|
|||||||
self.warn(e.description)
|
self.warn(e.description)
|
||||||
name = _make_phony_error_name()
|
name = _make_phony_error_name()
|
||||||
ast = ASTNamespace(name, None)
|
ast = ASTNamespace(name, None)
|
||||||
oldParent = env.ref_context.get('cpp:parent_symbol', None)
|
oldParent = env.temp_data.get('cpp:parent_symbol', None)
|
||||||
if not oldParent:
|
if not oldParent:
|
||||||
oldParent = env.domaindata['cpp']['root_symbol']
|
oldParent = env.domaindata['cpp']['root_symbol']
|
||||||
symbol = oldParent.add_name(ast.nestedName, ast.templatePrefix)
|
symbol = oldParent.add_name(ast.nestedName, ast.templatePrefix)
|
||||||
stack = env.temp_data.get('cpp:namespace_stack', [])
|
stack = env.temp_data.get('cpp:namespace_stack', [])
|
||||||
stack.append(symbol)
|
stack.append(symbol)
|
||||||
env.ref_context['cpp:parent_symbol'] = symbol
|
env.temp_data['cpp:parent_symbol'] = symbol
|
||||||
env.temp_data['cpp:namespace_stack'] = stack
|
env.temp_data['cpp:namespace_stack'] = stack
|
||||||
|
env.ref_context['cpp:parent_key'] = symbol.get_lookup_key()
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
@ -4775,17 +4781,16 @@ class CPPNamespacePopObject(Directive):
|
|||||||
symbol = stack[-1]
|
symbol = stack[-1]
|
||||||
else:
|
else:
|
||||||
symbol = env.domaindata['cpp']['root_symbol']
|
symbol = env.domaindata['cpp']['root_symbol']
|
||||||
env.ref_context['cpp:parent_symbol'] = symbol
|
env.temp_data['cpp:parent_symbol'] = symbol
|
||||||
env.temp_data['cpp:namespace_stack'] = stack
|
env.temp_data['cpp:namespace_stack'] = stack
|
||||||
|
env.ref_context['cpp:parent_key'] = symbol.get_lookup_key()
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
class CPPXRefRole(XRefRole):
|
class CPPXRefRole(XRefRole):
|
||||||
def process_link(self, env, refnode, has_explicit_title, title, target):
|
def process_link(self, env, refnode, has_explicit_title, title, target):
|
||||||
# type: (BuildEnvironment, nodes.Node, bool, unicode, unicode) -> Tuple[unicode, unicode] # NOQA
|
# type: (BuildEnvironment, nodes.Node, bool, unicode, unicode) -> Tuple[unicode, unicode] # NOQA
|
||||||
parent = env.ref_context.get('cpp:parent_symbol', None)
|
refnode.attributes.update(env.ref_context)
|
||||||
if parent:
|
|
||||||
refnode['cpp:parent_key'] = parent.get_lookup_key()
|
|
||||||
if refnode['reftype'] == 'any':
|
if refnode['reftype'] == 'any':
|
||||||
# Assume the removal part of fix_parens for :any: refs.
|
# Assume the removal part of fix_parens for :any: refs.
|
||||||
# The addition part is done with the reference is resolved.
|
# The addition part is done with the reference is resolved.
|
||||||
@ -4868,10 +4873,7 @@ class CPPDomain(Domain):
|
|||||||
|
|
||||||
def process_field_xref(self, pnode):
|
def process_field_xref(self, pnode):
|
||||||
# type: (nodes.Node) -> None
|
# type: (nodes.Node) -> None
|
||||||
symbol = self.env.ref_context['cpp:parent_symbol']
|
pnode.attributes.update(self.env.ref_context)
|
||||||
key = symbol.get_lookup_key()
|
|
||||||
assert key
|
|
||||||
pnode['cpp:parent_key'] = key
|
|
||||||
|
|
||||||
def merge_domaindata(self, docnames, otherdata):
|
def merge_domaindata(self, docnames, otherdata):
|
||||||
# type: (List[unicode], Dict) -> None
|
# type: (List[unicode], Dict) -> None
|
||||||
@ -5011,6 +5013,9 @@ class CPPDomain(Domain):
|
|||||||
'any', target, node, contnode,
|
'any', target, node, contnode,
|
||||||
emitWarnings=False)
|
emitWarnings=False)
|
||||||
if node:
|
if node:
|
||||||
|
if objtype == 'templateParam':
|
||||||
|
return [('cpp:templateParam', node)]
|
||||||
|
else:
|
||||||
return [('cpp:' + self.role_for_objtype(objtype), node)]
|
return [('cpp:' + self.role_for_objtype(objtype), node)]
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user