chiark / gitweb /
documentation/doxygen: don't trip up on WEIRD macros parsed as functions.
authorVladimír Vondruš <mosra@centrum.cz>
Fri, 14 Jan 2022 11:19:35 +0000 (12:19 +0100)
committerVladimír Vondruš <mosra@centrum.cz>
Fri, 14 Jan 2022 11:19:35 +0000 (12:19 +0100)
documentation/doxygen.py
documentation/test_doxygen/cpp_mishandled_macro_call/Doxyfile [new file with mode: 0644]
documentation/test_doxygen/cpp_mishandled_macro_call/File.h [new file with mode: 0644]
documentation/test_doxygen/cpp_mishandled_macro_call/File_8h.html [new file with mode: 0644]
documentation/test_doxygen/test_cpp.py

index afc8ccaaa789694c0f4b2b36d4c1f26085450d4e..d8da630b101d58e2e68519cabf0aaae17498129e 100755 (executable)
@@ -2087,7 +2087,11 @@ def parse_func(state: State, element: ET.Element):
         name = p.find('declname')
         param = Empty()
         param.name = name.text if name is not None else ''
-        param.type = parse_type(state, p.find('type'))
+        param_type = p.find('type')
+        if param_type is None:
+            logging.warning("{}: parameter {} of function {} has no type, ignoring the whole function as it's suspected to be a mishandled macro call".format(state.current, param.name, func.name))
+            return None
+        param.type = parse_type(state, param_type)
 
         # Recombine parameter name and array information back
         array = p.find('array')
diff --git a/documentation/test_doxygen/cpp_mishandled_macro_call/Doxyfile b/documentation/test_doxygen/cpp_mishandled_macro_call/Doxyfile
new file mode 100644 (file)
index 0000000..7e7e2ce
--- /dev/null
@@ -0,0 +1,15 @@
+INPUT                   = File.h
+AUTOLINK_SUPPORT        = NO
+QUIET                   = YES
+GENERATE_HTML           = NO
+GENERATE_LATEX          = NO
+GENERATE_XML            = YES
+XML_PROGRAMLISTING      = NO
+CASE_SENSE_NAMES        = YES
+
+##! M_PAGE_FINE_PRINT   =
+##! M_THEME_COLOR       =
+##! M_FAVICON           =
+##! M_LINKS_NAVBAR1     =
+##! M_LINKS_NAVBAR2     =
+##! M_SEARCH_DISABLED   = YES
diff --git a/documentation/test_doxygen/cpp_mishandled_macro_call/File.h b/documentation/test_doxygen/cpp_mishandled_macro_call/File.h
new file mode 100644 (file)
index 0000000..1700633
--- /dev/null
@@ -0,0 +1,27 @@
+/** @file
+ * @brief A file.
+ */
+
+/** @brief A function-defining macro */
+#define DEFINE_FUNCTION(name) int function_ ## name(int param)
+
+/**
+@brief A function-defining macro call
+
+This one is misparsed as a function definition and because it doesn't do
+anything that would make it look suspicious, it will appear in the output.
+*/
+DEFINE_FUNCTION(a) {
+    return param;
+}
+
+/**
+@brief A function-defining macro call
+
+In this case the $ will however lead to the parameter to have a declname but
+not a type, which triggers a suspicion in the parser and so the whole function
+gets ignored.
+*/
+DEFINE_FUNCTION($) {
+    return param;
+}
diff --git a/documentation/test_doxygen/cpp_mishandled_macro_call/File_8h.html b/documentation/test_doxygen/cpp_mishandled_macro_call/File_8h.html
new file mode 100644 (file)
index 0000000..3e27ba5
--- /dev/null
@@ -0,0 +1,71 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8" />
+  <title>File.h file | My Project</title>
+  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,400i,600,600i%7CSource+Code+Pro:400,400i,600" />
+  <link rel="stylesheet" href="m-dark+documentation.compiled.css" />
+  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+</head>
+<body>
+<header><nav id="navigation">
+  <div class="m-container">
+    <div class="m-row">
+      <a href="index.html" id="m-navbar-brand" class="m-col-t-8 m-col-m-none m-left-m">My Project</a>
+    </div>
+  </div>
+</nav></header>
+<main><article>
+  <div class="m-container m-container-inflatable">
+    <div class="m-row">
+      <div class="m-col-l-10 m-push-l-1">
+        <h1>
+          File.h <span class="m-thin">file</span>
+        </h1>
+        <p>A file.</p>
+        <nav class="m-block m-default">
+          <h3>Contents</h3>
+          <ul>
+            <li>
+              Reference
+              <ul>
+                <li><a href="#func-members">Functions</a></li>
+                <li><a href="#define-members">Defines</a></li>
+              </ul>
+            </li>
+          </ul>
+        </nav>
+        <section id="func-members">
+          <h2><a href="#func-members">Functions</a></h2>
+          <dl class="m-doc">
+            <dt>
+              <span class="m-doc-wrap-bumper"><a href="#a720de5dd630a2721e555233c5242142a" class="m-doc">DEFINE_FUNCTION</a>(</span><span class="m-doc-wrap">a)</span>
+            </dt>
+            <dd>A function-defining macro call.</dd>
+          </dl>
+        </section>
+        <section id="define-members">
+          <h2><a href="#define-members">Defines</a></h2>
+          <dl class="m-doc">
+            <dt id="a85e81f41af5f02b030bf07f4967a0a08">
+              <span class="m-doc-wrap-bumper">#define <a href="#a85e81f41af5f02b030bf07f4967a0a08" class="m-doc-self">DEFINE_FUNCTION</a>(</span><span class="m-doc-wrap">name)</span>
+            </dt>
+            <dd>A function-defining macro.</dd>
+          </dl>
+        </section>
+        <section>
+          <h2>Function documentation</h2>
+          <section class="m-doc-details" id="a720de5dd630a2721e555233c5242142a"><div>
+            <h3>
+              <span class="m-doc-wrap-bumper"> </span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#a720de5dd630a2721e555233c5242142a" class="m-doc-self">DEFINE_FUNCTION</a>(</span><span class="m-doc-wrap">a)</span></span>
+            </h3>
+            <p>A function-defining macro call.</p>
+<p>This one is misparsed as a function definition and because it doesn&#x27;t do anything that would make it look suspicious, it will appear in the output.</p>
+          </div></section>
+        </section>
+      </div>
+    </div>
+  </div>
+</article></main>
+</body>
+</html>
index fed05c759872f1e09a9027b31f5e828aa5a39820..2802f539e539633c74124e6ba775f5d210b2cbc5 100644 (file)
@@ -97,3 +97,12 @@ class FunctionAttributesNospace(IntegrationTestCase):
     def test(self):
         self.run_doxygen(wildcard='structFoo.xml')
         self.assertEqual(*self.actual_expected_contents('structFoo.html'))
+
+class MishandledMacroCall(IntegrationTestCase):
+    def test(self):
+        with self.assertLogs() as cm:
+            self.run_doxygen(wildcard='*.xml')
+        self.assertEqual(*self.actual_expected_contents('File_8h.html'))
+        self.assertEqual(cm.output, [
+            "WARNING:root:File_8h.xml: parameter $ of function DEFINE_FUNCTION has no type, ignoring the whole function as it's suspected to be a mishandled macro call"
+        ])