Skip to content

Commit bd51db5

Browse files
committed
[lldb] Implement GetFormat in terms of GetTypeInfo
(cherry picked from commit a5c2622)
1 parent e67eec6 commit bd51db5

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
@@ -6338,96 +6338,6 @@ lldb::Encoding SwiftASTContext::GetEncoding(opaque_compiler_type_t type,
63386338
return lldb::eEncodingInvalid;
63396339
}
63406340

6341-
lldb::Format SwiftASTContext::GetFormat(opaque_compiler_type_t type) {
6342-
VALID_OR_RETURN_CHECK_TYPE(type, lldb::eFormatInvalid);
6343-
6344-
swift::CanType swift_can_type(GetCanonicalSwiftType(type));
6345-
6346-
const swift::TypeKind type_kind = swift_can_type->getKind();
6347-
switch (type_kind) {
6348-
case swift::TypeKind::BuiltinDefaultActorStorage:
6349-
case swift::TypeKind::BuiltinExecutor:
6350-
case swift::TypeKind::BuiltinJob:
6351-
case swift::TypeKind::BuiltinRawUnsafeContinuation:
6352-
case swift::TypeKind::Error:
6353-
case swift::TypeKind::Module:
6354-
case swift::TypeKind::InOut:
6355-
case swift::TypeKind::VariadicSequence:
6356-
case swift::TypeKind::Placeholder:
6357-
case swift::TypeKind::SILBlockStorage:
6358-
case swift::TypeKind::SILBox:
6359-
case swift::TypeKind::SILFunction:
6360-
case swift::TypeKind::SILToken:
6361-
case swift::TypeKind::TypeVariable:
6362-
case swift::TypeKind::Unresolved:
6363-
break;
6364-
case swift::TypeKind::BuiltinIntegerLiteral:
6365-
case swift::TypeKind::BuiltinInteger:
6366-
return eFormatDecimal; // TODO: detect if an integer is unsigned
6367-
case swift::TypeKind::BuiltinFloat:
6368-
return eFormatFloat; // TODO: detect if an integer is unsigned
6369-
6370-
case swift::TypeKind::BuiltinRawPointer:
6371-
case swift::TypeKind::BuiltinNativeObject:
6372-
case swift::TypeKind::BuiltinUnsafeValueBuffer:
6373-
case swift::TypeKind::BuiltinBridgeObject:
6374-
case swift::TypeKind::PrimaryArchetype:
6375-
case swift::TypeKind::OpenedArchetype:
6376-
case swift::TypeKind::OpaqueTypeArchetype:
6377-
case swift::TypeKind::NestedArchetype:
6378-
case swift::TypeKind::GenericTypeParam:
6379-
case swift::TypeKind::DependentMember:
6380-
return eFormatAddressInfo;
6381-
6382-
// Classes are always pointers in swift.
6383-
case swift::TypeKind::Class:
6384-
case swift::TypeKind::BoundGenericClass:
6385-
return eFormatHex;
6386-
6387-
case swift::TypeKind::BuiltinVector:
6388-
break;
6389-
case swift::TypeKind::Tuple:
6390-
break;
6391-
case swift::TypeKind::UnmanagedStorage:
6392-
case swift::TypeKind::UnownedStorage:
6393-
case swift::TypeKind::WeakStorage:
6394-
return ToCompilerType(swift_can_type->getReferenceStorageReferent())
6395-
.GetFormat();
6396-
break;
6397-
6398-
case swift::TypeKind::Enum:
6399-
case swift::TypeKind::BoundGenericEnum:
6400-
return eFormatUnsigned;
6401-
6402-
case swift::TypeKind::GenericFunction:
6403-
case swift::TypeKind::Function:
6404-
return lldb::eFormatAddressInfo;
6405-
6406-
case swift::TypeKind::Struct:
6407-
case swift::TypeKind::Protocol:
6408-
case swift::TypeKind::Metatype:
6409-
case swift::TypeKind::ProtocolComposition:
6410-
break;
6411-
case swift::TypeKind::LValue:
6412-
return lldb::eFormatHex;
6413-
case swift::TypeKind::UnboundGeneric:
6414-
case swift::TypeKind::BoundGenericStruct:
6415-
case swift::TypeKind::ExistentialMetatype:
6416-
case swift::TypeKind::DynamicSelf:
6417-
break;
6418-
6419-
case swift::TypeKind::Optional:
6420-
case swift::TypeKind::TypeAlias:
6421-
case swift::TypeKind::Paren:
6422-
case swift::TypeKind::Dictionary:
6423-
case swift::TypeKind::ArraySlice:
6424-
assert(false && "Not a canonical type");
6425-
break;
6426-
}
6427-
// We don't know hot to display this type.
6428-
return lldb::eFormatBytes;
6429-
}
6430-
64316341
uint32_t SwiftASTContext::GetNumChildren(opaque_compiler_type_t type,
64326342
bool omit_empty_base_classes,
64336343
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
@@ -614,8 +614,6 @@ class SwiftASTContext : public TypeSystemSwift {
614614
lldb::Encoding GetEncoding(lldb::opaque_compiler_type_t type,
615615
uint64_t &count) override;
616616

617-
lldb::Format GetFormat(lldb::opaque_compiler_type_t type) override;
618-
619617
uint32_t GetNumChildren(lldb::opaque_compiler_type_t type,
620618
bool omit_empty_base_classes,
621619
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
@@ -120,3 +120,27 @@ uint32_t TypeSystemSwift::GetIndexOfChildWithName(
120120
type, name, exe_ctx, omit_empty_base_classes, child_indexes);
121121
return num_child_indexes == 1 ? child_indexes.front() : UINT32_MAX;
122122
}
123+
124+
lldb::Format TypeSystemSwift::GetFormat(opaque_compiler_type_t type) {
125+
auto swift_flags = GetTypeInfo(type, nullptr);
126+
127+
if (swift_flags & eTypeIsInteger)
128+
return eFormatDecimal;
129+
130+
if (swift_flags & eTypeIsFloat)
131+
return eFormatFloat;
132+
133+
if (swift_flags & eTypeIsPointer || swift_flags & eTypeIsClass)
134+
return eFormatAddressInfo;
135+
136+
if (swift_flags & eTypeIsClass)
137+
return eFormatHex;
138+
139+
if (swift_flags & eTypeIsGeneric)
140+
return eFormatUnsigned;
141+
142+
if (swift_flags & eTypeIsFuncPrototype || swift_flags & eTypeIsBlock)
143+
return eFormatAddressInfo;
144+
145+
return eFormatBytes;
146+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ class TypeSystemSwift : public TypeSystem {
169169

170170
/// \see lldb_private::TypeSystem::Dump
171171
void Dump(llvm::raw_ostream &output) override;
172+
173+
lldb::Format GetFormat(lldb::opaque_compiler_type_t type) override;
172174

173175
/// Unavailable hardcoded functions that don't make sense for Swift.
174176
/// \{

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2509,13 +2509,6 @@ lldb::Encoding TypeSystemSwiftTypeRef::GetEncoding(opaque_compiler_type_t type,
25092509
(ReconstructType(type), count));
25102510
}
25112511

2512-
lldb::Format TypeSystemSwiftTypeRef::GetFormat(opaque_compiler_type_t type) {
2513-
LLDB_SCOPED_TIMER();
2514-
if (auto *swift_ast_context = GetSwiftASTContext())
2515-
return swift_ast_context->GetFormat(ReconstructType(type));
2516-
return {};
2517-
}
2518-
25192512
uint32_t
25202513
TypeSystemSwiftTypeRef::GetNumChildren(opaque_compiler_type_t type,
25212514
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
@@ -163,7 +163,6 @@ class TypeSystemSwiftTypeRef : public TypeSystemSwift {
163163
ExecutionContextScope *exe_scope) override;
164164
lldb::Encoding GetEncoding(lldb::opaque_compiler_type_t type,
165165
uint64_t &count) override;
166-
lldb::Format GetFormat(lldb::opaque_compiler_type_t type) override;
167166
uint32_t GetNumChildren(lldb::opaque_compiler_type_t type,
168167
bool omit_empty_base_classes,
169168
const ExecutionContext *exe_ctx) override;

0 commit comments

Comments
 (0)