Initial refactor

This commit is contained in:
Bartek Kryza
2021-08-08 23:08:06 +02:00
parent af50446972
commit 42b9a481d1
3 changed files with 103 additions and 81 deletions

View File

@@ -513,30 +513,28 @@ bool tu_visitor::process_field_with_template_instantiation(
const cppast::cpp_member_variable &mv, const cppast::cpp_type &tr, const cppast::cpp_member_variable &mv, const cppast::cpp_type &tr,
class_ &c, class_member &m, cppast::cpp_access_specifier_kind as) class_ &c, class_member &m, cppast::cpp_access_specifier_kind as)
{ {
LOG_DBG("Processing field with template instatiation type {}", LOG_DBG("Processing field with template instantiation type {}",
cppast::to_string(tr)); cppast::to_string(tr));
bool res = false; bool res = false;
const auto &template_instantiation_type = const auto &template_instantiation_type =
static_cast<const cppast::cpp_template_instantiation_type &>(tr); static_cast<const cppast::cpp_template_instantiation_type &>(tr);
if (template_instantiation_type.primary_template()
.get(ctx.entity_index)
.size()) {
// Here we need the name of the primary template with full namespace
// prefix to apply config inclusion filters
auto primary_template_name = cx::util::full_name(ctx.namespace_,
template_instantiation_type.primary_template()
.get(ctx.entity_index)[0]
.get());
LOG_DBG("Maybe building instantiation for: {}{}", primary_template_name,
cppast::to_string(tr));
if (ctx.config.should_include(primary_template_name)) {
const auto &unaliased = const auto &unaliased =
static_cast<const cppast::cpp_template_instantiation_type &>( static_cast<const cppast::cpp_template_instantiation_type &>(
resolve_alias(template_instantiation_type)); resolve_alias(template_instantiation_type));
// if (unaliased.primary_template().get(ctx.entity_index).size()) {
// Here we need the name of the primary template with full namespace
// prefix to apply config inclusion filters
// auto primary_template_name = cx::util::full_name(ctx.namespace_,
// unaliased.primary_template().get(ctx.entity_index)[0].get());
// LOG_DBG("Maybe building instantiation for: {}, {}",
// primary_template_name, cppast::to_string(tr));
// if (ctx.config.should_include(primary_template_name)) {
class_ tinst = build_template_instantiation(unaliased); class_ tinst = build_template_instantiation(unaliased);
// Infer the relationship of this field to the template // Infer the relationship of this field to the template
@@ -563,6 +561,7 @@ bool tu_visitor::process_field_with_template_instantiation(
} }
} }
if (ctx.config.should_include(tinst.name)) {
LOG_DBG("Adding field instantiation relationship {} {} {} : {}", LOG_DBG("Adding field instantiation relationship {} {} {} : {}",
rr.destination, model::class_diagram::to_string(rr.type), c.usr, rr.destination, model::class_diagram::to_string(rr.type), c.usr,
rr.label); rr.label);
@@ -571,12 +570,16 @@ bool tu_visitor::process_field_with_template_instantiation(
res = true; res = true;
LOG_DBG("Created template instantiation: {}, {}", tinst.name, LOG_DBG(
tinst.usr); "Created template instantiation: {}, {}", tinst.name, tinst.usr);
ctx.d.add_class(std::move(tinst)); ctx.d.add_class(std::move(tinst));
} }
} //}
//}
// else {
// LOG_DBG("Field template instantiation has no primary template?");
//}
return res; return res;
} }
@@ -1146,7 +1149,8 @@ bool tu_visitor::find_relationships(const cppast::cpp_type &t_,
} }
class_ tu_visitor::build_template_instantiation( class_ tu_visitor::build_template_instantiation(
const cppast::cpp_template_instantiation_type &t) const cppast::cpp_template_instantiation_type &t,
std::optional<clanguml::model::class_diagram::class_ *> parent)
{ {
class_ tinst; class_ tinst;
std::string full_template_name; std::string full_template_name;
@@ -1263,16 +1267,18 @@ class_ tu_visitor::build_template_instantiation(
cppast::remove_cv(cx::util::unreferenced(targ.type().value())), cppast::remove_cv(cx::util::unreferenced(targ.type().value())),
ctx.entity_index, false); ctx.entity_index, false);
if (ctx.config.should_include(fn)) {
if (targ.type().value().kind() == if (targ.type().value().kind() ==
cppast::cpp_type_kind::template_instantiation_t) { cppast::cpp_type_kind::template_instantiation_t) {
class_ nested_tinst =
build_template_instantiation(static_cast<
const cppast::cpp_template_instantiation_type &>(
targ.type().value()));
fn = util::split(fn, "<")[0]; const auto &nested_template_parameter = static_cast<
const cppast::cpp_template_instantiation_type &>(
targ.type().value());
class_ nested_tinst =
build_template_instantiation(nested_template_parameter,
ctx.config.should_include(tinst.name)
? std::make_optional(&tinst)
: parent);
class_relationship tinst_dependency; class_relationship tinst_dependency;
tinst_dependency.type = relationship_t::kDependency; tinst_dependency.type = relationship_t::kDependency;
@@ -1281,15 +1287,27 @@ class_ tu_visitor::build_template_instantiation(
tinst_dependency.destination = tinst_dependency.destination =
nested_tinst.full_name(ctx.config.using_namespace); nested_tinst.full_name(ctx.config.using_namespace);
if (ctx.config.should_include(fn)) {
LOG_DBG("Creating nested template dependency to template " LOG_DBG("Creating nested template dependency to template "
"instantiation {} -> {}", "instantiation {}, {} -> {}",
tinst.full_name(ctx.config.using_namespace), fn, tinst.full_name(ctx.config.using_namespace),
tinst_dependency.destination); tinst_dependency.destination);
tinst.add_relationship(std::move(tinst_dependency)); tinst.add_relationship(std::move(tinst_dependency));
}
else if (parent) {
LOG_DBG("Creating nested template dependency to template "
"instantiation {}, {} -> {}",
fn, (*parent)->full_name(ctx.config.using_namespace),
tinst_dependency.destination);
(*parent)->add_relationship(std::move(tinst_dependency));
}
if (ctx.config.should_include(fn)) {
ctx.d.add_class(std::move(nested_tinst)); ctx.d.add_class(std::move(nested_tinst));
} }
}
else if (targ.type().value().kind() == else if (targ.type().value().kind() ==
cppast::cpp_type_kind::user_defined_t) { cppast::cpp_type_kind::user_defined_t) {
class_relationship tinst_dependency; class_relationship tinst_dependency;
@@ -1301,14 +1319,17 @@ class_ tu_visitor::build_template_instantiation(
cx::util::unreferenced(targ.type().value())), cx::util::unreferenced(targ.type().value())),
ctx.entity_index, false); ctx.entity_index, false);
LOG_DBG( LOG_DBG("Creating nested template dependency to user defined "
"Creating nested template dependency to user defined "
"type {} -> {}", "type {} -> {}",
tinst.full_name(ctx.config.using_namespace), tinst.full_name(ctx.config.using_namespace),
tinst_dependency.destination); tinst_dependency.destination);
if (ctx.config.should_include(fn)) {
tinst.add_relationship(std::move(tinst_dependency)); tinst.add_relationship(std::move(tinst_dependency));
} }
else if (parent) {
(*parent)->add_relationship(std::move(tinst_dependency));
}
} }
} }
else if (targ.expression()) { else if (targ.expression()) {

View File

@@ -220,7 +220,8 @@ public:
private: private:
clanguml::model::class_diagram::class_ build_template_instantiation( clanguml::model::class_diagram::class_ build_template_instantiation(
const cppast::cpp_template_instantiation_type &t); const cppast::cpp_template_instantiation_type &t,
std::optional<clanguml::model::class_diagram::class_ *> parent = {});
const cppast::cpp_type &resolve_alias(const cppast::cpp_type &t); const cppast::cpp_type &resolve_alias(const cppast::cpp_type &t);

View File

@@ -21,7 +21,7 @@ struct D {
}; };
struct R { struct R {
A<B<C<D>>> abc; std::shared_ptr<A<B<std::unique_ptr<C<D>>>>> abc;
}; };
} // namespace t00033 } // namespace t00033