Fixed generation of template specializations from alias template type members

This commit is contained in:
Bartek Kryza
2023-05-13 12:41:50 +02:00
parent 3b99ca1313
commit 2223f595cd
3 changed files with 35 additions and 21 deletions

View File

@@ -1852,8 +1852,11 @@ void translation_unit_visitor::process_field(
if (template_field_type != nullptr && if (template_field_type != nullptr &&
!field_type_is_template_template_parameter) { !field_type_is_template_template_parameter) {
// Build the template instantiation for the field type // Build the template instantiation for the field type
auto template_specialization_ptr = auto template_specialization_ptr = tbuilder().build(
tbuilder().build(&field_declaration, *template_field_type, {&c}); field_type->getAs<clang::TemplateSpecializationType>()
->getTemplateName()
.getAsTemplateDecl(),
*template_field_type, {&c});
if (!field.skip_relationship() && template_specialization_ptr) { if (!field.skip_relationship() && template_specialization_ptr) {
const auto &template_specialization = *template_specialization_ptr; const auto &template_specialization = *template_specialization_ptr;
@@ -1862,14 +1865,14 @@ void translation_unit_visitor::process_field(
// current diagram. Even if the top level template type for // current diagram. Even if the top level template type for
// this instantiation should not be part of the diagram, e.g. // this instantiation should not be part of the diagram, e.g.
// it's a std::vector<>, it's nested types might be added // it's a std::vector<>, it's nested types might be added
bool add_template_instantiation_to_diargam{false}; bool add_template_instantiation_to_diagram{false};
if (diagram().should_include( if (diagram().should_include(
template_specialization.full_name(false))) { template_specialization.full_name(false))) {
found_relationships_t::value_type r{ found_relationships_t::value_type r{
template_specialization.id(), relationship_hint}; template_specialization.id(), relationship_hint};
add_template_instantiation_to_diargam = true; add_template_instantiation_to_diagram = true;
// If the template instantiation for the build type has been // If the template instantiation for the build type has been
// added as aggregation, skip its nested templates // added as aggregation, skip its nested templates
@@ -1910,7 +1913,7 @@ void translation_unit_visitor::process_field(
// Add the template instantiation object to the diagram if it // Add the template instantiation object to the diagram if it
// matches the include pattern // matches the include pattern
if (add_template_instantiation_to_diargam) if (add_template_instantiation_to_diagram)
diagram().add_class(std::move(template_specialization_ptr)); diagram().add_class(std::move(template_specialization_ptr));
} }
} }

View File

@@ -36,6 +36,7 @@ using PairPairBA = std::pair<std::pair<B, A<long, T>>, long>;
template <class T> using VectorPtr = std::unique_ptr<std::vector<T>>; template <class T> using VectorPtr = std::unique_ptr<std::vector<T>>;
template <class T> using APtr = std::unique_ptr<A<double, T>>; template <class T> using APtr = std::unique_ptr<A<double, T>>;
template <class T> using ASharedPtr = std::shared_ptr<A<double, T>>; template <class T> using ASharedPtr = std::shared_ptr<A<double, T>>;
template <class T, class U> template <class T, class U>
using AAPtr = std::unique_ptr<std::pair<A<double, T>, A<long, U>>>; using AAPtr = std::unique_ptr<std::pair<A<double, T>, A<long, U>>>;
@@ -52,7 +53,7 @@ using ACharString = AString<char>;
using AStringString = AString<std::string>; using AStringString = AString<std::string>;
using BStringString = AStringString; using BStringString = AStringString;
class R { template <typename T> class R {
using AWCharString = AString<wchar_t>; using AWCharString = AString<wchar_t>;
PairPairBA<bool> bapair; PairPairBA<bool> bapair;
@@ -65,6 +66,7 @@ class R {
AIntString intstring; AIntString intstring;
AStringString stringstring; AStringString stringstring;
BStringString bstringstring; BStringString bstringstring;
AAPtr<T, float> atfloat;
protected: protected:
BVector bs; BVector bs;

View File

@@ -53,6 +53,7 @@ TEST_CASE("t00014", "[test-case][class]")
REQUIRE_THAT(puml, IsClassTemplate("A", "std::string,std::string")); REQUIRE_THAT(puml, IsClassTemplate("A", "std::string,std::string"));
REQUIRE_THAT(puml, IsClassTemplate("A", "char,std::string")); REQUIRE_THAT(puml, IsClassTemplate("A", "char,std::string"));
REQUIRE_THAT(puml, IsClass(_A("B"))); REQUIRE_THAT(puml, IsClass(_A("B")));
REQUIRE_THAT(puml, IsClassTemplate("R", "T"));
REQUIRE_THAT(puml, IsField<Private>("bapair", "PairPairBA<bool>")); REQUIRE_THAT(puml, IsField<Private>("bapair", "PairPairBA<bool>"));
REQUIRE_THAT(puml, IsField<Private>("abool", "APtr<bool>")); REQUIRE_THAT(puml, IsField<Private>("abool", "APtr<bool>"));
@@ -62,6 +63,8 @@ TEST_CASE("t00014", "[test-case][class]")
puml, IsField<Private>("boolstring", "A<bool,std::string>")); puml, IsField<Private>("boolstring", "A<bool,std::string>"));
REQUIRE_THAT( REQUIRE_THAT(
puml, IsField<Private>("floatstring", "AStringPtr<float>")); puml, IsField<Private>("floatstring", "AStringPtr<float>"));
REQUIRE_THAT(puml, IsField<Private>("atfloat", "AAPtr<T,float>"));
REQUIRE_THAT(puml, IsField<Private>("intstring", "AIntString")); REQUIRE_THAT(puml, IsField<Private>("intstring", "AIntString"));
REQUIRE_THAT(puml, IsField<Private>("stringstring", "AStringString")); REQUIRE_THAT(puml, IsField<Private>("stringstring", "AStringString"));
REQUIRE_THAT(puml, IsField<Private>("bstringstring", "BStringString")); REQUIRE_THAT(puml, IsField<Private>("bstringstring", "BStringString"));
@@ -114,23 +117,29 @@ TEST_CASE("t00014", "[test-case][class]")
IsInstantiation( IsInstantiation(
_A("A<T,P>"), _A("A<T,std::unique_ptr<std::string>>"))); _A("A<T,P>"), _A("A<T,std::unique_ptr<std::string>>")));
REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("B"), "+vps")); REQUIRE_THAT(puml, IsAggregation(_A("R<T>"), _A("B"), "+vps"));
REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("B"), "-bapair")); REQUIRE_THAT(puml, IsAggregation(_A("R<T>"), _A("B"), "-bapair"));
REQUIRE_THAT(
puml, IsAggregation(_A("R"), _A("A<long,float>"), "-aboolfloat"));
REQUIRE_THAT(
puml, IsAggregation(_A("R"), _A("A<long,bool>"), "-bapair"));
REQUIRE_THAT(
puml, IsAggregation(_A("R"), _A("A<double,bool>"), "-aboolfloat"));
REQUIRE_THAT(
puml, IsAssociation(_A("R"), _A("A<double,float>"), "-afloat"));
REQUIRE_THAT(puml, REQUIRE_THAT(puml,
IsAggregation(_A("R"), _A("A<bool,std::string>"), "-boolstring")); IsAggregation(_A("R<T>"), _A("A<long,float>"), "-aboolfloat"));
REQUIRE_THAT(
puml, IsAggregation(_A("R<T>"), _A("A<long,bool>"), "-bapair"));
REQUIRE_THAT(puml, REQUIRE_THAT(puml,
IsAggregation(_A("R"), _A("A<float,std::unique_ptr<std::string>>"), IsAggregation(_A("R<T>"), _A("A<double,bool>"), "-aboolfloat"));
"-floatstring")); REQUIRE_THAT(
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("A<char,std::string>"))); puml, IsAggregation(_A("R<T>"), _A("A<double,T>"), "-atfloat"));
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("A<wchar_t,std::string>"))); REQUIRE_THAT(
puml, IsAggregation(_A("R<T>"), _A("A<long,float>"), "-atfloat"));
REQUIRE_THAT(
puml, IsAssociation(_A("R<T>"), _A("A<double,float>"), "-afloat"));
REQUIRE_THAT(puml,
IsAggregation(
_A("R<T>"), _A("A<bool,std::string>"), "-boolstring"));
REQUIRE_THAT(puml,
IsAggregation(_A("R<T>"),
_A("A<float,std::unique_ptr<std::string>>"), "-floatstring"));
REQUIRE_THAT(puml, IsDependency(_A("R<T>"), _A("A<char,std::string>")));
REQUIRE_THAT(
puml, IsDependency(_A("R<T>"), _A("A<wchar_t,std::string>")));
save_puml( save_puml(
config.output_directory() + "/" + diagram->name + ".puml", puml); config.output_directory() + "/" + diagram->name + ".puml", puml);