[Lldb-commits] [lldb] 1432ae5 - [lldb] Add SBType::GetEnumerationIntegerType method

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Tue Dec 22 10:08:31 PST 2020


Author: Andy Yankovsky
Date: 2020-12-22T10:08:22-08:00
New Revision: 1432ae57bf6e4022b6f4541c9225674ee6b19c23

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

LOG: [lldb] Add SBType::GetEnumerationIntegerType method

Add a method for getting the enumeration underlying type.

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

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 b65eddb5fe29..2d9a4a4d11d1 100644
--- a/lldb/bindings/interface/SBType.i
+++ b/lldb/bindings/interface/SBType.i
@@ -244,6 +244,9 @@ public:
     lldb::SBType
     GetCanonicalType();
 
+    lldb::SBType
+    GetEnumerationIntegerType();
+
     lldb::SBType
     GetArrayElementType ();
 

diff  --git a/lldb/include/lldb/API/SBType.h b/lldb/include/lldb/API/SBType.h
index 9ac385c492ed..529b4d0eeffc 100644
--- a/lldb/include/lldb/API/SBType.h
+++ b/lldb/include/lldb/API/SBType.h
@@ -152,6 +152,9 @@ class SBType {
   lldb::SBType GetVectorElementType();
 
   lldb::SBType GetCanonicalType();
+
+  lldb::SBType GetEnumerationIntegerType();
+
   // Get the "lldb::BasicType" enumeration for a type. If a type is not a basic
   // type eBasicTypeInvalid will be returned
   lldb::BasicType GetBasicType();

diff  --git a/lldb/include/lldb/Symbol/CompilerType.h b/lldb/include/lldb/Symbol/CompilerType.h
index 1e0f520ab959..5a0e8e57200d 100644
--- a/lldb/include/lldb/Symbol/CompilerType.h
+++ b/lldb/include/lldb/Symbol/CompilerType.h
@@ -187,6 +187,8 @@ class CompilerType {
 
   CompilerType GetFullyUnqualifiedType() const;
 
+  CompilerType GetEnumerationIntegerType() const;
+
   /// Returns -1 if this isn't a function of if the function doesn't
   /// have a prototype Returns a value >= 0 if there is a prototype.
   int GetFunctionArgumentCount() const;

diff  --git a/lldb/include/lldb/Symbol/TypeSystem.h b/lldb/include/lldb/Symbol/TypeSystem.h
index b8393b9c39e1..1fad8f61ac37 100644
--- a/lldb/include/lldb/Symbol/TypeSystem.h
+++ b/lldb/include/lldb/Symbol/TypeSystem.h
@@ -227,6 +227,9 @@ class TypeSystem : public PluginInterface {
 
   virtual CompilerType GetCanonicalType(lldb::opaque_compiler_type_t type) = 0;
 
+  virtual CompilerType
+  GetEnumerationIntegerType(lldb::opaque_compiler_type_t type) = 0;
+
   // Returns -1 if this isn't a function of if the function doesn't have a
   // prototype Returns a value >= 0 if there is a prototype.
   virtual int GetFunctionArgumentCount(lldb::opaque_compiler_type_t type) = 0;

diff  --git a/lldb/source/API/SBType.cpp b/lldb/source/API/SBType.cpp
index 7d8d4cfeef4f..550c4b065914 100644
--- a/lldb/source/API/SBType.cpp
+++ b/lldb/source/API/SBType.cpp
@@ -344,6 +344,16 @@ lldb::SBType SBType::GetCanonicalType() {
   return LLDB_RECORD_RESULT(SBType());
 }
 
+SBType SBType::GetEnumerationIntegerType() {
+  LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetEnumerationIntegerType);
+
+  if (IsValid()) {
+    return LLDB_RECORD_RESULT(
+        SBType(m_opaque_sp->GetCompilerType(true).GetEnumerationIntegerType()));
+  }
+  return LLDB_RECORD_RESULT(SBType());
+}
+
 lldb::BasicType SBType::GetBasicType() {
   LLDB_RECORD_METHOD_NO_ARGS(lldb::BasicType, SBType, GetBasicType);
 
@@ -952,6 +962,7 @@ void RegisterMethods<SBType>(Registry &R) {
                        GetMemberFunctionAtIndex, (uint32_t));
   LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetUnqualifiedType, ());
   LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetCanonicalType, ());
+  LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetEnumerationIntegerType, ());
   LLDB_REGISTER_METHOD(lldb::BasicType, SBType, GetBasicType, ());
   LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetBasicType, (lldb::BasicType));
   LLDB_REGISTER_METHOD(uint32_t, SBType, GetNumberOfDirectBaseClasses, ());

diff  --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index d1a9e9387292..4f55cf7cfa79 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -4195,6 +4195,13 @@ TypeSystemClang::GetFullyUnqualifiedType(lldb::opaque_compiler_type_t type) {
   return CompilerType();
 }
 
+CompilerType
+TypeSystemClang::GetEnumerationIntegerType(lldb::opaque_compiler_type_t type) {
+  if (type)
+    return GetEnumerationIntegerType(GetType(GetCanonicalQualType(type)));
+  return CompilerType();
+}
+
 int TypeSystemClang::GetFunctionArgumentCount(
     lldb::opaque_compiler_type_t type) {
   if (type) {

diff  --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
index 7b16579cf240..d24c5958204f 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
@@ -678,6 +678,9 @@ class TypeSystemClang : public TypeSystem {
   CompilerType
   GetFullyUnqualifiedType(lldb::opaque_compiler_type_t type) override;
 
+  CompilerType
+  GetEnumerationIntegerType(lldb::opaque_compiler_type_t type) override;
+
   // Returns -1 if this isn't a function of if the function doesn't have a
   // prototype Returns a value >= 0 if there is a prototype.
   int GetFunctionArgumentCount(lldb::opaque_compiler_type_t type) override;

diff  --git a/lldb/source/Symbol/CompilerType.cpp b/lldb/source/Symbol/CompilerType.cpp
index 2c5910a683fa..4f0c3b366af5 100644
--- a/lldb/source/Symbol/CompilerType.cpp
+++ b/lldb/source/Symbol/CompilerType.cpp
@@ -350,6 +350,12 @@ CompilerType CompilerType::GetFullyUnqualifiedType() const {
   return CompilerType();
 }
 
+CompilerType CompilerType::GetEnumerationIntegerType() const {
+  if (IsValid())
+    return m_type_system->GetEnumerationIntegerType(m_type);
+  return CompilerType();
+}
+
 int CompilerType::GetFunctionArgumentCount() const {
   if (IsValid()) {
     return m_type_system->GetFunctionArgumentCount(m_type);

diff  --git a/lldb/test/API/python_api/type/TestTypeList.py b/lldb/test/API/python_api/type/TestTypeList.py
index 6ed6ca42727d..ff560de2f96f 100644
--- a/lldb/test/API/python_api/type/TestTypeList.py
+++ b/lldb/test/API/python_api/type/TestTypeList.py
@@ -150,7 +150,20 @@ def test(self):
         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())
+        int_scoped_enum_type = scoped_enum_type.GetEnumerationIntegerType()
+        self.assertTrue(int_scoped_enum_type)
+        self.DebugSBType(int_scoped_enum_type)
+        self.assertEquals(int_scoped_enum_type.GetName(), 'int')
+
+        enum_uchar = target.FindFirstType('EnumUChar')
+        self.assertTrue(enum_uchar)
+        self.DebugSBType(enum_uchar)
+        int_enum_uchar = enum_uchar.GetEnumerationIntegerType()
+        self.assertTrue(int_enum_uchar)
+        self.DebugSBType(int_enum_uchar)
+        self.assertEquals(int_enum_uchar.GetName(), 'unsigned char')

diff  --git a/lldb/test/API/python_api/type/main.cpp b/lldb/test/API/python_api/type/main.cpp
index 5b96f47ea366..b1ef62528385 100644
--- a/lldb/test/API/python_api/type/main.cpp
+++ b/lldb/test/API/python_api/type/main.cpp
@@ -31,6 +31,7 @@ class Task {
 
 enum EnumType {};
 enum class ScopedEnumType {};
+enum class EnumUChar : unsigned char {};
 
 int main (int argc, char const *argv[])
 {
@@ -63,6 +64,7 @@ int main (int argc, char const *argv[])
 
     EnumType enum_type;
     ScopedEnumType scoped_enum_type;
+    EnumUChar scoped_enum_type_uchar;
 
     return 0; // Break at this line
 }


        


More information about the lldb-commits mailing list