Skip to content

Commit

Permalink
Renamed common::id_t to eid_t to avoid conflicts with system id_t
Browse files Browse the repository at this point in the history
  • Loading branch information
bkryza committed Jun 5, 2024
1 parent 2cf9d2f commit 420475a
Show file tree
Hide file tree
Showing 57 changed files with 370 additions and 356 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

namespace clanguml::class_diagram::generators::mermaid {

using clanguml::common::eid_t;
using clanguml::common::generators::mermaid::indent;
using clanguml::common::generators::mermaid::render_name;

Expand Down Expand Up @@ -405,7 +406,7 @@ void generator::generate_relationships(
LOG_DBG("== Processing relationship {}", to_string(r.type()));

std::stringstream relstr;
clanguml::common::id_t destination{};
eid_t destination{};
try {
destination = r.destination();

Expand Down Expand Up @@ -513,7 +514,7 @@ void generator::generate_relationships(
LOG_DBG("== Processing relationship {}", to_string(r.type()));

std::stringstream relstr;
clanguml::common::id_t destination{};
eid_t destination{};
try {
destination = r.destination();

Expand Down Expand Up @@ -584,7 +585,7 @@ void generator::generate_relationships(const enum_ &e, std::ostream &ostr) const
if (!model().should_include(r.type()))
continue;

clanguml::common::id_t destination{};
eid_t destination{};
std::stringstream relstr;
try {
destination = r.destination();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ void generator::generate_relationships(
plantuml_common::to_plantuml(r, config()));

std::stringstream relstr;
clanguml::common::id_t destination{};
eid_t destination{};
try {
destination = r.destination();

Expand Down Expand Up @@ -583,7 +583,7 @@ void generator::generate_relationships(
LOG_DBG("== Processing relationship {}", to_string(r.type()));

std::stringstream relstr;
clanguml::common::id_t destination{};
eid_t destination{};
try {
destination = r.destination();

Expand Down Expand Up @@ -664,7 +664,7 @@ void generator::generate_relationships(const enum_ &e, std::ostream &ostr) const
if (!model().should_include(r.type()))
continue;

clanguml::common::id_t destination{};
eid_t destination{};
std::stringstream relstr;
try {
destination = r.destination();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ using clanguml::class_diagram::model::class_member;
using clanguml::class_diagram::model::class_method;
using clanguml::class_diagram::model::concept_;
using clanguml::class_diagram::model::enum_;
using clanguml::common::eid_t;
using clanguml::common::model::access_t;
using clanguml::common::model::package;
using clanguml::common::model::relationship;
Expand Down
2 changes: 0 additions & 2 deletions src/class_diagram/model/class.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ struct hash<std::reference_wrapper<clanguml::class_diagram::model::class_>> {
const std::reference_wrapper<clanguml::class_diagram::model::class_>
&key) const
{
using clanguml::common::id_t;

return std::hash<uint64_t>{}(key.get().id().value());
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/class_diagram/model/class_parent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ void class_parent::set_name(const std::string &name) { name_ = name; }

std::string class_parent::name() const { return name_; }

void class_parent::set_id(clanguml::common::id_t id) { id_ = id; }
void class_parent::set_id(eid_t id) { id_ = id; }

clanguml::common::id_t class_parent::id() const noexcept { return id_; }
eid_t class_parent::id() const noexcept { return id_; }

void class_parent::is_virtual(bool is_virtual) { is_virtual_ = is_virtual; }

Expand Down
8 changes: 5 additions & 3 deletions src/class_diagram/model/class_parent.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

namespace clanguml::class_diagram::model {

using clanguml::common::eid_t;

/**
* @brief Class parent relationship model.
*
Expand Down Expand Up @@ -59,14 +61,14 @@ class class_parent {
*
* @param id Id of the parent class.
*/
void set_id(clanguml::common::id_t id);
void set_id(eid_t id);

/**
* @brief Get the id of class parent.
*
* @return Id of the parent class.
*/
clanguml::common::id_t id() const noexcept;
eid_t id() const noexcept;

/**
* @brief Set whether the parent is virtual.
Expand Down Expand Up @@ -97,7 +99,7 @@ class class_parent {
common::model::access_t access() const;

private:
clanguml::common::id_t id_{};
eid_t id_{};
std::string name_;
bool is_virtual_{false};
common::model::access_t access_{common::model::access_t::kPublic};
Expand Down
10 changes: 5 additions & 5 deletions src/class_diagram/model/diagram.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ common::optional_ref<clanguml::common::model::diagram_element> diagram::get(
}

common::optional_ref<clanguml::common::model::diagram_element> diagram::get(
const clanguml::common::id_t id) const
const eid_t id) const
{
common::optional_ref<clanguml::common::model::diagram_element> res;

Expand Down Expand Up @@ -153,7 +153,7 @@ void diagram::get_parents(
}
}

bool diagram::has_element(clanguml::common::id_t id) const
bool diagram::has_element(eid_t id) const
{
const auto has_class = std::any_of(classes().begin(), classes().end(),
[id](const auto &c) { return c.get().id() == id; });
Expand All @@ -171,7 +171,7 @@ bool diagram::has_element(clanguml::common::id_t id) const
[id](const auto &c) { return c.get().id() == id; });
}

std::string diagram::to_alias(clanguml::common::id_t id) const
std::string diagram::to_alias(eid_t id) const
{
LOG_DBG("Looking for alias for {}", id);

Expand Down Expand Up @@ -224,12 +224,12 @@ inja::json diagram::context() const

void diagram::remove_redundant_dependencies()
{
using common::id_t;
using common::eid_t;
using common::model::relationship;
using common::model::relationship_t;

for (auto &c : element_view<class_>::view()) {
std::set<id_t> dependency_relationships_to_remove;
std::set<eid_t> dependency_relationships_to_remove;

for (auto &r : c.get().relationships()) {
if (r.type() != relationship_t::kDependency)
Expand Down
11 changes: 5 additions & 6 deletions src/class_diagram/model/diagram.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class diagram : public common::model::diagram,
* @param id Element id.
* @return Optional reference to a diagram element.
*/
opt_ref<diagram_element> get(common::id_t id) const override;
opt_ref<diagram_element> get(eid_t id) const override;

/**
* @brief Get list of references to classes in the diagram model.
Expand Down Expand Up @@ -172,7 +172,7 @@ class diagram : public common::model::diagram,
* @param id Id of the element
* @return Optional reference to a diagram element
*/
template <typename ElementT> opt_ref<ElementT> find(common::id_t id) const;
template <typename ElementT> opt_ref<ElementT> find(eid_t id) const;

/**
* @brief Get reference to vector of elements of specific type
Expand Down Expand Up @@ -218,7 +218,7 @@ class diagram : public common::model::diagram,
* @param id Id of the diagram element.
* @return PlantUML alias.
*/
std::string to_alias(common::id_t id) const;
std::string to_alias(eid_t id) const;

/**
* @brief Given an initial set of classes, add all their parents to the
Expand All @@ -235,7 +235,7 @@ class diagram : public common::model::diagram,
* @param id Id of the element.
* @return True, if diagram contains an element with a specific id.
*/
bool has_element(common::id_t id) const override;
bool has_element(eid_t id) const override;

/**
* @brief Remove redundant dependency relationships
Expand Down Expand Up @@ -431,8 +431,7 @@ std::vector<opt_ref<ElementT>> diagram::find(
return result;
}

template <typename ElementT>
opt_ref<ElementT> diagram::find(common::id_t id) const
template <typename ElementT> opt_ref<ElementT> diagram::find(eid_t id) const
{
for (const auto &element : element_view<ElementT>::view()) {
if (element.get().id() == id) {
Expand Down
20 changes: 10 additions & 10 deletions src/class_diagram/visitor/translation_unit_visitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ bool translation_unit_visitor::VisitEnumDecl(clang::EnumDecl *enm)
const auto *parent = enm->getParent();

// Id of parent class or struct in which this enum is potentially nested
std::optional<common::id_t> parent_id_opt;
std::optional<eid_t> parent_id_opt;

if (parent != nullptr) {
const auto *parent_record_decl =
clang::dyn_cast<clang::RecordDecl>(parent);

if (parent_record_decl != nullptr) {
common::id_t local_id{parent_record_decl->getID()};
eid_t local_id{parent_record_decl->getID()};

// First check if the parent has been added to the diagram as
// regular class
Expand Down Expand Up @@ -222,7 +222,7 @@ bool translation_unit_visitor::VisitClassTemplateSpecializationDecl(
if (!template_specialization.template_specialization_found()) {
// Only do this if we haven't found a better specialization during
// construction of the template specialization
const common::id_t ast_id{cls->getSpecializedTemplate()->getID()};
const eid_t ast_id{cls->getSpecializedTemplate()->getID()};
const auto maybe_id = id_mapper().get_global_id(ast_id);
if (maybe_id.has_value())
template_specialization.add_relationship(
Expand Down Expand Up @@ -621,7 +621,7 @@ void translation_unit_visitor::process_concept_specialization_relationships(
should_include(cpt)) {

const auto cpt_name = cpt->getNameAsString();
const common::id_t ast_id{cpt->getID()};
const eid_t ast_id{cpt->getID()};
const auto maybe_id = id_mapper().get_global_id(ast_id);
if (!maybe_id)
return;
Expand Down Expand Up @@ -707,7 +707,7 @@ bool translation_unit_visitor::VisitCXXRecordDecl(clang::CXXRecordDecl *cls)
if (cls->isTemplated() && (cls->getDescribedTemplate() != nullptr)) {
// If the described templated of this class is already in the model
// skip it:
const common::id_t ast_id{cls->getDescribedTemplate()->getID()};
const eid_t ast_id{cls->getDescribedTemplate()->getID()};
if (id_mapper().get_global_id(ast_id))
return true;
}
Expand Down Expand Up @@ -869,7 +869,7 @@ void translation_unit_visitor::process_record_parent(
{
const auto *parent = cls->getParent();

std::optional<common::id_t> id_opt;
std::optional<eid_t> id_opt;

auto parent_ns = ns;
if (parent != nullptr) {
Expand All @@ -879,7 +879,7 @@ void translation_unit_visitor::process_record_parent(
if (parent_record_decl != nullptr) {
parent_ns = common::get_tag_namespace(*parent_record_decl);

common::id_t ast_id{parent_record_decl->getID()};
eid_t ast_id{parent_record_decl->getID()};

// First check if the parent has been added to the diagram as
// regular class
Expand Down Expand Up @@ -2176,7 +2176,7 @@ void translation_unit_visitor::add_concept(std::unique_ptr<concept_> &&c)

void translation_unit_visitor::find_instantiation_relationships(
common::model::template_element &template_instantiation_base,
const std::string &full_name, common::id_t templated_decl_id)
const std::string &full_name, eid_t templated_decl_id)
{
auto &template_instantiation = dynamic_cast<class_diagram::model::class_ &>(
template_instantiation_base);
Expand All @@ -2187,7 +2187,7 @@ void translation_unit_visitor::find_instantiation_relationships(
std::string best_match_full_name{};
auto full_template_name = template_instantiation.full_name(false);
int best_match{};
common::id_t best_match_id{};
eid_t best_match_id{};

for (const auto templ : diagram().classes()) {
if (templ.get() == template_instantiation)
Expand All @@ -2206,7 +2206,7 @@ void translation_unit_visitor::find_instantiation_relationships(
}

auto templated_decl_global_id =
id_mapper().get_global_id(templated_decl_id).value_or(common::id_t{});
id_mapper().get_global_id(templated_decl_id).value_or(eid_t{});

if (best_match_id.value() > 0) {
destination = best_match_full_name;
Expand Down
6 changes: 3 additions & 3 deletions src/class_diagram/visitor/translation_unit_visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ using clanguml::class_diagram::model::concept_;
using clanguml::class_diagram::model::diagram;
using clanguml::class_diagram::model::enum_;
using clanguml::class_diagram::model::method_parameter;
using clanguml::common::eid_t;
using clanguml::common::model::access_t;
using clanguml::common::model::namespace_;
using clanguml::common::model::relationship;
Expand Down Expand Up @@ -149,7 +150,7 @@ class translation_unit_visitor

void find_instantiation_relationships(
common::model::template_element &template_instantiation_base,
const std::string &full_name, common::id_t templated_decl_id);
const std::string &full_name, eid_t templated_decl_id);

private:
/**
Expand Down Expand Up @@ -432,8 +433,7 @@ class translation_unit_visitor

template_builder_t template_builder_;

std::map<common::id_t,
std::unique_ptr<clanguml::class_diagram::model::class_>>
std::map<eid_t, std::unique_ptr<clanguml::class_diagram::model::class_>>
forward_declarations_;

std::map<int64_t /* local anonymous struct id */,
Expand Down
22 changes: 11 additions & 11 deletions src/common/clang_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -415,52 +415,52 @@ bool is_subexpr_of(const clang::Stmt *parent_stmt, const clang::Stmt *sub_stmt)
[sub_stmt](const auto *e) { return is_subexpr_of(e, sub_stmt); });
}

template <> common::id_t to_id(const std::string &full_name)
template <> eid_t to_id(const std::string &full_name)
{
return static_cast<common::id_t>(std::hash<std::string>{}(full_name));
return static_cast<eid_t>(std::hash<std::string>{}(full_name));
}

common::id_t to_id(const clang::QualType &type, const clang::ASTContext &ctx)
eid_t to_id(const clang::QualType &type, const clang::ASTContext &ctx)
{
return to_id(common::to_string(type, ctx));
}

template <> common::id_t to_id(const clang::NamespaceDecl &declaration)
template <> eid_t to_id(const clang::NamespaceDecl &declaration)
{
return to_id(get_qualified_name(declaration));
}

template <> common::id_t to_id(const clang::RecordDecl &declaration)
template <> eid_t to_id(const clang::RecordDecl &declaration)
{
return to_id(get_qualified_name(declaration));
}

template <> common::id_t to_id(const clang::EnumDecl &declaration)
template <> eid_t to_id(const clang::EnumDecl &declaration)
{
return to_id(get_qualified_name(declaration));
}

template <> common::id_t to_id(const clang::TagDecl &declaration)
template <> eid_t to_id(const clang::TagDecl &declaration)
{
return to_id(get_qualified_name(declaration));
}

template <> common::id_t to_id(const clang::CXXRecordDecl &declaration)
template <> eid_t to_id(const clang::CXXRecordDecl &declaration)
{
return to_id(get_qualified_name(declaration));
}

template <> common::id_t to_id(const clang::EnumType &t)
template <> eid_t to_id(const clang::EnumType &t)
{
return to_id(*t.getDecl());
}

template <> common::id_t to_id(const std::filesystem::path &file)
template <> eid_t to_id(const std::filesystem::path &file)
{
return to_id(file.lexically_normal().string());
}

template <> common::id_t to_id(const clang::TemplateArgument &template_argument)
template <> eid_t to_id(const clang::TemplateArgument &template_argument)
{
if (template_argument.getKind() == clang::TemplateArgument::Type) {
if (const auto *enum_type =
Expand Down
Loading

0 comments on commit 420475a

Please sign in to comment.