[clang-tools-extra] [clang-doc] Display enum type along with enum name in HTML view (PR #181347)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 13 03:26:33 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tools-extra
Author: Samrudh Nelli (SamrudhNelli)
<details>
<summary>Changes</summary>
Displays enum type along with name.
For named variables
Previous output : enum XYZ
Current output : enum XYZ : unsigned int
For unnamed variables
Previous output : enum
Current output : enum : unsigned int
Fixes #<!-- -->166652
---
Full diff: https://github.com/llvm/llvm-project/pull/181347.diff
3 Files Affected:
- (modified) clang-tools-extra/clang-doc/JSONGenerator.cpp (+7-3)
- (modified) clang-tools-extra/clang-doc/assets/enum-template.mustache (+1-1)
- (modified) clang-tools-extra/test/clang-doc/enum.cpp (+1-1)
``````````diff
diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp
index 5051e7e6e690d..e44bdaaf8e510 100644
--- a/clang-tools-extra/clang-doc/JSONGenerator.cpp
+++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp
@@ -565,9 +565,13 @@ static void serializeInfo(const EnumInfo &I, json::Object &Obj,
if (I.BaseType) {
json::Value BaseTypeVal = Object();
auto &BaseTypeObj = *BaseTypeVal.getAsObject();
- BaseTypeObj["Name"] = I.BaseType->Type.Name;
- BaseTypeObj["QualName"] = I.BaseType->Type.QualName;
- BaseTypeObj["USR"] = toHex(toStringRef(I.BaseType->Type.USR));
+ // Create a nested 'Type' object so the template can find {{Type.Name}}
+ json::Value TypeVal = Object();
+ auto &TypeObj = *TypeVal.getAsObject();
+ TypeObj["Name"] = I.BaseType->Type.Name;
+ TypeObj["QualName"] = I.BaseType->Type.QualName;
+ TypeObj["USR"] = toHex(toStringRef(I.BaseType->Type.USR));
+ BaseTypeObj["Type"] = TypeVal;
Obj["BaseType"] = BaseTypeVal;
}
diff --git a/clang-tools-extra/clang-doc/assets/enum-template.mustache b/clang-tools-extra/clang-doc/assets/enum-template.mustache
index 7434b7bfce347..dc4260dcc37e2 100644
--- a/clang-tools-extra/clang-doc/assets/enum-template.mustache
+++ b/clang-tools-extra/clang-doc/assets/enum-template.mustache
@@ -7,7 +7,7 @@
}}
<div id="{{USR}}" class="delimiter-container">
<div>
- <pre><code class="language-cpp code-clang-doc">enum {{Name}}</code></pre>
+ <pre><code class="language-cpp code-clang-doc">enum {{Name}}{{#BaseType}} : {{Type.Name}}{{/BaseType}}</code></pre>
</div>
{{! Enum Values }}
<table class="table-wrapper">
diff --git a/clang-tools-extra/test/clang-doc/enum.cpp b/clang-tools-extra/test/clang-doc/enum.cpp
index 6e11bbf065f25..a866f2e43aa75 100644
--- a/clang-tools-extra/test/clang-doc/enum.cpp
+++ b/clang-tools-extra/test/clang-doc/enum.cpp
@@ -82,7 +82,7 @@ enum class Shapes {
// COM: FIXME: Serialize "enum class" in template
// HTML-INDEX: <div>
-// HTML-INDEX: <pre><code class="language-cpp code-clang-doc">enum Shapes</code></pre>
+// HTML-INDEX: <pre><code class="language-cpp code-clang-doc">enum Shapes : int</code></pre>
// HTML-INDEX: </div>
// HTML-INDEX: <table class="table-wrapper">
// HTML-INDEX: <tbody>
``````````
</details>
https://github.com/llvm/llvm-project/pull/181347
More information about the cfe-commits
mailing list