diff options
author | Johnny Chen <johnny.chen@apple.com> | 2011-05-16 20:31:18 +0000 |
---|---|---|
committer | Johnny Chen <johnny.chen@apple.com> | 2011-05-16 20:31:18 +0000 |
commit | fac7b3aae60146638ce1446b2347ad43ccdd32ca (patch) | |
tree | 0a54544419398ffc615df08290ae5d2797eb52db /lldb/scripts/Python/modify-python-lldb.py | |
parent | 9ac944774f4b985e379c2bf316fd340baaeb901c (diff) | |
download | llvm-fac7b3aae60146638ce1446b2347ad43ccdd32ca.zip llvm-fac7b3aae60146638ce1446b2347ad43ccdd32ca.tar.gz llvm-fac7b3aae60146638ce1446b2347ad43ccdd32ca.tar.bz2 |
Add implementation of built-in function len() for those lldb containers with
unambiguous iteration support. So that we could, for example:
...
REGs = lldbutil.get_GPRs(frame)
print "Number of general purpose registers: %d" % len(REGs)
for reg in REGs:
print "%s => %s" %(reg.GetName(), reg.GetValue())
...
llvm-svn: 131418
Diffstat (limited to 'lldb/scripts/Python/modify-python-lldb.py')
-rw-r--r-- | lldb/scripts/Python/modify-python-lldb.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lldb/scripts/Python/modify-python-lldb.py b/lldb/scripts/Python/modify-python-lldb.py index 2a73e67..da395c5 100644 --- a/lldb/scripts/Python/modify-python-lldb.py +++ b/lldb/scripts/Python/modify-python-lldb.py @@ -41,6 +41,11 @@ iter_def = " def __iter__(self): return lldb_iter(self, '%s', '%s')" module_iter = " def module_iter(self): return lldb_iter(self, '%s', '%s')" breakpoint_iter = " def breakpoint_iter(self): return lldb_iter(self, '%s', '%s')" # +# Called to implement the built-in function len(). +# Eligible objects are those containers with unambiguous iteration support. +# +len_def = " def __len__(self): return self.%s()" +# # This supports the rich comparison methods of __eq__ and __ne__. eq_def = " def __eq__(self, other): return isinstance(other, %s) and %s" ne_def = " def __ne__(self, other): return not self.__eq__(other)" @@ -104,7 +109,7 @@ class_pattern = re.compile("^class (SB.*)\(_object\):$") # The pattern for recognizing the beginning of the __init__ method definition. init_pattern = re.compile("^ def __init__\(self, \*args\):") -# These define the states of our state machine. +# These define the states of our finite state machine. NORMAL = 0 DEFINING_ITERATOR = 1 DEFINING_EQUALITY = 2 @@ -140,6 +145,7 @@ for line in content.splitlines(): else: if (state & DEFINING_ITERATOR): print >> new_content, iter_def % d[cls] + print >> new_content, len_def % d[cls][0] if (state & DEFINING_EQUALITY): print >> new_content, eq_def % (cls, list_to_frag(e[cls])) print >> new_content, ne_def |