diff options
author | Erick Velez <erickvelez7@gmail.com> | 2025-07-24 22:10:51 -0700 |
---|---|---|
committer | Erick Velez <erickvelez7@gmail.com> | 2025-07-25 20:13:54 +0000 |
commit | 35762dd1ecd9a5544bbcc85ab83eb6706aaf6e10 (patch) | |
tree | adf65c096d0d9f56fb23302fea45ba63ffc01d70 | |
parent | 4df8f726087c68d6e654a76839c544b18e4ca70e (diff) | |
download | llvm-users/evelez7/clang-doc-throws-comments.zip llvm-users/evelez7/clang-doc-throws-comments.tar.gz llvm-users/evelez7/clang-doc-throws-comments.tar.bz2 |
[clang-doc] add throws comments to comment templateusers/evelez7/clang-doc-throws-comments
Serialize throw Doxygen comments for exceptions. Accepts both \throw and
\throws.
3 files changed, 19 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index 599b381..2db6451 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 4e38e5f..60a4c70 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"> 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 e2d9da6..8831739 100644 --- a/clang-tools-extra/test/clang-doc/basic-project.mustache.test +++ b/clang-tools-extra/test/clang-doc/basic-project.mustache.test @@ -384,6 +384,10 @@ HTML-CALC: </div> HTML-CALC: <h3>Returns</h3> HTML-CALC: <p> double The result of a / b.</p> HTML-CALC: <p></p> +HTML-CALC: <h3>Throws</h3> +HTML-CALC: <div> +HTML-CALC: <b></b> <div> +HTML-CALC: <p>if b is zero.</p> HTML-CALC: </div> HTML-CALC: </div> HTML-CALC: </div> |