Author: Erick Velez
Date: 2026-01-08T17:01:42-08:00
New Revision: 6de75a97c3861a27e173ed478712ebb26c72f793

URL: 
https://github.com/llvm/llvm-project/commit/6de75a97c3861a27e173ed478712ebb26c72f793
DIFF: 
https://github.com/llvm/llvm-project/commit/6de75a97c3861a27e173ed478712ebb26c72f793.diff

LOG: [clang-doc] Add protected methods to class template (#174884)

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

Added: 
    

Modified: 
    clang-tools-extra/clang-doc/JSONGenerator.cpp
    clang-tools-extra/clang-doc/assets/class-template.mustache
    clang-tools-extra/test/clang-doc/json/class.cpp

Removed: 
    


################################################################################
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..ef5a7572a3f48 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>
+                        {{#ProtectedFunctions}}
+                        {{>FunctionPartial}}
+                        {{/ProtectedFunctions}}
+                    </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..5c63aa5ec45ef 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,15 @@ 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 protectedMethod ()</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">


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

Reply via email to