1//===-- SBScriptObject.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/SBScriptObject.h"
10
11#include "Utils.h"
12
13#include "lldb/Interpreter/ScriptObject.h"
14#include "lldb/Utility/Instrumentation.h"
15
16using namespace lldb;
17using namespace lldb_private;
18
19SBScriptObject::SBScriptObject(const ScriptObjectPtr ptr,
20 lldb::ScriptLanguage lang)
21 : m_opaque_up(std::make_unique<lldb_private::ScriptObject>(args: ptr, args&: lang)) {
22 LLDB_INSTRUMENT_VA(this, ptr, lang);
23}
24
25SBScriptObject::SBScriptObject(const SBScriptObject &rhs)
26 : m_opaque_up(new ScriptObject(nullptr, eScriptLanguageNone)) {
27 LLDB_INSTRUMENT_VA(this, rhs);
28
29 m_opaque_up = clone(src: rhs.m_opaque_up);
30}
31SBScriptObject::~SBScriptObject() = default;
32
33const SBScriptObject &SBScriptObject::operator=(const SBScriptObject &rhs) {
34 LLDB_INSTRUMENT_VA(this, rhs);
35
36 if (this != &rhs)
37 m_opaque_up = clone(src: rhs.m_opaque_up);
38 return *this;
39}
40
41bool SBScriptObject::operator!=(const SBScriptObject &rhs) const {
42 LLDB_INSTRUMENT_VA(this, rhs);
43
44 return !(m_opaque_up == rhs.m_opaque_up);
45}
46
47bool SBScriptObject::IsValid() const {
48 LLDB_INSTRUMENT_VA(this);
49
50 return this->operator bool();
51}
52
53SBScriptObject::operator bool() const {
54 LLDB_INSTRUMENT_VA(this);
55
56 return m_opaque_up != nullptr && m_opaque_up->operator bool();
57}
58
59lldb::ScriptObjectPtr SBScriptObject::GetPointer() const {
60 LLDB_INSTRUMENT_VA(this);
61
62 return m_opaque_up ? const_cast<void *>(m_opaque_up->GetPointer()) : nullptr;
63}
64
65lldb::ScriptLanguage SBScriptObject::GetLanguage() const {
66 LLDB_INSTRUMENT_VA(this);
67
68 return m_opaque_up ? m_opaque_up->GetLanguage() : eScriptLanguageNone;
69}
70
71ScriptObject &SBScriptObject::ref() {
72 if (m_opaque_up == nullptr)
73 m_opaque_up = std::make_unique<ScriptObject>(args: nullptr, args: eScriptLanguageNone);
74 return *m_opaque_up;
75}
76
77const ScriptObject &SBScriptObject::ref() const {
78 // This object should already have checked with "IsValid()" prior to calling
79 // this function. In case you didn't we will assert and die to let you know.
80 assert(m_opaque_up.get());
81 return *m_opaque_up;
82}
83
84ScriptObject *SBScriptObject::get() { return m_opaque_up.get(); }
85

source code of lldb/source/API/SBScriptObject.cpp