C++, properly render multi-line declarations.

Fixes template rendering, e.g., when generating Latex.
Thanks to michaeljones/breathe#127 for pointing in the right direction.
This commit is contained in:
Jakob Lykke Andersen
2015-10-13 22:05:42 +09:00
parent 4d2c17e043
commit 346df54358
2 changed files with 23 additions and 12 deletions

View File

@@ -754,7 +754,7 @@ class ASTTemplateDeclarationPrefix(ASTBase):
def describe_signature(self, signode, mode, env, symbol):
_verify_description_mode(mode)
for t in self.templates:
templateNode = nodes.line()
templateNode = addnodes.desc_signature()
t.describe_signature(templateNode, 'lastIsName', env, symbol)
signode += templateNode
@@ -2049,36 +2049,43 @@ class ASTDeclaration(ASTBase):
def describe_signature(self, signode, mode, env):
_verify_description_mode(mode)
# the caller of the domain added a desc_signature node
# let's pop it so we can add templates before that
parentNode = signode.parent
mainDeclNode = signode
parentNode.pop()
assert self.symbol
if not self.declarationScope:
raise NotImplementedError("hmm, a bug? %s" % text_type(self))
assert self.declarationScope
if self.visibility and self.visibility != "public":
signode += addnodes.desc_annotation(self.visibility + " ",
self.visibility + " ")
if self.templatePrefix:
self.templatePrefix.describe_signature(signode, mode, env,
self.templatePrefix.describe_signature(parentNode, mode, env,
symbol=self.symbol)
if self.visibility and self.visibility != "public":
mainDeclNode += addnodes.desc_annotation(self.visibility + " ",
self.visibility + " ")
if self.objectType == 'type':
signode += addnodes.desc_annotation('type ', 'type ')
mainDeclNode += addnodes.desc_annotation('type ', 'type ')
elif self.objectType == 'member':
pass
elif self.objectType == 'function':
pass
elif self.objectType == 'class':
signode += addnodes.desc_annotation('class ', 'class ')
mainDeclNode += addnodes.desc_annotation('class ', 'class ')
elif self.objectType == 'enum':
prefix = 'enum '
if self.scoped:
prefix += self.scoped
prefix += ' '
signode += addnodes.desc_annotation(prefix, prefix)
mainDeclNode += addnodes.desc_annotation(prefix, prefix)
elif self.objectType == 'enumerator':
signode += addnodes.desc_annotation('enumerator ', 'enumerator ')
mainDeclNode += addnodes.desc_annotation('enumerator ', 'enumerator ')
else:
assert False
self.declaration.describe_signature(signode, mode, env,
self.declaration.describe_signature(mainDeclNode, mode, env,
symbol=self.symbol)
parentNode += mainDeclNode
class ASTNamespace(ASTBase):

View File

@@ -13,6 +13,7 @@ from six import text_type
from util import raises
from sphinx import addnodes
from sphinx.domains.cpp import DefinitionParser, DefinitionError, NoOldIdError
from sphinx.domains.cpp import Symbol
import sphinx.domains.cpp as cppDomain
@@ -48,7 +49,10 @@ def check(name, input, idv1output=None, idv2output=None, output=None):
raise DefinitionError("")
rootSymbol = Symbol(None, None, None, None, None, None)
symbol = rootSymbol.add_declaration(ast, docname="Test")
ast.describe_signature([], 'lastIsName', symbol)
parentNode = addnodes.desc()
signode = addnodes.desc_signature(input, '')
parentNode += signode
ast.describe_signature(signode, 'lastIsName', symbol)
if idv2output:
idv2output = "_CPPv2" + idv2output
@@ -357,7 +361,7 @@ def test_operators():
"not-operator", "ntv", output='void operator!()')
check('function', 'void operator "" _udl()',
None, 'li4_udlv', output='void operator""_udl()')
None, 'li4_udlv', output='void operator""_udl()')
#def test_print():
# # used for getting all the ids out for checking