1 //===-- SBScriptObject.cpp ------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/API/SBScriptObject.h"
13 #include "lldb/Interpreter/ScriptObject.h"
14 #include "lldb/Utility/Instrumentation.h"
17 using namespace lldb_private
;
19 SBScriptObject::SBScriptObject(const ScriptObjectPtr ptr
,
20 lldb::ScriptLanguage lang
)
21 : m_opaque_up(std::make_unique
<lldb_private::ScriptObject
>(ptr
, lang
)) {
22 LLDB_INSTRUMENT_VA(this, ptr
, lang
);
25 SBScriptObject::SBScriptObject(const SBScriptObject
&rhs
)
26 : m_opaque_up(new ScriptObject(nullptr, eScriptLanguageNone
)) {
27 LLDB_INSTRUMENT_VA(this, rhs
);
29 m_opaque_up
= clone(rhs
.m_opaque_up
);
31 SBScriptObject::~SBScriptObject() = default;
33 const SBScriptObject
&SBScriptObject::operator=(const SBScriptObject
&rhs
) {
34 LLDB_INSTRUMENT_VA(this, rhs
);
37 m_opaque_up
= clone(rhs
.m_opaque_up
);
41 bool SBScriptObject::operator!=(const SBScriptObject
&rhs
) const {
42 LLDB_INSTRUMENT_VA(this, rhs
);
44 return !(m_opaque_up
== rhs
.m_opaque_up
);
47 bool SBScriptObject::IsValid() const {
48 LLDB_INSTRUMENT_VA(this);
50 return this->operator bool();
53 SBScriptObject::operator bool() const {
54 LLDB_INSTRUMENT_VA(this);
56 return m_opaque_up
!= nullptr && m_opaque_up
->operator bool();
59 lldb::ScriptObjectPtr
SBScriptObject::GetPointer() const {
60 LLDB_INSTRUMENT_VA(this);
62 return m_opaque_up
? const_cast<void *>(m_opaque_up
->GetPointer()) : nullptr;
65 lldb::ScriptLanguage
SBScriptObject::GetLanguage() const {
66 LLDB_INSTRUMENT_VA(this);
68 return m_opaque_up
? m_opaque_up
->GetLanguage() : eScriptLanguageNone
;
71 ScriptObject
&SBScriptObject::ref() {
72 if (m_opaque_up
== nullptr)
73 m_opaque_up
= std::make_unique
<ScriptObject
>(nullptr, eScriptLanguageNone
);
77 const 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());
84 ScriptObject
*SBScriptObject::get() { return m_opaque_up
.get(); }