Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make doxygenfunction more robust when matching parameters #723

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
jakobandersen marked this conversation as resolved.
Show resolved Hide resolved
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));