summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2015-11-11 19:42:27 +0000
committerZachary Turner <zturner@google.com>2015-11-11 19:42:27 +0000
commita140514733e0ab0310688c727b70ba3e2a4a8ddc (patch)
tree00c8c54435082bda6ae8c33cb9eac146fe31865a /lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
parent51c402838ca37b51701f7e03738f6e503c7d1c7e (diff)
downloadbcm5719-llvm-a140514733e0ab0310688c727b70ba3e2a4a8ddc.tar.gz
bcm5719-llvm-a140514733e0ab0310688c727b70ba3e2a4a8ddc.zip
Create `PythonTuple` and `PythonCallable` wrapper classes.
This adds PythonTuple and PythonCallable classes to PythonDataObjects. Additionally, unit tests are provided that exercise this functionality, including invoking manipulating and checking for validity of tuples, and invoking and checking for validity of callables using a variety of different syntaxes. The goal here is to eventually replace the code in python-wrapper.swig that directly uses the Python C API to deal with callables and name resolution with this code that can be more easily tested and debugged. llvm-svn: 252787
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h')
-rw-r--r--lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h73
1 files changed, 71 insertions, 2 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
index beeea4ca6fa..22c86fd4c35 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
@@ -70,6 +70,8 @@ enum class PyObjectType
List,
String,
Module,
+ Callable,
+ Tuple,
File
};
@@ -203,7 +205,7 @@ public:
Str() const;
static PythonObject
- ResolveNameGlobal(llvm::StringRef name);
+ ResolveNameWithDictionary(llvm::StringRef name, PythonDictionary dict);
PythonObject
ResolveName(llvm::StringRef name) const;
@@ -295,6 +297,7 @@ public:
class PythonList : public PythonObject
{
public:
+ PythonList() {}
explicit PythonList(PyInitialValue value);
explicit PythonList(int list_size);
PythonList(PyRefType type, PyObject *o);
@@ -320,9 +323,39 @@ public:
StructuredData::ArraySP CreateStructuredArray() const;
};
+class PythonTuple : public PythonObject
+{
+public:
+ PythonTuple() {}
+ explicit PythonTuple(PyInitialValue value);
+ explicit PythonTuple(int tuple_size);
+ PythonTuple(PyRefType type, PyObject *o);
+ PythonTuple(const PythonTuple &tuple);
+ PythonTuple(std::initializer_list<PythonObject> objects);
+ PythonTuple(std::initializer_list<PyObject*> objects);
+
+ ~PythonTuple() override;
+
+ static bool Check(PyObject *py_obj);
+
+ // Bring in the no-argument base class version
+ using PythonObject::Reset;
+
+ void Reset(PyRefType type, PyObject *py_obj) override;
+
+ uint32_t GetSize() const;
+
+ PythonObject GetItemAtIndex(uint32_t index) const;
+
+ void SetItemAtIndex(uint32_t index, const PythonObject &object);
+
+ StructuredData::ArraySP CreateStructuredArray() const;
+};
+
class PythonDictionary : public PythonObject
{
public:
+ PythonDictionary() {}
explicit PythonDictionary(PyInitialValue value);
PythonDictionary(PyRefType type, PyObject *o);
PythonDictionary(const PythonDictionary &dict);
@@ -357,7 +390,14 @@ class PythonModule : public PythonObject
static bool Check(PyObject *py_obj);
- static PythonModule MainModule();
+ static PythonModule
+ BuiltinsModule();
+
+ static PythonModule
+ MainModule();
+
+ static PythonModule
+ AddModule(llvm::StringRef module);
// Bring in the no-argument base class version
using PythonObject::Reset;
@@ -367,6 +407,35 @@ class PythonModule : public PythonObject
PythonDictionary GetDictionary() const;
};
+class PythonCallable : public PythonObject
+{
+public:
+ PythonCallable();
+ PythonCallable(PyRefType type, PyObject *o);
+ PythonCallable(const PythonCallable &dict);
+
+ ~PythonCallable() override;
+
+ static bool
+ Check(PyObject *py_obj);
+
+ // Bring in the no-argument base class version
+ using PythonObject::Reset;
+
+ void
+ Reset(PyRefType type, PyObject *py_obj) override;
+
+ void
+ GetNumArguments(size_t &num_args, bool &has_varargs, bool &has_kwargs) const;
+
+ PythonObject
+ operator ()(std::initializer_list<PyObject*> args);
+
+ PythonObject
+ operator ()(std::initializer_list<PythonObject> args);
+};
+
+
class PythonFile : public PythonObject
{
public:
OpenPOWER on IntegriCloud