1 //===-- SBDeclaration.cpp -------------------------------------------------===//
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"
11 #include "lldb/API/SBStream.h"
12 #include "lldb/Core/Declaration.h"
13 #include "lldb/Host/PosixApi.h"
14 #include "lldb/Utility/Instrumentation.h"
15 #include "lldb/Utility/Stream.h"
20 using namespace lldb_private
;
22 SBDeclaration::SBDeclaration() { LLDB_INSTRUMENT_VA(this); }
24 SBDeclaration::SBDeclaration(const SBDeclaration
&rhs
) {
25 LLDB_INSTRUMENT_VA(this, rhs
);
27 m_opaque_up
= clone(rhs
.m_opaque_up
);
30 SBDeclaration::SBDeclaration(const lldb_private::Declaration
*lldb_object_ptr
) {
32 m_opaque_up
= std::make_unique
<Declaration
>(*lldb_object_ptr
);
35 const SBDeclaration
&SBDeclaration::operator=(const SBDeclaration
&rhs
) {
36 LLDB_INSTRUMENT_VA(this, rhs
);
39 m_opaque_up
= clone(rhs
.m_opaque_up
);
43 void SBDeclaration::SetDeclaration(
44 const lldb_private::Declaration
&lldb_object_ref
) {
45 ref() = lldb_object_ref
;
48 SBDeclaration::~SBDeclaration() = default;
50 bool SBDeclaration::IsValid() const {
51 LLDB_INSTRUMENT_VA(this);
52 return this->operator bool();
54 SBDeclaration::operator bool() const {
55 LLDB_INSTRUMENT_VA(this);
57 return m_opaque_up
.get() && m_opaque_up
->IsValid();
60 SBFileSpec
SBDeclaration::GetFileSpec() const {
61 LLDB_INSTRUMENT_VA(this);
63 SBFileSpec sb_file_spec
;
64 if (m_opaque_up
.get() && m_opaque_up
->GetFile())
65 sb_file_spec
.SetFileSpec(m_opaque_up
->GetFile());
70 uint32_t SBDeclaration::GetLine() const {
71 LLDB_INSTRUMENT_VA(this);
75 line
= m_opaque_up
->GetLine();
81 uint32_t SBDeclaration::GetColumn() const {
82 LLDB_INSTRUMENT_VA(this);
85 return m_opaque_up
->GetColumn();
89 void SBDeclaration::SetFileSpec(lldb::SBFileSpec filespec
) {
90 LLDB_INSTRUMENT_VA(this, filespec
);
92 if (filespec
.IsValid())
93 ref().SetFile(filespec
.ref());
95 ref().SetFile(FileSpec());
97 void SBDeclaration::SetLine(uint32_t line
) {
98 LLDB_INSTRUMENT_VA(this, line
);
103 void SBDeclaration::SetColumn(uint32_t column
) {
104 LLDB_INSTRUMENT_VA(this, column
);
106 ref().SetColumn(column
);
109 bool SBDeclaration::operator==(const SBDeclaration
&rhs
) const {
110 LLDB_INSTRUMENT_VA(this, rhs
);
112 lldb_private::Declaration
*lhs_ptr
= m_opaque_up
.get();
113 lldb_private::Declaration
*rhs_ptr
= rhs
.m_opaque_up
.get();
115 if (lhs_ptr
&& rhs_ptr
)
116 return lldb_private::Declaration::Compare(*lhs_ptr
, *rhs_ptr
) == 0;
118 return lhs_ptr
== rhs_ptr
;
121 bool SBDeclaration::operator!=(const SBDeclaration
&rhs
) const {
122 LLDB_INSTRUMENT_VA(this, rhs
);
124 lldb_private::Declaration
*lhs_ptr
= m_opaque_up
.get();
125 lldb_private::Declaration
*rhs_ptr
= rhs
.m_opaque_up
.get();
127 if (lhs_ptr
&& rhs_ptr
)
128 return lldb_private::Declaration::Compare(*lhs_ptr
, *rhs_ptr
) != 0;
130 return lhs_ptr
!= rhs_ptr
;
133 const lldb_private::Declaration
*SBDeclaration::operator->() const {
134 return m_opaque_up
.get();
137 lldb_private::Declaration
&SBDeclaration::ref() {
138 if (m_opaque_up
== nullptr)
139 m_opaque_up
= std::make_unique
<lldb_private::Declaration
>();
143 const lldb_private::Declaration
&SBDeclaration::ref() const {
147 bool SBDeclaration::GetDescription(SBStream
&description
) {
148 LLDB_INSTRUMENT_VA(this, description
);
150 Stream
&strm
= description
.ref();
153 char file_path
[PATH_MAX
* 2];
154 m_opaque_up
->GetFile().GetPath(file_path
, sizeof(file_path
));
155 strm
.Printf("%s:%u", file_path
, GetLine());
157 strm
.Printf(":%u", GetColumn());
159 strm
.PutCString("No value");
164 lldb_private::Declaration
*SBDeclaration::get() { return m_opaque_up
.get(); }