1//===-- SBSymbolContextList.cpp ---------------------------------*- C++ -*-===//
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 "SBReproducerPrivate.h"
11#include "Utils.h"
12#include "lldb/API/SBStream.h"
13#include "lldb/Symbol/SymbolContext.h"
14
15using namespace lldb;
16using namespace lldb_private;
17
18SBSymbolContextList::SBSymbolContextList()
19    : m_opaque_up(new SymbolContextList()) {
20  LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBSymbolContextList);
21}
22
23SBSymbolContextList::SBSymbolContextList(const SBSymbolContextList &rhs)
24    : m_opaque_up() {
25  LLDB_RECORD_CONSTRUCTOR(SBSymbolContextList,
26                          (const lldb::SBSymbolContextList &), rhs);
27
28  m_opaque_up = clone(rhs.m_opaque_up);
29}
30
31SBSymbolContextList::~SBSymbolContextList() {}
32
33const SBSymbolContextList &SBSymbolContextList::
34operator=(const SBSymbolContextList &rhs) {
35  LLDB_RECORD_METHOD(
36      const lldb::SBSymbolContextList &,
37      SBSymbolContextList, operator=,(const lldb::SBSymbolContextList &), rhs);
38
39  if (this != &rhs)
40    m_opaque_up = clone(rhs.m_opaque_up);
41  return LLDB_RECORD_RESULT(*this);
42}
43
44uint32_t SBSymbolContextList::GetSize() const {
45  LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBSymbolContextList, GetSize);
46
47  if (m_opaque_up)
48    return m_opaque_up->GetSize();
49  return 0;
50}
51
52SBSymbolContext SBSymbolContextList::GetContextAtIndex(uint32_t idx) {
53  LLDB_RECORD_METHOD(lldb::SBSymbolContext, SBSymbolContextList,
54                     GetContextAtIndex, (uint32_t), idx);
55
56  SBSymbolContext sb_sc;
57  if (m_opaque_up) {
58    SymbolContext sc;
59    if (m_opaque_up->GetContextAtIndex(idx, sc)) {
60      sb_sc.SetSymbolContext(&sc);
61    }
62  }
63  return LLDB_RECORD_RESULT(sb_sc);
64}
65
66void SBSymbolContextList::Clear() {
67  LLDB_RECORD_METHOD_NO_ARGS(void, SBSymbolContextList, Clear);
68
69  if (m_opaque_up)
70    m_opaque_up->Clear();
71}
72
73void SBSymbolContextList::Append(SBSymbolContext &sc) {
74  LLDB_RECORD_METHOD(void, SBSymbolContextList, Append,
75                     (lldb::SBSymbolContext &), sc);
76
77  if (sc.IsValid() && m_opaque_up.get())
78    m_opaque_up->Append(*sc);
79}
80
81void SBSymbolContextList::Append(SBSymbolContextList &sc_list) {
82  LLDB_RECORD_METHOD(void, SBSymbolContextList, Append,
83                     (lldb::SBSymbolContextList &), sc_list);
84
85  if (sc_list.IsValid() && m_opaque_up.get())
86    m_opaque_up->Append(*sc_list);
87}
88
89bool SBSymbolContextList::IsValid() const {
90  LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBSymbolContextList, IsValid);
91  return this->operator bool();
92}
93SBSymbolContextList::operator bool() const {
94  LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBSymbolContextList, operator bool);
95
96  return m_opaque_up != nullptr;
97}
98
99lldb_private::SymbolContextList *SBSymbolContextList::operator->() const {
100  return m_opaque_up.get();
101}
102
103lldb_private::SymbolContextList &SBSymbolContextList::operator*() const {
104  assert(m_opaque_up.get());
105  return *m_opaque_up;
106}
107
108bool SBSymbolContextList::GetDescription(lldb::SBStream &description) {
109  LLDB_RECORD_METHOD(bool, SBSymbolContextList, GetDescription,
110                     (lldb::SBStream &), description);
111
112  Stream &strm = description.ref();
113  if (m_opaque_up)
114    m_opaque_up->GetDescription(&strm, lldb::eDescriptionLevelFull, nullptr);
115  return true;
116}
117
118namespace lldb_private {
119namespace repro {
120
121template <>
122void RegisterMethods<SBSymbolContextList>(Registry &R) {
123  LLDB_REGISTER_CONSTRUCTOR(SBSymbolContextList, ());
124  LLDB_REGISTER_CONSTRUCTOR(SBSymbolContextList,
125                            (const lldb::SBSymbolContextList &));
126  LLDB_REGISTER_METHOD(
127      const lldb::SBSymbolContextList &,
128      SBSymbolContextList, operator=,(const lldb::SBSymbolContextList &));
129  LLDB_REGISTER_METHOD_CONST(uint32_t, SBSymbolContextList, GetSize, ());
130  LLDB_REGISTER_METHOD(lldb::SBSymbolContext, SBSymbolContextList,
131                       GetContextAtIndex, (uint32_t));
132  LLDB_REGISTER_METHOD(void, SBSymbolContextList, Clear, ());
133  LLDB_REGISTER_METHOD(void, SBSymbolContextList, Append,
134                       (lldb::SBSymbolContext &));
135  LLDB_REGISTER_METHOD(void, SBSymbolContextList, Append,
136                       (lldb::SBSymbolContextList &));
137  LLDB_REGISTER_METHOD_CONST(bool, SBSymbolContextList, IsValid, ());
138  LLDB_REGISTER_METHOD_CONST(bool, SBSymbolContextList, operator bool, ());
139  LLDB_REGISTER_METHOD(bool, SBSymbolContextList, GetDescription,
140                       (lldb::SBStream &));
141}
142
143}
144}
145