|
12 | 12 | #ifndef MRDOX_META_JAVADOC_HPP
|
13 | 13 | #define MRDOX_META_JAVADOC_HPP
|
14 | 14 |
|
| 15 | +#include <mrdox/meta/List.hpp> |
15 | 16 | #include <llvm/ADT/SmallString.h>
|
16 | 17 | #include <string>
|
| 18 | +#include <utility> |
17 | 19 |
|
18 | 20 | namespace clang {
|
19 | 21 | namespace mrdox {
|
@@ -61,18 +63,151 @@ struct CommentInfo
|
61 | 63 | std::vector<std::unique_ptr<CommentInfo>> Children; // List of child comments for this CommentInfo.
|
62 | 64 | };
|
63 | 65 |
|
64 |
| -/** A complete javadoc attached to a declaration |
| 66 | +//------------------------------------------------ |
| 67 | + |
| 68 | +/** A processed Javadoc-style comment attached to a declaration. |
65 | 69 | */
|
66 | 70 | struct Javadoc
|
67 | 71 | {
|
68 |
| - /** The brief description. |
| 72 | + using String = std::string; |
| 73 | + |
| 74 | + enum class Kind |
| 75 | + { |
| 76 | + text, |
| 77 | + code, |
| 78 | + styledText, |
| 79 | + paragraph |
| 80 | + }; |
| 81 | + |
| 82 | + /** This is a variant-like list element. |
| 83 | + */ |
| 84 | + struct Node |
| 85 | + { |
| 86 | + Kind const kind; |
| 87 | + |
| 88 | + explicit Node(Kind kind_) noexcept |
| 89 | + : kind(kind_) |
| 90 | + { |
| 91 | + } |
| 92 | + }; |
| 93 | + |
| 94 | + /** A string of plain text. |
69 | 95 | */
|
| 96 | + struct Text : Node |
| 97 | + { |
| 98 | + String text; |
| 99 | + |
| 100 | + explicit |
| 101 | + Text( |
| 102 | + String text_, |
| 103 | + Kind kind_ = Kind::text) |
| 104 | + : Node(kind_) |
| 105 | + , text(std::move(text)) |
| 106 | + { |
| 107 | + } |
| 108 | + }; |
| 109 | + |
| 110 | + /** A string of plain text representing source code. |
| 111 | + */ |
| 112 | + struct Code : Text |
| 113 | + { |
| 114 | + // VFALCO this can have a language (e.g. C++), |
| 115 | + // and we can emit attributes in the generator. |
| 116 | + |
| 117 | + explicit |
| 118 | + Code( |
| 119 | + String text_) |
| 120 | + : Text(std::move(text_), Kind::code) |
| 121 | + { |
| 122 | + } |
| 123 | + }; |
| 124 | + |
| 125 | + /** A text style. |
| 126 | + */ |
| 127 | + enum class Style |
| 128 | + { |
| 129 | + mono, |
| 130 | + bold, |
| 131 | + italic |
| 132 | + }; |
| 133 | + |
| 134 | + /** A piece of style text. |
| 135 | + */ |
| 136 | + struct StyledText : Text |
| 137 | + { |
| 138 | + Style style; |
| 139 | + |
| 140 | + StyledText( |
| 141 | + String text, |
| 142 | + Style style_) |
| 143 | + : Text(std::move(text), Kind::styledText) |
| 144 | + , style(style_) |
| 145 | + { |
| 146 | + } |
| 147 | + }; |
| 148 | + |
| 149 | + /** A sequence of text nodes. |
| 150 | + */ |
| 151 | + struct Paragraph : Node |
| 152 | + { |
| 153 | + Paragraph() |
| 154 | + : Node(Kind::paragraph) |
| 155 | + { |
| 156 | + } |
| 157 | + |
| 158 | + List<Text> list; |
| 159 | + }; |
| 160 | + |
| 161 | + // VFALCO LEGACY |
70 | 162 | llvm::SmallString<32> brief;
|
| 163 | + std::string desc; |
| 164 | + |
| 165 | + //--- |
| 166 | + |
| 167 | + ~Javadoc() |
| 168 | + { |
| 169 | + if(brief_) |
| 170 | + delete brief_; |
| 171 | + } |
| 172 | + |
| 173 | + Javadoc() = default; |
71 | 174 |
|
72 |
| - /** The detailed description. |
| 175 | + Paragraph const* |
| 176 | + getBrief() const noexcept |
| 177 | + { |
| 178 | + return brief_; |
| 179 | + } |
| 180 | + |
| 181 | + List<Node> const& |
| 182 | + getNodes() const noexcept |
| 183 | + { |
| 184 | + return list_; |
| 185 | + } |
| 186 | + |
| 187 | + /** Append a node to the documentation comment., |
73 | 188 | */
|
74 |
| - //llvm::SmallString<32> desc; // asciidoc |
75 |
| - std::string desc; // asciidoc |
| 189 | + template<class Child> |
| 190 | + void |
| 191 | + append(Child&& node) |
| 192 | + { |
| 193 | + static_assert(std::is_base_of<Node, Child>); |
| 194 | + |
| 195 | + list_.emplace_back<Child>(std::forward<Child>(node)); |
| 196 | + } |
| 197 | + |
| 198 | + /** Append a brief to the documentation comment., |
| 199 | + */ |
| 200 | + void |
| 201 | + append_brief(Paragraph&& paragraph) |
| 202 | + { |
| 203 | + assert(brief_ == nullptr); |
| 204 | + brief_ = new Paragraph(std::move(paragraph)); |
| 205 | + } |
| 206 | + |
| 207 | +private: |
| 208 | + List<Node> list_; |
| 209 | + |
| 210 | + Paragraph const* brief_ = nullptr; |
76 | 211 | };
|
77 | 212 |
|
78 | 213 | } // mrdox
|
|
0 commit comments