Added Repr() and Str() member functions to our PythonObject class to allow easy conversion to-string of every PythonObject

llvm-svn: 186205
This commit is contained in:
Enrico Granata 2013-07-12 21:11:02 +00:00
parent 456ed25149
commit b8b0bf9b81
2 changed files with 28 additions and 0 deletions

View File

@ -99,6 +99,12 @@ namespace lldb_private {
return m_py_obj;
}
PythonString
Repr ();
PythonString
Str ();
operator bool () const
{
return m_py_obj != NULL;

View File

@ -66,6 +66,28 @@ PythonObject::Dump (Stream &strm) const
strm.PutCString ("NULL");
}
PythonString
PythonObject::Repr ()
{
if (!m_py_obj)
return PythonString ();
PyObject *repr = PyObject_Repr(m_py_obj);
if (!repr)
return PythonString ();
return PythonString(repr);
}
PythonString
PythonObject::Str ()
{
if (!m_py_obj)
return PythonString ();
PyObject *str = PyObject_Str(m_py_obj);
if (!str)
return PythonString ();
return PythonString(str);
}
//----------------------------------------------------------------------
// PythonString
//----------------------------------------------------------------------