Added test case for inner type aliases with parent class template args
This commit is contained in:
@@ -99,15 +99,16 @@ void diagram::add_type_alias(std::unique_ptr<type_alias> &&ta)
|
|||||||
type_aliases_[ta->alias()] = std::move(ta);
|
type_aliases_[ta->alias()] = std::move(ta);
|
||||||
}
|
}
|
||||||
|
|
||||||
void diagram::add_package(std::unique_ptr<common::model::package> &&p)
|
bool diagram::add_package(std::unique_ptr<common::model::package> &&p)
|
||||||
{
|
{
|
||||||
LOG_DBG("Adding namespace package: {}, {}", p->name(), p->full_name(true));
|
LOG_DBG("Adding namespace package: {}, {}", p->name(), p->full_name(true));
|
||||||
|
|
||||||
auto ns = p->get_relative_namespace();
|
auto ns = p->get_relative_namespace();
|
||||||
add_element(ns, std::move(p));
|
|
||||||
|
return add_element(ns, std::move(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
void diagram::add_class(std::unique_ptr<class_> &&c)
|
bool diagram::add_class(std::unique_ptr<class_> &&c)
|
||||||
{
|
{
|
||||||
const auto base_name = c->name();
|
const auto base_name = c->name();
|
||||||
const auto full_name = c->full_name(false);
|
const auto full_name = c->full_name(false);
|
||||||
@@ -128,33 +129,48 @@ void diagram::add_class(std::unique_ptr<class_> &&c)
|
|||||||
auto name = base_name;
|
auto name = base_name;
|
||||||
auto name_with_ns = c->name_and_ns();
|
auto name_with_ns = c->name_and_ns();
|
||||||
auto name_and_ns = ns | name;
|
auto name_and_ns = ns | name;
|
||||||
|
const auto &cc = *c;
|
||||||
|
|
||||||
if (!has_class(*c)) {
|
auto cc_ref = type_safe::ref(cc);
|
||||||
classes_.push_back(type_safe::ref(*c));
|
|
||||||
|
|
||||||
add_element(ns, std::move(c));
|
if (!has_class(cc)) {
|
||||||
|
if (add_element(ns, std::move(c)))
|
||||||
|
classes_.push_back(std::move(cc_ref));
|
||||||
|
|
||||||
const auto &el = get_element<class_>(name_and_ns).value();
|
const auto &el = get_element<class_>(name_and_ns).value();
|
||||||
|
|
||||||
assert(el.name() == name);
|
assert(el.name() == name);
|
||||||
assert(el.get_relative_namespace() == ns);
|
assert(el.get_relative_namespace() == ns);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
LOG_DBG("Class {} ({}) already in the model", base_name, full_name);
|
LOG_DBG("Class {} ({}) already in the model", base_name, full_name);
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void diagram::add_enum(std::unique_ptr<enum_> &&e)
|
bool diagram::add_enum(std::unique_ptr<enum_> &&e)
|
||||||
{
|
{
|
||||||
LOG_DBG("Adding enum: {}", e->name());
|
const auto full_name = e->name();
|
||||||
|
|
||||||
|
LOG_DBG("Adding enum: {}", full_name);
|
||||||
|
|
||||||
assert(!util::contains(e->name(), "::"));
|
assert(!util::contains(e->name(), "::"));
|
||||||
|
|
||||||
|
auto e_ref = type_safe::ref(*e);
|
||||||
|
auto ns = e->get_relative_namespace();
|
||||||
|
|
||||||
if (!has_enum(*e)) {
|
if (!has_enum(*e)) {
|
||||||
enums_.emplace_back(*e);
|
if (add_element(ns, std::move(e))) {
|
||||||
auto ns = e->get_relative_namespace();
|
enums_.emplace_back(std::move(e_ref));
|
||||||
add_element(ns, std::move(e));
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
LOG_DBG("Enum {} already in the model", e->name());
|
LOG_DBG("Enum {} already in the model", full_name);
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void diagram::get_parents(
|
void diagram::get_parents(
|
||||||
|
|||||||
@@ -63,11 +63,11 @@ public:
|
|||||||
|
|
||||||
void add_type_alias(std::unique_ptr<type_alias> &&ta);
|
void add_type_alias(std::unique_ptr<type_alias> &&ta);
|
||||||
|
|
||||||
void add_class(std::unique_ptr<class_> &&c);
|
bool add_class(std::unique_ptr<class_> &&c);
|
||||||
|
|
||||||
void add_enum(std::unique_ptr<enum_> &&e);
|
bool add_enum(std::unique_ptr<enum_> &&e);
|
||||||
|
|
||||||
void add_package(std::unique_ptr<common::model::package> &&p);
|
bool add_package(std::unique_ptr<common::model::package> &&p);
|
||||||
|
|
||||||
std::string to_alias(const std::string &full_name) const;
|
std::string to_alias(const std::string &full_name) const;
|
||||||
|
|
||||||
|
|||||||
@@ -765,9 +765,12 @@ bool translation_unit_visitor::process_field_with_template_instantiation(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto tinst_namespace = tinst.get_namespace();
|
||||||
|
const auto tinst_name = tinst.name();
|
||||||
|
|
||||||
// Add instantiation relationship from the generated template instantiation
|
// Add instantiation relationship from the generated template instantiation
|
||||||
// of the field type to its primary template
|
// of the field type to its primary template
|
||||||
if (ctx.diagram().should_include(tinst.get_namespace(), tinst.name())) {
|
if (ctx.diagram().should_include(tinst_namespace, tinst_name)) {
|
||||||
LOG_DBG("Adding field instantiation relationship {} {} {} : {}",
|
LOG_DBG("Adding field instantiation relationship {} {} {} : {}",
|
||||||
rr.destination(), clanguml::common::model::to_string(rr.type()),
|
rr.destination(), clanguml::common::model::to_string(rr.type()),
|
||||||
c.full_name(), rr.label());
|
c.full_name(), rr.label());
|
||||||
@@ -787,7 +790,7 @@ bool translation_unit_visitor::process_field_with_template_instantiation(
|
|||||||
// Only add nested template relationships to this class if the top level
|
// Only add nested template relationships to this class if the top level
|
||||||
// template is not in the diagram (e.g. it is a std::shared_ptr<>)
|
// template is not in the diagram (e.g. it is a std::shared_ptr<>)
|
||||||
//
|
//
|
||||||
if (!ctx.diagram().should_include(tinst.get_namespace(), tinst.name())) {
|
if (!ctx.diagram().should_include(tinst_namespace, tinst_name)) {
|
||||||
res = add_nested_template_relationships(mv, c, member, as, tinst,
|
res = add_nested_template_relationships(mv, c, member, as, tinst,
|
||||||
relationship_type, decorator_rtype, decorator_rmult);
|
relationship_type, decorator_rtype, decorator_rmult);
|
||||||
}
|
}
|
||||||
@@ -1660,16 +1663,21 @@ std::unique_ptr<class_> translation_unit_visitor::build_template_instantiation(
|
|||||||
|
|
||||||
tinst.set_namespace(ctx.get_namespace());
|
tinst.set_namespace(ctx.get_namespace());
|
||||||
|
|
||||||
auto tinst_full_name = cppast::to_string(t);
|
std::string tinst_full_name;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Typically, every template instantiation should have a
|
// Typically, every template instantiation should have a
|
||||||
// primary_template() which should also be generated here if it doesn't
|
// primary_template(), which should also be generated here if it doesn't
|
||||||
// exist yet in the model
|
// exist yet in the model
|
||||||
//
|
//
|
||||||
if (t.primary_template().get(ctx.entity_index()).size()) {
|
if (t_is_alias &&
|
||||||
auto size = t.primary_template().get(ctx.entity_index()).size();
|
unaliased.primary_template().get(ctx.entity_index()).size()) {
|
||||||
(void)size;
|
tinst_full_name = cppast::to_string(unaliased);
|
||||||
|
build_template_instantiation_primary_template(
|
||||||
|
unaliased, tinst, template_base_params, parent, full_template_name);
|
||||||
|
}
|
||||||
|
else if (t.primary_template().get(ctx.entity_index()).size()) {
|
||||||
|
tinst_full_name = cppast::to_string(t);
|
||||||
build_template_instantiation_primary_template(
|
build_template_instantiation_primary_template(
|
||||||
t, tinst, template_base_params, parent, full_template_name);
|
t, tinst, template_base_params, parent, full_template_name);
|
||||||
}
|
}
|
||||||
@@ -1677,6 +1685,7 @@ std::unique_ptr<class_> translation_unit_visitor::build_template_instantiation(
|
|||||||
LOG_DBG("Template instantiation {} has no primary template?",
|
LOG_DBG("Template instantiation {} has no primary template?",
|
||||||
cppast::to_string(t));
|
cppast::to_string(t));
|
||||||
|
|
||||||
|
tinst_full_name = cppast::to_string(t);
|
||||||
full_template_name = cppast::to_string(t);
|
full_template_name = cppast::to_string(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,21 +38,24 @@ public:
|
|||||||
|
|
||||||
virtual ~nested_trait() = default;
|
virtual ~nested_trait() = default;
|
||||||
|
|
||||||
template <typename V = T> void add_element(std::unique_ptr<V> p)
|
template <typename V = T>
|
||||||
|
[[nodiscard]] bool add_element(std::unique_ptr<V> p)
|
||||||
{
|
{
|
||||||
auto it = std::find_if(elements_.begin(), elements_.end(),
|
auto it = std::find_if(elements_.begin(), elements_.end(),
|
||||||
[&p](const auto &e) { return *e == *p; });
|
[&p](const auto &e) { return *e == *p; });
|
||||||
|
|
||||||
if (it != elements_.end()) {
|
if (it != elements_.end()) {
|
||||||
(*it)->append(*p);
|
// Element already in element tree
|
||||||
}
|
return false;
|
||||||
else {
|
|
||||||
elements_.emplace_back(std::move(p));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
elements_.emplace_back(std::move(p));
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename V = T>
|
template <typename V = T>
|
||||||
void add_element(const Path &path, std::unique_ptr<V> p)
|
bool add_element(const Path &path, std::unique_ptr<V> p)
|
||||||
{
|
{
|
||||||
assert(p);
|
assert(p);
|
||||||
|
|
||||||
@@ -60,14 +63,13 @@ public:
|
|||||||
path.to_string());
|
path.to_string());
|
||||||
|
|
||||||
if (path.is_empty()) {
|
if (path.is_empty()) {
|
||||||
add_element(std::move(p));
|
return add_element(std::move(p));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto parent = get_element(path);
|
auto parent = get_element(path);
|
||||||
|
|
||||||
if (parent && dynamic_cast<nested_trait<T, Path> *>(&parent.value()))
|
if (parent && dynamic_cast<nested_trait<T, Path> *>(&parent.value()))
|
||||||
dynamic_cast<nested_trait<T, Path> &>(parent.value())
|
return dynamic_cast<nested_trait<T, Path> &>(parent.value())
|
||||||
.template add_element<V>(std::move(p));
|
.template add_element<V>(std::move(p));
|
||||||
else {
|
else {
|
||||||
spdlog::error("No parent element found at: {}", path.to_string());
|
spdlog::error("No parent element found at: {}", path.to_string());
|
||||||
|
|||||||
@@ -132,7 +132,8 @@ void translation_unit_visitor::process_external_system_header(
|
|||||||
f->set_name(include_directive.name());
|
f->set_name(include_directive.name());
|
||||||
f->set_type(common::model::source_file_t::kHeader);
|
f->set_type(common::model::source_file_t::kHeader);
|
||||||
|
|
||||||
ctx.diagram().add_element(std::move(f));
|
if (!ctx.diagram().add_element(std::move(f)))
|
||||||
|
LOG_DBG("Include {} already in the model", include_directive.name());
|
||||||
|
|
||||||
auto dependency_relationship = common::model::relationship{
|
auto dependency_relationship = common::model::relationship{
|
||||||
common::model::relationship_t::kDependency,
|
common::model::relationship_t::kDependency,
|
||||||
|
|||||||
@@ -48,11 +48,13 @@ using BVector2 = BVector;
|
|||||||
|
|
||||||
using AIntString = AString<int>;
|
using AIntString = AString<int>;
|
||||||
using ACharString = AString<char>;
|
using ACharString = AString<char>;
|
||||||
using AWCharString = AString<wchar_t>;
|
|
||||||
using AStringString = AString<std::string>;
|
using AStringString = AString<std::string>;
|
||||||
using BStringString = AStringString;
|
using BStringString = AStringString;
|
||||||
|
|
||||||
class R {
|
class R {
|
||||||
|
using AWCharString = AString<wchar_t>;
|
||||||
|
|
||||||
PairPairBA<bool> bapair;
|
PairPairBA<bool> bapair;
|
||||||
|
|
||||||
APtr<bool> abool;
|
APtr<bool> abool;
|
||||||
|
|||||||
@@ -61,7 +61,8 @@ TEST_CASE("t00014", "[test-case][class]")
|
|||||||
REQUIRE_THAT(puml, IsField<Protected>("bs", "BVector"));
|
REQUIRE_THAT(puml, IsField<Protected>("bs", "BVector"));
|
||||||
|
|
||||||
REQUIRE_THAT(puml, IsField<Public>("cb", "SimpleCallback<ACharString>"));
|
REQUIRE_THAT(puml, IsField<Public>("cb", "SimpleCallback<ACharString>"));
|
||||||
REQUIRE_THAT(puml, IsField<Public>("gcb", "GenericCallback<AWCharString>"));
|
REQUIRE_THAT(
|
||||||
|
puml, IsField<Public>("gcb", "GenericCallback<R::AWCharString>"));
|
||||||
REQUIRE_THAT(puml, IsField<Public>("vcb", "VoidCallback"));
|
REQUIRE_THAT(puml, IsField<Public>("vcb", "VoidCallback"));
|
||||||
|
|
||||||
REQUIRE_THAT(
|
REQUIRE_THAT(
|
||||||
|
|||||||
13
tests/t00044/.clang-uml
Normal file
13
tests/t00044/.clang-uml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
compilation_database_dir: ..
|
||||||
|
output_directory: puml
|
||||||
|
diagrams:
|
||||||
|
t00044_class:
|
||||||
|
type: class
|
||||||
|
generate_packages: true
|
||||||
|
glob:
|
||||||
|
- ../../tests/t00044/t00044.cc
|
||||||
|
using_namespace:
|
||||||
|
- clanguml::t00044
|
||||||
|
include:
|
||||||
|
namespaces:
|
||||||
|
- clanguml::t00044
|
||||||
35
tests/t00044/t00044.cc
Normal file
35
tests/t00044/t00044.cc
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
// Inspired by skypjack/entt signal handlers
|
||||||
|
// This test case checks that at least clang-uml does not crash on this code
|
||||||
|
namespace clanguml::t00044 {
|
||||||
|
|
||||||
|
template <typename T> class sink;
|
||||||
|
|
||||||
|
template <typename T, typename A> class signal_handler;
|
||||||
|
|
||||||
|
template <typename Ret, typename... Args, typename A>
|
||||||
|
class sink<signal_handler<Ret(Args...), A>> {
|
||||||
|
using signal_t = signal_handler<Ret(Args...), A>;
|
||||||
|
|
||||||
|
public:
|
||||||
|
sink(signal_t &sh)
|
||||||
|
: signal{&sh}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
signal_t *signal;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename Ret, typename... Args, typename A>
|
||||||
|
class signal_handler<Ret(Args...), A> {
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename Ret, typename... Args, typename A>
|
||||||
|
sink(signal_handler<Ret(Args...), A> &)
|
||||||
|
-> sink<signal_handler<Ret(Args...), A>>;
|
||||||
|
|
||||||
|
signal_handler<void(int), bool> int_handler;
|
||||||
|
|
||||||
|
sink sink1{int_handler};
|
||||||
|
|
||||||
|
} // namespace clanguml::t00044
|
||||||
43
tests/t00044/test_case.h
Normal file
43
tests/t00044/test_case.h
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
/**
|
||||||
|
* tests/t00044/test_case.cc
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021-2022 Bartek Kryza <bkryza@gmail.com>
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
TEST_CASE("t00044", "[test-case][class]")
|
||||||
|
{
|
||||||
|
auto [config, db] = load_config("t00044");
|
||||||
|
|
||||||
|
auto diagram = config.diagrams["t00044_class"];
|
||||||
|
|
||||||
|
REQUIRE(diagram->name == "t00044_class");
|
||||||
|
REQUIRE(diagram->generate_packages() == true);
|
||||||
|
|
||||||
|
auto model = generate_class_diagram(db, diagram);
|
||||||
|
|
||||||
|
REQUIRE(model->name() == "t00044_class");
|
||||||
|
|
||||||
|
auto puml = generate_class_puml(diagram, *model);
|
||||||
|
AliasMatcher _A(puml);
|
||||||
|
|
||||||
|
REQUIRE_THAT(puml, StartsWith("@startuml"));
|
||||||
|
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
|
||||||
|
|
||||||
|
// Check dependants filter<void(int), bool>
|
||||||
|
REQUIRE_THAT(puml, IsClassTemplate("signal_handler", "Ret,Args...,A"));
|
||||||
|
|
||||||
|
save_puml(
|
||||||
|
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
|
||||||
|
}
|
||||||
@@ -225,6 +225,7 @@ using namespace clanguml::test::matchers;
|
|||||||
#include "t00041/test_case.h"
|
#include "t00041/test_case.h"
|
||||||
#include "t00042/test_case.h"
|
#include "t00042/test_case.h"
|
||||||
#include "t00043/test_case.h"
|
#include "t00043/test_case.h"
|
||||||
|
#include "t00044/test_case.h"
|
||||||
|
|
||||||
//
|
//
|
||||||
// Sequence diagram tests
|
// Sequence diagram tests
|
||||||
|
|||||||
Reference in New Issue
Block a user