diff --git a/src/class_diagram/model/diagram.cc b/src/class_diagram/model/diagram.cc index b250ca86..e5fd697c 100644 --- a/src/class_diagram/model/diagram.cc +++ b/src/class_diagram/model/diagram.cc @@ -95,7 +95,7 @@ bool diagram::add_with_namespace_path( template <> bool diagram::add_with_filesystem_path( - const common::model::path &parent_path, + const common::model::path & /*parent_path*/, std::unique_ptr &&p) { LOG_DBG("Adding filesystem package: {}, {}", p->name(), p->full_name(true)); diff --git a/src/class_diagram/visitor/template_builder.cc b/src/class_diagram/visitor/template_builder.cc index a7375d7f..46be21b3 100644 --- a/src/class_diagram/visitor/template_builder.cc +++ b/src/class_diagram/visitor/template_builder.cc @@ -935,9 +935,9 @@ std::optional template_builder::try_as_decl_type( std::optional template_builder::try_as_typedef_type( std::optional &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(); diff --git a/src/class_diagram/visitor/translation_unit_visitor.cc b/src/class_diagram/visitor/translation_unit_visitor.cc index 05c89c08..0d9dfd4a 100644 --- a/src/class_diagram/visitor/translation_unit_visitor.cc +++ b/src/class_diagram/visitor/translation_unit_visitor.cc @@ -1308,7 +1308,7 @@ void translation_unit_visitor::process_method( .getUnqualifiedType() ->getAs(); templ != nullptr) { - auto *unaliased_type = templ; + const auto *unaliased_type = templ; if (unaliased_type->isTypeAlias()) unaliased_type = unaliased_type->getAliasedType() ->getAs(); diff --git a/src/common/model/path.h b/src/common/model/path.h index 577b24f0..f182f141 100644 --- a/src/common/model/path.h +++ b/src/common/model/path.h @@ -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]; } diff --git a/src/package_diagram/visitor/translation_unit_visitor.cc b/src/package_diagram/visitor/translation_unit_visitor.cc index ae706c92..3f3a77d2 100644 --- a/src/package_diagram/visitor/translation_unit_visitor.cc +++ b/src/package_diagram/visitor/translation_unit_visitor.cc @@ -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)); - common::model::path parent_path{ - relative_file, common::model::path_type::kFilesystem}; - parent_path.pop_back(); - return common::to_id(parent_path.to_string()); - } + 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,10 +466,12 @@ 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()->getDecl(); - enum_decl != nullptr) { - relationships.emplace_back( - get_package_id(enum_decl), relationship_hint); + if (const auto *enum_type = type->getAs(); + enum_type != nullptr) { + if (const auto *enum_decl = enum_type->getDecl(); + enum_decl != nullptr) + relationships.emplace_back( + get_package_id(enum_decl), relationship_hint); } } else if (const auto *template_specialization_type = @@ -530,18 +529,30 @@ bool translation_unit_visitor::find_relationships(const clang::QualType &type, } } } - else if (type->isRecordType() && type->getAsCXXRecordDecl()) { - if (config().package_type() == config::package_type_t::kNamespace) { - const auto *namespace_context = - type->getAsCXXRecordDecl()->getEnclosingNamespaceContext(); - if (namespace_context != nullptr && - namespace_context->isNamespace()) { - const auto *namespace_declaration = - clang::cast(namespace_context); + 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 = + cxxrecord_decl->getEnclosingNamespaceContext(); + if (namespace_context != nullptr && + namespace_context->isNamespace()) { + const auto *namespace_declaration = + clang::cast(namespace_context); - if (namespace_declaration != nullptr && - diagram().should_include( - common::get_qualified_name(*namespace_declaration))) { + if (namespace_declaration != nullptr && + 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()))) { const auto target_id = get_package_id(type->getAsCXXRecordDecl()); relationships.emplace_back(target_id, relationship_hint); @@ -549,25 +560,17 @@ bool translation_unit_visitor::find_relationships(const clang::QualType &type, } } } - else { - 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); - result = true; - } - } - } - else if (type->isRecordType() && type->getAsRecordDecl()) { - // 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()); - relationships.emplace_back(target_id, relationship_hint); - result = true; + 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(*record_decl))) { + const auto target_id = get_package_id(record_decl); + relationships.emplace_back(target_id, relationship_hint); + result = true; + } } } }