1 //===-- SBTypeSynthetic.cpp -----------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "lldb/lldb-python.h" 11 12 #include "lldb/API/SBTypeSynthetic.h" 13 14 #include "lldb/API/SBStream.h" 15 16 #include "lldb/DataFormatters/DataVisualization.h" 17 18 using namespace lldb; 19 using namespace lldb_private; 20 21 #ifndef LLDB_DISABLE_PYTHON 22 23 SBTypeSynthetic::SBTypeSynthetic() : 24 m_opaque_sp() 25 { 26 } 27 28 SBTypeSynthetic 29 SBTypeSynthetic::CreateWithClassName (const char* data, uint32_t options) 30 { 31 if (!data || data[0] == 0) 32 return SBTypeSynthetic(); 33 return SBTypeSynthetic(ScriptedSyntheticChildrenSP(new ScriptedSyntheticChildren(options, data, ""))); 34 } 35 36 SBTypeSynthetic 37 SBTypeSynthetic::CreateWithScriptCode (const char* data, uint32_t options) 38 { 39 if (!data || data[0] == 0) 40 return SBTypeSynthetic(); 41 return SBTypeSynthetic(ScriptedSyntheticChildrenSP(new ScriptedSyntheticChildren(options, "", data))); 42 } 43 44 SBTypeSynthetic::SBTypeSynthetic (const lldb::SBTypeSynthetic &rhs) : 45 m_opaque_sp(rhs.m_opaque_sp) 46 { 47 } 48 49 SBTypeSynthetic::~SBTypeSynthetic () 50 { 51 } 52 53 bool 54 SBTypeSynthetic::IsValid() const 55 { 56 return m_opaque_sp.get() != NULL; 57 } 58 59 bool 60 SBTypeSynthetic::IsClassCode() 61 { 62 if (!IsValid()) 63 return false; 64 const char* code = m_opaque_sp->GetPythonCode(); 65 return (code && *code); 66 } 67 68 bool 69 SBTypeSynthetic::IsClassName() 70 { 71 if (!IsValid()) 72 return false; 73 return !IsClassCode(); 74 } 75 76 const char* 77 SBTypeSynthetic::GetData () 78 { 79 if (!IsValid()) 80 return NULL; 81 if (IsClassCode()) 82 return m_opaque_sp->GetPythonCode(); 83 else 84 return m_opaque_sp->GetPythonClassName(); 85 } 86 87 void 88 SBTypeSynthetic::SetClassName (const char* data) 89 { 90 if (IsValid() && data && *data) 91 m_opaque_sp->SetPythonClassName(data); 92 } 93 94 void 95 SBTypeSynthetic::SetClassCode (const char* data) 96 { 97 if (IsValid() && data && *data) 98 m_opaque_sp->SetPythonCode(data); 99 } 100 101 uint32_t 102 SBTypeSynthetic::GetOptions () 103 { 104 if (!IsValid()) 105 return lldb::eTypeOptionNone; 106 return m_opaque_sp->GetOptions(); 107 } 108 109 void 110 SBTypeSynthetic::SetOptions (uint32_t value) 111 { 112 if (!CopyOnWrite_Impl()) 113 return; 114 m_opaque_sp->SetOptions(value); 115 } 116 117 bool 118 SBTypeSynthetic::GetDescription (lldb::SBStream &description, 119 lldb::DescriptionLevel description_level) 120 { 121 if (m_opaque_sp) 122 { 123 description.Printf("%s\n", 124 m_opaque_sp->GetDescription().c_str()); 125 return true; 126 } 127 return false; 128 } 129 130 lldb::SBTypeSynthetic & 131 SBTypeSynthetic::operator = (const lldb::SBTypeSynthetic &rhs) 132 { 133 if (this != &rhs) 134 { 135 m_opaque_sp = rhs.m_opaque_sp; 136 } 137 return *this; 138 } 139 140 bool 141 SBTypeSynthetic::operator == (lldb::SBTypeSynthetic &rhs) 142 { 143 if (IsValid() == false) 144 return !rhs.IsValid(); 145 return m_opaque_sp == rhs.m_opaque_sp; 146 } 147 148 bool 149 SBTypeSynthetic::IsEqualTo (lldb::SBTypeSynthetic &rhs) 150 { 151 if (IsValid() == false) 152 return !rhs.IsValid(); 153 154 if (m_opaque_sp->IsScripted() != rhs.m_opaque_sp->IsScripted()) 155 return false; 156 157 if (IsClassCode() != rhs.IsClassCode()) 158 return false; 159 160 if ( strcmp(GetData(), rhs.GetData()) ) 161 return false; 162 163 return GetOptions() == rhs.GetOptions(); 164 165 } 166 167 bool 168 SBTypeSynthetic::operator != (lldb::SBTypeSynthetic &rhs) 169 { 170 if (IsValid() == false) 171 return !rhs.IsValid(); 172 return m_opaque_sp != rhs.m_opaque_sp; 173 } 174 175 lldb::ScriptedSyntheticChildrenSP 176 SBTypeSynthetic::GetSP () 177 { 178 return m_opaque_sp; 179 } 180 181 void 182 SBTypeSynthetic::SetSP (const lldb::ScriptedSyntheticChildrenSP &TypeSynthetic_impl_sp) 183 { 184 m_opaque_sp = TypeSynthetic_impl_sp; 185 } 186 187 SBTypeSynthetic::SBTypeSynthetic (const lldb::ScriptedSyntheticChildrenSP &TypeSynthetic_impl_sp) : 188 m_opaque_sp(TypeSynthetic_impl_sp) 189 { 190 } 191 192 bool 193 SBTypeSynthetic::CopyOnWrite_Impl() 194 { 195 if (!IsValid()) 196 return false; 197 if (m_opaque_sp.unique()) 198 return true; 199 200 ScriptedSyntheticChildrenSP new_sp(new ScriptedSyntheticChildren(m_opaque_sp->GetOptions(), 201 m_opaque_sp->GetPythonClassName(), 202 m_opaque_sp->GetPythonCode())); 203 204 SetSP(new_sp); 205 206 return true; 207 } 208 209 #endif // LLDB_DISABLE_PYTHON 210