From 61b97022ae6ac0944bfbc9283a2d500693587ee4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 26 Nov 2018 14:40:13 +0100 Subject: [PATCH] doxygen: slightly more robust way of parsing template arguments. I don't want to parse C++, please don't ask for more. --- doxygen/dox2html5.py | 18 ++- .../compound_crazy_template_params/Doxyfile | 13 ++ .../compound_crazy_template_params/File.h | 22 ++++ .../File_8h.html | 122 ++++++++++++++++++ doxygen/test/test_compound.py | 10 ++ 5 files changed, 181 insertions(+), 4 deletions(-) create mode 100644 doxygen/test/compound_crazy_template_params/Doxyfile create mode 100644 doxygen/test/compound_crazy_template_params/File.h create mode 100644 doxygen/test/compound_crazy_template_params/File_8h.html diff --git a/doxygen/dox2html5.py b/doxygen/dox2html5.py index ff6dac2b..6941cd9f 100755 --- a/doxygen/dox2html5.py +++ b/doxygen/dox2html5.py @@ -1640,11 +1640,21 @@ def parse_template_params(state: State, element: ET.Element, description): if declname is not None: # declname or decltype?! template.name = declname.text + # Doxygen sometimes puts both in type, extract that, but only in case + # it's not too crazy to do (i.e., no pointer values, no nameless + # FooBar types). Using rpartition() to split on the last found + # space, but in case of nothing found, rpartition() puts the full + # string into [2] instead of [0], so we have to account for that. + elif template.type[-1].isalnum(): + parts = template.type.rpartition(' ') + if parts[1]: + template.type = parts[0] + template.name = parts[2] + else: + template.type = parts[2] + template.name = '' else: - # Doxygen sometimes puts both in type, extract that - parts = template.type.partition(' ') - template.type = parts[0] - template.name = parts[2] + template.name = '' default = i.find('defval') template.default = parse_type(state, default) if default is not None else '' if template.name in description: diff --git a/doxygen/test/compound_crazy_template_params/Doxyfile b/doxygen/test/compound_crazy_template_params/Doxyfile new file mode 100644 index 00000000..49e476ec --- /dev/null +++ b/doxygen/test/compound_crazy_template_params/Doxyfile @@ -0,0 +1,13 @@ +INPUT = File.h +QUIET = YES +GENERATE_HTML = NO +GENERATE_LATEX = NO +GENERATE_XML = YES +XML_PROGRAMLISTING = NO + +##! M_PAGE_FINE_PRINT = +##! M_THEME_COLOR = +##! M_FAVICON = +##! M_LINKS_NAVBAR1 = +##! M_LINKS_NAVBAR2 = +##! M_SEARCH_DISABLED = YES diff --git a/doxygen/test/compound_crazy_template_params/File.h b/doxygen/test/compound_crazy_template_params/File.h new file mode 100644 index 00000000..22658b62 --- /dev/null +++ b/doxygen/test/compound_crazy_template_params/File.h @@ -0,0 +1,22 @@ +#include + +/** @file + * @brief A file + */ + +/** +@brief Templates can get quite crazy +@tparam T yes they +@param value can +*/ +template && std::is_class_v>* = nullptr> void foo(T* value); + +/** +@brief Templates can get quite crazy +@tparam T yes they +@tparam ptr absolutely +@param value can +*/ +template && std::is_class_v>* ptr = nullptr> void bar(T* value); + +} diff --git a/doxygen/test/compound_crazy_template_params/File_8h.html b/doxygen/test/compound_crazy_template_params/File_8h.html new file mode 100644 index 00000000..e064c8fd --- /dev/null +++ b/doxygen/test/compound_crazy_template_params/File_8h.html @@ -0,0 +1,122 @@ + + + + + File.h file | My Project + + + + + +
+
+
+
+
+

+ File.h file +

+

A file.

+
+

Contents

+ +
+
+

Functions

+
+
+
template<class T, std::enable_if<!std::is_function_v<T> && std::is_class_v<T>>* = nullptr>
+ void foo(T* value) +
+
Templates can get quite crazy.
+
+
template<class T, std::enable_if<!std::is_function_v<T> && std::is_class_v<T>>* ptr = nullptr>
+ void bar(T* value) +
+
Templates can get quite crazy.
+
+
+
+

Function documentation

+
+

+
+ template<class T, std::enable_if<!std::is_function_v<T> && std::is_class_v<T>>* = nullptr> +
+ void foo(T* value) +

+

Templates can get quite crazy.

+ + + + + + + + + + + + + + + + + + + +
Template parameters
Tyes they
Parameters
valuecan
+
+
+

+
+ template<class T, std::enable_if<!std::is_function_v<T> && std::is_class_v<T>>* ptr = nullptr> +
+ void bar(T* value) +

+

Templates can get quite crazy.

+ + + + + + + + + + + + + + + + + + + + + + + +
Template parameters
Tyes they
ptrabsolutely
Parameters
valuecan
+
+
+
+
+
+
+ + diff --git a/doxygen/test/test_compound.py b/doxygen/test/test_compound.py index 69221b8c..a2478f5f 100644 --- a/doxygen/test/test_compound.py +++ b/doxygen/test/test_compound.py @@ -235,3 +235,13 @@ class FilenameCase(IntegrationTestCase): self.assertEqual(*self.actual_expected_contents('pages.html')) self.assertEqual(*self.actual_expected_contents('_u_p_p_e_r_c_a_s_e.html')) self.assertEqual(*self.actual_expected_contents('class_u_p_p_e_r_c_l_a_s_s.html')) + +class CrazyTemplateParams(IntegrationTestCase): + def __init__(self, *args, **kwargs): + super().__init__(__file__, 'crazy_template_params', *args, **kwargs) + + def test(self): + self.run_dox2html5(wildcard='*.xml') + + # The file should have the whole template argument as a type + self.assertEqual(*self.actual_expected_contents('File_8h.html')) -- 2.30.2