Skip to content

Conversation

@evelez7
Copy link
Member

@evelez7 evelez7 commented Jan 7, 2026

Protected method tags already existed in the class template, but they didn't conform to the current JSON scheme.

@evelez7 evelez7 changed the title [clang-doc] Serialize protected methods in class template [clang-doc] Add protected methods to class template Jan 7, 2026
@evelez7 evelez7 requested review from ilovepi and petrhosek January 7, 2026 23:11
@evelez7 evelez7 marked this pull request as ready for review January 7, 2026 23:11
@llvmbot
Copy link
Member

llvmbot commented Jan 7, 2026

@llvm/pr-subscribers-clang-tools-extra

Author: Erick Velez (evelez7)

Changes

Protected method tags already existed in the class template, but they didn't conform to the current JSON scheme.


Full diff: https://github.com/llvm/llvm-project/pull/174884.diff

3 Files Affected:

  • (modified) clang-tools-extra/clang-doc/JSONGenerator.cpp (+1-1)
  • (modified) clang-tools-extra/clang-doc/assets/class-template.mustache (+16-18)
  • (modified) clang-tools-extra/test/clang-doc/json/class.cpp (+18)
diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp
index fab54591b8faa..ad76c40d49db8 100644
--- a/clang-tools-extra/clang-doc/JSONGenerator.cpp
+++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp
@@ -628,7 +628,7 @@ static void serializeInfo(const RecordInfo &I, json::Object &Obj,
     if (!PubFunctionsArrayRef.empty())
       insertArray(Obj, PubFunctionsArray, "PublicFunctions");
     if (!ProtFunctionsArrayRef.empty())
-      Obj["ProtectedFunctions"] = ProtFunctionsArray;
+      insertArray(Obj, ProtFunctionsArray, "ProtectedFunctions");
   }
 
   if (!I.Members.empty()) {
diff --git a/clang-tools-extra/clang-doc/assets/class-template.mustache b/clang-tools-extra/clang-doc/assets/class-template.mustache
index 19e6e6adf1b44..368fc0472b3ca 100644
--- a/clang-tools-extra/clang-doc/assets/class-template.mustache
+++ b/clang-tools-extra/clang-doc/assets/class-template.mustache
@@ -63,22 +63,22 @@
                         </details>
                     </li>
                     {{/HasPublicFunctions}}
-                    {{#ProtectedFunction}}
+                    {{#HasProtectedFunctions}}
                     <li>
                         <details open>
                             <summary class="sidebar-section">
-                                <a class="sidebar-item" href="#ProtectedFunction">Protected Method</a>
+                                <a class="sidebar-item" href="#ProtectedMethods">Protected Methods</a>
                             </summary>
                             <ul>
-                                {{#Obj}}
+                                {{#ProtectedFunctions}}
                                 <li class="sidebar-item-container">
-                                    <a class="sidebar-item" href="#{{ID}}">{{Name}}</a>
+                                    <a class="sidebar-item" href="#{{USR}}">{{Name}}</a>
                                 </li>
-                                {{/Obj}}
+                                {{/ProtectedFunctions}}
                             </ul>
                         </details>
                     </li>
-                    {{/ProtectedFunction}}
+                    {{/HasProtectedFunctions}}
                     {{#HasEnums}}
                     <li>
                         <details open>
@@ -198,18 +198,16 @@
                     {{/PublicFunctions}}
                 </section>
                 {{/PublicFunctions}}
-                {{#ProtectedFunction}}
-                <li class="sidebar-section">
-                    <a class="sidebar-item" href="#ProtectedFunction">Protected Method</a>
-                </li>
-                <ul>
-                    {{#Obj}}
-                    <li class="sidebar-item-container">
-                        <a class="sidebar-item" href="#{{ID}}">{{Name}}</a>
-                    </li>
-                    {{/Obj}}
-                </ul>
-                {{/ProtectedFunction}}
+                {{#HasProtectedFunctions}}
+                <section id="ProtectedMethods" class="section-container">
+                    <h2>Protected Methods</h2>
+                    <div>
+                        {{#PublicFunctions}}
+                        {{>FunctionPartial}}
+                        {{/PublicFunctions}}
+                    </div>
+                </section>
+                {{/HasProtectedFunctions}}
                 {{#HasEnums}}
                 <section id="Enums" class="section-container">
                     <h2>Enumerations</h2>
diff --git a/clang-tools-extra/test/clang-doc/json/class.cpp b/clang-tools-extra/test/clang-doc/json/class.cpp
index 6356aee14c16c..869c6635418ae 100644
--- a/clang-tools-extra/test/clang-doc/json/class.cpp
+++ b/clang-tools-extra/test/clang-doc/json/class.cpp
@@ -170,6 +170,7 @@ struct MyClass {
 // CHECK-NEXT:    "HasEnums": true,
 // CHECK-NEXT:    "HasFriends": true,
 // CHECK-NEXT:    "HasPrivateMembers": true,
+// CHECK-NEXT:    "HasProtectedFunctions": true,
 // CHECK-NEXT:    "HasProtectedMembers": true,
 // CHECK-NEXT:    "HasPublicFunctions": true,
 // CHECK-NEXT:    "HasPublicMembers": true,
@@ -329,6 +330,23 @@ struct MyClass {
 // HTML-NEXT:         </div>
 // HTML-NEXT:     </div>
 // HTML-NEXT: </section>
+// HTML:      <section id="ProtectedMethods" class="section-container">
+// HTML-NEXT:     <h2>Protected Methods</h2>
+// HTML-NEXT:     <div>
+// HTML-NEXT:         <div id="{{([0-9A-F]{40})}}" class="delimiter-container">
+// HTML-NEXT:                 <pre><code class="language-cpp code-clang-doc">int myMethod (int MyParam)</code></pre>
+// HTML-NEXT:                 <p>Defined at line  of file </p>
+// HTML-NEXT:         </div>
+// HTML-NEXT:         <div id="{{([0-9A-F]{40})}}" class="delimiter-container">
+// HTML-NEXT:                 <pre><code class="language-cpp code-clang-doc">void staticMethod ()</code></pre>
+// HTML-NEXT:                 <p>Defined at line  of file </p>
+// HTML-NEXT:         </div>
+// HTML-NEXT:         <div id="{{([0-9A-F]{40})}}" class="delimiter-container">
+// HTML-NEXT:                 <pre><code class="language-cpp code-clang-doc">const int &amp; getConst ()</code></pre>
+// HTML-NEXT:                 <p>Defined at line  of file </p>
+// HTML-NEXT:         </div>
+// HTML-NEXT:     </div>
+// HTML-NEXT: </section>
 // HTML:      <section id="Classes" class="section-container">
 // HTML-NEXT:     <h2>Inner Classes</h2>
 // HTML-NEXT:     <ul class="class-container">

Copy link
Member Author

evelez7 commented Jan 7, 2026

insertArray(Obj, PubFunctionsArray, "PublicFunctions");
if (!ProtFunctionsArrayRef.empty())
Obj["ProtectedFunctions"] = ProtFunctionsArray;
insertArray(Obj, ProtFunctionsArray, "ProtectedFunctions");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
insertArray(Obj, ProtFunctionsArray, "ProtectedFunctions");
insertArray(Obj, ProtFunctionsArray, "ProtectedMethods");

If we're touching this, maybe we should name these and the tags in the templates consistently? WDYT? I'm fine either way, and this is more a minor nit than something that should block landing. We can follow up later w/ a small cleanup.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah these names need to be cleaned up across the templates as well, but I've put it off to not make these patches unnecessarily large and to get the functionality out there first. I'm planning to followup on these soon.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good. When one of us gets a chance lets clean those up. Or file a bug and tag it good first issue? its a trivial thing to do for a new person, so maybe that's better?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already have a chore patch ready with it unfortunately. I can separate it out since it has a few more things that needed to be addressed like typos.

Base automatically changed from users/evelez7/clang-doc-protected-members to main January 8, 2026 06:11
@evelez7 evelez7 force-pushed the users/evelez7/clang-doc-protected-methods branch from 9f8ecf5 to 2aa48a0 Compare January 8, 2026 06:13
Copy link
Member Author

evelez7 commented Jan 9, 2026

Merge activity

  • Jan 9, 1:00 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jan 9, 1:01 AM UTC: @evelez7 merged this pull request with Graphite.

@evelez7 evelez7 merged commit 6de75a9 into main Jan 9, 2026
10 checks passed
@evelez7 evelez7 deleted the users/evelez7/clang-doc-protected-methods branch January 9, 2026 01:01
kshitijvp pushed a commit to kshitijvp/llvm-project that referenced this pull request Jan 9, 2026
Protected method tags already existed in the class template, but they didn't conform to the current JSON scheme.
Priyanshu3820 pushed a commit to Priyanshu3820/llvm-project that referenced this pull request Jan 18, 2026
Protected method tags already existed in the class template, but they didn't conform to the current JSON scheme.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants