Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Deal with friends from multiple classes
  • Loading branch information
LarryOsterman committed Apr 9, 2024
commit c46e7be6540148e239ba91b5d0f093b2ad355dfc
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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add function comment

clang::FriendDecl const* friendDecl,
std::string const& parentNodeNavigationId)
{
std::string navigationId = parentNodeNavigationId + "_friend_";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the parentNodeNavigationId be ""? Can we assert these premises.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It cannot be empty, I'll add an error message if it is.

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you end up in the final else of the initial if/else then you could end up with navigationId being <parentNodeId>_friend_. Is a navigationId ending in "_" a valid format?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All strings are valid, the only restriction is that the names must be unique.

}

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