[lldb][dwarf] Compute fully qualified names on simplified template names with DWARFT...
[llvm-project.git] / lldb / source / API / SBDeclaration.cpp
blob5b7def09b5ccfa7efd27e11b30a596ddc59c1801
1 //===-- SBDeclaration.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 //===----------------------------------------------------------------------===//
9 #include "lldb/API/SBDeclaration.h"
10 #include "Utils.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"
17 #include <climits>
19 using namespace lldb;
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) {
31 if (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);
38 if (this != &rhs)
39 m_opaque_up = clone(rhs.m_opaque_up);
40 return *this;
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());
67 return sb_file_spec;
70 uint32_t SBDeclaration::GetLine() const {
71 LLDB_INSTRUMENT_VA(this);
73 uint32_t line = 0;
74 if (m_opaque_up)
75 line = m_opaque_up->GetLine();
78 return line;
81 uint32_t SBDeclaration::GetColumn() const {
82 LLDB_INSTRUMENT_VA(this);
84 if (m_opaque_up)
85 return m_opaque_up->GetColumn();
86 return 0;
89 void SBDeclaration::SetFileSpec(lldb::SBFileSpec filespec) {
90 LLDB_INSTRUMENT_VA(this, filespec);
92 if (filespec.IsValid())
93 ref().SetFile(filespec.ref());
94 else
95 ref().SetFile(FileSpec());
97 void SBDeclaration::SetLine(uint32_t line) {
98 LLDB_INSTRUMENT_VA(this, line);
100 ref().SetLine(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>();
140 return *m_opaque_up;
143 const lldb_private::Declaration &SBDeclaration::ref() const {
144 return *m_opaque_up;
147 bool SBDeclaration::GetDescription(SBStream &description) {
148 LLDB_INSTRUMENT_VA(this, description);
150 Stream &strm = description.ref();
152 if (m_opaque_up) {
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());
156 if (GetColumn() > 0)
157 strm.Printf(":%u", GetColumn());
158 } else
159 strm.PutCString("No value");
161 return true;
164 lldb_private::Declaration *SBDeclaration::get() { return m_opaque_up.get(); }