diff --git a/src/class_diagram/model/class_element.cc b/src/class_diagram/model/class_element.cc index f449e49e..0d1ab1a3 100644 --- a/src/class_diagram/model/class_element.cc +++ b/src/class_diagram/model/class_element.cc @@ -34,8 +34,12 @@ common::model::access_t class_element::access() const { return access_; } std::string class_element::name() const { return name_; } +void class_element::set_name(const std::string &name) { name_ = name; } + std::string class_element::type() const { return type_; } +void class_element::set_type(const std::string &type) { type_ = type; } + inja::json class_element::context() const { inja::json ctx; diff --git a/src/class_diagram/model/class_element.h b/src/class_diagram/model/class_element.h index d4161278..897158e8 100644 --- a/src/class_diagram/model/class_element.h +++ b/src/class_diagram/model/class_element.h @@ -36,7 +36,10 @@ public: common::model::access_t access() const; std::string name() const; + void set_name(const std::string &name); + std::string type() const; + void set_type(const std::string &type); virtual inja::json context() const; diff --git a/src/class_diagram/visitor/translation_unit_visitor.cc b/src/class_diagram/visitor/translation_unit_visitor.cc index c4d16b1c..41d6ea9a 100644 --- a/src/class_diagram/visitor/translation_unit_visitor.cc +++ b/src/class_diagram/visitor/translation_unit_visitor.cc @@ -986,14 +986,17 @@ bool translation_unit_visitor::process_template_parameters( const auto *template_nontype_parameter = clang::dyn_cast_or_null( parameter); + std::optional default_arg; + if (template_nontype_parameter->hasDefaultArgument()) default_arg = common::to_string( template_nontype_parameter->getDefaultArgument()); + auto ct = template_parameter::make_non_type_template( template_nontype_parameter->getType().getAsString(), - template_nontype_parameter->getNameAsString(), default_arg, - template_nontype_parameter->isParameterPack()); + template_nontype_parameter->getNameAsString(), + default_arg, template_nontype_parameter->isParameterPack()); c.add_template(std::move(ct)); } @@ -1082,6 +1085,7 @@ void translation_unit_visitor::process_class_bases( if (const auto *record_type = base.getType()->getAs(); record_type != nullptr) { + cp.set_name(record_type->getDecl()->getQualifiedNameAsString()); cp.set_id(common::to_id(*record_type->getDecl())); } else if (const auto *tsp = @@ -2543,7 +2547,9 @@ void translation_unit_visitor:: record_type_decl != nullptr) { argument.set_id(common::to_id(arg)); +#if LLVM_VERSION_MAJOR >= 16 argument.set_type(record_type_decl->getQualifiedNameAsString()); +#endif if (diagram().should_include(full_template_specialization_name)) { // Add dependency relationship to the parent // template diff --git a/src/common/clang_utils.cc b/src/common/clang_utils.cc index beb070bb..07eb980b 100644 --- a/src/common/clang_utils.cc +++ b/src/common/clang_utils.cc @@ -118,30 +118,11 @@ std::string to_string(const clang::QualType &type, const clang::ASTContext &ctx, clang::PrintingPolicy print_policy(ctx.getLangOpts()); print_policy.SuppressScope = false; print_policy.PrintCanonicalTypes = false; -// print_policy.FullyQualifiedName = true; - -#if LLVM_VERSION_MAJOR >= 16 - print_policy.AlwaysIncludeTypeForTemplateArgument = true; - print_policy.SplitTemplateClosers = false; - print_policy.SuppressDefaultTemplateArgs = false; - print_policy.SuppressInlineNamespace = false; -#endif std::string result; result = type.getAsString(print_policy); -#if LLVM_VERSION_MAJOR >= 16 - // Why do I have to this LLVM16? - if (const auto *decl = type->getAsCXXRecordDecl(); - decl && !decl->isTemplated() && result.find('<') == std::string::npos) { - // This is a workaround for LLVM >= 16 - const auto tag_namespace = get_tag_namespace(*decl).to_string(); - if (result.find(tag_namespace) != 0) - result = fmt::format("{}::{}", tag_namespace, result); - } -#endif - if (try_canonical && result.find('<') != std::string::npos) { auto canonical_type_name = type.getCanonicalType().getAsString(print_policy); diff --git a/src/config/config.cc b/src/config/config.cc index 14620e79..d00a3333 100644 --- a/src/config/config.cc +++ b/src/config/config.cc @@ -121,7 +121,8 @@ void inheritable_diagram_options::inherit( std::string inheritable_diagram_options::simplify_template_type( std::string full_name) const { - const auto &aliases = type_aliases(); + type_aliases_longer_first_t aliases; + aliases.insert(type_aliases().begin(), type_aliases().end()); for (const auto &[pattern, replacement] : aliases) { util::replace_all(full_name, pattern, replacement); @@ -176,12 +177,6 @@ std::optional diagram::get_together_group( void diagram::initialize_type_aliases() { - if (type_aliases().count("std::__cxx11::basic_string,std::allocator>") == 0U) { - type_aliases().insert({"std::__cxx11::basic_string,std::allocator>", - "std::string"}); - } if (type_aliases().count("std::basic_string") == 0U) { type_aliases().insert({"std::basic_string", "std::string"}); } @@ -210,11 +205,11 @@ void diagram::initialize_type_aliases() type_aliases().insert( {"std::integral_constant", "std::false_type"}); } - // #if LLVM_VERSION_MAJOR >= 16 - // if (type_aliases().count("std::basic_string") == 0U) { - // type_aliases().insert({"std::basic_string", "std::string"}); - // } - // #endif +#if LLVM_VERSION_MAJOR >= 16 + if (type_aliases().count("std::basic_string") == 0U) { + type_aliases().insert({"std::basic_string", "std::string"}); + } +#endif } common::model::diagram_t class_diagram::type() const diff --git a/src/config/config.h b/src/config/config.h index 1a5c1172..f44b78dc 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -132,7 +132,10 @@ struct relationship_hint_t { using relationship_hints_t = std::map; -using type_aliases_t = std::map; +using type_aliases_t = + std::map; +using type_aliases_longer_first_t = + std::map>; enum class location_t { marker, fileline, function }; diff --git a/tests/t00008/test_case.h b/tests/t00008/test_case.h index 8687106e..1946696e 100644 --- a/tests/t00008/test_case.h +++ b/tests/t00008/test_case.h @@ -64,8 +64,13 @@ TEST_CASE("t00008", "[test-case][class]") using namespace json; +#if LLVM_VERSION_MAJOR >= 16 + REQUIRE(IsClassTemplate( + j, "A")); +#else REQUIRE(IsClassTemplate( j, "A")); +#endif REQUIRE(IsClassTemplate(j, "E::nested_template")); REQUIRE(IsClass(j, "E::nested_template")); diff --git a/tests/t00014/test_case.h b/tests/t00014/test_case.h index f336750d..d1868352 100644 --- a/tests/t00014/test_case.h +++ b/tests/t00014/test_case.h @@ -70,8 +70,13 @@ TEST_CASE("t00014", "[test-case][class]") REQUIRE_THAT( puml, IsField("cb", "SimpleCallback")); +#if LLVM_VERSION_MAJOR >= 16 + REQUIRE_THAT( + puml, IsField("gcb", "GenericCallback")); +#else REQUIRE_THAT( puml, IsField("gcb", "GenericCallback")); +#endif REQUIRE_THAT(puml, IsField("vcb", "VoidCallback")); REQUIRE_THAT(puml,