Skip to content

Commit

Permalink
chore: rename 'safe names' to 'legible names'
Browse files Browse the repository at this point in the history
  • Loading branch information
sdkrystian committed Jun 12, 2024
1 parent ab29a11 commit cac1bc8
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 62 deletions.
6 changes: 3 additions & 3 deletions src/lib/Gen/adoc/AdocCorpus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#define MRDOCS_LIB_GEN_ADOC_ADOCCORPUS_HPP

#include <mrdocs/Platform.hpp>
#include "lib/Support/SafeNames.hpp"
#include "lib/Support/LegibleNames.hpp"
#include "Options.hpp"
#include <mrdocs/Metadata/DomMetadata.hpp>
#include <optional>
Expand All @@ -25,14 +25,14 @@ class AdocCorpus : public DomCorpus
{
public:
Options options;
SafeNames names_;
LegibleNames names_;

AdocCorpus(
Corpus const& corpus,
Options&& opts)
: DomCorpus(corpus)
, options(std::move(opts))
, names_(corpus, options.safe_names)
, names_(corpus, options.legible_names)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/Gen/adoc/AdocGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "Builder.hpp"
#include "MultiPageVisitor.hpp"
#include "SinglePageVisitor.hpp"
#include "lib/Support/SafeNames.hpp"
#include "lib/Support/LegibleNames.hpp"
#include <mrdocs/Metadata/DomMetadata.hpp>
#include <mrdocs/Support/Error.hpp>
#include <mrdocs/Support/Path.hpp>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Gen/adoc/Builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ Builder::
getRelPrefix(std::size_t depth)
{
std::string rel_prefix;
if(! depth || ! domCorpus.options.safe_names ||
if(! depth || ! domCorpus.options.legible_names ||
! domCorpus->config->multipage)
return rel_prefix;
--depth;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Gen/adoc/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct llvm::yaml::MappingTraits<
clang::mrdocs::adoc::YamlKey& yk)
{
auto& opt= yk.opt;
io.mapOptional("safe-names", opt.safe_names);
io.mapOptional("legible-names", opt.legible_names);
io.mapOptional("template-dir", opt.template_dir);
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Gen/adoc/Options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace adoc {
*/
struct Options
{
bool safe_names = true;
bool legible_names = true;
std::string template_dir;
};

Expand Down
4 changes: 2 additions & 2 deletions src/lib/Gen/bitcode/BitcodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include "BitcodeGenerator.hpp"
#include "lib/Support/Error.hpp"
#include "lib/Support/SafeNames.hpp"
#include "lib/Support/LegibleNames.hpp"
#include "lib/AST/Bitcode.hpp"
#include <mrdocs/Support/ThreadPool.hpp>
#include <mrdocs/Metadata.hpp>
Expand All @@ -26,7 +26,7 @@ class MultiFileBuilder
{
Corpus const& corpus_;
std::string_view outputPath_;
SafeNames names_;
LegibleNames names_;
TaskGroup taskGroup_;

public:
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Gen/html/HTMLGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "Builder.hpp"
#include "MultiPageVisitor.hpp"
#include "SinglePageVisitor.hpp"
#include "lib/Support/SafeNames.hpp"
#include "lib/Support/LegibleNames.hpp"
#include <mrdocs/Metadata/DomMetadata.hpp>
#include <mrdocs/Support/Error.hpp>
#include <mrdocs/Support/Path.hpp>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Gen/html/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct llvm::yaml::MappingTraits<
clang::mrdocs::html::YamlKey& yk)
{
auto& opt= yk.opt;
io.mapOptional("safe-names", opt.safe_names);
io.mapOptional("legible-names", opt.legible_names);
io.mapOptional("template-dir", opt.template_dir);
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Gen/html/Options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace html {
*/
struct Options
{
bool safe_names = false;
bool legible_names = false;
std::string template_dir;
};

Expand Down
14 changes: 7 additions & 7 deletions src/lib/Gen/xml/XMLWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "lib/Lib/ConfigImpl.hpp"
#include "lib/Support/Yaml.hpp"
#include "lib/Support/Radix.hpp"
#include "lib/Support/SafeNames.hpp"
#include "lib/Support/LegibleNames.hpp"
#include <mrdocs/Platform.hpp>
#include <llvm/Support/YAMLParser.h>
#include <llvm/Support/YAMLTraits.h>
Expand Down Expand Up @@ -68,7 +68,7 @@ struct llvm::yaml::MappingTraits<
auto& opt= opt_.opt;
io.mapOptional("index", opt.index);
io.mapOptional("prolog", opt.prolog);
io.mapOptional("safe-names", opt.safe_names);
io.mapOptional("legible-names", opt.legible_names);
}
};

Expand Down Expand Up @@ -139,7 +139,7 @@ build()
"<mrdocs xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
" xsi:noNamespaceSchemaLocation=\"https://github.com/cppalliance/mrdocs/raw/develop/mrdocs.rnc\">\n";

if(options_.index || options_.safe_names)
if(options_.index || options_.legible_names)
writeIndex();

visit(corpus_.globalNamespace(), *this);
Expand All @@ -159,14 +159,14 @@ writeIndex()
std::string temp;
temp.reserve(256);
tags_.open("symbols");
if(options_.safe_names)
if(options_.legible_names)
{
SafeNames names(corpus_, true);
LegibleNames names(corpus_, true);
for(auto& I : corpus_)
{
auto safe_name = names.getUnqualified(I.id);
auto legible_name = names.getUnqualified(I.id);
tags_.write("symbol", {}, {
{ "safe", safe_name },
{ "legible", legible_name },
{ "name", corpus_.getFullyQualifiedName(I, temp) },
{ "tag", toString(I.Kind) },
{ I.id } });
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Gen/xml/XMLWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class XMLWriter
{
bool index = false;
bool prolog = true;
bool safe_names = false;
bool legible_names = false;
};
Options options_;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/Metadata/DomMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//

#include "lib/Support/Radix.hpp"
#include "lib/Support/SafeNames.hpp"
#include "lib/Support/LegibleNames.hpp"
#include <mrdocs/Metadata.hpp>
#include <mrdocs/Metadata/DomMetadata.hpp>
#include <llvm/ADT/StringMap.h>
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Metadata/Function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace {
struct Item
{
char const* name;
char const* safe_name;
char const* legible_name;
char const* short_name;
OperatorKind kind;
};
Expand Down Expand Up @@ -122,7 +122,7 @@ getSafeOperatorName(
bool include_keyword) noexcept
{
MRDOCS_ASSERT(Table[to_underlying(kind)].kind == kind);
std::string_view full = Table[to_underlying(kind)].safe_name;
std::string_view full = Table[to_underlying(kind)].legible_name;
if(include_keyword || kind == OperatorKind::None)
return full;
// remove "operator_"
Expand Down
60 changes: 30 additions & 30 deletions src/lib/Support/SafeNames.cpp → src/lib/Support/LegibleNames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//

#include "lib/Support/Radix.hpp"
#include "lib/Support/SafeNames.hpp"
#include "lib/Support/LegibleNames.hpp"
#include "lib/Support/Validate.hpp"
#include "lib/Support/Debug.hpp"
#include <mrdocs/Corpus.hpp>
Expand All @@ -26,17 +26,17 @@
namespace clang {
namespace mrdocs {

class SafeNames::Impl
class LegibleNames::Impl
{
Corpus const& corpus_;

// name used for the global namespace
std::string global_ns_;

// store all info required to generate a safename
struct SafeNameInfo
// store all info required to generate a legible name
struct LegibleNameInfo
{
// safename without disambiguation characters
// legible name without disambiguation characters
std::string_view unqualified;
// number of characters from the SymbolID string
// required to uniquely identify this symbol
Expand All @@ -45,12 +45,12 @@ class SafeNames::Impl
std::string id_str;
};

std::unordered_map<SymbolID, SafeNameInfo> map_;
std::unordered_map<SymbolID, LegibleNameInfo> map_;

// maps unqualified names to all symbols
// with that name within the current scope
std::unordered_multimap<std::string_view,
SafeNameInfo*> disambiguation_map_;
LegibleNameInfo*> disambiguation_map_;

std::string_view
getReserved(const Info& I)
Expand Down Expand Up @@ -236,12 +236,12 @@ class SafeNames::Impl
#define MINIMAL_SUFFIX

void
buildSafeMember(
buildLegibleMember(
const Info& I,
std::string_view name)
{
// generate the unqualified name and SymbolID string
SafeNameInfo& info = map_.emplace(I.id, SafeNameInfo(
LegibleNameInfo& info = map_.emplace(I.id, LegibleNameInfo(
name, 0, toBase16(I.id, true))).first->second;
// if there are other symbols with the same name, then disambiguation
// is required. iterate over the other symbols with the same unqualified name,
Expand Down Expand Up @@ -313,9 +313,9 @@ class SafeNames::Impl
corpus_.globalNamespace();
// treat the global namespace as-if its "name"
// is in the same scope as its members
buildSafeMember(global, global_ns_);
buildLegibleMember(global, global_ns_);
visit(global, *this);
// after generating safenames for every symbol,
// after generating legible names for every symbol,
// set the number of disambiguation characters
// used for the global namespace to zero
map_.at(global.id).disambig_chars = 0;
Expand All @@ -327,7 +327,7 @@ class SafeNames::Impl
traverse(I, [this](const SymbolID& id)
{
if(const Info* M = corpus_.find(id))
buildSafeMember(*M, getUnqualified(*M));
buildLegibleMember(*M, getUnqualified(*M));
});
// clear the disambiguation map after visiting the members,
// then build disambiguation information for each member
Expand All @@ -340,7 +340,7 @@ class SafeNames::Impl
}

void
getSafeUnqualified(
getLegibleUnqualified(
std::string& result,
const SymbolID& id)
{
Expand All @@ -365,7 +365,7 @@ class SafeNames::Impl
}

void
getSafeQualified(
getLegibleQualified(
std::string& result,
const SymbolID& id,
char delim)
Expand All @@ -378,42 +378,42 @@ class SafeNames::Impl
std::views::reverse |
std::views::drop(1))
{
getSafeUnqualified(result, parent);
getLegibleUnqualified(result, parent);
result.push_back(delim);
}
}
getSafeUnqualified(result, id);
getLegibleUnqualified(result, id);
}
};

//------------------------------------------------

SafeNames::
SafeNames(
LegibleNames::
LegibleNames(
Corpus const& corpus,
bool enabled)
{
if(enabled)
impl_ = std::make_unique<Impl>(corpus, "index");
}

SafeNames::
~SafeNames() noexcept = default;
LegibleNames::
~LegibleNames() noexcept = default;

std::string
SafeNames::
LegibleNames::
getUnqualified(
SymbolID const& id) const
{
if(! impl_)
return toBase16(id);
std::string result;
impl_->getSafeUnqualified(result, id);
impl_->getLegibleUnqualified(result, id);
return result;
}

std::string
SafeNames::
LegibleNames::
getUnqualified(
OverloadSet const& os) const
{
Expand All @@ -424,20 +424,20 @@ getUnqualified(
}

std::string
SafeNames::
LegibleNames::
getQualified(
SymbolID const& id,
char delim) const
{
if(! impl_)
return toBase16(id);
std::string result;
impl_->getSafeQualified(result, id, delim);
impl_->getLegibleQualified(result, id, delim);
return result;
}

std::string
SafeNames::
LegibleNames::
getQualified(
OverloadSet const& os,
char delim) const
Expand All @@ -447,12 +447,12 @@ getQualified(
std::string result;
if(os.Parent != SymbolID::global)
{
impl_->getSafeQualified(result, os.Parent, delim);
impl_->getLegibleQualified(result, os.Parent, delim);
result.push_back(delim);
}
// the safename for an overload set is the unqualified
// safe name of its members, without any disambiguation characters.
// members of an overload set use the same safe name regardless of
// the legible name for an overload set is the unqualified
// legible name of its members, without any disambiguation characters.
// members of an overload set use the same legible name regardless of
// whether they belong to an overload set
result.append(impl_->getUnqualified(
os.Members.front()));
Expand Down
Loading

0 comments on commit cac1bc8

Please sign in to comment.