Skip to content

Commit 01835f4

Browse files
committed
chore: eliminate ToolExecutor, replace Corpus::index with iterator access, add ExecutionContext which skips bitcode
1 parent c3a18a5 commit 01835f4

File tree

14 files changed

+478
-384
lines changed

14 files changed

+478
-384
lines changed

include/mrdox/Corpus.hpp

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class MRDOX_VISIBLE
3737
{
3838
}
3939

40+
41+
class iterator;
4042
public:
4143
/** Destructor.
4244
*/
@@ -50,12 +52,19 @@ class MRDOX_VISIBLE
5052
*/
5153
Config const& config;
5254

53-
/** Return a sorted index of all symbols.
55+
/** Return the begin iterator for the index of all symbols.
56+
*/
57+
MRDOX_DECL
58+
virtual
59+
iterator
60+
begin() const noexcept = 0;
61+
62+
/** Return the end iterator for the index.
5463
*/
5564
MRDOX_DECL
5665
virtual
57-
std::vector<Info const*> const&
58-
index() const noexcept = 0;
66+
iterator
67+
end() const noexcept = 0;
5968

6069
/** Return the metadata for the global namespace.
6170
*/
@@ -180,6 +189,73 @@ traverse(
180189
std::forward<Args>(args)...);
181190
}
182191

192+
class Corpus::iterator
193+
{
194+
const Corpus* corpus_;
195+
const Info* val_;
196+
const Info*(*next_)(const Corpus*, const Info*);
197+
198+
public:
199+
using value_type = const Info;
200+
using size_type = std::size_t;
201+
using difference_type = std::ptrdiff_t;
202+
using pointer = value_type*;
203+
using reference = value_type&;
204+
using const_pointer = const value_type*;
205+
using const_reference = const value_type&;
206+
207+
iterator() = default;
208+
iterator(const iterator&) = default;
209+
iterator& operator=(const iterator&) = default;
210+
211+
iterator(
212+
const Corpus* corpus,
213+
const Info* val,
214+
const Info*(*next)(const Corpus*, const Info*))
215+
: corpus_(corpus)
216+
, val_(val)
217+
, next_(next)
218+
{
219+
}
220+
221+
iterator& operator++() noexcept
222+
{
223+
MRDOX_ASSERT(val_);
224+
val_ = next_(corpus_, val_);
225+
return *this;
226+
}
227+
228+
iterator operator++(int) noexcept
229+
{
230+
MRDOX_ASSERT(val_);
231+
auto temp = *this;
232+
val_ = next_(corpus_, val_);
233+
return temp;
234+
}
235+
236+
const_pointer operator->() const noexcept
237+
{
238+
MRDOX_ASSERT(val_);
239+
return val_;
240+
}
241+
242+
const_reference operator*() const noexcept
243+
{
244+
MRDOX_ASSERT(val_);
245+
return *val_;
246+
}
247+
248+
bool operator==(iterator const& other) const noexcept
249+
{
250+
return val_ == other.val_;
251+
}
252+
253+
bool operator!=(iterator const& other) const noexcept
254+
{
255+
return val_ != other.val_;
256+
}
257+
};
258+
183259
} // mrdox
184260
} // clang
185261

src/lib/-XML/XMLWriter.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,23 +171,23 @@ writeIndex()
171171
if(options_.safe_names)
172172
{
173173
SafeNames names(corpus_);
174-
for(auto I : corpus_.index())
174+
for(auto& I : corpus_)
175175
{
176-
auto safe_name = names.getUnqualified(I->id);
176+
auto safe_name = names.getUnqualified(I.id);
177177
tags_.write("symbol", {}, {
178178
{ "safe", safe_name },
179-
{ "name", corpus_.getFullyQualifiedName(*I, temp) },
180-
{ "tag", toString(I->Kind) },
181-
{ I->id } });
179+
{ "name", corpus_.getFullyQualifiedName(I, temp) },
180+
{ "tag", toString(I.Kind) },
181+
{ I.id } });
182182
}
183183
}
184184
else
185185
{
186-
for(auto I : corpus_.index())
186+
for(auto& I : corpus_)
187187
tags_.write("symbol", {}, {
188-
{ "name", corpus_.getFullyQualifiedName(*I, temp) },
189-
{ "tag", toString(I->Kind) },
190-
{ I->id } });
188+
{ "name", corpus_.getFullyQualifiedName(I, temp) },
189+
{ "tag", toString(I.Kind) },
190+
{ I.id } });
191191
}
192192
tags_.close("symbols");
193193
}

src/lib/AST/AnyBlock.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,15 +650,15 @@ class TemplateArgBlock
650650
{
651651
if(! I_->isTemplate())
652652
return formatError("only TemplateTArgs may reference a template");
653-
return decodeRecord(R,
653+
return decodeRecord(R,
654654
static_cast<TemplateTArg&>(
655655
*I_.get()).Template, Blob);
656656
}
657657
case TEMPLATE_ARG_NAME:
658658
{
659659
if(! I_->isTemplate())
660660
return formatError("only TemplateTArgs may have a template name");
661-
return decodeRecord(R,
661+
return decodeRecord(R,
662662
static_cast<TemplateTArg&>(
663663
*I_.get()).Name, Blob);
664664
}

src/lib/AST/Bitcode.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,5 @@
1414
namespace clang {
1515
namespace mrdox {
1616

17-
#if 0
18-
void
19-
insertBitcode(
20-
ExecutionContext& ex,
21-
Bitcode&& bitcode)
22-
{
23-
// bitcode.data.
24-
ex.reportResult(
25-
StringRef(bitcode.id),
26-
std::move(bitcode.data));
27-
}
28-
29-
Bitcodes
30-
collectBitcodes(
31-
ToolExecutor& ex)
32-
{
33-
Bitcodes results;
34-
ex.getToolResults()->forEachResult(
35-
[&](StringRef Key, StringRef Value)
36-
{
37-
auto result = results.try_emplace(
38-
Key, std::vector<StringRef>());
39-
result.first->second.emplace_back(Value);
40-
});
41-
return results;
42-
}
43-
#endif
44-
4517
} // mrdox
4618
} // clang

src/lib/AST/Bitcode.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#ifndef MRDOX_LIB_AST_BITCODE_HPP
1313
#define MRDOX_LIB_AST_BITCODE_HPP
1414

15-
#include "lib/Lib/ToolExecutor.hpp"
1615
#include <mrdox/Platform.hpp>
1716
#include <mrdox/MetadataFwd.hpp>
1817
#include <mrdox/Metadata/Info.hpp>

0 commit comments

Comments
 (0)