14
14
15
15
#include < mrdox/meta/List.hpp>
16
16
#include < llvm/ADT/SmallString.h>
17
+ #include < memory>
17
18
#include < string>
18
19
#include < utility>
19
20
@@ -76,14 +77,41 @@ struct Javadoc
76
77
text,
77
78
code,
78
79
styledText,
79
- paragraph
80
+ paragraph,
81
+ admonition,
82
+ returns,
83
+ param,
84
+ tparam
85
+ };
86
+
87
+ /* * A text style.
88
+ */
89
+ enum class Style
90
+ {
91
+ none,
92
+ mono,
93
+ bold,
94
+ italic
95
+ };
96
+
97
+ /* * An admonishment style.
98
+ */
99
+ enum class Admonish
100
+ {
101
+ note,
102
+ tip,
103
+ important,
104
+ caution,
105
+ warning
80
106
};
81
107
82
108
/* * This is a variant-like list element.
83
109
*/
84
110
struct Node
85
111
{
86
- Kind const kind;
112
+ Kind kind;
113
+
114
+ auto operator <=>(Node const &) const noexcept = default ;
87
115
88
116
explicit Node (Kind kind_) noexcept
89
117
: kind(kind_)
@@ -97,65 +125,166 @@ struct Javadoc
97
125
{
98
126
String text;
99
127
128
+ auto operator <=>(Text const &) const noexcept = default ;
129
+
100
130
explicit
131
+ Text (
132
+ String text_)
133
+ : Node(Kind::text)
134
+ , text(std::move(text_))
135
+ {
136
+ }
137
+
138
+ protected:
101
139
Text (
102
140
String text_,
103
- Kind kind_ = Kind::text )
141
+ Kind kind_)
104
142
: Node(kind_)
105
143
, text(std::move(text_))
106
144
{
107
145
}
108
146
};
109
147
110
- /* * A string of plain text representing source code.
148
+ /* * A piece of style text.
149
+ */
150
+ struct StyledText : Text
151
+ {
152
+ Style style;
153
+
154
+ auto operator <=>(StyledText const &) const noexcept = default ;
155
+
156
+ StyledText (
157
+ String text,
158
+ Style style_)
159
+ : Text(std::move(text), Kind::styledText)
160
+ , style(style_)
161
+ {
162
+ }
163
+ };
164
+
165
+ /* * A piece of block content
166
+
167
+ The top level is a list of blocks.
111
168
*/
112
- struct Code : Text
169
+ struct Block : Node
113
170
{
114
- // VFALCO this can have a language (e.g. C++),
115
- // and we can emit attributes in the generator.
171
+ auto operator <=>(Block const &) const noexcept = default ;
116
172
173
+ protected:
117
174
explicit
118
- Code (
119
- String text_)
120
- : Text(std::move(text_), Kind::code)
175
+ Block (Kind kind_) noexcept
176
+ : Node(kind_)
121
177
{
122
178
}
123
179
};
124
180
125
- /* * A text style .
181
+ /* * A sequence of text nodes .
126
182
*/
127
- enum class Style
183
+ struct Paragraph : Block
128
184
{
129
- mono,
130
- bold,
131
- italic
185
+ List<Text> list;
186
+
187
+ bool empty () const noexcept
188
+ {
189
+ return list.empty ();
190
+ }
191
+
192
+ auto operator <=>(Paragraph const &) const noexcept = default ;
193
+
194
+ Paragraph ()
195
+ : Block(Kind::paragraph)
196
+ {
197
+ }
198
+
199
+ protected:
200
+ explicit
201
+ Paragraph (Kind kind) noexcept
202
+ : Block(kind)
203
+ {
204
+ }
132
205
};
133
206
134
- /* * A piece of style text.
207
+ /* * Documentation for an admonition
135
208
*/
136
- struct StyledText : Text
209
+ struct Admonition : Paragraph
137
210
{
138
- Style style;
211
+ Admonish style;
139
212
140
- StyledText (
141
- String text,
142
- Style style_)
143
- : Text(std::move(text), Kind::styledText)
213
+ auto operator <=>(Admonition const &) const noexcept = default ;
214
+
215
+ explicit
216
+ Admonition (Admonish style_)
217
+ : Paragraph(Kind::admonition)
144
218
, style(style_)
145
219
{
146
220
}
147
221
};
148
222
149
- /* * A sequence of text nodes.
223
+ /* * Documentation for a function return type
150
224
*/
151
- struct Paragraph : Node
225
+ struct Returns : Paragraph
152
226
{
153
- Paragraph ()
154
- : Node(Kind::paragraph)
227
+ auto operator <=>(Returns const &) const noexcept = default ;
228
+
229
+ Returns ()
230
+ : Paragraph(Kind::returns)
231
+ {
232
+ }
233
+ };
234
+
235
+ /* * Documentation for a function parameter
236
+ */
237
+ struct Param : Block
238
+ {
239
+ String name;
240
+ Paragraph details;
241
+
242
+ auto operator <=>(Param const &) const noexcept = default ;
243
+
244
+ Param (
245
+ String name_,
246
+ Paragraph details_)
247
+ : Block(Kind::param)
248
+ , name(std::move(name_))
249
+ , details(std::move(details_))
250
+ {
251
+ }
252
+ };
253
+
254
+ /* * Documentation for a template parameter
255
+ */
256
+ struct TParam : Block
257
+ {
258
+ String name;
259
+ Paragraph details;
260
+
261
+ auto operator <=>(TParam const &) const noexcept = default ;
262
+
263
+ TParam (
264
+ String name_,
265
+ Paragraph details_)
266
+ : Block(Kind::param)
267
+ , name(std::move(name_))
268
+ , details(std::move(details_))
155
269
{
156
270
}
271
+ };
272
+
273
+ /* * Preformatted source code.
274
+ */
275
+ struct Code : Block
276
+ {
277
+ // VFALCO we can add a language (e.g. C++),
278
+ // then emit attributes in the generator.
157
279
158
280
List<Text> list;
281
+
282
+ auto operator <=>(Code const &) const noexcept = default ;
283
+
284
+ Code ()
285
+ : Block(Kind::code)
286
+ {
287
+ }
159
288
};
160
289
161
290
// VFALCO LEGACY
@@ -164,50 +293,82 @@ struct Javadoc
164
293
165
294
// ---
166
295
167
- ~Javadoc ()
296
+ Paragraph const &
297
+ getBrief () const noexcept
168
298
{
169
- if (brief_)
170
- delete brief_;
299
+ return *brief_;
171
300
}
172
301
173
- Javadoc () = default ;
302
+ List<Block> const &
303
+ getBlocks () const noexcept
304
+ {
305
+ return blocks_;
306
+ }
174
307
175
- Paragraph const *
176
- getBrief () const noexcept
308
+ Returns const &
309
+ getReturns () const noexcept
177
310
{
178
- return brief_ ;
311
+ return returns_ ;
179
312
}
180
313
181
- List<Node > const &
182
- getNodes () const noexcept
314
+ List<Param > const &
315
+ getParams () const noexcept
183
316
{
184
- return list_ ;
317
+ return params_ ;
185
318
}
186
319
320
+ List<TParam> const &
321
+ getTParams () const noexcept
322
+ {
323
+ return tparams_;
324
+ }
325
+
326
+ // ---
327
+
328
+ Javadoc () = default ;
329
+
330
+ /* * Constructor
331
+ */
332
+ Javadoc (
333
+ Paragraph brief,
334
+ List<Block> blocks,
335
+ List<Param> params,
336
+ List<TParam> tparams,
337
+ Returns returns);
338
+
339
+ bool operator <(Javadoc const &) const noexcept ;
340
+ bool operator ==(Javadoc const &) const noexcept ;
341
+
187
342
/* * Append a node to the documentation comment.,
188
343
*/
189
344
template <class Child >
190
345
void
191
- append (Child&& node)
346
+ emplace_back (Child&& node)
192
347
{
193
348
static_assert (std::is_base_of_v<Node, Child>);
194
349
195
- list_ .emplace_back <Child>(std::forward<Child>(node));
350
+ blocks_ .emplace_back <Child>(std::forward<Child>(node));
196
351
}
197
352
198
- /* * Append a brief to the documentation comment.,
199
- */
200
353
void
201
- append_brief (Paragraph&& paragraph )
354
+ emplace_back (Param param )
202
355
{
203
- assert (brief_ == nullptr );
204
- brief_ = new Paragraph (std::move (paragraph));
356
+ params_.emplace_back (std::move (param));
205
357
}
206
358
207
- private:
208
- List<Node> list_;
359
+ void
360
+ emplace_back (TParam tparam)
361
+ {
362
+ tparams_.emplace_back (std::move (tparam));
363
+ }
209
364
210
- Paragraph const * brief_ = nullptr ;
365
+ private:
366
+ std::shared_ptr<
367
+ Paragraph const > brief_;
368
+ List<Block> blocks_;
369
+ List<Param> params_;
370
+ List<TParam> tparams_;
371
+ Returns returns_;
211
372
};
212
373
213
374
} // mrdox
0 commit comments