Skip to content

Commit 8f26458

Browse files
authored
[clang-doc] Add class template to HTML (#171937)
Emit class template declaration info so that it appears above a record's name in the Mustache template.
1 parent e0e5b6e commit 8f26458

File tree

11 files changed

+89
-19
lines changed

11 files changed

+89
-19
lines changed

clang-tools-extra/clang-doc/JSONGenerator.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,15 @@ static void serializeInfo(const ArrayRef<TemplateParamInfo> &Params,
378378
json::Value ParamsArray = Array();
379379
auto &ParamsArrayRef = *ParamsArray.getAsArray();
380380
ParamsArrayRef.reserve(Params.size());
381-
for (const auto &Param : Params)
382-
ParamsArrayRef.push_back(Param.Contents);
381+
for (size_t Idx = 0; Idx < Params.size(); ++Idx) {
382+
json::Value ParamObjVal = Object();
383+
Object &ParamObj = *ParamObjVal.getAsObject();
384+
385+
ParamObj["Param"] = Params[Idx].Contents;
386+
if (Idx == Params.size() - 1)
387+
ParamObj["End"] = true;
388+
ParamsArrayRef.push_back(ParamObjVal);
389+
}
383390
Obj["Parameters"] = ParamsArray;
384391
}
385392

clang-tools-extra/clang-doc/assets/class-template.mustache

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@
107107
<div class="resizer" id="resizer"></div>
108108
<div class="content">
109109
<section class="hero section-container">
110+
{{#Template}}
111+
<pre><code class="language-cpp code-clang-doc">template &lt;{{#Parameters}}{{Param}}{{^End}}, {{/End}}{{/Parameters}}&gt;</code></pre>
112+
{{/Template}}
110113
<div class="hero__title">
111114
<h1 class="hero__title-large">{{TagType}} {{Name}}</h1>
112115
<p>Defined at line {{Location.LineNumber}} of file {{Location.Filename}}</p>

clang-tools-extra/test/clang-doc/json/class-requires.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ struct MyClass;
2929
// CHECK-NEXT: }
3030
// CHECK-NEXT: ],
3131
// CHECK-NEXT: "Parameters": [
32-
// CHECK-NEXT: "typename T"
32+
// CHECK-NEXT: {
33+
// CHECK-NEXT: "End": true,
34+
// CHECK-NEXT: "typename T"
35+
// CHECK-NEXT: }
3336
// CHECK-NEXT: ]
3437
// CHECK-NEXT: },
3538
// CHECK-NEXT: "USR": "{{[0-9A-F]*}}"

clang-tools-extra/test/clang-doc/json/class-specialization.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ template<> struct MyClass<int> {};
1616
// BASE-NEXT: "TagType": "struct",
1717
// BASE-NEXT: "Template": {
1818
// BASE-NEXT: "Parameters": [
19-
// BASE-NEXT: "typename T"
19+
// BASE-NEXT: {
20+
// BASE-NEXT: "End": true,
21+
// BASE-NEXT: "Param": "typename T"
22+
// BASE-NEXT: }
2023
// BASE-NEXT: ]
2124
// BASE-NEXT: },
2225

@@ -30,7 +33,10 @@ template<> struct MyClass<int> {};
3033
// SPECIALIZATION-NEXT: "Template": {
3134
// SPECIALIZATION-NEXT: "Specialization": {
3235
// SPECIALIZATION-NEXT: "Parameters": [
33-
// SPECIALIZATION-NEXT: "int"
36+
// SPECIALIZATION-NEXT: {
37+
// SPECIALIZATION-NEXT: "End": true,
38+
// SPECIALIZATION-NEXT: "Param": "int"
39+
// SPECIALIZATION-NEXT: }
3440
// SPECIALIZATION-NEXT: ],
3541
// SPECIALIZATION-NEXT: "SpecializationOf": "{{[0-9A-F]*}}"
3642
// SPECIALIZATION-NEXT: }

clang-tools-extra/test/clang-doc/json/class-template.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,8 @@ template<typename T> struct MyClass {
2626
// CHECK: "Type": "T"
2727
// CHECK: "Template": {
2828
// CHECK-NEXT: "Parameters": [
29-
// CHECK-NEXT: "typename T"
29+
// CHECK-NEXT: {
30+
// CHECK-NEXT: "End": true,
31+
// CHECK-NEXT: "Param": "typename T"
32+
// CHECK-NEXT: }
3033
// CHECK-NEXT: ]

clang-tools-extra/test/clang-doc/json/class.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ struct MyClass {
108108
// CHECK-NEXT: },
109109
// CHECK-NEXT: "Template": {
110110
// CHECK-NEXT: "Parameters": [
111-
// CHECK-NEXT: "typename T"
111+
// CHECK-NEXT: {
112+
// CHECK-NEXT: "End": true,
113+
// CHECK-NEXT: "Param": "typename T"
114+
// CHECK-NEXT: }
112115
// CHECK-NEXT: ]
113116
// CHECK-NEXT: }
114117
// CHECK-NEXT: },

clang-tools-extra/test/clang-doc/json/concept.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ concept Incrementable = requires(T x) {
2525
// CHECK-NEXT: "Name": "Incrementable",
2626
// CHECK-NEXT: "Template": {
2727
// CHECK-NEXT: "Parameters": [
28-
// CHECK-NEXT: "typename T"
28+
// CHECK-NEXT: {
29+
// CHECK-NEXT: "End": true,
30+
// CHECK-NEXT: "Param": "typename T"
31+
// CHECK-NEXT: }
2932
// CHECK-NEXT: ]
3033
// CHECK-NEXT: },
3134
// CHECK-NEXT: "USR": "{{[0-9A-F]*}}"

clang-tools-extra/test/clang-doc/json/function-requires.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ template<Incrementable T> Incrementable auto incrementTwo(T t);
4343
// CHECK-NEXT: }
4444
// CHECK-NEXT: ],
4545
// CHECK-NEXT: "Parameters": [
46-
// CHECK-NEXT: "typename T"
46+
// CHECK-NEXT: {
47+
// CHECK-NEXT: "End": true,
48+
// CHECK-NEXT: "Param": "typename T"
49+
// CHECK-NEXT: }
4750
// CHECK-NEXT: ]
4851
// CHECK-NEXT: },
4952
// CHECK-NEXT: "USR": "{{[0-9A-F]*}}"
@@ -79,7 +82,10 @@ template<Incrementable T> Incrementable auto incrementTwo(T t);
7982
// CHECK-NEXT: }
8083
// CHECK-NEXT: ],
8184
// CHECK-NEXT: "Parameters": [
82-
// CHECK-NEXT: "Incrementable T"
85+
// CHECK-NEXT: {
86+
// CHECK-NEXT: "End": true,
87+
// CHECK-NEXT: "Param": "Incrementable T"
88+
// CHECK-NEXT: }
8389
// CHECK-NEXT: ]
8490
// CHECK-NEXT: },
8591
// CHECK-NEXT: "USR": "{{[0-9A-F]*}}"

clang-tools-extra/test/clang-doc/json/method-template.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ struct MyClass {
3636
// CHECK-NEXT: },
3737
// CHECK-NEXT: "Template": {
3838
// CHECK-NEXT: "Parameters": [
39-
// CHECK-NEXT: "class T"
39+
// CHECK-NEXT: {
40+
// CHECK-NEXT: "End": true,
41+
// CHECK-NEXT: "Param": "class T"
42+
// CHECK-NEXT: }
4043
// CHECK-NEXT: ]
4144
// CHECK-NEXT: },
4245
// CHECK-NEXT: "USR": "{{[0-9A-F]*}}"

clang-tools-extra/test/clang-doc/templates.cpp

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
// RUN: clang-doc --doxygen --executor=standalone %s -output=%t/docs --format=md
88
// RUN: cat %t/docs/GlobalNamespace/index.md | FileCheck %s --check-prefix=MD
99

10-
// RUN: clang-doc --doxygen --executor=standalone %s -output=%t/docs --format=json
10+
// RUN: clang-doc --doxygen --executor=standalone %s -output=%t/docs --format=html
1111
// RUN: cat %t/docs/json/GlobalNamespace/index.json | FileCheck %s --check-prefix=JSON
12+
// RUN: cat %t/docs/html/GlobalNamespace/_ZTV5tuple.html | FileCheck %s --check-prefix=HTML-STRUCT
1213

1314
// YAML: ---
1415
// YAML-NEXT: USR: '{{([0-9A-F]{40})}}'
@@ -64,7 +65,10 @@ void ParamPackFunction(T... args);
6465
// JSON-NEXT: },
6566
// JSON-NEXT: "Template": {
6667
// JSON-NEXT: "Parameters": [
67-
// JSON-NEXT: "class... T"
68+
// JSON-NEXT: {
69+
// JSON-NEXT: "End": true,
70+
// JSON-NEXT: "Param": "class... T"
71+
// JSON-NEXT: }
6872
// JSON-NEXT: ]
6973
// JSON-NEXT: },
7074

@@ -111,10 +115,15 @@ void function(T x) {}
111115
// JSON-NEXT: },
112116
// JSON-NEXT: "Template": {
113117
// JSON-NEXT: "Parameters": [
114-
// JSON-NEXT: "typename T",
115-
// JSON-NEXT: "int U = 1"
118+
// JSON-NEXT: {
119+
// JSON-NEXT: "Param": "typename T"
120+
// JSON-NEXT: },
121+
// JSON-NEXT: {
122+
// JSON-NEXT: "End": true,
123+
// JSON-NEXT: "Param": "int U = 1"
124+
// JSON-NEXT: }
116125
// JSON-NEXT: ]
117-
// JSON-NEXT: },
126+
// JSON-NEXT: }
118127

119128
template <>
120129
void function<bool, 0>(bool x) {}
@@ -162,8 +171,13 @@ void function<bool, 0>(bool x) {}
162171
// JSON-NEXT: "Template": {
163172
// JSON-NEXT: "Specialization": {
164173
// JSON-NEXT: "Parameters": [
165-
// JSON-NEXT: "bool",
166-
// JSON-NEXT: "0"
174+
// JSON-NEXT: {
175+
// JSON-NEXT: "Param": "bool"
176+
// JSON-NEXT: },
177+
// JSON-NEXT: {
178+
// JSON-NEXT: "End": true,
179+
// JSON-NEXT: "Param": "0"
180+
// JSON-NEXT: }
167181
// JSON-NEXT: ],
168182
// JSON-NEXT: "SpecializationOf": "{{([0-9A-F]{40})}}"
169183
// JSON-NEXT: }
@@ -175,6 +189,22 @@ void function<bool, 0>(bool x) {}
175189
template <typename... Tys>
176190
struct tuple {};
177191

192+
// HTML-STRUCT: <section class="hero section-container">
193+
// HTML-STRUCT-NEXT: <pre><code class="language-cpp code-clang-doc">template &lt;typename... Tys&gt;</code></pre>
194+
// HTML-STRUCT-NEXT: <div class="hero__title">
195+
// HTML-STRUCT-NEXT: <h1 class="hero__title-large">struct tuple</h1>
196+
// HTML-STRUCT-NEXT: <p>Defined at line [[# @LINE - 6]] of file {{.*}}templates.cpp</p>
197+
// HTML-STRUCT-NEXT: <div class="hero__subtitle">
198+
// HTML-STRUCT-NEXT: <div>
199+
// HTML-STRUCT-NEXT: <p> A Tuple type</p>
200+
// HTML-STRUCT-NEXT: </div>
201+
// HTML-STRUCT-NEXT: <div>
202+
// HTML-STRUCT-NEXT: <p> Does Tuple things.</p>
203+
// HTML-STRUCT-NEXT: </div>
204+
// HTML-STRUCT-NEXT: </div>
205+
// HTML-STRUCT-NEXT: </div>
206+
// HTML-STRUCT-NEXT: </section>
207+
178208
/// A function with a tuple parameter
179209
///
180210
/// \param t The input to func_with_tuple_param

0 commit comments

Comments
 (0)