Applied clang-tidy nullptr access warnings
This commit is contained in:
@@ -625,14 +625,16 @@ void translation_unit_visitor::process_class_bases(
|
|||||||
|
|
||||||
cp.set_name(name_and_ns.to_string());
|
cp.set_name(name_and_ns.to_string());
|
||||||
|
|
||||||
if (base.getType()->getAs<clang::RecordType>() != nullptr)
|
if (const auto *record_type =
|
||||||
cp.set_id(common::to_id(
|
base.getType()->getAs<clang::RecordType>();
|
||||||
*base.getType()->getAs<clang::RecordType>()->getDecl()));
|
record_type != nullptr) {
|
||||||
else if (base.getType()->getAs<clang::TemplateSpecializationType>() !=
|
cp.set_id(common::to_id(*record_type->getDecl()));
|
||||||
nullptr) {
|
}
|
||||||
auto template_specialization_ptr = build_template_instantiation(
|
else if (const auto *tsp =
|
||||||
*base.getType()->getAs<clang::TemplateSpecializationType>(),
|
base.getType()->getAs<clang::TemplateSpecializationType>();
|
||||||
{});
|
tsp != nullptr) {
|
||||||
|
auto template_specialization_ptr =
|
||||||
|
build_template_instantiation(*tsp, {});
|
||||||
if (template_specialization_ptr) {
|
if (template_specialization_ptr) {
|
||||||
cp.set_id(template_specialization_ptr->id());
|
cp.set_id(template_specialization_ptr->id());
|
||||||
}
|
}
|
||||||
@@ -666,14 +668,19 @@ void translation_unit_visitor::process_template_specialization_children(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Iterate over class template methods
|
// Iterate over class template methods
|
||||||
for (auto const *decl_iterator :
|
if (const auto *cls_decl_context =
|
||||||
clang::dyn_cast_or_null<clang::DeclContext>(cls)->decls()) {
|
clang::dyn_cast_or_null<clang::DeclContext>(cls);
|
||||||
auto const *method_template =
|
cls_decl_context != nullptr) {
|
||||||
llvm::dyn_cast_or_null<clang::FunctionTemplateDecl>(decl_iterator);
|
for (auto const *decl_iterator :
|
||||||
if (method_template == nullptr)
|
clang::dyn_cast_or_null<clang::DeclContext>(cls)->decls()) {
|
||||||
continue;
|
auto const *method_template =
|
||||||
|
llvm::dyn_cast_or_null<clang::FunctionTemplateDecl>(
|
||||||
|
decl_iterator);
|
||||||
|
if (method_template == nullptr)
|
||||||
|
continue;
|
||||||
|
|
||||||
process_template_method(*method_template, c);
|
process_template_method(*method_template, c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate over regular class fields
|
// Iterate over regular class fields
|
||||||
@@ -728,14 +735,18 @@ void translation_unit_visitor::process_class_children(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Iterate over class template methods
|
// Iterate over class template methods
|
||||||
for (auto const *decl_iterator :
|
if (const auto *cls_decl_context =
|
||||||
clang::dyn_cast_or_null<clang::DeclContext>(cls)->decls()) {
|
clang::dyn_cast_or_null<clang::DeclContext>(cls);
|
||||||
auto const *method_template =
|
cls_decl_context != nullptr) {
|
||||||
llvm::dyn_cast_or_null<clang::FunctionTemplateDecl>(decl_iterator);
|
for (auto const *decl_iterator : cls_decl_context->decls()) {
|
||||||
if (method_template == nullptr)
|
auto const *method_template =
|
||||||
continue;
|
llvm::dyn_cast_or_null<clang::FunctionTemplateDecl>(
|
||||||
|
decl_iterator);
|
||||||
|
if (method_template == nullptr)
|
||||||
|
continue;
|
||||||
|
|
||||||
process_template_method(*method_template, c);
|
process_template_method(*method_template, c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate over regular class fields
|
// Iterate over regular class fields
|
||||||
@@ -896,20 +907,22 @@ bool translation_unit_visitor::find_relationships(const clang::QualType &type,
|
|||||||
relationships, relationship_t::kAggregation);
|
relationships, relationship_t::kAggregation);
|
||||||
}
|
}
|
||||||
else if (type->isEnumeralType()) {
|
else if (type->isEnumeralType()) {
|
||||||
relationships.emplace_back(
|
if (const auto *enum_type = type->getAs<clang::EnumType>();
|
||||||
common::to_id(*type->getAs<clang::EnumType>()->getDecl()),
|
enum_type != nullptr) {
|
||||||
relationship_hint);
|
relationships.emplace_back(
|
||||||
|
common::to_id(*enum_type->getDecl()), relationship_hint);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (type->isRecordType()) {
|
else if (type->isRecordType()) {
|
||||||
const auto *type_instantiation_decl =
|
const auto *type_instantiation_decl =
|
||||||
type->getAs<clang::TemplateSpecializationType>();
|
type->getAs<clang::TemplateSpecializationType>();
|
||||||
|
|
||||||
if (type_instantiation_decl != nullptr) {
|
// if (type_instantiation_decl != nullptr) {
|
||||||
if (type_instantiation_decl->isTypeAlias())
|
// if (type_instantiation_decl->isTypeAlias())
|
||||||
type_instantiation_decl =
|
// type_instantiation_decl =
|
||||||
type_instantiation_decl->getAliasedType()
|
// type_instantiation_decl->getAliasedType()
|
||||||
->getAs<clang::TemplateSpecializationType>();
|
// ->getAs<clang::TemplateSpecializationType>();
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (type_instantiation_decl != nullptr) {
|
if (type_instantiation_decl != nullptr) {
|
||||||
for (const auto &template_argument : *type_instantiation_decl) {
|
for (const auto &template_argument : *type_instantiation_decl) {
|
||||||
@@ -938,12 +951,12 @@ bool translation_unit_visitor::find_relationships(const clang::QualType &type,
|
|||||||
clang::TemplateArgument::ArgKind::TemplateExpansion) {
|
clang::TemplateArgument::ArgKind::TemplateExpansion) {
|
||||||
// pass
|
// pass
|
||||||
}
|
}
|
||||||
else if (template_argument.getAsType()
|
else if (const auto *function_type =
|
||||||
->getAs<clang::FunctionProtoType>() != nullptr) {
|
template_argument.getAsType()
|
||||||
|
->getAs<clang::FunctionProtoType>();
|
||||||
|
function_type != nullptr) {
|
||||||
for (const auto ¶m_type :
|
for (const auto ¶m_type :
|
||||||
template_argument.getAsType()
|
function_type->param_types()) {
|
||||||
->getAs<clang::FunctionProtoType>()
|
|
||||||
->param_types()) {
|
|
||||||
result = find_relationships(param_type, relationships,
|
result = find_relationships(param_type, relationships,
|
||||||
relationship_t::kDependency);
|
relationship_t::kDependency);
|
||||||
}
|
}
|
||||||
@@ -1018,11 +1031,11 @@ void translation_unit_visitor::process_function_parameter(
|
|||||||
if (underlying_type->isPointerType())
|
if (underlying_type->isPointerType())
|
||||||
underlying_type = underlying_type->getPointeeType();
|
underlying_type = underlying_type->getPointeeType();
|
||||||
|
|
||||||
if (underlying_type->getAs<clang::TemplateSpecializationType>() !=
|
if (const auto *tsp =
|
||||||
nullptr) {
|
underlying_type->getAs<clang::TemplateSpecializationType>();
|
||||||
process_function_parameter_find_relationships_in_template(c,
|
tsp != nullptr) {
|
||||||
template_parameter_names,
|
process_function_parameter_find_relationships_in_template(
|
||||||
*underlying_type->getAs<clang::TemplateSpecializationType>());
|
c, template_parameter_names, *tsp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1185,10 +1198,9 @@ void translation_unit_visitor::process_template_specialization_argument(
|
|||||||
|
|
||||||
// If this is a nested template type - add nested templates as
|
// If this is a nested template type - add nested templates as
|
||||||
// template arguments
|
// template arguments
|
||||||
if (arg.getAsType()->getAs<clang::TemplateSpecializationType>() !=
|
if (const auto *nested_template_type =
|
||||||
nullptr) {
|
|
||||||
const auto *nested_template_type =
|
|
||||||
arg.getAsType()->getAs<clang::TemplateSpecializationType>();
|
arg.getAsType()->getAs<clang::TemplateSpecializationType>();
|
||||||
|
nested_template_type != nullptr) {
|
||||||
|
|
||||||
const auto nested_template_name =
|
const auto nested_template_name =
|
||||||
nested_template_type->getTemplateName()
|
nested_template_type->getTemplateName()
|
||||||
@@ -1198,8 +1210,7 @@ void translation_unit_visitor::process_template_specialization_argument(
|
|||||||
argument.set_name(nested_template_name);
|
argument.set_name(nested_template_name);
|
||||||
|
|
||||||
auto nested_template_instantiation = build_template_instantiation(
|
auto nested_template_instantiation = build_template_instantiation(
|
||||||
*arg.getAsType()->getAs<clang::TemplateSpecializationType>(),
|
*nested_template_type, {&template_instantiation});
|
||||||
{&template_instantiation});
|
|
||||||
|
|
||||||
argument.set_id(nested_template_instantiation->id());
|
argument.set_id(nested_template_instantiation->id());
|
||||||
|
|
||||||
@@ -1482,11 +1493,13 @@ std::unique_ptr<class_> translation_unit_visitor::build_template_instantiation(
|
|||||||
template_base_params{};
|
template_base_params{};
|
||||||
|
|
||||||
const auto *template_type_ptr = &template_type_decl;
|
const auto *template_type_ptr = &template_type_decl;
|
||||||
if (template_type_decl.isTypeAlias() &&
|
|
||||||
(template_type_decl.getAliasedType()
|
if (template_type_decl.isTypeAlias()) {
|
||||||
->getAs<clang::TemplateSpecializationType>() != nullptr))
|
if (const auto *tsp = template_type_decl.getAliasedType()
|
||||||
template_type_ptr = template_type_decl.getAliasedType()
|
->getAs<clang::TemplateSpecializationType>();
|
||||||
->getAs<clang::TemplateSpecializationType>();
|
tsp != nullptr)
|
||||||
|
template_type_ptr = tsp;
|
||||||
|
}
|
||||||
|
|
||||||
const auto &template_type = *template_type_ptr;
|
const auto &template_type = *template_type_ptr;
|
||||||
|
|
||||||
@@ -1696,7 +1709,7 @@ void translation_unit_visitor::
|
|||||||
// the list of template params, from then this variable is true
|
// the list of template params, from then this variable is true
|
||||||
// and we can process following template parameters as belonging
|
// and we can process following template parameters as belonging
|
||||||
// to the variadic tuple
|
// to the variadic tuple
|
||||||
auto variadic_params = false;
|
[[maybe_unused]] auto variadic_params{false};
|
||||||
|
|
||||||
// In case any of the template arguments are base classes, add
|
// In case any of the template arguments are base classes, add
|
||||||
// them as parents of the current template instantiation class
|
// them as parents of the current template instantiation class
|
||||||
@@ -1743,12 +1756,14 @@ void translation_unit_visitor::
|
|||||||
|
|
||||||
// If this is a nested template type - add nested templates as
|
// If this is a nested template type - add nested templates as
|
||||||
// template arguments
|
// template arguments
|
||||||
if (arg.getAsType()->getAs<clang::FunctionType>() != nullptr) {
|
if (const auto *function_type =
|
||||||
|
arg.getAsType()->getAs<clang::FunctionProtoType>();
|
||||||
|
function_type != nullptr) {
|
||||||
|
|
||||||
for (const auto ¶m_type :
|
for (const auto ¶m_type : function_type->param_types()) {
|
||||||
arg.getAsType()->getAs<clang::FunctionProtoType>()->param_types()) {
|
const auto *param_record_type =
|
||||||
|
param_type->getAs<clang::RecordType>();
|
||||||
if (param_type->getAs<clang::RecordType>() == nullptr)
|
if (param_record_type == nullptr)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto *classTemplateSpecialization =
|
auto *classTemplateSpecialization =
|
||||||
@@ -1759,8 +1774,7 @@ void translation_unit_visitor::
|
|||||||
// Read arg info as needed.
|
// Read arg info as needed.
|
||||||
auto nested_template_instantiation =
|
auto nested_template_instantiation =
|
||||||
build_template_instantiation_from_class_template_specialization(
|
build_template_instantiation_from_class_template_specialization(
|
||||||
*classTemplateSpecialization,
|
*classTemplateSpecialization, *param_record_type,
|
||||||
*param_type->getAs<clang::RecordType>(),
|
|
||||||
diagram().should_include(
|
diagram().should_include(
|
||||||
full_template_specialization_name)
|
full_template_specialization_name)
|
||||||
? std::make_optional(&template_instantiation)
|
? std::make_optional(&template_instantiation)
|
||||||
@@ -1769,9 +1783,6 @@ void translation_unit_visitor::
|
|||||||
const auto nested_template_name =
|
const auto nested_template_name =
|
||||||
classTemplateSpecialization->getQualifiedNameAsString();
|
classTemplateSpecialization->getQualifiedNameAsString();
|
||||||
|
|
||||||
auto [tinst_ns, tinst_name] =
|
|
||||||
cx::util::split_ns(nested_template_name);
|
|
||||||
|
|
||||||
if (nested_template_instantiation) {
|
if (nested_template_instantiation) {
|
||||||
if (parent.has_value())
|
if (parent.has_value())
|
||||||
parent.value()->add_relationship(
|
parent.value()->add_relationship(
|
||||||
@@ -1789,25 +1800,22 @@ void translation_unit_visitor::
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (arg.getAsType()->getAs<clang::TemplateSpecializationType>() !=
|
else if (const auto *nested_template_type =
|
||||||
nullptr) {
|
arg.getAsType()->getAs<clang::TemplateSpecializationType>();
|
||||||
const auto *nested_template_type =
|
nested_template_type != nullptr) {
|
||||||
arg.getAsType()->getAs<clang::TemplateSpecializationType>();
|
|
||||||
|
|
||||||
const auto nested_template_name =
|
const auto nested_template_name =
|
||||||
nested_template_type->getTemplateName()
|
nested_template_type->getTemplateName()
|
||||||
.getAsTemplateDecl()
|
.getAsTemplateDecl()
|
||||||
->getQualifiedNameAsString();
|
->getQualifiedNameAsString();
|
||||||
|
|
||||||
auto [tinst_ns, tinst_name] = cx::util::split_ns(nested_template_name);
|
|
||||||
|
|
||||||
argument.set_name(nested_template_name);
|
argument.set_name(nested_template_name);
|
||||||
|
|
||||||
auto nested_template_instantiation = build_template_instantiation(
|
auto nested_template_instantiation =
|
||||||
*arg.getAsType()->getAs<clang::TemplateSpecializationType>(),
|
build_template_instantiation(*nested_template_type,
|
||||||
diagram().should_include(full_template_specialization_name)
|
diagram().should_include(full_template_specialization_name)
|
||||||
? std::make_optional(&template_instantiation)
|
? std::make_optional(&template_instantiation)
|
||||||
: parent);
|
: parent);
|
||||||
|
|
||||||
argument.set_id(nested_template_instantiation->id());
|
argument.set_id(nested_template_instantiation->id());
|
||||||
|
|
||||||
@@ -1890,21 +1898,23 @@ void translation_unit_visitor::
|
|||||||
argument.set_name(
|
argument.set_name(
|
||||||
common::to_string(arg.getAsType(), template_decl->getASTContext()));
|
common::to_string(arg.getAsType(), template_decl->getASTContext()));
|
||||||
|
|
||||||
if ((arg.getAsType()->getAs<clang::RecordType>() != nullptr) &&
|
if (const auto *record_type = arg.getAsType()->getAs<clang::RecordType>();
|
||||||
(arg.getAsType()->getAs<clang::RecordType>()->getAsRecordDecl() !=
|
record_type != nullptr) {
|
||||||
nullptr)) {
|
if (const auto *record_type_decl = record_type->getAsRecordDecl();
|
||||||
argument.set_id(common::to_id(arg));
|
record_type_decl != nullptr) {
|
||||||
|
argument.set_id(common::to_id(arg));
|
||||||
|
|
||||||
if (diagram().should_include(full_template_specialization_name)) {
|
if (diagram().should_include(full_template_specialization_name)) {
|
||||||
// Add dependency relationship to the parent
|
// Add dependency relationship to the parent
|
||||||
// template
|
// template
|
||||||
template_instantiation.add_relationship(
|
template_instantiation.add_relationship(
|
||||||
{relationship_t::kDependency, common::to_id(arg)});
|
{relationship_t::kDependency, common::to_id(arg)});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (arg.getAsType()->getAs<clang::EnumType>() != nullptr) {
|
else if (const auto *enum_type = arg.getAsType()->getAs<clang::EnumType>();
|
||||||
if (arg.getAsType()->getAs<clang::EnumType>()->getAsTagDecl() !=
|
enum_type != nullptr) {
|
||||||
nullptr) {
|
if (enum_type->getAsTagDecl() != nullptr) {
|
||||||
template_instantiation.add_relationship(
|
template_instantiation.add_relationship(
|
||||||
{relationship_t::kDependency, common::to_id(arg)});
|
{relationship_t::kDependency, common::to_id(arg)});
|
||||||
}
|
}
|
||||||
@@ -2028,8 +2038,8 @@ void translation_unit_visitor::process_field(
|
|||||||
!field_type_is_template_template_parameter) {
|
!field_type_is_template_template_parameter) {
|
||||||
|
|
||||||
// Build the template instantiation for the field type
|
// Build the template instantiation for the field type
|
||||||
auto template_specialization_ptr = build_template_instantiation(
|
auto template_specialization_ptr =
|
||||||
*field_type->getAs<clang::TemplateSpecializationType>(), {&c});
|
build_template_instantiation(*template_field_type, {&c});
|
||||||
|
|
||||||
if (!field.skip_relationship() && template_specialization_ptr) {
|
if (!field.skip_relationship() && template_specialization_ptr) {
|
||||||
const auto &template_specialization = *template_specialization_ptr;
|
const auto &template_specialization = *template_specialization_ptr;
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ std::string to_string(const clang::Expr *expr)
|
|||||||
clang::LangOptions lang_options;
|
clang::LangOptions lang_options;
|
||||||
std::string result;
|
std::string result;
|
||||||
llvm::raw_string_ostream ostream(result);
|
llvm::raw_string_ostream ostream(result);
|
||||||
expr->printPretty(ostream, NULL, clang::PrintingPolicy(lang_options));
|
expr->printPretty(ostream, nullptr, clang::PrintingPolicy(lang_options));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -181,7 +181,7 @@ std::string to_string(const clang::Stmt *stmt)
|
|||||||
clang::LangOptions lang_options;
|
clang::LangOptions lang_options;
|
||||||
std::string result;
|
std::string result;
|
||||||
llvm::raw_string_ostream ostream(result);
|
llvm::raw_string_ostream ostream(result);
|
||||||
stmt->printPretty(ostream, NULL, clang::PrintingPolicy(lang_options));
|
stmt->printPretty(ostream, nullptr, clang::PrintingPolicy(lang_options));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -284,15 +284,15 @@ template <> id_t to_id(const std::filesystem::path &file)
|
|||||||
template <> id_t to_id(const clang::TemplateArgument &template_argument)
|
template <> id_t to_id(const clang::TemplateArgument &template_argument)
|
||||||
{
|
{
|
||||||
if (template_argument.getKind() == clang::TemplateArgument::Type) {
|
if (template_argument.getKind() == clang::TemplateArgument::Type) {
|
||||||
if (template_argument.getAsType()->getAs<clang::EnumType>() != nullptr)
|
if (const auto *enum_type =
|
||||||
return to_id(*template_argument.getAsType()
|
template_argument.getAsType()->getAs<clang::EnumType>();
|
||||||
->getAs<clang::EnumType>()
|
enum_type != nullptr)
|
||||||
->getAsTagDecl());
|
return to_id(*enum_type->getAsTagDecl());
|
||||||
if (template_argument.getAsType()->getAs<clang::RecordType>() !=
|
|
||||||
nullptr)
|
if (const auto *record_type =
|
||||||
return to_id(*template_argument.getAsType()
|
template_argument.getAsType()->getAs<clang::RecordType>();
|
||||||
->getAs<clang::RecordType>()
|
record_type != nullptr)
|
||||||
->getAsRecordDecl());
|
return to_id(*record_type->getAsRecordDecl());
|
||||||
}
|
}
|
||||||
|
|
||||||
throw std::runtime_error("Cannot generate id for template argument");
|
throw std::runtime_error("Cannot generate id for template argument");
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ public:
|
|||||||
bool should_include(relationship_t r) const;
|
bool should_include(relationship_t r) const;
|
||||||
bool should_include(access_t s) const;
|
bool should_include(access_t s) const;
|
||||||
|
|
||||||
virtual bool has_element(const diagram_element::id_t /*id*/) const
|
virtual bool has_element(const diagram_element::id_t /*id*/) const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -160,6 +160,9 @@ void clang_visitor::visit_param_command(
|
|||||||
|
|
||||||
std::string description;
|
std::string description;
|
||||||
|
|
||||||
|
if (command == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
const auto name = command->getParamNameAsWritten().str();
|
const auto name = command->getParamNameAsWritten().str();
|
||||||
|
|
||||||
for (const auto *it = command->child_begin(); it != command->child_end();
|
for (const auto *it = command->child_begin(); it != command->child_end();
|
||||||
@@ -192,6 +195,9 @@ void clang_visitor::visit_tparam_command(
|
|||||||
|
|
||||||
std::string description;
|
std::string description;
|
||||||
|
|
||||||
|
if (command == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
const auto name = command->getParamNameAsWritten().str();
|
const auto name = command->getParamNameAsWritten().str();
|
||||||
|
|
||||||
for (const auto *it = command->child_begin(); it != command->child_end();
|
for (const auto *it = command->child_begin(); it != command->child_end();
|
||||||
@@ -220,12 +226,16 @@ void clang_visitor::visit_paragraph(
|
|||||||
using clang::comments::Comment;
|
using clang::comments::Comment;
|
||||||
using clang::comments::TextComment;
|
using clang::comments::TextComment;
|
||||||
|
|
||||||
|
if (paragraph == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
for (const auto *text_it = paragraph->child_begin();
|
for (const auto *text_it = paragraph->child_begin();
|
||||||
text_it != paragraph->child_end(); ++text_it) {
|
text_it != paragraph->child_end(); ++text_it) {
|
||||||
|
|
||||||
if ((*text_it)->getCommentKind() == Comment::TextCommentKind) {
|
if ((*text_it)->getCommentKind() == Comment::TextCommentKind &&
|
||||||
|
clang::dyn_cast<TextComment>(*text_it) != nullptr) {
|
||||||
// Merge paragraph lines into a single string
|
// Merge paragraph lines into a single string
|
||||||
text += clang::dyn_cast<TextComment>((*text_it))->getText();
|
text += clang::dyn_cast<TextComment>(*text_it)->getText();
|
||||||
text += "\n";
|
text += "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,6 @@
|
|||||||
|
|
||||||
namespace clanguml::package_diagram::visitor {
|
namespace clanguml::package_diagram::visitor {
|
||||||
|
|
||||||
using clanguml::class_diagram::model::type_alias;
|
|
||||||
using clanguml::common::model::access_t;
|
using clanguml::common::model::access_t;
|
||||||
using clanguml::common::model::namespace_;
|
using clanguml::common::model::namespace_;
|
||||||
using clanguml::common::model::package;
|
using clanguml::common::model::package;
|
||||||
@@ -198,15 +197,19 @@ void translation_unit_visitor::process_class_children(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate over class template methods
|
if (const auto *decl_context =
|
||||||
for (auto const *decl_iterator :
|
clang::dyn_cast_or_null<clang::DeclContext>(&cls);
|
||||||
clang::dyn_cast_or_null<clang::DeclContext>(&cls)->decls()) {
|
decl_context != nullptr) {
|
||||||
auto const *method_template =
|
// Iterate over class template methods
|
||||||
llvm::dyn_cast_or_null<clang::FunctionTemplateDecl>(decl_iterator);
|
for (auto const *decl_iterator : decl_context->decls()) {
|
||||||
if (method_template == nullptr)
|
auto const *method_template =
|
||||||
continue;
|
llvm::dyn_cast_or_null<clang::FunctionTemplateDecl>(
|
||||||
|
decl_iterator);
|
||||||
|
if (method_template == nullptr)
|
||||||
|
continue;
|
||||||
|
|
||||||
process_template_method(*method_template, relationships);
|
process_template_method(*method_template, relationships);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate over regular class fields
|
// Iterate over regular class fields
|
||||||
@@ -333,18 +336,14 @@ bool translation_unit_visitor::find_relationships(const clang::QualType &type,
|
|||||||
relationships, relationship_t::kAggregation);
|
relationships, relationship_t::kAggregation);
|
||||||
}
|
}
|
||||||
else if (type->isEnumeralType()) {
|
else if (type->isEnumeralType()) {
|
||||||
relationships.emplace_back(
|
if (const auto *enum_type = type->getAs<clang::EnumType>();
|
||||||
common::to_id(*type->getAs<clang::EnumType>()), relationship_hint);
|
enum_type != nullptr) {
|
||||||
|
relationships.emplace_back(
|
||||||
|
common::to_id(*enum_type), relationship_hint);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (const auto *template_specialization_type =
|
else if (const auto *template_specialization_type =
|
||||||
type->getAs<clang::TemplateSpecializationType>()) {
|
type->getAs<clang::TemplateSpecializationType>()) {
|
||||||
if (template_specialization_type != nullptr) {
|
|
||||||
if (template_specialization_type->isTypeAlias())
|
|
||||||
template_specialization_type =
|
|
||||||
template_specialization_type->getAliasedType()
|
|
||||||
->getAs<clang::TemplateSpecializationType>();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (template_specialization_type != nullptr) {
|
if (template_specialization_type != nullptr) {
|
||||||
for (const auto &template_argument :
|
for (const auto &template_argument :
|
||||||
*template_specialization_type) {
|
*template_specialization_type) {
|
||||||
@@ -373,12 +372,12 @@ bool translation_unit_visitor::find_relationships(const clang::QualType &type,
|
|||||||
clang::TemplateArgument::ArgKind::TemplateExpansion) {
|
clang::TemplateArgument::ArgKind::TemplateExpansion) {
|
||||||
// pass
|
// pass
|
||||||
}
|
}
|
||||||
else if (template_argument.getAsType()
|
else if (const auto *function_type =
|
||||||
->getAs<clang::FunctionProtoType>() != nullptr) {
|
template_argument.getAsType()
|
||||||
|
->getAs<clang::FunctionProtoType>();
|
||||||
|
function_type != nullptr) {
|
||||||
for (const auto ¶m_type :
|
for (const auto ¶m_type :
|
||||||
template_argument.getAsType()
|
function_type->param_types()) {
|
||||||
->getAs<clang::FunctionProtoType>()
|
|
||||||
->param_types()) {
|
|
||||||
result = find_relationships(param_type, relationships,
|
result = find_relationships(param_type, relationships,
|
||||||
relationship_t::kDependency);
|
relationship_t::kDependency);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1030,6 +1030,9 @@ bool translation_unit_visitor::process_class_template_method_call_expression(
|
|||||||
clang::dyn_cast_or_null<clang::CXXDependentScopeMemberExpr>(
|
clang::dyn_cast_or_null<clang::CXXDependentScopeMemberExpr>(
|
||||||
expr->getCallee());
|
expr->getCallee());
|
||||||
|
|
||||||
|
if (dependent_member_callee == nullptr)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (is_callee_valid_template_specialization(dependent_member_callee)) {
|
if (is_callee_valid_template_specialization(dependent_member_callee)) {
|
||||||
const auto *template_declaration =
|
const auto *template_declaration =
|
||||||
dependent_member_callee->getBaseType()
|
dependent_member_callee->getBaseType()
|
||||||
@@ -1172,21 +1175,21 @@ bool translation_unit_visitor::process_unresolved_lookup_call_expression(
|
|||||||
bool translation_unit_visitor::is_callee_valid_template_specialization(
|
bool translation_unit_visitor::is_callee_valid_template_specialization(
|
||||||
const clang::CXXDependentScopeMemberExpr *dependent_member_expr) const
|
const clang::CXXDependentScopeMemberExpr *dependent_member_expr) const
|
||||||
{
|
{
|
||||||
const bool base_type_is_not_null =
|
if (dependent_member_expr == nullptr)
|
||||||
!dependent_member_expr->getBaseType().isNull();
|
return false;
|
||||||
|
|
||||||
const bool base_type_is_specialization_type =
|
if (dependent_member_expr->getBaseType().isNull())
|
||||||
dependent_member_expr->getBaseType()
|
return false;
|
||||||
->getAs<clang::TemplateSpecializationType>() != nullptr;
|
|
||||||
|
|
||||||
const bool base_type_is_not_pointer_type =
|
const auto *tst = dependent_member_expr->getBaseType()
|
||||||
base_type_is_specialization_type &&
|
->getAs<clang::TemplateSpecializationType>();
|
||||||
!dependent_member_expr->getBaseType()
|
|
||||||
->getAs<clang::TemplateSpecializationType>()
|
|
||||||
->isPointerType();
|
|
||||||
|
|
||||||
return (base_type_is_not_null && base_type_is_specialization_type &&
|
if (tst == nullptr)
|
||||||
base_type_is_not_pointer_type);
|
return false;
|
||||||
|
|
||||||
|
return !(dependent_member_expr->getBaseType()
|
||||||
|
->getAs<clang::TemplateSpecializationType>()
|
||||||
|
->isPointerType());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool translation_unit_visitor::is_smart_pointer(
|
bool translation_unit_visitor::is_smart_pointer(
|
||||||
@@ -1554,18 +1557,15 @@ void translation_unit_visitor::
|
|||||||
if (arg.getAsType()->getAs<clang::FunctionType>() != nullptr) {
|
if (arg.getAsType()->getAs<clang::FunctionType>() != nullptr) {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
else if (arg.getAsType()->getAs<clang::TemplateSpecializationType>() !=
|
else if (const auto *nested_template_type =
|
||||||
nullptr) {
|
arg.getAsType()->getAs<clang::TemplateSpecializationType>();
|
||||||
const auto *nested_template_type =
|
nested_template_type != nullptr) {
|
||||||
arg.getAsType()->getAs<clang::TemplateSpecializationType>();
|
|
||||||
|
|
||||||
const auto nested_template_name =
|
const auto nested_template_name =
|
||||||
nested_template_type->getTemplateName()
|
nested_template_type->getTemplateName()
|
||||||
.getAsTemplateDecl()
|
.getAsTemplateDecl()
|
||||||
->getQualifiedNameAsString();
|
->getQualifiedNameAsString();
|
||||||
|
|
||||||
auto [tinst_ns, tinst_name] = cx::util::split_ns(nested_template_name);
|
|
||||||
|
|
||||||
argument.set_name(nested_template_name);
|
argument.set_name(nested_template_name);
|
||||||
|
|
||||||
// Check if this template should be simplified (e.g. system
|
// Check if this template should be simplified (e.g. system
|
||||||
@@ -1640,10 +1640,9 @@ void translation_unit_visitor::process_template_specialization_argument(
|
|||||||
|
|
||||||
// If this is a nested template type - add nested templates as
|
// If this is a nested template type - add nested templates as
|
||||||
// template arguments
|
// template arguments
|
||||||
if (arg.getAsType()->getAs<clang::TemplateSpecializationType>() !=
|
if (const auto *nested_template_type =
|
||||||
nullptr) {
|
|
||||||
const auto *nested_template_type =
|
|
||||||
arg.getAsType()->getAs<clang::TemplateSpecializationType>();
|
arg.getAsType()->getAs<clang::TemplateSpecializationType>();
|
||||||
|
nested_template_type != nullptr) {
|
||||||
|
|
||||||
const auto nested_template_name =
|
const auto nested_template_name =
|
||||||
nested_template_type->getTemplateName()
|
nested_template_type->getTemplateName()
|
||||||
@@ -1653,8 +1652,7 @@ void translation_unit_visitor::process_template_specialization_argument(
|
|||||||
argument.set_name(nested_template_name);
|
argument.set_name(nested_template_name);
|
||||||
|
|
||||||
auto nested_template_instantiation = build_template_instantiation(
|
auto nested_template_instantiation = build_template_instantiation(
|
||||||
*arg.getAsType()->getAs<clang::TemplateSpecializationType>(),
|
*nested_template_type, &template_instantiation);
|
||||||
&template_instantiation);
|
|
||||||
|
|
||||||
argument.set_id(nested_template_instantiation->id());
|
argument.set_id(nested_template_instantiation->id());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user