llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang-tools-extra Author: Erick Velez (evelez7) <details> <summary>Changes</summary> Serializing an `Anonymous` field for enums 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. --- Full diff: https://github.com/llvm/llvm-project/pull/174265.diff 3 Files Affected: - (modified) clang-tools-extra/clang-doc/JSONGenerator.cpp (+6) - (modified) clang-tools-extra/clang-doc/assets/namespace-template.mustache (+4) - (modified) clang-tools-extra/test/clang-doc/enum.cpp (+34) ``````````diff 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> `````````` </details> https://github.com/llvm/llvm-project/pull/174265 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
