https://github.com/SamrudhNelli updated 
https://github.com/llvm/llvm-project/pull/183085

>From 7e5abbeac7c100a07854af63402fcdaae740fa1e Mon Sep 17 00:00:00 2001
From: Samrudh Nelli <[email protected]>
Date: Tue, 24 Feb 2026 21:10:19 +0530
Subject: [PATCH 1/2] [Clang-doc] Display enum comments and member values in
 html/md

---
 clang-tools-extra/clang-doc/JSONGenerator.cpp | 16 ++++++++++
 clang-tools-extra/clang-doc/MDGenerator.cpp   | 30 +++++++++++++++++--
 .../clang-doc/assets/enum-template.mustache   |  2 ++
 3 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp 
b/clang-tools-extra/clang-doc/JSONGenerator.cpp
index 5051e7e6e690d..65a9a6bb94e04 100644
--- a/clang-tools-extra/clang-doc/JSONGenerator.cpp
+++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp
@@ -554,6 +554,22 @@ static void serializeInfo(const EnumValueInfo &I, Object 
&Obj) {
     Obj["ValueExpr"] = I.ValueExpr;
   else
     Obj["Value"] = I.Value;
+  if (!I.Description.empty()) {
+    json::Value CommentsArray = Array();
+    auto &CommentsArrayRef = *CommentsArray.getAsArray();
+    Object TempObj, ChildJson;
+    for (const auto &Child : I.Description) {
+      for (const auto &CI : Child.Children) {
+        ChildJson = serializeComment(*CI, TempObj);
+        if (!ChildJson.empty()) {
+          CommentsArrayRef.push_back(std::move(ChildJson));
+        }
+      }
+    }
+    if (!CommentsArrayRef.empty()) {
+      Obj["Description"] = CommentsArray;
+    }
+  }
 }
 
 static void serializeInfo(const EnumInfo &I, json::Object &Obj,
diff --git a/clang-tools-extra/clang-doc/MDGenerator.cpp 
b/clang-tools-extra/clang-doc/MDGenerator.cpp
index fcb75af80f9e9..7c01ae820b286 100644
--- a/clang-tools-extra/clang-doc/MDGenerator.cpp
+++ b/clang-tools-extra/clang-doc/MDGenerator.cpp
@@ -67,6 +67,23 @@ static void writeSourceFileRef(const ClangDocContext &CDCtx, 
const Location &L,
   OS << "\n\n";
 }
 
+static std::string genRawText(const std::vector<CommentInfo> &Comments) {
+  std::string Result;
+  std::queue<const CommentInfo *> Q;
+  for (const auto &CI : Comments)
+    Q.push(&CI);
+  const CommentInfo *Comment;
+  while (Q.size()) {
+    Comment = Q.front();
+    Q.pop();
+    if (!Comment->Text.empty())
+      Result += Comment->Text;
+    for (const auto &CI : Comment->Children)
+      Q.push(CI.get());
+  }
+  return Result;
+}
+
 static void maybeWriteSourceFileRef(llvm::raw_ostream &OS,
                                     const ClangDocContext &CDCtx,
                                     const std::optional<Location> &DefLoc) {
@@ -162,11 +179,20 @@ static void genMarkdown(const ClangDocContext &CDCtx, 
const EnumInfo &I,
     writeLine("| enum " + I.Name + " |", OS);
   writeLine("--", OS);
 
+  OS << "| Name | Value | Comments |\n\n";
   std::string Buffer;
   llvm::raw_string_ostream Members(Buffer);
   if (!I.Members.empty())
-    for (const auto &N : I.Members)
-      Members << "| " << N.Name << " |\n";
+    for (const auto &N : I.Members) {
+      Members << "| " << N.Name << " ";
+      if (!N.Value.empty())
+        Members << "| " << N.Value << " ";
+      std::string RawComment = genRawText(N.Description);
+      RawComment.erase(0, RawComment.find_first_not_of(" \t\r\n"));
+      RawComment.erase(RawComment.find_last_not_of(" \t\r\n") + 1);
+      Members << "| " << (RawComment.empty() ? "--" : RawComment) << " ";
+      Members << "|\n";
+    }
   writeLine(Members.str(), OS);
 
   maybeWriteSourceFileRef(OS, CDCtx, I.DefLoc);
diff --git a/clang-tools-extra/clang-doc/assets/enum-template.mustache 
b/clang-tools-extra/clang-doc/assets/enum-template.mustache
index 7434b7bfce347..783aaf9d2193f 100644
--- a/clang-tools-extra/clang-doc/assets/enum-template.mustache
+++ b/clang-tools-extra/clang-doc/assets/enum-template.mustache
@@ -15,6 +15,7 @@
             <tr>
                 <th>Name</th>
                 <th>Value</th>
+                <th>Comments</th>
             </tr>
             {{#Members}}
             <tr>
@@ -26,6 +27,7 @@
                 {{^Value}}
                 <td>{{ValueExpr}}</td>
                 {{/Value}}
+                
<td>{{#Description}}{{>Comments}}{{/Description}}{{^Description}} -- 
{{/Description}}</td>
             </tr>
             {{/Members}}
         </tbody>

>From 213d9741b87e73a16d28203b28601b7d48653e52 Mon Sep 17 00:00:00 2001
From: Samrudh Nelli <[email protected]>
Date: Wed, 25 Feb 2026 16:32:53 +0530
Subject: [PATCH 2/2] display the comment column only if atleast any one member
 has comments

---
 clang-tools-extra/clang-doc/JSONGenerator.cpp | 24 +++++++++++++------
 clang-tools-extra/clang-doc/MDGenerator.cpp   | 22 +++++++++++++----
 .../clang-doc/assets/enum-template.mustache   |  4 ++--
 3 files changed, 36 insertions(+), 14 deletions(-)

diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp 
b/clang-tools-extra/clang-doc/JSONGenerator.cpp
index 65a9a6bb94e04..4acb2cfd4f4f1 100644
--- a/clang-tools-extra/clang-doc/JSONGenerator.cpp
+++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp
@@ -34,9 +34,10 @@ static void serializeInfo(const RecordInfo &I, Object &Obj,
 static void serializeReference(const Reference &Ref, Object &ReferenceObj);
 
 template <typename Container, typename SerializationFunc>
-static void serializeArray(const Container &Records, Object &Obj,
-                           const std::string &Key,
-                           SerializationFunc SerializeInfo);
+static void serializeArray(
+    const Container &Records, Object &Obj, const StringRef Key,
+    SerializationFunc SerializeInfo, const StringRef EndKey = "End",
+    function_ref<void(Object &)> UpdateJson = [](Object &Obj) {});
 
 // Convenience lambda to pass to serializeArray.
 // If a serializeInfo needs a RepositoryUrl, create a local lambda that 
captures
@@ -442,9 +443,9 @@ serializeCommonChildren(const ScopeChildren &Children, 
json::Object &Obj,
 }
 
 template <typename Container, typename SerializationFunc>
-static void serializeArray(const Container &Records, Object &Obj,
-                           const std::string &Key,
-                           SerializationFunc SerializeInfo) {
+static void serializeArray(const Container &Records, Object &Obj, StringRef 
Key,
+                           SerializationFunc SerializeInfo, StringRef EndKey,
+                           function_ref<void(Object &)> UpdateJson) {
   json::Value RecordsArray = Array();
   auto &RecordsArrayRef = *RecordsArray.getAsArray();
   RecordsArrayRef.reserve(Records.size());
@@ -457,6 +458,7 @@ static void serializeArray(const Container &Records, Object 
&Obj,
     RecordsArrayRef.push_back(ItemVal);
   }
   Obj[Key] = RecordsArray;
+  UpdateJson(Obj);
 }
 
 static void serializeInfo(const ConstraintInfo &I, Object &Obj) {
@@ -588,7 +590,15 @@ static void serializeInfo(const EnumInfo &I, json::Object 
&Obj,
   }
 
   if (!I.Members.empty())
-    serializeArray(I.Members, Obj, "Members", SerializeInfoLambda);
+    serializeArray(I.Members, Obj, "Members", SerializeInfoLambda, "End",
+                   [&I](Object &JsonObj) {
+                     for (const auto &Member : I.Members) {
+                       if (!Member.Description.empty()) {
+                         JsonObj["HasComments"] = true;
+                         break;
+                       }
+                     }
+                   });
 }
 
 static void
diff --git a/clang-tools-extra/clang-doc/MDGenerator.cpp 
b/clang-tools-extra/clang-doc/MDGenerator.cpp
index 7c01ae820b286..f1a8dbcc344c1 100644
--- a/clang-tools-extra/clang-doc/MDGenerator.cpp
+++ b/clang-tools-extra/clang-doc/MDGenerator.cpp
@@ -179,7 +179,17 @@ static void genMarkdown(const ClangDocContext &CDCtx, 
const EnumInfo &I,
     writeLine("| enum " + I.Name + " |", OS);
   writeLine("--", OS);
 
-  OS << "| Name | Value | Comments |\n\n";
+  OS << "| Name | Value |";
+  bool HasComments = false;
+  for (const auto &Member : I.Members) {
+    if (!Member.Description.empty()) {
+      HasComments = true;
+      break;
+    }
+  }
+  if (HasComments)
+    OS << " Comments |";
+  OS << "\n\n";
   std::string Buffer;
   llvm::raw_string_ostream Members(Buffer);
   if (!I.Members.empty())
@@ -187,10 +197,12 @@ static void genMarkdown(const ClangDocContext &CDCtx, 
const EnumInfo &I,
       Members << "| " << N.Name << " ";
       if (!N.Value.empty())
         Members << "| " << N.Value << " ";
-      std::string RawComment = genRawText(N.Description);
-      RawComment.erase(0, RawComment.find_first_not_of(" \t\r\n"));
-      RawComment.erase(RawComment.find_last_not_of(" \t\r\n") + 1);
-      Members << "| " << (RawComment.empty() ? "--" : RawComment) << " ";
+      if (HasComments) {
+        std::string RawComment = genRawText(N.Description);
+        RawComment.erase(0, RawComment.find_first_not_of(" \t\r\n"));
+        RawComment.erase(RawComment.find_last_not_of(" \t\r\n") + 1);
+        Members << "| " << (RawComment.empty() ? "--" : RawComment) << " ";
+      }
       Members << "|\n";
     }
   writeLine(Members.str(), OS);
diff --git a/clang-tools-extra/clang-doc/assets/enum-template.mustache 
b/clang-tools-extra/clang-doc/assets/enum-template.mustache
index 783aaf9d2193f..09e107c4850d2 100644
--- a/clang-tools-extra/clang-doc/assets/enum-template.mustache
+++ b/clang-tools-extra/clang-doc/assets/enum-template.mustache
@@ -15,7 +15,7 @@
             <tr>
                 <th>Name</th>
                 <th>Value</th>
-                <th>Comments</th>
+                {{#HasComments}}<th>Comments</th>{{/HasComments}}
             </tr>
             {{#Members}}
             <tr>
@@ -27,7 +27,7 @@
                 {{^Value}}
                 <td>{{ValueExpr}}</td>
                 {{/Value}}
-                
<td>{{#Description}}{{>Comments}}{{/Description}}{{^Description}} -- 
{{/Description}}</td>
+                
{{#HasComments}}<td>{{#Description}}{{>Comments}}{{/Description}}{{^Description}}
 -- {{/Description}}</td>{{/HasComments}}
             </tr>
             {{/Members}}
         </tbody>

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to