Skip to content

Commit

Permalink
Merging jakobandersen#711 into jakobandersen#723
Browse files Browse the repository at this point in the history
Note, both of these PRs are on top of the changes introduced by
jakobandersen#698.

Links to PRs for future reference:
- breathe-doc#698
- breathe-doc#711
- breathe-doc#723

Signed-off-by: Abrar Rahman Protyasha <abrar@openrobotics.org>
  • Loading branch information
Abrar Rahman Protyasha committed Aug 19, 2021
2 parents 42846fa + e36d4a1 commit e0a266e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 14 deletions.
21 changes: 20 additions & 1 deletion breathe/directives/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,18 @@ def run(self) -> List[Node]:
return warning.warn('doxygenfunction: %s' % e)

# Extract arguments from the function name.
args = self._parse_args(args)
try:
args = self._parse_args(args)
except cpp.DefinitionError as e:
return self.create_warning(
project_info,
namespace='%s::' % namespace if namespace else '',
function=function_name,
args=str(args),
cpperror=str(e)
).warn('doxygenfunction: Unable to resolve function '
'"{namespace}{function}" with arguments "{args}".\n'
'Could not parse arguments. Parsing eror is\n{cpperror}')

finder_filter = self.filter_factory.create_function_and_all_friend_finder_filter(
namespace, function_name)
Expand Down Expand Up @@ -118,6 +129,12 @@ def run(self) -> List[Node]:
result = warning.warn(message, rendered_nodes=warning_nodes,
unformatted_suffix=text)
return result
except cpp.DefinitionError as error:
warning.context['cpperror'] = str(error)
return warning.warn(
'doxygenfunction: Unable to resolve function '
'"{namespace}{function}" with arguments "{args}".\n'
'Candidate function could not be parsed. Parsing error is\n{cpperror}')

target_handler = create_target_handler(self.options, project_info, self.state.document)
filter_ = self.filter_factory.create_outline_filter(self.options)
Expand All @@ -126,6 +143,7 @@ def run(self) -> List[Node]:
self.directive_args)

def _parse_args(self, function_description: str) -> Optional[cpp.ASTParametersQualifiers]:
# Note: the caller must catch cpp.DefinitionError
if function_description == '':
return None

Expand Down Expand Up @@ -235,6 +253,7 @@ def _resolve_function(self, matches, args: Optional[cpp.ASTParametersQualifiers]
_match_args = match.group(2)

# Parse the text to find the arguments
# This one should succeed as it came from _create_function_signature
match_args = self._parse_args(_match_args)

# Match them against the arg spec
Expand Down
32 changes: 19 additions & 13 deletions breathe/renderer/sphinxrenderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2019,8 +2019,8 @@ def visit_friendclass(self, node) -> List[Node]:
signode += nodes.Text(node.name)
return [desc]

def visit_param(self, node: compound.paramTypeSub, *,
insertDeclNameByParsing: bool = False) -> List[Node]:
def visit_templateparam(self, node: compound.paramTypeSub, *,
insertDeclNameByParsing: bool = False) -> List[Node]:
nodelist = []

# Parameter type
Expand Down Expand Up @@ -2048,15 +2048,22 @@ def visit_param(self, node: compound.paramTypeSub, *,
''.join(n.astext() for n in nodelist),
location=self.state.state_machine.get_source_and_line(),
config=self.app.config)
ast = parser._parse_type(named='single', outer='templateParam')
assert ast.name is None
nn = cpp.ASTNestedName(
names=[cpp.ASTNestedNameElement(cpp.ASTIdentifier(node.declname), None)],
templates=[False], rooted=False)
ast.name = nn
# the actual nodes don't matter, as it is astext()-ed later
nodelist = [nodes.Text(str(ast))]
appendDeclName = False
try:
# we really should use _parse_template_parameter()
# but setting a name there is non-trivial, so we use type
ast = parser._parse_type(named='single', outer='templateParam')
assert ast.name is None
nn = cpp.ASTNestedName(
names=[cpp.ASTNestedNameElement(
cpp.ASTIdentifier(node.declname), None)],
templates=[False], rooted=False)
ast.name = nn
# the actual nodes don't matter, as it is astext()-ed later
nodelist = [nodes.Text(str(ast))]
appendDeclName = False
except cpp.DefinitionError:
# happens with "typename ...Args", so for now, just append
pass

if appendDeclName:
if nodelist:
Expand Down Expand Up @@ -2086,7 +2093,7 @@ def visit_templateparamlist(self, node: compound.templateparamlistTypeSub) -> Li
for i, item in enumerate(node.param):
if i:
nodelist.append(nodes.Text(", "))
nodelist.extend(self.visit_param(item, insertDeclNameByParsing=True))
nodelist.extend(self.visit_templateparam(item, insertDeclNameByParsing=True))
self.output_defname = True
return nodelist

Expand Down Expand Up @@ -2225,7 +2232,6 @@ def dispatch_memberdef(self, node) -> List[Node]:
"compoundref": visit_compoundref,
"mixedcontainer": visit_mixedcontainer,
"description": visit_description,
"param": visit_param,
"templateparamlist": visit_templateparamlist,
"docparamlist": visit_docparamlist,
"docxrefsect": visit_docxrefsect,
Expand Down

0 comments on commit e0a266e

Please sign in to comment.