Skip to content

Commit 47ba542

Browse files
committed
comments and tidy
1 parent 6169bbd commit 47ba542

File tree

3 files changed

+59
-40
lines changed

3 files changed

+59
-40
lines changed

include/mrdox/Corpus.hpp

+9-36
Original file line numberDiff line numberDiff line change
@@ -21,49 +21,22 @@
2121
namespace clang {
2222
namespace mrdox {
2323

24-
class ThreadSafeToolResults
25-
: public tooling::ToolResults
26-
{
27-
public:
28-
void
29-
addResult(
30-
llvm::StringRef Key,
31-
llvm::StringRef Value) override
32-
{
33-
std::unique_lock<std::mutex> LockGuard(Mutex);
34-
Results.addResult(Key, Value);
35-
}
36-
37-
std::vector<std::pair<llvm::StringRef, llvm::StringRef>>
38-
AllKVResults() override
39-
{
40-
return Results.AllKVResults();
41-
}
42-
43-
void
44-
forEachResult(
45-
llvm::function_ref<void(
46-
llvm::StringRef Key, llvm::StringRef Value)> Callback) override
47-
{
48-
Results.forEachResult(Callback);
49-
}
50-
51-
private:
52-
tooling::InMemoryToolResults Results;
53-
std::mutex Mutex;
54-
};
55-
5624
/** The collection of declarations in extracted form.
5725
*/
5826
struct Corpus
5927
{
60-
Corpus() = default;
28+
Corpus();
6129
Corpus(Corpus const&) = delete;
6230
Corpus& operator=(Corpus const&) = delete;
6331

64-
// In ToolResults, the Key is the hashed USR and the value is the
65-
// bitcode-encoded representation of the Info object.
66-
ThreadSafeToolResults toolResults;
32+
/** Holds the results of visiting the AST.
33+
34+
This is a table of key/value pairs where
35+
the key is the SHA1 digest of the USR and
36+
the value is the bitcode-encoded representation
37+
of the Info object.
38+
*/
39+
std::unique_ptr<tooling::ToolResults> toolResults;
6740

6841
Index Idx;
6942

source/lib/Visitor.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Visitor::
3939
reportResult(
4040
StringRef Key, StringRef Value)
4141
{
42-
corpus_.toolResults.addResult(Key, Value);
42+
corpus_.toolResults->addResult(Key, Value);
4343
}
4444

4545
template<typename T>

source/lib/jad/Corpus.cpp

+49-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,50 @@
2222
namespace clang {
2323
namespace mrdox {
2424

25+
namespace {
26+
27+
class ThreadSafeToolResults
28+
: public tooling::ToolResults
29+
{
30+
public:
31+
void
32+
addResult(
33+
llvm::StringRef Key,
34+
llvm::StringRef Value) override
35+
{
36+
std::unique_lock<std::mutex> LockGuard(Mutex);
37+
Results.addResult(Key, Value);
38+
}
39+
40+
std::vector<std::pair<llvm::StringRef, llvm::StringRef>>
41+
AllKVResults() override
42+
{
43+
return Results.AllKVResults();
44+
}
45+
46+
void
47+
forEachResult(
48+
llvm::function_ref<void(
49+
llvm::StringRef Key, llvm::StringRef Value)> Callback) override
50+
{
51+
Results.forEachResult(Callback);
52+
}
53+
54+
private:
55+
tooling::InMemoryToolResults Results;
56+
std::mutex Mutex;
57+
};
58+
59+
} // (anon)
60+
61+
//------------------------------------------------
62+
63+
Corpus::
64+
Corpus()
65+
: toolResults(std::make_unique<ThreadSafeToolResults>())
66+
{
67+
}
68+
2569
//------------------------------------------------
2670

2771
llvm::Error
@@ -58,10 +102,13 @@ buildIndex(
58102
Corpus& corpus,
59103
Config const& cfg)
60104
{
61-
// Collect values into output by key.
105+
/* Collect all symbols. The result is a vector of
106+
one or more bitcodes for each symbol. These will
107+
be merged later.
108+
*/
62109
llvm::outs() << "Collecting symbols\n";
63110
llvm::StringMap<std::vector<StringRef>> USRToBitcode;
64-
corpus.toolResults.forEachResult(
111+
corpus.toolResults->forEachResult(
65112
[&](StringRef Key, StringRef Value)
66113
{
67114
auto R = USRToBitcode.try_emplace(Key, std::vector<StringRef>());
@@ -134,6 +181,5 @@ buildIndex(
134181
return llvm::Error::success();
135182
}
136183

137-
138184
} // mrdox
139185
} // clang

0 commit comments

Comments
 (0)