Remove all the __repr__ methods from the API/*.h files, and put them

into python-extensions.swig, which gets included into lldb.swig, and
adds them back into the classes when swig generates it's C++ file.  This
keeps the Python stuff out of the general API classes.

Also fixed a small bug in the copy constructor for SBSymbolContext.

llvm-svn: 114602
This commit is contained in:
Caroline Tice 2010-09-22 23:01:29 +00:00
parent a9424d4f2f
commit dac97f31a3
47 changed files with 171 additions and 348 deletions

View File

@ -47,13 +47,6 @@ public:
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
protected:
friend class SBFrame;

View File

@ -52,13 +52,6 @@ public:
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject *, which contains a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
private:
friend class SBFrame;
friend class SBSymbolContext;

View File

@ -116,13 +116,6 @@ public:
static lldb::SBBreakpointLocation
GetBreakpointLocationAtIndexFromEvent (const lldb::SBEvent& event, uint32_t loc_idx);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
private:
friend class SBBreakpointLocation;
friend class SBTarget;

View File

@ -74,13 +74,6 @@ public:
SBBreakpoint
GetBreakpoint ();
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
private:
friend class SBBreakpoint;

View File

@ -61,13 +61,6 @@ public:
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
protected:
friend class SBCommandInterpreter;
friend class SBOptions;

View File

@ -53,13 +53,6 @@ public:
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
private:
friend class SBFrame;
friend class SBSymbolContext;

View File

@ -157,13 +157,6 @@ public:
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
uint32_t
GetTerminalWidth () const;

View File

@ -10,11 +10,6 @@
#ifndef LLDB_SBDefines_h_
#define LLDB_SBDefines_h_
// In order to guarantee correct working with Python, Python.h *MUST* be
// the *FIRST* header file included:
#include <Python.h>
// C Includes
// C++ Includes
// Other libraries and framework includes

View File

@ -68,13 +68,6 @@ public:
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
protected:
friend class SBArguments;
friend class SBDebugger;

View File

@ -57,13 +57,6 @@ public:
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
protected:
friend class SBListener;
friend class SBBroadcaster;

View File

@ -54,13 +54,6 @@ public:
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
private:
friend class SBBlock;
friend class SBCompileUnit;

View File

@ -115,13 +115,6 @@ public:
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
protected:
friend class SBValue;

View File

@ -42,13 +42,6 @@ public:
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
private:
friend class SBFrame;
friend class SBSymbolContext;

View File

@ -49,13 +49,6 @@ public:
//bool
//GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
//PyObject *
//__repr__ ();
private:
//lldb_private::Disassembler::Instruction::SharedPtr m_opaque_sp;

View File

@ -61,13 +61,6 @@ public:
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
private:
friend class SBCompileUnit;
friend class SBFrame;

View File

@ -52,13 +52,6 @@ public:
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
private:
friend class SBSymbolContext;
friend class SBTarget;

View File

@ -155,13 +155,6 @@ public:
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It take no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
protected:
friend class SBAddress;
friend class SBBreakpoint;

View File

@ -43,13 +43,6 @@ public:
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
private:
friend class SBSymbolContext;

View File

@ -44,6 +44,9 @@ public:
SBLineEntry GetLineEntry ();
SBSymbol GetSymbol ();
bool
GetDescription (lldb::SBStream &description);
protected:
friend class SBFrame;
friend class SBModule;
@ -58,6 +61,9 @@ protected:
lldb_private::SymbolContext&
operator*();
lldb_private::SymbolContext&
ref();
const lldb_private::SymbolContext&
operator*() const;
@ -71,16 +77,6 @@ protected:
void
SetSymbolContext (const lldb_private::SymbolContext *sc_ptr);
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
private:
std::auto_ptr<lldb_private::SymbolContext> m_opaque_ap;
};

View File

@ -145,13 +145,6 @@ public:
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
protected:
friend class SBAddress;
friend class SBDebugger;

View File

@ -91,13 +91,6 @@ public:
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
protected:
friend class SBBreakpoint;
friend class SBBreakpointLocation;

View File

@ -57,13 +57,6 @@ public:
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
protected:
void *m_ast;
void *m_type;

View File

@ -88,13 +88,6 @@ public:
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It take no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
protected:
friend class SBValueList;
friend class SBFrame;

View File

@ -1046,6 +1046,7 @@
9A42976211861AA600FE05CD /* CommandObjectBreakpointCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CommandObjectBreakpointCommand.cpp; path = source/Commands/CommandObjectBreakpointCommand.cpp; sourceTree = "<group>"; };
9A4633DA11F65D8600955CE1 /* UserSettingsController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UserSettingsController.h; path = include/lldb/Core/UserSettingsController.h; sourceTree = "<group>"; };
9A4633DC11F65D9A00955CE1 /* UserSettingsController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = UserSettingsController.cpp; path = source/Core/UserSettingsController.cpp; sourceTree = "<group>"; };
9A48A3A7124AAA5A00922451 /* python-extensions.swig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "python-extensions.swig"; sourceTree = "<group>"; };
9A633FE7112DCE3C001A7E43 /* SBFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SBFrame.cpp; path = source/API/SBFrame.cpp; sourceTree = "<group>"; };
9A633FE8112DCE3C001A7E43 /* SBFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SBFrame.h; path = include/lldb/API/SBFrame.h; sourceTree = "<group>"; };
9A82010B10FFB49800182560 /* ScriptInterpreter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ScriptInterpreter.cpp; path = source/Interpreter/ScriptInterpreter.cpp; sourceTree = "<group>"; };
@ -1553,6 +1554,7 @@
266960601199F4230075C61A /* build-swig-Python.sh */,
266960611199F4230075C61A /* edit-swig-python-wrapper-file.py */,
266960621199F4230075C61A /* finish-swig-Python-lldb.sh */,
9A48A3A7124AAA5A00922451 /* python-extensions.swig */,
);
path = Python;
sourceTree = "<group>";
@ -2349,7 +2351,6 @@
isa = PBXProject;
buildConfigurationList = 1DEB91EF08733DB70010E9CD /* Build configuration list for PBXProject "lldb" */;
compatibilityVersion = "Xcode 3.1";
developmentRegion = English;
hasScannedForEncodings = 1;
knownRegions = (
en,

View File

@ -0,0 +1,135 @@
%extend lldb::SBAddress {
PyObject *lldb::SBAddress::__repr__ (){
lldb::SBStream description;
$self->GetDescription (description);
return PyString_FromString (description.GetData());
}
}
%extend lldb::SBBlock {
PyObject *lldb::SBBlock::__repr__ (){
lldb::SBStream description;
$self->GetDescription (description);
return PyString_FromString (description.GetData());
}
}
%extend lldb::SBBreakpoint {
PyObject *lldb::SBBreakpoint::__repr__ (){
lldb::SBStream description;
$self->GetDescription ("full", description);
return PyString_FromString (description.GetData());
}
}
%extend lldb::SBBreakpointLocation {
PyObject *lldb::SBBreakpointLocation::__repr__ (){
lldb::SBStream description;
$self->GetDescription ("full", description);
return PyString_FromString (description.GetData());
}
}
%extend lldb::SBCommandReturnObject {
PyObject *lldb::SBCommandReturnObject::__repr__ (){
lldb::SBStream description;
$self->GetDescription (description);
return PyString_FromString (description.GetData());
}
}
%extend lldb::SBCompileUnit {
PyObject *lldb::SBCompileUnit::__repr__ (){
lldb::SBStream description;
$self->GetDescription (description);
return PyString_FromString (description.GetData());
}
}
%extend lldb::SBDebugger {
PyObject *lldb::SBDebugger::__repr__ (){
lldb::SBStream description;
$self->GetDescription (description);
return PyString_FromString (description.GetData());
}
}
%extend lldb::SBError {
PyObject *lldb::SBError::__repr__ (){
lldb::SBStream description;
$self->GetDescription (description);
return PyString_FromString (description.GetData());
}
}
%extend lldb::SBFileSpec {
PyObject *lldb::SBFileSpec::__repr__ (){
lldb::SBStream description;
$self->GetDescription (description);
return PyString_FromString (description.GetData());
}
}
%extend lldb::SBFrame {
PyObject *lldb::SBFrame::__repr__ (){
lldb::SBStream description;
$self->GetDescription (description);
return PyString_FromString (description.GetData());
}
}
%extend lldb::SBFunction {
PyObject *lldb::SBFunction::__repr__ (){
lldb::SBStream description;
$self->GetDescription (description);
return PyString_FromString (description.GetData());
}
}
%extend lldb::SBLineEntry {
PyObject *lldb::SBLineEntry::__repr__ (){
lldb::SBStream description;
$self->GetDescription (description);
return PyString_FromString (description.GetData());
}
}
%extend lldb::SBModule {
PyObject *lldb::SBModule::__repr__ (){
lldb::SBStream description;
$self->GetDescription (description);
return PyString_FromString (description.GetData());
}
}
%extend lldb::SBProcess {
PyObject *lldb::SBProcess::__repr__ (){
lldb::SBStream description;
$self->GetDescription (description);
return PyString_FromString (description.GetData());
}
}
%extend lldb::SBSymbol {
PyObject *lldb::SBSymbol::__repr__ (){
lldb::SBStream description;
$self->GetDescription (description);
return PyString_FromString (description.GetData());
}
}
%extend lldb::SBSymbolContext {
PyObject *lldb::SBSymbolContext::__repr__ (){
lldb::SBStream description;
$self->GetDescription (description);
return PyString_FromString (description.GetData());
}
}
%extend lldb::SBTarget {
PyObject *lldb::SBTarget::__repr__ (){
lldb::SBStream description;
$self->GetDescription (description);
return PyString_FromString (description.GetData());
}
}
%extend lldb::SBThread {
PyObject *lldb::SBThread::__repr__ (){
lldb::SBStream description;
$self->GetDescription (description);
return PyString_FromString (description.GetData());
}
}
%extend lldb::SBValue {
PyObject *lldb::SBValue::__repr__ (){
lldb::SBStream description;
$self->GetDescription (description);
return PyString_FromString (description.GetData());
}
}

View File

@ -156,4 +156,4 @@ typedef int StopReason;
%include "lldb/API/SBValueList.h"
%include "lldb/lldb-types.h"
%include "./Python/python-extensions.swig"

View File

@ -140,6 +140,7 @@ SBAddress::operator*() const
bool
SBAddress::GetDescription (SBStream &description)
{
description.ref();
if (m_opaque_ap.get())
{
m_opaque_ap->DumpDebug (description.get());
@ -149,12 +150,3 @@ SBAddress::GetDescription (SBStream &description)
return true;
}
PyObject *
SBAddress::__repr__ ()
{
SBStream description;
description.ref(); // Make sure it contains a valid StreamString.
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -158,12 +158,3 @@ SBBlock::GetDescription (SBStream &description)
return true;
}
PyObject *
SBBlock::__repr__ ()
{
SBStream description;
description.ref();
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -337,7 +337,7 @@ SBBreakpoint::GetDescription (const char *description_level, SBStream &descripti
else
level = eDescriptionLevelBrief;
description.ref();
m_opaque_sp->GetDescription (description.get(), level);
description.get()->EOL();
}
@ -347,15 +347,6 @@ SBBreakpoint::GetDescription (const char *description_level, SBStream &descripti
return true;
}
PyObject *
SBBreakpoint::__repr__ ()
{
SBStream description;
description.ref();
GetDescription ("full", description);
return PyString_FromString (description.GetData());
}
bool
SBBreakpoint::PrivateBreakpointHitCallback
(

View File

@ -212,6 +212,7 @@ SBBreakpointLocation::GetDescription (const char *description_level, SBStream &d
else
level = eDescriptionLevelBrief;
description.ref();
m_opaque_sp->GetDescription (description.get(), level);
description.get()->EOL();
}
@ -221,15 +222,6 @@ SBBreakpointLocation::GetDescription (const char *description_level, SBStream &d
return true;
}
PyObject *
SBBreakpointLocation::__repr__ ()
{
SBStream description;
description.ref();
GetDescription ("full", description);
return PyString_FromString (description.GetData());
}
SBBreakpoint
SBBreakpointLocation::GetBreakpoint ()
{

View File

@ -188,11 +188,3 @@ SBCommandReturnObject::GetDescription (SBStream &description)
return true;
}
PyObject *
SBCommandReturnObject::__repr__ ()
{
SBStream description;
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -125,6 +125,7 @@ SBCompileUnit::GetDescription (SBStream &description)
{
if (m_opaque_ptr)
{
description.ref();
m_opaque_ptr->Dump (description.get(), false);
}
else
@ -132,12 +133,3 @@ SBCompileUnit::GetDescription (SBStream &description)
return true;
}
PyObject *
SBCompileUnit::__repr__ ()
{
SBStream description;
description.ref();
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -695,12 +695,3 @@ SBDebugger::GetDescription (SBStream &description)
return true;
}
PyObject *
SBDebugger::__repr__ ()
{
SBStream description;
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -198,11 +198,3 @@ SBError::GetDescription (SBStream &description)
return true;
}
PyObject *
SBError::__repr__ ()
{
SBStream description;
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -156,6 +156,7 @@ SBEvent::GetDescription (SBStream &description)
{
if (m_opaque)
{
description.ref();
m_opaque->Dump (description.get());
}
else
@ -163,12 +164,3 @@ SBEvent::GetDescription (SBStream &description)
return true;
}
PyObject *
SBEvent::__repr__ ()
{
SBStream description;
description.ref();
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -158,11 +158,3 @@ SBFileSpec::GetDescription (SBStream &description)
return true;
}
PyObject *
SBFileSpec::__repr__ ()
{
SBStream description;
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -394,6 +394,7 @@ SBFrame::GetDescription (SBStream &description)
{
if (m_opaque_sp)
{
description.ref();
m_opaque_sp->Dump (description.get(), true, false);
}
else
@ -401,12 +402,3 @@ SBFrame::GetDescription (SBStream &description)
return true;
}
PyObject *
SBFrame::__repr__ ()
{
SBStream description;
description.ref();
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -69,6 +69,7 @@ SBFunction::GetDescription (SBStream &description)
{
if (m_opaque_ptr)
{
description.ref();
m_opaque_ptr->Dump (description.get(), false);
}
else
@ -76,12 +77,3 @@ SBFunction::GetDescription (SBStream &description)
return true;
}
PyObject *
SBFunction::__repr__ ()
{
SBStream description;
description.ref();
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -172,11 +172,3 @@ SBLineEntry::GetDescription (SBStream &description)
return true;
}
PyObject *
SBLineEntry::__repr__ ()
{
SBStream description;
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -133,6 +133,7 @@ SBModule::GetDescription (SBStream &description)
{
if (m_opaque_sp)
{
description.ref();
m_opaque_sp->Dump (description.get());
}
else
@ -140,12 +141,3 @@ SBModule::GetDescription (SBStream &description)
return true;
}
PyObject *
SBModule::__repr__ ()
{
SBStream description;
description.ref();
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -485,11 +485,3 @@ SBProcess::GetDescription (SBStream &description)
return true;
}
PyObject *
SBProcess::__repr__ ()
{
SBStream description;
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -69,19 +69,12 @@ SBSymbol::GetDescription (SBStream &description)
{
if (m_opaque_ptr)
{
m_opaque_ptr->GetDescription (description.get(), lldb::eDescriptionLevelFull, NULL);
description.ref();
m_opaque_ptr->GetDescription (description.get(),
lldb::eDescriptionLevelFull, NULL);
}
else
description.Printf ("No value");
return true;
}
PyObject *
SBSymbol::__repr__ ()
{
SBStream description;
description.ref();
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -32,7 +32,12 @@ SBSymbolContext::SBSymbolContext (const SBSymbolContext& rhs) :
m_opaque_ap ()
{
if (rhs.IsValid())
*m_opaque_ap = *rhs.m_opaque_ap;
{
if (m_opaque_ap.get())
*m_opaque_ap = *rhs.m_opaque_ap;
else
ref() = *rhs.m_opaque_ap;
}
}
SBSymbolContext::~SBSymbolContext ()
@ -141,6 +146,14 @@ SBSymbolContext::operator*()
return *m_opaque_ap.get();
}
lldb_private::SymbolContext&
SBSymbolContext::ref()
{
if (m_opaque_ap.get() == NULL)
m_opaque_ap.reset (new SymbolContext);
return *m_opaque_ap.get();
}
lldb_private::SymbolContext *
SBSymbolContext::get() const
{
@ -152,6 +165,7 @@ SBSymbolContext::GetDescription (SBStream &description)
{
if (m_opaque_ap.get())
{
description.ref();
m_opaque_ap->GetDescription (description.get(), lldb::eDescriptionLevelFull, NULL);
}
else
@ -159,12 +173,3 @@ SBSymbolContext::GetDescription (SBStream &description)
return true;
}
PyObject *
SBSymbolContext::__repr__ ()
{
SBStream description;
description.ref();
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -507,6 +507,7 @@ SBTarget::GetDescription (SBStream &description)
{
if (m_opaque_sp)
{
description.ref();
m_opaque_sp->Dump (description.get());
}
else
@ -514,12 +515,3 @@ SBTarget::GetDescription (SBStream &description)
return true;
}
PyObject *
SBTarget::__repr__ ()
{
SBStream description;
description.ref();
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -428,11 +428,3 @@ SBThread::GetDescription (SBStream &description)
return true;
}
PyObject *
SBThread::__repr__ ()
{
SBStream description;
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -185,14 +185,6 @@ SBType::GetDescription (SBStream &description)
return true;
}
PyObject *
SBType::__repr__ ()
{
SBStream description;
GetDescription (description);
return PyString_FromString (description.GetData());
}
SBTypeMember::SBTypeMember () :
m_ast (NULL),
m_parent_type (NULL),

View File

@ -293,11 +293,3 @@ SBValue::GetDescription (SBStream &description)
return true;
}
PyObject *
SBValue::__repr__ ()
{
SBStream description;
GetDescription (description);
return PyString_FromString (description.GetData());
}