From 4a28558fc1f1ae9d195d42e68074d3fae25393df Mon Sep 17 00:00:00 2001 From: alandefreitas Date: Fri, 3 Jan 2025 16:23:02 -0300 Subject: [PATCH] support throw symbols #feat --- include/mrdocs/Metadata/Javadoc.hpp | 2 +- src/lib/AST/ParseJavadoc.cpp | 26 +++------ src/lib/Gen/hbs/HandlebarsCorpus.cpp | 2 +- test-files/golden-tests/core/libcxx.adoc | 4 +- test-files/golden-tests/core/libcxx.html | 4 +- test-files/golden-tests/core/libcxx.xml | 2 +- test-files/golden-tests/javadoc/throw.adoc | 54 +++++++++++++++++++ test-files/golden-tests/javadoc/throw.cpp | 5 ++ .../golden-tests/metadata/overloads.cpp | 19 +++++++ test-files/golden-tests/snippets/sqrt.adoc | 4 +- test-files/golden-tests/snippets/sqrt.html | 4 +- test-files/golden-tests/snippets/sqrt.xml | 2 +- 12 files changed, 96 insertions(+), 32 deletions(-) create mode 100644 test-files/golden-tests/javadoc/throw.adoc create mode 100644 test-files/golden-tests/javadoc/throw.cpp create mode 100644 test-files/golden-tests/metadata/overloads.cpp diff --git a/include/mrdocs/Metadata/Javadoc.hpp b/include/mrdocs/Metadata/Javadoc.hpp index 0fd51a107..43da81c9e 100644 --- a/include/mrdocs/Metadata/Javadoc.hpp +++ b/include/mrdocs/Metadata/Javadoc.hpp @@ -683,7 +683,7 @@ struct TParam : Paragraph */ struct Throws : Paragraph { - String exception; + Reference exception; static constexpr Kind static_kind = Kind::throws; diff --git a/src/lib/AST/ParseJavadoc.cpp b/src/lib/AST/ParseJavadoc.cpp index 8cc75a274..12e57993c 100644 --- a/src/lib/AST/ParseJavadoc.cpp +++ b/src/lib/AST/ParseJavadoc.cpp @@ -1143,28 +1143,14 @@ visitBlockCommandComment( doc::Throws throws; auto scope = enterScope(throws); visitChildren(C->getParagraph()); - // KRYSTIAN NOTE: clang doesn't consider these commands - // to have any arguments, so we have to extract the exception - // type manually - if(! throws.children.empty()) + if (C->getNumArgs()) { - // string will start with a non-whitespace character - doc::String& text = - throws.children.front()->string; - constexpr char ws[] = " \t\n\v\f\r"; - const auto except_end = text.find_first_of(ws); - throws.exception = text.substr(0, except_end); - // find the start of the next word, ignoring whitespace - const auto word_start = - text.find_first_not_of(ws, except_end); - // if we ran out of string, remove this block - if(word_start == doc::String::npos) - throws.children.erase(throws.children.begin()); - // otherwise, trim the string to exclude the argument - else - text.erase(0, word_start); + throws.exception.string = C->getArgText(0); + } + else + { + throws.exception.string = "undefined"; } - jd_.emplace_back(std::move(throws)); return; } diff --git a/src/lib/Gen/hbs/HandlebarsCorpus.cpp b/src/lib/Gen/hbs/HandlebarsCorpus.cpp index ed8c08723..54ed35225 100644 --- a/src/lib/Gen/hbs/HandlebarsCorpus.cpp +++ b/src/lib/Gen/hbs/HandlebarsCorpus.cpp @@ -80,7 +80,7 @@ domCreate( const HandlebarsCorpus& corpus) { dom::Object::storage_type entries = { - { "exception", I.exception } + { "exception", I.exception.string } }; std::string s = corpus.toStringFn(corpus, I); if (!s.empty()) diff --git a/test-files/golden-tests/core/libcxx.adoc b/test-files/golden-tests/core/libcxx.adoc index f92d2fa4e..4f98fa960 100644 --- a/test-files/golden-tests/core/libcxx.adoc +++ b/test-files/golden-tests/core/libcxx.adoc @@ -64,8 +64,8 @@ This function calculates the square root of a given integral value using bit |=== | Name | Thrown on -| `if` -| the input value is negative. +| `std::invalid_argument` +| if the input value is negative. |=== diff --git a/test-files/golden-tests/core/libcxx.html b/test-files/golden-tests/core/libcxx.html index 1ed03ad8b..df50908d0 100644 --- a/test-files/golden-tests/core/libcxx.html +++ b/test-files/golden-tests/core/libcxx.html @@ -79,8 +79,8 @@

Exceptions

-if -

the input value is negative.

+std::invalid_argument +

if the input value is negative.

diff --git a/test-files/golden-tests/core/libcxx.xml b/test-files/golden-tests/core/libcxx.xml index 10a6d9695..c9ace632b 100644 --- a/test-files/golden-tests/core/libcxx.xml +++ b/test-files/golden-tests/core/libcxx.xml @@ -22,7 +22,7 @@ This function calculates the square root of a given integral value using bit manipulation. - the input value is negative. + if the input value is negative. The type of the input value. Must be an integral type. diff --git a/test-files/golden-tests/javadoc/throw.adoc b/test-files/golden-tests/javadoc/throw.adoc new file mode 100644 index 000000000..a71954e62 --- /dev/null +++ b/test-files/golden-tests/javadoc/throw.adoc @@ -0,0 +1,54 @@ += Reference +:mrdocs: + +[#index] +== Global namespace + + +=== Functions + +[cols=2] +|=== +| Name | Description + +| <> +| brief + + + +|=== + +[#f] +== f + + +brief + + + +=== Synopsis + + +Declared in `<throw.cpp>` + +[source,cpp,subs="verbatim,replacements,macros,-callouts"] +---- +void +f(); +---- + +=== Exceptions + + +|=== +| Name | Thrown on + +| `std::length_error` +| `dest_size < ipv4_address::max_str_len` + + +|=== + + + +[.small]#Created with https://www.mrdocs.com[MrDocs]# diff --git a/test-files/golden-tests/javadoc/throw.cpp b/test-files/golden-tests/javadoc/throw.cpp new file mode 100644 index 000000000..57f1de1e5 --- /dev/null +++ b/test-files/golden-tests/javadoc/throw.cpp @@ -0,0 +1,5 @@ +/** brief + + @throw std::length_error `dest_size < ipv4_address::max_str_len` + */ +void f(); diff --git a/test-files/golden-tests/metadata/overloads.cpp b/test-files/golden-tests/metadata/overloads.cpp new file mode 100644 index 000000000..578b0b0ef --- /dev/null +++ b/test-files/golden-tests/metadata/overloads.cpp @@ -0,0 +1,19 @@ +struct A { + void f(); + int f(int); + + static void g(); + static int g(int); + + friend bool operator==(A, A); + friend bool operator==(A, int); +}; + +void f(); +int f(int); + +struct B {}; + +bool operator==(B, B); +bool operator==(B, int); + diff --git a/test-files/golden-tests/snippets/sqrt.adoc b/test-files/golden-tests/snippets/sqrt.adoc index ab257e8e5..931d91fd1 100644 --- a/test-files/golden-tests/snippets/sqrt.adoc +++ b/test-files/golden-tests/snippets/sqrt.adoc @@ -64,8 +64,8 @@ This function calculates the square root of a given integral value using bit |=== | Name | Thrown on -| `if` -| the input value is negative. +| `std::invalid_argument` +| if the input value is negative. |=== diff --git a/test-files/golden-tests/snippets/sqrt.html b/test-files/golden-tests/snippets/sqrt.html index bea941490..464d9bbfc 100644 --- a/test-files/golden-tests/snippets/sqrt.html +++ b/test-files/golden-tests/snippets/sqrt.html @@ -79,8 +79,8 @@

Exceptions

-if -

the input value is negative.

+std::invalid_argument +

if the input value is negative.

diff --git a/test-files/golden-tests/snippets/sqrt.xml b/test-files/golden-tests/snippets/sqrt.xml index cb0db2e2e..6929d29b2 100644 --- a/test-files/golden-tests/snippets/sqrt.xml +++ b/test-files/golden-tests/snippets/sqrt.xml @@ -22,7 +22,7 @@ This function calculates the square root of a given integral value using bit manipulation. - the input value is negative. + if the input value is negative. The type of the input value. Must be an integral type.