chiark / gitweb /
documentation/doxygen: preserve template info in base classes.
authorVladimír Vondruš <mosra@centrum.cz>
Mon, 8 Jun 2020 21:06:10 +0000 (23:06 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Mon, 8 Jun 2020 22:27:47 +0000 (00:27 +0200)
documentation/doxygen.py
documentation/test_doxygen/compound_base_template_classes/Doxyfile [new file with mode: 0644]
documentation/test_doxygen/compound_base_template_classes/File.h [new file with mode: 0644]
documentation/test_doxygen/compound_base_template_classes/structNamespace_1_1MyClass.html [new file with mode: 0644]
documentation/test_doxygen/test_compound.py

index 599c85ab5a3d8e95504f5159357eb925d2b06d7f..cde5914af0b09835edd5f040f1bb702a565951d4 100755 (executable)
@@ -2702,12 +2702,20 @@ def parse_xml(state: State, xml: str):
                 if not compounddef_child.attrib['prot'] == 'private' and id in state.compounds and state.compounds[id].has_details:
                     symbol = state.compounds[id]
 
+                    # Strip parent if the base class has the same parent as
+                    # this class. Can't just use symbol.leaf_name vs
+                    # symbol.name because the <basecompoundref> can contain
+                    # template information.
+                    symbol_name = fix_type_spacing(html.escape(compounddef_child.text))
+                    if state.compounds[compound.id].parent and symbol.parent and symbol.parent.startswith(state.compounds[compound.id].parent):
+                        parent_name = state.compounds[symbol.parent].name + '::'
+                        if symbol_name.startswith(parent_name):
+                            symbol_name = symbol_name[len(parent_name):]
+
                     class_ = Empty()
                     class_.kind = symbol.kind
                     class_.url = symbol.url
-                    # Use only the leaf name if the base class has the same
-                    # parent as this class
-                    class_.name = symbol.leaf_name if state.compounds[compound.id].parent and symbol.parent and symbol.parent.startswith(state.compounds[compound.id].parent) else symbol.name
+                    class_.name = symbol_name
                     class_.brief = symbol.brief
                     class_.templates = symbol.templates
                     class_.deprecated = symbol.deprecated
diff --git a/documentation/test_doxygen/compound_base_template_classes/Doxyfile b/documentation/test_doxygen/compound_base_template_classes/Doxyfile
new file mode 100644 (file)
index 0000000..7e9ad92
--- /dev/null
@@ -0,0 +1,14 @@
+INPUT                   = File.h
+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/compound_base_template_classes/File.h b/documentation/test_doxygen/compound_base_template_classes/File.h
new file mode 100644 (file)
index 0000000..e2e7506
--- /dev/null
@@ -0,0 +1,18 @@
+/** @file
+ * @brief A file
+ */
+
+/** @brief A namespace */
+namespace Namespace {
+
+/** @brief A base */
+template<class> struct Base {};
+
+/**
+@brief A class with two different template bases
+
+The @ref Namespace gets stripped from the references.
+*/
+struct MyClass: Base<int>, Base<Base<float>> {};
+
+}
diff --git a/documentation/test_doxygen/compound_base_template_classes/structNamespace_1_1MyClass.html b/documentation/test_doxygen/compound_base_template_classes/structNamespace_1_1MyClass.html
new file mode 100644 (file)
index 0000000..8dbe582
--- /dev/null
@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8" />
+  <title>Namespace::MyClass struct | 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>
+          <span class="m-breadcrumb"><a href="namespaceNamespace.html">Namespace</a>::<wbr/></span>MyClass <span class="m-thin">struct</span>
+          <div class="m-doc-include m-code m-inverted m-text-right"><span class="cp">#include</span> <a class="cpf" href="File_8h.html">&lt;File.h&gt;</a></div>
+        </h1>
+        <p>A class with two different template bases.</p>
+<p>The <a href="namespaceNamespace.html" class="m-doc">Namespace</a> gets stripped from the references.</p>
+        <section id="base-classes">
+          <h2><a href="#base-classes">Base classes</a></h2>
+          <dl class="m-doc">
+            <dt>
+              <div class="m-doc-template">template&lt;class&gt;</div>
+              struct <a href="structNamespace_1_1Base.html" class="m-doc">Base&lt;int&gt;</a>
+            </dt>
+            <dd>A base.</dd>
+            <dt>
+              <div class="m-doc-template">template&lt;class&gt;</div>
+              struct <a href="structNamespace_1_1Base.html" class="m-doc">Base&lt;Base&lt;float&gt;&gt;</a>
+            </dt>
+            <dd>A base.</dd>
+          </dl>
+        </section>
+      </div>
+    </div>
+  </div>
+</article></main>
+</body>
+</html>
index 870542ccf2899adc6df4c341ae1b9a1a2f9cc775..efcd7d1b110001629d5aa261244739cf3a97dff6 100644 (file)
@@ -314,3 +314,8 @@ class ExceptionReference(IntegrationTestCase):
     def test(self):
         self.run_doxygen(wildcard='*.xml')
         self.assertEqual(*self.actual_expected_contents('File_8h.html'))
+
+class BaseTemplateClasses(IntegrationTestCase):
+    def test(self):
+        self.run_doxygen(wildcard='*.xml')
+        self.assertEqual(*self.actual_expected_contents('structNamespace_1_1MyClass.html'))