Skip to content

Commit

Permalink
support throw symbols
Browse files Browse the repository at this point in the history
#feat
  • Loading branch information
alandefreitas committed Jan 3, 2025
1 parent 741047c commit 4a28558
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 32 deletions.
2 changes: 1 addition & 1 deletion include/mrdocs/Metadata/Javadoc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ struct TParam : Paragraph
*/
struct Throws : Paragraph
{
String exception;
Reference exception;

static constexpr Kind static_kind = Kind::throws;

Expand Down
26 changes: 6 additions & 20 deletions src/lib/AST/ParseJavadoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Gen/hbs/HandlebarsCorpus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions test-files/golden-tests/core/libcxx.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.


|===
Expand Down
4 changes: 2 additions & 2 deletions test-files/golden-tests/core/libcxx.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ <h3>Exceptions</h3>
</thead>
<tbody>
<tr>
<td><code>if</code></td>
<td><p><span>the input value is negative.</span></p>
<td><code>std::invalid_argument</code></td>
<td><p><span>if the input value is negative.</span></p>
</td>
</tr>
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion test-files/golden-tests/core/libcxx.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<text>This function calculates the square root of a given integral value using bit manipulation.</text>
</para>
<throws>
<text>the input value is negative.</text>
<text>if the input value is negative.</text>
</throws>
<tparam name="T">
<text>The type of the input value. Must be an integral type. </text>
Expand Down
54 changes: 54 additions & 0 deletions test-files/golden-tests/javadoc/throw.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
= Reference
:mrdocs:

[#index]
== Global namespace


=== Functions

[cols=2]
|===
| Name | Description

| <<f,`f`>>
| brief



|===

[#f]
== f


brief



=== Synopsis


Declared in `&lt;throw&period;cpp&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
void
f();
----

=== Exceptions


|===
| Name | Thrown on

| `std&colon;&colon;length&lowbar;error`
| `dest&lowbar;size &lt; ipv4&lowbar;address&colon;&colon;max&lowbar;str&lowbar;len`


|===



[.small]#Created with https://www.mrdocs.com[MrDocs]#
5 changes: 5 additions & 0 deletions test-files/golden-tests/javadoc/throw.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** brief
@throw std::length_error `dest_size < ipv4_address::max_str_len`
*/
void f();
19 changes: 19 additions & 0 deletions test-files/golden-tests/metadata/overloads.cpp
Original file line number Diff line number Diff line change
@@ -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);

4 changes: 2 additions & 2 deletions test-files/golden-tests/snippets/sqrt.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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&period;
| `std&colon;&colon;invalid&lowbar;argument`
| if the input value is negative&period;


|===
Expand Down
4 changes: 2 additions & 2 deletions test-files/golden-tests/snippets/sqrt.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ <h3>Exceptions</h3>
</thead>
<tbody>
<tr>
<td><code>if</code></td>
<td><p><span>the input value is negative.</span></p>
<td><code>std::invalid_argument</code></td>
<td><p><span>if the input value is negative.</span></p>
</td>
</tr>
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion test-files/golden-tests/snippets/sqrt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<text>This function calculates the square root of a given integral value using bit manipulation.</text>
</para>
<throws>
<text>the input value is negative.</text>
<text>if the input value is negative.</text>
</throws>
<tparam name="T">
<text>The type of the input value. Must be an integral type. </text>
Expand Down

0 comments on commit 4a28558

Please sign in to comment.