1 //===-- SBDeclaration.cpp ----------------------------------------*- C++-*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/API/SBDeclaration.h"
10 #include "SBReproducerPrivate.h"
12 #include "lldb/API/SBStream.h"
13 #include "lldb/Host/PosixApi.h"
14 #include "lldb/Symbol/Declaration.h"
15 #include "lldb/Utility/Stream.h"
20 using namespace lldb_private
;
22 SBDeclaration::SBDeclaration() : m_opaque_up() {
23 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBDeclaration
);
26 SBDeclaration::SBDeclaration(const SBDeclaration
&rhs
) : m_opaque_up() {
27 LLDB_RECORD_CONSTRUCTOR(SBDeclaration
, (const lldb::SBDeclaration
&), rhs
);
29 m_opaque_up
= clone(rhs
.m_opaque_up
);
32 SBDeclaration::SBDeclaration(const lldb_private::Declaration
*lldb_object_ptr
)
35 m_opaque_up
= std::make_unique
<Declaration
>(*lldb_object_ptr
);
38 const SBDeclaration
&SBDeclaration::operator=(const SBDeclaration
&rhs
) {
39 LLDB_RECORD_METHOD(const lldb::SBDeclaration
&,
40 SBDeclaration
, operator=,(const lldb::SBDeclaration
&),
44 m_opaque_up
= clone(rhs
.m_opaque_up
);
45 return LLDB_RECORD_RESULT(*this);
48 void SBDeclaration::SetDeclaration(
49 const lldb_private::Declaration
&lldb_object_ref
) {
50 ref() = lldb_object_ref
;
53 SBDeclaration::~SBDeclaration() {}
55 bool SBDeclaration::IsValid() const {
56 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBDeclaration
, IsValid
);
57 return this->operator bool();
59 SBDeclaration::operator bool() const {
60 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBDeclaration
, operator bool);
62 return m_opaque_up
.get() && m_opaque_up
->IsValid();
65 SBFileSpec
SBDeclaration::GetFileSpec() const {
66 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBFileSpec
, SBDeclaration
,
70 SBFileSpec sb_file_spec
;
71 if (m_opaque_up
.get() && m_opaque_up
->GetFile())
72 sb_file_spec
.SetFileSpec(m_opaque_up
->GetFile());
75 return LLDB_RECORD_RESULT(sb_file_spec
);
78 uint32_t SBDeclaration::GetLine() const {
79 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBDeclaration
, GetLine
);
84 line
= m_opaque_up
->GetLine();
90 uint32_t SBDeclaration::GetColumn() const {
91 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBDeclaration
, GetColumn
);
94 return m_opaque_up
->GetColumn();
98 void SBDeclaration::SetFileSpec(lldb::SBFileSpec filespec
) {
99 LLDB_RECORD_METHOD(void, SBDeclaration
, SetFileSpec
, (lldb::SBFileSpec
),
102 if (filespec
.IsValid())
103 ref().SetFile(filespec
.ref());
105 ref().SetFile(FileSpec());
107 void SBDeclaration::SetLine(uint32_t line
) {
108 LLDB_RECORD_METHOD(void, SBDeclaration
, SetLine
, (uint32_t), line
);
113 void SBDeclaration::SetColumn(uint32_t column
) {
114 LLDB_RECORD_METHOD(void, SBDeclaration
, SetColumn
, (uint32_t), column
);
116 ref().SetColumn(column
);
119 bool SBDeclaration::operator==(const SBDeclaration
&rhs
) const {
120 LLDB_RECORD_METHOD_CONST(
121 bool, SBDeclaration
, operator==,(const lldb::SBDeclaration
&), rhs
);
123 lldb_private::Declaration
*lhs_ptr
= m_opaque_up
.get();
124 lldb_private::Declaration
*rhs_ptr
= rhs
.m_opaque_up
.get();
126 if (lhs_ptr
&& rhs_ptr
)
127 return lldb_private::Declaration::Compare(*lhs_ptr
, *rhs_ptr
) == 0;
129 return lhs_ptr
== rhs_ptr
;
132 bool SBDeclaration::operator!=(const SBDeclaration
&rhs
) const {
133 LLDB_RECORD_METHOD_CONST(
134 bool, SBDeclaration
, operator!=,(const lldb::SBDeclaration
&), rhs
);
136 lldb_private::Declaration
*lhs_ptr
= m_opaque_up
.get();
137 lldb_private::Declaration
*rhs_ptr
= rhs
.m_opaque_up
.get();
139 if (lhs_ptr
&& rhs_ptr
)
140 return lldb_private::Declaration::Compare(*lhs_ptr
, *rhs_ptr
) != 0;
142 return lhs_ptr
!= rhs_ptr
;
145 const lldb_private::Declaration
*SBDeclaration::operator->() const {
146 return m_opaque_up
.get();
149 lldb_private::Declaration
&SBDeclaration::ref() {
150 if (m_opaque_up
== nullptr)
151 m_opaque_up
.reset(new lldb_private::Declaration());
155 const lldb_private::Declaration
&SBDeclaration::ref() const {
159 bool SBDeclaration::GetDescription(SBStream
&description
) {
160 LLDB_RECORD_METHOD(bool, SBDeclaration
, GetDescription
, (lldb::SBStream
&),
163 Stream
&strm
= description
.ref();
166 char file_path
[PATH_MAX
* 2];
167 m_opaque_up
->GetFile().GetPath(file_path
, sizeof(file_path
));
168 strm
.Printf("%s:%u", file_path
, GetLine());
170 strm
.Printf(":%u", GetColumn());
172 strm
.PutCString("No value");
177 lldb_private::Declaration
*SBDeclaration::get() { return m_opaque_up
.get(); }
179 namespace lldb_private
{
183 void RegisterMethods
<SBDeclaration
>(Registry
&R
) {
184 LLDB_REGISTER_CONSTRUCTOR(SBDeclaration
, ());
185 LLDB_REGISTER_CONSTRUCTOR(SBDeclaration
, (const lldb::SBDeclaration
&));
186 LLDB_REGISTER_METHOD(
187 const lldb::SBDeclaration
&,
188 SBDeclaration
, operator=,(const lldb::SBDeclaration
&));
189 LLDB_REGISTER_METHOD_CONST(bool, SBDeclaration
, IsValid
, ());
190 LLDB_REGISTER_METHOD_CONST(bool, SBDeclaration
, operator bool, ());
191 LLDB_REGISTER_METHOD_CONST(lldb::SBFileSpec
, SBDeclaration
, GetFileSpec
,
193 LLDB_REGISTER_METHOD_CONST(uint32_t, SBDeclaration
, GetLine
, ());
194 LLDB_REGISTER_METHOD_CONST(uint32_t, SBDeclaration
, GetColumn
, ());
195 LLDB_REGISTER_METHOD(void, SBDeclaration
, SetFileSpec
, (lldb::SBFileSpec
));
196 LLDB_REGISTER_METHOD(void, SBDeclaration
, SetLine
, (uint32_t));
197 LLDB_REGISTER_METHOD(void, SBDeclaration
, SetColumn
, (uint32_t));
198 LLDB_REGISTER_METHOD_CONST(
199 bool, SBDeclaration
, operator==,(const lldb::SBDeclaration
&));
200 LLDB_REGISTER_METHOD_CONST(
201 bool, SBDeclaration
, operator!=,(const lldb::SBDeclaration
&));
202 LLDB_REGISTER_METHOD(bool, SBDeclaration
, GetDescription
,