diff --git a/src/puml/class_diagram_generator.h b/src/puml/class_diagram_generator.h index c3c84c15..29a4ff37 100644 --- a/src/puml/class_diagram_generator.h +++ b/src/puml/class_diagram_generator.h @@ -210,6 +210,8 @@ public: if (!m_config.should_include_relationship(name(r.type))) continue; + LOG_DBG("===== Processing relationship {}", to_string(r.type)); + std::stringstream relstr; std::string destination; try { @@ -240,10 +242,8 @@ public: relstr << m_model.to_alias( uns, ns_relative(uns, c.full_name(uns))) - //uns, c.full_name(uns)) << " " << puml_relation << " " << m_model.to_alias(uns, ns_relative(uns, destination)); - //<< m_model.to_alias(uns, destination); if (!r.label.empty()) { relstr << " : " << to_string(r.scope) << r.label; diff --git a/src/uml/class_diagram_model.h b/src/uml/class_diagram_model.h index 961d85a5..e8d50a7c 100644 --- a/src/uml/class_diagram_model.h +++ b/src/uml/class_diagram_model.h @@ -350,6 +350,8 @@ struct diagram { std::string to_alias(const std::vector &using_namespaces, const std::string &full_name) const { + LOG_DBG("Looking for alias for {}", full_name); + for (const auto &c : classes) { if (c.full_name(using_namespaces) == full_name) { return c.alias(); diff --git a/src/uml/class_diagram_visitor.cc b/src/uml/class_diagram_visitor.cc index fddfc6ce..0a128d2b 100644 --- a/src/uml/class_diagram_visitor.cc +++ b/src/uml/class_diagram_visitor.cc @@ -525,22 +525,12 @@ bool tu_visitor::process_field_with_template_instantiation( static_cast( 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); // Infer the relationship of this field to the template // instantiation class_relationship rr; - rr.destination = tinst.usr; + rr.destination = tinst.full_name(ctx.config.using_namespace); if (mv.type().kind() == cppast::cpp_type_kind::pointer_t || mv.type().kind() == cppast::cpp_type_kind::reference_t) rr.type = relationship_t::kAssociation; @@ -575,11 +565,6 @@ bool tu_visitor::process_field_with_template_instantiation( ctx.d.add_class(std::move(tinst)); } - //} - //} - // else { - // LOG_DBG("Field template instantiation has no primary template?"); - //} return res; } @@ -1048,8 +1033,11 @@ bool tu_visitor::find_relationships(const cppast::cpp_type &t_, { bool found{false}; - LOG_DBG("Finding relationships for type {}, {}", cppast::to_string(t_), - t_.kind()); + const auto fn = + cx::util::full_name(cppast::remove_cv(t_), ctx.entity_index, false); + + LOG_DBG("Finding relationships for type {}, {}, {}", cppast::to_string(t_), + t_.kind(), fn); relationship_t relationship_type = relationship_hint; const auto &t = cppast::remove_cv(cx::util::unreferenced(t_)); @@ -1091,8 +1079,6 @@ bool tu_visitor::find_relationships(const cppast::cpp_type &t_, cppast::to_string(t), relationship_t::kAggregation); // Check if t_ has an alias in the alias index - const auto fn = - cx::util::full_name(cppast::remove_cv(t_), ctx.entity_index, false); if (ctx.has_type_alias(fn)) { LOG_DBG("Find relationship in alias of {} | {}", fn, cppast::to_string(ctx.get_type_alias(fn).get())); @@ -1135,6 +1121,29 @@ bool tu_visitor::find_relationships(const cppast::cpp_type &t_, found = find_relationships(args[0u].type().value(), relationships, relationship_t::kAggregation); } + else if (ctx.config.should_include(fn)) { + LOG_DBG("User defined template instantiation: {} | {}", + cppast::to_string(t_), cppast::to_string(t_.canonical())); + + if (relationship_type != relationship_t::kNone) + relationships.emplace_back( + cppast::to_string(t), relationship_type); + else + relationships.emplace_back( + cppast::to_string(t), relationship_t::kAggregation); + + // Check if t_ has an alias in the alias index + if (ctx.has_type_alias(fn)) { + LOG_DBG("Find relationship in alias of {} | {}", fn, + cppast::to_string(ctx.get_type_alias(fn).get())); + found = find_relationships(ctx.get_type_alias(fn).get(), + relationships, relationship_type); + if (found) + return found; + } + + return found; + } else { for (const auto &arg : args) { if (arg.type()) { diff --git a/tests/t00033/t00033.cc b/tests/t00033/t00033.cc index c25cfb13..66e7df06 100644 --- a/tests/t00033/t00033.cc +++ b/tests/t00033/t00033.cc @@ -21,7 +21,7 @@ struct D { }; struct R { - std::shared_ptr>>>> abc; + A>>> abc; }; } // namespace t00033