From a140514733e0ab0310688c727b70ba3e2a4a8ddc Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Wed, 11 Nov 2015 19:42:27 +0000 Subject: 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 --- .../ScriptInterpreter/Python/PythonDataObjects.h | 73 +++++++++++++++++++++- 1 file changed, 71 insertions(+), 2 deletions(-) (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h') 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 objects); + PythonTuple(std::initializer_list 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 args); + + PythonObject + operator ()(std::initializer_list args); +}; + + class PythonFile : public PythonObject { public: -- cgit v1.2.3