]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/llvm/tools/lldb/include/lldb/Interpreter/PythonDataObjects.h
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / llvm / tools / lldb / include / lldb / Interpreter / PythonDataObjects.h
1 //===-- PythonDataObjects.h----------------------------------------*- 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 #ifndef liblldb_PythonDataObjects_h_
11 #define liblldb_PythonDataObjects_h_
12
13 // C Includes
14 // C++ Includes
15
16 // Other libraries and framework includes
17 // Project includes
18 #include "lldb/lldb-defines.h"
19 #include "lldb/Core/ConstString.h"
20 #include "lldb/Core/Flags.h"
21 #include "lldb/Interpreter/OptionValue.h"
22 #include "lldb/lldb-python.h"
23
24 namespace lldb_private {
25     
26     class PythonObject
27     {
28     public:
29         PythonObject () :
30             m_py_obj(NULL)
31         {
32         }
33         
34         explicit PythonObject (PyObject* py_obj) :
35             m_py_obj(NULL)
36         {
37             Reset (py_obj);
38         }
39         
40         PythonObject (const PythonObject &rhs) :
41             m_py_obj(NULL)
42         {
43             Reset (rhs.m_py_obj);
44         }
45         
46         explicit PythonObject (const lldb::ScriptInterpreterObjectSP &script_object_sp);
47
48         virtual
49         ~PythonObject ()
50         {
51             Reset (NULL);
52         }
53
54         bool
55         Reset (const PythonObject &object)
56         {
57             return Reset(object.get());
58         }
59
60         virtual bool
61         Reset (PyObject* py_obj = NULL)
62         {
63             if (py_obj != m_py_obj)
64             {
65                 Py_XDECREF(m_py_obj);
66                 m_py_obj = py_obj;
67                 Py_XINCREF(m_py_obj);
68             }
69             return true;
70         }
71         
72         void
73         Dump () const
74         {
75             if (m_py_obj)
76                 _PyObject_Dump (m_py_obj);
77             else
78                 puts ("NULL");
79         }
80         
81         void
82         Dump (Stream &strm) const;
83
84         PyObject*
85         get () const
86         {
87             return m_py_obj;
88         }
89
90         PythonString
91         Repr ();
92         
93         PythonString
94         Str ();
95         
96         explicit operator bool () const
97         {
98             return m_py_obj != NULL;
99         }
100         
101         bool
102         IsNULLOrNone () const;
103         
104     protected:
105         PyObject* m_py_obj;
106     };
107     
108     class PythonString: public PythonObject
109     {
110     public:
111         
112         PythonString ();
113         PythonString (PyObject *o);
114         PythonString (const PythonObject &object);
115         PythonString (const lldb::ScriptInterpreterObjectSP &script_object_sp);
116         PythonString (const char* string);
117         virtual ~PythonString ();
118         
119         virtual bool
120         Reset (PyObject* py_obj = NULL);
121
122         const char*
123         GetString() const;
124
125         size_t
126         GetSize() const;
127
128         void
129         SetString (const char* string);        
130     };
131     
132     class PythonInteger: public PythonObject
133     {
134     public:
135         
136         PythonInteger ();
137         PythonInteger (PyObject* py_obj);
138         PythonInteger (const PythonObject &object);
139         PythonInteger (const lldb::ScriptInterpreterObjectSP &script_object_sp);
140         PythonInteger (int64_t value);
141         virtual ~PythonInteger ();
142         
143         virtual bool
144         Reset (PyObject* py_obj = NULL);
145         
146         int64_t
147         GetInteger();
148         
149         void
150         SetInteger (int64_t value);
151     };
152     
153     class PythonList: public PythonObject
154     {
155     public:
156         
157         PythonList (bool create_empty);
158         PythonList (PyObject* py_obj);
159         PythonList (const PythonObject &object);
160         PythonList (const lldb::ScriptInterpreterObjectSP &script_object_sp);
161         PythonList (uint32_t count);
162         virtual ~PythonList ();
163         
164         virtual bool
165         Reset (PyObject* py_obj = NULL);
166         
167         uint32_t
168         GetSize();
169         
170         PythonObject
171         GetItemAtIndex (uint32_t index);
172         
173         void
174         SetItemAtIndex (uint32_t index, const PythonObject &object);
175         
176         void
177         AppendItem (const PythonObject &object);
178     };
179     
180     class PythonDictionary: public PythonObject
181     {
182     public:
183         
184         explicit PythonDictionary (bool create_empty);
185         PythonDictionary (PyObject* object);
186         PythonDictionary (const PythonObject &object);
187         PythonDictionary (const lldb::ScriptInterpreterObjectSP &script_object_sp);
188         virtual ~PythonDictionary ();
189         
190         virtual bool
191         Reset (PyObject* object = NULL);
192         
193         uint32_t GetSize();
194         
195         PythonObject
196         GetItemForKey (const PythonString &key) const;
197         
198         const char *
199         GetItemForKeyAsString (const PythonString &key, const char *fail_value = NULL) const;
200
201         int64_t
202         GetItemForKeyAsInteger (const PythonString &key, int64_t fail_value = 0) const;
203
204         PythonObject
205         GetItemForKey (const char *key) const;
206
207         typedef bool (*DictionaryIteratorCallback)(PythonString* key, PythonDictionary* dict);
208         
209         PythonList
210         GetKeys () const;
211         
212         PythonString
213         GetKeyAtPosition (uint32_t pos) const;
214         
215         PythonObject
216         GetValueAtPosition (uint32_t pos) const;
217         
218         void
219         SetItemForKey (const PythonString &key, PyObject *value);
220
221         void
222         SetItemForKey (const PythonString &key, const PythonObject& value);
223     };
224     
225 } // namespace lldb_private
226
227 #endif  // liblldb_PythonDataObjects_h_