1 //===-- ValueObjectSyntheticFilter.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/lldb-python.h"
12 #include "lldb/Core/ValueObjectSyntheticFilter.h"
16 // Other libraries and framework includes
18 #include "lldb/Core/ValueObject.h"
19 #include "lldb/DataFormatters/TypeSynthetic.h"
21 using namespace lldb_private;
23 class DummySyntheticFrontEnd : public SyntheticChildrenFrontEnd
26 DummySyntheticFrontEnd(ValueObject &backend) :
27 SyntheticChildrenFrontEnd(backend)
31 CalculateNumChildren()
33 return m_backend.GetNumChildren();
37 GetChildAtIndex (size_t idx)
39 return m_backend.GetChildAtIndex(idx, true);
43 GetIndexOfChildWithName (const ConstString &name)
45 return m_backend.GetIndexOfChildWithName(name);
62 ValueObjectSynthetic::ValueObjectSynthetic (ValueObject &parent, lldb::SyntheticChildrenSP filter) :
67 m_synthetic_children_count(UINT32_MAX),
68 m_parent_type_name(parent.GetTypeName()),
69 m_might_have_children(eLazyBoolCalculate)
71 #ifdef LLDB_CONFIGURATION_DEBUG
72 std::string new_name(parent.GetName().AsCString());
73 new_name += "$$__synth__";
74 SetName (ConstString(new_name.c_str()));
76 SetName(parent.GetName());
82 ValueObjectSynthetic::~ValueObjectSynthetic()
87 ValueObjectSynthetic::GetClangTypeImpl ()
89 return m_parent->GetClangType();
93 ValueObjectSynthetic::GetTypeName()
95 return m_parent->GetTypeName();
99 ValueObjectSynthetic::GetQualifiedTypeName()
101 return m_parent->GetQualifiedTypeName();
105 ValueObjectSynthetic::GetDisplayTypeName()
107 return m_parent->GetDisplayTypeName();
111 ValueObjectSynthetic::CalculateNumChildren()
113 UpdateValueIfNeeded();
114 if (m_synthetic_children_count < UINT32_MAX)
115 return m_synthetic_children_count;
116 return (m_synthetic_children_count = m_synth_filter_ap->CalculateNumChildren());
120 ValueObjectSynthetic::GetDynamicValue (lldb::DynamicValueType valueType)
123 return lldb::ValueObjectSP();
124 if (IsDynamic() && GetDynamicValueType() == valueType)
126 return m_parent->GetDynamicValue(valueType);
130 ValueObjectSynthetic::MightHaveChildren()
132 if (m_might_have_children == eLazyBoolCalculate)
133 m_might_have_children = (m_synth_filter_ap->MightHaveChildren() ? eLazyBoolYes : eLazyBoolNo);
134 return (m_might_have_children == eLazyBoolNo ? false : true);
138 ValueObjectSynthetic::GetByteSize()
140 return m_parent->GetByteSize();
144 ValueObjectSynthetic::GetValueType() const
146 return m_parent->GetValueType();
150 ValueObjectSynthetic::CreateSynthFilter ()
152 m_synth_filter_ap = (m_synth_sp->GetFrontEnd(*m_parent));
153 if (!m_synth_filter_ap.get())
154 m_synth_filter_ap.reset(new DummySyntheticFrontEnd(*m_parent));
158 ValueObjectSynthetic::UpdateValue ()
160 SetValueIsValid (false);
163 if (!m_parent->UpdateValueIfNeeded(false))
165 // our parent could not update.. as we are meaningless without a parent, just stop
166 if (m_parent->GetError().Fail())
167 m_error = m_parent->GetError();
171 // regenerate the synthetic filter if our typename changes
172 // <rdar://problem/12424824>
173 ConstString new_parent_type_name = m_parent->GetTypeName();
174 if (new_parent_type_name != m_parent_type_name)
176 m_parent_type_name = new_parent_type_name;
180 // let our backend do its update
181 if (m_synth_filter_ap->Update() == false)
183 // filter said that cached values are stale
184 m_children_byindex.clear();
185 m_name_toindex.clear();
186 // usually, an object's value can change but this does not alter its children count
187 // for a synthetic VO that might indeed happen, so we need to tell the upper echelons
188 // that they need to come back to us asking for children
189 m_children_count_valid = false;
190 m_synthetic_children_count = UINT32_MAX;
191 m_might_have_children = eLazyBoolCalculate;
196 SetValueIsValid(true);
201 ValueObjectSynthetic::GetChildAtIndex (size_t idx, bool can_create)
203 UpdateValueIfNeeded();
205 ByIndexIterator iter = m_children_byindex.find(idx);
207 if (iter == m_children_byindex.end())
209 if (can_create && m_synth_filter_ap.get() != NULL)
211 lldb::ValueObjectSP synth_guy = m_synth_filter_ap->GetChildAtIndex (idx);
214 m_children_byindex[idx]= synth_guy.get();
218 return lldb::ValueObjectSP();
221 return iter->second->GetSP();
225 ValueObjectSynthetic::GetChildMemberWithName (const ConstString &name, bool can_create)
227 UpdateValueIfNeeded();
229 uint32_t index = GetIndexOfChildWithName(name);
231 if (index == UINT32_MAX)
232 return lldb::ValueObjectSP();
234 return GetChildAtIndex(index, can_create);
238 ValueObjectSynthetic::GetIndexOfChildWithName (const ConstString &name)
240 UpdateValueIfNeeded();
242 NameToIndexIterator iter = m_name_toindex.find(name.GetCString());
244 if (iter == m_name_toindex.end() && m_synth_filter_ap.get() != NULL)
246 uint32_t index = m_synth_filter_ap->GetIndexOfChildWithName (name);
247 if (index == UINT32_MAX)
249 m_name_toindex[name.GetCString()] = index;
252 else if (iter == m_name_toindex.end() && m_synth_filter_ap.get() == NULL)
254 else /*if (iter != m_name_toindex.end())*/
259 ValueObjectSynthetic::IsInScope ()
261 return m_parent->IsInScope();
265 ValueObjectSynthetic::GetNonSyntheticValue ()
267 return m_parent->GetSP();
271 ValueObjectSynthetic::CopyParentData ()
273 m_value = m_parent->GetValue();
274 ExecutionContext exe_ctx (GetExecutionContextRef());
275 m_error = m_value.GetValueAsData (&exe_ctx, m_data, 0, GetModule().get());