[Lldb-commits] [lldb] r130531 - in /lldb/trunk: scripts/Python/modify-python-lldb.py test/python_api/lldbutil/TestLLDBIterator.py

Johnny Chen johnny.chen at apple.com
Fri Apr 29 12:03:03 PDT 2011


Author: johnny
Date: Fri Apr 29 14:03:02 2011
New Revision: 130531

URL: http://llvm.org/viewvc/llvm-project?rev=130531&view=rev
Log:
Add the Python rich comparison methods for SBBreakpoint, where GetID() returns
the breakpoint ID and provides the semantics needed for '==' and '!='.  And
modify LLDBIteratorTestCase.lldb_iter_2() to use '==' between two SBBreakpoint's.

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=130531&r1=130530&r2=130531&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/modify-python-lldb.py (original)
+++ lldb/trunk/scripts/Python/modify-python-lldb.py Fri Apr 29 14:03:02 2011
@@ -40,6 +40,10 @@
 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')"
+#
+# 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()"
+ne_def = "    def __ne__(self, other): return not self.__eq__(other)"
 
 #
 # The dictionary defines a mapping from classname to (getsize, getelem) tuple.
@@ -64,6 +68,11 @@
                    }
       }
 
+#
+# This dictionary defines a mapping from classname to equality method name.
+#
+e = { 'SBBreakpoint': 'GetID' }
+
 # The new content will have the iteration protocol defined for our lldb objects.
 new_content = StringIO.StringIO()
 
@@ -79,7 +88,7 @@
 # These define the states of our state machine.
 NORMAL = 0
 DEFINING_ITERATOR = 1
-DEFINING_TARGET_ITERATOR = 2
+DEFINING_EQUALITY = 2
 
 # The lldb_iter_def only needs to be inserted once.
 lldb_iter_defined = False;
@@ -91,25 +100,32 @@
         if not lldb_iter_defined and match:
             print >> new_content, lldb_iter_def
             lldb_iter_defined = True
-        if match and match.group(1) in d:
-            # Adding support for iteration for the matched SB class.
+        if match:
             cls = match.group(1)
-            # Next state will be DEFINING_ITERATOR.
-            state = DEFINING_ITERATOR
-    elif state == DEFINING_ITERATOR:
+            if cls in d:
+                # Adding support for iteration for the matched SB class.
+                state = (state | DEFINING_ITERATOR)
+            if cls in e:
+                # Adding support for eq and ne for the matched SB class.
+                state = (state | DEFINING_EQUALITY)
+    elif state > NORMAL:
         match = init_pattern.search(line)
         if match:
             # We found the beginning of the __init__ method definition.
-            # This is a good spot to insert the iteration support.
+            # This is a good spot to insert the iter and/or eq-ne support.
             #
             # But note that SBTarget has two types of iterations.
             if cls == "SBTarget":
                 print >> new_content, module_iter % (d[cls]['module'])
                 print >> new_content, breakpoint_iter % (d[cls]['breakpoint'])
             else:
-                print >> new_content, iter_def % d[cls]
-            # Next state will be NORMAL.
-            state = NORMAL
+                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, ne_def
+                # Next state will be NORMAL.
+                state = NORMAL
 
     # Pass the original line of content to the ew_content.
     print >> new_content, line

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=130531&r1=130530&r2=130531&view=diff
==============================================================================
--- lldb/trunk/test/python_api/lldbutil/TestLLDBIterator.py (original)
+++ lldb/trunk/test/python_api/lldbutil/TestLLDBIterator.py Fri Apr 29 14:03:02 2011
@@ -92,7 +92,7 @@
             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].GetID() == mine[i].GetID(),
+            self.assertTrue(yours[i] == mine[i],
                             "ID of yours[{0}] and mine[{0}] matches".format(i))
 
     def lldb_iter_3(self):





More information about the lldb-commits mailing list