diff options
author | Johnny Chen <johnny.chen@apple.com> | 2011-05-02 19:05:52 +0000 |
---|---|---|
committer | Johnny Chen <johnny.chen@apple.com> | 2011-05-02 19:05:52 +0000 |
commit | d71670c04a94fbad23d64f9f48ed0462e458599d (patch) | |
tree | 84794bb83640017d597fa5e32aca9db902223d06 /lldb/scripts/Python/modify-python-lldb.py | |
parent | 0b510279c6fa37ba1494bd3d7310c3308257634d (diff) | |
download | bcm5719-llvm-d71670c04a94fbad23d64f9f48ed0462e458599d.tar.gz bcm5719-llvm-d71670c04a94fbad23d64f9f48ed0462e458599d.zip |
Add implementation of '==' and '!=' for SBFileSpec and SBModule. Modify a test case to take advantage of 'ths_module == that_module'.
llvm-svn: 130709
Diffstat (limited to 'lldb/scripts/Python/modify-python-lldb.py')
-rw-r--r-- | lldb/scripts/Python/modify-python-lldb.py | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/lldb/scripts/Python/modify-python-lldb.py b/lldb/scripts/Python/modify-python-lldb.py index 6908fac09d5..2a73e6788dd 100644 --- a/lldb/scripts/Python/modify-python-lldb.py +++ b/lldb/scripts/Python/modify-python-lldb.py @@ -42,7 +42,7 @@ module_iter = " def module_iter(self): return lldb_iter(self, '%s', '%s')" breakpoint_iter = " def breakpoint_iter(self): return lldb_iter(self, '%s', '%s')" # # This supports the rich comparison methods of __eq__ and __ne__. -eq_def = " def __eq__(self, other): return isinstance(other, %s) and self.%s() == other.%s()" +eq_def = " def __eq__(self, other): return isinstance(other, %s) and %s" ne_def = " def __ne__(self, other): return not self.__eq__(other)" # @@ -69,9 +69,28 @@ d = { 'SBBreakpoint': ('GetNumLocations', 'GetLocationAtIndex'), } # -# This dictionary defines a mapping from classname to equality method name. +# This dictionary defines a mapping from classname to equality method name(s). # -e = { 'SBBreakpoint': 'GetID' } +e = { 'SBBreakpoint': ['GetID'], + 'SBFileSpec': ['GetFilename', 'GetDirectory'], + 'SBModule': ['GetFileSpec', 'GetUUIDString'] + } + +def list_to_frag(list): + """Transform a list to equality program fragment. + + For example, ['GetID'] is transformed to 'self.GetID() == other.GetID()', + and ['GetFilename', 'GetDirectory'] to 'self.GetFilename() == other.GetFilename() + and self.GetDirectory() == other.GetDirectory()'. + """ + if not list: + raise Exception("list should be non-empty") + frag = StringIO.StringIO() + for i in range(len(list)): + if i > 0: + frag.write(" and ") + frag.write("self.{0}() == other.{0}()".format(list[i])) + return frag.getvalue() # The new content will have the iteration protocol defined for our lldb objects. new_content = StringIO.StringIO() @@ -122,7 +141,7 @@ for line in content.splitlines(): if (state & DEFINING_ITERATOR): print >> new_content, iter_def % d[cls] if (state & DEFINING_EQUALITY): - print >> new_content, eq_def % (cls, e[cls], e[cls]) + print >> new_content, eq_def % (cls, list_to_frag(e[cls])) print >> new_content, ne_def # Next state will be NORMAL. |