mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Also do better error handling when an outer name could not be parsed.
This commit is contained in:
parent
7e119135e5
commit
5047098d24
@ -2157,7 +2157,6 @@ class CPPObject(ObjectDescription):
|
|||||||
if uninstantiated != name and uninstantiated not in objects:
|
if uninstantiated != name and uninstantiated not in objects:
|
||||||
signode['names'].append(uninstantiated)
|
signode['names'].append(uninstantiated)
|
||||||
objects.setdefault(uninstantiated, (self.env.docname, ast))
|
objects.setdefault(uninstantiated, (self.env.docname, ast))
|
||||||
self.env.ref_context['cpp:lastname'] = ast.prefixedName
|
|
||||||
|
|
||||||
indextext = self.get_index_text(name)
|
indextext = self.get_index_text(name)
|
||||||
if not re.compile(r'^[a-zA-Z0-9_]*$').match(theid):
|
if not re.compile(r'^[a-zA-Z0-9_]*$').match(theid):
|
||||||
@ -2174,6 +2173,16 @@ class CPPObject(ObjectDescription):
|
|||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def handle_signature(self, sig, signode):
|
def handle_signature(self, sig, signode):
|
||||||
|
def set_lastname(name):
|
||||||
|
parent = self.env.ref_context.get('cpp:parent')
|
||||||
|
if parent and len(parent) > 0:
|
||||||
|
res = name.prefix_nested_name(parent[-1])
|
||||||
|
else:
|
||||||
|
res = name
|
||||||
|
assert res
|
||||||
|
self.env.ref_context['cpp:lastname'] = res
|
||||||
|
return res
|
||||||
|
|
||||||
parser = DefinitionParser(sig)
|
parser = DefinitionParser(sig)
|
||||||
try:
|
try:
|
||||||
ast = self.parse_definition(parser)
|
ast = self.parse_definition(parser)
|
||||||
@ -2181,15 +2190,17 @@ class CPPObject(ObjectDescription):
|
|||||||
except DefinitionError as e:
|
except DefinitionError as e:
|
||||||
self.state_machine.reporter.warning(e.description,
|
self.state_machine.reporter.warning(e.description,
|
||||||
line=self.lineno)
|
line=self.lineno)
|
||||||
|
# It is easier to assume some phony name than handling the error in
|
||||||
|
# the possibly inner declarations.
|
||||||
|
name = ASTNestedName([
|
||||||
|
ASTNestedNameElement("PhonyNameDueToError", None)
|
||||||
|
])
|
||||||
|
set_lastname(name)
|
||||||
raise ValueError
|
raise ValueError
|
||||||
self.describe_signature(signode, ast)
|
self.describe_signature(signode, ast)
|
||||||
|
|
||||||
parent = self.env.ref_context.get('cpp:parent')
|
ast.prefixedName = set_lastname(ast.name)
|
||||||
if parent and len(parent) > 0:
|
assert ast.prefixedName
|
||||||
ast = ast.clone()
|
|
||||||
ast.prefixedName = ast.name.prefix_nested_name(parent[-1])
|
|
||||||
else:
|
|
||||||
ast.prefixedName = ast.name
|
|
||||||
return ast
|
return ast
|
||||||
|
|
||||||
|
|
||||||
@ -2232,14 +2243,12 @@ class CPPClassObject(CPPObject):
|
|||||||
return _('%s (C++ class)') % name
|
return _('%s (C++ class)') % name
|
||||||
|
|
||||||
def before_content(self):
|
def before_content(self):
|
||||||
# lastname may not be set if there was an error
|
lastname = self.env.ref_context['cpp:lastname']
|
||||||
if 'cpp:lastname' in self.env.ref_context:
|
assert lastname
|
||||||
lastname = self.env.ref_context['cpp:lastname']
|
if 'cpp:parent' in self.env.ref_context:
|
||||||
assert lastname
|
self.env.ref_context['cpp:parent'].append(lastname)
|
||||||
if 'cpp:parent' in self.env.ref_context:
|
else:
|
||||||
self.env.ref_context['cpp:parent'].append(lastname)
|
self.env.ref_context['cpp:parent'] = [lastname]
|
||||||
else:
|
|
||||||
self.env.ref_context['cpp:parent'] = [lastname]
|
|
||||||
|
|
||||||
def after_content(self):
|
def after_content(self):
|
||||||
self.env.ref_context['cpp:parent'].pop()
|
self.env.ref_context['cpp:parent'].pop()
|
||||||
@ -2257,14 +2266,12 @@ class CPPEnumObject(CPPObject):
|
|||||||
return _('%s (C++ enum)') % name
|
return _('%s (C++ enum)') % name
|
||||||
|
|
||||||
def before_content(self):
|
def before_content(self):
|
||||||
# lastname may not be set if there was an error
|
lastname = self.env.ref_context['cpp:lastname']
|
||||||
if 'cpp:lastname' in self.env.ref_context:
|
assert lastname
|
||||||
lastname = self.env.ref_context['cpp:lastname']
|
if 'cpp:parent' in self.env.ref_context:
|
||||||
assert lastname
|
self.env.ref_context['cpp:parent'].append(lastname)
|
||||||
if 'cpp:parent' in self.env.ref_context:
|
else:
|
||||||
self.env.ref_context['cpp:parent'].append(lastname)
|
self.env.ref_context['cpp:parent'] = [lastname]
|
||||||
else:
|
|
||||||
self.env.ref_context['cpp:parent'] = [lastname]
|
|
||||||
|
|
||||||
def after_content(self):
|
def after_content(self):
|
||||||
self.env.ref_context['cpp:parent'].pop()
|
self.env.ref_context['cpp:parent'].pop()
|
||||||
|
Loading…
Reference in New Issue
Block a user