Skip to content

Commit 82eaeec

Browse files
committed
UndocumentedInfoSet stores InfoKind
#feat
1 parent 9decbdb commit 82eaeec

File tree

4 files changed

+49
-31
lines changed

4 files changed

+49
-31
lines changed

src/lib/AST/ASTVisitor.cpp

+14-4
Original file line numberDiff line numberDiff line change
@@ -3362,9 +3362,9 @@ checkUndocumented(
33623362
}
33633363
// If the symbol is undocumented, check if we haven't seen a
33643364
// documented version before.
3365-
auto const it = info_.find(id);
3366-
if (it != info_.end() &&
3367-
it->get()->javadoc)
3365+
if (auto const infoIt = info_.find(id);
3366+
infoIt != info_.end() &&
3367+
infoIt->get()->javadoc)
33683368
{
33693369
return {};
33703370
}
@@ -3373,7 +3373,17 @@ checkUndocumented(
33733373
// symbols we've seen so far in this translation unit.
33743374
if (config_->warnIfUndocumented)
33753375
{
3376-
undocumented_.insert({id, extractName(D)});
3376+
auto const undocIt = undocumented_.find(id);
3377+
if (undocIt == undocumented_.end())
3378+
{
3379+
InfoKind const kind = InfoTy::kind_id;
3380+
undocumented_.insert(UndocumentedInfo{id, extractName(D), kind});
3381+
}
3382+
// Populate the location
3383+
auto handle = undocumented_.extract(undocIt);
3384+
UndocumentedInfo& UI = handle.value();
3385+
populate(dynamic_cast<SourceInfo&>(UI), D);
3386+
undocumented_.insert(std::move(handle));
33773387
}
33783388
return Unexpected(Error("Undocumented"));
33793389
}

src/lib/Gen/hbs/Builder.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ Builder(
202202
return nullptr;
203203
}
204204
dom::Value decls = sourceInfo.get("decl");
205-
if(dom::Value def = sourceInfo.get("def"))
205+
if (dom::Value def = sourceInfo.get("def"))
206206
{
207207
// for classes/enums, prefer the definition
208208
if (dom::Value const kind = v.get("kind");
@@ -423,7 +423,7 @@ commonTemplatesDir() const
423423

424424
std::string
425425
Builder::
426-
commonTemplatesDir(std::string_view subdir) const
426+
commonTemplatesDir(std::string_view const subdir) const
427427
{
428428
Config const& config = domCorpus->config;
429429
return files::appendPath(

src/lib/Lib/ExecutionContext.cpp

+3-13
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,7 @@ report(
5959
UndocumentedInfoSet&& undocumented)
6060
{
6161
InfoSet info = std::move(results);
62-
// KRYSTIAN TODO: read stage will be required to
63-
// update Info references once we switch to using Info*
64-
#if 0
65-
{
66-
std::shared_lock<std::shared_mutex> read_lock(mutex_);
67-
}
68-
#endif
69-
70-
std::unique_lock<std::shared_mutex> write_lock(mutex_);
62+
std::unique_lock write_lock(mutex_);
7163

7264
// Add all new Info to the existing set.
7365
info_.merge(info);
@@ -83,16 +75,14 @@ report(
8375
// Merge diagnostics and report any new messages.
8476
diags_.mergeAndReport(std::move(diags));
8577

86-
87-
8878
// Merge undocumented symbols and remove any symbols
8979
// from undocumented that we can find in info_ with
9080
// documentation from other translation units.
9181
undocumented_.merge(undocumented);
9282
for (auto it = undocumented_.begin(); it != undocumented_.end();)
9383
{
94-
auto infoIt = info_.find(it->first);
95-
if (infoIt != info_.end() &&
84+
if (auto infoIt = info_.find(it->id);
85+
infoIt != info_.end() &&
9686
infoIt->get()->javadoc)
9787
{
9888
it = undocumented_.erase(it);

src/lib/Lib/Info.hpp

+30-12
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,25 @@ struct InfoPtrEqual
116116
using InfoSet = std::unordered_set<
117117
std::unique_ptr<Info>, InfoPtrHasher, InfoPtrEqual>;
118118

119-
struct SymbolIDNameHasher {
119+
struct UndocumentedInfo final : SourceInfo {
120+
SymbolID id;
121+
std::string name;
122+
InfoKind kind;
123+
124+
constexpr
125+
UndocumentedInfo(
126+
SymbolID id_,
127+
std::string name_,
128+
InfoKind kind_) noexcept
129+
: SourceInfo()
130+
, id(id_)
131+
, name(std::move(name_))
132+
, kind(kind_)
133+
{
134+
}
135+
};
136+
137+
struct UndocumentedInfoHasher {
120138
using is_transparent = void;
121139

122140
std::size_t
@@ -125,41 +143,41 @@ struct SymbolIDNameHasher {
125143
}
126144

127145
std::size_t
128-
operator()(std::pair<SymbolID, std::string> const& I) const {
129-
return std::hash<SymbolID>()(I.first);
146+
operator()(UndocumentedInfo const& I) const {
147+
return std::hash<SymbolID>()(I.id);
130148
}
131149
};
132150

133-
struct SymbolIDNameEqual {
151+
struct UndocumentedInfoEqual {
134152
using is_transparent = void;
135153

136154
bool
137155
operator()(
138-
std::pair<SymbolID, std::string> const& a,
139-
std::pair<SymbolID, std::string> const& b) const
156+
UndocumentedInfo const& a,
157+
UndocumentedInfo const& b) const
140158
{
141-
return a.first == b.first;
159+
return a.id == b.id;
142160
}
143161

144162
bool
145163
operator()(
146-
std::pair<SymbolID, std::string> const& a,
164+
UndocumentedInfo const& a,
147165
SymbolID const& b) const
148166
{
149-
return a.first == b;
167+
return a.id == b;
150168
}
151169

152170
bool
153171
operator()(
154172
SymbolID const& a,
155-
std::pair<SymbolID, std::string> const& b) const
173+
UndocumentedInfo const& b) const
156174
{
157-
return a == b.first;
175+
return a == b.id;
158176
}
159177
};
160178

161179
using UndocumentedInfoSet = std::unordered_set<
162-
std::pair<SymbolID, std::string>, SymbolIDNameHasher, SymbolIDNameEqual>;
180+
UndocumentedInfo, UndocumentedInfoHasher, UndocumentedInfoEqual>;
163181

164182
} // clang::mrdocs
165183

0 commit comments

Comments
 (0)