1 //===-- SBSymbolContextList.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/SBSymbolContextList.h"
10 #include "lldb/Utility/ReproducerInstrumentation.h"
11 #include "Utils.h"
12 #include "lldb/API/SBStream.h"
13 #include "lldb/Symbol/SymbolContext.h"
14 
15 using namespace lldb;
16 using namespace lldb_private;
17 
18 SBSymbolContextList::SBSymbolContextList()
19     : m_opaque_up(new SymbolContextList()) {
20   LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBSymbolContextList);
21 }
22 
23 SBSymbolContextList::SBSymbolContextList(const SBSymbolContextList &rhs) {
24   LLDB_RECORD_CONSTRUCTOR(SBSymbolContextList,
25                           (const lldb::SBSymbolContextList &), rhs);
26 
27   m_opaque_up = clone(rhs.m_opaque_up);
28 }
29 
30 SBSymbolContextList::~SBSymbolContextList() = default;
31 
32 const SBSymbolContextList &SBSymbolContextList::
33 operator=(const SBSymbolContextList &rhs) {
34   LLDB_RECORD_METHOD(
35       const lldb::SBSymbolContextList &,
36       SBSymbolContextList, operator=,(const lldb::SBSymbolContextList &), rhs);
37 
38   if (this != &rhs)
39     m_opaque_up = clone(rhs.m_opaque_up);
40   return *this;
41 }
42 
43 uint32_t SBSymbolContextList::GetSize() const {
44   LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBSymbolContextList, GetSize);
45 
46   if (m_opaque_up)
47     return m_opaque_up->GetSize();
48   return 0;
49 }
50 
51 SBSymbolContext SBSymbolContextList::GetContextAtIndex(uint32_t idx) {
52   LLDB_RECORD_METHOD(lldb::SBSymbolContext, SBSymbolContextList,
53                      GetContextAtIndex, (uint32_t), idx);
54 
55   SBSymbolContext sb_sc;
56   if (m_opaque_up) {
57     SymbolContext sc;
58     if (m_opaque_up->GetContextAtIndex(idx, sc))
59       sb_sc = sc;
60   }
61   return sb_sc;
62 }
63 
64 void SBSymbolContextList::Clear() {
65   LLDB_RECORD_METHOD_NO_ARGS(void, SBSymbolContextList, Clear);
66 
67   if (m_opaque_up)
68     m_opaque_up->Clear();
69 }
70 
71 void SBSymbolContextList::Append(SBSymbolContext &sc) {
72   LLDB_RECORD_METHOD(void, SBSymbolContextList, Append,
73                      (lldb::SBSymbolContext &), sc);
74 
75   if (sc.IsValid() && m_opaque_up.get())
76     m_opaque_up->Append(*sc);
77 }
78 
79 void SBSymbolContextList::Append(SBSymbolContextList &sc_list) {
80   LLDB_RECORD_METHOD(void, SBSymbolContextList, Append,
81                      (lldb::SBSymbolContextList &), sc_list);
82 
83   if (sc_list.IsValid() && m_opaque_up.get())
84     m_opaque_up->Append(*sc_list);
85 }
86 
87 bool SBSymbolContextList::IsValid() const {
88   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBSymbolContextList, IsValid);
89   return this->operator bool();
90 }
91 SBSymbolContextList::operator bool() const {
92   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBSymbolContextList, operator bool);
93 
94   return m_opaque_up != nullptr;
95 }
96 
97 lldb_private::SymbolContextList *SBSymbolContextList::operator->() const {
98   return m_opaque_up.get();
99 }
100 
101 lldb_private::SymbolContextList &SBSymbolContextList::operator*() const {
102   assert(m_opaque_up.get());
103   return *m_opaque_up;
104 }
105 
106 bool SBSymbolContextList::GetDescription(lldb::SBStream &description) {
107   LLDB_RECORD_METHOD(bool, SBSymbolContextList, GetDescription,
108                      (lldb::SBStream &), description);
109 
110   Stream &strm = description.ref();
111   if (m_opaque_up)
112     m_opaque_up->GetDescription(&strm, lldb::eDescriptionLevelFull, nullptr);
113   return true;
114 }
115