Skip to content

Commit 708f059

Browse files
authored
Merge pull request #69341 from augusto2112/mangle-name-typeref
Add a method that produces a string from a TypeRef
2 parents 363ad2f + e2fa23a commit 708f059

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

include/swift/RemoteInspection/TypeRef.h

+3
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ class alignas(8) TypeRef {
210210
/// Build a demangle tree from this TypeRef.
211211
Demangle::NodePointer getDemangling(Demangle::Demangler &Dem) const;
212212

213+
/// Build the mangled name from this TypeRef.
214+
llvm::Optional<std::string> mangle(Demangle::Demangler &Dem) const;
215+
213216
bool isConcrete() const;
214217
bool isConcreteAfterSubstitutions(const GenericArgumentMap &Subs) const;
215218

stdlib/public/RemoteInspection/TypeRef.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,24 @@ Demangle::NodePointer TypeRef::getDemangling(Demangle::Demangler &Dem) const {
10251025
return DemanglingForTypeRef(Dem).visit(this);
10261026
}
10271027

1028+
llvm::Optional<std::string> TypeRef::mangle(Demangle::Demangler &Dem) const {
1029+
NodePointer node = getDemangling(Dem);
1030+
if (!node)
1031+
return {};
1032+
1033+
// The mangled tree stored in this typeref implicitly assumes the type and
1034+
// global mangling, so add those back in.
1035+
auto typeMangling = Dem.createNode(Node::Kind::TypeMangling);
1036+
typeMangling->addChild(node, Dem);
1037+
auto global = Dem.createNode(Node::Kind::Global);
1038+
global->addChild(node, Dem);
1039+
1040+
auto mangling = mangleNode(global);
1041+
if (!mangling.isSuccess())
1042+
return {};
1043+
return mangling.result();
1044+
}
1045+
10281046
bool TypeRef::isConcrete() const {
10291047
GenericArgumentMap Subs;
10301048
return TypeRefIsConcrete(Subs).visit(this);

0 commit comments

Comments
 (0)