diff options
author | Zachary Turner <zturner@google.com> | 2015-11-12 16:23:16 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2015-11-12 16:23:16 +0000 |
commit | b58fb2f47a4f792fed292b139c2b2a325ed3abb5 (patch) | |
tree | fcf7947f8aba5ab719b7edad32300c10db75e777 /lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h | |
parent | 183c010c9a36ff131288c15b324f1c2f7d6a0a50 (diff) | |
download | llvm-b58fb2f47a4f792fed292b139c2b2a325ed3abb5.zip llvm-b58fb2f47a4f792fed292b139c2b2a325ed3abb5.tar.gz llvm-b58fb2f47a4f792fed292b139c2b2a325ed3abb5.tar.bz2 |
Begin converting uses of PyCallable to PythonCallable.
PyCallable is a class that exists solely within the swig wrapper
code. PythonCallable is a more generic implementation of the same
idea that can be used by any Python-related interop code, and lives
in PythonDataObjects.h
The CL is mostly mechanical, and it doesn't cover every possible
user of PyCallable, because I want to minimize the impact of this
change (as well as making it easier to figure out what went wrong
in case this causes a failure). I plan to finish up the rest of
the changes in a subsequent patch, culminating in the removal of
PyCallable entirely.
llvm-svn: 252906
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h')
-rw-r--r-- | lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h index 22c86fd..3794cc04 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h +++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h @@ -207,9 +207,23 @@ public: static PythonObject ResolveNameWithDictionary(llvm::StringRef name, PythonDictionary dict); + template<typename T> + static T + ResolveNameWithDictionary(llvm::StringRef name, PythonDictionary dict) + { + return ResolveNameWithDictionary(name, dict).AsType<T>(); + } + PythonObject ResolveName(llvm::StringRef name) const; + template<typename T> + T + ResolveName(llvm::StringRef name) const + { + return ResolveName(name).AsType<T>(); + } + bool HasAttribute(llvm::StringRef attribute) const; @@ -410,6 +424,12 @@ class PythonModule : public PythonObject class PythonCallable : public PythonObject { public: + struct ArgInfo { + size_t count; + bool has_varargs : 1; + bool has_kwargs : 1; + }; + PythonCallable(); PythonCallable(PyRefType type, PyObject *o); PythonCallable(const PythonCallable &dict); @@ -425,14 +445,24 @@ public: void Reset(PyRefType type, PyObject *py_obj) override; - void - GetNumArguments(size_t &num_args, bool &has_varargs, bool &has_kwargs) const; + ArgInfo + GetNumArguments() const; + + PythonObject + operator ()(); PythonObject operator ()(std::initializer_list<PyObject*> args); PythonObject operator ()(std::initializer_list<PythonObject> args); + + template<typename Arg, typename... Args> + PythonObject + operator ()(const Arg &arg, Args... args) + { + return operator()({ arg, args... }); + } }; |