Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
cppjit_interop.h
Go to the documentation of this file.
1#ifndef CPPJIT_INTEROP_H
2#define CPPJIT_INTEROP_H
3
4#include <CppInterOp/CppInterOpTypes.h>
5#include <CppInterOp/Dispatch.h>
6
7// Standard
8#include <cassert>
9#include <set>
10#include <stddef.h>
11#include <stdint.h>
12#include <string>
13#include <vector>
14
15#include "callcontext.h"
16#include "precommondefs.h"
17
18// some more types; assumes cppjit_interop.h follows Python.h
19#ifndef PY_LONG_LONG
20#ifdef _WIN32
21typedef __int64 PY_LONG_LONG;
22#else
23typedef long long PY_LONG_LONG;
24#endif
25#endif
26
27#ifndef PY_ULONG_LONG
28#ifdef _WIN32
29typedef unsigned __int64 PY_ULONG_LONG;
30#else
31typedef unsigned long long PY_ULONG_LONG;
32#endif
33#endif
34
35#ifndef PY_LONG_DOUBLE
36typedef long double PY_LONG_DOUBLE;
37#endif
38
39namespace cppjit::interop {
40typedef Cpp::DeclRef TCppScope_t;
41typedef Cpp::TypeRef TCppType_t;
42typedef Cpp::ObjectRef TCppObject_t;
43typedef Cpp::FuncRef TCppMethod_t;
44typedef Cpp::InterpRef TInterp_t;
45typedef size_t TCppIndex_t;
46typedef void* TCppFuncAddr_t;
47
48// direct interpreter access -------------------------------------------------
50bool Compile(const std::string& code, bool silent = false);
51// the interpreter lock (ROOT's gInterpreterMutex when thread safety is on)
52// for Cpp:: calls made directly from Python; recursive, pair the calls
54void LockInterpreter();
58std::string ToString(TCppScope_t klass, TCppObject_t obj);
59
60// name to opaque C++ scope representation -----------------------------------
62std::string ResolveName(const std::string& cppitem_name);
74TCppType_t GetReferencedType(TCppType_t type, bool rvalue = false);
76std::string ResolveEnum(TCppScope_t enum_scope);
86bool IsIntegerType(TCppType_t type, bool* is_signed = nullptr);
92TCppType_t GetType(const std::string& name, bool enable_slow_lookup = false);
94bool AppendTypesSlow(const std::string& name,
95 std::vector<Cpp::TemplateArgInfo>& types,
96 TCppScope_t parent = nullptr);
98TCppType_t GetComplexType(const std::string& element_type);
100TCppScope_t GetScope(const std::string& scope_name,
101 TCppScope_t parent_scope = TCppScope_t{});
103TCppScope_t GetUnderlyingScope(TCppScope_t scope);
105TCppScope_t GetFullScope(const std::string& scope_name);
107TCppScope_t GetTypeScope(TCppScope_t klass);
109TCppScope_t GetNamed(const std::string& scope_name,
110 TCppScope_t parent_scope = TCppScope_t{});
112TCppScope_t GetParentScope(TCppScope_t scope);
114TCppScope_t GetScopeFromType(TCppType_t type);
116TCppType_t GetTypeFromScope(TCppScope_t klass);
118TCppScope_t GetGlobalScope();
120TCppScope_t GetActualClass(TCppScope_t klass, TCppObject_t obj);
122size_t SizeOf(TCppScope_t klass);
125
127bool IsBuiltin(const std::string& type_name);
128
131
133bool IsComplete(TCppScope_t type);
134
135// memory management ---------------------------------------------------------
137TCppObject_t Allocate(TCppScope_t scope);
139void Deallocate(TCppScope_t scope, TCppObject_t instance);
141TCppObject_t Construct(TCppScope_t scope, void* arena = nullptr);
143void Destruct(TCppScope_t scope, TCppObject_t instance);
144
145// method/function dispatching -----------------------------------------------
147void CallV(TCppMethod_t method, TCppObject_t self, size_t nargs, void* args);
149unsigned char CallB(TCppMethod_t method, TCppObject_t self, size_t nargs,
150 void* args);
152char CallC(TCppMethod_t method, TCppObject_t self, size_t nargs, void* args);
154short CallH(TCppMethod_t method, TCppObject_t self, size_t nargs, void* args);
156int CallI(TCppMethod_t method, TCppObject_t self, size_t nargs, void* args);
158long CallL(TCppMethod_t method, TCppObject_t self, size_t nargs, void* args);
160PY_LONG_LONG CallLL(TCppMethod_t method, TCppObject_t self, size_t nargs,
161 void* args);
163float CallF(TCppMethod_t method, TCppObject_t self, size_t nargs, void* args);
165double CallD(TCppMethod_t method, TCppObject_t self, size_t nargs, void* args);
167PY_LONG_DOUBLE CallLD(TCppMethod_t method, TCppObject_t self, size_t nargs,
168 void* args);
169
171void* CallR(TCppMethod_t method, TCppObject_t self, size_t nargs, void* args);
173char* CallS(TCppMethod_t method, TCppObject_t self, size_t nargs, void* args,
174 size_t* length);
176TCppObject_t CallConstructor(TCppMethod_t method, TCppScope_t klass,
177 size_t nargs, void* args);
179void CallDestructor(TCppScope_t type, TCppObject_t self);
181TCppObject_t CallO(TCppMethod_t method, TCppObject_t self, size_t nargs,
182 void* args, TCppType_t result_type);
183
186 bool check_enabled = true);
187
188// handling of function argument buffer --------------------------------------
190void* AllocateFunctionArgs(size_t nargs);
192void DeallocateFunctionArgs(void* args);
194size_t GetFunctionArgSizeof();
197
198// scope reflection information ----------------------------------------------
200bool IsNamespace(TCppScope_t scope);
202bool IsClass(TCppScope_t scope);
204bool IsTemplate(TCppScope_t scope);
206bool IsTemplateInstantiation(TCppScope_t scope);
208bool IsTypedefed(TCppScope_t scope);
210bool IsAbstract(TCppScope_t scope);
212bool IsEnumScope(TCppScope_t scope);
214bool IsEnumConstant(TCppScope_t scope);
218bool IsAggregate(TCppScope_t type);
220bool IsDefaultConstructable(TCppScope_t scope);
222bool IsVariable(TCppScope_t scope);
223
225void GetAllCppNames(TCppScope_t scope, std::set<std::string>& cppnames);
226
227// namespace reflection information ------------------------------------------
229std::vector<TCppScope_t> GetUsingNamespaces(TCppScope_t);
230
231// class reflection information ----------------------------------------------
233std::string GetFinalName(TCppScope_t type);
235std::string GetScopedFinalName(TCppScope_t type);
237bool HasVirtualDestructor(TCppScope_t type);
239TCppIndex_t GetNumBases(TCppScope_t klass);
241TCppIndex_t GetNumBasesLongestBranch(TCppScope_t klass);
243std::string GetBaseName(TCppScope_t klass, TCppIndex_t ibase);
245TCppScope_t GetBaseScope(TCppScope_t klass, TCppIndex_t ibase);
247bool IsSubclass(TCppScope_t derived, TCppScope_t base);
249bool IsSmartPtr(TCppScope_t klass);
251bool GetSmartPtrInfo(const std::string&, TCppScope_t* raw, TCppMethod_t* deref);
252// calculate offsets between declared and actual type, up-cast: direction > 0;
253// down-cast: direction < 0
255ptrdiff_t GetBaseOffset(TCppScope_t derived, TCppScope_t base,
256 TCppObject_t address, int direction,
257 bool rerror = false);
258
259// method/function reflection information ------------------------------------
261void GetClassMethods(TCppScope_t scope, std::vector<TCppMethod_t>& methods);
263std::vector<TCppMethod_t> GetMethodsFromName(TCppScope_t scope,
264 const std::string& name);
266std::string GetName(TCppScope_t);
268std::string GetFullName(TCppScope_t);
278std::string GetMethodArgName(TCppMethod_t, TCppIndex_t iarg);
283 const std::string& req_type);
285std::string GetMethodArgTypeAsString(TCppMethod_t method, TCppIndex_t iarg);
288 TCppIndex_t iarg);
292std::string GetMethodSignature(TCppMethod_t, bool show_formal_args,
293 TCppIndex_t max_args = (TCppIndex_t)-1);
295bool IsFunctionType(TCppType_t typ);
299void GetFnTypeSig(TCppType_t fn_type, std::vector<TCppType_t>& arg_types);
301bool IsSameType(TCppType_t typ1, TCppType_t typ2);
303bool IsSimilarFnTypes(TCppType_t typ1, TCppType_t typ2);
305std::string GetDoxygenComment(TCppScope_t scope, bool strip_markers = true);
308// Templated method/function reflection information
309// ------------------------------------
311void GetTemplatedMethods(TCppScope_t scope, std::vector<TCppMethod_t>& methods);
313TCppIndex_t GetNumTemplatedMethods(TCppScope_t scope,
314 bool accept_namespace = false);
316std::string GetTemplatedMethodName(TCppScope_t scope, TCppIndex_t imeth);
318bool ExistsMethodTemplate(TCppScope_t scope, const std::string& name);
322bool IsStaticTemplate(TCppScope_t scope, const std::string& name);
324TCppMethod_t GetMethodTemplate(TCppScope_t scope, const std::string& name,
325 const std::string& proto);
327void GetClassOperators(TCppScope_t klass, const std::string& opname,
328 std::vector<TCppMethod_t>& operators);
330TCppMethod_t GetGlobalOperator(TCppScope_t scope, const std::string& lc,
331 const std::string& rc, const std::string& op);
332
333// method properties ---------------------------------------------------------
335bool IsDeletedMethod(TCppMethod_t method);
337bool IsPublicMethod(TCppMethod_t method);
341bool IsPrivateMethod(TCppMethod_t method);
343bool IsConstructor(TCppMethod_t method);
345bool IsDestructor(TCppMethod_t method);
347bool IsStaticMethod(TCppMethod_t method);
349bool IsExplicit(TCppMethod_t method);
350
351// data member reflection information ----------------------------------------
353void GetDatamembers(TCppScope_t scope, std::vector<TCppScope_t>& datamembers);
357TCppScope_t WrapLambdaFromVariable(TCppScope_t var);
363std::string GetDatamemberTypeAsString(TCppScope_t var);
365std::string GetTypeAsString(TCppType_t type);
367intptr_t GetDatamemberOffset(TCppScope_t var, TCppScope_t klass = nullptr);
369bool CheckDatamember(TCppScope_t scope, const std::string& name);
370
371// // data member properties
372// ----------------------------------------------------
374bool IsPublicData(TCppScope_t var);
376bool IsProtectedData(TCppScope_t var);
378bool IsPrivateData(TCppScope_t var);
380bool IsStaticDatamember(TCppScope_t var);
382bool IsConstVar(TCppScope_t var);
386std::vector<long int> GetDimensions(TCppType_t type);
387
388// enum properties -----------------------------------------------------------
390std::vector<TCppScope_t> GetEnumConstants(TCppScope_t scope);
392TCppType_t GetEnumConstantType(TCppScope_t scope);
394long long GetEnumDataValue(TCppScope_t scope);
395
397TCppScope_t InstantiateTemplate(TCppScope_t tmpl, Cpp::TemplateArgInfo* args,
398 size_t args_size);
399
401void DumpScope(TCppScope_t scope);
402} // namespace cppjit::interop
403
404#endif // !CPPJIT_INTEROP_H
static Roo_reg_AGKInteg1D instance
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
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 length
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 req_type
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 type
char name[80]
Definition TGX11.cxx:142
long double PY_LONG_DOUBLE
unsigned long long PY_ULONG_LONG
long long PY_LONG_LONG
bool IsConstVar(TCppScope_t var)
Cpp::TypeRef TCppType_t
Definition API.h:42
unsigned char CallB(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
TCppScope_t GetFullScope(const std::string &scope_name)
void GetDatamembers(TCppScope_t scope, std::vector< TCppScope_t > &datamembers)
Cpp::ObjectRef TCppObject_t
Definition API.h:43
TCppType_t GetTypeFromScope(TCppScope_t klass)
std::string GetTypeAsString(TCppType_t type)
TCppType_t GetDatamemberType(TCppScope_t data)
TCppType_t ResolveEnumPointerType(TCppType_t type)
bool ExistsMethodTemplate(TCppScope_t scope, const std::string &name)
bool IsFunctionType(TCppType_t typ)
TCppScope_t WrapLambdaFromVariable(TCppScope_t var)
void DeallocateFunctionArgs(void *args)
bool IsBuiltin(const std::string &type_name)
void CallV(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
std::string GetName(TCppScope_t)
std::string ToString(TCppScope_t klass, TCppObject_t obj)
bool IsClassType(TCppType_t type)
void CallDestructor(TCppScope_t type, TCppObject_t self)
PY_LONG_DOUBLE CallLD(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
bool CheckDatamember(TCppScope_t scope, const std::string &name)
TCppMethod_t GetMethodTemplate(TCppScope_t scope, const std::string &name, const std::string &proto)
bool IsTemplateInstantiation(TCppScope_t scope)
TCppMethod_t AdaptFunctionForLambdaReturn(TCppMethod_t fn)
bool IsStaticTemplate(TCppScope_t scope, const std::string &name)
bool IsConstructor(TCppMethod_t method)
std::string GetMethodArgCanonTypeAsString(TCppMethod_t method, TCppIndex_t iarg)
bool HasVirtualDestructor(TCppScope_t type)
TCppIndex_t GetNumTemplatedMethods(TCppScope_t scope, bool accept_namespace=false)
TCppScope_t GetActualClass(TCppScope_t klass, TCppObject_t obj)
void GetTemplatedMethods(TCppScope_t scope, std::vector< TCppMethod_t > &methods)
std::string ResolveName(const std::string &cppitem_name)
std::string GetMethodArgTypeAsString(TCppMethod_t method, TCppIndex_t iarg)
TCppIndex_t GetMethodReqArgs(TCppMethod_t)
bool AppendTypesSlow(const std::string &name, std::vector< Cpp::TemplateArgInfo > &types, TCppScope_t parent=nullptr)
bool IsAbstract(TCppScope_t scope)
TCppScope_t GetParentScope(TCppScope_t scope)
std::string GetMethodReturnTypeAsString(TCppMethod_t)
TCppType_t GetReferencedType(TCppType_t type, bool rvalue=false)
TCppIndex_t GetMethodNumArgs(TCppMethod_t)
bool IsStaticDatamember(TCppScope_t var)
bool IsProtectedMethod(TCppMethod_t method)
Cpp::InterpRef TInterp_t
bool IsClass(TCppScope_t scope)
void Destruct(TCppScope_t scope, TCppObject_t instance)
TCppIndex_t GetNumBases(TCppScope_t klass)
int CallI(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
TCppIndex_t CompareMethodArgType(TCppMethod_t, TCppIndex_t iarg, const std::string &req_type)
bool IsSubclass(TCppScope_t derived, TCppScope_t base)
TCppScope_t GetNamed(const std::string &scope_name, TCppScope_t parent_scope=TCppScope_t{})
intptr_t GetDatamemberOffset(TCppScope_t var, TCppScope_t klass=nullptr)
size_t SizeOfType(TCppType_t type)
Cpp::FuncRef TCppMethod_t
Definition API.h:44
bool IsPublicData(TCppScope_t var)
TCppType_t GetMethodArgType(TCppMethod_t, TCppIndex_t iarg)
TCppScope_t GetBaseScope(TCppScope_t klass, TCppIndex_t ibase)
bool IsIntegerType(TCppType_t type, bool *is_signed=nullptr)
bool IsFunctionPointerType(TCppType_t type)
short CallH(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
bool IsTypedefed(TCppScope_t scope)
bool IsPrivateMethod(TCppMethod_t method)
TCppObject_t Allocate(TCppScope_t scope)
bool IsEnumScope(TCppScope_t scope)
char CallC(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
bool IsSimilarFnTypes(TCppType_t typ1, TCppType_t typ2)
void GetClassMethods(TCppScope_t scope, std::vector< TCppMethod_t > &methods)
TCppMethod_t GetGlobalOperator(TCppScope_t scope, const std::string &lc, const std::string &rc, const std::string &op)
TCppMethod_t ReduceReturnType(TCppMethod_t fn, TCppType_t reduce)
void * AllocateFunctionArgs(size_t nargs)
void GetClassOperators(TCppScope_t klass, const std::string &opname, std::vector< TCppMethod_t > &operators)
TCppObject_t CallO(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args, TCppType_t result_type)
bool IsPointerType(TCppType_t type)
std::string GetMethodArgName(TCppMethod_t, TCppIndex_t iarg)
void GetFnTypeSig(TCppType_t fn_type, std::vector< TCppType_t > &arg_types)
TCppFuncAddr_t GetFunctionAddress(TCppMethod_t method, bool check_enabled=true)
long long GetEnumDataValue(TCppScope_t scope)
size_t SizeOf(TCppScope_t klass)
std::string GetDoxygenComment(TCppScope_t scope, bool strip_markers=true)
TCppType_t GetMethodReturnType(TCppMethod_t)
TCppType_t ResolveType(TCppType_t cppitem_name)
TCppScope_t GetUnderlyingScope(TCppScope_t scope)
std::string GetMethodSignature(TCppMethod_t, bool show_formal_args, TCppIndex_t max_args=(TCppIndex_t) -1)
bool IsExplicit(TCppMethod_t method)
TCppScope_t GetGlobalScope()
std::string GetTemplatedMethodName(TCppScope_t scope, TCppIndex_t imeth)
std::string GetFullName(TCppScope_t)
TCppScope_t GetTypeScope(TCppScope_t klass)
bool IsTemplate(TCppScope_t scope)
bool IsDestructor(TCppMethod_t method)
std::vector< TCppScope_t > GetEnumConstants(TCppScope_t scope)
double CallD(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
bool Compile(const std::string &code, bool silent=false)
TCppType_t GetPointerType(TCppType_t type)
std::vector< TCppMethod_t > GetMethodsFromName(TCppScope_t scope, const std::string &name)
std::string ResolveEnum(TCppScope_t enum_scope)
size_t TCppIndex_t
Definition API.h:45
void * CallR(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
PY_LONG_LONG CallLL(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
bool IsDefaultConstructable(TCppScope_t scope)
TCppObject_t CallConstructor(TCppMethod_t method, TCppScope_t klass, size_t nargs, void *args)
bool IsDeletedMethod(TCppMethod_t method)
bool IsLValueReferenceType(TCppType_t type)
bool IsNamespace(TCppScope_t scope)
bool IsTemplatedMethod(TCppMethod_t method)
void DumpScope(TCppScope_t scope)
TCppScope_t GetScopeFromType(TCppType_t type)
TCppType_t GetFnTypeFromStdFn(TCppType_t fn_type)
std::string GetBaseName(TCppScope_t klass, TCppIndex_t ibase)
TCppType_t GetRealType(TCppType_t type)
TCppIndex_t GetNumBasesLongestBranch(TCppScope_t klass)
TCppScope_t GetScope(const std::string &scope_name, TCppScope_t parent_scope=TCppScope_t{})
TCppType_t GetEnumConstantType(TCppScope_t scope)
bool IsSameType(TCppType_t typ1, TCppType_t typ2)
bool IsEnumConstant(TCppScope_t scope)
std::string GetFinalName(TCppScope_t type)
bool IsProtectedData(TCppScope_t var)
bool IsLambdaClass(TCppType_t type)
bool IsConstMethod(TCppMethod_t)
ptrdiff_t GetBaseOffset(TCppScope_t derived, TCppScope_t base, TCppObject_t address, int direction, bool rerror=false)
TCppObject_t Construct(TCppScope_t scope, void *arena=nullptr)
bool IsPrivateData(TCppScope_t var)
float CallF(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
void Deallocate(TCppScope_t scope, TCppObject_t instance)
void * TCppFuncAddr_t
Definition API.h:46
bool IsMutablePtrRefType(TCppType_t type)
bool IsVariable(TCppScope_t scope)
bool IsSmartPtr(TCppScope_t klass)
std::string GetMethodArgDefault(TCppMethod_t, TCppIndex_t iarg)
bool IsStaticMethod(TCppMethod_t method)
char * CallS(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args, size_t *length)
bool IsRValueReferenceType(TCppType_t type)
TCppType_t GetComplexType(const std::string &element_type)
bool GetSmartPtrInfo(const std::string &, TCppScope_t *raw, TCppMethod_t *deref)
std::vector< TCppScope_t > GetUsingNamespaces(TCppScope_t)
bool IsPublicMethod(TCppMethod_t method)
TCppType_t GetType(const std::string &name, bool enable_slow_lookup=false)
bool IsAggregate(TCppScope_t type)
std::string GetScopedFinalName(TCppScope_t type)
void GetAllCppNames(TCppScope_t scope, std::set< std::string > &cppnames)
size_t GetFunctionArgTypeoffset()
std::string GetDatamemberTypeAsString(TCppScope_t var)
TCppType_t ResolveEnumReferenceType(TCppType_t type)
long CallL(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
Cpp::DeclRef TCppScope_t
Definition API.h:41
std::vector< long int > GetDimensions(TCppType_t type)
bool IsEnumType(TCppType_t type)
bool IsComplete(TCppScope_t type)
TCppScope_t InstantiateTemplate(TCppScope_t tmpl, Cpp::TemplateArgInfo *args, size_t args_size)
#define RPY_EXPORTED