27
27
namespace clang {
28
28
namespace mrdocs {
29
29
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
+ */
32
53
namespace doc {
33
54
34
55
struct Node ;
@@ -39,6 +60,46 @@ template<typename T>
39
60
requires std::derived_from<T, doc::Node>
40
61
using List = std::vector<std::unique_ptr<T>>;
41
62
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
+ */
42
103
enum class Kind
43
104
{
44
105
// VFALCO Don't forget to update
@@ -59,7 +120,9 @@ enum class Kind
59
120
tparam,
60
121
reference,
61
122
copied,
62
- throws
123
+ throws,
124
+ details,
125
+ see
63
126
};
64
127
65
128
/* * A text style.
@@ -163,7 +226,7 @@ struct Text : Node
163
226
{
164
227
}
165
228
166
- bool isBlock () const noexcept final override
229
+ bool isBlock () const noexcept final
167
230
{
168
231
return false ;
169
232
}
@@ -305,7 +368,7 @@ struct MRDOCS_DECL
305
368
{
306
369
List<Text> children;
307
370
308
- bool isBlock () const noexcept final override
371
+ bool isBlock () const noexcept final
309
372
{
310
373
return true ;
311
374
}
@@ -337,7 +400,7 @@ struct MRDOCS_DECL
337
400
T& emplace_back (T&& text)
338
401
{
339
402
return static_cast <T&>(emplace_back (
340
- std::make_unique<T>(std::move (text))));
403
+ std::make_unique<T>(std::forward<T> (text))));
341
404
}
342
405
343
406
void append (List<Node>&& blocks);
@@ -427,6 +490,10 @@ struct Brief : Paragraph
427
490
};
428
491
429
492
/* * An admonition.
493
+
494
+ This paragraph represents an admonition, such as
495
+ a note, tip, important, caution, or warning.
496
+
430
497
*/
431
498
struct Admonition : Paragraph
432
499
{
@@ -452,7 +519,7 @@ struct Admonition : Paragraph
452
519
*/
453
520
struct Code : Paragraph
454
521
{
455
- // VFALCO we can add a language (e.g. C++),
522
+ // VFALCO we can add a language (e.g., C++),
456
523
// then emit attributes in the generator.
457
524
458
525
static constexpr Kind static_kind = Kind::code;
@@ -491,6 +558,48 @@ struct ListItem : Paragraph
491
558
}
492
559
};
493
560
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
+
494
603
/* * Documentation for a function parameter
495
604
*/
496
605
struct Param : Paragraph
@@ -543,6 +652,7 @@ struct Returns : Paragraph
543
652
*this == static_cast <const Returns&>(other);
544
653
}
545
654
};
655
+
546
656
/* * Documentation for a template parameter
547
657
*/
548
658
struct TParam : Paragraph
@@ -594,6 +704,8 @@ struct Throws : Paragraph
594
704
595
705
// ------------------------------------------------
596
706
707
+ /* * A visitor for node types.
708
+ */
597
709
template <class F , class ... Args>
598
710
constexpr
599
711
auto
@@ -633,11 +745,21 @@ visit(
633
745
return f.template operator ()<TParam>(std::forward<Args>(args)...);
634
746
case Kind::throws:
635
747
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)...);
636
752
default :
637
753
return f.template operator ()<void >(std::forward<Args>(args)...);
638
754
}
639
755
}
640
756
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
+ */
641
763
template <
642
764
class NodeTy ,
643
765
class Fn ,
@@ -684,11 +806,21 @@ visit(
684
806
return visitor.template visit <TParam>();
685
807
case Kind::throws:
686
808
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>();
687
813
default :
688
814
MRDOCS_UNREACHABLE ();
689
815
}
690
816
}
691
817
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
+ */
692
824
template <class F , class T , class ... Args>
693
825
requires std::derived_from<T, Node>
694
826
void traverse (
@@ -810,13 +942,15 @@ class MRDOCS_DECL
810
942
std::string
811
943
emplace_back (T&& block)
812
944
{
813
- return emplace_back (std::make_unique<T>(std::move (block)));
945
+ return emplace_back (std::make_unique<T>(std::forward<T> (block)));
814
946
}
815
947
816
948
/* * Append blocks from another javadoc to this.
817
949
*/
818
950
void append (Javadoc&& other);
819
951
952
+ /* * Append blocks from a list to this.
953
+ */
820
954
void append (doc::List<doc::Node>&& blocks);
821
955
822
956
private:
0 commit comments