[llvm-branch-commits] [lldb] e17a00f - [lldb] Add SBType::IsScopedEnumerationType method

Jonas Devlieghere via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Dec 22 10:13:05 PST 2020


Author: Andy Yankovsky
Date: 2020-12-22T10:08:21-08:00
New Revision: e17a00fc87bc163cc2438ce10faca51d94b91ab3

URL: https://github.com/llvm/llvm-project/commit/e17a00fc87bc163cc2438ce10faca51d94b91ab3
DIFF: https://github.com/llvm/llvm-project/commit/e17a00fc87bc163cc2438ce10faca51d94b91ab3.diff

LOG: [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

Added: 
    

Modified: 
    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

Removed: 
    


################################################################################
diff  --git a/lldb/bindings/interface/SBType.i b/lldb/bindings/interface/SBType.i
index fd2dda188454..b65eddb5fe29 100644
--- a/lldb/bindings/interface/SBType.i
+++ b/lldb/bindings/interface/SBType.i
@@ -220,6 +220,9 @@ public:
     bool
     IsAnonymousType ();
 
+    bool
+    IsScopedEnumerationType ();
+
     lldb::SBType
     GetPointerType();
 

diff  --git a/lldb/include/lldb/API/SBType.h b/lldb/include/lldb/API/SBType.h
index 5f487aa5d258..9ac385c492ed 100644
--- a/lldb/include/lldb/API/SBType.h
+++ b/lldb/include/lldb/API/SBType.h
@@ -131,6 +131,8 @@ class SBType {
 
   bool IsAnonymousType();
 
+  bool IsScopedEnumerationType();
+
   lldb::SBType GetPointerType();
 
   lldb::SBType GetPointeeType();

diff  --git a/lldb/include/lldb/Symbol/CompilerType.h b/lldb/include/lldb/Symbol/CompilerType.h
index f1cde0ac3084..1e0f520ab959 100644
--- a/lldb/include/lldb/Symbol/CompilerType.h
+++ b/lldb/include/lldb/Symbol/CompilerType.h
@@ -82,6 +82,8 @@ class CompilerType {
 
   bool IsAnonymousType() const;
 
+  bool IsScopedEnumerationType() const;
+
   bool IsBeingDefined() const;
 
   bool IsCharType() const;

diff  --git a/lldb/include/lldb/Symbol/TypeSystem.h b/lldb/include/lldb/Symbol/TypeSystem.h
index 4c51d290ad2c..b8393b9c39e1 100644
--- a/lldb/include/lldb/Symbol/TypeSystem.h
+++ b/lldb/include/lldb/Symbol/TypeSystem.h
@@ -175,6 +175,8 @@ class TypeSystem : public PluginInterface {
     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;

diff  --git a/lldb/source/API/SBType.cpp b/lldb/source/API/SBType.cpp
index 0a99ac0f2292..7d8d4cfeef4f 100644
--- a/lldb/source/API/SBType.cpp
+++ b/lldb/source/API/SBType.cpp
@@ -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,
                        ());

diff  --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 894faa847450..d1a9e9387292 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -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) {

diff  --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
index 484c251aa00e..7b16579cf240 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
@@ -600,6 +600,8 @@ class TypeSystemClang : public TypeSystem {
   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,

diff  --git a/lldb/source/Symbol/CompilerType.cpp b/lldb/source/Symbol/CompilerType.cpp
index c2f68283f603..2c5910a683fa 100644
--- a/lldb/source/Symbol/CompilerType.cpp
+++ b/lldb/source/Symbol/CompilerType.cpp
@@ -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())

diff  --git a/lldb/test/API/python_api/type/TestTypeList.py b/lldb/test/API/python_api/type/TestTypeList.py
index 901ddc62f4e5..6ed6ca42727d 100644
--- a/lldb/test/API/python_api/type/TestTypeList.py
+++ b/lldb/test/API/python_api/type/TestTypeList.py
@@ -144,3 +144,13 @@ def test(self):
         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())

diff  --git a/lldb/test/API/python_api/type/main.cpp b/lldb/test/API/python_api/type/main.cpp
index 13e6bbc127ba..5b96f47ea366 100644
--- a/lldb/test/API/python_api/type/main.cpp
+++ b/lldb/test/API/python_api/type/main.cpp
@@ -29,6 +29,8 @@ class Task {
     {}
 };
 
+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
 }


        


More information about the llvm-branch-commits mailing list