Skip to content

Commit d9b7bf8

Browse files
committed
Hoist SwiftASTContext::IsFloatingPointType into TypeSystemSwift (NFC)
and add a unit test for it.
1 parent b5e1ab2 commit d9b7bf8

File tree

7 files changed

+48
-25
lines changed

7 files changed

+48
-25
lines changed

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5156,20 +5156,6 @@ bool SwiftASTContext::IsReferenceType(opaque_compiler_type_t type,
51565156
return false;
51575157
}
51585158

5159-
bool SwiftASTContext::IsFloatingPointType(opaque_compiler_type_t type,
5160-
uint32_t &count, bool &is_complex) {
5161-
if (type) {
5162-
if (GetTypeInfo(type, nullptr) & eTypeIsFloat) {
5163-
count = 1;
5164-
is_complex = false;
5165-
return true;
5166-
}
5167-
}
5168-
count = 0;
5169-
is_complex = false;
5170-
return false;
5171-
}
5172-
51735159
bool SwiftASTContext::IsDefined(opaque_compiler_type_t type) {
51745160
if (!type)
51755161
return false;

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,6 @@ class SwiftASTContext : public TypeSystemSwift {
455455

456456
bool IsDefined(lldb::opaque_compiler_type_t type) override;
457457

458-
bool IsFloatingPointType(lldb::opaque_compiler_type_t type, uint32_t &count,
459-
bool &is_complex) override;
460-
461458
bool IsFunctionType(lldb::opaque_compiler_type_t type,
462459
bool *is_variadic_ptr) override;
463460

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,18 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "Plugins/TypeSystem/Swift/TypeSystemSwift.h"
14+
#include <lldb/lldb-enumerations.h>
15+
16+
using namespace lldb;
17+
using namespace lldb_private;
18+
19+
bool TypeSystemSwift::IsFloatingPointType(opaque_compiler_type_t type,
20+
uint32_t &count, bool &is_complex) {
21+
count = 0;
22+
is_complex = false;
23+
if (GetTypeInfo(type, nullptr) & eTypeIsFloat) {
24+
count = 1;
25+
return true;
26+
}
27+
return false;
28+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ class TypeSystemSwift : public TypeSystem {
132132
return true;
133133
}
134134
bool IsConst(lldb::opaque_compiler_type_t type) override { return false; }
135+
bool IsFloatingPointType(lldb::opaque_compiler_type_t type, uint32_t &count,
136+
bool &is_complex) override;
135137
bool IsCStringType(lldb::opaque_compiler_type_t type,
136138
uint32_t &length) override {
137139
return false;

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,12 +1254,6 @@ bool TypeSystemSwiftTypeRef::IsDefined(opaque_compiler_type_t type) {
12541254
auto impl = [&]() -> bool { return type; };
12551255
VALIDATE_AND_RETURN(impl, IsDefined, type, (ReconstructType(type)));
12561256
}
1257-
bool TypeSystemSwiftTypeRef::IsFloatingPointType(opaque_compiler_type_t type,
1258-
uint32_t &count,
1259-
bool &is_complex) {
1260-
return m_swift_ast_context->IsFloatingPointType(ReconstructType(type), count,
1261-
is_complex);
1262-
}
12631257

12641258
bool TypeSystemSwiftTypeRef::IsFunctionType(opaque_compiler_type_t type,
12651259
bool *is_variadic_ptr) {

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ class TypeSystemSwiftTypeRef : public TypeSystemSwift {
8888
bool *is_incomplete) override;
8989
bool IsAggregateType(lldb::opaque_compiler_type_t type) override;
9090
bool IsDefined(lldb::opaque_compiler_type_t type) override;
91-
bool IsFloatingPointType(lldb::opaque_compiler_type_t type, uint32_t &count,
92-
bool &is_complex) override;
9391
bool IsFunctionType(lldb::opaque_compiler_type_t type,
9492
bool *is_variadic_ptr) override;
9593
size_t

lldb/unittests/Symbol/TestTypeSystemSwiftTypeRef.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ class NodeBuilder {
6969
Node(Node::Kind::Module, swift::STDLIB_NAME),
7070
Node(Node::Kind::Identifier, swift::BUILTIN_TYPE_NAME_INT)));
7171
}
72+
NodePointer FloatType() {
73+
return Node(
74+
Node::Kind::Type,
75+
Node(Node::Kind::Structure,
76+
Node(Node::Kind::Module, swift::STDLIB_NAME),
77+
Node(Node::Kind::Identifier, swift::BUILTIN_TYPE_NAME_FLOAT)));
78+
}
7279
NodePointer GlobalTypeMangling(NodePointer type) {
7380
assert(type && type->getKind() == Node::Kind::Type);
7481
return Node(Node::Kind::Global, Node(Node::Kind::TypeMangling, type));
@@ -281,3 +288,27 @@ TEST_F(TestTypeSystemSwiftTypeRef, Defined) {
281288
ASSERT_FALSE(m_swift_ts.IsDefined(nullptr));
282289
}
283290
}
291+
292+
TEST_F(TestTypeSystemSwiftTypeRef, Float) {
293+
using namespace swift::Demangle;
294+
Demangler dem;
295+
NodeBuilder b(dem);
296+
{
297+
NodePointer int_node = b.GlobalTypeMangling(b.IntType());
298+
CompilerType int_type = GetCompilerType(b.Mangle(int_node));
299+
uint32_t count = 99;
300+
bool is_complex = true;
301+
ASSERT_FALSE(int_type.IsFloatingPointType(count, is_complex));
302+
ASSERT_EQ(count, 0);
303+
ASSERT_EQ(is_complex, false);
304+
}
305+
{
306+
NodePointer float_node = b.GlobalTypeMangling(b.FloatType());
307+
CompilerType float_type = GetCompilerType(b.Mangle(float_node));
308+
uint32_t count = 99;
309+
bool is_complex = true;
310+
ASSERT_TRUE(float_type.IsFloatingPointType(count, is_complex));
311+
ASSERT_EQ(count, 1);
312+
ASSERT_EQ(is_complex, false);
313+
}
314+
}

0 commit comments

Comments
 (0)