[lldb] Add SBType::IsScopedEnumerationType method
authorAndy Yankovsky <weratt@gmail.com>
Tue, 22 Dec 2020 18:06:46 +0000 (10:06 -0800)
committerJonas Devlieghere <jonas@devlieghere.com>
Tue, 22 Dec 2020 18:08:21 +0000 (10:08 -0800)
Add a method to check if the type is a scoped enumeration (i.e. "enum
class/struct").

Differential revision: https://reviews.llvm.org/D93690

lldb/bindings/interface/SBType.i
lldb/include/lldb/API/SBType.h
lldb/include/lldb/Symbol/CompilerType.h
lldb/include/lldb/Symbol/TypeSystem.h
lldb/source/API/SBType.cpp
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
lldb/source/Symbol/CompilerType.cpp
lldb/test/API/python_api/type/TestTypeList.py
lldb/test/API/python_api/type/main.cpp

index fd2dda18845491cf54a11e28ed8b25e025bb2ed4..b65eddb5fe29d800ae65f845dc79aeb764ba58dc 100644 (file)
@@ -220,6 +220,9 @@ public:
     bool
     IsAnonymousType ();
 
+    bool
+    IsScopedEnumerationType ();
+
     lldb::SBType
     GetPointerType();
 
index 5f487aa5d2581d4d2a44f94670466aa1c0dbc740..9ac385c492ed56baa2b891b446a61e472c835c40 100644 (file)
@@ -131,6 +131,8 @@ public:
 
   bool IsAnonymousType();
 
+  bool IsScopedEnumerationType();
+
   lldb::SBType GetPointerType();
 
   lldb::SBType GetPointeeType();
index f1cde0ac3084967433164d703598c060b0fb44dd..1e0f520ab95964028d11d09f23949062debea9e7 100644 (file)
@@ -82,6 +82,8 @@ public:
 
   bool IsAnonymousType() const;
 
+  bool IsScopedEnumerationType() const;
+
   bool IsBeingDefined() const;
 
   bool IsCharType() const;
index 4c51d290ad2c5ffc8184c158b5f9c34d93bbaec1..b8393b9c39e1d8c73c34364bbb5bf1aac5caae69 100644 (file)
@@ -175,6 +175,8 @@ public:
     return false;
   }
 
+  virtual bool IsScopedEnumerationType(lldb::opaque_compiler_type_t type) = 0;
+
   virtual bool IsPossibleDynamicType(lldb::opaque_compiler_type_t type,
                                      CompilerType *target_type, // Can pass NULL
                                      bool check_cplusplus, bool check_objc) = 0;
index 0a99ac0f229230c2def87adcae058047195b6968..7d8d4cfeef4f8927632ff4bfeaece1f556179a51 100644 (file)
@@ -271,6 +271,14 @@ bool SBType::IsAnonymousType() {
   return m_opaque_sp->GetCompilerType(true).IsAnonymousType();
 }
 
+bool SBType::IsScopedEnumerationType() {
+  LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsScopedEnumerationType);
+
+  if (!IsValid())
+    return false;
+  return m_opaque_sp->GetCompilerType(true).IsScopedEnumerationType();
+}
+
 lldb::SBType SBType::GetFunctionReturnType() {
   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetFunctionReturnType);
 
@@ -935,6 +943,7 @@ void RegisterMethods<SBType>(Registry &R) {
   LLDB_REGISTER_METHOD(bool, SBType, IsPolymorphicClass, ());
   LLDB_REGISTER_METHOD(bool, SBType, IsTypedefType, ());
   LLDB_REGISTER_METHOD(bool, SBType, IsAnonymousType, ());
+  LLDB_REGISTER_METHOD(bool, SBType, IsScopedEnumerationType, ());
   LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetFunctionReturnType, ());
   LLDB_REGISTER_METHOD(lldb::SBTypeList, SBType, GetFunctionArgumentTypes,
                        ());
index 894faa84745074817fa94ac723625b963854af50..d1a9e9387292a4cec2a9028f6a880165c416a5cd 100644 (file)
@@ -3147,6 +3147,20 @@ bool TypeSystemClang::IsEnumerationType(lldb::opaque_compiler_type_t type,
   return false;
 }
 
+bool TypeSystemClang::IsScopedEnumerationType(
+    lldb::opaque_compiler_type_t type) {
+  if (type) {
+    const clang::EnumType *enum_type = llvm::dyn_cast<clang::EnumType>(
+        GetCanonicalQualType(type)->getCanonicalTypeInternal());
+
+    if (enum_type) {
+      return enum_type->isScopedEnumeralType();
+    }
+  }
+
+  return false;
+}
+
 bool TypeSystemClang::IsPointerType(lldb::opaque_compiler_type_t type,
                                     CompilerType *pointee_type) {
   if (type) {
index 484c251aa00e180c0f06767185632c0beb2f3dcf..7b16579cf240d71a23737d5fb57ab05e55512539 100644 (file)
@@ -600,6 +600,8 @@ public:
   bool IsEnumerationType(lldb::opaque_compiler_type_t type,
                          bool &is_signed) override;
 
+  bool IsScopedEnumerationType(lldb::opaque_compiler_type_t type) override;
+
   static bool IsObjCClassType(const CompilerType &type);
 
   static bool IsObjCClassTypeAndHasIVars(const CompilerType &type,
index c2f68283f60360b23e0ba7c9604aeabe8e97a3e2..2c5910a683fac4a2634d9221cd959d3556cc7d8d 100644 (file)
@@ -40,6 +40,12 @@ bool CompilerType::IsAnonymousType() const {
   return false;
 }
 
+bool CompilerType::IsScopedEnumerationType() const {
+  if (IsValid())
+    return m_type_system->IsScopedEnumerationType(m_type);
+  return false;
+}
+
 bool CompilerType::IsArrayType(CompilerType *element_type_ptr, uint64_t *size,
                                bool *is_incomplete) const {
   if (IsValid())
index 901ddc62f4e5698db7b1aec4ed08428638c75de6..6ed6ca42727d250b30a98c9e266de4ef2bab5674 100644 (file)
@@ -144,3 +144,13 @@ class TypeAndTypeListTestCase(TestBase):
         myint_type = target.FindFirstType('myint')
         self.DebugSBType(myint_type)
         self.assertTrue(myint_arr_element_type == myint_type)
+
+        # Test enum methods.
+        enum_type = target.FindFirstType('EnumType')
+        self.assertTrue(enum_type)
+        self.DebugSBType(enum_type)
+        self.assertFalse(enum_type.IsScopedEnumerationType())
+        scoped_enum_type = target.FindFirstType('ScopedEnumType')
+        self.assertTrue(scoped_enum_type)
+        self.DebugSBType(scoped_enum_type)
+        self.assertTrue(scoped_enum_type.IsScopedEnumerationType())
index 13e6bbc127ba65dec63768f6357546bbdab007f0..5b96f47ea3664ae6ea97140e4b57931db1d2bf04 100644 (file)
@@ -29,6 +29,8 @@ public:
     {}
 };
 
+enum EnumType {};
+enum class ScopedEnumType {};
 
 int main (int argc, char const *argv[])
 {
@@ -59,5 +61,8 @@ int main (int argc, char const *argv[])
     typedef int myint;
     myint myint_arr[] = {1, 2, 3};
 
+    EnumType enum_type;
+    ScopedEnumType scoped_enum_type;
+
     return 0; // Break at this line
 }