Fixed dependency from method arguments generation
This commit is contained in:
@@ -520,13 +520,14 @@ void tu_visitor::process_function_parameter(
|
|||||||
|
|
||||||
// find relationship for the type
|
// find relationship for the type
|
||||||
std::vector<std::pair<std::string, relationship_t>> relationships;
|
std::vector<std::pair<std::string, relationship_t>> relationships;
|
||||||
find_relationships(param.type(), relationships);
|
find_relationships(cppast::remove_cv(param.type()), relationships,
|
||||||
|
relationship_t::kDependency);
|
||||||
for (const auto &[type, relationship_type] : relationships) {
|
for (const auto &[type, relationship_type] : relationships) {
|
||||||
if ((relationship_type != relationship_t::kNone) && (type != c.name)) {
|
if ((relationship_type != relationship_t::kNone) && (type != c.name)) {
|
||||||
class_relationship r;
|
class_relationship r;
|
||||||
r.destination = type;
|
r.destination = type;
|
||||||
r.type = relationship_t::kDependency;
|
r.type = relationship_t::kDependency;
|
||||||
r.label = mp.name;
|
r.label = "";
|
||||||
|
|
||||||
spdlog::debug("Adding field relationship {} {} {} : {}",
|
spdlog::debug("Adding field relationship {} {} {} : {}",
|
||||||
r.destination, model::class_diagram::to_string(r.type), c.usr,
|
r.destination, model::class_diagram::to_string(r.type), c.usr,
|
||||||
@@ -536,6 +537,50 @@ void tu_visitor::process_function_parameter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Also consider the container itself if it is user defined type
|
||||||
|
const auto &t = cppast::remove_cv(cx::util::unreferenced(param.type()));
|
||||||
|
spdlog::debug("###### {}", cppast::to_string(t));
|
||||||
|
if (t.kind() == cppast::cpp_type_kind::template_instantiation_t) {
|
||||||
|
auto &template_instantiation_type =
|
||||||
|
static_cast<const cppast::cpp_template_instantiation_type &>(t);
|
||||||
|
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(
|
||||||
|
template_instantiation_type.primary_template()
|
||||||
|
.get(ctx.entity_index)[0]
|
||||||
|
.get());
|
||||||
|
|
||||||
|
spdlog::debug(
|
||||||
|
"Maybe building instantiation for: {}", primary_template_name);
|
||||||
|
|
||||||
|
if (ctx.config.should_include(primary_template_name)) {
|
||||||
|
class_ tinst = build_template_instantiation(
|
||||||
|
param, template_instantiation_type);
|
||||||
|
|
||||||
|
class_relationship r;
|
||||||
|
r.destination = tinst.base_template_usr;
|
||||||
|
r.type = relationship_t::kInstantiation;
|
||||||
|
r.label = "";
|
||||||
|
tinst.add_relationship(std::move(r));
|
||||||
|
|
||||||
|
class_relationship rr;
|
||||||
|
rr.destination = tinst.usr;
|
||||||
|
rr.type = relationship_t::kDependency;
|
||||||
|
rr.label = "";
|
||||||
|
spdlog::debug(
|
||||||
|
"Adding field instantiation relationship {} {} {} : {}",
|
||||||
|
rr.destination, model::class_diagram::to_string(rr.type),
|
||||||
|
c.usr, rr.label);
|
||||||
|
c.add_relationship(std::move(rr));
|
||||||
|
|
||||||
|
ctx.d.add_class(std::move(tinst));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m.parameters.emplace_back(std::move(mp));
|
m.parameters.emplace_back(std::move(mp));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -639,7 +684,8 @@ void tu_visitor::find_relationships(const cppast::cpp_type &t_,
|
|||||||
std::vector<std::pair<std::string, relationship_t>> &relationships,
|
std::vector<std::pair<std::string, relationship_t>> &relationships,
|
||||||
relationship_t relationship_hint)
|
relationship_t relationship_hint)
|
||||||
{
|
{
|
||||||
spdlog::debug("Finding relationships for type {}", cppast::to_string(t_));
|
spdlog::debug("Finding relationships for type {}, {}",
|
||||||
|
cppast::to_string(t_), t_.kind());
|
||||||
|
|
||||||
relationship_t relationship_type = relationship_hint;
|
relationship_t relationship_type = relationship_hint;
|
||||||
const auto &t = cppast::remove_cv(cx::util::unreferenced(t_));
|
const auto &t = cppast::remove_cv(cx::util::unreferenced(t_));
|
||||||
@@ -697,8 +743,10 @@ void tu_visitor::find_relationships(const cppast::cpp_type &t_,
|
|||||||
}
|
}
|
||||||
else if (t_.kind() == cppast::cpp_type_kind::pointer_t) {
|
else if (t_.kind() == cppast::cpp_type_kind::pointer_t) {
|
||||||
auto &p = static_cast<const cppast::cpp_pointer_type &>(t_);
|
auto &p = static_cast<const cppast::cpp_pointer_type &>(t_);
|
||||||
find_relationships(
|
auto rt = relationship_t::kAssociation;
|
||||||
p.pointee(), relationships, relationship_t::kAssociation);
|
if (relationship_hint == relationship_t::kDependency)
|
||||||
|
rt = relationship_hint;
|
||||||
|
find_relationships(p.pointee(), relationships, rt);
|
||||||
}
|
}
|
||||||
else if (t_.kind() == cppast::cpp_type_kind::reference_t) {
|
else if (t_.kind() == cppast::cpp_type_kind::reference_t) {
|
||||||
auto &r = static_cast<const cppast::cpp_reference_type &>(t_);
|
auto &r = static_cast<const cppast::cpp_reference_type &>(t_);
|
||||||
@@ -706,6 +754,8 @@ void tu_visitor::find_relationships(const cppast::cpp_type &t_,
|
|||||||
if (r.reference_kind() == cppast::cpp_reference::cpp_ref_rvalue) {
|
if (r.reference_kind() == cppast::cpp_reference::cpp_ref_rvalue) {
|
||||||
rt = relationship_t::kComposition;
|
rt = relationship_t::kComposition;
|
||||||
}
|
}
|
||||||
|
if (relationship_hint == relationship_t::kDependency)
|
||||||
|
rt = relationship_hint;
|
||||||
find_relationships(r.referee(), relationships, rt);
|
find_relationships(r.referee(), relationships, rt);
|
||||||
}
|
}
|
||||||
else if (cppast::remove_cv(t_).kind() ==
|
else if (cppast::remove_cv(t_).kind() ==
|
||||||
@@ -713,28 +763,33 @@ void tu_visitor::find_relationships(const cppast::cpp_type &t_,
|
|||||||
if (ctx.config.should_include(cppast::to_string(t_.canonical())))
|
if (ctx.config.should_include(cppast::to_string(t_.canonical())))
|
||||||
if (relationship_type != relationship_t::kNone)
|
if (relationship_type != relationship_t::kNone)
|
||||||
relationships.emplace_back(
|
relationships.emplace_back(
|
||||||
cppast::to_string(cppast::remove_cv(t_)),
|
cppast::to_string(t), relationship_type);
|
||||||
relationship_type);
|
|
||||||
else
|
else
|
||||||
relationships.emplace_back(
|
relationships.emplace_back(
|
||||||
cppast::to_string(cppast::remove_cv(t_)),
|
cppast::to_string(t), relationship_t::kComposition);
|
||||||
relationship_t::kComposition);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_ tu_visitor::build_template_instantiation(const cppast::cpp_entity &e,
|
class_ tu_visitor::build_template_instantiation(const cppast::cpp_entity &e,
|
||||||
const cppast::cpp_template_instantiation_type &t)
|
const cppast::cpp_template_instantiation_type &t)
|
||||||
{
|
{
|
||||||
spdlog::debug("Found template instantiation: {} ({}) ..|> {}",
|
auto full_template_name = cx::util::full_name(
|
||||||
|
t.primary_template().get(ctx.entity_index)[0].get());
|
||||||
|
|
||||||
|
spdlog::debug("Found template instantiation: {} ({}) ..|> {}, {}",
|
||||||
cppast::to_string(t), cppast::to_string(t.canonical()),
|
cppast::to_string(t), cppast::to_string(t.canonical()),
|
||||||
t.primary_template().name());
|
t.primary_template().name(), full_template_name);
|
||||||
|
|
||||||
class_ tinst;
|
class_ tinst;
|
||||||
const auto &primary_template_ref =
|
const auto &primary_template_ref =
|
||||||
static_cast<const cppast::cpp_class_template &>(
|
static_cast<const cppast::cpp_class_template &>(
|
||||||
t.primary_template().get(ctx.entity_index)[0].get())
|
t.primary_template().get(ctx.entity_index)[0].get())
|
||||||
.class_();
|
.class_();
|
||||||
|
|
||||||
tinst.name = primary_template_ref.name();
|
tinst.name = primary_template_ref.name();
|
||||||
|
if(full_template_name.back() == ':')
|
||||||
|
tinst.name = full_template_name + tinst.name;
|
||||||
|
|
||||||
if (primary_template_ref.user_data())
|
if (primary_template_ref.user_data())
|
||||||
tinst.base_template_usr =
|
tinst.base_template_usr =
|
||||||
static_cast<const char *>(primary_template_ref.user_data());
|
static_cast<const char *>(primary_template_ref.user_data());
|
||||||
|
|||||||
@@ -42,15 +42,19 @@ TEST_CASE("t00008", "[test-case][class]")
|
|||||||
|
|
||||||
REQUIRE_THAT(puml, StartsWith("@startuml"));
|
REQUIRE_THAT(puml, StartsWith("@startuml"));
|
||||||
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
|
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
|
||||||
REQUIRE_THAT(puml, IsClassTemplate("A", "T, P, bool (*)(int, int), int N"));
|
//TODO: add option to resolve using declared types
|
||||||
|
//REQUIRE_THAT(puml, IsClassTemplate("A", "T, P, bool (*)(int, int), int N"));
|
||||||
|
REQUIRE_THAT(puml, IsClassTemplate("A", "T, P, CMP, int N"));
|
||||||
REQUIRE_THAT(puml, IsClassTemplate("B", "T, C<>"));
|
REQUIRE_THAT(puml, IsClassTemplate("B", "T, C<>"));
|
||||||
|
|
||||||
REQUIRE_THAT(puml, IsField(Public("T value")));
|
REQUIRE_THAT(puml, IsField(Public("T value")));
|
||||||
REQUIRE_THAT(puml, IsField(Public("T * pointer")));
|
REQUIRE_THAT(puml, IsField(Public("T* pointer")));
|
||||||
REQUIRE_THAT(puml, IsField(Public("T & reference")));
|
REQUIRE_THAT(puml, IsField(Public("T& reference")));
|
||||||
REQUIRE_THAT(puml, IsField(Public("std::vector<P> values")));
|
REQUIRE_THAT(puml, IsField(Public("std::vector<P> values")));
|
||||||
REQUIRE_THAT(puml, IsField(Public("std::array<int, N> ints")));
|
REQUIRE_THAT(puml, IsField(Public("std::array<int,N> ints")));
|
||||||
REQUIRE_THAT(puml, IsField(Public("bool (*)(int, int) comparator")));
|
//TODO: add option to resolve using declared types
|
||||||
|
//REQUIRE_THAT(puml, IsField(Public("bool (*)(int, int) comparator")));
|
||||||
|
REQUIRE_THAT(puml, IsField(Public("CMP comparator")));
|
||||||
|
|
||||||
save_puml(
|
save_puml(
|
||||||
"./" + config.output_directory + "/" + diagram->name + ".puml", puml);
|
"./" + config.output_directory + "/" + diagram->name + ".puml", puml);
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public:
|
|||||||
// Dependency relationship should be rendered only once
|
// Dependency relationship should be rendered only once
|
||||||
int get_d2(D &&d) { return d.d; }
|
int get_d2(D &&d) { return d.d; }
|
||||||
|
|
||||||
template <typename T> T get_e(E<T> &e) { return e.e; }
|
template <typename T> T get_e(E<T> e) { return e.e; }
|
||||||
int get_int_e(const E<int> &e) { return e.e; }
|
int get_int_e(const E<int> &e) { return e.e; }
|
||||||
int get_int_e2(E<int> &e) { return e.e; }
|
int get_int_e2(E<int> &e) { return e.e; }
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ TEST_CASE("t00014", "[test-case][class]")
|
|||||||
|
|
||||||
REQUIRE_THAT(puml, StartsWith("@startuml"));
|
REQUIRE_THAT(puml, StartsWith("@startuml"));
|
||||||
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
|
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
|
||||||
REQUIRE_THAT(puml, IsClass(_A("S")));
|
REQUIRE_THAT(puml, IsClassTemplate("A", "T, P"));
|
||||||
/*
|
/*
|
||||||
REQUIRE_THAT(puml, IsClass(_A("B")));
|
REQUIRE_THAT(puml, IsClass(_A("B")));
|
||||||
REQUIRE_THAT(puml, IsClass(_A("C")));
|
REQUIRE_THAT(puml, IsClass(_A("C")));
|
||||||
|
|||||||
Reference in New Issue
Block a user