Skip to content

Commit 10f02cb

Browse files
committed
Hoist SwiftASTContext::IsScalarType into TypeSystemSwift (NFC)
and add a unit test for it. (cherry picked from commit a58f88f)
1 parent 24c8c66 commit 10f02cb

File tree

7 files changed

+12
-14
lines changed

7 files changed

+12
-14
lines changed

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5155,13 +5155,6 @@ bool SwiftASTContext::IsPossibleDynamicType(opaque_compiler_type_t type,
51555155
return false;
51565156
}
51575157

5158-
bool SwiftASTContext::IsScalarType(opaque_compiler_type_t type) {
5159-
if (!type)
5160-
return false;
5161-
5162-
return (GetTypeInfo(type, nullptr) & eTypeIsScalar) != 0;
5163-
}
5164-
51655158
bool SwiftASTContext::IsTypedefType(opaque_compiler_type_t type) {
51665159
if (!type)
51675160
return false;

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,6 @@ class SwiftASTContext : public TypeSystemSwift {
467467
bool IsPointerType(lldb::opaque_compiler_type_t type,
468468
CompilerType *pointee_type) override;
469469

470-
bool IsScalarType(lldb::opaque_compiler_type_t type) override;
471-
472470
bool IsVoidType(lldb::opaque_compiler_type_t type) override;
473471

474472
static bool IsGenericType(const CompilerType &compiler_type);

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,10 @@ bool TypeSystemSwift::IsIntegerType(opaque_compiler_type_t type,
8181
bool &is_signed) {
8282
return (GetTypeInfo(type, nullptr) & eTypeIsInteger);
8383
}
84+
85+
bool TypeSystemSwift::IsScalarType(opaque_compiler_type_t type) {
86+
if (!type)
87+
return false;
88+
89+
return (GetTypeInfo(type, nullptr) & eTypeIsScalar) != 0;
90+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ class TypeSystemSwift : public TypeSystem {
145145
bool &is_complex) override;
146146
bool IsIntegerType(lldb::opaque_compiler_type_t type,
147147
bool &is_signed) override;
148+
bool IsScalarType(lldb::opaque_compiler_type_t type) override;
148149
bool IsCStringType(lldb::opaque_compiler_type_t type,
149150
uint32_t &length) override {
150151
return false;

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,9 +1365,6 @@ bool TypeSystemSwiftTypeRef::IsPointerType(opaque_compiler_type_t type,
13651365
VALIDATE_AND_RETURN(impl, IsPointerType, type,
13661366
(ReconstructType(type), pointee_type));
13671367
}
1368-
bool TypeSystemSwiftTypeRef::IsScalarType(opaque_compiler_type_t type) {
1369-
return m_swift_ast_context->IsScalarType(ReconstructType(type));
1370-
}
13711368
bool TypeSystemSwiftTypeRef::IsVoidType(opaque_compiler_type_t type) {
13721369
auto impl = [&]() {
13731370
using namespace swift::Demangle;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ class TypeSystemSwiftTypeRef : public TypeSystemSwift {
100100
bool check_cplusplus, bool check_objc) override;
101101
bool IsPointerType(lldb::opaque_compiler_type_t type,
102102
CompilerType *pointee_type) override;
103-
bool IsScalarType(lldb::opaque_compiler_type_t type) override;
104103
bool IsVoidType(lldb::opaque_compiler_type_t type) override;
105104
// Type Completion
106105
bool GetCompleteType(lldb::opaque_compiler_type_t type) override;

lldb/unittests/Symbol/TestTypeSystemSwiftTypeRef.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ TEST_F(TestTypeSystemSwiftTypeRef, Aggregate) {
264264
NodePointer n = b.GlobalType(b.Node(Node::Kind::Tuple));
265265
CompilerType tuple = GetCompilerType(b.Mangle(n));
266266
ASSERT_TRUE(tuple.IsAggregateType());
267+
ASSERT_FALSE(tuple.IsScalarType());
267268
// Yes, Int is a struct.
268269
NodePointer int_node = b.GlobalTypeMangling(b.IntType());
269270
CompilerType int_type = GetCompilerType(b.Mangle(int_node));
@@ -289,7 +290,7 @@ TEST_F(TestTypeSystemSwiftTypeRef, Defined) {
289290
}
290291
}
291292

292-
TEST_F(TestTypeSystemSwiftTypeRef, IntFloat) {
293+
TEST_F(TestTypeSystemSwiftTypeRef, Scalar) {
293294
using namespace swift::Demangle;
294295
Demangler dem;
295296
NodeBuilder b(dem);
@@ -303,6 +304,7 @@ TEST_F(TestTypeSystemSwiftTypeRef, IntFloat) {
303304
ASSERT_EQ(is_complex, false);
304305
bool is_signed = true;
305306
ASSERT_TRUE(int_type.IsIntegerType(is_signed));
307+
ASSERT_TRUE(int_type.IsScalarType());
306308
}
307309
{
308310
NodePointer float_node = b.GlobalTypeMangling(b.FloatType());
@@ -314,5 +316,6 @@ TEST_F(TestTypeSystemSwiftTypeRef, IntFloat) {
314316
ASSERT_EQ(is_complex, false);
315317
bool is_signed = true;
316318
ASSERT_FALSE(float_type.IsIntegerType(is_signed));
319+
ASSERT_TRUE(float_type.IsScalarType());
317320
}
318321
}

0 commit comments

Comments
 (0)