Added class diagram test case with C++20 module partitions

This commit is contained in:
Bartek Kryza
2023-12-25 17:21:53 +01:00
parent 637112cea5
commit edfaabd4fa
20 changed files with 305 additions and 68 deletions

View File

@@ -139,6 +139,11 @@ void generator::generate_diagram(nlohmann::json &parent) const
if (config().using_namespace)
parent["using_namespace"] = config().using_namespace().to_string();
if (config().using_module)
parent["using_module"] = config().using_module();
if (config().generate_packages.has_value)
parent["package_type"] = to_string(config().package_type());
parent["elements"] = std::vector<nlohmann::json>{};
parent["relationships"] = std::vector<nlohmann::json>{};

View File

@@ -116,6 +116,18 @@ bool diagram::add_with_filesystem_path<common::model::package>(
return add_element(ns, std::move(p));
}
template <>
bool diagram::add_with_module_path<common::model::package>(
const common::model::path & /*parent_path*/,
std::unique_ptr<common::model::package> &&p)
{
LOG_DBG("Adding module package: {}, {}", p->name(), p->full_name(true));
auto ns = p->get_relative_namespace();
return add_element(ns, std::move(p));
}
void diagram::get_parents(
clanguml::common::reference_set<class_> &parents) const
{

View File

@@ -203,6 +203,10 @@ public:
return add_with_namespace_path(std::move(e));
}
if (parent_path.type() == common::model::path_type::kModule) {
return add_with_module_path(parent_path, std::move(e));
}
return add_with_filesystem_path(parent_path, std::move(e));
}
@@ -224,8 +228,6 @@ public:
*/
void get_parents(clanguml::common::reference_set<class_> &parents) const;
friend void print_diagram_tree(const diagram &d, int level);
/**
* @brief Check if diagram contains element by id.
*
@@ -252,6 +254,10 @@ private:
template <typename ElementT>
bool add_with_namespace_path(std::unique_ptr<ElementT> &&e);
template <typename ElementT>
bool add_with_module_path(
const common::model::path &parent_path, std::unique_ptr<ElementT> &&e);
template <typename ElementT>
bool add_with_filesystem_path(
const common::model::path &parent_path, std::unique_ptr<ElementT> &&e);
@@ -317,19 +323,53 @@ bool diagram::add_with_namespace_path(std::unique_ptr<ElementT> &&e)
return false;
}
template <typename ElementT>
bool diagram::add_with_module_path(
const common::model::path &parent_path, std::unique_ptr<ElementT> &&e)
{
const auto element_type = e->type_name();
// Make sure all parent modules are already packages in the
// model
for (auto it = parent_path.begin(); it != parent_path.end(); it++) {
auto pkg = std::make_unique<common::model::package>(
e->using_namespace(), parent_path.type());
pkg->set_name(*it);
auto ns =
common::model::path(parent_path.begin(), it, parent_path.type());
// ns.pop_back();
pkg->set_namespace(ns);
pkg->set_id(common::to_id(pkg->full_name(false)));
add(ns, std::move(pkg));
}
const auto base_name = e->name();
const auto full_name = e->full_name(false);
auto &e_ref = *e;
if (add_element(parent_path, std::move(e))) {
element_view<ElementT>::add(std::ref(e_ref));
return true;
}
return false;
}
template <typename ElementT>
bool diagram::add_with_filesystem_path(
const common::model::path &parent_path, std::unique_ptr<ElementT> &&e)
{
const auto element_type = e->type_name();
// Make sure all parent directories are already packages in the
// Make sure all parent modules are already packages in the
// model
for (auto it = parent_path.begin(); it != parent_path.end(); it++) {
auto pkg =
std::make_unique<common::model::package>(e->using_namespace());
auto pkg = std::make_unique<common::model::package>(
e->using_namespace(), parent_path.type());
pkg->set_name(*it);
auto ns = common::model::path(parent_path.begin(), it);
auto ns =
common::model::path(parent_path.begin(), it, parent_path.type());
// ns.pop_back();
pkg->set_namespace(ns);
pkg->set_id(common::to_id(pkg->full_name(false)));
@@ -405,6 +445,11 @@ template <>
bool diagram::add_with_namespace_path<common::model::package>(
std::unique_ptr<common::model::package> &&p);
template <>
bool diagram::add_with_module_path<common::model::package>(
const common::model::path &parent_path,
std::unique_ptr<common::model::package> &&p);
template <>
bool diagram::add_with_filesystem_path<common::model::package>(
const common::model::path &parent_path,

View File

@@ -213,7 +213,7 @@ bool translation_unit_visitor::VisitClassTemplateSpecializationDecl(
}
if (!template_specialization.template_specialization_found()) {
// Only do this if we haven't found a bettern specialization during
// Only do this if we haven't found a better specialization during
// construction of the template specialization
const auto maybe_id =
id_mapper().get_global_id(cls->getSpecializedTemplate()->getID());