1 //===-- ValueObjectCast.cpp -------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Core/ValueObjectCast.h"
12 #include "lldb/Core/Value.h"
13 #include "lldb/Core/ValueObject.h"
14 #include "lldb/Symbol/CompilerType.h"
15 #include "lldb/Target/ExecutionContext.h"
16 #include "lldb/Utility/Scalar.h"
17 #include "lldb/Utility/Status.h"
19 namespace lldb_private {
23 using namespace lldb_private;
25 lldb::ValueObjectSP ValueObjectCast::Create(ValueObject &parent,
26 const ConstString &name,
27 const CompilerType &cast_type) {
28 ValueObjectCast *cast_valobj_ptr =
29 new ValueObjectCast(parent, name, cast_type);
30 return cast_valobj_ptr->GetSP();
33 ValueObjectCast::ValueObjectCast(ValueObject &parent, const ConstString &name,
34 const CompilerType &cast_type)
35 : ValueObject(parent), m_cast_type(cast_type) {
37 // m_value.SetContext (Value::eContextTypeClangType,
38 // cast_type.GetOpaqueQualType());
39 m_value.SetCompilerType(cast_type);
42 ValueObjectCast::~ValueObjectCast() {}
44 CompilerType ValueObjectCast::GetCompilerTypeImpl() { return m_cast_type; }
46 size_t ValueObjectCast::CalculateNumChildren(uint32_t max) {
47 ExecutionContext exe_ctx(GetExecutionContextRef());
48 auto children_count = GetCompilerType().GetNumChildren(
50 return children_count <= max ? children_count : max;
53 uint64_t ValueObjectCast::GetByteSize() {
54 ExecutionContext exe_ctx(GetExecutionContextRef());
55 return m_value.GetValueByteSize(nullptr, &exe_ctx);
58 lldb::ValueType ValueObjectCast::GetValueType() const {
59 // Let our parent answer global, local, argument, etc...
60 return m_parent->GetValueType();
63 bool ValueObjectCast::UpdateValue() {
64 SetValueIsValid(false);
67 if (m_parent->UpdateValueIfNeeded(false)) {
68 Value old_value(m_value);
69 m_update_point.SetUpdated();
70 m_value = m_parent->GetValue();
71 CompilerType compiler_type(GetCompilerType());
72 // m_value.SetContext (Value::eContextTypeClangType, compiler_type);
73 m_value.SetCompilerType(compiler_type);
74 SetAddressTypeOfChildren(m_parent->GetAddressTypeOfChildren());
75 if (!CanProvideValue()) {
76 // this value object represents an aggregate type whose children have
77 // values, but this object does not. So we say we are changed if our
78 // location has changed.
79 SetValueDidChange(m_value.GetValueType() != old_value.GetValueType() ||
80 m_value.GetScalar() != old_value.GetScalar());
82 ExecutionContext exe_ctx(GetExecutionContextRef());
83 m_error = m_value.GetValueAsData(&exe_ctx, m_data, 0, GetModule().get());
84 SetValueDidChange(m_parent->GetValueDidChange());
88 // The dynamic value failed to get an error, pass the error along
89 if (m_error.Success() && m_parent->GetError().Fail())
90 m_error = m_parent->GetError();
91 SetValueIsValid(false);
95 bool ValueObjectCast::IsInScope() { return m_parent->IsInScope(); }