Skip to content

Commit a5c2622

Browse files
committed
[lldb] Implement GetFormat in terms of GetTypeInfo
1 parent 08e5663 commit a5c2622

File tree

6 files changed

+26
-100
lines changed

6 files changed

+26
-100
lines changed

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -6361,96 +6361,6 @@ lldb::Encoding SwiftASTContext::GetEncoding(opaque_compiler_type_t type,
63616361
return lldb::eEncodingInvalid;
63626362
}
63636363

6364-
lldb::Format SwiftASTContext::GetFormat(opaque_compiler_type_t type) {
6365-
VALID_OR_RETURN_CHECK_TYPE(type, lldb::eFormatInvalid);
6366-
6367-
swift::CanType swift_can_type(GetCanonicalSwiftType(type));
6368-
6369-
const swift::TypeKind type_kind = swift_can_type->getKind();
6370-
switch (type_kind) {
6371-
case swift::TypeKind::BuiltinDefaultActorStorage:
6372-
case swift::TypeKind::BuiltinExecutor:
6373-
case swift::TypeKind::BuiltinJob:
6374-
case swift::TypeKind::BuiltinRawUnsafeContinuation:
6375-
case swift::TypeKind::Error:
6376-
case swift::TypeKind::Module:
6377-
case swift::TypeKind::InOut:
6378-
case swift::TypeKind::VariadicSequence:
6379-
case swift::TypeKind::Placeholder:
6380-
case swift::TypeKind::SILBlockStorage:
6381-
case swift::TypeKind::SILBox:
6382-
case swift::TypeKind::SILFunction:
6383-
case swift::TypeKind::SILToken:
6384-
case swift::TypeKind::TypeVariable:
6385-
case swift::TypeKind::Unresolved:
6386-
break;
6387-
case swift::TypeKind::BuiltinIntegerLiteral:
6388-
case swift::TypeKind::BuiltinInteger:
6389-
return eFormatDecimal; // TODO: detect if an integer is unsigned
6390-
case swift::TypeKind::BuiltinFloat:
6391-
return eFormatFloat; // TODO: detect if an integer is unsigned
6392-
6393-
case swift::TypeKind::BuiltinRawPointer:
6394-
case swift::TypeKind::BuiltinNativeObject:
6395-
case swift::TypeKind::BuiltinUnsafeValueBuffer:
6396-
case swift::TypeKind::BuiltinBridgeObject:
6397-
case swift::TypeKind::PrimaryArchetype:
6398-
case swift::TypeKind::OpenedArchetype:
6399-
case swift::TypeKind::OpaqueTypeArchetype:
6400-
case swift::TypeKind::NestedArchetype:
6401-
case swift::TypeKind::GenericTypeParam:
6402-
case swift::TypeKind::DependentMember:
6403-
return eFormatAddressInfo;
6404-
6405-
// Classes are always pointers in swift.
6406-
case swift::TypeKind::Class:
6407-
case swift::TypeKind::BoundGenericClass:
6408-
return eFormatHex;
6409-
6410-
case swift::TypeKind::BuiltinVector:
6411-
break;
6412-
case swift::TypeKind::Tuple:
6413-
break;
6414-
case swift::TypeKind::UnmanagedStorage:
6415-
case swift::TypeKind::UnownedStorage:
6416-
case swift::TypeKind::WeakStorage:
6417-
return ToCompilerType(swift_can_type->getReferenceStorageReferent())
6418-
.GetFormat();
6419-
break;
6420-
6421-
case swift::TypeKind::Enum:
6422-
case swift::TypeKind::BoundGenericEnum:
6423-
return eFormatUnsigned;
6424-
6425-
case swift::TypeKind::GenericFunction:
6426-
case swift::TypeKind::Function:
6427-
return lldb::eFormatAddressInfo;
6428-
6429-
case swift::TypeKind::Struct:
6430-
case swift::TypeKind::Protocol:
6431-
case swift::TypeKind::Metatype:
6432-
case swift::TypeKind::ProtocolComposition:
6433-
break;
6434-
case swift::TypeKind::LValue:
6435-
return lldb::eFormatHex;
6436-
case swift::TypeKind::UnboundGeneric:
6437-
case swift::TypeKind::BoundGenericStruct:
6438-
case swift::TypeKind::ExistentialMetatype:
6439-
case swift::TypeKind::DynamicSelf:
6440-
break;
6441-
6442-
case swift::TypeKind::Optional:
6443-
case swift::TypeKind::TypeAlias:
6444-
case swift::TypeKind::Paren:
6445-
case swift::TypeKind::Dictionary:
6446-
case swift::TypeKind::ArraySlice:
6447-
assert(false && "Not a canonical type");
6448-
break;
6449-
}
6450-
// We don't know hot to display this type.
6451-
return lldb::eFormatBytes;
6452-
}
6453-
64546364
uint32_t SwiftASTContext::GetNumChildren(opaque_compiler_type_t type,
64556365
bool omit_empty_base_classes,
64566366
const ExecutionContext *exe_ctx) {

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,6 @@ class SwiftASTContext : public TypeSystemSwift {
617617
lldb::Encoding GetEncoding(lldb::opaque_compiler_type_t type,
618618
uint64_t &count) override;
619619

620-
lldb::Format GetFormat(lldb::opaque_compiler_type_t type) override;
621-
622620
uint32_t GetNumChildren(lldb::opaque_compiler_type_t type,
623621
bool omit_empty_base_classes,
624622
const ExecutionContext *exe_ctx) override;

lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwift.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,27 @@ uint32_t TypeSystemSwift::GetIndexOfChildWithName(
122122
type, name, exe_ctx, omit_empty_base_classes, child_indexes);
123123
return num_child_indexes == 1 ? child_indexes.front() : UINT32_MAX;
124124
}
125+
126+
lldb::Format TypeSystemSwift::GetFormat(opaque_compiler_type_t type) {
127+
auto swift_flags = GetTypeInfo(type, nullptr);
128+
129+
if (swift_flags & eTypeIsInteger)
130+
return eFormatDecimal;
131+
132+
if (swift_flags & eTypeIsFloat)
133+
return eFormatFloat;
134+
135+
if (swift_flags & eTypeIsPointer || swift_flags & eTypeIsClass)
136+
return eFormatAddressInfo;
137+
138+
if (swift_flags & eTypeIsClass)
139+
return eFormatHex;
140+
141+
if (swift_flags & eTypeIsGeneric)
142+
return eFormatUnsigned;
143+
144+
if (swift_flags & eTypeIsFuncPrototype || swift_flags & eTypeIsBlock)
145+
return eFormatAddressInfo;
146+
147+
return eFormatBytes;
148+
}

lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwift.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ class TypeSystemSwift : public TypeSystem {
168168
bool show_types, bool show_summary, bool verbose,
169169
uint32_t depth) override;
170170

171+
lldb::Format GetFormat(lldb::opaque_compiler_type_t type) override;
172+
171173
/// Unavailable hardcoded functions that don't make sense for Swift.
172174
/// \{
173175
ConstString DeclContextGetName(void *opaque_decl_ctx) override { return {}; }

lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2512,13 +2512,6 @@ lldb::Encoding TypeSystemSwiftTypeRef::GetEncoding(opaque_compiler_type_t type,
25122512
(ReconstructType(type), count));
25132513
}
25142514

2515-
lldb::Format TypeSystemSwiftTypeRef::GetFormat(opaque_compiler_type_t type) {
2516-
LLDB_SCOPED_TIMER();
2517-
if (auto *swift_ast_context = GetSwiftASTContext())
2518-
return swift_ast_context->GetFormat(ReconstructType(type));
2519-
return {};
2520-
}
2521-
25222515
uint32_t
25232516
TypeSystemSwiftTypeRef::GetNumChildren(opaque_compiler_type_t type,
25242517
bool omit_empty_base_classes,

lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ class TypeSystemSwiftTypeRef : public TypeSystemSwift {
164164
ExecutionContextScope *exe_scope) override;
165165
lldb::Encoding GetEncoding(lldb::opaque_compiler_type_t type,
166166
uint64_t &count) override;
167-
lldb::Format GetFormat(lldb::opaque_compiler_type_t type) override;
168167
uint32_t GetNumChildren(lldb::opaque_compiler_type_t type,
169168
bool omit_empty_base_classes,
170169
const ExecutionContext *exe_ctx) override;

0 commit comments

Comments
 (0)