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_
21 // Other libraries and framework includes
24 #include "lldb/lldb-public.h"
25 #include "lldb/lldb-enumerations.h"
27 #include "lldb/Core/ValueObject.h"
28 #include "lldb/Interpreter/ScriptInterpreterPython.h"
29 #include "lldb/Symbol/Type.h"
31 namespace lldb_private {
41 m_flags (lldb::eTypeOptionCascade)
44 Flags (const Flags& other) :
45 m_flags (other.m_flags)
48 Flags (uint32_t value) :
53 operator = (const Flags& rhs)
56 m_flags = rhs.m_flags;
62 operator = (const uint32_t& rhs)
78 return (m_flags & lldb::eTypeOptionCascade) == lldb::eTypeOptionCascade;
82 SetCascades (bool value = true)
85 m_flags |= lldb::eTypeOptionCascade;
87 m_flags &= ~lldb::eTypeOptionCascade;
92 GetSkipPointers () const
94 return (m_flags & lldb::eTypeOptionSkipPointers) == lldb::eTypeOptionSkipPointers;
98 SetSkipPointers (bool value = true)
101 m_flags |= lldb::eTypeOptionSkipPointers;
103 m_flags &= ~lldb::eTypeOptionSkipPointers;
108 GetSkipReferences () const
110 return (m_flags & lldb::eTypeOptionSkipReferences) == lldb::eTypeOptionSkipReferences;
114 SetSkipReferences (bool value = true)
117 m_flags |= lldb::eTypeOptionSkipReferences;
119 m_flags &= ~lldb::eTypeOptionSkipReferences;
124 GetDontShowChildren () const
126 return (m_flags & lldb::eTypeOptionHideChildren) == lldb::eTypeOptionHideChildren;
130 SetDontShowChildren (bool value = true)
133 m_flags |= lldb::eTypeOptionHideChildren;
135 m_flags &= ~lldb::eTypeOptionHideChildren;
140 GetDontShowValue () const
142 return (m_flags & lldb::eTypeOptionHideValue) == lldb::eTypeOptionHideValue;
146 SetDontShowValue (bool value = true)
149 m_flags |= lldb::eTypeOptionHideValue;
151 m_flags &= ~lldb::eTypeOptionHideValue;
156 GetShowMembersOneLiner () const
158 return (m_flags & lldb::eTypeOptionShowOneLiner) == lldb::eTypeOptionShowOneLiner;
162 SetShowMembersOneLiner (bool value = true)
165 m_flags |= lldb::eTypeOptionShowOneLiner;
167 m_flags &= ~lldb::eTypeOptionShowOneLiner;
172 GetHideItemNames () const
174 return (m_flags & lldb::eTypeOptionHideNames) == lldb::eTypeOptionHideNames;
178 SetHideItemNames (bool value = true)
181 m_flags |= lldb::eTypeOptionHideNames;
183 m_flags &= ~lldb::eTypeOptionHideNames;
194 SetValue (uint32_t value)
211 TypeSummaryImpl (const TypeSummaryImpl::Flags& flags);
216 return m_flags.GetCascades();
219 SkipsPointers () const
221 return m_flags.GetSkipPointers();
224 SkipsReferences () const
226 return m_flags.GetSkipReferences();
230 DoesPrintChildren () const
232 return !m_flags.GetDontShowChildren();
236 DoesPrintValue () const
238 return !m_flags.GetDontShowValue();
244 return m_flags.GetShowMembersOneLiner();
250 return m_flags.GetHideItemNames();
254 SetCascades (bool value)
256 m_flags.SetCascades(value);
260 SetSkipsPointers (bool value)
262 m_flags.SetSkipPointers(value);
266 SetSkipsReferences (bool value)
268 m_flags.SetSkipReferences(value);
272 SetDoesPrintChildren (bool value)
274 m_flags.SetDontShowChildren(!value);
278 SetDoesPrintValue (bool value)
280 m_flags.SetDontShowValue(!value);
284 SetIsOneliner (bool value)
286 m_flags.SetShowMembersOneLiner(value);
290 SetHideNames (bool value)
292 m_flags.SetHideItemNames(value);
298 return m_flags.GetValue();
302 SetOptions (uint32_t value)
304 m_flags.SetValue(value);
312 // we are using a ValueObject* instead of a ValueObjectSP because we do not need to hold on to this for
313 // extended periods of time and we trust the ValueObject to stay around for as long as it is required
314 // for us to generate its summary
316 FormatObject (ValueObject *valobj,
317 std::string& dest) = 0;
320 GetDescription () = 0;
331 return m_my_revision;
334 typedef std::shared_ptr<TypeSummaryImpl> SharedPointer;
335 typedef bool(*SummaryCallback)(void*, ConstString, const lldb::TypeSummaryImplSP&);
336 typedef bool(*RegexSummaryCallback)(void*, lldb::RegularExpressionSP, const lldb::TypeSummaryImplSP&);
339 uint32_t m_my_revision;
343 DISALLOW_COPY_AND_ASSIGN(TypeSummaryImpl);
346 // simple string-based summaries, using ${var to show data
347 struct StringSummaryFormat : public TypeSummaryImpl
349 std::string m_format;
351 StringSummaryFormat(const TypeSummaryImpl::Flags& flags,
355 GetSummaryString () const
357 return m_format.c_str();
361 SetSummaryString (const char* data)
364 m_format.assign(data);
370 ~StringSummaryFormat()
375 FormatObject(ValueObject *valobj,
391 return TypeSummaryImpl::eTypeString;
395 DISALLOW_COPY_AND_ASSIGN(StringSummaryFormat);
398 // summaries implemented via a C++ function
399 struct CXXFunctionSummaryFormat : public TypeSummaryImpl
402 // we should convert these to SBValue and SBStream if we ever cross
403 // the boundary towards the external world
404 typedef bool (*Callback)(ValueObject& valobj, Stream& dest);
407 std::string m_description;
409 CXXFunctionSummaryFormat (const TypeSummaryImpl::Flags& flags,
411 const char* description);
414 GetBackendFunction () const
420 GetTextualInfo () const
422 return m_description.c_str();
426 SetBackendFunction (Callback cb_func)
432 SetTextualInfo (const char* descr)
435 m_description.assign(descr);
437 m_description.clear();
441 ~CXXFunctionSummaryFormat ()
446 FormatObject (ValueObject *valobj,
461 return TypeSummaryImpl::eTypeCallback;
464 typedef std::shared_ptr<CXXFunctionSummaryFormat> SharedPointer;
467 DISALLOW_COPY_AND_ASSIGN(CXXFunctionSummaryFormat);
470 #ifndef LLDB_DISABLE_PYTHON
472 // Python-based summaries, running script code to show data
473 struct ScriptSummaryFormat : public TypeSummaryImpl
475 std::string m_function_name;
476 std::string m_python_script;
477 lldb::ScriptInterpreterObjectSP m_script_function_sp;
479 ScriptSummaryFormat(const TypeSummaryImpl::Flags& flags,
480 const char *function_name,
481 const char* python_script = NULL);
484 GetFunctionName () const
486 return m_function_name.c_str();
490 GetPythonScript () const
492 return m_python_script.c_str();
496 SetFunctionName (const char* function_name)
499 m_function_name.assign(function_name);
501 m_function_name.clear();
502 m_python_script.clear();
506 SetPythonScript (const char* script)
509 m_python_script.assign(script);
511 m_python_script.clear();
515 ~ScriptSummaryFormat ()
520 FormatObject (ValueObject *valobj,
535 return TypeSummaryImpl::eTypeScript;
538 typedef std::shared_ptr<ScriptSummaryFormat> SharedPointer;
542 DISALLOW_COPY_AND_ASSIGN(ScriptSummaryFormat);
545 } // namespace lldb_private
547 #endif // lldb_TypeSummary_h_