Skip to content

Commit

Permalink
fix: safename disambiguation
Browse files Browse the repository at this point in the history
  • Loading branch information
sdkrystian authored and alandefreitas committed Sep 27, 2023
1 parent 0ec670a commit a2e033b
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{#if relfileprefix}}:relfileprefix: {{relfileprefix}}{{/if}}
{{#with symbol}}
[#{{#if (is_multipage)}}{{id}}{{else}}{{ref}}{{/if}}]
{{> (lookup . 'kind') symbol=.}}
{{/with}}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{{!-- enum --}}
[#{{symbol.id}}]
== {{#if symbol.name}}Enum {{symbol.name}}{{else}}Unnamed enum{{/if}}

{{symbol.doc.brief}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{{!-- field --}}
[#{{symbol.id}}]
== {{symbol.name}}

{{symbol.doc.brief}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{{!-- function --}}
[#{{symbol.id}}]
== {{symbol.name}}

{{symbol.doc.brief}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{{!-- namespace --}}
[#{{symbol.id}}]
== {{#if symbol.name}}Namespace {{symbol.name}}{{else}}Unnamed namespace{{/if}}

[,cols=2]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{{!-- record --}}
[#{{symbol.id}}]
== {{#if symbol.name}}Class {{symbol.name}}{{else}}Unnamed class{{/if}}

{{symbol.doc.brief}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{{!-- typedef --}}
[#{{symbol.id}}]
== {{symbol.name}}

{{symbol.doc.brief}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{{!-- variable --}}
[#{{symbol.id}}]
== {{symbol.name}}

{{symbol.doc.brief}}
Expand Down
20 changes: 10 additions & 10 deletions src/lib/Support/SafeNames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,25 +213,25 @@ class SafeNames::Impl
// to uniquely identify each symbol. then, update all symbols with the new value.
if(! disambig_emplaced)
{
std::uint8_t n_chars = 1;
std::uint8_t n_chars = 0;
std::string_view id_str = it->second.id_str;
for(const SymbolID& other : disambig_it->second)
for(const SymbolID& other_id : disambig_it->second)
{
std::string_view other_id_str =
map_.find(other)->second.id_str;
auto& other = map_.find(other_id)->second;
auto [mismatch_id, mismatch_other] =
std::mismatch(id_str.begin(), id_str.end(),
other_id_str.begin(), other_id_str.end());
const auto n_required = std::distance(
other.id_str.begin(), other.id_str.end());
std::uint8_t n_required = std::distance(
id_str.begin(), mismatch_id) + 1;
n_chars = std::max(n_chars,
static_cast<std::uint8_t>(n_required));
n_chars = std::max({
n_chars, other.disambig_chars, n_required});
}

MRDOX_ASSERT(n_chars);
// update the number of disambiguation characters for each symbol
it->second.disambig_chars = n_chars;
for(const SymbolID& other : disambig_it->second)
map_.find(other)->second.disambig_chars = n_chars;
for(const SymbolID& other_id : disambig_it->second)
map_.find(other_id)->second.disambig_chars = n_chars;

}
disambig_it->second.push_back(I->id);
Expand Down

0 comments on commit a2e033b

Please sign in to comment.