-
Notifications
You must be signed in to change notification settings - Fork 15.7k
[clang-doc] Serialize type info for function parameters #174268
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
base: main
Are you sure you want to change the base?
Conversation
Only the type name of function parameters were serialized, which was left over from the old Mustache generator. Without the type info, the fully qualified name of templated parameters wouldn't serialized.
|
@llvm/pr-subscribers-clang-tools-extra Author: Erick Velez (evelez7) ChangesOnly the type name of function parameters were serialized, which was Full diff: https://github.com/llvm/llvm-project/pull/174268.diff 9 Files Affected:
diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp
index 15fcbb4a9cff5..86b8687c05cd8 100644
--- a/clang-tools-extra/clang-doc/JSONGenerator.cpp
+++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp
@@ -448,7 +448,11 @@ static void serializeInfo(const TypeInfo &I, Object &Obj) {
static void serializeInfo(const FieldTypeInfo &I, Object &Obj) {
Obj["Name"] = I.Name;
- Obj["Type"] = I.Type.Name;
+ insertNonEmpty("DefaultValue", I.DefaultValue, Obj);
+ json::Value ReferenceVal = Object();
+ Object &ReferenceObj = *ReferenceVal.getAsObject();
+ serializeReference(I.Type, ReferenceObj);
+ Obj["Type"] = ReferenceVal;
}
static void serializeInfo(const FunctionInfo &F, json::Object &Obj,
diff --git a/clang-tools-extra/clang-doc/assets/class-template.mustache b/clang-tools-extra/clang-doc/assets/class-template.mustache
index c28655fbb219a..20510b6fd4d10 100644
--- a/clang-tools-extra/clang-doc/assets/class-template.mustache
+++ b/clang-tools-extra/clang-doc/assets/class-template.mustache
@@ -243,7 +243,7 @@
<pre><code class="language-cpp code-clang-doc">class {{Reference.Name}}</code></pre>
{{/IsClass}}
{{^IsClass}}
- <pre><code class="language-cpp code-clang-doc">{{ReturnType.Name}} {{Name}}{{#Template}}{{#Specialization}}<{{#Parameters}}{{Param}}{{^End}}, {{/End}}{{/Parameters}}>{{/Specialization}}{{/Template}} ({{#Params}}{{^End}}{{Type}} {{Name}}, {{/End}}{{#End}}{{Type}} {{Name}}{{/End}}{{/Params}})</code></pre>
+ <pre><code class="language-cpp code-clang-doc">{{ReturnType.Name}} {{Name}}{{#Template}}{{#Specialization}}<{{#Parameters}}{{Param}}{{^End}}, {{/End}}{{/Parameters}}>{{/Specialization}}{{/Template}} ({{#Params}}{{Type.QualName}} {{Name}}{{^End}}, {{/End}}{{/Params}})</code></pre>
{{/IsClass}}
{{#.Description}}
{{>Comments}}
diff --git a/clang-tools-extra/clang-doc/assets/function-template.mustache b/clang-tools-extra/clang-doc/assets/function-template.mustache
index 5e02257f86de8..2692f0cd73b94 100644
--- a/clang-tools-extra/clang-doc/assets/function-template.mustache
+++ b/clang-tools-extra/clang-doc/assets/function-template.mustache
@@ -11,7 +11,7 @@
<pre><code class="language-cpp code-clang-doc">template <{{#Parameters}}{{Param}}{{^End}}, {{/End}}{{/Parameters}}></code></pre>
{{/Template}}
{{! Function Prototype }}
- <pre><code class="language-cpp code-clang-doc">{{ReturnType.Name}} {{Name}}{{#Template}}{{#Specialization}}<{{#Parameters}}{{Param}}{{^End}}, {{/End}}{{/Parameters}}>{{/Specialization}}{{/Template}} ({{#Params}}{{^End}}{{Type}} {{Name}}, {{/End}}{{#End}}{{Type}} {{Name}}{{/End}}{{/Params}})</code></pre>
+ <pre><code class="language-cpp code-clang-doc">{{ReturnType.QualName}} {{Name}}{{#Template}}{{#Specialization}}<{{#Parameters}}{{Param}}{{^End}}, {{/End}}{{/Parameters}}>{{/Specialization}}{{/Template}} ({{#Params}}{{Type.QualName}} {{Name}}{{^End}}, {{/End}}{{/Params}})</code></pre>
{{! Function Comments }}
{{#Description}}
<div>
diff --git a/clang-tools-extra/test/clang-doc/json/class-template.cpp b/clang-tools-extra/test/clang-doc/json/class-template.cpp
index 9b0d4c4a9ba23..26234509dc183 100644
--- a/clang-tools-extra/test/clang-doc/json/class-template.cpp
+++ b/clang-tools-extra/test/clang-doc/json/class-template.cpp
@@ -13,7 +13,11 @@ template<typename T> struct MyClass {
// CHECK-NEXT: {
// CHECK-NEXT: "End": true,
// CHECK-NEXT: "Name": "Param",
-// CHECK-NEXT: "Type": "T"
+// CHECK-NEXT: "Type": {
+// CHECK-NEXT: "Name": "T",
+// CHECK-NEXT: "QualName": "T",
+// CHECK-NEXT: "USR": "0000000000000000000000000000000000000000"
+// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT: ],
// CHECK-NEXT: "ReturnType": {
diff --git a/clang-tools-extra/test/clang-doc/json/class.cpp b/clang-tools-extra/test/clang-doc/json/class.cpp
index 9feb04c792a43..936d2c5b10571 100644
--- a/clang-tools-extra/test/clang-doc/json/class.cpp
+++ b/clang-tools-extra/test/clang-doc/json/class.cpp
@@ -104,7 +104,11 @@ struct MyClass {
// CHECK-NEXT: {
// CHECK-NEXT: "End": true,
// CHECK-NEXT: "Name": "",
-// CHECK-NEXT: "Type": "int"
+// CHECK-NEXT: "Type": {
+// CHECK-NEXT: "Name": "int",
+// CHECK-NEXT: "QualName": "int",
+// CHECK-NEXT: "USR": "0000000000000000000000000000000000000000"
+// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT: ],
// CHECK-NEXT: "Reference": {
@@ -217,7 +221,11 @@ struct MyClass {
// CHECK-NEXT: {
// CHECK-NEXT: "End": true,
// CHECK-NEXT: "Name": "MyParam",
-// CHECK-NEXT: "Type": "int"
+// CHECK-NEXT: "Type": {
+// CHECK-NEXT: "Name": "int",
+// CHECK-NEXT: "QualName": "int",
+// CHECK-NEXT: "USR": "0000000000000000000000000000000000000000"
+// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT: ],
// CHECK-NEXT: "ReturnType": {
diff --git a/clang-tools-extra/test/clang-doc/json/function-requires.cpp b/clang-tools-extra/test/clang-doc/json/function-requires.cpp
index 8c86b1f93cc5e..18604e0ddeac7 100644
--- a/clang-tools-extra/test/clang-doc/json/function-requires.cpp
+++ b/clang-tools-extra/test/clang-doc/json/function-requires.cpp
@@ -21,7 +21,11 @@ template<Incrementable T> Incrementable auto incrementTwo(T t);
// CHECK-NEXT: {
// CHECK-NEXT: "End": true,
// CHECK-NEXT: "Name": "t",
-// CHECK-NEXT: "Type": "T"
+// CHECK-NEXT: "Type": {
+// CHECK-NEXT: "Name": "T",
+// CHECK-NEXT: "QualName": "T",
+// CHECK-NEXT: "USR": "0000000000000000000000000000000000000000"
+// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT: ],
// CHECK-NEXT: "ReturnType": {
@@ -59,7 +63,11 @@ template<Incrementable T> Incrementable auto incrementTwo(T t);
// CHECK-NEXT: {
// CHECK-NEXT: "End": true,
// CHECK-NEXT: "Name": "t",
-// CHECK-NEXT: "Type": "T"
+// CHECK-NEXT: "Type": {
+// CHECK-NEXT: "Name": "T",
+// CHECK-NEXT: "QualName": "T",
+// CHECK-NEXT: "USR": "0000000000000000000000000000000000000000"
+// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT: ],
// CHECK-NEXT: "ReturnType": {
diff --git a/clang-tools-extra/test/clang-doc/json/method-template.cpp b/clang-tools-extra/test/clang-doc/json/method-template.cpp
index a617f983d1269..9cfefa32158ef 100644
--- a/clang-tools-extra/test/clang-doc/json/method-template.cpp
+++ b/clang-tools-extra/test/clang-doc/json/method-template.cpp
@@ -24,7 +24,11 @@ struct MyClass {
// CHECK-NEXT: {
// CHECK-NEXT: "End": true,
// CHECK-NEXT: "Name": "param",
-// CHECK-NEXT: "Type": "T"
+// CHECK-NEXT: "Type": {
+// CHECK-NEXT: "Name": "T",
+// CHECK-NEXT: "QualName": "T",
+// CHECK-NEXT: "USR": "0000000000000000000000000000000000000000"
+// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT: ],
// CHECK-NEXT: "ReturnType": {
diff --git a/clang-tools-extra/test/clang-doc/json/namespace.cpp b/clang-tools-extra/test/clang-doc/json/namespace.cpp
index 1337efe3f268d..34f4eb3cb8f81 100644
--- a/clang-tools-extra/test/clang-doc/json/namespace.cpp
+++ b/clang-tools-extra/test/clang-doc/json/namespace.cpp
@@ -59,7 +59,11 @@ typedef int MyTypedef;
// CHECK-NEXT: {
// CHECK-NEXT: "End": true,
// CHECK-NEXT: "Name": "Param",
-// CHECK-NEXT: "Type": "int"
+// CHECK-NEXT: "Type": {
+// CHECK-NEXT: "Name": "int",
+// CHECK-NEXT: "QualName": "int",
+// CHECK-NEXT: "USR": "0000000000000000000000000000000000000000"
+// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT: ],
// CHECK-NEXT: "ReturnType": {
diff --git a/clang-tools-extra/test/clang-doc/templates.cpp b/clang-tools-extra/test/clang-doc/templates.cpp
index e76ccb240dcfc..1a5f3058abce9 100644
--- a/clang-tools-extra/test/clang-doc/templates.cpp
+++ b/clang-tools-extra/test/clang-doc/templates.cpp
@@ -54,7 +54,11 @@ void ParamPackFunction(T... args);
// JSON-NEXT: {
// JSON-NEXT: "End": true,
// JSON-NEXT: "Name": "args",
-// JSON-NEXT: "Type": "T..."
+// JSON-NEXT: "Type": {
+// JSON-NEXT: "Name": "T...",
+// JSON-NEXT: "QualName": "T...",
+// JSON-NEXT: "USR": "0000000000000000000000000000000000000000"
+// JSON-NEXT: }
// JSON-NEXT: }
// JSON-NEXT: ],
// JSON-NEXT: "ReturnType": {
@@ -113,7 +117,11 @@ void function(T x) {}
// JSON-NEXT: {
// JSON-NEXT: "End": true,
// JSON-NEXT: "Name": "x",
-// JSON-NEXT: "Type": "T"
+// JSON-NEXT: "Type": {
+// JSON-NEXT: "Name": "T",
+// JSON-NEXT: "QualName": "T",
+// JSON-NEXT: "USR": "0000000000000000000000000000000000000000"
+// JSON-NEXT: }
// JSON-NEXT: }
// JSON-NEXT: ],
// JSON-NEXT: "ReturnType": {
@@ -139,7 +147,7 @@ void function(T x) {}
// HTML-NEXT: <div id="{{([0-9A-F]{40})}}">
// HTML-NEXT: <pre><code class="language-cpp code-clang-doc">template <typename T, int U = 1></code></pre>
// HTML-NEXT: <pre><code class="language-cpp code-clang-doc">void function (T x)</code></pre>
-// HTML-NEXT: <p>Defined at line [[# @LINE - 56]] of file {{.*}}templates.cpp</p>
+// HTML-NEXT: <p>Defined at line [[# @LINE - 60]] of file {{.*}}templates.cpp</p>
// HTML-NEXT: </div>
// HTML-NEXT: </div>
@@ -177,7 +185,11 @@ void function<bool, 0>(bool x) {}
// JSON-NEXT: {
// JSON-NEXT: "End": true,
// JSON-NEXT: "Name": "x",
-// JSON-NEXT: "Type": "bool"
+// JSON-NEXT: "Type": {
+// JSON-NEXT: "Name": "bool",
+// JSON-NEXT: "QualName": "bool",
+// JSON-NEXT: "USR": "0000000000000000000000000000000000000000"
+// JSON-NEXT: }
// JSON-NEXT: }
// JSON-NEXT: ],
// JSON-NEXT: "ReturnType": {
@@ -206,7 +218,7 @@ void function<bool, 0>(bool x) {}
// HTML-NEXT: <div id="{{([0-9A-F]{40})}}">
// HTML-NEXT: <pre><code class="language-cpp code-clang-doc">template <></code></pre>
// HTML-NEXT: <pre><code class="language-cpp code-clang-doc">void function<bool, 0> (bool x)</code></pre>
-// HTML-NEXT: <p>Defined at line [[# @LINE - 62]] of file {{.*}}templates.cpp</p>
+// HTML-NEXT: <p>Defined at line [[# @LINE - 66]] of file {{.*}}templates.cpp</p>
// HTML-NEXT: </div>
// HTML-NEXT: </div>
@@ -284,12 +296,16 @@ tuple<int, int, bool> func_with_tuple_param(tuple<int, int, bool> t) { return t;
// MD: **t** The input to func_with_tuple_param
// JSON: "Name": "func_with_tuple_param",
-// COM: FIXME: Add type info to parameters
// JSON-NEXT: "Params": [
// JSON-NEXT: {
// JSON-NEXT: "End": true,
// JSON-NEXT: "Name": "t",
-// JSON-NEXT: "Type": "tuple"
+// JSON-NEXT: "Type": {
+// JSON-NEXT: "Name": "tuple",
+// JSON-NEXT: "Path": "GlobalNamespace",
+// JSON-NEXT: "QualName": "tuple<int, int, bool>",
+// JSON-NEXT: "USR": "{{([0-9A-F]{40})}}"
+// JSON-NEXT: }
// JSON-NEXT: }
// JSON-NEXT: ],
// JSON-NEXT: "ReturnType": {
@@ -302,7 +318,7 @@ tuple<int, int, bool> func_with_tuple_param(tuple<int, int, bool> t) { return t;
// HTML: <div class="delimiter-container">
// HTML-NEXT: <div id="{{([0-9A-F]{40})}}">
-// HTML-NEXT: <pre><code class="language-cpp code-clang-doc">tuple func_with_tuple_param (tuple t)</code></pre>
+// HTML-NEXT: <pre><code class="language-cpp code-clang-doc">tuple<int, int, bool> func_with_tuple_param (tuple<int, int, bool> t)</code></pre>
// HTML-NEXT: <div>
// HTML-NEXT: <div>
// HTML-NEXT: <p> A function with a tuple parameter</p>
@@ -312,6 +328,6 @@ tuple<int, int, bool> func_with_tuple_param(tuple<int, int, bool> t) { return t;
// HTML-NEXT: <b>t</b> The input to func_with_tuple_param
// HTML-NEXT: </div>
// HTML-NEXT: </div>
-// HTML-NEXT: <p>Defined at line [[# @LINE - 77]] of file {{.*}}templates.cpp</p>
+// HTML-NEXT: <p>Defined at line [[# @LINE - 81]] of file {{.*}}templates.cpp</p>
// HTML-NEXT: </div>
// HTML-NEXT: </div>
|
|
Before: https://erickvelez.com/clang-doc-mustache-output/pr174268-before/GlobalNamespace/index.html The return value and param of |

Only the type name of function parameters were serialized, which was
left over from the old Mustache generator. Without the type info, the
fully qualified name of templated parameters wouldn't serialized.