Skip to content

Commit 5c9e7d2

Browse files
committed
replace AnyList with std::vector<std::unique_ptr<Node>>
1 parent 6600fe7 commit 5c9e7d2

File tree

15 files changed

+352
-1435
lines changed

15 files changed

+352
-1435
lines changed

include/mrdox/ADT/AnyList.hpp

Lines changed: 0 additions & 837 deletions
This file was deleted.

include/mrdox/Metadata/Javadoc.hpp

Lines changed: 148 additions & 71 deletions
Large diffs are not rendered by default.

source/-XML/XMLWriter.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
// Copyright (c) 2023 Vinnie Falco ([email protected])
8+
// Copyright (c) 2023 Krystian Stasiowski ([email protected])
89
//
910
// Official repository: https://github.com/cppalliance/mrdox
1011
//
@@ -586,12 +587,12 @@ template<class T>
586587
void
587588
XMLWriter::
588589
writeNodes(
589-
AnyList<T> const& list)
590+
doc::List<T> const& list)
590591
{
591592
if(list.empty())
592593
return;
593594
for(auto const& node : list)
594-
writeNode(node);
595+
writeNode(*node);
595596
}
596597

597598
void

source/-XML/XMLWriter.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class XMLWriter
8282
void closeTemplate(const std::unique_ptr<TemplateInfo>& I);
8383

8484
template<class T>
85-
void writeNodes(AnyList<T> const& list);
85+
void writeNodes(doc::List<T> const& list);
8686
void writeNode(doc::Node const& node);
8787
void writeBrief(doc::Paragraph const& node);
8888
void writeText(doc::Text const& node);

source/-adoc/AdocWriter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -729,22 +729,22 @@ writeNode(
729729
os_ <<
730730
"[,cpp]\n"
731731
"----\n";
732-
AnyList<doc::Text> const& list(node.children);
732+
doc::List<doc::Text> const& list = node.children;
733733
if(! list.empty())
734734
{
735735
// measure the left margin
736736
std::size_t n = std::size_t(-1);
737737
for(auto& text : list)
738738
{
739-
auto const space = text.string.size() -
740-
llvm::StringRef(text.string).ltrim().size();
739+
auto const space = text->string.size() -
740+
llvm::StringRef(text->string).ltrim().size();
741741
if( n > space)
742742
n = space;
743743
}
744744
// now write left-aligned
745745
for(auto& text : list)
746746
{
747-
llvm::StringRef string(text.string);
747+
llvm::StringRef string(text->string);
748748
string = string.ltrim(n);
749749
os_ << string << "\n";
750750
}

source/-adoc/AdocWriter.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ class AdocWriter
103103
SymbolInfo const& S);
104104

105105
template<class T>
106-
void writeNodes(AnyList<T> const& list)
106+
void writeNodes(doc::List<T> const& list)
107107
{
108108
if(list.empty())
109109
return;
110-
for(doc::Node const& node : list)
111-
writeNode(node);
110+
for(const auto& node : list)
111+
writeNode(*node);
112112
}
113113

114114
void writeNode(doc::Node const& node);

source/AST/AnyBlock.hpp

Lines changed: 97 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#define MRDOX_TOOL_AST_ANYBLOCK_HPP
1515

1616
#include "BitcodeReader.hpp"
17-
#include "AnyNodeList.hpp"
1817
#include "DecodeRecord.hpp"
1918
#include "Support/Debug.hpp"
2019
#include "Support/Error.hpp"
@@ -74,72 +73,144 @@ class VersionBlock
7473

7574
//------------------------------------------------
7675

77-
/** An AnyNodeList
76+
/** A doc::List<doc::Node>
7877
*/
7978
class JavadocNodesBlock
8079
: public BitcodeReader::AnyBlock
8180
{
8281
BitcodeReader& br_;
8382

8483
public:
85-
AnyNodeList J;
84+
doc::List<doc::Node> nodes;
85+
doc::Kind list_kind;
8686

8787
explicit
8888
JavadocNodesBlock(
89-
AnyNodeList*& stack,
9089
BitcodeReader& br) noexcept
9190
: br_(br)
92-
, J(stack)
91+
, list_kind()
9392
{
9493
}
9594

9695
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
99100
{
100101
switch (ID)
101102
{
103+
// KRYSTIAN NOTE: this doesn't actually do anything
102104
case JAVADOC_LIST_KIND:
103105
{
104106
doc::Kind kind{};
105107
if(auto err = decodeRecord(R, kind, Blob))
106108
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();
108114
}
109115
case JAVADOC_NODE_KIND:
110116
{
111117
doc::Kind kind{};
112118
if(auto err = decodeRecord(R, kind, Blob))
113119
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+
}
115152
}
116153
case JAVADOC_PARAM_DIRECTION:
117154
{
118155
doc::ParamDirection direction =
119156
doc::ParamDirection::none;
120157
if(auto err = decodeRecord(R, direction, Blob))
121158
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();
123165
}
124166
case JAVADOC_NODE_STRING:
125167
{
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+
}
127187
}
128188
case JAVADOC_NODE_STYLE:
129189
{
130190
doc::Style style =
131191
doc::Style::none;
132192
if(auto err = decodeRecord(R, style, Blob))
133193
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+
135201
}
136202
case JAVADOC_NODE_ADMONISH:
137203
{
138204
doc::Admonish admonish =
139205
doc::Admonish::none;
140206
if(auto err = decodeRecord(R, admonish, Blob))
141207
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();
143214
}
144215
default:
145216
return AnyBlock::parseRecord(R, ID, Blob);
@@ -158,11 +229,17 @@ class JavadocNodesBlock
158229
}
159230
case BI_JAVADOC_LIST_BLOCK_ID:
160231
{
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_);
162238
if(auto err = br_.readBlock(B, ID))
163239
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));
166243
return Error::success();
167244
}
168245
default:
@@ -178,16 +255,13 @@ class JavadocBlock
178255
{
179256
BitcodeReader& br_;
180257
std::unique_ptr<Javadoc>& I_;
181-
AnyNodeList* stack_ = nullptr;
182-
AnyNodeList J_;
183258

184259
public:
185260
JavadocBlock(
186261
std::unique_ptr<Javadoc>& I,
187262
BitcodeReader& br) noexcept
188263
: br_(br)
189264
, I_(I)
190-
, J_(stack_)
191265
{
192266
I_ = std::make_unique<Javadoc>();
193267
}
@@ -200,11 +274,12 @@ class JavadocBlock
200274
{
201275
case BI_JAVADOC_LIST_BLOCK_ID:
202276
{
203-
JavadocNodesBlock B(stack_, br_);
277+
JavadocNodesBlock B(br_);
204278
if(auto err = br_.readBlock(B, ID))
205279
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));
208283
return Error::success();
209284
}
210285
default:

0 commit comments

Comments
 (0)