1*fe013be4SDimitry Andric //===-- SBScriptObject.cpp ------------------------------------------------===//
2*fe013be4SDimitry Andric //
3*fe013be4SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*fe013be4SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*fe013be4SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*fe013be4SDimitry Andric //
7*fe013be4SDimitry Andric //===----------------------------------------------------------------------===//
8*fe013be4SDimitry Andric
9*fe013be4SDimitry Andric #include "lldb/API/SBScriptObject.h"
10*fe013be4SDimitry Andric
11*fe013be4SDimitry Andric #include "Utils.h"
12*fe013be4SDimitry Andric
13*fe013be4SDimitry Andric #include "lldb/Interpreter/ScriptObject.h"
14*fe013be4SDimitry Andric #include "lldb/Utility/Instrumentation.h"
15*fe013be4SDimitry Andric
16*fe013be4SDimitry Andric using namespace lldb;
17*fe013be4SDimitry Andric using namespace lldb_private;
18*fe013be4SDimitry Andric
SBScriptObject(const ScriptObjectPtr ptr,lldb::ScriptLanguage lang)19*fe013be4SDimitry Andric SBScriptObject::SBScriptObject(const ScriptObjectPtr ptr,
20*fe013be4SDimitry Andric lldb::ScriptLanguage lang)
21*fe013be4SDimitry Andric : m_opaque_up(std::make_unique<lldb_private::ScriptObject>(ptr, lang)) {
22*fe013be4SDimitry Andric LLDB_INSTRUMENT_VA(this, ptr, lang);
23*fe013be4SDimitry Andric }
24*fe013be4SDimitry Andric
SBScriptObject(const SBScriptObject & rhs)25*fe013be4SDimitry Andric SBScriptObject::SBScriptObject(const SBScriptObject &rhs)
26*fe013be4SDimitry Andric : m_opaque_up(new ScriptObject(nullptr, eScriptLanguageNone)) {
27*fe013be4SDimitry Andric LLDB_INSTRUMENT_VA(this, rhs);
28*fe013be4SDimitry Andric
29*fe013be4SDimitry Andric m_opaque_up = clone(rhs.m_opaque_up);
30*fe013be4SDimitry Andric }
31*fe013be4SDimitry Andric SBScriptObject::~SBScriptObject() = default;
32*fe013be4SDimitry Andric
operator =(const SBScriptObject & rhs)33*fe013be4SDimitry Andric const SBScriptObject &SBScriptObject::operator=(const SBScriptObject &rhs) {
34*fe013be4SDimitry Andric LLDB_INSTRUMENT_VA(this, rhs);
35*fe013be4SDimitry Andric
36*fe013be4SDimitry Andric if (this != &rhs)
37*fe013be4SDimitry Andric m_opaque_up = clone(rhs.m_opaque_up);
38*fe013be4SDimitry Andric return *this;
39*fe013be4SDimitry Andric }
40*fe013be4SDimitry Andric
operator !=(const SBScriptObject & rhs) const41*fe013be4SDimitry Andric bool SBScriptObject::operator!=(const SBScriptObject &rhs) const {
42*fe013be4SDimitry Andric LLDB_INSTRUMENT_VA(this, rhs);
43*fe013be4SDimitry Andric
44*fe013be4SDimitry Andric return !(m_opaque_up == rhs.m_opaque_up);
45*fe013be4SDimitry Andric }
46*fe013be4SDimitry Andric
IsValid() const47*fe013be4SDimitry Andric bool SBScriptObject::IsValid() const {
48*fe013be4SDimitry Andric LLDB_INSTRUMENT_VA(this);
49*fe013be4SDimitry Andric
50*fe013be4SDimitry Andric return this->operator bool();
51*fe013be4SDimitry Andric }
52*fe013be4SDimitry Andric
operator bool() const53*fe013be4SDimitry Andric SBScriptObject::operator bool() const {
54*fe013be4SDimitry Andric LLDB_INSTRUMENT_VA(this);
55*fe013be4SDimitry Andric
56*fe013be4SDimitry Andric return m_opaque_up != nullptr && m_opaque_up->operator bool();
57*fe013be4SDimitry Andric }
58*fe013be4SDimitry Andric
GetPointer() const59*fe013be4SDimitry Andric lldb::ScriptObjectPtr SBScriptObject::GetPointer() const {
60*fe013be4SDimitry Andric LLDB_INSTRUMENT_VA(this);
61*fe013be4SDimitry Andric
62*fe013be4SDimitry Andric return m_opaque_up ? const_cast<void *>(m_opaque_up->GetPointer()) : nullptr;
63*fe013be4SDimitry Andric }
64*fe013be4SDimitry Andric
GetLanguage() const65*fe013be4SDimitry Andric lldb::ScriptLanguage SBScriptObject::GetLanguage() const {
66*fe013be4SDimitry Andric LLDB_INSTRUMENT_VA(this);
67*fe013be4SDimitry Andric
68*fe013be4SDimitry Andric return m_opaque_up ? m_opaque_up->GetLanguage() : eScriptLanguageNone;
69*fe013be4SDimitry Andric }
70*fe013be4SDimitry Andric
ref()71*fe013be4SDimitry Andric ScriptObject &SBScriptObject::ref() {
72*fe013be4SDimitry Andric if (m_opaque_up == nullptr)
73*fe013be4SDimitry Andric m_opaque_up = std::make_unique<ScriptObject>(nullptr, eScriptLanguageNone);
74*fe013be4SDimitry Andric return *m_opaque_up;
75*fe013be4SDimitry Andric }
76*fe013be4SDimitry Andric
ref() const77*fe013be4SDimitry Andric const ScriptObject &SBScriptObject::ref() const {
78*fe013be4SDimitry Andric // This object should already have checked with "IsValid()" prior to calling
79*fe013be4SDimitry Andric // this function. In case you didn't we will assert and die to let you know.
80*fe013be4SDimitry Andric assert(m_opaque_up.get());
81*fe013be4SDimitry Andric return *m_opaque_up;
82*fe013be4SDimitry Andric }
83*fe013be4SDimitry Andric
get()84*fe013be4SDimitry Andric ScriptObject *SBScriptObject::get() { return m_opaque_up.get(); }
85