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.



git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@114602 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/API/SBAddress.cpp b/source/API/SBAddress.cpp
index 0afe914..7f21cf7 100644
--- a/source/API/SBAddress.cpp
+++ b/source/API/SBAddress.cpp
@@ -140,6 +140,7 @@
 bool
 SBAddress::GetDescription (SBStream &description)
 {
+    description.ref();
     if (m_opaque_ap.get())
     {
         m_opaque_ap->DumpDebug (description.get());
@@ -149,12 +150,3 @@
 
     return true;
 }
-
-PyObject *
-SBAddress::__repr__ ()
-{
-    SBStream description;
-    description.ref();            // Make sure it contains a valid StreamString.
-    GetDescription (description);
-    return PyString_FromString (description.GetData());
-}
diff --git a/source/API/SBBlock.cpp b/source/API/SBBlock.cpp
index 02db9b2..b57936d 100644
--- a/source/API/SBBlock.cpp
+++ b/source/API/SBBlock.cpp
@@ -158,12 +158,3 @@
     
     return true;
 }
-
-PyObject *
-SBBlock::__repr__ ()
-{
-    SBStream description;
-    description.ref();
-    GetDescription (description);
-    return PyString_FromString (description.GetData());
-}
diff --git a/source/API/SBBreakpoint.cpp b/source/API/SBBreakpoint.cpp
index aa84575..70a7045 100644
--- a/source/API/SBBreakpoint.cpp
+++ b/source/API/SBBreakpoint.cpp
@@ -337,7 +337,7 @@
         else
             level = eDescriptionLevelBrief;
 
-
+        description.ref();
         m_opaque_sp->GetDescription (description.get(), level);
         description.get()->EOL();
     }
@@ -347,15 +347,6 @@
     return true;
 }
 
-PyObject *
-SBBreakpoint::__repr__ ()
-{
-    SBStream description;
-    description.ref();
-    GetDescription ("full", description);
-    return PyString_FromString (description.GetData());
-}
-
 bool
 SBBreakpoint::PrivateBreakpointHitCallback 
 (
diff --git a/source/API/SBBreakpointLocation.cpp b/source/API/SBBreakpointLocation.cpp
index f7e059b..07300ea 100644
--- a/source/API/SBBreakpointLocation.cpp
+++ b/source/API/SBBreakpointLocation.cpp
@@ -212,6 +212,7 @@
         else
             level = eDescriptionLevelBrief;
 
+        description.ref();
         m_opaque_sp->GetDescription (description.get(), level);
         description.get()->EOL();
     }
@@ -221,15 +222,6 @@
     return true;
 }
 
-PyObject *
-SBBreakpointLocation::__repr__ ()
-{
-    SBStream description;
-    description.ref();
-    GetDescription ("full", description);
-    return PyString_FromString (description.GetData());
-}
-
 SBBreakpoint
 SBBreakpointLocation::GetBreakpoint ()
 {
diff --git a/source/API/SBCommandReturnObject.cpp b/source/API/SBCommandReturnObject.cpp
index 458ce50..35195f6 100644
--- a/source/API/SBCommandReturnObject.cpp
+++ b/source/API/SBCommandReturnObject.cpp
@@ -188,11 +188,3 @@
 
     return true;
 }
-
-PyObject *
-SBCommandReturnObject::__repr__ ()
-{
-    SBStream description;
-    GetDescription (description);
-    return PyString_FromString (description.GetData());
-}
diff --git a/source/API/SBCompileUnit.cpp b/source/API/SBCompileUnit.cpp
index 9e68e28..42bbf82 100644
--- a/source/API/SBCompileUnit.cpp
+++ b/source/API/SBCompileUnit.cpp
@@ -125,6 +125,7 @@
 {
     if (m_opaque_ptr)
     {
+        description.ref();
         m_opaque_ptr->Dump (description.get(), false);
     }
     else
@@ -132,12 +133,3 @@
     
     return true;
 }
-
-PyObject *
-SBCompileUnit::__repr__ ()
-{
-    SBStream description;
-    description.ref();
-    GetDescription (description);
-    return PyString_FromString (description.GetData());
-}
diff --git a/source/API/SBDebugger.cpp b/source/API/SBDebugger.cpp
index 0a48e69..81658d5 100644
--- a/source/API/SBDebugger.cpp
+++ b/source/API/SBDebugger.cpp
@@ -695,12 +695,3 @@
     
     return true;
 }
-
-
-PyObject *
-SBDebugger::__repr__ ()
-{
-    SBStream description;
-    GetDescription (description);
-    return PyString_FromString (description.GetData());
-}
diff --git a/source/API/SBError.cpp b/source/API/SBError.cpp
index 1365619..9553b6f 100644
--- a/source/API/SBError.cpp
+++ b/source/API/SBError.cpp
@@ -198,11 +198,3 @@
 
     return true;
 } 
-
-PyObject *
-SBError::__repr__ ()
-{
-    SBStream description;
-    GetDescription (description);
-    return PyString_FromString (description.GetData());
-}
diff --git a/source/API/SBEvent.cpp b/source/API/SBEvent.cpp
index d77f002..d1123e7 100644
--- a/source/API/SBEvent.cpp
+++ b/source/API/SBEvent.cpp
@@ -156,6 +156,7 @@
 {
     if (m_opaque)
     {
+        description.ref();
         m_opaque->Dump (description.get());
     }
     else
@@ -163,12 +164,3 @@
 
     return true;
 }
-
-PyObject *
-SBEvent::__repr__ ()
-{
-    SBStream description;
-    description.ref();
-    GetDescription (description);
-    return PyString_FromString (description.GetData());
-}
diff --git a/source/API/SBFileSpec.cpp b/source/API/SBFileSpec.cpp
index 1edd946..36fcf1b 100644
--- a/source/API/SBFileSpec.cpp
+++ b/source/API/SBFileSpec.cpp
@@ -158,11 +158,3 @@
     
     return true;
 }
-
-PyObject *
-SBFileSpec::__repr__ ()
-{
-    SBStream description;
-    GetDescription (description);
-    return PyString_FromString (description.GetData());
-}
diff --git a/source/API/SBFrame.cpp b/source/API/SBFrame.cpp
index 9095269..9e0f35d 100644
--- a/source/API/SBFrame.cpp
+++ b/source/API/SBFrame.cpp
@@ -394,6 +394,7 @@
 {
     if (m_opaque_sp)
     {
+        description.ref();
         m_opaque_sp->Dump (description.get(), true, false);
     }
     else
@@ -401,12 +402,3 @@
 
     return true;
 }
-
-PyObject *
-SBFrame::__repr__ ()
-{
-    SBStream description;
-    description.ref();
-    GetDescription (description);
-    return PyString_FromString (description.GetData());
-}
diff --git a/source/API/SBFunction.cpp b/source/API/SBFunction.cpp
index 4c5f64e..38e349b 100644
--- a/source/API/SBFunction.cpp
+++ b/source/API/SBFunction.cpp
@@ -69,6 +69,7 @@
 {
     if (m_opaque_ptr)
     {
+        description.ref();
         m_opaque_ptr->Dump (description.get(), false);
     }
     else
@@ -76,12 +77,3 @@
 
     return true;
 }
-
-PyObject *
-SBFunction::__repr__ ()
-{
-    SBStream description;
-    description.ref();
-    GetDescription (description);
-    return PyString_FromString (description.GetData());
-}
diff --git a/source/API/SBLineEntry.cpp b/source/API/SBLineEntry.cpp
index 27f01d5..023afb9 100644
--- a/source/API/SBLineEntry.cpp
+++ b/source/API/SBLineEntry.cpp
@@ -172,11 +172,3 @@
 
     return true;
 }
-
-PyObject *
-SBLineEntry::__repr__ ()
-{
-    SBStream description; 
-    GetDescription (description);
-    return PyString_FromString (description.GetData());
-}
diff --git a/source/API/SBModule.cpp b/source/API/SBModule.cpp
index a0b340a..b59a600 100644
--- a/source/API/SBModule.cpp
+++ b/source/API/SBModule.cpp
@@ -133,6 +133,7 @@
 {
     if (m_opaque_sp)
     {
+        description.ref();
         m_opaque_sp->Dump (description.get());
     }
     else
@@ -140,12 +141,3 @@
 
     return true;
 }
-
-PyObject *
-SBModule::__repr__ ()
-{
-    SBStream description;
-    description.ref();
-    GetDescription (description);
-    return PyString_FromString (description.GetData());
-}
diff --git a/source/API/SBProcess.cpp b/source/API/SBProcess.cpp
index d2c85ba..2d6e6b0 100644
--- a/source/API/SBProcess.cpp
+++ b/source/API/SBProcess.cpp
@@ -485,11 +485,3 @@
 
     return true;
 }
-
-PyObject *
-SBProcess::__repr__ ()
-{
-    SBStream description;
-    GetDescription (description);
-    return PyString_FromString (description.GetData());
-}
diff --git a/source/API/SBSymbol.cpp b/source/API/SBSymbol.cpp
index 3c700e1..017df43 100644
--- a/source/API/SBSymbol.cpp
+++ b/source/API/SBSymbol.cpp
@@ -69,19 +69,12 @@
 {
     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());
-}
diff --git a/source/API/SBSymbolContext.cpp b/source/API/SBSymbolContext.cpp
index 4381994..ecd7d66 100644
--- a/source/API/SBSymbolContext.cpp
+++ b/source/API/SBSymbolContext.cpp
@@ -32,7 +32,12 @@
     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 @@
     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 @@
 {
     if (m_opaque_ap.get())
     {
+        description.ref();
         m_opaque_ap->GetDescription (description.get(), lldb::eDescriptionLevelFull, NULL);
     }
     else
@@ -159,12 +173,3 @@
 
     return true;
 }
-
-PyObject *
-SBSymbolContext::__repr__ ()
-{
-    SBStream description;
-    description.ref();
-    GetDescription (description);
-    return PyString_FromString (description.GetData());
-}
diff --git a/source/API/SBTarget.cpp b/source/API/SBTarget.cpp
index cc544db..f34b014 100644
--- a/source/API/SBTarget.cpp
+++ b/source/API/SBTarget.cpp
@@ -507,6 +507,7 @@
 {
     if (m_opaque_sp)
     {
+        description.ref();
         m_opaque_sp->Dump (description.get());
     }
     else
@@ -514,12 +515,3 @@
     
     return true;
 }
-
-PyObject *
-SBTarget::__repr__ ()
-{
-    SBStream description;
-    description.ref();
-    GetDescription (description);
-    return PyString_FromString (description.GetData());
-}
diff --git a/source/API/SBThread.cpp b/source/API/SBThread.cpp
index aa621fb..8c74a34 100644
--- a/source/API/SBThread.cpp
+++ b/source/API/SBThread.cpp
@@ -428,11 +428,3 @@
     
     return true;
 }
-
-PyObject *
-SBThread::__repr__ ()
-{
-    SBStream description;
-    GetDescription (description);
-    return PyString_FromString (description.GetData());
-}
diff --git a/source/API/SBType.cpp b/source/API/SBType.cpp
index d34e94a..5c3e973 100644
--- a/source/API/SBType.cpp
+++ b/source/API/SBType.cpp
@@ -185,14 +185,6 @@
     return true;
 }
 
-PyObject *
-SBType::__repr__ ()
-{
-    SBStream description;
-    GetDescription (description);
-    return PyString_FromString (description.GetData());
-}
-
 SBTypeMember::SBTypeMember () :
     m_ast (NULL),
     m_parent_type (NULL),
diff --git a/source/API/SBValue.cpp b/source/API/SBValue.cpp
index e2fdffa..4b437f4 100644
--- a/source/API/SBValue.cpp
+++ b/source/API/SBValue.cpp
@@ -293,11 +293,3 @@
 
     return true;
 }
-
-PyObject *
-SBValue::__repr__ ()
-{
-    SBStream description;
-    GetDescription (description);
-    return PyString_FromString (description.GetData());
-}