Skip to content

[lldb] Reimplement and implement GetPointerType #1908

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
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
9 changes: 5 additions & 4 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5886,10 +5886,11 @@ CompilerType SwiftASTContext::GetPointerType(opaque_compiler_type_t type) {
VALID_OR_RETURN(CompilerType());

if (type) {
swift::Type swift_type(GetSwiftType({this, type}));
const swift::TypeKind type_kind = swift_type->getKind();
if (type_kind == swift::TypeKind::BuiltinRawPointer)
return ToCompilerType({swift_type});
auto swift_type = GetSwiftType({this, type});
auto pointer_type =
swift_type->wrapInPointer(swift::PointerTypeKind::PTK_UnsafePointer);
if (pointer_type)
return ToCompilerType(pointer_type);
}
return {};
}
Expand Down
46 changes: 41 additions & 5 deletions lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ GetClangTypeNode(CompilerType clang_type, swift::Demangle::Demangler &dem) {
}

/// \return the child of the \p Type node.
static swift::Demangle::NodePointer GetType(swift::Demangle::Demangler &dem,
swift::Demangle::NodePointer n) {
static NodePointer GetType(swift::Demangle::NodePointer n) {
Copy link
Author

Choose a reason for hiding this comment

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

I removed the unused Demangler parameter.

using namespace swift::Demangle;
if (!n || n->getKind() != Node::Kind::Global || !n->hasChildren())
return nullptr;
Expand All @@ -109,7 +108,7 @@ static swift::Demangle::NodePointer GetType(swift::Demangle::Demangler &dem,
static swift::Demangle::NodePointer
GetDemangledType(swift::Demangle::Demangler &dem, StringRef name) {
NodePointer n = dem.demangleSymbol(name);
return GetType(dem, n);
return GetType(n);
}

/// Resolve a type alias node and return a demangle tree for the
Expand Down Expand Up @@ -1291,7 +1290,7 @@ swift::Demangle::NodePointer TypeSystemSwiftTypeRef::DemangleCanonicalType(
using namespace swift::Demangle;
NodePointer node =
GetCanonicalDemangleTree(GetModule(), dem, AsMangledName(opaque_type));
return GetType(dem, node);
return GetType(node);
}

bool TypeSystemSwiftTypeRef::IsArrayType(opaque_compiler_type_t type,
Expand Down Expand Up @@ -1669,9 +1668,46 @@ CompilerType
TypeSystemSwiftTypeRef::GetPointeeType(opaque_compiler_type_t type) {
return m_swift_ast_context->GetPointeeType(ReconstructType(type));
}

CompilerType
TypeSystemSwiftTypeRef::GetPointerType(opaque_compiler_type_t type) {
return m_swift_ast_context->GetPointerType(ReconstructType(type));
auto impl = [&]() -> CompilerType {
using namespace swift::Demangle;
Demangler dem;

// The type that will be wrapped in UnsafePointer.
auto *pointee_type = GetDemangledType(dem, AsMangledName(type));
// The UnsafePointer type.
auto *pointer_type = dem.createNode(Node::Kind::Type);

auto *bgs = dem.createNode(Node::Kind::BoundGenericStructure);
pointer_type->addChild(bgs, dem);

// Construct the first branch of BoundGenericStructure.
{
auto *type = dem.createNode(Node::Kind::Type);
bgs->addChild(type, dem);
auto *structure = dem.createNode(Node::Kind::Structure);
type->addChild(structure, dem);
structure->addChild(dem.createNodeWithAllocatedText(Node::Kind::Module,
swift::STDLIB_NAME),
dem);
structure->addChild(
dem.createNode(Node::Kind::Identifier, "UnsafePointer"), dem);
}

// Construct the second branch of BoundGenericStructure.
{
auto *typelist = dem.createNode(Node::Kind::TypeList);
bgs->addChild(typelist, dem);
auto *type = dem.createNode(Node::Kind::Type);
typelist->addChild(type, dem);
type->addChild(pointee_type, dem);
}

return RemangleAsType(dem, pointer_type);
};
VALIDATE_AND_RETURN(impl, GetPointerType, type, (ReconstructType(type)));
}

// Exploring the type
Expand Down