33 std::vector<PyCallable*>* overloads =
nullptr) {
38 PyObject* pyncl = PyUnicode_FromString(ncl.c_str());
45 PyType_Type.tp_setattro(pyclass, pyncl, (
PyObject*)pytmpl);
55 for (
auto clb : *overloads)
58 for (
auto clb : *overloads)
74 return PyType_Type.tp_alloc(meta,
nitems);
92 return PyType_Type.tp_dealloc((
PyObject*)scope);
98 return PyUnicode_FromString(
"CPPInstance_Type");
99 return PyUnicode_FromString(
106 return PyUnicode_FromString(
"cppjit.gbl");
114 return PyUnicode_FromString(
const_cast<char*
>(
"cppjit.gbl"));
127 PyUnicode_AppendAndDel(&pymodule, PyUnicode_FromString(
"."));
128 PyUnicode_AppendAndDel(&pymodule, pymodname);
141 return PyUnicode_FromString((
"cppjit.gbl." + modname).c_str());
147 PyErr_SetString(PyExc_AttributeError,
148 "attribute \'__module__\' of 'cppjit.CPPScope\' objects is "
153 const char* newname = PyUnicode_AsUTF8(
value);
158 Py_ssize_t sz = PyUnicode_GET_LENGTH(
value);
170 return PyUnicode_FromFormat(
171 const_cast<char*
>(
"<class cppjit.CPPInstance at %p>"), scope);
175 return PyType_Type.tp_repr((
PyObject*)scope);
180 return PyType_Type.tp_repr((
PyObject*)scope);
189 PyUnicode_FromFormat(
"<%s %s.%s at %p>", kind, PyUnicode_AsUTF8(modname),
190 clName.c_str(), scope);
230 result->fOperators =
nullptr;
231 result->fModuleName =
nullptr;
241 !strstr(subtype->tp_name,
"_meta") ) {
258 if (3 <= PyTuple_GET_SIZE(args)) {
259 PyObject* dct = PyTuple_GET_ITEM(args, 2);
260 Py_ssize_t sz = PyDict_Size(dct);
263 if (1 < PyTuple_GET_SIZE(PyTuple_GET_ITEM(args, 1)))
265 std::ostringstream errmsg;
267 PyErr_Format(PyExc_TypeError,
268 "no python-side overrides supported (%s)",
269 errmsg.str().c_str());
275 PyObject* bname = PyUnicode_FromString(
286 }
else if (sz == (Py_ssize_t)-1)
312 result->fImp.fCppObjects =
nullptr;
315 result->fImp.fUsing =
nullptr;
319 if (PyErr_Occurred()) {
330 PyObject*
attr = PyType_Type.tp_getattro(pyclass, pyname);
334 PyObject* possibly_shadowed =
nullptr;
345 PyObject* attr_from_dict = PyObject_GetItem(dct, pyname);
347 if (attr_from_dict) {
349 return attr_from_dict;
351 possibly_shadowed =
attr;
363 return possibly_shadowed;
366 std::string
name = PyUnicode_AsUTF8(pyname);
367 if (
name.size() >= 5 &&
name.compare(0, 2,
"__") == 0 &&
369 return possibly_shadowed;
372 std::vector<Utility::PyError_t> errors;
383 bool templated_functions_checked =
false;
394 const std::vector<interop::TCppMethod_t> methods =
396 if (!methods.empty()) {
398 std::vector<PyCallable*> overloads;
399 for (
auto method : methods) {
400 overloads.push_back(
new CPPFunction(scope, method));
410 templated_functions_checked =
true;
422 const std::string& cpd =
439 if (!
attr && !templated_functions_checked) {
444 PyErr_Format(PyExc_TypeError,
"\'%s\' is not a known C++ template",
459 PyErr_Format(PyExc_TypeError,
"\'%s\' is not a known C++ enum",
468 PyType_Type.tp_setattro((
PyObject*)Py_TYPE(pyclass), pyname,
attr);
472 attr = PyType_Type.tp_getattro(pyclass, pyname);
473 if (!
attr && PyErr_Occurred())
476 PyType_Type.tp_setattro(pyclass, pyname,
attr);
485 const std::vector<interop::TCppScope_t>& uv =
493 klass->
fImp.
fUsing =
new std::vector<PyObject*>;
496 for (
auto uid : uv) {
500 klass->
fImp.
fUsing->push_back(PyWeakref_NewRef(pyuscope,
nullptr));
503 PyUnicode_FromString((
"__lifeline_" + uname).c_str());
504 PyType_Type.tp_setattro(pyclass, llname, pyuscope);
518 attr = PyObject_GetAttr(pyuscope, pyname);
532 if (possibly_shadowed) {
534 Py_DECREF(possibly_shadowed);
536 attr = possibly_shadowed;
537 PyType_Type.tp_setattro(pyclass, pyname,
attr);
546 PyObject *pytype = 0, *pyvalue = 0, *pytrace = 0;
547 PyErr_Fetch(&pytype, &pyvalue, &pytrace);
548 PyObject* sklass = PyObject_Str(pyclass);
549 PyErr_Restore(pytype, pyvalue, pytrace);
551 topmsg = PyUnicode_FromFormat(
552 "%s has no attribute \'%s\'. Full details:", PyUnicode_AsUTF8(sklass),
553 PyUnicode_AsUTF8(pyname));
556 topmsg = PyUnicode_FromFormat(
"no such attribute \'%s\'. Full details:",
557 PyUnicode_AsUTF8(pyname));
559 SetDetailedException(std::move(errors), topmsg ,
560 PyExc_AttributeError );
576 std::string
name = PyUnicode_AsUTF8(pyname);
586 return PyType_Type.tp_setattro(pyclass, pyname, pyval);
594 if (!PyArg_ParseTuple(args,
const_cast<char*
>(
"i|i:__cpp_reflex__"), &request,
615 PyErr_Format(PyExc_ValueError,
"unsupported reflex request %d or format %d",
632 return PyList_New(0);
635 PyErr_SetString(PyExc_TypeError,
"C++ proxy scope expected");
643 std::set<std::string> cppnames;
647 std::set<std::string> dir_cppnames;
648 for (
const std::string&
name : cppnames) {
649 if (
name.find(
"__", 0, 2) != std::string::npos ||
650 name.find(
"<") != std::string::npos ||
651 name.find(
"operator", 0, 8) != std::string::npos)
653 dir_cppnames.insert(
name);
657 for (Py_ssize_t i = 0; i < PyList_GET_SIZE(dirlist); ++i)
658 dir_cppnames.insert(PyUnicode_AsUTF8(PyList_GET_ITEM(dirlist, i)));
661 dirlist = PyList_New(dir_cppnames.size());
665 for (
const auto&
name : dir_cppnames) {
666 PyList_SET_ITEM(dirlist, i++, PyUnicode_FromString(
name.c_str()));
673 {(
char*)
"__cpp_reflex__", (PyCFunction)
meta_reflex, METH_VARARGS,
674 (
char*)
"C++ datamember reflection information"},
675 {(
char*)
"__dir__", (PyCFunction)
meta_dir, METH_NOARGS,
nullptr},
676 {(
char*)
nullptr,
nullptr, 0,
nullptr}};
680 {(
char*)
"__cpp_name__", (getter)
meta_getcppname,
nullptr,
nullptr,
nullptr},
683 {(
char*)
nullptr,
nullptr,
nullptr,
nullptr,
nullptr}};
687 PyVarObject_HEAD_INIT(&PyType_Type, 0)(
char*)
"cppjit.CPPScope",
705 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
706 Py_TPFLAGS_TYPE_SUBCLASS,
707 (
char*)
"cpyrt metatype (internal)",
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t nitems
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t attr
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t format
Utility::PyOperators * fOperators
std::vector< PyObject * > * fUsing
union cppjit::cpyrt::CPPScope::@183 fImp
CppToPyMap_t * fCppObjects
interop::TCppScope_t fCppType
void AdoptTemplate(PyCallable *pc)
void AdoptMethod(PyCallable *pc)
#define CPYRT_PYTYPE_TAIL
static PyObject * cpyrt_GetWeakRef(PyObject *ref)
std::string clean_type(const std::string &cppname, bool template_strip=true, bool const_strip=true)
std::string compound(const std::string &name)
void cppscope_to_pyscope(std::string &cppscope)
size_t FetchError(std::vector< PyError_t > &, bool is_cpp=false)
static int meta_setattro(PyObject *pyclass, PyObject *pyname, PyObject *pyval)
static PyObject * meta_reflex(CPPScope *klass, PyObject *args)
bool InsertDispatcher(CPPScope *klass, PyObject *bases, PyObject *dct, std::ostringstream &err)
TemplateProxy * TemplateProxy_New(const std::string &cppname, const std::string &pyname, PyObject *pyclass)
PyObject * CreateExcScopeProxy(PyObject *pyscope, PyObject *pyname, PyObject *parent)
static PyObject * meta_alloc(PyTypeObject *meta, Py_ssize_t nitems)
PyTypeObject CPPScope_Type
PyTypeObject TypedefPointerToClass_Type
static PyObject * meta_dir(CPPScope *klass)
PyTypeObject CPPInstance_Type
PyObject * GetScopeProxy(interop::TCppScope_t)
static void meta_dealloc(CPPScope *scope)
static PyObject * meta_getmodule(CPPScope *scope, void *)
static PyObject * pt_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)
static PyGetSetDef meta_getset[]
bool TemplateProxy_CheckExact(T *object)
static PyObject * meta_repr(CPPScope *scope)
PyObject * CreateScopeProxy(PyObject *, PyObject *args)
bool CPPDataMember_Check(T *object)
bool CPPScope_CheckExact(T *object)
std::unordered_map< interop::TCppObject_t, PyObject * > CppToPyMap_t
Type object to hold class reference (this is only semantically a presentation of CPPScope instances,...
static PyObject * add_template(PyObject *pyclass, const std::string &name, std::vector< PyCallable * > *overloads=nullptr)
static PyMethodDef meta_methods[]
bool CPPScope_Check(T *object)
CPPEnum * CPPEnum_New(const std::string &name, interop::TCppScope_t scope)
static int meta_setmodule(CPPScope *scope, PyObject *value, void *)
CPPOverload * CPPOverload_New(const std::string &name, std::vector< PyCallable * > &methods)
CPPDataMember * CPPDataMember_New(interop::TCppScope_t scope, interop::TCppScope_t var)
static PyObject * meta_getattro(PyObject *pyclass, PyObject *pyname)
static PyObject * meta_getcppname(CPPScope *scope, void *)
const RequestId_t IS_AGGREGATE
const RequestId_t IS_NAMESPACE
TCppType_t GetTypeFromScope(TCppScope_t klass)
std::string GetTypeAsString(TCppType_t type)
bool ExistsMethodTemplate(TCppScope_t scope, const std::string &name)
bool HasVirtualDestructor(TCppScope_t type)
TCppScope_t GetParentScope(TCppScope_t scope)
bool IsSubclass(TCppScope_t derived, TCppScope_t base)
TCppScope_t GetNamed(const std::string &scope_name, TCppScope_t parent_scope=TCppScope_t{})
Cpp::FuncRef TCppMethod_t
bool IsTypedefed(TCppScope_t scope)
bool IsEnumScope(TCppScope_t scope)
TCppType_t ResolveType(TCppType_t cppitem_name)
TCppScope_t GetUnderlyingScope(TCppScope_t scope)
TCppScope_t GetGlobalScope()
std::vector< TCppMethod_t > GetMethodsFromName(TCppScope_t scope, const std::string &name)
bool IsNamespace(TCppScope_t scope)
TCppScope_t GetScopeFromType(TCppType_t type)
std::string GetBaseName(TCppScope_t klass, TCppIndex_t ibase)
TCppScope_t GetScope(const std::string &scope_name, TCppScope_t parent_scope=TCppScope_t{})
bool IsEnumConstant(TCppScope_t scope)
std::string GetFinalName(TCppScope_t type)
bool IsVariable(TCppScope_t scope)
bool GetSmartPtrInfo(const std::string &, TCppScope_t *raw, TCppMethod_t *deref)
std::vector< TCppScope_t > GetUsingNamespaces(TCppScope_t)
bool IsAggregate(TCppScope_t type)
std::string GetScopedFinalName(TCppScope_t type)
void GetAllCppNames(TCppScope_t scope, std::set< std::string > &cppnames)
Custom "builtins," detectable by type, for pass by ref and improved performance.
PyObject_HEAD interop::TCppScope_t fCppType