Skip to content

Commit

Permalink
chore: better bitcoding for doc nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
vinniefalco committed Jun 15, 2023
1 parent 17ee2ef commit 87d0752
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 173 deletions.
147 changes: 89 additions & 58 deletions include/mrdox/Metadata/Javadoc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,24 @@ struct Node

virtual ~Node() = default;

bool operator==(const Node&)
const noexcept = default;

virtual bool equals(
const Node& other) const noexcept
bool operator==(const Node&)const noexcept = default;
virtual bool equals(const Node& other) const noexcept
{
return kind == other.kind;
}
};

/** A string of plain text.
//------------------------------------------------
//
// Text nodes
//
//------------------------------------------------

/** A Node containing a string of text.
There will be no newlines in the text. Otherwise,
this would be represented as multiple text nodes
within a Paragraph node.
*/
struct Text : Node
{
Expand All @@ -117,15 +124,13 @@ struct Text : Node

explicit
Text(
String string_ = String())
String string_ = String()) noexcept
: Node(Kind::text)
, string(std::move(string_))
{
}

bool operator==(const Text&)
const noexcept = default;

bool operator==(const Text&) const noexcept = default;
bool equals(const Node& other) const noexcept override
{
return kind == other.kind &&
Expand All @@ -144,31 +149,35 @@ struct Text : Node

/** A piece of style text.
*/
struct StyledText : Text
struct Styled : Text
{
Style style;

static constexpr Kind static_kind = Kind::styled;

StyledText(
Styled(
String string_ = String(),
Style style_ = Style::none)
Style style_ = Style::none) noexcept
: Text(std::move(string_), Kind::styled)
, style(style_)
{
}

bool operator==(const StyledText&)
const noexcept = default;

bool equals(const Node& other) const noexcept override
bool operator==(Styled const&) const noexcept = default;
bool equals(Node const& other) const noexcept override
{
return kind == other.kind &&
*this == static_cast<const StyledText&>(other);
*this == static_cast<const Styled&>(other);
}

};

//------------------------------------------------
//
// Block nodes
//
//------------------------------------------------

/** A piece of block content
The top level is a list of blocks.
Expand Down Expand Up @@ -220,15 +229,13 @@ struct Heading : Block
String string;

Heading(
String string_ = String())
String string_ = String()) noexcept
: Block(Kind::heading)
, string(std::move(string_))
{
}

bool operator==(const Heading&)
const noexcept = default;

bool operator==(Heading const&) const noexcept = default;
bool equals(const Node& other) const noexcept override
{
return kind == other.kind &&
Expand All @@ -247,9 +254,7 @@ struct Paragraph : Block
{
}

bool operator==(const Paragraph&)
const noexcept = default;

bool operator==(const Paragraph&) const noexcept = default;
bool equals(const Node& other) const noexcept override
{
return kind == other.kind &&
Expand All @@ -260,7 +265,7 @@ struct Paragraph : Block
explicit
Paragraph(
Kind kind,
List<Text> children_ = {})
List<Text> children_ = {}) noexcept
: Block(kind, std::move(children_))
{
}
Expand All @@ -277,33 +282,29 @@ struct Brief : Paragraph
{
}

bool operator==(const Brief&)
const noexcept = default;

bool operator==(const Brief&) const noexcept = default;
bool equals(const Node& other) const noexcept override
{
return kind == other.kind &&
*this == static_cast<const Brief&>(other);
}
};

/** Documentation for an admonition
/** An admonition.
*/
struct Admonition : Paragraph
{
Admonish style;

explicit
Admonition(
Admonish style_ = Admonish::none)
Admonish style_ = Admonish::none) noexcept
: Paragraph(Kind::admonition)
, style(style_)
{
}

bool operator==(const Admonition&)
const noexcept = default;

bool operator==(const Admonition&) const noexcept = default;
bool equals(const Node& other) const noexcept override
{
return kind == other.kind &&
Expand All @@ -320,14 +321,12 @@ struct Code : Paragraph

static constexpr Kind static_kind = Kind::code;

Code()
Code() noexcept
: Paragraph(Kind::code)
{
}

bool operator==(const Code&)
const noexcept = default;

bool operator==(const Code&) const noexcept = default;
bool equals(const Node& other) const noexcept override
{
return kind == other.kind &&
Expand Down Expand Up @@ -366,52 +365,84 @@ struct Param : Paragraph
}
};

/** Documentation for a template parameter

/** Documentation for a function return type
*/
struct TParam : Paragraph
struct Returns : Paragraph
{
String name;

static constexpr Kind static_kind = Kind::tparam;
static constexpr Kind static_kind = Kind::returns;

TParam()
: Paragraph(Kind::tparam)
Returns()
: Paragraph(Kind::returns)
{
}

bool operator==(const TParam&)
bool operator==(const Returns&)
const noexcept = default;

bool equals(const Node& other) const noexcept override
{
return kind == other.kind &&
*this == static_cast<const TParam&>(other);
*this == static_cast<const Returns&>(other);
}
};

/** Documentation for a function return type
/** Documentation for a template parameter
*/
struct Returns : Paragraph
struct TParam : Paragraph
{
static constexpr Kind static_kind = Kind::returns;
String name;

Returns()
: Paragraph(Kind::returns)
static constexpr Kind static_kind = Kind::tparam;

TParam()
: Paragraph(Kind::tparam)
{
}

bool operator==(const Returns&)
const noexcept = default;

bool operator==(const TParam&) const noexcept = default;
bool equals(const Node& other) const noexcept override
{
return kind == other.kind &&
*this == static_cast<const Returns&>(other);
*this == static_cast<const TParam&>(other);
}
};

//------------------------------------------------

template<class F, class... Args>
constexpr
auto
visit(
Kind kind,
F&& f, Args&&... args)
{
switch(kind)
{
case Kind::admonition:
return f.template operator()<Admonition>(std::forward<Args>(args)...);
case Kind::brief:
return f.template operator()<Brief>(std::forward<Args>(args)...);
case Kind::code:
return f.template operator()<Code>(std::forward<Args>(args)...);
case Kind::heading:
return f.template operator()<Heading>(std::forward<Args>(args)...);
case Kind::paragraph:
return f.template operator()<Paragraph>(std::forward<Args>(args)...);
case Kind::param:
return f.template operator()<Param>(std::forward<Args>(args)...);
case Kind::returns:
return f.template operator()<Returns>(std::forward<Args>(args)...);
case Kind::styled:
return f.template operator()<Styled>(std::forward<Args>(args)...);
case Kind::text:
return f.template operator()<Text>(std::forward<Args>(args)...);
case Kind::tparam:
return f.template operator()<TParam>(std::forward<Args>(args)...);
default:
return f.template operator()<void>(std::forward<Args>(args)...);
}
}

template<class F, class... Args>
constexpr
auto
Expand Down Expand Up @@ -443,7 +474,7 @@ visit(
return f(static_cast<Returns const&>(node),
std::forward<Args>(args)...);
case Kind::styled:
return f(static_cast<StyledText const&>(node),
return f(static_cast<Styled const&>(node),
std::forward<Args>(args)...);
case Kind::text:
return f(static_cast<Text const&>(node),
Expand Down
4 changes: 2 additions & 2 deletions source/-XML/XMLWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ writeNode(
writeText(static_cast<doc::Text const&>(node));
break;
case doc::Kind::styled:
writeStyledText(static_cast<doc::StyledText const&>(node));
writeStyledText(static_cast<doc::Styled const&>(node));
break;
case doc::Kind::heading:
writeHeading(static_cast<doc::Heading const&>(node));
Expand Down Expand Up @@ -661,7 +661,7 @@ writeText(
void
XMLWriter::
writeStyledText(
doc::StyledText const& node)
doc::Styled const& node)
{
tags_.write(toString(node.style), node.string);
}
Expand Down
2 changes: 1 addition & 1 deletion source/-XML/XMLWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class XMLWriter
void writeNode(doc::Node const& node);
void writeBrief(doc::Paragraph const& node);
void writeText(doc::Text const& node);
void writeStyledText(doc::StyledText const& node);
void writeStyledText(doc::Styled const& node);
void writeHeading(doc::Heading const& node);
void writeParagraph(doc::Paragraph const& node, llvm::StringRef tag = "");
void writeAdmonition(doc::Admonition const& node);
Expand Down
4 changes: 2 additions & 2 deletions source/-adoc/AdocWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ writeNode(
writeNode(static_cast<doc::Text const&>(node));
return;
case doc::Kind::styled:
writeNode(static_cast<doc::StyledText const&>(node));
writeNode(static_cast<doc::Styled const&>(node));
return;
#if 0
case doc::Node::block:
Expand Down Expand Up @@ -687,7 +687,7 @@ writeNode(
void
AdocWriter::
writeNode(
doc::StyledText const& node)
doc::Styled const& node)
{
switch(node.style)
{
Expand Down
2 changes: 1 addition & 1 deletion source/-adoc/AdocWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class AdocWriter
void writeNode(doc::Node const& node);
void writeNode(doc::Block const& node);
void writeNode(doc::Text const& node);
void writeNode(doc::StyledText const& node);
void writeNode(doc::Styled const& node);
void writeNode(doc::Paragraph const& node);
void writeNode(doc::Admonition const& node);
void writeNode(doc::Code const& node);
Expand Down
Loading

0 comments on commit 87d0752

Please sign in to comment.