Skip to content

Commit 1432ae5

Browse files
weratJDevlieghere
authored andcommitted
[lldb] Add SBType::GetEnumerationIntegerType method
Add a method for getting the enumeration underlying type. Differential revision: https://reviews.llvm.org/D93696
1 parent e17a00f commit 1432ae5

File tree

10 files changed

+53
-0
lines changed

10 files changed

+53
-0
lines changed

lldb/bindings/interface/SBType.i

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ public:
244244
lldb::SBType
245245
GetCanonicalType();
246246

247+
lldb::SBType
248+
GetEnumerationIntegerType();
249+
247250
lldb::SBType
248251
GetArrayElementType ();
249252

lldb/include/lldb/API/SBType.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ class SBType {
152152
lldb::SBType GetVectorElementType();
153153

154154
lldb::SBType GetCanonicalType();
155+
156+
lldb::SBType GetEnumerationIntegerType();
157+
155158
// Get the "lldb::BasicType" enumeration for a type. If a type is not a basic
156159
// type eBasicTypeInvalid will be returned
157160
lldb::BasicType GetBasicType();

lldb/include/lldb/Symbol/CompilerType.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ class CompilerType {
187187

188188
CompilerType GetFullyUnqualifiedType() const;
189189

190+
CompilerType GetEnumerationIntegerType() const;
191+
190192
/// Returns -1 if this isn't a function of if the function doesn't
191193
/// have a prototype Returns a value >= 0 if there is a prototype.
192194
int GetFunctionArgumentCount() const;

lldb/include/lldb/Symbol/TypeSystem.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ class TypeSystem : public PluginInterface {
227227

228228
virtual CompilerType GetCanonicalType(lldb::opaque_compiler_type_t type) = 0;
229229

230+
virtual CompilerType
231+
GetEnumerationIntegerType(lldb::opaque_compiler_type_t type) = 0;
232+
230233
// Returns -1 if this isn't a function of if the function doesn't have a
231234
// prototype Returns a value >= 0 if there is a prototype.
232235
virtual int GetFunctionArgumentCount(lldb::opaque_compiler_type_t type) = 0;

lldb/source/API/SBType.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,16 @@ lldb::SBType SBType::GetCanonicalType() {
344344
return LLDB_RECORD_RESULT(SBType());
345345
}
346346

347+
SBType SBType::GetEnumerationIntegerType() {
348+
LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetEnumerationIntegerType);
349+
350+
if (IsValid()) {
351+
return LLDB_RECORD_RESULT(
352+
SBType(m_opaque_sp->GetCompilerType(true).GetEnumerationIntegerType()));
353+
}
354+
return LLDB_RECORD_RESULT(SBType());
355+
}
356+
347357
lldb::BasicType SBType::GetBasicType() {
348358
LLDB_RECORD_METHOD_NO_ARGS(lldb::BasicType, SBType, GetBasicType);
349359

@@ -952,6 +962,7 @@ void RegisterMethods<SBType>(Registry &R) {
952962
GetMemberFunctionAtIndex, (uint32_t));
953963
LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetUnqualifiedType, ());
954964
LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetCanonicalType, ());
965+
LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetEnumerationIntegerType, ());
955966
LLDB_REGISTER_METHOD(lldb::BasicType, SBType, GetBasicType, ());
956967
LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetBasicType, (lldb::BasicType));
957968
LLDB_REGISTER_METHOD(uint32_t, SBType, GetNumberOfDirectBaseClasses, ());

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4195,6 +4195,13 @@ TypeSystemClang::GetFullyUnqualifiedType(lldb::opaque_compiler_type_t type) {
41954195
return CompilerType();
41964196
}
41974197

4198+
CompilerType
4199+
TypeSystemClang::GetEnumerationIntegerType(lldb::opaque_compiler_type_t type) {
4200+
if (type)
4201+
return GetEnumerationIntegerType(GetType(GetCanonicalQualType(type)));
4202+
return CompilerType();
4203+
}
4204+
41984205
int TypeSystemClang::GetFunctionArgumentCount(
41994206
lldb::opaque_compiler_type_t type) {
42004207
if (type) {

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,9 @@ class TypeSystemClang : public TypeSystem {
678678
CompilerType
679679
GetFullyUnqualifiedType(lldb::opaque_compiler_type_t type) override;
680680

681+
CompilerType
682+
GetEnumerationIntegerType(lldb::opaque_compiler_type_t type) override;
683+
681684
// Returns -1 if this isn't a function of if the function doesn't have a
682685
// prototype Returns a value >= 0 if there is a prototype.
683686
int GetFunctionArgumentCount(lldb::opaque_compiler_type_t type) override;

lldb/source/Symbol/CompilerType.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,12 @@ CompilerType CompilerType::GetFullyUnqualifiedType() const {
350350
return CompilerType();
351351
}
352352

353+
CompilerType CompilerType::GetEnumerationIntegerType() const {
354+
if (IsValid())
355+
return m_type_system->GetEnumerationIntegerType(m_type);
356+
return CompilerType();
357+
}
358+
353359
int CompilerType::GetFunctionArgumentCount() const {
354360
if (IsValid()) {
355361
return m_type_system->GetFunctionArgumentCount(m_type);

lldb/test/API/python_api/type/TestTypeList.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,20 @@ def test(self):
150150
self.assertTrue(enum_type)
151151
self.DebugSBType(enum_type)
152152
self.assertFalse(enum_type.IsScopedEnumerationType())
153+
153154
scoped_enum_type = target.FindFirstType('ScopedEnumType')
154155
self.assertTrue(scoped_enum_type)
155156
self.DebugSBType(scoped_enum_type)
156157
self.assertTrue(scoped_enum_type.IsScopedEnumerationType())
158+
int_scoped_enum_type = scoped_enum_type.GetEnumerationIntegerType()
159+
self.assertTrue(int_scoped_enum_type)
160+
self.DebugSBType(int_scoped_enum_type)
161+
self.assertEquals(int_scoped_enum_type.GetName(), 'int')
162+
163+
enum_uchar = target.FindFirstType('EnumUChar')
164+
self.assertTrue(enum_uchar)
165+
self.DebugSBType(enum_uchar)
166+
int_enum_uchar = enum_uchar.GetEnumerationIntegerType()
167+
self.assertTrue(int_enum_uchar)
168+
self.DebugSBType(int_enum_uchar)
169+
self.assertEquals(int_enum_uchar.GetName(), 'unsigned char')

lldb/test/API/python_api/type/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class Task {
3131

3232
enum EnumType {};
3333
enum class ScopedEnumType {};
34+
enum class EnumUChar : unsigned char {};
3435

3536
int main (int argc, char const *argv[])
3637
{
@@ -63,6 +64,7 @@ int main (int argc, char const *argv[])
6364

6465
EnumType enum_type;
6566
ScopedEnumType scoped_enum_type;
67+
EnumUChar scoped_enum_type_uchar;
6668

6769
return 0; // Break at this line
6870
}

0 commit comments

Comments
 (0)