Fixed dependency generation for template parameters
This commit is contained in:
@@ -185,14 +185,14 @@ public:
|
|||||||
|
|
||||||
for (const auto &r : c.relationships) {
|
for (const auto &r : c.relationships) {
|
||||||
std::string destination;
|
std::string destination;
|
||||||
if (r.type == relationship_t::kInstantiation) {
|
if (r.destination.find("#") != std::string::npos ||
|
||||||
destination = m_model.usr_to_name(
|
|
||||||
m_config.using_namespace, r.destination);
|
|
||||||
}
|
|
||||||
else if (r.destination.find("#") != std::string::npos ||
|
|
||||||
r.destination.find("@") != std::string::npos) {
|
r.destination.find("@") != std::string::npos) {
|
||||||
destination = m_model.usr_to_name(
|
destination = m_model.usr_to_name(
|
||||||
m_config.using_namespace, r.destination);
|
m_config.using_namespace, r.destination);
|
||||||
|
if (destination.empty()) {
|
||||||
|
ostr << "' ";
|
||||||
|
destination = r.destination;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
destination = r.destination;
|
destination = r.destination;
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ struct diagram {
|
|||||||
return c.full_name(using_namespaces);
|
return c.full_name(using_namespaces);
|
||||||
}
|
}
|
||||||
|
|
||||||
return usr;
|
return "";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -218,8 +218,8 @@ static enum CXChildVisitResult method_parameter_visitor(
|
|||||||
enum CXChildVisitResult ret = CXChildVisit_Break;
|
enum CXChildVisitResult ret = CXChildVisit_Break;
|
||||||
switch (cursor.kind()) {
|
switch (cursor.kind()) {
|
||||||
case CXCursor_ParmDecl: {
|
case CXCursor_ParmDecl: {
|
||||||
spdlog::debug(
|
spdlog::debug("Analyzing method parameter: {}, {}, {}", cursor,
|
||||||
"Analyzing method parameter: {}, {}", cursor, cursor.type());
|
cursor.type(), cursor.type().named_type());
|
||||||
|
|
||||||
auto t = cursor.type();
|
auto t = cursor.type();
|
||||||
method_parameter mp;
|
method_parameter mp;
|
||||||
@@ -228,21 +228,35 @@ static enum CXChildVisitResult method_parameter_visitor(
|
|||||||
mp.default_value = cursor.default_value();
|
mp.default_value = cursor.default_value();
|
||||||
|
|
||||||
ctx->element.parameters.emplace_back(std::move(mp));
|
ctx->element.parameters.emplace_back(std::move(mp));
|
||||||
|
std::string rdestination{};
|
||||||
|
|
||||||
if (t.is_relationship() &&
|
if (t.is_relationship()) {
|
||||||
ctx->ctx->config.should_include(t.referenced().spelling()) &&
|
if (t.is_template_instantiation()) {
|
||||||
(t.referenced().spelling() != ctx->parent_class->name)) {
|
rdestination = t.referenced().instantiation_template();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rdestination = t.referenced().spelling();
|
||||||
|
}
|
||||||
|
|
||||||
class_relationship r;
|
if (ctx->ctx->config.should_include(rdestination) &&
|
||||||
r.type = relationship_t::kDependency;
|
rdestination != ctx->parent_class->name) {
|
||||||
r.destination = t.referenced().spelling();
|
|
||||||
|
|
||||||
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;
|
} break;
|
||||||
default:
|
default:
|
||||||
ret = CXChildVisit_Continue;
|
ret = CXChildVisit_Continue;
|
||||||
|
|||||||
@@ -10,3 +10,4 @@ diagrams:
|
|||||||
include:
|
include:
|
||||||
namespaces:
|
namespaces:
|
||||||
- clanguml::t00013
|
- clanguml::t00013
|
||||||
|
- ABCD
|
||||||
|
|||||||
@@ -4,6 +4,11 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
|
||||||
|
namespace ABCD {
|
||||||
|
template <typename T> struct F {
|
||||||
|
T f;
|
||||||
|
};
|
||||||
|
}
|
||||||
namespace clanguml {
|
namespace clanguml {
|
||||||
namespace t00013 {
|
namespace t00013 {
|
||||||
|
|
||||||
@@ -26,15 +31,25 @@ struct D {
|
|||||||
void print(R *r) {}
|
void print(R *r) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename T> struct E {
|
||||||
|
T e;
|
||||||
|
};
|
||||||
|
|
||||||
|
using namespace ABCD;
|
||||||
class R {
|
class R {
|
||||||
public:
|
public:
|
||||||
int get_a(A *a) { return a->a; }
|
int get_a(A *a) { return a->a; }
|
||||||
int get_b(B &b) { return b.b; }
|
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_c(C c) { return c.c; }
|
||||||
int get_d(D &&d) { return d.d; }
|
int get_d(D &&d) { return d.d; }
|
||||||
// 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; }
|
||||||
|
int get_int_e(E<int> &e) { return e.e; }
|
||||||
|
|
||||||
|
template <typename T> T get_f(const F<T> &f) { return f.f; }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ TEST_CASE("t00013", "[test-case][class]")
|
|||||||
|
|
||||||
REQUIRE(diagram->name == "t00013_class");
|
REQUIRE(diagram->name == "t00013_class");
|
||||||
|
|
||||||
REQUIRE(diagram->include.namespaces.size() == 1);
|
|
||||||
REQUIRE_THAT(diagram->include.namespaces,
|
REQUIRE_THAT(diagram->include.namespaces,
|
||||||
VectorContains(std::string{"clanguml::t00013"}));
|
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::A"));
|
||||||
REQUIRE(diagram->should_include("clanguml::t00013::B"));
|
REQUIRE(diagram->should_include("clanguml::t00013::B"));
|
||||||
|
REQUIRE(diagram->should_include("ABCD::F"));
|
||||||
|
|
||||||
auto model = generate_class_diagram(db, diagram);
|
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("B")));
|
||||||
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("C")));
|
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("C")));
|
||||||
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("D")));
|
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")));
|
REQUIRE_THAT(puml, IsDependency(_A("D"), _A("R")));
|
||||||
|
|
||||||
save_puml(
|
save_puml(
|
||||||
|
|||||||
Reference in New Issue
Block a user