Fixed friend class root namespace handling

This commit is contained in:
Bartek Kryza
2022-06-22 23:11:31 +02:00
parent 934a8edbbf
commit 96534f8e42
3 changed files with 32 additions and 2 deletions

View File

@@ -1384,7 +1384,7 @@ void translation_unit_visitor::process_friend(const cppast::cpp_friend &f,
r.set_destination(name); r.set_destination(name);
} }
else if (f.entity()) { else if (f.entity()) {
std::string name; std::string name = f.entity().value().name();
if (f.entity().value().kind() == if (f.entity().value().kind() ==
cppast::cpp_entity_kind::class_template_t) { cppast::cpp_entity_kind::class_template_t) {
@@ -1411,7 +1411,17 @@ void translation_unit_visitor::process_friend(const cppast::cpp_friend &f,
cppast::is_templated(f.entity().value()), cppast::is_templated(f.entity().value()),
cppast::to_string(f.entity().value().kind())); cppast::to_string(f.entity().value().kind()));
name = cx::util::full_name(ctx.get_namespace(), f.entity().value()); const auto &maybe_definition =
cppast::get_definition(ctx.entity_index(), f.entity().value());
if (maybe_definition.has_value()) {
const auto &friend_class = maybe_definition.value();
auto entity_ns =
common::model::namespace_{cx::util::ns(friend_class)};
name = cx::util::full_name(entity_ns, f.entity().value());
}
} }
if (!ctx.diagram().should_include(ctx.get_namespace(), name)) if (!ctx.diagram().should_include(ctx.get_namespace(), name))

View File

@@ -4,6 +4,13 @@ class A {
class AA { class AA {
}; };
class AAA {
};
template <typename T> class AAAA {
T t;
};
namespace ns1 { namespace ns1 {
class A { class A {
@@ -26,6 +33,9 @@ class D : public ns1::ns2::A {
class E : public ::A { class E : public ::A {
}; };
class AAA {
};
class R { class R {
public: public:
A *a; A *a;
@@ -33,6 +43,10 @@ public:
ns1::ns2::A *ns1_ns2_a; ns1::ns2::A *ns1_ns2_a;
::A *root_a; ::A *root_a;
friend ::AAA;
// TODO:
// template<typename T> friend class ::AAAA;
void foo(::AA &aa) { (void)aa; } void foo(::AA &aa) { (void)aa; }
}; };
} }

View File

@@ -58,6 +58,12 @@ TEST_CASE("t00045", "[test-case][class]")
REQUIRE_THAT(puml, IsDependency(_A("ns1::ns2::R"), _A("AA"))); REQUIRE_THAT(puml, IsDependency(_A("ns1::ns2::R"), _A("AA")));
REQUIRE_THAT(puml, IsFriend<Public>(_A("ns1::ns2::R"), _A("AAA")));
REQUIRE_THAT(
puml, !IsFriend<Public>(_A("ns1::ns2::R"), _A("ns1::ns2::AAA")));
// TODO:
// REQUIRE_THAT(puml, IsFriend<Public>(_A("ns1::ns2::R"), _A("AAAA<T>")));
save_puml( save_puml(
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml); "./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
} }