[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`](cde9f9df79/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
This commit is contained in:
committed by
GitHub
parent
02f67c097d
commit
93229c7bfd
@@ -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)
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user