Initial refactor of namespace handling

This commit is contained in:
Bartek Kryza
2022-03-04 23:38:18 +01:00
parent bee20e7f26
commit a67b459437
40 changed files with 620 additions and 201 deletions

View File

@@ -154,14 +154,14 @@ translation_unit_context::get_type_alias_template(
void translation_unit_context::push_namespace(const std::string &ns)
{
namespace_.push_back(ns);
ns_ |= ns;
}
void translation_unit_context::pop_namespace() { namespace_.pop_back(); }
void translation_unit_context::pop_namespace() { ns_.pop_back(); }
const std::vector<std::string> &translation_unit_context::get_namespace() const
const common::model::namespace_ &translation_unit_context::get_namespace() const
{
return namespace_;
return ns_;
}
const cppast::cpp_entity_index &translation_unit_context::entity_index() const

View File

@@ -66,7 +66,7 @@ public:
void pop_namespace();
const std::vector<std::string> &get_namespace() const;
const common::model::namespace_ &get_namespace() const;
const cppast::cpp_entity_index &entity_index() const;
@@ -80,7 +80,7 @@ public:
private:
// Current visitor namespace
std::vector<std::string> namespace_;
common::model::namespace_ ns_;
// Reference to the cppast entity index
cppast::cpp_entity_index &entity_index_;

View File

@@ -200,7 +200,7 @@ void translation_unit_visitor::process_type_alias_template(
cx::util::full_name(ctx.get_namespace(), at),
type_safe::ref(at.type_alias().underlying_type()));
if (ctx.config().should_include(tinst->get_namespace(), tinst->name()))
if (ctx.config().should_include(tinst->get_namespace() | tinst->name()))
ctx.diagram().add_class(std::move(tinst));
}
}
@@ -222,15 +222,14 @@ void translation_unit_visitor::process_type_alias(
void translation_unit_visitor::process_namespace(
const cppast::cpp_entity &e, const cppast::cpp_namespace &ns_declaration)
{
std::vector<std::string> package_parent = ctx.get_namespace();
auto package_path = package_parent;
package_path.push_back(e.name());
auto package_parent = ctx.get_namespace();
auto package_path = package_parent | e.name();
auto usn = util::split(ctx.config().using_namespace()[0], "::");
auto usn = ctx.config().using_namespace();
if (ctx.config().should_include_package(util::join(package_path, "::"))) {
if (ctx.config().should_include_package(package_path)) {
auto p = std::make_unique<common::model::package>(usn);
util::remove_prefix(package_path, usn);
package_path = package_path.relative_to(usn);
p->set_name(e.name());
p->set_namespace(package_parent);
@@ -267,8 +266,7 @@ void translation_unit_visitor::process_enum_declaration(
return;
}
auto e_ptr = std::make_unique<enum_>(
util::split(ctx.config().using_namespace()[0], "::"));
auto e_ptr = std::make_unique<enum_>(ctx.config().using_namespace());
auto &e = *e_ptr;
e.set_name(enm.name());
e.set_namespace(ctx.get_namespace());
@@ -312,8 +310,7 @@ void translation_unit_visitor::process_class_declaration(
const cppast::cpp_class &cls,
type_safe::optional_ref<const cppast::cpp_template_specialization> tspec)
{
auto c_ptr = std::make_unique<class_>(
util::split(ctx.config().using_namespace()[0], "::"));
auto c_ptr = std::make_unique<class_>(ctx.config().using_namespace());
auto &c = *c_ptr;
c.is_struct(cls.class_kind() == cppast::cpp_class_kind::struct_t);
// c.set_name(cx::util::full_name(ctx.get_namespace(), cls));
@@ -1275,8 +1272,7 @@ bool translation_unit_visitor::find_relationships_in_template_instantiation(
const auto [ns, base_name] = cx::util::split_ns(fn);
auto ns_and_name = ns;
ns_and_name.push_back(base_name);
auto ns_and_name = ns | base_name;
auto full_name = fmt::format("{}", fmt::join(ns_and_name, "::"));
@@ -1403,8 +1399,7 @@ std::unique_ptr<class_> translation_unit_visitor::build_template_instantiation(
std::optional<clanguml::class_diagram::model::class_ *> parent)
{
// Create class_ instance to hold the template instantiation
auto tinst_ptr = std::make_unique<class_>(
util::split(ctx.config().using_namespace()[0], "::"));
auto tinst_ptr = std::make_unique<class_>(ctx.config().using_namespace());
auto &tinst = *tinst_ptr;
std::string full_template_name;
@@ -1430,7 +1425,7 @@ std::unique_ptr<class_> translation_unit_visitor::build_template_instantiation(
// Extract namespace from base template name
const auto [ns, name] = cx::util::split_ns(tinst_full_name);
tinst.set_name(name);
if (ns.empty())
if (ns.is_empty())
tinst.set_namespace(ctx.get_namespace());
else
tinst.set_namespace(ns);