Skip to content

Commit 75611fc

Browse files
committed
feat: extra javadoc and HTML tags
1 parent be25522 commit 75611fc

File tree

4 files changed

+527
-135
lines changed

4 files changed

+527
-135
lines changed

include/mrdocs/Metadata/Javadoc.hpp

Lines changed: 142 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,29 @@
2727
namespace clang {
2828
namespace mrdocs {
2929

30-
// This namespace contains all of the Javadoc
31-
// related types, constants, and functions.
30+
/** Javadoc related types and functions.
31+
32+
Javadoc is a documentation generator originally
33+
created for the Java language from source code.
34+
35+
The Javadoc documentation generator tool can interpret
36+
text in the "doc comments" format included
37+
directly in the source code.
38+
39+
The same "doc comments" format has been replicated
40+
and extended by documentation systems for other
41+
languages, including the cross-language Doxygen
42+
and the JSDoc system for JavaScript.
43+
44+
Because Clang can already parse and extract
45+
blocks of Javadoc-style comments from source
46+
code, these classes are used to represent the
47+
parsed documentation in a structured form.
48+
49+
@see https://en.wikipedia.org/wiki/Javadoc
50+
@see https://www.doxygen.nl
51+
52+
*/
3253
namespace doc {
3354

3455
struct Node;
@@ -39,6 +60,46 @@ template<typename T>
3960
requires std::derived_from<T, doc::Node>
4061
using List = std::vector<std::unique_ptr<T>>;
4162

63+
/** The kind of a node.
64+
65+
This includes tags and block types.
66+
67+
Some of the available tags are:
68+
69+
@li `@author Author Name`
70+
@li `{@docRoot}`
71+
@li `@version version`
72+
@li `@since since-text `
73+
@li `@see reference`
74+
@li `@param name description`
75+
@li `@return description`
76+
@li `@exception classname description`
77+
@li `@throws classname description`
78+
@li `@deprecated description`
79+
@li `{@inheritDoc}`
80+
@li `{@link reference}`
81+
@li `{@linkplain reference}`
82+
@li `{@value #STATIC_FIELD}`
83+
@li `{@code literal}`
84+
@li `{@literal literal}`
85+
@li `{@serial literal}`
86+
@li `{@serialData literal}`
87+
@li `{@serialField literal}`
88+
89+
Doxygen also introduces a number of additional tags on top
90+
of the the doc comment specification.
91+
92+
@see https://en.wikipedia.org/wiki/Javadoc[Javadoc - Wikipedia]
93+
@see https://docs.oracle.com/javase/1.5.0/docs/tooldocs/solaris/javadoc.html[Javadoc Documentation]
94+
@see https://docs.oracle.com/en/java/javase/13/docs/specs/javadoc/doc-comment-spec.html[Doc Comment Specification]
95+
@see https://www.oracle.com/java/technologies/javase/javadoc-tool.html[Javadoc Tool]
96+
@see https://www.oracle.com/technical-resources/articles/java/javadoc-tool.html[How to Write Doc Comments]
97+
@see https://docs.oracle.com/javase/8/docs/technotes/tools/unix/javadoc.html[Javadoc Package]
98+
@see https://web.archive.org/web/20170714215721/http://agile.csc.ncsu.edu:80/SEMaterials/tutorials/javadoc[Javadoc Tutorial]
99+
@see https://en.wikipedia.org/wiki/Doxygen[Doxygen - Wikipedia]
100+
@see https://www.doxygen.nl/manual/commands.html[Doxygen Special Tags]
101+
102+
*/
42103
enum class Kind
43104
{
44105
// VFALCO Don't forget to update
@@ -59,7 +120,9 @@ enum class Kind
59120
tparam,
60121
reference,
61122
copied,
62-
throws
123+
throws,
124+
details,
125+
see
63126
};
64127

65128
/** A text style.
@@ -163,7 +226,7 @@ struct Text : Node
163226
{
164227
}
165228

166-
bool isBlock() const noexcept final override
229+
bool isBlock() const noexcept final
167230
{
168231
return false;
169232
}
@@ -305,7 +368,7 @@ struct MRDOCS_DECL
305368
{
306369
List<Text> children;
307370

308-
bool isBlock() const noexcept final override
371+
bool isBlock() const noexcept final
309372
{
310373
return true;
311374
}
@@ -337,7 +400,7 @@ struct MRDOCS_DECL
337400
T& emplace_back(T&& text)
338401
{
339402
return static_cast<T&>(emplace_back(
340-
std::make_unique<T>(std::move(text))));
403+
std::make_unique<T>(std::forward<T>(text))));
341404
}
342405

343406
void append(List<Node>&& blocks);
@@ -427,6 +490,10 @@ struct Brief : Paragraph
427490
};
428491

429492
/** An admonition.
493+
494+
This paragraph represents an admonition, such as
495+
a note, tip, important, caution, or warning.
496+
430497
*/
431498
struct Admonition : Paragraph
432499
{
@@ -452,7 +519,7 @@ struct Admonition : Paragraph
452519
*/
453520
struct Code : Paragraph
454521
{
455-
// VFALCO we can add a language (e.g. C++),
522+
// VFALCO we can add a language (e.g., C++),
456523
// then emit attributes in the generator.
457524

458525
static constexpr Kind static_kind = Kind::code;
@@ -491,6 +558,48 @@ struct ListItem : Paragraph
491558
}
492559
};
493560

561+
/** A @details paragraph
562+
*/
563+
struct Details : Paragraph
564+
{
565+
static constexpr Kind static_kind = Kind::details;
566+
567+
Details()
568+
: Paragraph(Kind::details)
569+
{
570+
}
571+
572+
bool operator==(const Details&)
573+
const noexcept = default;
574+
575+
bool equals(const Node& other) const noexcept override
576+
{
577+
return kind == other.kind &&
578+
*this == static_cast<const Details&>(other);
579+
}
580+
};
581+
582+
/** A @see paragraph
583+
*/
584+
struct See : Paragraph
585+
{
586+
static constexpr Kind static_kind = Kind::see;
587+
588+
See()
589+
: Paragraph(Kind::see)
590+
{
591+
}
592+
593+
bool operator==(const See&)
594+
const noexcept = default;
595+
596+
bool equals(const Node& other) const noexcept override
597+
{
598+
return kind == other.kind &&
599+
*this == static_cast<const See&>(other);
600+
}
601+
};
602+
494603
/** Documentation for a function parameter
495604
*/
496605
struct Param : Paragraph
@@ -543,6 +652,7 @@ struct Returns : Paragraph
543652
*this == static_cast<const Returns&>(other);
544653
}
545654
};
655+
546656
/** Documentation for a template parameter
547657
*/
548658
struct TParam : Paragraph
@@ -594,6 +704,8 @@ struct Throws : Paragraph
594704

595705
//------------------------------------------------
596706

707+
/** A visitor for node types.
708+
*/
597709
template<class F, class... Args>
598710
constexpr
599711
auto
@@ -633,11 +745,21 @@ visit(
633745
return f.template operator()<TParam>(std::forward<Args>(args)...);
634746
case Kind::throws:
635747
return f.template operator()<Throws>(std::forward<Args>(args)...);
748+
case Kind::details:
749+
return f.template operator()<Details>(std::forward<Args>(args)...);
750+
case Kind::see:
751+
return f.template operator()<See>(std::forward<Args>(args)...);
636752
default:
637753
return f.template operator()<void>(std::forward<Args>(args)...);
638754
}
639755
}
640756

757+
/** Visit a node.
758+
759+
@param node The node to visit.
760+
@param f The function to call for each node.
761+
@param args Additional arguments to pass to the function.
762+
*/
641763
template<
642764
class NodeTy,
643765
class Fn,
@@ -684,11 +806,21 @@ visit(
684806
return visitor.template visit<TParam>();
685807
case Kind::throws:
686808
return visitor.template visit<Throws>();
809+
case Kind::details:
810+
return visitor.template visit<Details>();
811+
case Kind::see:
812+
return visitor.template visit<See>();
687813
default:
688814
MRDOCS_UNREACHABLE();
689815
}
690816
}
691817

818+
/** Traverse a list of nodes.
819+
820+
@param list The list of nodes to traverse.
821+
@param f The function to call for each node.
822+
@param args Additional arguments to pass to the function.
823+
*/
692824
template<class F, class T, class... Args>
693825
requires std::derived_from<T, Node>
694826
void traverse(
@@ -810,13 +942,15 @@ class MRDOCS_DECL
810942
std::string
811943
emplace_back(T&& block)
812944
{
813-
return emplace_back(std::make_unique<T>(std::move(block)));
945+
return emplace_back(std::make_unique<T>(std::forward<T>(block)));
814946
}
815947

816948
/** Append blocks from another javadoc to this.
817949
*/
818950
void append(Javadoc&& other);
819951

952+
/** Append blocks from a list to this.
953+
*/
820954
void append(doc::List<doc::Node>&& blocks);
821955

822956
private:

src/lib/AST/AnyBlock.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,12 @@ class JavadocNodesBlock
399399
case doc::Kind::throws:
400400
nodes.emplace_back(std::make_unique<doc::Throws>());
401401
break;
402+
case doc::Kind::details:
403+
nodes.emplace_back(std::make_unique<doc::Details>());
404+
break;
405+
case doc::Kind::see:
406+
nodes.emplace_back(std::make_unique<doc::See>());
407+
break;
402408
default:
403409
return formatError("unknown doc::Kind");
404410
}

0 commit comments

Comments
 (0)