Added friend relationship to class templates

This commit is contained in:
Bartek Kryza
2021-03-11 22:11:11 +01:00
parent bf64b75bdd
commit 0ee5eeb619
3 changed files with 16 additions and 5 deletions

View File

@@ -209,21 +209,24 @@ static enum CXChildVisitResult friend_class_visitor(
cx::cursor cursor{std::move(cx_cursor)};
cx::cursor parent{std::move(cx_parent)};
spdlog::info("Visiting friend class declaration{}: {} - {}:{}",
ctx->element.name, cursor.spelling(), cursor.kind());
spdlog::info("Visiting friend class declaration {}: {} - {}:{}",
ctx->element.name, cursor.spelling(), cursor.kind(),
cursor.referenced());
enum CXChildVisitResult ret = CXChildVisit_Break;
switch (cursor.kind()) {
case CXCursor_TemplateRef:
case CXCursor_ClassTemplate:
case CXCursor_TypeRef: {
spdlog::info("Analyzing friend declaration: {}, {}", cursor,
cursor.specialized_cursor_template());
if (!ctx->ctx->config.should_include(
cursor.referenced().fully_qualified())) {
ret = CXChildVisit_Continue;
break;
}
spdlog::info("Adding friend declaration: {}, {}", cursor,
cursor.referenced());
class_relationship r;
r.type = relationship_t::kFriendship;
r.label = "<<friend>>";

View File

@@ -8,11 +8,17 @@ namespace t00011 {
class B;
template <typename T> class D {
T value;
};
class A {
private:
void foo() {}
friend class B;
friend class external::C;
template <typename T> friend class D;
// TODO: Add friend for a template specialization
};
class B {

View File

@@ -46,8 +46,10 @@ TEST_CASE("Test t00011", "[unit-test]")
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
REQUIRE_THAT(puml, IsClass(_A("A")));
REQUIRE_THAT(puml, IsClass(_A("B")));
REQUIRE_THAT(puml, IsClass(_A("D<T>")));
REQUIRE_THAT(puml, IsFriend(_A("A"), _A("B")));
REQUIRE_THAT(puml, IsFriend(_A("A"), _A("D<T>")));
save_puml(
"./" + config.output_directory + "/" + diagram->name + ".puml", puml);