Fixed dependency generation for template parameters

This commit is contained in:
Bartek Kryza
2021-03-19 19:52:39 +01:00
parent ce1d94984d
commit bd2aecb775
6 changed files with 52 additions and 20 deletions

View File

@@ -185,14 +185,14 @@ public:
for (const auto &r : c.relationships) {
std::string destination;
if (r.type == relationship_t::kInstantiation) {
destination = m_model.usr_to_name(
m_config.using_namespace, r.destination);
}
else if (r.destination.find("#") != std::string::npos ||
if (r.destination.find("#") != std::string::npos ||
r.destination.find("@") != std::string::npos) {
destination = m_model.usr_to_name(
m_config.using_namespace, r.destination);
if (destination.empty()) {
ostr << "' ";
destination = r.destination;
}
}
else {
destination = r.destination;

View File

@@ -231,7 +231,7 @@ struct diagram {
return c.full_name(using_namespaces);
}
return usr;
return "";
}
};
}

View File

@@ -218,8 +218,8 @@ static enum CXChildVisitResult method_parameter_visitor(
enum CXChildVisitResult ret = CXChildVisit_Break;
switch (cursor.kind()) {
case CXCursor_ParmDecl: {
spdlog::debug(
"Analyzing method parameter: {}, {}", cursor, cursor.type());
spdlog::debug("Analyzing method parameter: {}, {}, {}", cursor,
cursor.type(), cursor.type().named_type());
auto t = cursor.type();
method_parameter mp;
@@ -228,21 +228,35 @@ static enum CXChildVisitResult method_parameter_visitor(
mp.default_value = cursor.default_value();
ctx->element.parameters.emplace_back(std::move(mp));
std::string rdestination{};
if (t.is_relationship() &&
ctx->ctx->config.should_include(t.referenced().spelling()) &&
(t.referenced().spelling() != ctx->parent_class->name)) {
if (t.is_relationship()) {
if (t.is_template_instantiation()) {
rdestination = t.referenced().instantiation_template();
}
else {
rdestination = t.referenced().spelling();
}
class_relationship r;
r.type = relationship_t::kDependency;
r.destination = t.referenced().spelling();
if (ctx->ctx->config.should_include(rdestination) &&
rdestination != ctx->parent_class->name) {
assert(ctx->parent_class != nullptr);
spdlog::debug("ADDING DEPENDENCY TO {} \n\tCURSOR={} "
"\n\tREFTYPE={} \n\tTYPEDECL={}",
rdestination, cursor, t.referenced(),
t.referenced().type_declaration().usr());
ctx->parent_class->add_relationship(std::move(r));
class_relationship r;
r.type = relationship_t::kDependency;
r.destination = t.referenced().type_declaration().usr();
assert(ctx->parent_class != nullptr);
ctx->parent_class->add_relationship(std::move(r));
}
ret = CXChildVisit_Continue;
}
ret = CXChildVisit_Continue;
} break;
default:
ret = CXChildVisit_Continue;

View File

@@ -10,3 +10,4 @@ diagrams:
include:
namespaces:
- clanguml::t00013
- ABCD

View File

@@ -4,6 +4,11 @@
#include <string>
#include <variant>
namespace ABCD {
template <typename T> struct F {
T f;
};
}
namespace clanguml {
namespace t00013 {
@@ -26,15 +31,25 @@ struct D {
void print(R *r) {}
};
template <typename T> struct E {
T e;
};
using namespace ABCD;
class R {
public:
int get_a(A *a) { return a->a; }
int get_b(B &b) { return b.b; }
// TODO: int get_b(const B &b) { return b.b; }
// TODO: int get_const_b(const B &b) { return b.b; }
int get_c(C c) { return c.c; }
int get_d(D &&d) { return d.d; }
// Dependency relationship should be rendered only once
int get_d2(D &&d) { return d.d; }
template <typename T> T get_e(E<T> &e) { return e.e; }
int get_int_e(E<int> &e) { return e.e; }
template <typename T> T get_f(const F<T> &f) { return f.f; }
};
}
}

View File

@@ -24,7 +24,6 @@ TEST_CASE("t00013", "[test-case][class]")
REQUIRE(diagram->name == "t00013_class");
REQUIRE(diagram->include.namespaces.size() == 1);
REQUIRE_THAT(diagram->include.namespaces,
VectorContains(std::string{"clanguml::t00013"}));
@@ -32,6 +31,7 @@ TEST_CASE("t00013", "[test-case][class]")
REQUIRE(diagram->should_include("clanguml::t00013::A"));
REQUIRE(diagram->should_include("clanguml::t00013::B"));
REQUIRE(diagram->should_include("ABCD::F"));
auto model = generate_class_diagram(db, diagram);
@@ -50,6 +50,8 @@ TEST_CASE("t00013", "[test-case][class]")
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("B")));
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("C")));
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("D")));
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("E<T>")));
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("ABCD::F<T>")));
REQUIRE_THAT(puml, IsDependency(_A("D"), _A("R")));
save_puml(