[NFC][Coroutines] Use structured binding with llvm::enumerate in CoroSplit (#116879)
[llvm-project.git] / lldb / bindings / interface / SBValueListExtensions.i
bloba74df7b5f0a61106899bc276845c7841c1456df9
1 %extend lldb::SBValueList {
3 #ifdef SWIGPYTHON
4 %nothreadallow;
5 #endif
6 std::string lldb::SBValueList::__str__ (){
7 lldb::SBStream description;
8 const size_t n = $self->GetSize();
9 if (n)
11 for (size_t i=0; i<n; ++i)
12 $self->GetValueAtIndex(i).GetDescription(description);
14 else
16 description.Printf("<empty> lldb.SBValueList()");
18 const char *desc = description.GetData();
19 size_t desc_len = description.GetSize();
20 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r'))
21 --desc_len;
22 return std::string(desc, desc_len);
24 #ifdef SWIGPYTHON
25 %clearnothreadallow;
26 #endif
28 #ifdef SWIGPYTHON
29 %pythoncode %{
30 def __iter__(self):
31 '''Iterate over all values in a lldb.SBValueList object.'''
32 return lldb_iter(self, 'GetSize', 'GetValueAtIndex')
34 def __len__(self):
35 return int(self.GetSize())
37 def __getitem__(self, key):
38 count = len(self)
39 #------------------------------------------------------------
40 # Access with "int" to get Nth item in the list
41 #------------------------------------------------------------
42 if type(key) is int:
43 if -count <= key < count:
44 key %= count
45 return self.GetValueAtIndex(key)
46 #------------------------------------------------------------
47 # Access with "str" to get values by name
48 #------------------------------------------------------------
49 elif type(key) is str:
50 matches = []
51 for idx in range(count):
52 value = self.GetValueAtIndex(idx)
53 if value.name == key:
54 matches.append(value)
55 return matches
56 #------------------------------------------------------------
57 # Match with regex
58 #------------------------------------------------------------
59 elif isinstance(key, type(re.compile('.'))):
60 matches = []
61 for idx in range(count):
62 value = self.GetValueAtIndex(idx)
63 re_match = key.search(value.name)
64 if re_match:
65 matches.append(value)
66 return matches
69 #endif