From cac1bc8b745dc8c51909b4bcf671e0f1900f8e10 Mon Sep 17 00:00:00 2001 From: Krystian Stasiowski Date: Mon, 10 Jun 2024 12:23:29 -0400 Subject: [PATCH] chore: rename 'safe names' to 'legible names' --- src/lib/Gen/adoc/AdocCorpus.hpp | 6 +- src/lib/Gen/adoc/AdocGenerator.cpp | 2 +- src/lib/Gen/adoc/Builder.cpp | 2 +- src/lib/Gen/adoc/Options.cpp | 2 +- src/lib/Gen/adoc/Options.hpp | 2 +- src/lib/Gen/bitcode/BitcodeGenerator.cpp | 4 +- src/lib/Gen/html/HTMLGenerator.cpp | 2 +- src/lib/Gen/html/Options.cpp | 2 +- src/lib/Gen/html/Options.hpp | 2 +- src/lib/Gen/xml/XMLWriter.cpp | 14 ++--- src/lib/Gen/xml/XMLWriter.hpp | 2 +- src/lib/Metadata/DomMetadata.cpp | 2 +- src/lib/Metadata/Function.cpp | 4 +- .../{SafeNames.cpp => LegibleNames.cpp} | 60 +++++++++---------- .../{SafeNames.hpp => LegibleNames.hpp} | 18 +++--- 15 files changed, 62 insertions(+), 62 deletions(-) rename src/lib/Support/{SafeNames.cpp => LegibleNames.cpp} (91%) rename src/lib/Support/{SafeNames.hpp => LegibleNames.hpp} (76%) diff --git a/src/lib/Gen/adoc/AdocCorpus.hpp b/src/lib/Gen/adoc/AdocCorpus.hpp index 519cd7c77..a426ba709 100644 --- a/src/lib/Gen/adoc/AdocCorpus.hpp +++ b/src/lib/Gen/adoc/AdocCorpus.hpp @@ -12,7 +12,7 @@ #define MRDOCS_LIB_GEN_ADOC_ADOCCORPUS_HPP #include -#include "lib/Support/SafeNames.hpp" +#include "lib/Support/LegibleNames.hpp" #include "Options.hpp" #include #include @@ -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) { } diff --git a/src/lib/Gen/adoc/AdocGenerator.cpp b/src/lib/Gen/adoc/AdocGenerator.cpp index bacf7241f..57cc5681c 100644 --- a/src/lib/Gen/adoc/AdocGenerator.cpp +++ b/src/lib/Gen/adoc/AdocGenerator.cpp @@ -14,7 +14,7 @@ #include "Builder.hpp" #include "MultiPageVisitor.hpp" #include "SinglePageVisitor.hpp" -#include "lib/Support/SafeNames.hpp" +#include "lib/Support/LegibleNames.hpp" #include #include #include diff --git a/src/lib/Gen/adoc/Builder.cpp b/src/lib/Gen/adoc/Builder.cpp index 91ea9659f..3b3a31c9b 100644 --- a/src/lib/Gen/adoc/Builder.cpp +++ b/src/lib/Gen/adoc/Builder.cpp @@ -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; diff --git a/src/lib/Gen/adoc/Options.cpp b/src/lib/Gen/adoc/Options.cpp index 933dd351f..b3ed053a8 100644 --- a/src/lib/Gen/adoc/Options.cpp +++ b/src/lib/Gen/adoc/Options.cpp @@ -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); } }; diff --git a/src/lib/Gen/adoc/Options.hpp b/src/lib/Gen/adoc/Options.hpp index 50b11962e..8db45b71e 100644 --- a/src/lib/Gen/adoc/Options.hpp +++ b/src/lib/Gen/adoc/Options.hpp @@ -25,7 +25,7 @@ namespace adoc { */ struct Options { - bool safe_names = true; + bool legible_names = true; std::string template_dir; }; diff --git a/src/lib/Gen/bitcode/BitcodeGenerator.cpp b/src/lib/Gen/bitcode/BitcodeGenerator.cpp index 401f25960..cbf85df8c 100644 --- a/src/lib/Gen/bitcode/BitcodeGenerator.cpp +++ b/src/lib/Gen/bitcode/BitcodeGenerator.cpp @@ -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 #include @@ -26,7 +26,7 @@ class MultiFileBuilder { Corpus const& corpus_; std::string_view outputPath_; - SafeNames names_; + LegibleNames names_; TaskGroup taskGroup_; public: diff --git a/src/lib/Gen/html/HTMLGenerator.cpp b/src/lib/Gen/html/HTMLGenerator.cpp index c95463819..f67224cd8 100644 --- a/src/lib/Gen/html/HTMLGenerator.cpp +++ b/src/lib/Gen/html/HTMLGenerator.cpp @@ -14,7 +14,7 @@ #include "Builder.hpp" #include "MultiPageVisitor.hpp" #include "SinglePageVisitor.hpp" -#include "lib/Support/SafeNames.hpp" +#include "lib/Support/LegibleNames.hpp" #include #include #include diff --git a/src/lib/Gen/html/Options.cpp b/src/lib/Gen/html/Options.cpp index 0baf5612e..c2f4fe029 100644 --- a/src/lib/Gen/html/Options.cpp +++ b/src/lib/Gen/html/Options.cpp @@ -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); } }; diff --git a/src/lib/Gen/html/Options.hpp b/src/lib/Gen/html/Options.hpp index 1cf695cf9..faac05fe7 100644 --- a/src/lib/Gen/html/Options.hpp +++ b/src/lib/Gen/html/Options.hpp @@ -25,7 +25,7 @@ namespace html { */ struct Options { - bool safe_names = false; + bool legible_names = false; std::string template_dir; }; diff --git a/src/lib/Gen/xml/XMLWriter.cpp b/src/lib/Gen/xml/XMLWriter.cpp index b659cd3c0..6fc7c91b6 100644 --- a/src/lib/Gen/xml/XMLWriter.cpp +++ b/src/lib/Gen/xml/XMLWriter.cpp @@ -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 #include #include @@ -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); } }; @@ -139,7 +139,7 @@ build() "\n"; - if(options_.index || options_.safe_names) + if(options_.index || options_.legible_names) writeIndex(); visit(corpus_.globalNamespace(), *this); @@ -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 } }); diff --git a/src/lib/Gen/xml/XMLWriter.hpp b/src/lib/Gen/xml/XMLWriter.hpp index 9f8f6e4e1..b78b09411 100644 --- a/src/lib/Gen/xml/XMLWriter.hpp +++ b/src/lib/Gen/xml/XMLWriter.hpp @@ -43,7 +43,7 @@ class XMLWriter { bool index = false; bool prolog = true; - bool safe_names = false; + bool legible_names = false; }; Options options_; diff --git a/src/lib/Metadata/DomMetadata.cpp b/src/lib/Metadata/DomMetadata.cpp index 31b0771db..67e3c1fb0 100644 --- a/src/lib/Metadata/DomMetadata.cpp +++ b/src/lib/Metadata/DomMetadata.cpp @@ -10,7 +10,7 @@ // #include "lib/Support/Radix.hpp" -#include "lib/Support/SafeNames.hpp" +#include "lib/Support/LegibleNames.hpp" #include #include #include diff --git a/src/lib/Metadata/Function.cpp b/src/lib/Metadata/Function.cpp index e2a7808ad..93272dbaa 100644 --- a/src/lib/Metadata/Function.cpp +++ b/src/lib/Metadata/Function.cpp @@ -22,7 +22,7 @@ namespace { struct Item { char const* name; - char const* safe_name; + char const* legible_name; char const* short_name; OperatorKind kind; }; @@ -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_" diff --git a/src/lib/Support/SafeNames.cpp b/src/lib/Support/LegibleNames.cpp similarity index 91% rename from src/lib/Support/SafeNames.cpp rename to src/lib/Support/LegibleNames.cpp index b603d6f4b..f00fe4904 100644 --- a/src/lib/Support/SafeNames.cpp +++ b/src/lib/Support/LegibleNames.cpp @@ -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 @@ -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 @@ -45,12 +45,12 @@ class SafeNames::Impl std::string id_str; }; - std::unordered_map map_; + std::unordered_map map_; // maps unqualified names to all symbols // with that name within the current scope std::unordered_multimap disambiguation_map_; + LegibleNameInfo*> disambiguation_map_; std::string_view getReserved(const Info& I) @@ -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, @@ -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; @@ -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 @@ -340,7 +340,7 @@ class SafeNames::Impl } void - getSafeUnqualified( + getLegibleUnqualified( std::string& result, const SymbolID& id) { @@ -365,7 +365,7 @@ class SafeNames::Impl } void - getSafeQualified( + getLegibleQualified( std::string& result, const SymbolID& id, char delim) @@ -378,18 +378,18 @@ 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) { @@ -397,23 +397,23 @@ SafeNames( impl_ = std::make_unique(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 { @@ -424,7 +424,7 @@ getUnqualified( } std::string -SafeNames:: +LegibleNames:: getQualified( SymbolID const& id, char delim) const @@ -432,12 +432,12 @@ getQualified( 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 @@ -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())); diff --git a/src/lib/Support/SafeNames.hpp b/src/lib/Support/LegibleNames.hpp similarity index 76% rename from src/lib/Support/SafeNames.hpp rename to src/lib/Support/LegibleNames.hpp index 72614256b..b02707e01 100644 --- a/src/lib/Support/SafeNames.hpp +++ b/src/lib/Support/LegibleNames.hpp @@ -3,13 +3,13 @@ // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // -// Copyright (c) 2023 Vinnie Falco (vinnie.falco@gmail.com) +// Copyright (c) 2023 Krystian Stasiowski (sdkrystian@gmail.com) // // Official repository: https://github.com/cppalliance/mrdocs // -#ifndef MRDOCS_LIB_SUPPORT_SAFENAMES_HPP -#define MRDOCS_LIB_SUPPORT_SAFENAMES_HPP +#ifndef MRDOCS_LIB_SUPPORT_LEGIBLENAMES_HPP +#define MRDOCS_LIB_SUPPORT_LEGIBLENAMES_HPP #include #include @@ -19,16 +19,16 @@ namespace clang { namespace mrdocs { -/** A table mapping symbolIDs to safe names. +/** A table mapping symbolIDs to legible names. - A safe name for a symbol is case-insensitive + A legible name for a symbol is case-insensitive unique and only contains characters which are valid for both filenames and URL paths. For filenames this includes only the subset of characters valid for Windows, OSX, and Linux type filesystems. */ -class SafeNames +class LegibleNames { class Impl; @@ -38,13 +38,13 @@ class SafeNames /** Constructor. Upon construction, the entire table of - safe names is built from the corpus. + legible names is built from the corpus. */ - SafeNames( + LegibleNames( Corpus const& corpus, bool enabled); - ~SafeNames() noexcept; + ~LegibleNames() noexcept; std::string getUnqualified(