From 673b08f027ec18ea3bc5b622f08295086c48897a Mon Sep 17 00:00:00 2001 From: Bartek Kryza Date: Tue, 19 Jul 2022 23:48:58 +0200 Subject: [PATCH] Fixed t00007 --- .../visitor/translation_unit_visitor.cc | 81 ++++++++++++------- tests/t00007/test_case.h | 2 +- tests/t00008/test_case.h | 2 +- tests/test_cases.cc | 4 +- 4 files changed, 57 insertions(+), 32 deletions(-) diff --git a/src/class_diagram/visitor/translation_unit_visitor.cc b/src/class_diagram/visitor/translation_unit_visitor.cc index e62f5c14..736f8a22 100644 --- a/src/class_diagram/visitor/translation_unit_visitor.cc +++ b/src/class_diagram/visitor/translation_unit_visitor.cc @@ -410,7 +410,6 @@ bool translation_unit_visitor::find_relationships(const clang::QualType &type, clanguml::common::model::relationship_t relationship_hint) { bool result = false; - std::string type_name = type.getAsString(); (void)type_name; @@ -433,14 +432,21 @@ bool translation_unit_visitor::find_relationships(const clang::QualType &type, find_relationships(type->getAsArrayTypeUnsafe()->getElementType(), relationships, relationship_t::kAggregation); } - else if (type->isClassType()) { + else if (type->isRecordType()) { + if(type_name.find("std::shared_ptr") == 0) + relationship_hint = relationship_t::kAssociation; + if(type_name.find("std::weak_ptr") == 0) + relationship_hint = relationship_t::kAssociation; + const auto *type_instantiation_decl = type->getAs(); if (type_instantiation_decl != nullptr) { for (const auto &template_argument : *type_instantiation_decl) { - result = find_relationships(template_argument.getAsType(), - relationships, relationship_hint); + if (template_argument.getKind() == + clang::TemplateArgument::ArgKind::Type) + result = find_relationships(template_argument.getAsType(), + relationships, relationship_hint); } } else { @@ -600,12 +606,12 @@ std::unique_ptr translation_unit_visitor::build_template_instantiation( for (const auto &arg : template_type) { auto argument_kind = arg.getKind(); if (argument_kind == clang::TemplateArgument::ArgKind::Type) { - const auto *argument_record_decl = - arg.getAsType()->getAsRecordDecl(); +// const auto *argument_record_decl = +// arg.getAsType()->getAsRecordDecl(); template_parameter argument; argument.is_template_parameter(false); argument.set_name(to_string( - arg.getAsType(), argument_record_decl->getASTContext())); + arg.getAsType(), template_record->getASTContext())); template_instantiation.add_template(std::move(argument)); @@ -630,36 +636,55 @@ void translation_unit_visitor::process_field( detail::access_specifier_to_access_t(field_declaration.getAccess()), field_declaration.getNameAsString(), type_name}; - if (field.name() == "e") { - LOG_DBG("EEEEEEEEE"); - } - process_comment(field_declaration, field); set_source_location(field_declaration, field); if (field.skip()) return; - if (!field.skip_relationship()) { - found_relationships_t relationships; - // find relationship for the type - find_relationships(field_declaration.getType(), relationships, - relationship_t::kAggregation); + if (field_type->getAs()) { + if (diagram().should_include(type_name)) { + auto template_specialization_ptr = build_template_instantiation( + *field_type->getAs()); - add_relationships(c, relationships, - detail::access_specifier_to_access_t(field_declaration.getAccess()), - field_declaration.getNameAsString()); + relationship r{relationship_t::kAggregation, + template_specialization_ptr->id()}; + r.set_label(field_declaration.getNameAsString()); + r.set_access(detail::access_specifier_to_access_t( + field_declaration.getAccess())); + + diagram().add_class(std::move(template_specialization_ptr)); + + LOG_DBG("ADDED TEMPLATE SPECIALIZATION TO DIAGRAM"); + + c.add_relationship(std::move(r)); + } + else { + if (!field.skip_relationship()) { + found_relationships_t relationships; + // find relationship for the type + find_relationships(field_declaration.getType(), relationships, + relationship_t::kAggregation); + + add_relationships(c, relationships, + detail::access_specifier_to_access_t( + field_declaration.getAccess()), + field_declaration.getNameAsString()); + } + } } + else { + if (!field.skip_relationship()) { + found_relationships_t relationships; + // find relationship for the type + find_relationships(field_declaration.getType(), relationships, + relationship_t::kAggregation); - if (field_type->getAs() && - diagram().should_include(type_name)) { - - auto template_specialization_ptr = build_template_instantiation( - *field_type->getAs()); - - diagram().add_class(std::move(template_specialization_ptr)); - - LOG_DBG("ADDED TEMPLATE SPECIALIZATION TO DIAGRAM"); + add_relationships(c, relationships, + detail::access_specifier_to_access_t( + field_declaration.getAccess()), + field_declaration.getNameAsString()); + } } /* diff --git a/tests/t00007/test_case.h b/tests/t00007/test_case.h index af0c02a0..9c18d33e 100644 --- a/tests/t00007/test_case.h +++ b/tests/t00007/test_case.h @@ -24,7 +24,7 @@ TEST_CASE("t00007", "[test-case][class]") REQUIRE(diagram->name == "t00007_class"); - auto model = generate_class_diagram(db, diagram); + auto model = generate_class_diagram(*db, diagram); REQUIRE(model->name() == "t00007_class"); diff --git a/tests/t00008/test_case.h b/tests/t00008/test_case.h index ce30cc75..c96d7f9c 100644 --- a/tests/t00008/test_case.h +++ b/tests/t00008/test_case.h @@ -24,7 +24,7 @@ TEST_CASE("t00008", "[test-case][class]") REQUIRE(diagram->name == "t00008_class"); - auto model = generate_class_diagram(db, diagram); + auto model = generate_class_diagram(*db, diagram); REQUIRE(model->name() == "t00008_class"); diff --git a/tests/test_cases.cc b/tests/test_cases.cc index 20b33179..d729864a 100644 --- a/tests/test_cases.cc +++ b/tests/test_cases.cc @@ -195,8 +195,8 @@ using namespace clanguml::test::matchers; #include "t00004/test_case.h" #include "t00005/test_case.h" #include "t00006/test_case.h" -//#include "t00007/test_case.h" -//#include "t00008/test_case.h" +#include "t00007/test_case.h" +#include "t00008/test_case.h" //#include "t00009/test_case.h" //#include "t00010/test_case.h" //#include "t00011/test_case.h"