Skip to content

Commit e17a00f

Browse files
weratJDevlieghere
authored andcommitted
[lldb] Add SBType::IsScopedEnumerationType method
Add a method to check if the type is a scoped enumeration (i.e. "enum class/struct"). Differential revision: https://reviews.llvm.org/D93690
1 parent f507148 commit e17a00f

File tree

10 files changed

+55
-0
lines changed

10 files changed

+55
-0
lines changed

lldb/bindings/interface/SBType.i

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ public:
220220
bool
221221
IsAnonymousType ();
222222

223+
bool
224+
IsScopedEnumerationType ();
225+
223226
lldb::SBType
224227
GetPointerType();
225228

lldb/include/lldb/API/SBType.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ class SBType {
131131

132132
bool IsAnonymousType();
133133

134+
bool IsScopedEnumerationType();
135+
134136
lldb::SBType GetPointerType();
135137

136138
lldb::SBType GetPointeeType();

lldb/include/lldb/Symbol/CompilerType.h

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

8383
bool IsAnonymousType() const;
8484

85+
bool IsScopedEnumerationType() const;
86+
8587
bool IsBeingDefined() const;
8688

8789
bool IsCharType() const;

lldb/include/lldb/Symbol/TypeSystem.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ class TypeSystem : public PluginInterface {
175175
return false;
176176
}
177177

178+
virtual bool IsScopedEnumerationType(lldb::opaque_compiler_type_t type) = 0;
179+
178180
virtual bool IsPossibleDynamicType(lldb::opaque_compiler_type_t type,
179181
CompilerType *target_type, // Can pass NULL
180182
bool check_cplusplus, bool check_objc) = 0;

lldb/source/API/SBType.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,14 @@ bool SBType::IsAnonymousType() {
271271
return m_opaque_sp->GetCompilerType(true).IsAnonymousType();
272272
}
273273

274+
bool SBType::IsScopedEnumerationType() {
275+
LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsScopedEnumerationType);
276+
277+
if (!IsValid())
278+
return false;
279+
return m_opaque_sp->GetCompilerType(true).IsScopedEnumerationType();
280+
}
281+
274282
lldb::SBType SBType::GetFunctionReturnType() {
275283
LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetFunctionReturnType);
276284

@@ -935,6 +943,7 @@ void RegisterMethods<SBType>(Registry &R) {
935943
LLDB_REGISTER_METHOD(bool, SBType, IsPolymorphicClass, ());
936944
LLDB_REGISTER_METHOD(bool, SBType, IsTypedefType, ());
937945
LLDB_REGISTER_METHOD(bool, SBType, IsAnonymousType, ());
946+
LLDB_REGISTER_METHOD(bool, SBType, IsScopedEnumerationType, ());
938947
LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetFunctionReturnType, ());
939948
LLDB_REGISTER_METHOD(lldb::SBTypeList, SBType, GetFunctionArgumentTypes,
940949
());

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3147,6 +3147,20 @@ bool TypeSystemClang::IsEnumerationType(lldb::opaque_compiler_type_t type,
31473147
return false;
31483148
}
31493149

3150+
bool TypeSystemClang::IsScopedEnumerationType(
3151+
lldb::opaque_compiler_type_t type) {
3152+
if (type) {
3153+
const clang::EnumType *enum_type = llvm::dyn_cast<clang::EnumType>(
3154+
GetCanonicalQualType(type)->getCanonicalTypeInternal());
3155+
3156+
if (enum_type) {
3157+
return enum_type->isScopedEnumeralType();
3158+
}
3159+
}
3160+
3161+
return false;
3162+
}
3163+
31503164
bool TypeSystemClang::IsPointerType(lldb::opaque_compiler_type_t type,
31513165
CompilerType *pointee_type) {
31523166
if (type) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,8 @@ class TypeSystemClang : public TypeSystem {
600600
bool IsEnumerationType(lldb::opaque_compiler_type_t type,
601601
bool &is_signed) override;
602602

603+
bool IsScopedEnumerationType(lldb::opaque_compiler_type_t type) override;
604+
603605
static bool IsObjCClassType(const CompilerType &type);
604606

605607
static bool IsObjCClassTypeAndHasIVars(const CompilerType &type,

lldb/source/Symbol/CompilerType.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ bool CompilerType::IsAnonymousType() const {
4040
return false;
4141
}
4242

43+
bool CompilerType::IsScopedEnumerationType() const {
44+
if (IsValid())
45+
return m_type_system->IsScopedEnumerationType(m_type);
46+
return false;
47+
}
48+
4349
bool CompilerType::IsArrayType(CompilerType *element_type_ptr, uint64_t *size,
4450
bool *is_incomplete) const {
4551
if (IsValid())

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,13 @@ def test(self):
144144
myint_type = target.FindFirstType('myint')
145145
self.DebugSBType(myint_type)
146146
self.assertTrue(myint_arr_element_type == myint_type)
147+
148+
# Test enum methods.
149+
enum_type = target.FindFirstType('EnumType')
150+
self.assertTrue(enum_type)
151+
self.DebugSBType(enum_type)
152+
self.assertFalse(enum_type.IsScopedEnumerationType())
153+
scoped_enum_type = target.FindFirstType('ScopedEnumType')
154+
self.assertTrue(scoped_enum_type)
155+
self.DebugSBType(scoped_enum_type)
156+
self.assertTrue(scoped_enum_type.IsScopedEnumerationType())

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class Task {
2929
{}
3030
};
3131

32+
enum EnumType {};
33+
enum class ScopedEnumType {};
3234

3335
int main (int argc, char const *argv[])
3436
{
@@ -59,5 +61,8 @@ int main (int argc, char const *argv[])
5961
typedef int myint;
6062
myint myint_arr[] = {1, 2, 3};
6163

64+
EnumType enum_type;
65+
ScopedEnumType scoped_enum_type;
66+
6267
return 0; // Break at this line
6368
}

0 commit comments

Comments
 (0)