19f2f44ceSEd Maste //===-- PythonDataObjects.h--------------------------------------*- C++ -*-===// 29f2f44ceSEd Maste // 39f2f44ceSEd Maste // The LLVM Compiler Infrastructure 49f2f44ceSEd Maste // 59f2f44ceSEd Maste // This file is distributed under the University of Illinois Open Source 69f2f44ceSEd Maste // License. See LICENSE.TXT for details. 79f2f44ceSEd Maste // 89f2f44ceSEd Maste //===----------------------------------------------------------------------===// 99f2f44ceSEd Maste 109f2f44ceSEd Maste #ifndef LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_PYTHONDATAOBJECTS_H 119f2f44ceSEd Maste #define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_PYTHONDATAOBJECTS_H 129f2f44ceSEd Maste 139f2f44ceSEd Maste #ifndef LLDB_DISABLE_PYTHON 149f2f44ceSEd Maste 15435933ddSDimitry Andric // LLDB Python header must be included first 16435933ddSDimitry Andric #include "lldb-python.h" 17435933ddSDimitry Andric 18f678e45dSDimitry Andric #include "lldb/Utility/Flags.h" 19f678e45dSDimitry Andric 209f2f44ceSEd Maste #include "lldb/Host/File.h" 219f2f44ceSEd Maste #include "lldb/Interpreter/OptionValue.h" 22f678e45dSDimitry Andric #include "lldb/Utility/ConstString.h" 23a580b014SDimitry Andric #include "lldb/Utility/StructuredData.h" 24435933ddSDimitry Andric #include "lldb/lldb-defines.h" 259f2f44ceSEd Maste 26444ed5c5SDimitry Andric #include "llvm/ADT/ArrayRef.h" 27444ed5c5SDimitry Andric 289f2f44ceSEd Maste namespace lldb_private { 299f2f44ceSEd Maste 30444ed5c5SDimitry Andric class PythonBytes; 319f2f44ceSEd Maste class PythonString; 329f2f44ceSEd Maste class PythonList; 339f2f44ceSEd Maste class PythonDictionary; 349f2f44ceSEd Maste class PythonInteger; 359f2f44ceSEd Maste 36435933ddSDimitry Andric class StructuredPythonObject : public StructuredData::Generic { 379f2f44ceSEd Maste public: StructuredPythonObject()38435933ddSDimitry Andric StructuredPythonObject() : StructuredData::Generic() {} 399f2f44ceSEd Maste StructuredPythonObject(void * obj)40435933ddSDimitry Andric StructuredPythonObject(void *obj) : StructuredData::Generic(obj) { 419f2f44ceSEd Maste Py_XINCREF(GetValue()); 429f2f44ceSEd Maste } 439f2f44ceSEd Maste ~StructuredPythonObject()44435933ddSDimitry Andric ~StructuredPythonObject() override { 459f2f44ceSEd Maste if (Py_IsInitialized()) 469f2f44ceSEd Maste Py_XDECREF(GetValue()); 479f2f44ceSEd Maste SetValue(nullptr); 489f2f44ceSEd Maste } 499f2f44ceSEd Maste IsValid()50435933ddSDimitry Andric bool IsValid() const override { return GetValue() && GetValue() != Py_None; } 519f2f44ceSEd Maste 52435933ddSDimitry Andric void Dump(Stream &s, bool pretty_print = true) const override; 539f2f44ceSEd Maste 549f2f44ceSEd Maste private: 559f2f44ceSEd Maste DISALLOW_COPY_AND_ASSIGN(StructuredPythonObject); 569f2f44ceSEd Maste }; 579f2f44ceSEd Maste 58435933ddSDimitry Andric enum class PyObjectType { 599f2f44ceSEd Maste Unknown, 609f2f44ceSEd Maste None, 619f2f44ceSEd Maste Integer, 629f2f44ceSEd Maste Dictionary, 639f2f44ceSEd Maste List, 649f2f44ceSEd Maste String, 65444ed5c5SDimitry Andric Bytes, 664bb0738eSEd Maste ByteArray, 679f2f44ceSEd Maste Module, 689f2f44ceSEd Maste Callable, 699f2f44ceSEd Maste Tuple, 709f2f44ceSEd Maste File 719f2f44ceSEd Maste }; 729f2f44ceSEd Maste 73435933ddSDimitry Andric enum class PyRefType { 749f2f44ceSEd Maste Borrowed, // We are not given ownership of the incoming PyObject. 759f2f44ceSEd Maste // We cannot safely hold it without calling Py_INCREF. 769f2f44ceSEd Maste Owned // We have ownership of the incoming PyObject. We should 779f2f44ceSEd Maste // not call Py_INCREF. 789f2f44ceSEd Maste }; 799f2f44ceSEd Maste 80435933ddSDimitry Andric enum class PyInitialValue { Invalid, Empty }; 819f2f44ceSEd Maste 82435933ddSDimitry Andric class PythonObject { 839f2f44ceSEd Maste public: PythonObject()84435933ddSDimitry Andric PythonObject() : m_py_obj(nullptr) {} 859f2f44ceSEd Maste PythonObject(PyRefType type,PyObject * py_obj)86435933ddSDimitry Andric PythonObject(PyRefType type, PyObject *py_obj) : m_py_obj(nullptr) { 879f2f44ceSEd Maste Reset(type, py_obj); 889f2f44ceSEd Maste } 899f2f44ceSEd Maste PythonObject(const PythonObject & rhs)90435933ddSDimitry Andric PythonObject(const PythonObject &rhs) : m_py_obj(nullptr) { Reset(rhs); } 919f2f44ceSEd Maste ~PythonObject()92435933ddSDimitry Andric virtual ~PythonObject() { Reset(); } 939f2f44ceSEd Maste Reset()94435933ddSDimitry Andric void Reset() { 959f2f44ceSEd Maste // Avoid calling the virtual method since it's not necessary 969f2f44ceSEd Maste // to actually validate the type of the PyObject if we're 979f2f44ceSEd Maste // just setting to null. 989f2f44ceSEd Maste if (Py_IsInitialized()) 999f2f44ceSEd Maste Py_XDECREF(m_py_obj); 1009f2f44ceSEd Maste m_py_obj = nullptr; 1019f2f44ceSEd Maste } 1029f2f44ceSEd Maste Reset(const PythonObject & rhs)103435933ddSDimitry Andric void Reset(const PythonObject &rhs) { 1049f2f44ceSEd Maste // Avoid calling the virtual method if it's not necessary 1059f2f44ceSEd Maste // to actually validate the type of the PyObject. 1069f2f44ceSEd Maste if (!rhs.IsValid()) 1079f2f44ceSEd Maste Reset(); 1089f2f44ceSEd Maste else 1099f2f44ceSEd Maste Reset(PyRefType::Borrowed, rhs.m_py_obj); 1109f2f44ceSEd Maste } 1119f2f44ceSEd Maste 1129f2f44ceSEd Maste // PythonObject is implicitly convertible to PyObject *, which will call the 1139f2f44ceSEd Maste // wrong overload. We want to explicitly disallow this, since a PyObject 1149f2f44ceSEd Maste // *always* owns its reference. Therefore the overload which takes a 1159f2f44ceSEd Maste // PyRefType doesn't make sense, and the copy constructor should be used. 116435933ddSDimitry Andric void Reset(PyRefType type, const PythonObject &ref) = delete; 1179f2f44ceSEd Maste Reset(PyRefType type,PyObject * py_obj)118435933ddSDimitry Andric virtual void Reset(PyRefType type, PyObject *py_obj) { 1199f2f44ceSEd Maste if (py_obj == m_py_obj) 1209f2f44ceSEd Maste return; 1219f2f44ceSEd Maste 1229f2f44ceSEd Maste if (Py_IsInitialized()) 1239f2f44ceSEd Maste Py_XDECREF(m_py_obj); 1249f2f44ceSEd Maste 1259f2f44ceSEd Maste m_py_obj = py_obj; 1269f2f44ceSEd Maste 1279f2f44ceSEd Maste // If this is a borrowed reference, we need to convert it to 1289f2f44ceSEd Maste // an owned reference by incrementing it. If it is an owned 1299f2f44ceSEd Maste // reference (for example the caller allocated it with PyDict_New() 1309f2f44ceSEd Maste // then we must *not* increment it. 1319f2f44ceSEd Maste if (Py_IsInitialized() && type == PyRefType::Borrowed) 1329f2f44ceSEd Maste Py_XINCREF(m_py_obj); 1339f2f44ceSEd Maste } 1349f2f44ceSEd Maste Dump()135435933ddSDimitry Andric void Dump() const { 1369f2f44ceSEd Maste if (m_py_obj) 1379f2f44ceSEd Maste _PyObject_Dump(m_py_obj); 1389f2f44ceSEd Maste else 1399f2f44ceSEd Maste puts("NULL"); 1409f2f44ceSEd Maste } 1419f2f44ceSEd Maste 142435933ddSDimitry Andric void Dump(Stream &strm) const; 1439f2f44ceSEd Maste get()144435933ddSDimitry Andric PyObject *get() const { return m_py_obj; } 1459f2f44ceSEd Maste release()146435933ddSDimitry Andric PyObject *release() { 1479f2f44ceSEd Maste PyObject *result = m_py_obj; 1489f2f44ceSEd Maste m_py_obj = nullptr; 1499f2f44ceSEd Maste return result; 1509f2f44ceSEd Maste } 1519f2f44ceSEd Maste 152435933ddSDimitry Andric PythonObject &operator=(const PythonObject &other) { 1539f2f44ceSEd Maste Reset(PyRefType::Borrowed, other.get()); 1549f2f44ceSEd Maste return *this; 1559f2f44ceSEd Maste } 1569f2f44ceSEd Maste 157435933ddSDimitry Andric PyObjectType GetObjectType() const; 1589f2f44ceSEd Maste 159435933ddSDimitry Andric PythonString Repr() const; 1609f2f44ceSEd Maste 161435933ddSDimitry Andric PythonString Str() const; 1629f2f44ceSEd Maste 163435933ddSDimitry Andric static PythonObject ResolveNameWithDictionary(llvm::StringRef name, 164435933ddSDimitry Andric const PythonDictionary &dict); 1659f2f44ceSEd Maste 1669f2f44ceSEd Maste template <typename T> ResolveNameWithDictionary(llvm::StringRef name,const PythonDictionary & dict)167435933ddSDimitry Andric static T ResolveNameWithDictionary(llvm::StringRef name, 168435933ddSDimitry Andric const PythonDictionary &dict) { 1699f2f44ceSEd Maste return ResolveNameWithDictionary(name, dict).AsType<T>(); 1709f2f44ceSEd Maste } 1719f2f44ceSEd Maste 172435933ddSDimitry Andric PythonObject ResolveName(llvm::StringRef name) const; 1739f2f44ceSEd Maste ResolveName(llvm::StringRef name)174435933ddSDimitry Andric template <typename T> T ResolveName(llvm::StringRef name) const { 1759f2f44ceSEd Maste return ResolveName(name).AsType<T>(); 1769f2f44ceSEd Maste } 1779f2f44ceSEd Maste 178435933ddSDimitry Andric bool HasAttribute(llvm::StringRef attribute) const; 1799f2f44ceSEd Maste 180435933ddSDimitry Andric PythonObject GetAttributeValue(llvm::StringRef attribute) const; 1819f2f44ceSEd Maste 182435933ddSDimitry Andric bool IsValid() const; 1839f2f44ceSEd Maste 184435933ddSDimitry Andric bool IsAllocated() const; 1859f2f44ceSEd Maste 186435933ddSDimitry Andric bool IsNone() const; 1879f2f44ceSEd Maste AsType()188435933ddSDimitry Andric template <typename T> T AsType() const { 1899f2f44ceSEd Maste if (!T::Check(m_py_obj)) 1909f2f44ceSEd Maste return T(); 1919f2f44ceSEd Maste return T(PyRefType::Borrowed, m_py_obj); 1929f2f44ceSEd Maste } 1939f2f44ceSEd Maste 194435933ddSDimitry Andric StructuredData::ObjectSP CreateStructuredObject() const; 1959f2f44ceSEd Maste 1969f2f44ceSEd Maste protected: 1979f2f44ceSEd Maste PyObject *m_py_obj; 1989f2f44ceSEd Maste }; 1999f2f44ceSEd Maste 200435933ddSDimitry Andric class PythonBytes : public PythonObject { 201444ed5c5SDimitry Andric public: 202444ed5c5SDimitry Andric PythonBytes(); 203444ed5c5SDimitry Andric explicit PythonBytes(llvm::ArrayRef<uint8_t> bytes); 204444ed5c5SDimitry Andric PythonBytes(const uint8_t *bytes, size_t length); 205444ed5c5SDimitry Andric PythonBytes(PyRefType type, PyObject *o); 206444ed5c5SDimitry Andric PythonBytes(const PythonBytes &object); 207444ed5c5SDimitry Andric 208444ed5c5SDimitry Andric ~PythonBytes() override; 209444ed5c5SDimitry Andric 210435933ddSDimitry Andric static bool Check(PyObject *py_obj); 211444ed5c5SDimitry Andric 212444ed5c5SDimitry Andric // Bring in the no-argument base class version 213444ed5c5SDimitry Andric using PythonObject::Reset; 214444ed5c5SDimitry Andric 215435933ddSDimitry Andric void Reset(PyRefType type, PyObject *py_obj) override; 216444ed5c5SDimitry Andric 217435933ddSDimitry Andric llvm::ArrayRef<uint8_t> GetBytes() const; 218444ed5c5SDimitry Andric 219435933ddSDimitry Andric size_t GetSize() const; 220444ed5c5SDimitry Andric 221435933ddSDimitry Andric void SetBytes(llvm::ArrayRef<uint8_t> stringbytes); 222444ed5c5SDimitry Andric 223435933ddSDimitry Andric StructuredData::StringSP CreateStructuredString() const; 224444ed5c5SDimitry Andric }; 225444ed5c5SDimitry Andric 226435933ddSDimitry Andric class PythonByteArray : public PythonObject { 2274bb0738eSEd Maste public: 2284bb0738eSEd Maste PythonByteArray(); 2294bb0738eSEd Maste explicit PythonByteArray(llvm::ArrayRef<uint8_t> bytes); 2304bb0738eSEd Maste PythonByteArray(const uint8_t *bytes, size_t length); 2314bb0738eSEd Maste PythonByteArray(PyRefType type, PyObject *o); 2324bb0738eSEd Maste PythonByteArray(const PythonBytes &object); 2334bb0738eSEd Maste 2344bb0738eSEd Maste ~PythonByteArray() override; 2354bb0738eSEd Maste 236435933ddSDimitry Andric static bool Check(PyObject *py_obj); 2374bb0738eSEd Maste 2384bb0738eSEd Maste // Bring in the no-argument base class version 2394bb0738eSEd Maste using PythonObject::Reset; 2404bb0738eSEd Maste 241435933ddSDimitry Andric void Reset(PyRefType type, PyObject *py_obj) override; 2424bb0738eSEd Maste 243435933ddSDimitry Andric llvm::ArrayRef<uint8_t> GetBytes() const; 2444bb0738eSEd Maste 245435933ddSDimitry Andric size_t GetSize() const; 2464bb0738eSEd Maste 247435933ddSDimitry Andric void SetBytes(llvm::ArrayRef<uint8_t> stringbytes); 2484bb0738eSEd Maste 249435933ddSDimitry Andric StructuredData::StringSP CreateStructuredString() const; 2504bb0738eSEd Maste }; 2514bb0738eSEd Maste 252435933ddSDimitry Andric class PythonString : public PythonObject { 2539f2f44ceSEd Maste public: 2549f2f44ceSEd Maste PythonString(); 2559f2f44ceSEd Maste explicit PythonString(llvm::StringRef string); 2569f2f44ceSEd Maste explicit PythonString(const char *string); 2579f2f44ceSEd Maste PythonString(PyRefType type, PyObject *o); 2589f2f44ceSEd Maste PythonString(const PythonString &object); 2599f2f44ceSEd Maste 2609f2f44ceSEd Maste ~PythonString() override; 2619f2f44ceSEd Maste 2629f2f44ceSEd Maste static bool Check(PyObject *py_obj); 2639f2f44ceSEd Maste 2649f2f44ceSEd Maste // Bring in the no-argument base class version 2659f2f44ceSEd Maste using PythonObject::Reset; 2669f2f44ceSEd Maste 2679f2f44ceSEd Maste void Reset(PyRefType type, PyObject *py_obj) override; 2689f2f44ceSEd Maste 269435933ddSDimitry Andric llvm::StringRef GetString() const; 2709f2f44ceSEd Maste 271435933ddSDimitry Andric size_t GetSize() const; 2729f2f44ceSEd Maste 2739f2f44ceSEd Maste void SetString(llvm::StringRef string); 2749f2f44ceSEd Maste 2759f2f44ceSEd Maste StructuredData::StringSP CreateStructuredString() const; 2769f2f44ceSEd Maste }; 2779f2f44ceSEd Maste 278435933ddSDimitry Andric class PythonInteger : public PythonObject { 2799f2f44ceSEd Maste public: 2809f2f44ceSEd Maste PythonInteger(); 2819f2f44ceSEd Maste explicit PythonInteger(int64_t value); 2829f2f44ceSEd Maste PythonInteger(PyRefType type, PyObject *o); 2839f2f44ceSEd Maste PythonInteger(const PythonInteger &object); 2849f2f44ceSEd Maste 2859f2f44ceSEd Maste ~PythonInteger() override; 2869f2f44ceSEd Maste 2879f2f44ceSEd Maste static bool Check(PyObject *py_obj); 2889f2f44ceSEd Maste 2899f2f44ceSEd Maste // Bring in the no-argument base class version 2909f2f44ceSEd Maste using PythonObject::Reset; 2919f2f44ceSEd Maste 2929f2f44ceSEd Maste void Reset(PyRefType type, PyObject *py_obj) override; 2939f2f44ceSEd Maste 2949f2f44ceSEd Maste int64_t GetInteger() const; 2959f2f44ceSEd Maste 296435933ddSDimitry Andric void SetInteger(int64_t value); 2979f2f44ceSEd Maste 2989f2f44ceSEd Maste StructuredData::IntegerSP CreateStructuredInteger() const; 2999f2f44ceSEd Maste }; 3009f2f44ceSEd Maste 301435933ddSDimitry Andric class PythonList : public PythonObject { 3029f2f44ceSEd Maste public: PythonList()3039f2f44ceSEd Maste PythonList() {} 3049f2f44ceSEd Maste explicit PythonList(PyInitialValue value); 3059f2f44ceSEd Maste explicit PythonList(int list_size); 3069f2f44ceSEd Maste PythonList(PyRefType type, PyObject *o); 3079f2f44ceSEd Maste PythonList(const PythonList &list); 3089f2f44ceSEd Maste 3099f2f44ceSEd Maste ~PythonList() override; 3109f2f44ceSEd Maste 3119f2f44ceSEd Maste static bool Check(PyObject *py_obj); 3129f2f44ceSEd Maste 3139f2f44ceSEd Maste // Bring in the no-argument base class version 3149f2f44ceSEd Maste using PythonObject::Reset; 3159f2f44ceSEd Maste 3169f2f44ceSEd Maste void Reset(PyRefType type, PyObject *py_obj) override; 3179f2f44ceSEd Maste 3189f2f44ceSEd Maste uint32_t GetSize() const; 3199f2f44ceSEd Maste 3209f2f44ceSEd Maste PythonObject GetItemAtIndex(uint32_t index) const; 3219f2f44ceSEd Maste 3229f2f44ceSEd Maste void SetItemAtIndex(uint32_t index, const PythonObject &object); 3239f2f44ceSEd Maste 3249f2f44ceSEd Maste void AppendItem(const PythonObject &object); 3259f2f44ceSEd Maste 3269f2f44ceSEd Maste StructuredData::ArraySP CreateStructuredArray() const; 3279f2f44ceSEd Maste }; 3289f2f44ceSEd Maste 329435933ddSDimitry Andric class PythonTuple : public PythonObject { 3309f2f44ceSEd Maste public: PythonTuple()3319f2f44ceSEd Maste PythonTuple() {} 3329f2f44ceSEd Maste explicit PythonTuple(PyInitialValue value); 3339f2f44ceSEd Maste explicit PythonTuple(int tuple_size); 3349f2f44ceSEd Maste PythonTuple(PyRefType type, PyObject *o); 3359f2f44ceSEd Maste PythonTuple(const PythonTuple &tuple); 3369f2f44ceSEd Maste PythonTuple(std::initializer_list<PythonObject> objects); 3379f2f44ceSEd Maste PythonTuple(std::initializer_list<PyObject *> objects); 3389f2f44ceSEd Maste 3399f2f44ceSEd Maste ~PythonTuple() override; 3409f2f44ceSEd Maste 3419f2f44ceSEd Maste static bool Check(PyObject *py_obj); 3429f2f44ceSEd Maste 3439f2f44ceSEd Maste // Bring in the no-argument base class version 3449f2f44ceSEd Maste using PythonObject::Reset; 3459f2f44ceSEd Maste 3469f2f44ceSEd Maste void Reset(PyRefType type, PyObject *py_obj) override; 3479f2f44ceSEd Maste 3489f2f44ceSEd Maste uint32_t GetSize() const; 3499f2f44ceSEd Maste 3509f2f44ceSEd Maste PythonObject GetItemAtIndex(uint32_t index) const; 3519f2f44ceSEd Maste 3529f2f44ceSEd Maste void SetItemAtIndex(uint32_t index, const PythonObject &object); 3539f2f44ceSEd Maste 3549f2f44ceSEd Maste StructuredData::ArraySP CreateStructuredArray() const; 3559f2f44ceSEd Maste }; 3569f2f44ceSEd Maste 357435933ddSDimitry Andric class PythonDictionary : public PythonObject { 3589f2f44ceSEd Maste public: PythonDictionary()3599f2f44ceSEd Maste PythonDictionary() {} 3609f2f44ceSEd Maste explicit PythonDictionary(PyInitialValue value); 3619f2f44ceSEd Maste PythonDictionary(PyRefType type, PyObject *o); 3629f2f44ceSEd Maste PythonDictionary(const PythonDictionary &dict); 3639f2f44ceSEd Maste 3649f2f44ceSEd Maste ~PythonDictionary() override; 3659f2f44ceSEd Maste 3669f2f44ceSEd Maste static bool Check(PyObject *py_obj); 3679f2f44ceSEd Maste 3689f2f44ceSEd Maste // Bring in the no-argument base class version 3699f2f44ceSEd Maste using PythonObject::Reset; 3709f2f44ceSEd Maste 3719f2f44ceSEd Maste void Reset(PyRefType type, PyObject *py_obj) override; 3729f2f44ceSEd Maste 3739f2f44ceSEd Maste uint32_t GetSize() const; 3749f2f44ceSEd Maste 3759f2f44ceSEd Maste PythonList GetKeys() const; 3769f2f44ceSEd Maste 3779f2f44ceSEd Maste PythonObject GetItemForKey(const PythonObject &key) const; 3789f2f44ceSEd Maste void SetItemForKey(const PythonObject &key, const PythonObject &value); 3799f2f44ceSEd Maste 3809f2f44ceSEd Maste StructuredData::DictionarySP CreateStructuredDictionary() const; 3819f2f44ceSEd Maste }; 3829f2f44ceSEd Maste 383435933ddSDimitry Andric class PythonModule : public PythonObject { 3849f2f44ceSEd Maste public: 3859f2f44ceSEd Maste PythonModule(); 3869f2f44ceSEd Maste PythonModule(PyRefType type, PyObject *o); 3879f2f44ceSEd Maste PythonModule(const PythonModule &dict); 3889f2f44ceSEd Maste 3899f2f44ceSEd Maste ~PythonModule() override; 3909f2f44ceSEd Maste 3919f2f44ceSEd Maste static bool Check(PyObject *py_obj); 3929f2f44ceSEd Maste 393435933ddSDimitry Andric static PythonModule BuiltinsModule(); 3949f2f44ceSEd Maste 395435933ddSDimitry Andric static PythonModule MainModule(); 3969f2f44ceSEd Maste 397435933ddSDimitry Andric static PythonModule AddModule(llvm::StringRef module); 3989f2f44ceSEd Maste 399435933ddSDimitry Andric static PythonModule ImportModule(llvm::StringRef module); 4009f2f44ceSEd Maste 4019f2f44ceSEd Maste // Bring in the no-argument base class version 4029f2f44ceSEd Maste using PythonObject::Reset; 4039f2f44ceSEd Maste 4049f2f44ceSEd Maste void Reset(PyRefType type, PyObject *py_obj) override; 4059f2f44ceSEd Maste 4069f2f44ceSEd Maste PythonDictionary GetDictionary() const; 4079f2f44ceSEd Maste }; 4089f2f44ceSEd Maste 409435933ddSDimitry Andric class PythonCallable : public PythonObject { 4109f2f44ceSEd Maste public: 4119f2f44ceSEd Maste struct ArgInfo { 4129f2f44ceSEd Maste size_t count; 4134bb0738eSEd Maste bool is_bound_method : 1; 4149f2f44ceSEd Maste bool has_varargs : 1; 4159f2f44ceSEd Maste bool has_kwargs : 1; 4169f2f44ceSEd Maste }; 4179f2f44ceSEd Maste 4189f2f44ceSEd Maste PythonCallable(); 4199f2f44ceSEd Maste PythonCallable(PyRefType type, PyObject *o); 4209f2f44ceSEd Maste PythonCallable(const PythonCallable &dict); 4219f2f44ceSEd Maste 4229f2f44ceSEd Maste ~PythonCallable() override; 4239f2f44ceSEd Maste 424435933ddSDimitry Andric static bool Check(PyObject *py_obj); 4259f2f44ceSEd Maste 4269f2f44ceSEd Maste // Bring in the no-argument base class version 4279f2f44ceSEd Maste using PythonObject::Reset; 4289f2f44ceSEd Maste 429435933ddSDimitry Andric void Reset(PyRefType type, PyObject *py_obj) override; 4309f2f44ceSEd Maste 431435933ddSDimitry Andric ArgInfo GetNumArguments() const; 4329f2f44ceSEd Maste 433435933ddSDimitry Andric PythonObject operator()(); 4349f2f44ceSEd Maste 435435933ddSDimitry Andric PythonObject operator()(std::initializer_list<PyObject *> args); 4369f2f44ceSEd Maste 437435933ddSDimitry Andric PythonObject operator()(std::initializer_list<PythonObject> args); 4389f2f44ceSEd Maste 4399f2f44ceSEd Maste template <typename Arg, typename... Args> operator()440435933ddSDimitry Andric PythonObject operator()(const Arg &arg, Args... args) { 4419f2f44ceSEd Maste return operator()({arg, args...}); 4429f2f44ceSEd Maste } 4439f2f44ceSEd Maste }; 4449f2f44ceSEd Maste 445435933ddSDimitry Andric class PythonFile : public PythonObject { 4469f2f44ceSEd Maste public: 4479f2f44ceSEd Maste PythonFile(); 4489f2f44ceSEd Maste PythonFile(File &file, const char *mode); 4499f2f44ceSEd Maste PythonFile(const char *path, const char *mode); 4509f2f44ceSEd Maste PythonFile(PyRefType type, PyObject *o); 4519f2f44ceSEd Maste 4529f2f44ceSEd Maste ~PythonFile() override; 4539f2f44ceSEd Maste 4549f2f44ceSEd Maste static bool Check(PyObject *py_obj); 4559f2f44ceSEd Maste 4569f2f44ceSEd Maste using PythonObject::Reset; 4579f2f44ceSEd Maste 4589f2f44ceSEd Maste void Reset(PyRefType type, PyObject *py_obj) override; 4599f2f44ceSEd Maste void Reset(File &file, const char *mode); 4609f2f44ceSEd Maste 4614bb0738eSEd Maste static uint32_t GetOptionsFromMode(llvm::StringRef mode); 4624bb0738eSEd Maste 4639f2f44ceSEd Maste bool GetUnderlyingFile(File &file) const; 4649f2f44ceSEd Maste }; 4659f2f44ceSEd Maste 4669f2f44ceSEd Maste } // namespace lldb_private 4679f2f44ceSEd Maste 4689f2f44ceSEd Maste #endif 4699f2f44ceSEd Maste 4709f2f44ceSEd Maste #endif // LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_PYTHONDATAOBJECTS_H 471