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 <>
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)
{
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<clanguml::class_diagram::model::class_ *> &parent,
const clang::NamedDecl *cls, const clang::TemplateDecl *template_decl,
clang::QualType &type, class_ &template_instantiation,
size_t argument_index)
const clang::NamedDecl * /*cls*/,
const clang::TemplateDecl * /*template_decl*/, clang::QualType &type,
class_ & /*template_instantiation*/, size_t /*argument_index*/)
{
const auto *typedef_type =
common::dereference(type)->getAs<clang::TypedefType>();

View File

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

View File

@@ -75,14 +75,13 @@ public:
std::copy(begin, end, std::back_inserter(path_));
}
path(const path &right)
: path_type_{right.path_type_}
, path_{right.path_}
{
}
path(const path &right) = default;
path &operator=(const path &right)
{
if (&right == this)
return *this;
if (path_type_ != right.path_type_)
throw std::runtime_error("");
@@ -161,9 +160,9 @@ public:
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];
}

View File

@@ -258,18 +258,15 @@ common::model::diagram_element::id_t translation_unit_visitor::get_package_id(
return {};
}
else {
auto file = source_manager()
.getFilename(cls->getSourceRange().getBegin())
.str();
auto relative_file =
util::path_to_url(config().make_path_relative(file));
auto file =
source_manager().getFilename(cls->getSourceRange().getBegin()).str();
auto relative_file = util::path_to_url(config().make_path_relative(file));
common::model::path parent_path{
relative_file, common::model::path_type::kFilesystem};
parent_path.pop_back();
return common::to_id(parent_path.to_string());
}
}
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);
}
else if (type->isEnumeralType()) {
if (const auto *enum_decl = type->getAs<clang::EnumType>()->getDecl();
enum_decl != nullptr) {
if (const auto *enum_type = type->getAs<clang::EnumType>();
enum_type != nullptr) {
if (const auto *enum_decl = enum_type->getDecl();
enum_decl != nullptr)
relationships.emplace_back(
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) {
const auto *namespace_context =
type->getAsCXXRecordDecl()->getEnclosingNamespaceContext();
cxxrecord_decl->getEnclosingNamespaceContext();
if (namespace_context != nullptr &&
namespace_context->isNamespace()) {
const auto *namespace_declaration =
clang::cast<clang::NamespaceDecl>(namespace_context);
if (namespace_declaration != nullptr &&
diagram().should_include(
common::get_qualified_name(*namespace_declaration))) {
const auto target_id =
get_package_id(type->getAsCXXRecordDecl());
relationships.emplace_back(target_id, relationship_hint);
diagram().should_include(common::get_qualified_name(
*namespace_declaration))) {
const auto target_id = get_package_id(cxxrecord_decl);
relationships.emplace_back(
target_id, relationship_hint);
result = true;
}
}
}
else {
if (diagram().should_include(
common::get_qualified_name(*type->getAsCXXRecordDecl()))) {
if (diagram().should_include(common::get_qualified_name(
*type->getAsCXXRecordDecl()))) {
const auto target_id =
get_package_id(type->getAsCXXRecordDecl());
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
// need to consider namespaces here
if (config().package_type() == config::package_type_t::kDirectory) {
if (diagram().should_include(
common::get_qualified_name(*type->getAsRecordDecl()))) {
const auto target_id = get_package_id(type->getAsRecordDecl());
common::get_qualified_name(*record_decl))) {
const auto target_id = get_package_id(record_decl);
relationships.emplace_back(target_id, relationship_hint);
result = true;
}
}
}
}
return result;
}