Skip to content

Commit e29bd89

Browse files
committed
chore: Javadoc preserves order
1 parent f53619d commit e29bd89

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+792
-483
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ find_package(fmt REQUIRED CONFIG)
126126
#-------------------------------------------------
127127

128128
file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS source/*.cpp source/*.hpp source/*.in source/*.natvis)
129-
file(GLOB_RECURSE INCLUDES CONFIGURE_DEPENDS include/*.hpp)
129+
file(GLOB_RECURSE INCLUDES CONFIGURE_DEPENDS include/*.hpp include/*.natvis)
130130
add_executable(mrdox ${SOURCES} ${INCLUDES})
131131

132132
target_compile_features(mrdox PUBLIC cxx_std_20)

include/mrdox/Metadata/Javadoc.hpp

Lines changed: 57 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,15 @@ struct Node;
3333
using String = std::string;
3434

3535
template<typename T>
36-
requires std::derived_from<T, doc::Node>
36+
requires std::derived_from<T, doc::Node>
3737
using List = std::vector<std::unique_ptr<T>>;
3838

3939
enum class Kind
4040
{
41+
// VFALCO Don't forget to update
42+
// Node::isText() and Node::isBlock()
43+
// when changing this enum!
44+
4145
text = 1, // needed by bitstream
4246
admonition,
4347
brief,
@@ -88,16 +92,20 @@ enum class ParamDirection : int
8892

8993
/** This is a variant-like list element.
9094
*/
91-
struct Node
95+
struct MRDOX_DECL
96+
Node
9297
{
9398
Kind kind;
9499

100+
virtual ~Node() = default;
101+
95102
explicit Node(Kind kind_) noexcept
96103
: kind(kind_)
97104
{
98105
}
99106

100-
virtual ~Node() = default;
107+
bool isBlock() const noexcept;
108+
bool isText() const noexcept;
101109

102110
bool operator==(const Node&)const noexcept = default;
103111
virtual bool equals(const Node& other) const noexcept
@@ -209,7 +217,8 @@ struct Link : Text
209217
210218
The top level is a list of blocks.
211219
*/
212-
struct Block : Node
220+
struct MRDOX_DECL
221+
Block : Node
213222
{
214223
List<Text> children;
215224

@@ -230,12 +239,20 @@ struct Block : Node
230239
});
231240
}
232241

233-
bool equals(const Node& other) const noexcept override
242+
bool equals(Node const& other) const noexcept override
234243
{
235244
return kind == other.kind &&
236245
*this == static_cast<const Block&>(other);
237246
}
238247

248+
template<std::derived_from<Text> T>
249+
void emplace_back(T&& text)
250+
{
251+
emplace_back(std::make_unique<T>(std::move(text)));
252+
}
253+
254+
void append(List<Node>&& blocks);
255+
239256
protected:
240257
explicit
241258
Block(
@@ -245,6 +262,9 @@ struct Block : Node
245262
, children(std::move(children_))
246263
{
247264
}
265+
266+
private:
267+
void emplace_back(std::unique_ptr<Text> text);
248268
};
249269

250270
/** A manually specified section heading.
@@ -321,13 +341,13 @@ struct Brief : Paragraph
321341
*/
322342
struct Admonition : Paragraph
323343
{
324-
Admonish style;
344+
Admonish admonish;
325345

326346
explicit
327347
Admonition(
328-
Admonish style_ = Admonish::none) noexcept
348+
Admonish admonish_ = Admonish::none) noexcept
329349
: Paragraph(Kind::admonition)
330-
, style(style_)
350+
, admonish(admonish_)
331351
{
332352
}
333353

@@ -559,9 +579,9 @@ void traverse(
559579

560580
struct Overview
561581
{
562-
Paragraph const* brief;
582+
Paragraph const* brief = nullptr;
563583
std::vector<Block const*> blocks;
564-
Returns const* returns;
584+
Returns const* returns = nullptr;
565585
std::vector<Param const*> params;
566586
std::vector<TParam const*> tparams;
567587
};
@@ -572,35 +592,30 @@ struct Overview
572592

573593
/** A processed Doxygen-style comment attached to a declaration.
574594
*/
575-
struct MRDOX_VISIBLE
595+
class MRDOX_DECL
576596
Javadoc
577597
{
578-
MRDOX_DECL
598+
public:
579599
Javadoc() noexcept;
580600

581601
/** Constructor
582602
*/
583-
MRDOX_DECL
584603
explicit
585604
Javadoc(
586605
doc::List<doc::Block> blocks);
587606

588607
/** Return true if this is empty
589608
*/
590-
MRDOX_DECL
591609
bool
592-
empty() const noexcept;
610+
empty() const noexcept
611+
{
612+
return blocks_.empty();
613+
}
593614

594615
/** Return the brief, or nullptr if there is none.
595-
596-
This function should only be called
597-
after postProcess() has been invoked.
598616
*/
599617
doc::Paragraph const*
600-
getBrief() const noexcept
601-
{
602-
return brief_.get();
603-
}
618+
brief() const noexcept;
604619

605620
/** Return the list of top level blocks.
606621
*/
@@ -610,30 +625,6 @@ struct MRDOX_VISIBLE
610625
return blocks_;
611626
}
612627

613-
/** Return the element describing the return type.
614-
*/
615-
doc::Returns const*
616-
getReturns() const noexcept
617-
{
618-
return returns_.get();
619-
}
620-
621-
/** Return the list of top level blocks.
622-
*/
623-
doc::List<doc::Param> const&
624-
getParams() const noexcept
625-
{
626-
return params_;
627-
}
628-
629-
/** Return the list of top level blocks.
630-
*/
631-
doc::List<doc::TParam> const&
632-
getTParams() const noexcept
633-
{
634-
return tparams_;
635-
}
636-
637628
// VFALCO This is unfortunately necessary for
638629
// the deserialization from bitcode...
639630
doc::List<doc::Block>&
@@ -651,34 +642,10 @@ struct MRDOX_VISIBLE
651642
output format.
652643
*/
653644
/** @{ */
654-
MRDOX_DECL bool operator==(Javadoc const&) const noexcept;
655-
MRDOX_DECL bool operator!=(Javadoc const&) const noexcept;
645+
bool operator==(Javadoc const&) const noexcept;
646+
bool operator!=(Javadoc const&) const noexcept;
656647
/* @} */
657648

658-
/** Apply post-processing to the final object.
659-
660-
The implementation calls this function once,
661-
after all doc comments have been merged
662-
and attached, to calculate the brief as
663-
follows:
664-
665-
@li Sets the brief to the first paragraph
666-
in which a "brief" command exists, or
667-
668-
@li Sets the first paragraph as the brief if
669-
no "brief" is found.
670-
671-
@li Otherwise, the brief is set to a
672-
null pointer to indicate absence.
673-
674-
Furthermore, the Params and TParams are
675-
spliced out of the top level list of
676-
blocks into their own lists.
677-
*/
678-
MRDOX_DECL
679-
void
680-
postProcess();
681-
682649
/** Return an overview of the javadoc.
683650
684651
The Javadoc is stored as a list of blocks,
@@ -692,54 +659,35 @@ struct MRDOX_VISIBLE
692659
the returend overview is invalidated if the
693660
javadoc object is destroyed.
694661
*/
695-
MRDOX_DECL doc::Overview makeOverview() const;
662+
doc::Overview makeOverview() const;
696663

697664
//--------------------------------------------
698665

699-
/** These are used to bottleneck all insertions.
700-
*/
701-
/** @{ */
702-
template<class T, class U>
703-
static
704-
void
705-
append(doc::List<T>& list, doc::List<U>&& other) noexcept
706-
{
707-
list.reserve(list.size() + other.size());
708-
for(auto& p : other)
709-
list.emplace_back(static_cast<T*>(p.release()));
710-
other.clear();
711-
}
666+
/** Attempt to append a block.
712667
713-
template<class T, class Child>
714-
static
715-
void
716-
append(
717-
doc::List<T>& list,
718-
std::unique_ptr<Child>&& child)
719-
{
720-
list.emplace_back(
721-
std::move(child));
722-
}
668+
@return An empty string on success, otherwise
669+
a string indicating the reason for the failure.
723670
724-
template<class Parent, class Child>
725-
static
726-
void
727-
append(
728-
Parent& parent,
729-
std::unique_ptr<Child>&& child)
671+
@param block The block to append.
672+
*/
673+
template<std::derived_from<doc::Block> T>
674+
std::string
675+
emplace_back(T&& block)
730676
{
731-
append(parent.children,
732-
std::move(child));
677+
return emplace_back(std::make_unique<T>(std::move(block)));
733678
}
734679

735-
//--------------------------------------------
680+
/** Append blocks from another javadoc to this.
681+
*/
682+
void append(Javadoc&& other);
683+
684+
void append(doc::List<doc::Node>&& blocks);
736685

737686
private:
738-
std::unique_ptr<doc::Paragraph> brief_;
739-
std::unique_ptr<doc::Returns> returns_;
687+
std::string emplace_back(std::unique_ptr<doc::Block>);
688+
689+
doc::Paragraph const* brief_ = nullptr;
740690
doc::List<doc::Block> blocks_;
741-
doc::List<doc::Param> params_;
742-
doc::List<doc::TParam> tparams_;
743691
};
744692

745693
} // mrdox

include/mrdox/MetadataFwd.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct EnumInfo;
4141
struct FieldInfo;
4242
struct FunctionInfo;
4343
struct Info;
44-
struct Javadoc;
44+
class Javadoc;
4545
struct Location;
4646
struct NamespaceInfo;
4747
struct RecordInfo;

0 commit comments

Comments
 (0)