[Lldb-commits] [lldb] r130709 - in /lldb/trunk: scripts/Python/modify-python-lldb.py test/python_api/lldbutil/TestLLDBIterator.py
Johnny Chen
johnny.chen at apple.com
Mon May 2 12:05:52 PDT 2011
Author: johnny
Date: Mon May 2 14:05:52 2011
New Revision: 130709
URL: http://llvm.org/viewvc/llvm-project?rev=130709&view=rev
Log:
Add implementation of '==' and '!=' for SBFileSpec and SBModule. Modify a test case to take advantage of 'ths_module == that_module'.
Modified:
lldb/trunk/scripts/Python/modify-python-lldb.py
lldb/trunk/test/python_api/lldbutil/TestLLDBIterator.py
Modified: lldb/trunk/scripts/Python/modify-python-lldb.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/modify-python-lldb.py?rev=130709&r1=130708&r2=130709&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/modify-python-lldb.py (original)
+++ lldb/trunk/scripts/Python/modify-python-lldb.py Mon May 2 14:05:52 2011
@@ -42,7 +42,7 @@
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 @@
}
#
-# 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 @@
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.
Modified: lldb/trunk/test/python_api/lldbutil/TestLLDBIterator.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/lldbutil/TestLLDBIterator.py?rev=130709&r1=130708&r2=130709&view=diff
==============================================================================
--- lldb/trunk/test/python_api/lldbutil/TestLLDBIterator.py (original)
+++ lldb/trunk/test/python_api/lldbutil/TestLLDBIterator.py Mon May 2 14:05:52 2011
@@ -63,8 +63,8 @@
if self.TraceOn():
print "yours[%d]='%s'" % (i, get_description(yours[i]))
print "mine[%d]='%s'" % (i, get_description(mine[i]))
- self.assertTrue(yours[i].GetUUIDString() == mine[i].GetUUIDString(),
- "UUID of yours[{0}] and mine[{0}] matches".format(i))
+ self.assertTrue(yours[i] == mine[i],
+ "UUID+FileSpec of yours[{0}] and mine[{0}] matches".format(i))
def lldb_iter_2(self):
exe = os.path.join(os.getcwd(), "a.out")
More information about the lldb-commits
mailing list