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