Skip to content

Conversation

@evelez7
Copy link
Member

@evelez7 evelez7 commented Jul 25, 2025

Serialize throw Doxygen comments for exceptions. Accepts both \throw and
\throws.

Copy link
Member Author

evelez7 commented Jul 25, 2025

@llvmbot
Copy link
Member

llvmbot commented Jul 25, 2025

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

Author: Erick Velez (evelez7)

Changes

Serialize throw Doxygen comments for exceptions. Accepts both \throw and
\throws.


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

2 Files Affected:

  • (modified) clang-tools-extra/clang-doc/JSONGenerator.cpp (+7)
  • (modified) clang-tools-extra/clang-doc/assets/comment-template.mustache (+8)
diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp
index 599b381cea60d..2db6451259f60 100644
--- a/clang-tools-extra/clang-doc/JSONGenerator.cpp
+++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp
@@ -140,6 +140,13 @@ static Object serializeComment(const CommentInfo &I, Object &Description) {
       insertComment(Description, TextCommentsArray, "BriefComments");
     else if (I.Name == "return")
       insertComment(Description, TextCommentsArray, "ReturnComments");
+    else if (I.Name == "throws" || I.Name == "throw") {
+      json::Value ThrowsVal = Object();
+      auto &ThrowsObj = *ThrowsVal.getAsObject();
+      ThrowsObj["Exception"] = I.Args.front();
+      ThrowsObj["Children"] = TextCommentsArray;
+      insertComment(Description, ThrowsVal, "ThrowsComments");
+    }
     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 4e38e5fb92d18..60a4c70ec0dc4 100644
--- a/clang-tools-extra/clang-doc/assets/comment-template.mustache
+++ b/clang-tools-extra/clang-doc/assets/comment-template.mustache
@@ -54,6 +54,14 @@
     </div>
     {{/CodeComments}}
 {{/HasCodeComments}}
+{{#HasThrowsComments}}
+    <h3>Throws</h3>
+    {{#ThrowsComments}}
+    <div>
+        <b>{{ThrowName}}</b> {{#Children}}{{>Comments}}{{/Children}}
+    </div>
+    {{/ThrowsComments}}
+{{/HasThrowsComments}}
 {{#BlockCommandComment}}
     <div class="block-command-comment__command">
         <div class="block-command-command">

@evelez7 evelez7 marked this pull request as draft July 25, 2025 17:19
@evelez7 evelez7 force-pushed the users/evelez7/clang-doc-throws-comments branch from 26f70f8 to e736a45 Compare July 25, 2025 17:25
@evelez7 evelez7 marked this pull request as ready for review July 25, 2025 17:38
@evelez7 evelez7 requested review from ilovepi and petrhosek July 25, 2025 17:38
@evelez7 evelez7 force-pushed the users/evelez7/clang-doc-code-comments branch from 9543783 to 7d6c38c Compare July 25, 2025 17:43
@evelez7 evelez7 force-pushed the users/evelez7/clang-doc-throws-comments branch from e736a45 to ff3d3ad Compare July 25, 2025 17:44
@evelez7 evelez7 force-pushed the users/evelez7/clang-doc-code-comments branch from 7d6c38c to e8795d0 Compare July 25, 2025 18:18
@evelez7 evelez7 force-pushed the users/evelez7/clang-doc-throws-comments branch from ff3d3ad to eb95d56 Compare July 25, 2025 18:19
@evelez7 evelez7 force-pushed the users/evelez7/clang-doc-code-comments branch 3 times, most recently from 1ef0736 to 3dbfb45 Compare July 25, 2025 20:05
@evelez7 evelez7 force-pushed the users/evelez7/clang-doc-code-comments branch from 3dbfb45 to 9c3d458 Compare July 25, 2025 20:08
Base automatically changed from users/evelez7/clang-doc-code-comments to main July 25, 2025 20:10
Serialize throw Doxygen comments for exceptions. Accepts both \throw and
\throws.
@evelez7 evelez7 force-pushed the users/evelez7/clang-doc-throws-comments branch from eb95d56 to 35762dd Compare July 25, 2025 20:13
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.

5 participants