Skip to content

Commit

Permalink
Deal with friends from multiple classes (#8037)
Browse files Browse the repository at this point in the history
  • Loading branch information
LarryOsterman authored Apr 9, 2024
1 parent 50cffcf commit e99e474
Showing 1 changed file with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,45 @@ static std::string GetNavigationId(clang::FunctionDecl const* func)
return navigationId;
}

static std::string GetNavigationId(
clang::FriendDecl const* friendDecl,
std::string const& parentNodeNavigationId)
{
std::string navigationId = parentNodeNavigationId + "_friend_";
auto dc = friendDecl->getFriendDecl();
if (dc)
{
if (isa<FunctionDecl>(dc))
{
auto fd = cast<FunctionDecl>(dc);
navigationId += GetNavigationId(fd);
}
else if (isa<CXXRecordDecl>(dc))
{
auto rd = cast<CXXRecordDecl>(dc);
navigationId += rd->getQualifiedNameAsString();
}
else
{
dc->dump(llvm::outs());
}
}
else
{
auto friendType = friendDecl->getFriendType();
if (friendType)
{
navigationId
+= QualType::getAsString(friendDecl->getFriendType()->getType().split(), LangOptions{});
}
else
{
friendDecl->dump(llvm::outs());
}
}
return navigationId;
}

static std::string GetNavigationId(clang::ParmVarDecl const* param)
{

Expand Down Expand Up @@ -2690,6 +2729,7 @@ class AstField : public AstNamedNode {

class AstFriend : public AstNode {
std::string m_friendType;
std::string m_navigationId;
std::unique_ptr<AstNode> m_friendFunction;

public:
Expand Down Expand Up @@ -2727,6 +2767,7 @@ class AstFriend : public AstNode {
{
if (ShouldIncludeFriendDeclaration(friendDecl))
{
m_navigationId = GetNavigationId(friendDecl, parentNode->NavigationId);
if (friendDecl->getFriendType())
{
m_friendType
Expand Down Expand Up @@ -2763,7 +2804,7 @@ class AstFriend : public AstNode {
}
else
{
dumper->InsertTypeName(m_friendType, "friend_" + m_friendType);
dumper->InsertTypeName(m_friendType, m_navigationId);
if (dumpOptions.NeedsTrailingSemi)
{
dumper->InsertPunctuation(';');
Expand Down

0 comments on commit e99e474

Please sign in to comment.