Fixed multiple instantiation of templates instances

This commit is contained in:
Bartek Kryza
2021-03-20 20:35:55 +01:00
parent 90952d8c3c
commit 32948ab143
3 changed files with 35 additions and 4 deletions

View File

@@ -131,6 +131,11 @@ struct class_template {
std::string type;
std::string default_value;
bool is_variadic{false};
friend bool operator==(const class_template &l, const class_template &r)
{
return (l.name == r.name) && (l.type == r.type);
}
};
class class_ : public element {
@@ -147,6 +152,11 @@ public:
std::vector<class_template> templates;
std::string base_template_usr;
friend bool operator==(const class_ &l, const class_ &r)
{
return (l.usr == r.usr) && (l.templates == r.templates);
}
void add_relationship(class_relationship &&cr)
{
auto it = std::find(relationships.begin(), relationships.end(), cr);
@@ -201,6 +211,11 @@ public:
struct enum_ : public element {
std::vector<std::string> constants;
friend bool operator==(const enum_ &l, const enum_ &r)
{
return l.name == r.name;
}
};
struct diagram {
@@ -208,6 +223,21 @@ struct diagram {
std::vector<class_> classes;
std::vector<enum_> enums;
void add_class(class_ &&c)
{
spdlog::debug("ADDING CLASS: {}, {}", c.name, c.usr);
auto it = std::find(classes.begin(), classes.end(), c);
if (it == classes.end())
classes.emplace_back(std::move(c));
}
void add_enum(enum_ &&e)
{
auto it = std::find(enums.begin(), enums.end(), e);
if (it == enums.end())
enums.emplace_back(std::move(e));
}
std::string to_alias(const std::vector<std::string> &using_namespaces,
const std::string &full_name) const
{

View File

@@ -237,7 +237,7 @@ enum CXChildVisitResult method_parameter_visitor(
r.destination = t.referenced().unqualified();
ctx->d.classes.emplace_back(std::move(tinst));
ctx->d.add_class(std::move(tinst));
}
else
r.destination = t.referenced().type_declaration().usr();
@@ -453,7 +453,7 @@ enum CXChildVisitResult process_class_declaration(
spdlog::debug("Added relationship {} +-- {}", parent->name, c.name);
}
ctx->d.classes.emplace_back(std::move(c));
ctx->d.add_class(std::move(c));
return CXChildVisit_Continue;
}
@@ -482,7 +482,7 @@ enum CXChildVisitResult process_enum_declaration(
spdlog::debug("Added relationship {} +-- {}", parent->name, e.name);
}
ctx->d.enums.emplace_back(std::move(e));
ctx->d.add_enum(std::move(e));
return CXChildVisit_Continue;
}
@@ -569,7 +569,7 @@ bool process_template_specialization_class_field(
tinst.add_relationship(std::move(r));
ctx->d.classes.emplace_back(std::move(tinst));
ctx->d.add_class(std::move(tinst));
return true;
}

View File

@@ -48,6 +48,7 @@ public:
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_e2(E<int> &e) { return e.e; }
template <typename T> T get_f(const F<T> &f) { return f.f; }