From e99e474e6bbd519fb7cc16dcfc814a97a122e9a3 Mon Sep 17 00:00:00 2001 From: Larry Osterman Date: Mon, 8 Apr 2024 17:34:38 -0700 Subject: [PATCH] Deal with friends from multiple classes (#8037) --- .../ApiViewProcessor/AstNode.cpp | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/tools/apiview/parsers/cpp-api-parser/ApiViewProcessor/AstNode.cpp b/tools/apiview/parsers/cpp-api-parser/ApiViewProcessor/AstNode.cpp index 7f3c90761dc..bef846e88f3 100644 --- a/tools/apiview/parsers/cpp-api-parser/ApiViewProcessor/AstNode.cpp +++ b/tools/apiview/parsers/cpp-api-parser/ApiViewProcessor/AstNode.cpp @@ -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(dc)) + { + auto fd = cast(dc); + navigationId += GetNavigationId(fd); + } + else if (isa(dc)) + { + auto rd = cast(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) { @@ -2690,6 +2729,7 @@ class AstField : public AstNamedNode { class AstFriend : public AstNode { std::string m_friendType; + std::string m_navigationId; std::unique_ptr m_friendFunction; public: @@ -2727,6 +2767,7 @@ class AstFriend : public AstNode { { if (ShouldIncludeFriendDeclaration(friendDecl)) { + m_navigationId = GetNavigationId(friendDecl, parentNode->NavigationId); if (friendDecl->getFriendType()) { m_friendType @@ -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(';');