Skip to content

[lldb] Implement GetFormat in terms of GetTypeInfo #3604

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 1 commit into from
Dec 2, 2021
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
90 changes: 0 additions & 90 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6361,96 +6361,6 @@ lldb::Encoding SwiftASTContext::GetEncoding(opaque_compiler_type_t type,
return lldb::eEncodingInvalid;
}

lldb::Format SwiftASTContext::GetFormat(opaque_compiler_type_t type) {
VALID_OR_RETURN_CHECK_TYPE(type, lldb::eFormatInvalid);

swift::CanType swift_can_type(GetCanonicalSwiftType(type));

const swift::TypeKind type_kind = swift_can_type->getKind();
switch (type_kind) {
case swift::TypeKind::BuiltinDefaultActorStorage:
case swift::TypeKind::BuiltinExecutor:
case swift::TypeKind::BuiltinJob:
case swift::TypeKind::BuiltinRawUnsafeContinuation:
case swift::TypeKind::Error:
case swift::TypeKind::Module:
case swift::TypeKind::InOut:
case swift::TypeKind::VariadicSequence:
case swift::TypeKind::Placeholder:
case swift::TypeKind::SILBlockStorage:
case swift::TypeKind::SILBox:
case swift::TypeKind::SILFunction:
case swift::TypeKind::SILToken:
case swift::TypeKind::TypeVariable:
case swift::TypeKind::Unresolved:
break;
case swift::TypeKind::BuiltinIntegerLiteral:
case swift::TypeKind::BuiltinInteger:
return eFormatDecimal; // TODO: detect if an integer is unsigned
case swift::TypeKind::BuiltinFloat:
return eFormatFloat; // TODO: detect if an integer is unsigned

case swift::TypeKind::BuiltinRawPointer:
case swift::TypeKind::BuiltinNativeObject:
case swift::TypeKind::BuiltinUnsafeValueBuffer:
case swift::TypeKind::BuiltinBridgeObject:
case swift::TypeKind::PrimaryArchetype:
case swift::TypeKind::OpenedArchetype:
case swift::TypeKind::OpaqueTypeArchetype:
case swift::TypeKind::NestedArchetype:
case swift::TypeKind::GenericTypeParam:
case swift::TypeKind::DependentMember:
return eFormatAddressInfo;

// Classes are always pointers in swift.
case swift::TypeKind::Class:
case swift::TypeKind::BoundGenericClass:
return eFormatHex;

case swift::TypeKind::BuiltinVector:
break;
case swift::TypeKind::Tuple:
break;
case swift::TypeKind::UnmanagedStorage:
case swift::TypeKind::UnownedStorage:
case swift::TypeKind::WeakStorage:
return ToCompilerType(swift_can_type->getReferenceStorageReferent())
.GetFormat();
break;

case swift::TypeKind::Enum:
case swift::TypeKind::BoundGenericEnum:
return eFormatUnsigned;

case swift::TypeKind::GenericFunction:
case swift::TypeKind::Function:
return lldb::eFormatAddressInfo;

case swift::TypeKind::Struct:
case swift::TypeKind::Protocol:
case swift::TypeKind::Metatype:
case swift::TypeKind::ProtocolComposition:
break;
case swift::TypeKind::LValue:
return lldb::eFormatHex;
case swift::TypeKind::UnboundGeneric:
case swift::TypeKind::BoundGenericStruct:
case swift::TypeKind::ExistentialMetatype:
case swift::TypeKind::DynamicSelf:
break;

case swift::TypeKind::Optional:
case swift::TypeKind::TypeAlias:
case swift::TypeKind::Paren:
case swift::TypeKind::Dictionary:
case swift::TypeKind::ArraySlice:
assert(false && "Not a canonical type");
break;
}
// We don't know hot to display this type.
return lldb::eFormatBytes;
}

uint32_t SwiftASTContext::GetNumChildren(opaque_compiler_type_t type,
bool omit_empty_base_classes,
const ExecutionContext *exe_ctx) {
Expand Down
2 changes: 0 additions & 2 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,6 @@ class SwiftASTContext : public TypeSystemSwift {
lldb::Encoding GetEncoding(lldb::opaque_compiler_type_t type,
uint64_t &count) override;

lldb::Format GetFormat(lldb::opaque_compiler_type_t type) override;

uint32_t GetNumChildren(lldb::opaque_compiler_type_t type,
bool omit_empty_base_classes,
const ExecutionContext *exe_ctx) override;
Expand Down
24 changes: 24 additions & 0 deletions lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,27 @@ uint32_t TypeSystemSwift::GetIndexOfChildWithName(
type, name, exe_ctx, omit_empty_base_classes, child_indexes);
return num_child_indexes == 1 ? child_indexes.front() : UINT32_MAX;
}

lldb::Format TypeSystemSwift::GetFormat(opaque_compiler_type_t type) {
auto swift_flags = GetTypeInfo(type, nullptr);

if (swift_flags & eTypeIsInteger)
return eFormatDecimal;

if (swift_flags & eTypeIsFloat)
return eFormatFloat;

if (swift_flags & eTypeIsPointer || swift_flags & eTypeIsClass)
return eFormatAddressInfo;

if (swift_flags & eTypeIsClass)
return eFormatHex;

if (swift_flags & eTypeIsGeneric)
return eFormatUnsigned;

if (swift_flags & eTypeIsFuncPrototype || swift_flags & eTypeIsBlock)
return eFormatAddressInfo;

return eFormatBytes;
}
2 changes: 2 additions & 0 deletions lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwift.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ class TypeSystemSwift : public TypeSystem {
bool show_types, bool show_summary, bool verbose,
uint32_t depth) override;

lldb::Format GetFormat(lldb::opaque_compiler_type_t type) override;

/// Unavailable hardcoded functions that don't make sense for Swift.
/// \{
ConstString DeclContextGetName(void *opaque_decl_ctx) override { return {}; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2512,13 +2512,6 @@ lldb::Encoding TypeSystemSwiftTypeRef::GetEncoding(opaque_compiler_type_t type,
(ReconstructType(type), count));
}

lldb::Format TypeSystemSwiftTypeRef::GetFormat(opaque_compiler_type_t type) {
LLDB_SCOPED_TIMER();
if (auto *swift_ast_context = GetSwiftASTContext())
return swift_ast_context->GetFormat(ReconstructType(type));
return {};
}

uint32_t
TypeSystemSwiftTypeRef::GetNumChildren(opaque_compiler_type_t type,
bool omit_empty_base_classes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ class TypeSystemSwiftTypeRef : public TypeSystemSwift {
ExecutionContextScope *exe_scope) override;
lldb::Encoding GetEncoding(lldb::opaque_compiler_type_t type,
uint64_t &count) override;
lldb::Format GetFormat(lldb::opaque_compiler_type_t type) override;
uint32_t GetNumChildren(lldb::opaque_compiler_type_t type,
bool omit_empty_base_classes,
const ExecutionContext *exe_ctx) override;
Expand Down