Fixed template instantiations generation without known primary template

This commit is contained in:
Bartek Kryza
2021-07-20 19:35:47 +02:00
parent 0563a251fa
commit 524cf36ecd
10 changed files with 63 additions and 27 deletions

View File

@@ -111,8 +111,10 @@ struct diagram {
auto name = clanguml::util::unqualify(name_);
for (const auto &ex : exclude.namespaces) {
if (name.find(ex) == 0)
if (name.find(ex) == 0) {
spdlog::debug("Skipping from diagram: {}", name);
return false;
}
}
// If no inclusive namespaces are provided,

View File

@@ -341,16 +341,24 @@ public:
if (m_config.should_include_entities("classes")) {
for (const auto &c : m_model.classes) {
if (!c.is_template_instantiation &&
!m_config.should_include(c.name))
continue;
generate_alias(c, ostr);
ostr << std::endl;
}
for (const auto &e : m_model.enums) {
if (!m_config.should_include(e.name))
continue;
generate_alias(e, ostr);
ostr << std::endl;
}
for (const auto &c : m_model.classes) {
if (!c.is_template_instantiation &&
!m_config.should_include(c.name))
continue;
generate(c, ostr);
ostr << std::endl;
}

View File

@@ -1048,31 +1048,40 @@ void tu_visitor::find_relationships(const cppast::cpp_type &t_,
class_ tu_visitor::build_template_instantiation(
const cppast::cpp_template_instantiation_type &t)
{
const auto &primary_template_ref =
static_cast<const cppast::cpp_class_template &>(
t.primary_template().get(ctx.entity_index)[0].get())
.class_();
auto full_template_name =
cx::util::full_name(ctx.namespace_, primary_template_ref);
LOG_DBG("Found template instantiation: {} ({}) ..|> {}, {}",
cppast::to_string(t), cppast::to_string(t.canonical()),
t.primary_template().name(), full_template_name);
class_ tinst;
std::string full_template_name;
if (full_template_name.back() == ':')
tinst.name = full_template_name + tinst.name;
if (t.primary_template().get(ctx.entity_index).size()) {
const auto &primary_template_ref =
static_cast<const cppast::cpp_class_template &>(
t.primary_template().get(ctx.entity_index)[0].get())
.class_();
if (primary_template_ref.user_data()) {
tinst.base_template_usr =
static_cast<const char *>(primary_template_ref.user_data());
LOG_DBG("Primary template ref set to: {}", tinst.base_template_usr);
full_template_name =
cx::util::full_name(ctx.namespace_, primary_template_ref);
LOG_DBG("Found template instantiation: {} ({}) ..|> {}, {}",
cppast::to_string(t), cppast::to_string(t.canonical()),
t.primary_template().name(), full_template_name);
if (full_template_name.back() == ':')
tinst.name = full_template_name + tinst.name;
if (primary_template_ref.user_data()) {
tinst.base_template_usr =
static_cast<const char *>(primary_template_ref.user_data());
LOG_DBG("Primary template ref set to: {}", tinst.base_template_usr);
}
else
LOG_WARN("No user data for base template {}",
primary_template_ref.name());
}
else {
LOG_WARN("Template instantiation {} has no primary template",
cppast::to_string(t));
full_template_name = cppast::to_string(t);
}
else
LOG_WARN(
"No user data for base template {}", primary_template_ref.name());
// Extract namespace from base template name
auto ns_toks = clanguml::util::split(