Skip to content

Commit c54dc26

Browse files
committed
javadoc work and custom commands
1 parent 905570c commit c54dc26

File tree

12 files changed

+925
-57
lines changed

12 files changed

+925
-57
lines changed

include/mrdox/meta/Javadoc.hpp

Lines changed: 140 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
#ifndef MRDOX_META_JAVADOC_HPP
1313
#define MRDOX_META_JAVADOC_HPP
1414

15+
#include <mrdox/meta/List.hpp>
1516
#include <llvm/ADT/SmallString.h>
1617
#include <string>
18+
#include <utility>
1719

1820
namespace clang {
1921
namespace mrdox {
@@ -61,18 +63,151 @@ struct CommentInfo
6163
std::vector<std::unique_ptr<CommentInfo>> Children; // List of child comments for this CommentInfo.
6264
};
6365

64-
/** A complete javadoc attached to a declaration
66+
//------------------------------------------------
67+
68+
/** A processed Javadoc-style comment attached to a declaration.
6569
*/
6670
struct Javadoc
6771
{
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.
6995
*/
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
70162
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;
71174

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.,
73188
*/
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;
76211
};
77212

78213
} // mrdox

0 commit comments

Comments
 (0)