aboutsummaryrefslogtreecommitdiff
path: root/lldb/test/API/python_api
diff options
context:
space:
mode:
authorVlad Serebrennikov <serebrennikov.vladislav@gmail.com>2023-10-14 10:52:34 +0400
committerGitHub <noreply@github.com>2023-10-14 10:52:34 +0400
commit93229c7bfd97429aa0ac55b45e618bdb013702b2 (patch)
tree06ceff4d8dab25540e0c9b70fe16ac91772cf881 /lldb/test/API/python_api
parent02f67c097de12dc9f6c97a68d9e180af79a2483b (diff)
downloadllvm-93229c7bfd97429aa0ac55b45e618bdb013702b2.zip
llvm-93229c7bfd97429aa0ac55b45e618bdb013702b2.tar.gz
llvm-93229c7bfd97429aa0ac55b45e618bdb013702b2.tar.bz2
[lldb] Add SBType::FindDirectNestedType() function (#68705)
This patch adds a `SBType::FindDirectNestedType(name)` function which performs a non-recursive search in given class for a type with specified name. The intent is to perform a fast search in debug info, so that it can be used in formatters, and let them remain responsive. This is driven by my work on formatters for Clang and LLVM types. In particular, by [`PointerIntPairInfo::MaskAndShiftConstants`](https://github.com/llvm/llvm-project/blob/cde9f9df79805a0850310870d6dcc64004292727/llvm/include/llvm/ADT/PointerIntPair.h#L174C16-L174C16), which is required to extract pointer and integer from `PointerIntPair`. Related Discourse thread: https://discourse.llvm.org/t/traversing-member-types-of-a-type/72452
Diffstat (limited to 'lldb/test/API/python_api')
-rw-r--r--lldb/test/API/python_api/type/TestTypeList.py31
-rw-r--r--lldb/test/API/python_api/type/main.cpp5
2 files changed, 36 insertions, 0 deletions
diff --git a/lldb/test/API/python_api/type/TestTypeList.py b/lldb/test/API/python_api/type/TestTypeList.py
index c2fcadc..c267def 100644
--- a/lldb/test/API/python_api/type/TestTypeList.py
+++ b/lldb/test/API/python_api/type/TestTypeList.py
@@ -119,6 +119,37 @@ class TypeAndTypeListTestCase(TestBase):
self.assertEqual(task_type, task_head_pointee_type)
+ # Check whether we can find a directly nested type by name
+ name_type = task_type.FindDirectNestedType("name")
+ self.assertTrue(name_type)
+ self.DebugSBType(name_type)
+
+ enum_type = task_type.FindDirectNestedType("E")
+ self.assertTrue(enum_type)
+ self.DebugSBType(enum_type)
+
+ union_type = task_type.FindDirectNestedType("U")
+ self.assertTrue(union_type)
+ self.DebugSBType(union_type)
+
+ # Check that we don't find indirectly nested types
+ self.assertTrue(enum_type.size == 1)
+
+ invalid_type = task_type.FindDirectNestedType("E2")
+ self.assertFalse(invalid_type)
+
+ # Check that FindDirectNestedType handles types without DeclContext
+ # and other errorneous inputs
+ task_ptr_type = task_type.GetPointerType()
+ invalid_type = task_ptr_type.FindDirectNestedType("name")
+ self.assertFalse(invalid_type)
+
+ invalid_type = task_type.FindDirectNestedType("")
+ self.assertFalse(invalid_type)
+
+ invalid_type = task_type.FindDirectNestedType(None)
+ self.assertFalse(invalid_type)
+
# We'll now get the child member 'id' from 'task_head'.
id = task_head.GetChildMemberWithName("id")
self.DebugSBValue(id)
diff --git a/lldb/test/API/python_api/type/main.cpp b/lldb/test/API/python_api/type/main.cpp
index b1ef625..98de970 100644
--- a/lldb/test/API/python_api/type/main.cpp
+++ b/lldb/test/API/python_api/type/main.cpp
@@ -21,7 +21,12 @@ public:
} my_type_is_nameless;
struct name {
int x;
+ enum E : int {} e;
+ enum E2 {} e2;
} my_type_is_named;
+ enum E : unsigned char {} e;
+ union U {
+ } u;
Task(int i, Task *n):
id(i),
next(n),