Skip to content

Commit 149dcc7

Browse files
committed
Hoist SwiftASTContext::IsFloatingPointType into TypeSystemSwift (NFC)
and add a unit test for it. (cherry picked from commit d9b7bf8) Conflicts: lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwift.cpp
1 parent 92fc3bf commit 149dcc7

File tree

7 files changed

+51
-25
lines changed

7 files changed

+51
-25
lines changed

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5116,20 +5116,6 @@ bool SwiftASTContext::IsReferenceType(opaque_compiler_type_t type,
51165116
return false;
51175117
}
51185118

5119-
bool SwiftASTContext::IsFloatingPointType(opaque_compiler_type_t type,
5120-
uint32_t &count, bool &is_complex) {
5121-
if (type) {
5122-
if (GetTypeInfo(type, nullptr) & eTypeIsFloat) {
5123-
count = 1;
5124-
is_complex = false;
5125-
return true;
5126-
}
5127-
}
5128-
count = 0;
5129-
is_complex = false;
5130-
return false;
5131-
}
5132-
51335119
bool SwiftASTContext::IsDefined(opaque_compiler_type_t type) {
51345120
if (!type)
51355121
return false;

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

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

450450
bool IsDefined(lldb::opaque_compiler_type_t type) override;
451451

452-
bool IsFloatingPointType(lldb::opaque_compiler_type_t type, uint32_t &count,
453-
bool &is_complex) override;
454-
455452
bool IsFunctionType(lldb::opaque_compiler_type_t type,
456453
bool *is_variadic_ptr) override;
457454

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@
1414

1515
#include "lldb/Core/PluginManager.h"
1616
#include "lldb/Target/SwiftLanguageRuntime.h"
17+
#include <lldb/lldb-enumerations.h>
1718

1819
LLDB_PLUGIN_DEFINE(TypeSystemSwift)
1920

21+
using namespace lldb;
2022
using namespace lldb_private;
2123

24+
/// TypeSystem Plugin functionality.
25+
/// \{
2226
static lldb::TypeSystemSP CreateTypeSystemInstance(lldb::LanguageType language,
2327
Module *module,
2428
Target *target,
@@ -58,3 +62,17 @@ ConstString TypeSystemSwift::GetPluginName() {
5862
}
5963

6064
uint32_t TypeSystemSwift::GetPluginVersion() { return 1; }
65+
66+
/// \}
67+
68+
69+
bool TypeSystemSwift::IsFloatingPointType(opaque_compiler_type_t type,
70+
uint32_t &count, bool &is_complex) {
71+
count = 0;
72+
is_complex = false;
73+
if (GetTypeInfo(type, nullptr) & eTypeIsFloat) {
74+
count = 1;
75+
return true;
76+
}
77+
return false;
78+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ class TypeSystemSwift : public TypeSystem {
141141
return true;
142142
}
143143
bool IsConst(lldb::opaque_compiler_type_t type) override { return false; }
144+
bool IsFloatingPointType(lldb::opaque_compiler_type_t type, uint32_t &count,
145+
bool &is_complex) override;
144146
bool IsCStringType(lldb::opaque_compiler_type_t type,
145147
uint32_t &length) override {
146148
return false;

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,12 +1252,6 @@ bool TypeSystemSwiftTypeRef::IsDefined(opaque_compiler_type_t type) {
12521252
};
12531253
VALIDATE_AND_RETURN(impl, IsDefined, type, (ReconstructType(type)));
12541254
}
1255-
bool TypeSystemSwiftTypeRef::IsFloatingPointType(opaque_compiler_type_t type,
1256-
uint32_t &count,
1257-
bool &is_complex) {
1258-
return m_swift_ast_context->IsFloatingPointType(ReconstructType(type), count,
1259-
is_complex);
1260-
}
12611255

12621256
bool TypeSystemSwiftTypeRef::IsFunctionType(opaque_compiler_type_t type,
12631257
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)