Skip to content

Commit

Permalink
Merge pull request #723 from jakobandersen/func_lookup_function_pointer
Browse files Browse the repository at this point in the history
Make doxygenfunction more robust when matching parameters
  • Loading branch information
jakobandersen authored Sep 2, 2021
2 parents c84ac08 + 341afb7 commit 3023db0
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 11 deletions.
41 changes: 30 additions & 11 deletions breathe/directives/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,36 @@ def _parse_args(self, function_description: str) -> Optional[cpp.ASTParametersQu
location=self.get_source_info(),
config=self.config)
paramQual = parser._parse_parameters_and_qualifiers(paramMode='function')
# now erase the parameter names
for p in paramQual.args:
if p.arg is None:
assert p.ellipsis
continue
declarator = p.arg.type.decl
while hasattr(declarator, 'next'):
declarator = declarator.next # type: ignore
assert hasattr(declarator, 'declId')
declarator.declId = None # type: ignore
p.arg.init = None # type: ignore
# strip everything that doesn't contribute to overloading

def stripParamQual(paramQual):
paramQual.exceptionSpec = None # type: ignore
paramQual.final = None # type: ignore
paramQual.override = None # type: ignore
# TODO: strip attrs when Doxygen handles them
paramQual.initializer = None # type: ignore
paramQual.trailingReturn = None # type: ignore
for p in paramQual.args:
if p.arg is None:
assert p.ellipsis
continue
p.arg.init = None # type: ignore
declarator = p.arg.type.decl

def stripDeclarator(declarator):
if hasattr(declarator, 'next'):
stripDeclarator(declarator.next)
if isinstance(declarator, cpp.ASTDeclaratorParen):
assert hasattr(declarator, 'inner')
stripDeclarator(declarator.inner)
else:
assert isinstance(declarator, cpp.ASTDeclaratorNameParamQual)
assert hasattr(declarator, 'declId')
declarator.declId = None # type: ignore
if declarator.paramQual is not None:
stripParamQual(declarator.paramQual)
stripDeclarator(declarator)
stripParamQual(paramQual)
return paramQual

def _create_function_signature(self, node_stack, project_info, filter_, target_handler,
Expand Down
1 change: 1 addition & 0 deletions documentation/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@
"cpp_enum":"../../examples/specific/cpp_enum/xml/",
"cpp_union":"../../examples/specific/cpp_union/xml/",
"cpp_function":"../../examples/specific/cpp_function/xml/",
"cpp_function_lookup":"../../examples/specific/cpp_function_lookup/xml/",
"cpp_friendclass":"../../examples/specific/cpp_friendclass/xml/",
"cpp_inherited_members":"../../examples/specific/cpp_inherited_members/xml/",
"cpp_trailing_return_type":"../../examples/specific/cpp_trailing_return_type/xml/",
Expand Down
42 changes: 42 additions & 0 deletions documentation/source/specific.rst
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,48 @@ Test for issue 717.
.. doxygenfile:: cpp_constexpr_hax.h
:project: cpp_constexpr_hax

C++ Function Lookup
-------------------

.. cpp:namespace:: @ex_specific_cpp_function_lookup

.. doxygenfunction:: fNoexcept()
:project: cpp_function_lookup
.. doxygenfunction:: fFinal()
:project: cpp_function_lookup
.. doxygenfunction:: fOverride()
:project: cpp_function_lookup

This one should actually have ``[[myattr]]`` but Doxygen seems to not put attributes into the XML:

.. doxygenfunction:: fAttr()
:project: cpp_function_lookup
.. doxygenfunction:: fFInit()
:project: cpp_function_lookup
.. doxygenfunction:: fTrailing()
:project: cpp_function_lookup

.. doxygenfunction:: fInit(int)
:project: cpp_function_lookup
.. doxygenfunction:: fPlain(int)
:project: cpp_function_lookup
.. doxygenfunction:: fPtr(int*)
:project: cpp_function_lookup
.. doxygenfunction:: fLRef(int&)
:project: cpp_function_lookup
.. doxygenfunction:: fRRef(int&&)
:project: cpp_function_lookup
.. doxygenfunction:: fParamPack(T...)
:project: cpp_function_lookup
.. doxygenfunction:: fMemPtr(int A::*)
:project: cpp_function_lookup
.. doxygenfunction:: fParen(void (*)())
:project: cpp_function_lookup

.. doxygenfunction:: fParenPlain(void (*)(int))
:project: cpp_function_lookup


Doxygen xrefsect
----------------

Expand Down
1 change: 1 addition & 0 deletions examples/specific/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ projects = nutshell alias rst inline namespacefile array inheritance \
enum define interface xrefsect tables \
cpp_anon cpp_enum cpp_union cpp_function cpp_friendclass \
cpp_inherited_members cpp_trailing_return_type cpp_constexpr_hax \
cpp_function_lookup \
c_file c_struct c_enum c_typedef c_macro c_union membergroups

special = programlisting decl_impl multifilexml auto class typedef
Expand Down
11 changes: 11 additions & 0 deletions examples/specific/cpp_function_lookup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
PROJECT_NAME = "C++ Function Lookup"
OUTPUT_DIRECTORY = cpp_function_lookup
GENERATE_LATEX = NO
GENERATE_MAN = NO
GENERATE_RTF = NO
CASE_SENSE_NAMES = NO
INPUT = cpp_function_lookup.h
QUIET = YES
JAVADOC_AUTOBRIEF = YES
GENERATE_HTML = NO
GENERATE_XML = YES
22 changes: 22 additions & 0 deletions examples/specific/cpp_function_lookup.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// stuff on the paramQual
void fNoexcept() noexcept;
void fFinal() final;
void fOverride() override;
void fAttr() [[myattr]]; // TODO: Doxygen seems to strip attributes
void fFInit() = default;
auto fTrailing() -> int;

// different parameters
void fInit(int arg = 42);
void fPlain(int arg);
void fPtr(int *arg);
void fLRef(int &arg);
void fRRef(int &&arg);
template<typename ...T>
void fParamPack(T ...arg);
class A {};
void fMemPtr(int A::*arg);
void fParen(void (*arg)());

// different parameters in a function pointer
void fParenPlain(void (*arg)(int argInner));

0 comments on commit 3023db0

Please sign in to comment.