Skip to content

Commit afc4bd0

Browse files
authored
Merge pull request #2238 from apple/lldb-Implement-TypeSystemSwiftTypeRef-IsPossibleDynamicType-next
[lldb] Implement TypeSystemSwiftTypeRef::IsPossibleDynamicType
2 parents abb4977 + aa0f1aa commit afc4bd0

File tree

1 file changed

+53
-2
lines changed

1 file changed

+53
-2
lines changed

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

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,13 +1762,64 @@ bool TypeSystemSwiftTypeRef::IsFunctionPointerType(
17621762
VALIDATE_AND_RETURN(impl, IsFunctionPointerType, type,
17631763
(ReconstructType(type)));
17641764
}
1765+
17651766
bool TypeSystemSwiftTypeRef::IsPossibleDynamicType(opaque_compiler_type_t type,
17661767
CompilerType *target_type,
17671768
bool check_cplusplus,
17681769
bool check_objc) {
1769-
return m_swift_ast_context->IsPossibleDynamicType(
1770-
ReconstructType(type), target_type, check_cplusplus, check_objc);
1770+
if (target_type)
1771+
target_type->Clear();
1772+
1773+
if (!type)
1774+
return false;
1775+
1776+
// This is a discrepancy with `SwiftASTContext`. The `impl` below correctly
1777+
// returns true, but `VALIDATE_AND_RETURN` will assert. This hardcoded
1778+
// handling of `__C.NSNotificationName` can be removed when the
1779+
// `VALIDATE_AND_RETURN` is removed.
1780+
if (GetMangledTypeName(type) == "$sSo18NSNotificationNameaD")
1781+
return true;
1782+
1783+
auto impl = [&]() {
1784+
using namespace swift::Demangle;
1785+
Demangler dem;
1786+
auto *node = DemangleCanonicalType(dem, type);
1787+
if (!node)
1788+
return false;
1789+
1790+
if (node->getKind() == Node::Kind::TypeAlias) {
1791+
auto resolved = ResolveTypeAlias(m_swift_ast_context, dem, node);
1792+
if (auto *n = std::get<swift::Demangle::NodePointer>(resolved))
1793+
node = n;
1794+
}
1795+
1796+
switch (node->getKind()) {
1797+
case Node::Kind::Class:
1798+
case Node::Kind::BoundGenericClass:
1799+
case Node::Kind::Protocol:
1800+
case Node::Kind::ProtocolList:
1801+
case Node::Kind::ProtocolListWithClass:
1802+
case Node::Kind::ProtocolListWithAnyObject:
1803+
case Node::Kind::ExistentialMetatype:
1804+
case Node::Kind::DynamicSelf:
1805+
return true;
1806+
case Node::Kind::BuiltinTypeName: {
1807+
if (!node->hasText())
1808+
return false;
1809+
StringRef name = node->getText();
1810+
return name == swift::BUILTIN_TYPE_NAME_RAWPOINTER ||
1811+
name == swift::BUILTIN_TYPE_NAME_NATIVEOBJECT ||
1812+
name == swift::BUILTIN_TYPE_NAME_BRIDGEOBJECT;
1813+
}
1814+
default:
1815+
return ContainsGenericTypeParameter(node);
1816+
}
1817+
};
1818+
VALIDATE_AND_RETURN(
1819+
impl, IsPossibleDynamicType, type,
1820+
(ReconstructType(type), nullptr, check_cplusplus, check_objc));
17711821
}
1822+
17721823
bool TypeSystemSwiftTypeRef::IsPointerType(opaque_compiler_type_t type,
17731824
CompilerType *pointee_type) {
17741825
auto impl = [&]() {

0 commit comments

Comments
 (0)