diff options
author | Enrico Granata <egranata@apple.com> | 2013-05-03 01:29:27 +0000 |
---|---|---|
committer | Enrico Granata <egranata@apple.com> | 2013-05-03 01:29:27 +0000 |
commit | c3387333ced81f6ef83b9022c5bde4a42bba05fa (patch) | |
tree | 4278e4f4cb83ae061635238e4a9563d251b4bb6a /lldb/scripts/Python/python-extensions.swig | |
parent | 57f745ec96f14847e13de25d664ac8e9b5b59509 (diff) | |
download | bcm5719-llvm-c3387333ced81f6ef83b9022c5bde4a42bba05fa.tar.gz bcm5719-llvm-c3387333ced81f6ef83b9022c5bde4a42bba05fa.zip |
<rdar://problem/11742979>
SWIG is smart enough to recognize that C++ operators == and != mean __eq__ and __ne__ in Python and do the appropriate translation
But it is not smart enough to recognize that mySBObject == None should return False instead of erroring out
The %pythoncode blocks are meant to provide those extra smarts (and they play some SWIG&Python magic to find the right function to call behind the scenes with no risk of typos :-)
Lastly, SBBreakpoint provides an == but never provided a != operator - common courtesy is to provide both
llvm-svn: 180987
Diffstat (limited to 'lldb/scripts/Python/python-extensions.swig')
-rw-r--r-- | lldb/scripts/Python/python-extensions.swig | 211 |
1 files changed, 211 insertions, 0 deletions
diff --git a/lldb/scripts/Python/python-extensions.swig b/lldb/scripts/Python/python-extensions.swig index 1ff07829248..8d57156469f 100644 --- a/lldb/scripts/Python/python-extensions.swig +++ b/lldb/scripts/Python/python-extensions.swig @@ -40,6 +40,21 @@ else return PyString_FromString(""); } + + %pythoncode %{ + def __eq__(self, rhs): + if not isinstance(rhs, type(self)): + return False + + return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) + + def __ne__(self, rhs): + if not isinstance(rhs, type(self)): + return True + + return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) + %} + } %extend lldb::SBBreakpointLocation { PyObject *lldb::SBBreakpointLocation::__str__ (){ @@ -55,6 +70,23 @@ return PyString_FromString(""); } } + +%extend lldb::SBBroadcaster { + %pythoncode %{ + def __eq__(self, rhs): + if not isinstance(rhs, type(self)): + return False + + return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) + + def __ne__(self, rhs): + if not isinstance(rhs, type(self)): + return True + + return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) + %} +} + %extend lldb::SBCommandReturnObject { PyObject *lldb::SBCommandReturnObject::__str__ (){ lldb::SBStream description; @@ -95,6 +127,19 @@ else return PyString_FromString(""); } + %pythoncode %{ + def __eq__(self, rhs): + if not isinstance(rhs, type(self)): + return False + + return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) + + def __ne__(self, rhs): + if not isinstance(rhs, type(self)): + return True + + return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) + %} } %extend lldb::SBData { PyObject *lldb::SBData::__str__ (){ @@ -137,6 +182,21 @@ else return PyString_FromString(""); } + + %pythoncode %{ + def __eq__(self, rhs): + if not isinstance(rhs, type(self)): + return False + + return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) + + def __ne__(self, rhs): + if not isinstance(rhs, type(self)): + return True + + return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) + %} + } %extend lldb::SBError { PyObject *lldb::SBError::__str__ (){ @@ -193,6 +253,21 @@ else return PyString_FromString(""); } + + %pythoncode %{ + def __eq__(self, rhs): + if not isinstance(rhs, type(self)): + return False + + return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) + + def __ne__(self, rhs): + if not isinstance(rhs, type(self)): + return True + + return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) + %} + } %extend lldb::SBInstruction { PyObject *lldb::SBInstruction::__str__ (){ @@ -235,6 +310,20 @@ else return PyString_FromString(""); } + + %pythoncode %{ + def __eq__(self, rhs): + if not isinstance(rhs, type(self)): + return False + + return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) + + def __ne__(self, rhs): + if not isinstance(rhs, type(self)): + return True + + return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) + %} } %extend lldb::SBModule { PyObject *lldb::SBModule::__str__ (){ @@ -249,6 +338,20 @@ else return PyString_FromString(""); } + + %pythoncode %{ + def __eq__(self, rhs): + if not isinstance(rhs, type(self)): + return False + + return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) + + def __ne__(self, rhs): + if not isinstance(rhs, type(self)): + return True + + return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) + %} } %extend lldb::SBProcess { PyObject *lldb::SBProcess::__str__ (){ @@ -277,6 +380,20 @@ else return PyString_FromString(""); } + + %pythoncode %{ + def __eq__(self, rhs): + if not isinstance(rhs, type(self)): + return False + + return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) + + def __ne__(self, rhs): + if not isinstance(rhs, type(self)): + return True + + return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) + %} } %extend lldb::SBStream { /* the write() and flush() calls are not part of the SB API proper, and are solely for Python usage @@ -305,6 +422,19 @@ else return PyString_FromString(""); } + %pythoncode %{ + def __eq__(self, rhs): + if not isinstance(rhs, type(self)): + return False + + return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) + + def __ne__(self, rhs): + if not isinstance(rhs, type(self)): + return True + + return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) + %} } %extend lldb::SBSymbolContext { PyObject *lldb::SBSymbolContext::__str__ (){ @@ -334,6 +464,7 @@ return PyString_FromString(""); } } + %extend lldb::SBTarget { PyObject *lldb::SBTarget::__str__ (){ lldb::SBStream description; @@ -347,7 +478,22 @@ else return PyString_FromString(""); } + + %pythoncode %{ + def __eq__(self, rhs): + if not isinstance(rhs, type(self)): + return False + + return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) + + def __ne__(self, rhs): + if not isinstance(rhs, type(self)): + return True + + return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) + %} } + %extend lldb::SBType { PyObject *lldb::SBType::__str__ (){ lldb::SBStream description; @@ -389,6 +535,19 @@ else return PyString_FromString(""); } + %pythoncode %{ + def __eq__(self, rhs): + if not isinstance(rhs, type(self)): + return False + + return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) + + def __ne__(self, rhs): + if not isinstance(rhs, type(self)): + return True + + return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) + %} } %extend lldb::SBTypeFormat { PyObject *lldb::SBTypeFormat::__str__ (){ @@ -431,6 +590,19 @@ else return PyString_FromString(""); } + %pythoncode %{ + def __eq__(self, rhs): + if not isinstance(rhs, type(self)): + return False + + return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) + + def __ne__(self, rhs): + if not isinstance(rhs, type(self)): + return True + + return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) + %} } %extend lldb::SBTypeSummary { PyObject *lldb::SBTypeSummary::__str__ (){ @@ -445,6 +617,19 @@ else return PyString_FromString(""); } + %pythoncode %{ + def __eq__(self, rhs): + if not isinstance(rhs, type(self)): + return False + + return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) + + def __ne__(self, rhs): + if not isinstance(rhs, type(self)): + return True + + return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) + %} } %extend lldb::SBTypeSynthetic { PyObject *lldb::SBTypeSynthetic::__str__ (){ @@ -459,6 +644,19 @@ else return PyString_FromString(""); } + %pythoncode %{ + def __eq__(self, rhs): + if not isinstance(rhs, type(self)): + return False + + return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) + + def __ne__(self, rhs): + if not isinstance(rhs, type(self)): + return True + + return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) + %} } %extend lldb::SBThread { PyObject *lldb::SBThread::__str__ (){ @@ -473,6 +671,19 @@ else return PyString_FromString(""); } + %pythoncode %{ + def __eq__(self, rhs): + if not isinstance(rhs, type(self)): + return False + + return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) + + def __ne__(self, rhs): + if not isinstance(rhs, type(self)): + return True + + return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) + %} } %extend lldb::SBValue { PyObject *lldb::SBValue::__str__ (){ |