Fixed clang-tidy warnings

This commit is contained in:
Bartek Kryza
2023-05-27 23:41:16 +02:00
parent e6fa19ff39
commit 5c4a98ba79
5 changed files with 59 additions and 57 deletions

View File

@@ -95,7 +95,7 @@ bool diagram::add_with_namespace_path<common::model::package>(
template <> template <>
bool diagram::add_with_filesystem_path<common::model::package>( bool diagram::add_with_filesystem_path<common::model::package>(
const common::model::path &parent_path, const common::model::path & /*parent_path*/,
std::unique_ptr<common::model::package> &&p) std::unique_ptr<common::model::package> &&p)
{ {
LOG_DBG("Adding filesystem package: {}, {}", p->name(), p->full_name(true)); LOG_DBG("Adding filesystem package: {}, {}", p->name(), p->full_name(true));

View File

@@ -935,9 +935,9 @@ std::optional<template_parameter> template_builder::try_as_decl_type(
std::optional<template_parameter> template_builder::try_as_typedef_type( std::optional<template_parameter> template_builder::try_as_typedef_type(
std::optional<clanguml::class_diagram::model::class_ *> &parent, std::optional<clanguml::class_diagram::model::class_ *> &parent,
const clang::NamedDecl *cls, const clang::TemplateDecl *template_decl, const clang::NamedDecl * /*cls*/,
clang::QualType &type, class_ &template_instantiation, const clang::TemplateDecl * /*template_decl*/, clang::QualType &type,
size_t argument_index) class_ & /*template_instantiation*/, size_t /*argument_index*/)
{ {
const auto *typedef_type = const auto *typedef_type =
common::dereference(type)->getAs<clang::TypedefType>(); common::dereference(type)->getAs<clang::TypedefType>();

View File

@@ -1308,7 +1308,7 @@ void translation_unit_visitor::process_method(
.getUnqualifiedType() .getUnqualifiedType()
->getAs<clang::TemplateSpecializationType>(); ->getAs<clang::TemplateSpecializationType>();
templ != nullptr) { templ != nullptr) {
auto *unaliased_type = templ; const auto *unaliased_type = templ;
if (unaliased_type->isTypeAlias()) if (unaliased_type->isTypeAlias())
unaliased_type = unaliased_type->getAliasedType() unaliased_type = unaliased_type->getAliasedType()
->getAs<clang::TemplateSpecializationType>(); ->getAs<clang::TemplateSpecializationType>();

View File

@@ -75,14 +75,13 @@ public:
std::copy(begin, end, std::back_inserter(path_)); std::copy(begin, end, std::back_inserter(path_));
} }
path(const path &right) path(const path &right) = default;
: path_type_{right.path_type_}
, path_{right.path_}
{
}
path &operator=(const path &right) path &operator=(const path &right)
{ {
if (&right == this)
return *this;
if (path_type_ != right.path_type_) if (path_type_ != right.path_type_)
throw std::runtime_error(""); throw std::runtime_error("");
@@ -161,9 +160,9 @@ public:
void operator|=(const std::string &right) { append(right); } void operator|=(const std::string &right) { append(right); }
std::string &operator[](const int index) { return path_[index]; } std::string &operator[](const unsigned int index) { return path_[index]; }
const std::string &operator[](const int index) const const std::string &operator[](const unsigned int index) const
{ {
return path_[index]; return path_[index];
} }

View File

@@ -258,18 +258,15 @@ common::model::diagram_element::id_t translation_unit_visitor::get_package_id(
return {}; return {};
} }
else {
auto file = source_manager() auto file =
.getFilename(cls->getSourceRange().getBegin()) source_manager().getFilename(cls->getSourceRange().getBegin()).str();
.str(); auto relative_file = util::path_to_url(config().make_path_relative(file));
auto relative_file =
util::path_to_url(config().make_path_relative(file));
common::model::path parent_path{ common::model::path parent_path{
relative_file, common::model::path_type::kFilesystem}; relative_file, common::model::path_type::kFilesystem};
parent_path.pop_back(); parent_path.pop_back();
return common::to_id(parent_path.to_string()); return common::to_id(parent_path.to_string());
}
} }
void translation_unit_visitor::process_class_declaration( void translation_unit_visitor::process_class_declaration(
@@ -469,8 +466,10 @@ 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()) {
if (const auto *enum_decl = type->getAs<clang::EnumType>()->getDecl(); if (const auto *enum_type = type->getAs<clang::EnumType>();
enum_decl != nullptr) { enum_type != nullptr) {
if (const auto *enum_decl = enum_type->getDecl();
enum_decl != nullptr)
relationships.emplace_back( relationships.emplace_back(
get_package_id(enum_decl), relationship_hint); get_package_id(enum_decl), relationship_hint);
} }
@@ -530,28 +529,30 @@ bool translation_unit_visitor::find_relationships(const clang::QualType &type,
} }
} }
} }
else if (type->isRecordType() && type->getAsCXXRecordDecl()) { else if (type->isRecordType()) {
if (const auto *cxxrecord_decl = type->getAsCXXRecordDecl();
cxxrecord_decl != nullptr) {
if (config().package_type() == config::package_type_t::kNamespace) { if (config().package_type() == config::package_type_t::kNamespace) {
const auto *namespace_context = const auto *namespace_context =
type->getAsCXXRecordDecl()->getEnclosingNamespaceContext(); cxxrecord_decl->getEnclosingNamespaceContext();
if (namespace_context != nullptr && if (namespace_context != nullptr &&
namespace_context->isNamespace()) { namespace_context->isNamespace()) {
const auto *namespace_declaration = const auto *namespace_declaration =
clang::cast<clang::NamespaceDecl>(namespace_context); clang::cast<clang::NamespaceDecl>(namespace_context);
if (namespace_declaration != nullptr && if (namespace_declaration != nullptr &&
diagram().should_include( diagram().should_include(common::get_qualified_name(
common::get_qualified_name(*namespace_declaration))) { *namespace_declaration))) {
const auto target_id = const auto target_id = get_package_id(cxxrecord_decl);
get_package_id(type->getAsCXXRecordDecl()); relationships.emplace_back(
relationships.emplace_back(target_id, relationship_hint); target_id, relationship_hint);
result = true; result = true;
} }
} }
} }
else { else {
if (diagram().should_include( if (diagram().should_include(common::get_qualified_name(
common::get_qualified_name(*type->getAsCXXRecordDecl()))) { *type->getAsCXXRecordDecl()))) {
const auto target_id = const auto target_id =
get_package_id(type->getAsCXXRecordDecl()); get_package_id(type->getAsCXXRecordDecl());
relationships.emplace_back(target_id, relationship_hint); relationships.emplace_back(target_id, relationship_hint);
@@ -559,18 +560,20 @@ bool translation_unit_visitor::find_relationships(const clang::QualType &type,
} }
} }
} }
else if (type->isRecordType() && type->getAsRecordDecl()) { else if (const auto *record_decl = type->getAsRecordDecl();
record_decl != nullptr) {
// This is only possible for plain C translation unit, so we don't // This is only possible for plain C translation unit, so we don't
// need to consider namespaces here // need to consider namespaces here
if (config().package_type() == config::package_type_t::kDirectory) { if (config().package_type() == config::package_type_t::kDirectory) {
if (diagram().should_include( if (diagram().should_include(
common::get_qualified_name(*type->getAsRecordDecl()))) { common::get_qualified_name(*record_decl))) {
const auto target_id = get_package_id(type->getAsRecordDecl()); const auto target_id = get_package_id(record_decl);
relationships.emplace_back(target_id, relationship_hint); relationships.emplace_back(target_id, relationship_hint);
result = true; result = true;
} }
} }
} }
}
return result; return result;
} }