[clang-tools-extra] [clang-doc] add support for enums comments in html generation (PR #101282)
Paul Kirth via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 12 16:18:45 PDT 2024
================
@@ -653,22 +695,38 @@ static std::vector<std::unique_ptr<TagNode>>
genHTML(const EnumInfo &I, const ClangDocContext &CDCtx) {
std::vector<std::unique_ptr<TagNode>> Out;
std::string EnumType = I.Scoped ? "enum class " : "enum ";
-
- Out.emplace_back(
- std::make_unique<TagNode>(HTMLTag::TAG_H3, EnumType + I.Name));
- Out.back()->Attributes.emplace_back("id",
- llvm::toHex(llvm::toStringRef(I.USR)));
+ // Determine if enum members have comments attached
+ bool HasComments =
+ std::any_of(I.Members.begin(), I.Members.end(),
+ [](const EnumValueInfo &M) { return M.Description.empty(); });
+ std::unique_ptr<TagNode> Table =
+ std::make_unique<TagNode>(HTMLTag::TAG_TABLE);
+ std::unique_ptr<TagNode> THead =
+ std::make_unique<TagNode>(HTMLTag::TAG_THEAD);
+ std::unique_ptr<TagNode> TRow = std::make_unique<TagNode>(HTMLTag::TAG_TR);
+ std::unique_ptr<TagNode> TD =
+ std::make_unique<TagNode>(HTMLTag::TAG_TH, EnumType + I.Name);
+ // Span 3 columns if enum has comments
+ TD->Attributes.emplace_back("colspan", HasComments ? "3" : "2");
+
+ Table->Attributes.emplace_back("id", llvm::toHex(llvm::toStringRef(I.USR)));
+ TRow->Children.emplace_back(std::move(TD));
+ THead->Children.emplace_back(std::move(TRow));
+ Table->Children.emplace_back(std::move(THead));
std::unique_ptr<TagNode> Node = genEnumMembersBlock(I.Members);
+
if (Node)
- Out.emplace_back(std::move(Node));
+ Table->Children.emplace_back(std::move(Node));
----------------
ilovepi wrote:
Can you combine the condition and decl for Node?
```suggestion
if(std::unique_ptr<TagNode> Node = genEnumMembersBlock(I.Members))
Table->Children.emplace_back(std::move(Node));
```
https://github.com/llvm/llvm-project/pull/101282
More information about the cfe-commits
mailing list