]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Interpreter/PythonDataObjects.h
Merge OpenSSL 1.0.1p.
[FreeBSD/FreeBSD.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                 if (Py_IsInitialized())
66                     Py_XDECREF(m_py_obj);
67                 m_py_obj = py_obj;
68                 if (Py_IsInitialized())
69                     Py_XINCREF(m_py_obj);
70             }
71             return true;
72         }
73         
74         void
75         Dump () const
76         {
77             if (m_py_obj)
78                 _PyObject_Dump (m_py_obj);
79             else
80                 puts ("NULL");
81         }
82         
83         void
84         Dump (Stream &strm) const;
85
86         PyObject*
87         get () const
88         {
89             return m_py_obj;
90         }
91
92         PythonString
93         Repr ();
94         
95         PythonString
96         Str ();
97         
98         explicit operator bool () const
99         {
100             return m_py_obj != NULL;
101         }
102         
103         bool
104         IsNULLOrNone () const;
105         
106     protected:
107         PyObject* m_py_obj;
108     };
109     
110     class PythonString: public PythonObject
111     {
112     public:
113         
114         PythonString ();
115         PythonString (PyObject *o);
116         PythonString (const PythonObject &object);
117         PythonString (const lldb::ScriptInterpreterObjectSP &script_object_sp);
118         PythonString (const char* string);
119         virtual ~PythonString ();
120         
121         virtual bool
122         Reset (PyObject* py_obj = NULL);
123
124         const char*
125         GetString() const;
126
127         size_t
128         GetSize() const;
129
130         void
131         SetString (const char* string);        
132     };
133     
134     class PythonInteger: public PythonObject
135     {
136     public:
137         
138         PythonInteger ();
139         PythonInteger (PyObject* py_obj);
140         PythonInteger (const PythonObject &object);
141         PythonInteger (const lldb::ScriptInterpreterObjectSP &script_object_sp);
142         PythonInteger (int64_t value);
143         virtual ~PythonInteger ();
144         
145         virtual bool
146         Reset (PyObject* py_obj = NULL);
147         
148         int64_t
149         GetInteger();
150         
151         void
152         SetInteger (int64_t value);
153     };
154     
155     class PythonList: public PythonObject
156     {
157     public:
158         
159         PythonList (bool create_empty);
160         PythonList (PyObject* py_obj);
161         PythonList (const PythonObject &object);
162         PythonList (const lldb::ScriptInterpreterObjectSP &script_object_sp);
163         PythonList (uint32_t count);
164         virtual ~PythonList ();
165         
166         virtual bool
167         Reset (PyObject* py_obj = NULL);
168         
169         uint32_t
170         GetSize();
171         
172         PythonObject
173         GetItemAtIndex (uint32_t index);
174         
175         void
176         SetItemAtIndex (uint32_t index, const PythonObject &object);
177         
178         void
179         AppendItem (const PythonObject &object);
180     };
181     
182     class PythonDictionary: public PythonObject
183     {
184     public:
185         
186         explicit PythonDictionary (bool create_empty);
187         PythonDictionary (PyObject* object);
188         PythonDictionary (const PythonObject &object);
189         PythonDictionary (const lldb::ScriptInterpreterObjectSP &script_object_sp);
190         virtual ~PythonDictionary ();
191         
192         virtual bool
193         Reset (PyObject* object = NULL);
194         
195         uint32_t GetSize();
196         
197         PythonObject
198         GetItemForKey (const PythonString &key) const;
199         
200         const char *
201         GetItemForKeyAsString (const PythonString &key, const char *fail_value = NULL) const;
202
203         int64_t
204         GetItemForKeyAsInteger (const PythonString &key, int64_t fail_value = 0) const;
205
206         PythonObject
207         GetItemForKey (const char *key) const;
208
209         typedef bool (*DictionaryIteratorCallback)(PythonString* key, PythonDictionary* dict);
210         
211         PythonList
212         GetKeys () const;
213         
214         PythonString
215         GetKeyAtPosition (uint32_t pos) const;
216         
217         PythonObject
218         GetValueAtPosition (uint32_t pos) const;
219         
220         void
221         SetItemForKey (const PythonString &key, PyObject *value);
222
223         void
224         SetItemForKey (const PythonString &key, const PythonObject& value);
225     };
226     
227 } // namespace lldb_private
228
229 #endif  // liblldb_PythonDataObjects_h_