1//===-- TypeSynthetic.cpp ----------------------------------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/lldb-python.h"
11
12// C Includes
13
14// C++ Includes
15
16// Other libraries and framework includes
17
18// Project includes
19#include "lldb/lldb-public.h"
20#include "lldb/lldb-enumerations.h"
21
22#include "lldb/Core/Debugger.h"
23#include "lldb/Core/StreamString.h"
24#include "lldb/DataFormatters/TypeSynthetic.h"
25#include "lldb/Interpreter/CommandInterpreter.h"
26#include "lldb/Symbol/ClangASTType.h"
27#include "lldb/Target/StackFrame.h"
28#include "lldb/Target/Target.h"
29
30using namespace lldb;
31using namespace lldb_private;
32
33std::string
34TypeFilterImpl::GetDescription()
35{
36    StreamString sstr;
37    sstr.Printf("%s%s%s {\n",
38                Cascades() ? "" : " (not cascading)",
39                SkipsPointers() ? " (skip pointers)" : "",
40                SkipsReferences() ? " (skip references)" : "");
41
42    for (size_t i = 0; i < GetCount(); i++)
43    {
44        sstr.Printf("    %s\n",
45                    GetExpressionPathAtIndex(i));
46    }
47
48    sstr.Printf("}");
49    return sstr.GetString();
50}
51
52std::string
53CXXSyntheticChildren::GetDescription()
54{
55    StreamString sstr;
56    sstr.Printf("%s%s%s Generator at %p - %s",
57                Cascades() ? "" : " (not cascading)",
58                SkipsPointers() ? " (skip pointers)" : "",
59                SkipsReferences() ? " (skip references)" : "",
60                m_create_callback,
61                m_description.c_str());
62
63    return sstr.GetString();
64}
65
66#ifndef LLDB_DISABLE_PYTHON
67
68ScriptedSyntheticChildren::FrontEnd::FrontEnd(std::string pclass, ValueObject &backend) :
69SyntheticChildrenFrontEnd(backend),
70m_python_class(pclass),
71m_wrapper_sp(),
72m_interpreter(NULL)
73{
74    if (backend == LLDB_INVALID_UID)
75        return;
76
77    TargetSP target_sp = backend.GetTargetSP();
78
79    if (!target_sp)
80        return;
81
82    m_interpreter = target_sp->GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
83
84    if (m_interpreter != NULL)
85        m_wrapper_sp = m_interpreter->CreateSyntheticScriptedProvider(m_python_class.c_str(), backend.GetSP());
86}
87
88ScriptedSyntheticChildren::FrontEnd::~FrontEnd()
89{
90}
91
92lldb::ValueObjectSP
93ScriptedSyntheticChildren::FrontEnd::GetChildAtIndex (size_t idx)
94{
95    if (!m_wrapper_sp || !m_interpreter)
96        return lldb::ValueObjectSP();
97
98    return m_interpreter->GetChildAtIndex(m_wrapper_sp, idx);
99}
100
101std::string
102ScriptedSyntheticChildren::GetDescription()
103{
104    StreamString sstr;
105    sstr.Printf("%s%s%s Python class %s",
106                Cascades() ? "" : " (not cascading)",
107                SkipsPointers() ? " (skip pointers)" : "",
108                SkipsReferences() ? " (skip references)" : "",
109                m_python_class.c_str());
110
111    return sstr.GetString();
112}
113
114#endif // #ifndef LLDB_DISABLE_PYTHON
115