From ae5f2b200681dcb7bf4d048fc273dd525a35c7cc Mon Sep 17 00:00:00 2001 From: Bartek Kryza Date: Sat, 24 Jul 2021 18:46:02 +0200 Subject: [PATCH] Added scope symbol in front of relationships --- src/puml/class_diagram_generator.h | 2 +- src/uml/class_diagram_model.h | 3 ++- src/uml/class_diagram_visitor.cc | 12 +++++++++-- src/uml/class_diagram_visitor.h | 3 ++- tests/t00002/test_case.h | 2 +- tests/t00005/test_case.h | 22 ++++++++++---------- tests/t00006/test_case.h | 32 +++++++++++++++--------------- tests/t00007/test_case.h | 6 +++--- tests/t00009/test_case.h | 7 ++++--- tests/t00010/test_case.h | 4 ++-- tests/t00013/test_case.h | 3 ++- tests/t00014/t00014.cc | 4 ++++ tests/t00014/test_case.h | 8 ++++---- 13 files changed, 62 insertions(+), 46 deletions(-) diff --git a/src/puml/class_diagram_generator.h b/src/puml/class_diagram_generator.h index 1ed6a9e8..5dc3cd28 100644 --- a/src/puml/class_diagram_generator.h +++ b/src/puml/class_diagram_generator.h @@ -258,7 +258,7 @@ public: << m_model.to_alias(uns, ns_relative(uns, destination)); if (!r.label.empty()) - relstr << " : " << r.label; + relstr << " : " << to_string(r.scope) << r.label; relstr << std::endl; ostr << relstr.str(); diff --git a/src/uml/class_diagram_model.h b/src/uml/class_diagram_model.h index 674c5449..096ba0f2 100644 --- a/src/uml/class_diagram_model.h +++ b/src/uml/class_diagram_model.h @@ -36,7 +36,7 @@ namespace clanguml { namespace model { namespace class_diagram { -enum class scope_t { kPublic, kProtected, kPrivate }; +enum class scope_t { kPublic, kProtected, kPrivate, kNone }; enum class relationship_t { kNone, @@ -121,6 +121,7 @@ struct class_relationship { std::string cardinality_source; std::string cardinality_destination; std::string label; + scope_t scope{scope_t::kNone}; friend bool operator==( const class_relationship &l, const class_relationship &r) diff --git a/src/uml/class_diagram_visitor.cc b/src/uml/class_diagram_visitor.cc index 8b26f103..873c9253 100644 --- a/src/uml/class_diagram_visitor.cc +++ b/src/uml/class_diagram_visitor.cc @@ -171,6 +171,7 @@ void tu_visitor::operator()(const cppast::cpp_entity &file) r.destination = tinst.base_template_usr; r.type = relationship_t::kInstantiation; r.label = ""; + r.scope = scope_t::kNone; tinst.add_relationship(std::move(r)); LOG_DBG("Created template instantiation: {}, {}, {}", @@ -206,6 +207,7 @@ void tu_visitor::process_enum_declaration(const cppast::cpp_enum &enm) containment.type = relationship_t::kContainment; containment.destination = cx::util::full_name(ctx.namespace_, cur.value()); + containment.scope = scope_t::kNone; e.relationships.emplace_back(std::move(containment)); LOG_DBG("Added relationship {} +-- {}", e.name, @@ -398,6 +400,7 @@ void tu_visitor::process_class_declaration(const cppast::cpp_class &cls, r.type = relationship_t::kInstantiation; r.label = ""; r.destination = base_template_usr; + r.scope = scope_t::kNone; c.add_relationship(std::move(r)); } else { @@ -484,7 +487,7 @@ void tu_visitor::process_class_declaration(const cppast::cpp_class &cls, void tu_visitor::process_field_with_template_instantiation( const cppast::cpp_member_variable &mv, const cppast::cpp_type &tr, - class_ &c) + class_ &c, cppast::cpp_access_specifier_kind as) { LOG_DBG("Processing field with template instatiation type {}", cppast::to_string(tr)); @@ -527,6 +530,7 @@ void tu_visitor::process_field_with_template_instantiation( } r.type = relationship_t::kInstantiation; r.label = ""; + r.scope = scope_t::kNone; tinst.add_relationship(std::move(r)); class_relationship rr; @@ -537,9 +541,12 @@ void tu_visitor::process_field_with_template_instantiation( else rr.type = relationship_t::kAggregation; rr.label = mv.name(); + rr.scope = detail::cpp_access_specifier_to_scope(as); + LOG_DBG("Adding field instantiation relationship {} {} {} : {}", rr.destination, model::class_diagram::to_string(rr.type), c.usr, rr.label); + c.add_relationship(std::move(rr)); LOG_DBG("Created template instantiation: {}, {}", tinst.name, @@ -572,7 +579,7 @@ void tu_visitor::process_field(const cppast::cpp_member_variable &mv, class_ &c, cppast::to_string(tr), mv.name()); } else if (tr.kind() == cppast::cpp_type_kind::template_instantiation_t) { - process_field_with_template_instantiation(mv, resolve_alias(tr), c); + process_field_with_template_instantiation(mv, resolve_alias(tr), c, as); } else if (tr.kind() == cppast::cpp_type_kind::unexposed_t) { LOG_DBG( @@ -592,6 +599,7 @@ void tu_visitor::process_field(const cppast::cpp_member_variable &mv, class_ &c, r.destination = type; r.type = relationship_type; r.label = m.name; + r.scope = m.scope; LOG_DBG("Adding field relationship {} {} {} : {}", r.destination, model::class_diagram::to_string(r.type), diff --git a/src/uml/class_diagram_visitor.h b/src/uml/class_diagram_visitor.h index c826d0c4..0234f723 100644 --- a/src/uml/class_diagram_visitor.h +++ b/src/uml/class_diagram_visitor.h @@ -165,7 +165,8 @@ public: void process_field_with_template_instantiation( const cppast::cpp_member_variable &mv, const cppast::cpp_type &tr, - clanguml::model::class_diagram::class_ &c); + clanguml::model::class_diagram::class_ &c, + cppast::cpp_access_specifier_kind as); void process_static_field(const cppast::cpp_variable &mv, clanguml::model::class_diagram::class_ &c, diff --git a/tests/t00002/test_case.h b/tests/t00002/test_case.h index b2c637f5..d6beaf68 100644 --- a/tests/t00002/test_case.h +++ b/tests/t00002/test_case.h @@ -53,7 +53,7 @@ TEST_CASE("t00002", "[test-case][class]") REQUIRE_THAT(puml, (IsMethod("foo_a"))); REQUIRE_THAT(puml, (IsMethod("foo_c"))); - REQUIRE_THAT(puml, IsAssociation(_A("D"), _A("A"), "as")); + REQUIRE_THAT(puml, IsAssociation(_A("D"), _A("A"), "-as")); save_puml( "./" + config.output_directory + "/" + diagram->name + ".puml", puml); diff --git a/tests/t00005/test_case.h b/tests/t00005/test_case.h index c3706fe8..1a76961e 100644 --- a/tests/t00005/test_case.h +++ b/tests/t00005/test_case.h @@ -61,17 +61,17 @@ TEST_CASE("t00005", "[test-case][class]") REQUIRE_THAT(puml, (IsField("some_int_pointer", "int*"))); REQUIRE_THAT(puml, (IsField("some_int_pointer_pointer", "int**"))); - REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("A"), "a")); - REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("B"), "b")); - REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("C"), "c")); - REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("D"), "d")); - REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("E"), "e")); - REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("F"), "f")); - REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("G"), "g")); - REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("H"), "h")); - REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("I"), "i")); - REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("J"), "j")); - REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("K"), "k")); + REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("A"), "+a")); + REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("B"), "+b")); + REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("C"), "+c")); + REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("D"), "+d")); + REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("E"), "+e")); + REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("F"), "+f")); + REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("G"), "+g")); + REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("H"), "+h")); + REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("I"), "+i")); + REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("J"), "+j")); + REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("K"), "+k")); save_puml( "./" + config.output_directory + "/" + diagram->name + ".puml", puml); diff --git a/tests/t00006/test_case.h b/tests/t00006/test_case.h index 75e35d4b..94b7ab71 100644 --- a/tests/t00006/test_case.h +++ b/tests/t00006/test_case.h @@ -65,22 +65,22 @@ TEST_CASE("t00006", "[test-case][class]") REQUIRE_THAT(puml, IsInstantiation(_A("custom_container"), _A("custom_container"))); - REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("A"), "a")); - REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("B"), "b")); - REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("C"), "c")); - REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("D"), "d")); - REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("custom_container"), "e")); - REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("F"), "f")); - REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("G"), "g")); - REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("H"), "h")); - REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("I"), "i")); - REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("J"), "j")); - REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("K"), "k")); - REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("L"), "lm")); - REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("M"), "lm")); - REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("N"), "ns")); - REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("NN"), "ns")); - REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("NNN"), "ns")); + REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("A"), "+a")); + REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("B"), "+b")); + REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("C"), "+c")); + REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("D"), "+d")); + REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("custom_container"), "+e")); + REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("F"), "+f")); + REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("G"), "+g")); + REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("H"), "+h")); + REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("I"), "+i")); + REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("J"), "+j")); + REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("K"), "+k")); + REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("L"), "+lm")); + REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("M"), "+lm")); + REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("N"), "+ns")); + REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("NN"), "+ns")); + REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("NNN"), "+ns")); save_puml( "./" + config.output_directory + "/" + diagram->name + ".puml", puml); diff --git a/tests/t00007/test_case.h b/tests/t00007/test_case.h index 948afe32..ce51e6e7 100644 --- a/tests/t00007/test_case.h +++ b/tests/t00007/test_case.h @@ -50,9 +50,9 @@ TEST_CASE("t00007", "[test-case][class]") REQUIRE_THAT(puml, IsClass(_A("C"))); REQUIRE_THAT(puml, IsClass(_A("R"))); - REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("A"), "a")); - REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("B"), "b")); - REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("C"), "c")); + REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("A"), "+a")); + REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("B"), "+b")); + REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("C"), "+c")); save_puml( "./" + config.output_directory + "/" + diagram->name + ".puml", puml); diff --git a/tests/t00009/test_case.h b/tests/t00009/test_case.h index 1cd8d33e..6fc48835 100644 --- a/tests/t00009/test_case.h +++ b/tests/t00009/test_case.h @@ -54,10 +54,11 @@ TEST_CASE("t00009", "[test-case][class]") REQUIRE_THAT(puml, IsInstantiation(_A("A"), _A("A"))); REQUIRE_THAT(puml, IsInstantiation(_A("A"), _A("A"))); - REQUIRE_THAT(puml, IsAggregation(_A("B"), _A("A"), "aint")); - REQUIRE_THAT(puml, IsAssociation(_A("B"), _A("A"), "astring")); + REQUIRE_THAT(puml, IsAggregation(_A("B"), _A("A"), "+aint")); + REQUIRE_THAT( + puml, IsAssociation(_A("B"), _A("A"), "+astring")); REQUIRE_THAT(puml, - IsAssociation(_A("B"), _A("A>"), "avector")); + IsAssociation(_A("B"), _A("A>"), "+avector")); save_puml( "./" + config.output_directory + "/" + diagram->name + ".puml", puml); diff --git a/tests/t00010/test_case.h b/tests/t00010/test_case.h index ad68f487..13472978 100644 --- a/tests/t00010/test_case.h +++ b/tests/t00010/test_case.h @@ -52,8 +52,8 @@ TEST_CASE("t00010", "[test-case][class]") REQUIRE_THAT(puml, IsInstantiation(_A("B"), _A("B"))); REQUIRE_THAT( - puml, IsAggregation(_A("B"), _A("A"), "astring")); - REQUIRE_THAT(puml, IsAggregation(_A("C"), _A("B"), "aintstring")); + puml, IsAggregation(_A("B"), _A("A"), "+astring")); + REQUIRE_THAT(puml, IsAggregation(_A("C"), _A("B"), "+aintstring")); save_puml( "./" + config.output_directory + "/" + diagram->name + ".puml", puml); diff --git a/tests/t00013/test_case.h b/tests/t00013/test_case.h index 00e1acd3..4bdf9772 100644 --- a/tests/t00013/test_case.h +++ b/tests/t00013/test_case.h @@ -56,7 +56,8 @@ TEST_CASE("t00013", "[test-case][class]") REQUIRE_THAT(puml, IsDependency(_A("R"), _A("E"))); REQUIRE_THAT(puml, IsInstantiation(_A("E"), _A("E"))); REQUIRE_THAT(puml, IsInstantiation(_A("E"), _A("E"))); - REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("E"), "estring")); + REQUIRE_THAT( + puml, IsAggregation(_A("R"), _A("E"), "-estring")); REQUIRE_THAT(puml, IsDependency(_A("R"), _A("ABCD::F"))); REQUIRE_THAT(puml, IsInstantiation(_A("ABCD::F"), _A("ABCD::F"))); REQUIRE_THAT(puml, IsDependency(_A("R"), _A("ABCD::F"))); diff --git a/tests/t00014/t00014.cc b/tests/t00014/t00014.cc index 1f84ed26..a1e3824a 100644 --- a/tests/t00014/t00014.cc +++ b/tests/t00014/t00014.cc @@ -48,7 +48,11 @@ class R { AString floatstring; AIntString intstring; AStringString stringstring; + +protected: BVector bs; + +public: BVector2 bs2; GeneralCallback cb; VoidCallback vcb; diff --git a/tests/t00014/test_case.h b/tests/t00014/test_case.h index 1bf5ceef..17a646dd 100644 --- a/tests/t00014/test_case.h +++ b/tests/t00014/test_case.h @@ -49,11 +49,11 @@ TEST_CASE("t00014", "[test-case][class]") REQUIRE_THAT( puml, IsInstantiation(_A("A"), _A("AString"))); REQUIRE_THAT( - puml, IsAggregation(_A("R"), _A("A"), "boolstring")); + puml, IsAggregation(_A("R"), _A("A"), "-boolstring")); REQUIRE_THAT( - puml, IsAggregation(_A("R"), _A("AString"), "floatstring")); - REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("B"), "bs")); - REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("B"), "bs2")); + puml, IsAggregation(_A("R"), _A("AString"), "-floatstring")); + REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("B"), "#bs")); + REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("B"), "+bs2")); save_puml( "./" + config.output_directory + "/" + diagram->name + ".puml", puml);