15
15
16
16
#include < mrdocs/Platform.hpp>
17
17
#include < mrdocs/Dom.hpp>
18
+ #include < mrdocs/Metadata/Symbols.hpp>
18
19
#include < mrdocs/Support/Error.hpp>
20
+ #include < mrdocs/Support/Visitor.hpp>
19
21
#include < memory>
20
22
#include < string>
21
23
#include < type_traits>
@@ -55,6 +57,8 @@ enum class Kind
55
57
returns,
56
58
styled,
57
59
tparam,
60
+ reference,
61
+ copied
58
62
};
59
63
60
64
/* * A text style.
@@ -81,14 +85,27 @@ enum class Admonish
81
85
82
86
/* * Parameter pass direction.
83
87
*/
84
- enum class ParamDirection : int
88
+ enum class ParamDirection
85
89
{
86
90
none,
87
91
in,
88
92
out,
89
93
inout
90
94
};
91
95
96
+ /* * Which parts of the documentation to copy.
97
+
98
+ @li `all`: copy the brief and the description.
99
+ @li `brief`: only copy the brief.
100
+ @li `description`: only copy the description.
101
+ */
102
+ enum class Parts
103
+ {
104
+ all = 1 , // needed by bitstream
105
+ brief,
106
+ description
107
+ };
108
+
92
109
// --------------------------------------------
93
110
94
111
/* * This is a variant-like list element.
@@ -208,6 +225,61 @@ struct Link : Text
208
225
}
209
226
};
210
227
228
+ /* * A reference to a symbol.
229
+ */
230
+ struct Reference : Text
231
+ {
232
+ SymbolID id = SymbolID::zero;
233
+
234
+ static constexpr Kind static_kind = Kind::reference;
235
+
236
+ explicit
237
+ Reference (
238
+ String string_ = String()) noexcept
239
+ : Text(std::move(string_), Kind::reference)
240
+ {
241
+ }
242
+
243
+ bool operator ==(const Reference&) const noexcept = default ;
244
+ bool equals (const Node& other) const noexcept override
245
+ {
246
+ return kind == other.kind &&
247
+ *this == static_cast <const Reference&>(other);
248
+ }
249
+
250
+ protected:
251
+ Reference (
252
+ String string_,
253
+ Kind kind_) noexcept
254
+ : Text(std::move(string_), kind_)
255
+ {
256
+ }
257
+ };
258
+
259
+ /* * Documentation copied from another symbol.
260
+ */
261
+ struct Copied : Reference
262
+ {
263
+ Parts parts;
264
+
265
+ static constexpr Kind static_kind = Kind::copied;
266
+
267
+ Copied (
268
+ String string_ = String(),
269
+ Parts parts_ = Parts::all) noexcept
270
+ : Reference(std::move(string_), Kind::copied)
271
+ , parts(parts_)
272
+ {
273
+ }
274
+
275
+ bool operator ==(Copied const &) const noexcept = default ;
276
+ bool equals (Node const & other) const noexcept override
277
+ {
278
+ return kind == other.kind &&
279
+ *this == static_cast <const Copied&>(other);
280
+ }
281
+ };
282
+
211
283
// ------------------------------------------------
212
284
//
213
285
// Block nodes
@@ -247,9 +319,10 @@ struct MRDOCS_DECL
247
319
}
248
320
249
321
template <std::derived_from<Text> T>
250
- void emplace_back (T&& text)
322
+ T& emplace_back (T&& text)
251
323
{
252
- emplace_back (std::make_unique<T>(std::move (text)));
324
+ return static_cast <T&>(emplace_back (
325
+ std::make_unique<T>(std::move (text))));
253
326
}
254
327
255
328
void append (List<Node>&& blocks);
@@ -265,7 +338,7 @@ struct MRDOCS_DECL
265
338
}
266
339
267
340
private:
268
- void emplace_back (std::unique_ptr<Text> text);
341
+ Text& emplace_back (std::unique_ptr<Text> text);
269
342
};
270
343
271
344
/* * A manually specified section heading.
@@ -497,6 +570,10 @@ visit(
497
570
return f.template operator ()<Heading>(std::forward<Args>(args)...);
498
571
case Kind::link :
499
572
return f.template operator ()<Link>(std::forward<Args>(args)...);
573
+ case Kind::reference:
574
+ return f.template operator ()<Reference>(std::forward<Args>(args)...);
575
+ case Kind::copied:
576
+ return f.template operator ()<Copied>(std::forward<Args>(args)...);
500
577
case Kind::list_item:
501
578
return f.template operator ()<ListItem>(std::forward<Args>(args)...);
502
579
case Kind::paragraph:
@@ -516,51 +593,50 @@ visit(
516
593
}
517
594
}
518
595
519
- template <class F , class ... Args>
520
- constexpr
521
- auto
596
+ template <
597
+ class NodeTy ,
598
+ class Fn ,
599
+ class ... Args>
600
+ requires std::derived_from<NodeTy, Node>
601
+ decltype (auto )
522
602
visit(
523
- Node const & node,
524
- F&& f, Args&&... args)
603
+ NodeTy& node,
604
+ Fn&& fn,
605
+ Args&&... args)
525
606
{
607
+ auto visitor = makeVisitor<Node>(
608
+ node, std::forward<Fn>(fn),
609
+ std::forward<Args>(args)...);
526
610
switch (node.kind )
527
611
{
528
612
case Kind::admonition:
529
- return f (static_cast <Admonition const &>(node),
530
- std::forward<Args>(args)...);
613
+ return visitor.template visit <Admonition>();
531
614
case Kind::brief:
532
- return f (static_cast <Brief const &>(node),
533
- std::forward<Args>(args)...);
615
+ return visitor.template visit <Brief>();
534
616
case Kind::code:
535
- return f (static_cast <Code const &>(node),
536
- std::forward<Args>(args)...);
617
+ return visitor.template visit <Code>();
537
618
case Kind::heading:
538
- return f (static_cast <Heading const &>(node),
539
- std::forward<Args>(args)...);
619
+ return visitor.template visit <Heading>();
540
620
case Kind::paragraph:
541
- return f (static_cast <Paragraph const &>(node),
542
- std::forward<Args>(args)...);
621
+ return visitor.template visit <Paragraph>();
543
622
case Kind::link :
544
- return f (static_cast <Link const &>(node),
545
- std::forward<Args>(args)...);
623
+ return visitor.template visit <Link>();
624
+ case Kind::reference:
625
+ return visitor.template visit <Reference>();
626
+ case Kind::copied:
627
+ return visitor.template visit <Copied>();
546
628
case Kind::list_item:
547
- return f (static_cast <ListItem const &>(node),
548
- std::forward<Args>(args)...);
629
+ return visitor.template visit <ListItem>();
549
630
case Kind::param:
550
- return f (static_cast <Param const &>(node),
551
- std::forward<Args>(args)...);
631
+ return visitor.template visit <Param>();
552
632
case Kind::returns:
553
- return f (static_cast <Returns const &>(node),
554
- std::forward<Args>(args)...);
633
+ return visitor.template visit <Returns>();
555
634
case Kind::styled:
556
- return f (static_cast <Styled const &>(node),
557
- std::forward<Args>(args)...);
635
+ return visitor.template visit <Styled>();
558
636
case Kind::text:
559
- return f (static_cast <Text const &>(node),
560
- std::forward<Args>(args)...);
637
+ return visitor.template visit <Text>();
561
638
case Kind::tparam:
562
- return f (static_cast <TParam const &>(node),
563
- std::forward<Args>(args)...);
639
+ return visitor.template visit <TParam>();
564
640
default :
565
641
MRDOCS_UNREACHABLE ();
566
642
}
@@ -593,6 +669,8 @@ MRDOCS_DECL dom::String toString(Style style) noexcept;
593
669
594
670
// ------------------------------------------------
595
671
672
+ class Corpus ;
673
+
596
674
/* * A processed Doxygen-style comment attached to a declaration.
597
675
*/
598
676
class MRDOCS_DECL
@@ -621,7 +699,10 @@ class MRDOCS_DECL
621
699
/* * Return the brief, or nullptr if there is none.
622
700
*/
623
701
doc::Paragraph const *
624
- brief () const noexcept ;
702
+ getBrief (Corpus const & corpus) const noexcept ;
703
+
704
+ doc::List<doc::Block> const &
705
+ getDescription (Corpus const & corpus) const noexcept ;
625
706
626
707
/* * Return the list of top level blocks.
627
708
*/
@@ -665,7 +746,8 @@ class MRDOCS_DECL
665
746
the returend overview is invalidated if the
666
747
javadoc object is destroyed.
667
748
*/
668
- doc::Overview makeOverview () const ;
749
+ doc::Overview
750
+ makeOverview (const Corpus& corpus) const ;
669
751
670
752
// --------------------------------------------
671
753
@@ -692,7 +774,6 @@ class MRDOCS_DECL
692
774
private:
693
775
std::string emplace_back (std::unique_ptr<doc::Block>);
694
776
695
- doc::Paragraph const * brief_ = nullptr ;
696
777
doc::List<doc::Block> blocks_;
697
778
};
698
779
0 commit comments