Coverage Report

Created: 2023-11-11 10:31

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