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