Skip to content

Hoist SwiftASTContext::IsScalarType into TypeSystemSwift (NFC) #1483

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 3 commits into from
Jul 17, 2020
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
26 changes: 0 additions & 26 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5101,11 +5101,6 @@ bool SwiftASTContext::IsFunctionPointerType(opaque_compiler_type_t type) {
return IsFunctionType(type, nullptr); // FIXME: think about this
}

bool SwiftASTContext::IsIntegerType(opaque_compiler_type_t type,
bool &is_signed) {
return (GetTypeInfo(type, nullptr) & eTypeIsInteger);
}

bool SwiftASTContext::IsPointerType(opaque_compiler_type_t type,
CompilerType *pointee_type) {
VALID_OR_RETURN(false);
Expand Down Expand Up @@ -5156,20 +5151,6 @@ bool SwiftASTContext::IsReferenceType(opaque_compiler_type_t type,
return false;
}

bool SwiftASTContext::IsFloatingPointType(opaque_compiler_type_t type,
uint32_t &count, bool &is_complex) {
if (type) {
if (GetTypeInfo(type, nullptr) & eTypeIsFloat) {
count = 1;
is_complex = false;
return true;
}
}
count = 0;
is_complex = false;
return false;
}

bool SwiftASTContext::IsDefined(opaque_compiler_type_t type) {
if (!type)
return false;
Expand Down Expand Up @@ -5214,13 +5195,6 @@ bool SwiftASTContext::IsPossibleDynamicType(opaque_compiler_type_t type,
return false;
}

bool SwiftASTContext::IsScalarType(opaque_compiler_type_t type) {
if (!type)
return false;

return (GetTypeInfo(type, nullptr) & eTypeIsScalar) != 0;
}

bool SwiftASTContext::IsTypedefType(opaque_compiler_type_t type) {
if (!type)
return false;
Expand Down
8 changes: 0 additions & 8 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,6 @@ class SwiftASTContext : public TypeSystemSwift {

bool IsDefined(lldb::opaque_compiler_type_t type) override;

bool IsFloatingPointType(lldb::opaque_compiler_type_t type, uint32_t &count,
bool &is_complex) override;

bool IsFunctionType(lldb::opaque_compiler_type_t type,
bool *is_variadic_ptr) override;

Expand All @@ -469,18 +466,13 @@ class SwiftASTContext : public TypeSystemSwift {

bool IsFunctionPointerType(lldb::opaque_compiler_type_t type) override;

bool IsIntegerType(lldb::opaque_compiler_type_t type,
bool &is_signed) override;

bool IsPossibleDynamicType(lldb::opaque_compiler_type_t type,
CompilerType *target_type, // Can pass NULL
bool check_cplusplus, bool check_objc) override;

bool IsPointerType(lldb::opaque_compiler_type_t type,
CompilerType *pointee_type) override;

bool IsScalarType(lldb::opaque_compiler_type_t type) override;

bool IsVoidType(lldb::opaque_compiler_type_t type) override;

static bool IsGenericType(const CompilerType &compiler_type);
Expand Down
27 changes: 27 additions & 0 deletions lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,30 @@
//===----------------------------------------------------------------------===//

#include "Plugins/TypeSystem/Swift/TypeSystemSwift.h"
#include <lldb/lldb-enumerations.h>

using namespace lldb;
using namespace lldb_private;

bool TypeSystemSwift::IsFloatingPointType(opaque_compiler_type_t type,
uint32_t &count, bool &is_complex) {
count = 0;
is_complex = false;
if (GetTypeInfo(type, nullptr) & eTypeIsFloat) {
count = 1;
return true;
}
return false;
}

bool TypeSystemSwift::IsIntegerType(opaque_compiler_type_t type,
bool &is_signed) {
return (GetTypeInfo(type, nullptr) & eTypeIsInteger);
}

bool TypeSystemSwift::IsScalarType(opaque_compiler_type_t type) {
if (!type)
return false;

return (GetTypeInfo(type, nullptr) & eTypeIsScalar) != 0;
}
5 changes: 5 additions & 0 deletions lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwift.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ class TypeSystemSwift : public TypeSystem {
return true;
}
bool IsConst(lldb::opaque_compiler_type_t type) override { return false; }
bool IsFloatingPointType(lldb::opaque_compiler_type_t type, uint32_t &count,
bool &is_complex) override;
bool IsIntegerType(lldb::opaque_compiler_type_t type,
bool &is_signed) override;
bool IsScalarType(lldb::opaque_compiler_type_t type) override;
bool IsCStringType(lldb::opaque_compiler_type_t type,
uint32_t &length) override {
return false;
Expand Down
13 changes: 0 additions & 13 deletions lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1254,12 +1254,6 @@ bool TypeSystemSwiftTypeRef::IsDefined(opaque_compiler_type_t type) {
auto impl = [&]() -> bool { return type; };
VALIDATE_AND_RETURN(impl, IsDefined, type, (ReconstructType(type)));
}
bool TypeSystemSwiftTypeRef::IsFloatingPointType(opaque_compiler_type_t type,
uint32_t &count,
bool &is_complex) {
return m_swift_ast_context->IsFloatingPointType(ReconstructType(type), count,
is_complex);
}

bool TypeSystemSwiftTypeRef::IsFunctionType(opaque_compiler_type_t type,
bool *is_variadic_ptr) {
Expand Down Expand Up @@ -1349,10 +1343,6 @@ bool TypeSystemSwiftTypeRef::IsFunctionPointerType(
VALIDATE_AND_RETURN(impl, IsFunctionPointerType, type,
(ReconstructType(type)));
}
bool TypeSystemSwiftTypeRef::IsIntegerType(opaque_compiler_type_t type,
bool &is_signed) {
return m_swift_ast_context->IsIntegerType(ReconstructType(type), is_signed);
}
bool TypeSystemSwiftTypeRef::IsPossibleDynamicType(opaque_compiler_type_t type,
CompilerType *target_type,
bool check_cplusplus,
Expand All @@ -1377,9 +1367,6 @@ bool TypeSystemSwiftTypeRef::IsPointerType(opaque_compiler_type_t type,
VALIDATE_AND_RETURN(impl, IsPointerType, type,
(ReconstructType(type), pointee_type));
}
bool TypeSystemSwiftTypeRef::IsScalarType(opaque_compiler_type_t type) {
return m_swift_ast_context->IsScalarType(ReconstructType(type));
}
bool TypeSystemSwiftTypeRef::IsVoidType(opaque_compiler_type_t type) {
auto impl = [&]() {
using namespace swift::Demangle;
Expand Down
5 changes: 0 additions & 5 deletions lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,18 @@ class TypeSystemSwiftTypeRef : public TypeSystemSwift {
bool *is_incomplete) override;
bool IsAggregateType(lldb::opaque_compiler_type_t type) override;
bool IsDefined(lldb::opaque_compiler_type_t type) override;
bool IsFloatingPointType(lldb::opaque_compiler_type_t type, uint32_t &count,
bool &is_complex) override;
bool IsFunctionType(lldb::opaque_compiler_type_t type,
bool *is_variadic_ptr) override;
size_t
GetNumberOfFunctionArguments(lldb::opaque_compiler_type_t type) override;
CompilerType GetFunctionArgumentAtIndex(lldb::opaque_compiler_type_t type,
const size_t index) override;
bool IsFunctionPointerType(lldb::opaque_compiler_type_t type) override;
bool IsIntegerType(lldb::opaque_compiler_type_t type,
bool &is_signed) override;
bool IsPossibleDynamicType(lldb::opaque_compiler_type_t type,
CompilerType *target_type, // Can pass NULL
bool check_cplusplus, bool check_objc) override;
bool IsPointerType(lldb::opaque_compiler_type_t type,
CompilerType *pointee_type) override;
bool IsScalarType(lldb::opaque_compiler_type_t type) override;
bool IsVoidType(lldb::opaque_compiler_type_t type) override;
// Type Completion
bool GetCompleteType(lldb::opaque_compiler_type_t type) override;
Expand Down
38 changes: 38 additions & 0 deletions lldb/unittests/Symbol/TestTypeSystemSwiftTypeRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ class NodeBuilder {
Node(Node::Kind::Module, swift::STDLIB_NAME),
Node(Node::Kind::Identifier, swift::BUILTIN_TYPE_NAME_INT)));
}
NodePointer FloatType() {
return Node(
Node::Kind::Type,
Node(Node::Kind::Structure,
Node(Node::Kind::Module, swift::STDLIB_NAME),
Node(Node::Kind::Identifier, swift::BUILTIN_TYPE_NAME_FLOAT)));
}
NodePointer GlobalTypeMangling(NodePointer type) {
assert(type && type->getKind() == Node::Kind::Type);
return Node(Node::Kind::Global, Node(Node::Kind::TypeMangling, type));
Expand Down Expand Up @@ -257,6 +264,7 @@ TEST_F(TestTypeSystemSwiftTypeRef, Aggregate) {
NodePointer n = b.GlobalType(b.Node(Node::Kind::Tuple));
CompilerType tuple = GetCompilerType(b.Mangle(n));
ASSERT_TRUE(tuple.IsAggregateType());
ASSERT_FALSE(tuple.IsScalarType());
// Yes, Int is a struct.
NodePointer int_node = b.GlobalTypeMangling(b.IntType());
CompilerType int_type = GetCompilerType(b.Mangle(int_node));
Expand All @@ -281,3 +289,33 @@ TEST_F(TestTypeSystemSwiftTypeRef, Defined) {
ASSERT_FALSE(m_swift_ts.IsDefined(nullptr));
}
}

TEST_F(TestTypeSystemSwiftTypeRef, Scalar) {
using namespace swift::Demangle;
Demangler dem;
NodeBuilder b(dem);
{
NodePointer int_node = b.GlobalTypeMangling(b.IntType());
CompilerType int_type = GetCompilerType(b.Mangle(int_node));
uint32_t count = 99;
bool is_complex = true;
ASSERT_FALSE(int_type.IsFloatingPointType(count, is_complex));
ASSERT_EQ(count, 0);
ASSERT_EQ(is_complex, false);
bool is_signed = true;
ASSERT_TRUE(int_type.IsIntegerType(is_signed));
ASSERT_TRUE(int_type.IsScalarType());
}
{
NodePointer float_node = b.GlobalTypeMangling(b.FloatType());
CompilerType float_type = GetCompilerType(b.Mangle(float_node));
uint32_t count = 99;
bool is_complex = true;
ASSERT_TRUE(float_type.IsFloatingPointType(count, is_complex));
ASSERT_EQ(count, 1);
ASSERT_EQ(is_complex, false);
bool is_signed = true;
ASSERT_FALSE(float_type.IsIntegerType(is_signed));
ASSERT_TRUE(float_type.IsScalarType());
}
}