1 //===-- TypeSummary.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_TypeSummary_h_
11 #define lldb_TypeSummary_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"
27 #include "lldb/Interpreter/ScriptInterpreterPython.h"
28 #include "lldb/Symbol/Type.h"
30 namespace lldb_private {
40 m_flags (lldb::eTypeOptionCascade)
43 Flags (const Flags& other) :
44 m_flags (other.m_flags)
47 Flags (uint32_t value) :
52 operator = (const Flags& rhs)
55 m_flags = rhs.m_flags;
61 operator = (const uint32_t& rhs)
77 return (m_flags & lldb::eTypeOptionCascade) == lldb::eTypeOptionCascade;
81 SetCascades (bool value = true)
84 m_flags |= lldb::eTypeOptionCascade;
86 m_flags &= ~lldb::eTypeOptionCascade;
91 GetSkipPointers () const
93 return (m_flags & lldb::eTypeOptionSkipPointers) == lldb::eTypeOptionSkipPointers;
97 SetSkipPointers (bool value = true)
100 m_flags |= lldb::eTypeOptionSkipPointers;
102 m_flags &= ~lldb::eTypeOptionSkipPointers;
107 GetSkipReferences () const
109 return (m_flags & lldb::eTypeOptionSkipReferences) == lldb::eTypeOptionSkipReferences;
113 SetSkipReferences (bool value = true)
116 m_flags |= lldb::eTypeOptionSkipReferences;
118 m_flags &= ~lldb::eTypeOptionSkipReferences;
123 GetDontShowChildren () const
125 return (m_flags & lldb::eTypeOptionHideChildren) == lldb::eTypeOptionHideChildren;
129 SetDontShowChildren (bool value = true)
132 m_flags |= lldb::eTypeOptionHideChildren;
134 m_flags &= ~lldb::eTypeOptionHideChildren;
139 GetDontShowValue () const
141 return (m_flags & lldb::eTypeOptionHideValue) == lldb::eTypeOptionHideValue;
145 SetDontShowValue (bool value = true)
148 m_flags |= lldb::eTypeOptionHideValue;
150 m_flags &= ~lldb::eTypeOptionHideValue;
155 GetShowMembersOneLiner () const
157 return (m_flags & lldb::eTypeOptionShowOneLiner) == lldb::eTypeOptionShowOneLiner;
161 SetShowMembersOneLiner (bool value = true)
164 m_flags |= lldb::eTypeOptionShowOneLiner;
166 m_flags &= ~lldb::eTypeOptionShowOneLiner;
171 GetHideItemNames () const
173 return (m_flags & lldb::eTypeOptionHideNames) == lldb::eTypeOptionHideNames;
177 SetHideItemNames (bool value = true)
180 m_flags |= lldb::eTypeOptionHideNames;
182 m_flags &= ~lldb::eTypeOptionHideNames;
193 SetValue (uint32_t value)
210 TypeSummaryImpl (const TypeSummaryImpl::Flags& flags);
215 return m_flags.GetCascades();
218 SkipsPointers () const
220 return m_flags.GetSkipPointers();
223 SkipsReferences () const
225 return m_flags.GetSkipReferences();
229 DoesPrintChildren () const
231 return !m_flags.GetDontShowChildren();
235 DoesPrintValue () const
237 return !m_flags.GetDontShowValue();
243 return m_flags.GetShowMembersOneLiner();
249 return m_flags.GetHideItemNames();
253 SetCascades (bool value)
255 m_flags.SetCascades(value);
259 SetSkipsPointers (bool value)
261 m_flags.SetSkipPointers(value);
265 SetSkipsReferences (bool value)
267 m_flags.SetSkipReferences(value);
271 SetDoesPrintChildren (bool value)
273 m_flags.SetDontShowChildren(!value);
277 SetDoesPrintValue (bool value)
279 m_flags.SetDontShowValue(!value);
283 SetIsOneLiner (bool value)
285 m_flags.SetShowMembersOneLiner(value);
289 SetHideNames (bool value)
291 m_flags.SetHideItemNames(value);
297 return m_flags.GetValue();
301 SetOptions (uint32_t value)
303 m_flags.SetValue(value);
311 // we are using a ValueObject* instead of a ValueObjectSP because we do not need to hold on to this for
312 // extended periods of time and we trust the ValueObject to stay around for as long as it is required
313 // for us to generate its summary
315 FormatObject (ValueObject *valobj,
316 std::string& dest) = 0;
319 GetDescription () = 0;
330 return m_my_revision;
333 typedef std::shared_ptr<TypeSummaryImpl> SharedPointer;
334 typedef bool(*SummaryCallback)(void*, ConstString, const lldb::TypeSummaryImplSP&);
335 typedef bool(*RegexSummaryCallback)(void*, lldb::RegularExpressionSP, const lldb::TypeSummaryImplSP&);
338 uint32_t m_my_revision;
342 DISALLOW_COPY_AND_ASSIGN(TypeSummaryImpl);
345 // simple string-based summaries, using ${var to show data
346 struct StringSummaryFormat : public TypeSummaryImpl
348 std::string m_format;
350 StringSummaryFormat(const TypeSummaryImpl::Flags& flags,
354 GetSummaryString () const
356 return m_format.c_str();
360 SetSummaryString (const char* data)
363 m_format.assign(data);
369 ~StringSummaryFormat()
374 FormatObject(ValueObject *valobj,
390 return TypeSummaryImpl::eTypeString;
394 DISALLOW_COPY_AND_ASSIGN(StringSummaryFormat);
397 // summaries implemented via a C++ function
398 struct CXXFunctionSummaryFormat : public TypeSummaryImpl
401 // we should convert these to SBValue and SBStream if we ever cross
402 // the boundary towards the external world
403 typedef bool (*Callback)(ValueObject& valobj, Stream& dest);
406 std::string m_description;
408 CXXFunctionSummaryFormat (const TypeSummaryImpl::Flags& flags,
410 const char* description);
413 GetBackendFunction () const
419 GetTextualInfo () const
421 return m_description.c_str();
425 SetBackendFunction (Callback cb_func)
431 SetTextualInfo (const char* descr)
434 m_description.assign(descr);
436 m_description.clear();
440 ~CXXFunctionSummaryFormat ()
445 FormatObject (ValueObject *valobj,
460 return TypeSummaryImpl::eTypeCallback;
463 typedef std::shared_ptr<CXXFunctionSummaryFormat> SharedPointer;
466 DISALLOW_COPY_AND_ASSIGN(CXXFunctionSummaryFormat);
469 #ifndef LLDB_DISABLE_PYTHON
471 // Python-based summaries, running script code to show data
472 struct ScriptSummaryFormat : public TypeSummaryImpl
474 std::string m_function_name;
475 std::string m_python_script;
476 lldb::ScriptInterpreterObjectSP m_script_function_sp;
478 ScriptSummaryFormat(const TypeSummaryImpl::Flags& flags,
479 const char *function_name,
480 const char* python_script = NULL);
483 GetFunctionName () const
485 return m_function_name.c_str();
489 GetPythonScript () const
491 return m_python_script.c_str();
495 SetFunctionName (const char* function_name)
498 m_function_name.assign(function_name);
500 m_function_name.clear();
501 m_python_script.clear();
505 SetPythonScript (const char* script)
508 m_python_script.assign(script);
510 m_python_script.clear();
514 ~ScriptSummaryFormat ()
519 FormatObject (ValueObject *valobj,
534 return TypeSummaryImpl::eTypeScript;
537 typedef std::shared_ptr<ScriptSummaryFormat> SharedPointer;
541 DISALLOW_COPY_AND_ASSIGN(ScriptSummaryFormat);
544 } // namespace lldb_private
546 #endif // lldb_TypeSummary_h_