@@ -1532,34 +1532,53 @@ NodePointer Demangler::demangleExtensionContext() {
15321532
15331533// / Associate any \c OpaqueReturnType nodes with the declaration whose opaque
15341534// / return type they refer back to.
1535- static Node * setParentForOpaqueReturnTypeNodes (Demangler &D,
1536- Node *parent,
1537- Node *visitedNode) {
1538- if (!parent || ! visitedNode)
1539- return nullptr ;
1540- if (visitedNode-> getKind () == Node::Kind::OpaqueReturnType) {
1535+ // / Implementation for \c setParentForOpaqueReturnTypeNodes. Don't invoke
1536+ // / directly.
1537+ static void setParentForOpaqueReturnTypeNodesImpl (
1538+ Demangler &D, Node & visitedNode,
1539+ llvm::function_ref<StringRef()> getParentID) {
1540+ if (visitedNode. getKind () == Node::Kind::OpaqueReturnType) {
15411541 // If this node is not already parented, parent it.
1542- if (visitedNode-> hasChildren ()
1543- && visitedNode-> getLastChild ()-> getKind () == Node::Kind::OpaqueReturnTypeParent) {
1544- return parent ;
1542+ if (visitedNode. hasChildren () && visitedNode. getLastChild ()-> getKind () ==
1543+ Node::Kind::OpaqueReturnTypeParent) {
1544+ return ;
15451545 }
1546- visitedNode->addChild (D.createNode (Node::Kind::OpaqueReturnTypeParent,
1547- (Node::IndexType)parent), D);
1548- return parent;
1546+ visitedNode.addChild (D.createNode (Node::Kind::OpaqueReturnTypeParent,
1547+ StringRef (getParentID ())),
1548+ D);
1549+ return ;
15491550 }
1550-
1551+
15511552 // If this node is one that may in turn define its own opaque return type,
15521553 // stop recursion, since any opaque return type nodes underneath would refer
15531554 // to the nested declaration rather than the one we're looking at.
1554- if (visitedNode-> getKind () == Node::Kind::Function
1555- || visitedNode-> getKind () == Node::Kind::Variable
1556- || visitedNode-> getKind () == Node::Kind::Subscript) {
1557- return parent ;
1555+ if (visitedNode. getKind () == Node::Kind::Function ||
1556+ visitedNode. getKind () == Node::Kind::Variable ||
1557+ visitedNode. getKind () == Node::Kind::Subscript) {
1558+ return ;
15581559 }
1559-
1560- for (size_t i = 0 , e = visitedNode->getNumChildren (); i < e; ++i) {
1561- setParentForOpaqueReturnTypeNodes (D, parent, visitedNode->getChild (i));
1560+
1561+ for (Node *child : visitedNode) {
1562+ assert (child);
1563+ setParentForOpaqueReturnTypeNodesImpl (D, *child, getParentID);
15621564 }
1565+ }
1566+
1567+ // / Associate any \c OpaqueReturnType nodes with the declaration whose opaque
1568+ // / return type they refer back to.
1569+ static Node *setParentForOpaqueReturnTypeNodes (Demangler &D, Node *parent,
1570+ Node *visitedNode) {
1571+ if (!parent || !visitedNode)
1572+ return nullptr ;
1573+ std::string parentID;
1574+ setParentForOpaqueReturnTypeNodesImpl (D, *visitedNode, [&] {
1575+ if (!parentID.empty ())
1576+ return StringRef (parentID);
1577+ const auto mangleResult = mangleNode (parent);
1578+ assert (mangleResult.isSuccess ());
1579+ parentID = mangleResult.result ();
1580+ return StringRef (parentID);
1581+ });
15631582 return parent;
15641583}
15651584
0 commit comments