1 //===-- TypeSynthetic.h -------------------------------------------*- 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 #ifndef lldb_TypeSynthetic_h_
11 #define lldb_TypeSynthetic_h_
20 // Other libraries and framework includes
23 #include "lldb/lldb-public.h"
24 #include "lldb/lldb-enumerations.h"
26 #include "lldb/Core/ValueObject.h"
28 namespace lldb_private {
29 class SyntheticChildrenFrontEnd
32 ValueObject &m_backend;
48 SyntheticChildrenFrontEnd (ValueObject &backend) :
54 ~SyntheticChildrenFrontEnd ()
59 CalculateNumChildren () = 0;
61 virtual lldb::ValueObjectSP
62 GetChildAtIndex (size_t idx) = 0;
65 GetIndexOfChildWithName (const ConstString &name) = 0;
67 // this function is assumed to always succeed and it if fails, the front-end should know to deal
68 // with it in the correct way (most probably, by refusing to return any children)
69 // the return value of Update() should actually be interpreted as "ValueObjectSyntheticFilter cache is good/bad"
70 // if =true, ValueObjectSyntheticFilter is allowed to use the children it fetched previously and cached
71 // if =false, ValueObjectSyntheticFilter must throw away its cache, and query again for children
75 // if this function returns false, then CalculateNumChildren() MUST return 0 since UI frontends
76 // might validly decide not to inquire for children given a false return value from this call
77 // if it returns true, then CalculateNumChildren() can return any number >= 0 (0 being valid)
78 // it should if at all possible be more efficient than CalculateNumChildren()
80 MightHaveChildren () = 0;
82 // if this function returns a non-null ValueObject, then the returned ValueObject will stand
83 // for this ValueObject whenever a "value" request is made to this ValueObject
84 virtual lldb::ValueObjectSP
85 GetSyntheticValue () { return nullptr; }
87 typedef std::shared_ptr<SyntheticChildrenFrontEnd> SharedPointer;
88 typedef std::unique_ptr<SyntheticChildrenFrontEnd> AutoPointer;
92 CreateValueObjectFromExpression (const char* name,
93 const char* expression,
94 const ExecutionContext& exe_ctx);
97 CreateValueObjectFromAddress (const char* name,
99 const ExecutionContext& exe_ctx,
103 CreateValueObjectFromData (const char* name,
104 const DataExtractor& data,
105 const ExecutionContext& exe_ctx,
110 DISALLOW_COPY_AND_ASSIGN(SyntheticChildrenFrontEnd);
113 class SyntheticValueProviderFrontEnd : public SyntheticChildrenFrontEnd
116 SyntheticValueProviderFrontEnd (ValueObject &backend) :
117 SyntheticChildrenFrontEnd(backend)
121 ~SyntheticValueProviderFrontEnd ()
126 CalculateNumChildren () { return 0; }
128 virtual lldb::ValueObjectSP
129 GetChildAtIndex (size_t idx) { return nullptr; }
132 GetIndexOfChildWithName (const ConstString &name) { return UINT32_MAX; }
135 Update () { return false; }
138 MightHaveChildren () { return false; }
140 virtual lldb::ValueObjectSP
141 GetSyntheticValue () = 0;
144 DISALLOW_COPY_AND_ASSIGN(SyntheticValueProviderFrontEnd);
147 class SyntheticChildren
156 m_flags (lldb::eTypeOptionCascade)
159 Flags (const Flags& other) :
160 m_flags (other.m_flags)
163 Flags (uint32_t value) :
168 operator = (const Flags& rhs)
171 m_flags = rhs.m_flags;
177 operator = (const uint32_t& rhs)
193 return (m_flags & lldb::eTypeOptionCascade) == lldb::eTypeOptionCascade;
197 SetCascades (bool value = true)
200 m_flags |= lldb::eTypeOptionCascade;
202 m_flags &= ~lldb::eTypeOptionCascade;
207 GetSkipPointers () const
209 return (m_flags & lldb::eTypeOptionSkipPointers) == lldb::eTypeOptionSkipPointers;
213 SetSkipPointers (bool value = true)
216 m_flags |= lldb::eTypeOptionSkipPointers;
218 m_flags &= ~lldb::eTypeOptionSkipPointers;
223 GetSkipReferences () const
225 return (m_flags & lldb::eTypeOptionSkipReferences) == lldb::eTypeOptionSkipReferences;
229 SetSkipReferences (bool value = true)
232 m_flags |= lldb::eTypeOptionSkipReferences;
234 m_flags &= ~lldb::eTypeOptionSkipReferences;
245 SetValue (uint32_t value)
254 SyntheticChildren (const Flags& flags) :
260 ~SyntheticChildren ()
267 return m_flags.GetCascades();
270 SkipsPointers () const
272 return m_flags.GetSkipPointers();
275 SkipsReferences () const
277 return m_flags.GetSkipReferences();
281 SetCascades (bool value)
283 m_flags.SetCascades(value);
287 SetSkipsPointers (bool value)
289 m_flags.SetSkipPointers(value);
293 SetSkipsReferences (bool value)
295 m_flags.SetSkipReferences(value);
301 return m_flags.GetValue();
305 SetOptions (uint32_t value)
307 m_flags.SetValue(value);
314 GetDescription () = 0;
316 virtual SyntheticChildrenFrontEnd::AutoPointer
317 GetFrontEnd (ValueObject &backend) = 0;
319 typedef std::shared_ptr<SyntheticChildren> SharedPointer;
320 typedef bool(*SyntheticChildrenCallback)(void*, ConstString, const SyntheticChildren::SharedPointer&);
325 return m_my_revision;
329 uint32_t m_my_revision;
333 DISALLOW_COPY_AND_ASSIGN(SyntheticChildren);
336 class TypeFilterImpl : public SyntheticChildren
338 std::vector<std::string> m_expression_paths;
340 TypeFilterImpl(const SyntheticChildren::Flags& flags) :
341 SyntheticChildren(flags),
346 TypeFilterImpl(const SyntheticChildren::Flags& flags,
347 const std::initializer_list<const char*> items) :
348 SyntheticChildren(flags),
351 for (auto path : items)
352 AddExpressionPath (path);
356 AddExpressionPath (const char* path)
358 AddExpressionPath(std::string(path));
364 m_expression_paths.clear();
370 return m_expression_paths.size();
374 GetExpressionPathAtIndex(size_t i) const
376 return m_expression_paths[i].c_str();
380 SetExpressionPathAtIndex (size_t i, const char* path)
382 return SetExpressionPathAtIndex(i, std::string(path));
386 AddExpressionPath (const std::string& path);
389 SetExpressionPathAtIndex (size_t i, const std::string& path);
400 class FrontEnd : public SyntheticChildrenFrontEnd
403 TypeFilterImpl* filter;
406 FrontEnd(TypeFilterImpl* flt,
407 ValueObject &backend) :
408 SyntheticChildrenFrontEnd(backend),
418 CalculateNumChildren ()
420 return filter->GetCount();
423 virtual lldb::ValueObjectSP
424 GetChildAtIndex (size_t idx)
426 if (idx >= filter->GetCount())
427 return lldb::ValueObjectSP();
428 return m_backend.GetSyntheticExpressionPathChild(filter->GetExpressionPathAtIndex(idx), true);
432 Update() { return false; }
437 return filter->GetCount() > 0;
441 GetIndexOfChildWithName (const ConstString &name);
443 typedef std::shared_ptr<SyntheticChildrenFrontEnd> SharedPointer;
446 DISALLOW_COPY_AND_ASSIGN(FrontEnd);
449 virtual SyntheticChildrenFrontEnd::AutoPointer
450 GetFrontEnd(ValueObject &backend)
452 return SyntheticChildrenFrontEnd::AutoPointer(new FrontEnd(this, backend));
456 DISALLOW_COPY_AND_ASSIGN(TypeFilterImpl);
459 class CXXSyntheticChildren : public SyntheticChildren
462 typedef SyntheticChildrenFrontEnd* (*CreateFrontEndCallback) (CXXSyntheticChildren*, lldb::ValueObjectSP);
464 CreateFrontEndCallback m_create_callback;
465 std::string m_description;
467 CXXSyntheticChildren (const SyntheticChildren::Flags& flags,
468 const char* description,
469 CreateFrontEndCallback callback) :
470 SyntheticChildren(flags),
471 m_create_callback(callback),
472 m_description(description ? description : "")
485 virtual SyntheticChildrenFrontEnd::AutoPointer
486 GetFrontEnd (ValueObject &backend)
488 return SyntheticChildrenFrontEnd::AutoPointer(m_create_callback(this, backend.GetSP()));
492 DISALLOW_COPY_AND_ASSIGN(CXXSyntheticChildren);
495 #ifndef LLDB_DISABLE_PYTHON
497 class ScriptedSyntheticChildren : public SyntheticChildren
499 std::string m_python_class;
500 std::string m_python_code;
503 ScriptedSyntheticChildren (const SyntheticChildren::Flags& flags,
505 const char* pcode = NULL) :
506 SyntheticChildren(flags),
511 m_python_class = pclass;
513 m_python_code = pcode;
517 GetPythonClassName ()
519 return m_python_class.c_str();
525 return m_python_code.c_str();
529 SetPythonClassName (const char* fname)
531 m_python_class.assign(fname);
532 m_python_code.clear();
536 SetPythonCode (const char* script)
538 m_python_code.assign(script);
550 class FrontEnd : public SyntheticChildrenFrontEnd
553 std::string m_python_class;
554 lldb::ScriptInterpreterObjectSP m_wrapper_sp;
555 ScriptInterpreter *m_interpreter;
558 FrontEnd (std::string pclass,
559 ValueObject &backend);
568 CalculateNumChildren ();
570 virtual lldb::ValueObjectSP
571 GetChildAtIndex (size_t idx);
577 MightHaveChildren ();
580 GetIndexOfChildWithName (const ConstString &name);
582 virtual lldb::ValueObjectSP
583 GetSyntheticValue ();
585 typedef std::shared_ptr<SyntheticChildrenFrontEnd> SharedPointer;
588 DISALLOW_COPY_AND_ASSIGN(FrontEnd);
591 virtual SyntheticChildrenFrontEnd::AutoPointer
592 GetFrontEnd(ValueObject &backend)
594 auto synth_ptr = SyntheticChildrenFrontEnd::AutoPointer(new FrontEnd(m_python_class, backend));
595 if (synth_ptr && ((FrontEnd*)synth_ptr.get())->IsValid())
601 DISALLOW_COPY_AND_ASSIGN(ScriptedSyntheticChildren);
604 } // namespace lldb_private
606 #endif // lldb_TypeSynthetic_h_