Added support for class friend declarations
This commit is contained in:
@@ -126,6 +126,8 @@ public:
|
||||
return to_string(clang_getCursorKindSpelling(m_cursor.kind));
|
||||
}
|
||||
|
||||
cursor definition() const { return clang_getCursorDefinition(m_cursor); }
|
||||
|
||||
bool is_definition() const { return clang_isCursorDefinition(m_cursor); }
|
||||
|
||||
bool is_declaration() const { return clang_isDeclaration(kind()); }
|
||||
|
||||
@@ -90,12 +90,14 @@ public:
|
||||
return "-->";
|
||||
case relationship_t::kInstantiation:
|
||||
return "..|>";
|
||||
case relationship_t::kFriendship:
|
||||
return "<..";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
void generate(const class_ &c, std::ostream &ostr) const
|
||||
void generate_aliases(const class_ &c, std::ostream &ostr) const
|
||||
{
|
||||
std::string class_type{"class"};
|
||||
if (c.is_abstract())
|
||||
@@ -104,6 +106,13 @@ public:
|
||||
ostr << class_type << " \"" << c.full_name(m_config.using_namespace);
|
||||
|
||||
ostr << "\" as " << c.alias() << std::endl;
|
||||
}
|
||||
|
||||
void generate(const class_ &c, std::ostream &ostr) const
|
||||
{
|
||||
std::string class_type{"class"};
|
||||
if (c.is_abstract())
|
||||
class_type = "abstract";
|
||||
|
||||
ostr << class_type << " " << c.alias() << " {" << std::endl;
|
||||
|
||||
@@ -166,7 +175,8 @@ public:
|
||||
destination = m_model.usr_to_name(
|
||||
m_config.using_namespace, r.destination);
|
||||
}
|
||||
else if (r.destination.find("#") != std::string::npos) {
|
||||
else if (r.destination.find("#") != std::string::npos ||
|
||||
r.destination.find("@") != std::string::npos) {
|
||||
destination = m_model.usr_to_name(
|
||||
m_config.using_namespace, r.destination);
|
||||
}
|
||||
@@ -204,6 +214,11 @@ public:
|
||||
{
|
||||
ostr << "@startuml" << std::endl;
|
||||
|
||||
for (const auto &c : m_model.classes) {
|
||||
generate_aliases(c, ostr);
|
||||
ostr << std::endl;
|
||||
}
|
||||
|
||||
for (const auto &c : m_model.classes) {
|
||||
generate(c, ostr);
|
||||
ostr << std::endl;
|
||||
|
||||
@@ -44,7 +44,8 @@ enum class relationship_t {
|
||||
kContainment,
|
||||
kOwnership,
|
||||
kAssociation,
|
||||
kInstantiation
|
||||
kInstantiation,
|
||||
kFriendship
|
||||
};
|
||||
|
||||
class element {
|
||||
|
||||
@@ -201,6 +201,39 @@ static enum CXChildVisitResult enum_visitor(
|
||||
return ret;
|
||||
}
|
||||
|
||||
static enum CXChildVisitResult friend_class_visitor(
|
||||
CXCursor cx_cursor, CXCursor cx_parent, CXClientData client_data)
|
||||
{
|
||||
auto ctx = (element_visitor_context<class_> *)client_data;
|
||||
|
||||
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());
|
||||
|
||||
enum CXChildVisitResult ret = CXChildVisit_Break;
|
||||
switch (cursor.kind()) {
|
||||
case CXCursor_TypeRef: {
|
||||
spdlog::info("Adding friend declaration: {}, {}", cursor,
|
||||
cursor.referenced());
|
||||
class_relationship r;
|
||||
r.type = relationship_t::kFriendship;
|
||||
r.label = "<<friend>>";
|
||||
r.destination = cursor.referenced().usr();
|
||||
|
||||
ctx->element.relationships.emplace_back(std::move(r));
|
||||
|
||||
ret = CXChildVisit_Continue;
|
||||
} break;
|
||||
default:
|
||||
ret = CXChildVisit_Continue;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static enum CXChildVisitResult class_visitor(
|
||||
CXCursor cx_cursor, CXCursor cx_parent, CXClientData client_data)
|
||||
{
|
||||
@@ -534,8 +567,12 @@ static enum CXChildVisitResult class_visitor(
|
||||
ctx->element.bases.emplace_back(std::move(cp));
|
||||
|
||||
ret = CXChildVisit_Continue;
|
||||
break;
|
||||
}
|
||||
} break;
|
||||
case CXCursor_FriendDecl: {
|
||||
clang_visitChildren(cursor.get(), friend_class_visitor, ctx);
|
||||
|
||||
ret = CXChildVisit_Continue;
|
||||
} break;
|
||||
default:
|
||||
ret = CXChildVisit_Continue;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user