Fixed handling of decltype cxxmember type aliases with dependend parameters

This commit is contained in:
Bartek Kryza
2023-05-14 16:34:59 +02:00
parent 4b0fcd631d
commit 0fbf491dfe
10 changed files with 374 additions and 144 deletions

View File

@@ -1291,6 +1291,30 @@ void translation_unit_visitor::process_method(
// find relationship for return type
found_relationships_t relationships;
// Move dereferencing to build() method of template_builder
if (const auto *templ = mf.getReturnType()
.getNonReferenceType()
.getUnqualifiedType()
->getAs<clang::TemplateSpecializationType>();
templ != nullptr) {
auto *unaliased_type = templ;
if (unaliased_type->isTypeAlias())
unaliased_type = unaliased_type->getAliasedType()
->getAs<clang::TemplateSpecializationType>();
auto template_specialization_ptr = tbuilder().build(
unaliased_type->getTemplateName().getAsTemplateDecl(),
*unaliased_type, &c);
if (diagram().should_include(
template_specialization_ptr->full_name(false))) {
relationships.emplace_back(
template_specialization_ptr->id(), relationship_t::kDependency);
diagram().add_class(std::move(template_specialization_ptr));
}
}
find_relationships(
mf.getReturnType(), relationships, relationship_t::kDependency);
@@ -1317,13 +1341,8 @@ void translation_unit_visitor::process_method(
if (underlying_type->isPointerType())
underlying_type = underlying_type->getPointeeType();
if (const auto *tsp =
underlying_type->getAs<clang::TemplateSpecializationType>();
tsp != nullptr) {
process_function_parameter_find_relationships_in_template(c, {}, *tsp);
}
else if (const auto *atsp = underlying_type->getAs<clang::AutoType>();
atsp != nullptr) {
if (const auto *atsp = underlying_type->getAs<clang::AutoType>();
atsp != nullptr) {
process_function_parameter_find_relationships_in_autotype(c, atsp);
}
@@ -1521,6 +1540,60 @@ bool translation_unit_visitor::find_relationships(const clang::QualType &type,
result = true;
}
}
else if (const auto *template_specialization_type =
type->getAs<clang::TemplateSpecializationType>();
template_specialization_type != nullptr) {
if (should_include(template_specialization_type->getTemplateName()
.getAsTemplateDecl())) {
relationships.emplace_back(
template_specialization_type->getTemplateName()
.getAsTemplateDecl()
->getID(),
relationship_hint);
}
for (const auto &template_argument :
template_specialization_type->template_arguments()) {
const auto template_argument_kind = template_argument.getKind();
if (template_argument_kind ==
clang::TemplateArgument::ArgKind::Integral) {
// pass
}
else if (template_argument_kind ==
clang::TemplateArgument::ArgKind::Null) {
// pass
}
else if (template_argument_kind ==
clang::TemplateArgument::ArgKind::Expression) {
// pass
}
else if (template_argument.getKind() ==
clang::TemplateArgument::ArgKind::NullPtr) {
// pass
}
else if (template_argument_kind ==
clang::TemplateArgument::ArgKind::Template) {
// pass
}
else if (template_argument_kind ==
clang::TemplateArgument::ArgKind::TemplateExpansion) {
// pass
}
else if (const auto *function_type =
template_argument.getAsType()
->getAs<clang::FunctionProtoType>();
function_type != nullptr) {
for (const auto &param_type : function_type->param_types()) {
result = find_relationships(
param_type, relationships, relationship_t::kDependency);
}
}
else if (template_argument_kind ==
clang::TemplateArgument::ArgKind::Type) {
result = find_relationships(template_argument.getAsType(),
relationships, relationship_hint);
}
}
}
return result;
}
@@ -1557,6 +1630,27 @@ void translation_unit_visitor::process_function_parameter(
// find relationship for the type
found_relationships_t relationships;
LOG_DBG("Looking for relationships in type: {}",
common::to_string(p.getType(), p.getASTContext()));
if (const auto *templ =
p.getType()
.getNonReferenceType()
.getUnqualifiedType()
->getAs<clang::TemplateSpecializationType>();
templ != nullptr) {
auto template_specialization_ptr = tbuilder().build(
templ->getTemplateName().getAsTemplateDecl(), *templ, &c);
if (diagram().should_include(
template_specialization_ptr->full_name(false))) {
relationships.emplace_back(template_specialization_ptr->id(),
relationship_t::kDependency);
diagram().add_class(std::move(template_specialization_ptr));
}
}
find_relationships(
p.getType(), relationships, relationship_t::kDependency);
@@ -1573,22 +1667,6 @@ void translation_unit_visitor::process_function_parameter(
c.add_relationship(std::move(r));
}
}
// Also consider the container itself if it is a template
// instantiation it's arguments could count as reference to relevant
// types
auto underlying_type = p.getType();
if (underlying_type->isReferenceType())
underlying_type = underlying_type.getNonReferenceType();
if (underlying_type->isPointerType())
underlying_type = underlying_type->getPointeeType();
if (const auto *tsp =
underlying_type->getAs<clang::TemplateSpecializationType>();
tsp != nullptr) {
process_function_parameter_find_relationships_in_template(
c, template_parameter_names, *tsp);
}
}
method.add_parameter(std::move(parameter));
@@ -1630,40 +1708,6 @@ void translation_unit_visitor::ensure_lambda_type_is_relative(
}
}
void translation_unit_visitor::
process_function_parameter_find_relationships_in_template(class_ &c,
const std::set<std::string> & /*template_parameter_names*/,
const clang::TemplateSpecializationType &template_instantiation_type)
{
if (!should_include(
template_instantiation_type.getTemplateName().getAsTemplateDecl()))
return;
auto template_specialization_ptr = tbuilder().build(
template_instantiation_type.getTemplateName().getAsTemplateDecl(),
template_instantiation_type, &c);
if (template_instantiation_type.isDependentType()) {
if (template_specialization_ptr) {
relationship r{
relationship_t::kDependency, template_specialization_ptr->id()};
c.add_relationship(std::move(r));
}
}
else {
if (template_specialization_ptr) {
relationship r{
relationship_t::kDependency, template_specialization_ptr->id()};
if (!diagram().has_element(template_specialization_ptr->id()))
diagram().add_class(std::move(template_specialization_ptr));
c.add_relationship(std::move(r));
}
}
}
void translation_unit_visitor::add_relationships(class_ &c,
const class_member &field, const found_relationships_t &relationships,
bool break_on_first_aggregation)