https://github.com/evelez7 created https://github.com/llvm/llvm-project/pull/174265
Serializing an `Anonymous` field allows them to be excluded from the HTML sidebar. Before, there would be several empty spaces in the sidebar for anonymous enums. This patch also allows the same for anonymous records, but since they're a GNU extension we don't handle them explicitly yet. >From 5a5262ddc52761a46c9590e22fca908af181b923 Mon Sep 17 00:00:00 2001 From: Erick Velez <[email protected]> Date: Fri, 2 Jan 2026 22:36:10 -0800 Subject: [PATCH] [clang-doc] Serialize an `Anonymous` JSON field for enums and records Serializing an `Anonymous` field allows them to be excluded from the HTML sidebar. Before, there would be several empty spaces in the sidebar for anonymous enums. This patch also allows the same for anonymous records, but since they're a GNU extension we don't handle them explicitly yet. --- clang-tools-extra/clang-doc/JSONGenerator.cpp | 6 ++++ .../assets/namespace-template.mustache | 4 +++ clang-tools-extra/test/clang-doc/enum.cpp | 34 +++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index 15fcbb4a9cff5..eb5cb50ec618b 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -323,6 +323,12 @@ serializeCommonAttributes(const Info &I, json::Object &Obj, Obj["Location"] = serializeLocation(Symbol->DefLoc.value(), RepositoryUrl); } + + // Allow for special handling for anonymous records/enums + // Anonymous records are a GNU extension, so we don't currently test them. + if ((I.IT == InfoType::IT_record || I.IT == InfoType::IT_enum) && + I.Name.empty()) + Obj["Anonymous"] = true; } static void serializeReference(const Reference &Ref, Object &ReferenceObj) { diff --git a/clang-tools-extra/clang-doc/assets/namespace-template.mustache b/clang-tools-extra/clang-doc/assets/namespace-template.mustache index 2d8381a9ea6e3..7474199861778 100644 --- a/clang-tools-extra/clang-doc/assets/namespace-template.mustache +++ b/clang-tools-extra/clang-doc/assets/namespace-template.mustache @@ -22,9 +22,11 @@ <li> <ul> {{#Enums}} + {{^Anonymous}} <li class="sidebar-item-container"> <a class="sidebar-item" href="#{{USR}}">{{Name}}</a> </li> + {{/Anonymous}} {{/Enums}} </ul> </li> @@ -36,9 +38,11 @@ <li> <ul> {{#Records}} + {{^Anonymous}} <li class="sidebar-item-container"> <a class="sidebar-item" href="#{{USR}}">{{Name}}</a> </li> + {{/Anonymous}} {{/Records}} </ul> </li> diff --git a/clang-tools-extra/test/clang-doc/enum.cpp b/clang-tools-extra/test/clang-doc/enum.cpp index ce844ec072564..3a9f6e1418c02 100644 --- a/clang-tools-extra/test/clang-doc/enum.cpp +++ b/clang-tools-extra/test/clang-doc/enum.cpp @@ -251,3 +251,37 @@ enum ColorUserSpecified { // HTML-INDEX: </tr> // HTML-INDEX: </tbody> // HTML-INDEX: </table> + +enum { + Debug, + Release, + RelWithDebInfo, + MinSizeRel +}; + +// HTML-INDEX: <pre><code class="language-cpp code-clang-doc">enum </code></pre> +// HTML-INDEX: </div> +// HTML-INDEX: <table class="table-wrapper"> +// HTML-INDEX: <tbody> +// HTML-INDEX: <tr> +// HTML-INDEX: <th>Name</th> +// HTML-INDEX: <th>Value</th> +// HTML-INDEX: </tr> +// HTML-INDEX: <tr> +// HTML-INDEX: <td>Debug</td> +// HTML-INDEX: <td>0</td> +// HTML-INDEX: </tr> +// HTML-INDEX: <tr> +// HTML-INDEX: <td>Release</td> +// HTML-INDEX: <td>1</td> +// HTML-INDEX: </tr> +// HTML-INDEX: <tr> +// HTML-INDEX: <td>RelWithDebInfo</td> +// HTML-INDEX: <td>2</td> +// HTML-INDEX: </tr> +// HTML-INDEX: <tr> +// HTML-INDEX: <td>MinSizeRel</td> +// HTML-INDEX: <td>3</td> +// HTML-INDEX: </tr> +// HTML-INDEX: </tbody> +// HTML-INDEX: </table> _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
