[clang-tools-extra] 63c2b8a - [clang-doc] add return comments to comment template (#150647)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 25 12:32:07 PDT 2025
Author: Erick Velez
Date: 2025-07-25T12:32:04-07:00
New Revision: 63c2b8a5b35f552e00f5458307f04ce9a6f4cfff
URL: https://github.com/llvm/llvm-project/commit/63c2b8a5b35f552e00f5458307f04ce9a6f4cfff
DIFF: https://github.com/llvm/llvm-project/commit/63c2b8a5b35f552e00f5458307f04ce9a6f4cfff.diff
LOG: [clang-doc] add return comments to comment template (#150647)
Serialize return comments in HTML templates.
Added:
Modified:
clang-tools-extra/clang-doc/JSONGenerator.cpp
clang-tools-extra/clang-doc/assets/comment-template.mustache
clang-tools-extra/test/clang-doc/basic-project.mustache.test
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp
index 5fc28406ee870..cae1a686266c6 100644
--- a/clang-tools-extra/clang-doc/JSONGenerator.cpp
+++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp
@@ -126,6 +126,8 @@ static Object serializeComment(const CommentInfo &I, Object &Description) {
auto TextCommentsArray = extractTextComments(CARef.front().getAsObject());
if (I.Name == "brief")
insertComment(Description, TextCommentsArray, "BriefComments");
+ else if (I.Name == "return")
+ insertComment(Description, TextCommentsArray, "ReturnComments");
return Obj;
}
diff --git a/clang-tools-extra/clang-doc/assets/comment-template.mustache b/clang-tools-extra/clang-doc/assets/comment-template.mustache
index d55a53194ee5c..89c48d26278c0 100644
--- a/clang-tools-extra/clang-doc/assets/comment-template.mustache
+++ b/clang-tools-extra/clang-doc/assets/comment-template.mustache
@@ -32,6 +32,14 @@
</div>
{{/ParamComments}}
{{/HasParamComments}}
+{{#HasReturnComments}}
+ <h3>Returns</h3>
+ {{#ReturnComments}}
+ {{#.}}
+ <p>{{TextComment}}</p>
+ {{/.}}
+ {{/ReturnComments}}
+{{/HasReturnComments}}
{{#BlockCommandComment}}
<div class="block-command-comment__command">
<div class="block-command-command">
diff --git a/clang-tools-extra/test/clang-doc/basic-project.mustache.test b/clang-tools-extra/test/clang-doc/basic-project.mustache.test
index b55e0abe2cdef..2c87fe2533195 100644
--- a/clang-tools-extra/test/clang-doc/basic-project.mustache.test
+++ b/clang-tools-extra/test/clang-doc/basic-project.mustache.test
@@ -93,6 +93,8 @@ HTML-SHAPE: </div>
HTML-SHAPE: <div>
HTML-SHAPE: <p></p>
HTML-SHAPE: </div>
+HTML-SHAPE: <h3>Returns</h3>
+HTML-SHAPE: <p> double The area of the shape.</p>
HTML-SHAPE: </div>
HTML-SHAPE: </div>
HTML-SHAPE: </div>
@@ -113,6 +115,8 @@ HTML-SHAPE: </div>
HTML-SHAPE: <div>
HTML-SHAPE: <p></p>
HTML-SHAPE: </div>
+HTML-SHAPE: <h3>Returns</h3>
+HTML-SHAPE: <p> double The perimeter of the shape.</p>
HTML-SHAPE: </div>
HTML-SHAPE: </div>
HTML-SHAPE: </div>
@@ -277,6 +281,8 @@ HTML-CALC: <div>
HTML-CALC: <p></p>
HTML-CALC: </div>
HTML-CALC: </div>
+HTML-CALC: <h3>Returns</h3>
+HTML-CALC: <p> int The sum of a and b.</p>
HTML-CALC: </div>
HTML-CALC: </div>
HTML-CALC: </div>
@@ -297,6 +303,8 @@ HTML-CALC: </div>
HTML-CALC: <div>
HTML-CALC: <p></p>
HTML-CALC: </div>
+HTML-CALC: <h3>Returns</h3>
+HTML-CALC: <p> int The result of a - b.</p>
HTML-CALC: </div>
HTML-CALC: </div>
HTML-CALC: </div>
@@ -334,6 +342,8 @@ HTML-CALC: <div>
HTML-CALC: <p></p>
HTML-CALC: </div>
HTML-CALC: </div>
+HTML-CALC: <h3>Returns</h3>
+HTML-CALC: <p> int The product of a and b.</p>
HTML-CALC: </div>
HTML-CALC: </div>
HTML-CALC: </div>
@@ -371,6 +381,9 @@ HTML-CALC: <div>
HTML-CALC: <p></p>
HTML-CALC: </div>
HTML-CALC: </div>
+HTML-CALC: <h3>Returns</h3>
+HTML-CALC: <p> double The result of a / b.</p>
+HTML-CALC: <p></p>
HTML-CALC: </div>
HTML-CALC: </div>
HTML-CALC: </div>
@@ -408,6 +421,8 @@ HTML-CALC: <div>
HTML-CALC: <p></p>
HTML-CALC: </div>
HTML-CALC: </div>
+HTML-CALC: <h3>Returns</h3>
+HTML-CALC: <p> The result of a % b.</p>
HTML-CALC: </div>
HTML-CALC: </div>
HTML-CALC: </div>
@@ -541,6 +556,8 @@ HTML-RECTANGLE: </div>
HTML-RECTANGLE: <div>
HTML-RECTANGLE: <p></p>
HTML-RECTANGLE: </div>
+HTML-RECTANGLE: <h3>Returns</h3>
+HTML-RECTANGLE: <p> double The area of the rectangle.</p>
HTML-RECTANGLE: </div>
HTML-RECTANGLE: </div>
HTML-RECTANGLE: </div>
@@ -561,6 +578,8 @@ HTML-RECTANGLE: </div>
HTML-RECTANGLE: <div>
HTML-RECTANGLE: <p></p>
HTML-RECTANGLE: </div>
+HTML-RECTANGLE: <h3>Returns</h3>
+HTML-RECTANGLE: <p> double The perimeter of the rectangle.</p>
HTML-RECTANGLE: </div>
HTML-RECTANGLE: </div>
HTML-RECTANGLE: </div>
@@ -686,6 +705,8 @@ HTML-CIRCLE: </div>
HTML-CIRCLE: <div>
HTML-CIRCLE: <p></p>
HTML-CIRCLE: </div>
+HTML-CIRCLE: <h3>Returns</h3>
+HTML-CIRCLE: <p> double The area of the circle.</p>
HTML-CIRCLE: </div>
HTML-CIRCLE: </div>
HTML-CIRCLE: </div>
@@ -706,6 +727,8 @@ HTML-CIRCLE: </div>
HTML-CIRCLE: <div>
HTML-CIRCLE: <p></p>
HTML-CIRCLE: </div>
+HTML-CIRCLE: <h3>Returns</h3>
+HTML-CIRCLE: <p> double The perimeter of the circle.</p>
HTML-CIRCLE: </div>
HTML-CIRCLE: </div>
HTML-CIRCLE: </div>
More information about the cfe-commits
mailing list