14
14
#define MRDOX_TOOL_AST_ANYBLOCK_HPP
15
15
16
16
#include " BitcodeReader.hpp"
17
- #include " AnyNodeList.hpp"
18
17
#include " DecodeRecord.hpp"
19
18
#include " Support/Debug.hpp"
20
19
#include " Support/Error.hpp"
@@ -74,72 +73,144 @@ class VersionBlock
74
73
75
74
// ------------------------------------------------
76
75
77
- /* * An AnyNodeList
76
+ /* * A doc::List<doc::Node>
78
77
*/
79
78
class JavadocNodesBlock
80
79
: public BitcodeReader::AnyBlock
81
80
{
82
81
BitcodeReader& br_;
83
82
84
83
public:
85
- AnyNodeList J;
84
+ doc::List<doc::Node> nodes;
85
+ doc::Kind list_kind;
86
86
87
87
explicit
88
88
JavadocNodesBlock (
89
- AnyNodeList*& stack,
90
89
BitcodeReader& br) noexcept
91
90
: br_(br)
92
- , J(stack )
91
+ , list_kind( )
93
92
{
94
93
}
95
94
96
95
Error
97
- parseRecord (Record const & R,
98
- unsigned ID, llvm::StringRef Blob) override
96
+ parseRecord (
97
+ Record const & R,
98
+ unsigned ID,
99
+ llvm::StringRef Blob) override
99
100
{
100
101
switch (ID)
101
102
{
103
+ // KRYSTIAN NOTE: this doesn't actually do anything
102
104
case JAVADOC_LIST_KIND:
103
105
{
104
106
doc::Kind kind{};
105
107
if (auto err = decodeRecord (R, kind, Blob))
106
108
return err;
107
- return J.setKind (kind);
109
+ if (kind != doc::Kind::block &&
110
+ kind != doc::Kind::text)
111
+ return Error (" wrong or unknown kind" );
112
+ list_kind = kind;
113
+ return Error::success ();
108
114
}
109
115
case JAVADOC_NODE_KIND:
110
116
{
111
117
doc::Kind kind{};
112
118
if (auto err = decodeRecord (R, kind, Blob))
113
119
return err;
114
- return J.getNodes ().appendChild (kind);
120
+ switch (kind)
121
+ {
122
+ case doc::Kind::text:
123
+ nodes.emplace_back (std::make_unique<doc::Text>());
124
+ return Error::success ();
125
+ case doc::Kind::styled:
126
+ nodes.emplace_back (std::make_unique<doc::StyledText>());
127
+ return Error::success ();
128
+ case doc::Kind::paragraph:
129
+ nodes.emplace_back (std::make_unique<doc::Paragraph>());
130
+ return Error::success ();
131
+ case doc::Kind::brief:
132
+ nodes.emplace_back (std::make_unique<doc::Brief>());
133
+ return Error::success ();
134
+ case doc::Kind::admonition:
135
+ nodes.emplace_back (std::make_unique<doc::Admonition>());
136
+ return Error::success ();
137
+ case doc::Kind::code:
138
+ nodes.emplace_back (std::make_unique<doc::Code>());
139
+ return Error::success ();
140
+ case doc::Kind::returns:
141
+ nodes.emplace_back (std::make_unique<doc::Returns>());
142
+ return Error::success ();
143
+ case doc::Kind::param:
144
+ nodes.emplace_back (std::make_unique<doc::Param>());
145
+ return Error::success ();
146
+ case doc::Kind::tparam:
147
+ nodes.emplace_back (std::make_unique<doc::TParam>());
148
+ return Error::success ();
149
+ default :
150
+ return Error (" invalid kind" );
151
+ }
115
152
}
116
153
case JAVADOC_PARAM_DIRECTION:
117
154
{
118
155
doc::ParamDirection direction =
119
156
doc::ParamDirection::none;
120
157
if (auto err = decodeRecord (R, direction, Blob))
121
158
return err;
122
- return J.getNodes ().setDirection (direction);
159
+ auto node = nodes.back ().get ();
160
+ if (node->kind != doc::Kind::param)
161
+ return Error (" direction on wrong kind" );
162
+ auto param = static_cast <doc::Param*>(node);
163
+ param->direction = direction;
164
+ return Error::success ();
123
165
}
124
166
case JAVADOC_NODE_STRING:
125
167
{
126
- return J.getNodes ().setString (Blob);
168
+ switch (auto node = nodes.back ().get ();
169
+ node->kind )
170
+ {
171
+ case doc::Kind::text:
172
+ case doc::Kind::styled:
173
+ static_cast <doc::Text*>(
174
+ node)->string = Blob.str ();
175
+ return Error::success ();
176
+ case doc::Kind::param:
177
+ static_cast <doc::Param*>(
178
+ node)->name = Blob.str ();
179
+ return Error::success ();
180
+ case doc::Kind::tparam:
181
+ static_cast <doc::TParam*>(
182
+ node)->name = Blob.str ();
183
+ return Error::success ();
184
+ default :
185
+ return Error (" string on wrong kind" );
186
+ }
127
187
}
128
188
case JAVADOC_NODE_STYLE:
129
189
{
130
190
doc::Style style =
131
191
doc::Style::none;
132
192
if (auto err = decodeRecord (R, style, Blob))
133
193
return err;
134
- return J.getNodes ().setStyle (style);
194
+ auto node = nodes.back ().get ();
195
+ if (node->kind != doc::Kind::styled)
196
+ return Error (" style on wrong kind" );
197
+ static_cast <doc::StyledText*>(
198
+ node)->style = style;
199
+ return Error::success ();
200
+
135
201
}
136
202
case JAVADOC_NODE_ADMONISH:
137
203
{
138
204
doc::Admonish admonish =
139
205
doc::Admonish::none;
140
206
if (auto err = decodeRecord (R, admonish, Blob))
141
207
return err;
142
- return J.getNodes ().setAdmonish (admonish);
208
+ auto node = nodes.back ().get ();
209
+ if (node->kind != doc::Kind::admonition)
210
+ return Error (" admonish on wrong kind" );
211
+ static_cast <doc::Admonition*>(
212
+ node)->style = admonish;
213
+ return Error::success ();
143
214
}
144
215
default :
145
216
return AnyBlock::parseRecord (R, ID, Blob);
@@ -158,11 +229,17 @@ class JavadocNodesBlock
158
229
}
159
230
case BI_JAVADOC_LIST_BLOCK_ID:
160
231
{
161
- JavadocNodesBlock B (J.stack (), br_);
232
+ auto node = nodes.back ().get ();
233
+ if (node->kind == doc::Kind::text ||
234
+ node->kind == doc::Kind::styled)
235
+ return Error (" text node cannot have list" );
236
+
237
+ JavadocNodesBlock B (br_);
162
238
if (auto err = br_.readBlock (B, ID))
163
239
return err;
164
- if (auto err = B.J .spliceIntoParent ())
165
- return err;
240
+ Javadoc::append (static_cast <
241
+ doc::Block*>(node)->children ,
242
+ std::move (B.nodes ));
166
243
return Error::success ();
167
244
}
168
245
default :
@@ -178,16 +255,13 @@ class JavadocBlock
178
255
{
179
256
BitcodeReader& br_;
180
257
std::unique_ptr<Javadoc>& I_;
181
- AnyNodeList* stack_ = nullptr ;
182
- AnyNodeList J_;
183
258
184
259
public:
185
260
JavadocBlock (
186
261
std::unique_ptr<Javadoc>& I,
187
262
BitcodeReader& br) noexcept
188
263
: br_(br)
189
264
, I_(I)
190
- , J_(stack_)
191
265
{
192
266
I_ = std::make_unique<Javadoc>();
193
267
}
@@ -200,11 +274,12 @@ class JavadocBlock
200
274
{
201
275
case BI_JAVADOC_LIST_BLOCK_ID:
202
276
{
203
- JavadocNodesBlock B (stack_, br_);
277
+ JavadocNodesBlock B (br_);
204
278
if (auto err = br_.readBlock (B, ID))
205
279
return err;
206
- if (auto err = B.J .spliceInto (I_->getBlocks ()))
207
- return err;
280
+ Javadoc::append (
281
+ I_->getBlocks (),
282
+ std::move (B.nodes ));
208
283
return Error::success ();
209
284
}
210
285
default :
0 commit comments