61 static std::set< std::string > gSmartPtrTypes =
62 {
"auto_ptr",
"shared_ptr",
"weak_ptr",
"unique_ptr" };
68 class ApplicationStarter {
70 ApplicationStarter() {
79 g_globalvars.push_back(
nullptr );
82 ~ApplicationStarter() {
83 for (
auto ifunc : g_method2callfunc )
86 } _applicationStarter;
96 return g_classrefs[ (ClassRefs_t::size_type)scope ];
135 if ( name.find(
"::") == std::string::npos )
146 if ( dt )
return dt->GetFullTypeName();
152 std::string scope_name;
153 if ( sname.find(
"std::", 0, 5 ) == 0 )
154 scope_name = sname.substr( 5, std::string::npos );
159 auto icr = g_name2classrefidx.find( scope_name );
160 if ( icr != g_name2classrefidx.end() )
171 g_name2classrefidx[ scope_name ] = sz;
185 if ( clActual && clActual != cr.
GetClass() ) {
217 ClassInfo_t* ci =
gInterpreter->ClassInfo_Factory( type_name.c_str() );
255 static ClassInfo_t* gcl =
gInterpreter->ClassInfo_Factory();
261 auto icf = g_method2callfunc.find( method );
262 if ( icf != g_method2callfunc.end() )
265 CallFunc_t* callf =
nullptr;
267 std::string callString =
"";
278 TIter iarg( method_args );
283 if ( callString.empty() )
284 callString = fullType;
286 callString +=
", " + fullType;
319 if ( !( callf &&
gInterpreter->CallFunc_IsValid( callf ) ) ) {
320 PyErr_Format( PyExc_RuntimeError,
"could not resolve %s::%s(%s)",
321 const_cast<TClassRef&>(klass).GetClassName(),
323 callString.c_str() );
328 g_method2callfunc[ method ] = callf;
332 static inline void copy_args(
void* args_,
void** vargs ) {
333 std::vector<TParameter>& args = *(std::vector<TParameter>*)args_;
334 for ( std::vector<TParameter>::size_type i = 0; i < args.size(); ++i ) {
335 switch ( args[i].fTypeCode ) {
337 vargs[i] = (
void*)&args[i].
fValue.fLong;
340 vargs[i] = (
void*)&args[i].fValue.fFloat;
343 vargs[i] = (
void*)&args[i].
fValue.fDouble;
346 vargs[i] = (
void*)&args[i].fValue.fLongDouble;
352 vargs[i] = (
void*)&args[i].
fValue.fVoidp;
355 vargs[i] = args[i].fValue.fVoidp;
358 vargs[i] = args[i].fRef;
361 std::cerr <<
"unknown type code: " << args[i].fTypeCode << std::endl;
370 const std::vector<TParameter>& args = *(std::vector<TParameter>*)args_;
383 std::vector<void*> buf( args.size() );
394 faceptr.
fCtor( (
void**)smallbuf, result, args.size() );
396 std::vector<void*> buf( args.size() );
404 std::cerr <<
" DESTRUCTOR NOT IMPLEMENTED YET! " << std::endl;
411 template<
typename T >
415 if (
FastCall( method, args, (
void*)
self, &
t ) )
420 #define CPPYY_IMP_CALL( typecode, rtype ) \
421 rtype Cppyy::Call##typecode( TCppMethod_t method, TCppObject_t self, void* args )\
423 return CallT< rtype >( method, self, args ); \
428 if ( !
FastCall( method, args, (
void*)
self,
nullptr ) )
445 if (
FastCall( method, args, (
void*)
self, &r ) )
453 if (
FastCall( method, args, (
void*)
self, &s ) )
461 if (
FastCall( method, args,
nullptr, &obj ) )
477 if (
FastCall( method, args,
self, obj ) )
492 return new TParameter[nargs];
497 delete [] (TParameter*)args;
507 return offsetof( TParameter, fTypeCode );
529 return gInterpreter->ClassInfo_IsEnum( type_name.c_str() );
536 if ( klass == GLOBAL_HANDLE )
573 if ( derived == base )
587 const std::string& real_name =
ResolveName( type_name );
588 return gSmartPtrTypes.find(
589 real_name.substr( 0,real_name.find(
"<" ) ) ) != gSmartPtrTypes.end();
597 if ( derived == base || !(base && derived) )
613 std::ostringstream msg;
614 msg <<
"failed offset calculation between " << cb->
GetName() <<
" and " << cd->
GetName();
615 PyErr_Warn( PyExc_RuntimeWarning, const_cast<char*>( msg.str().c_str() ) );
619 return rerror ? (ptrdiff_t)offset : 0;
625 return rerror ? (ptrdiff_t)offset : 0;
627 return (ptrdiff_t)(direction < 0 ? -offset :
offset);
639 if ( clName.find(
'<' ) != std::string::npos ) {
642 clName =
"std::" + clName;
643 std::ostringstream stmt;
644 stmt <<
"template class " << clName <<
";";
651 }
else if ( scope == (
TCppScope_t)GLOBAL_HANDLE ) {
669 std::vector< TCppMethod_t > methods;
670 if ( scope == GLOBAL_HANDLE ) {
672 g_globalfuncs.reserve(funcs->
GetSize());
679 std::string fn = func->
GetName();
680 if ( fn.rfind( name, 0 ) == 0 ) {
682 if ( (name.size() == fn.size()) ||
683 (name.size() < fn.size() && fn[name.size()] ==
'<') ) {
722 return "constructor";
797 return (name[name.size()-1] ==
'>') && (name.find(
'<') != std::string::npos);
855 std::cerr <<
" global data should be retrieved lazily " << std::endl;
857 if ( g_globalvars.size() != (GlobalVars_t::size_type)vars->
GetSize() ) {
858 g_globalvars.clear();
859 g_globalvars.reserve(vars->
GetSize());
865 g_globalvars.push_back( var );
886 if ( scope == GLOBAL_HANDLE ) {
889 if ( fullType[fullType.size()-1] ==
'*' && \
890 fullType.find(
"char", 0, 4 ) == std::string::npos )
891 fullType.append(
"*" );
893 fullType.append(
"*" );
895 std::ostringstream s;
896 s <<
'[' << gbl->
GetMaxIndex( 0 ) <<
']' << std::ends;
897 fullType.append( s.str() );
907 fullType.append(
"*" );
909 std::ostringstream s;
910 s <<
'[' << m->
GetMaxIndex( 0 ) <<
']' << std::ends;
911 fullType.append( s.str() );
921 if ( scope == GLOBAL_HANDLE ) {
937 if ( scope == GLOBAL_HANDLE ) {
940 g_globalvars.push_back( gb );
941 return g_globalvars.size() - 1;
961 if ( scope == GLOBAL_HANDLE )
972 if ( scope == GLOBAL_HANDLE )
983 if ( scope == GLOBAL_HANDLE ) {
997 if ( scope == GLOBAL_HANDLE ) {
1011 if ( scope == GLOBAL_HANDLE ) {
std::map< std::string, ClassRefs_t::size_type > Name2ClassRefIndex_t
size_t GetFunctionArgSizeof()
TList * GetListOfBases()
Return list containing the TBaseClass(es) of a class.
virtual CallFuncIFacePtr_t CallFunc_IFacePtr(CallFunc_t *) const
std::string GetScopedFinalName(TCppType_t type)
std::vector< TClassRef > ClassRefs_t
R__EXTERN Int_t gErrorIgnoreLevel
std::vector< TGlobal * > GlobalVars_t
static ClassRefs_t g_classrefs(1)
Bool_t IsNamespace(TCppScope_t scope)
R__EXTERN TClassTable * gClassTable
RooArgList L(const RooAbsArg &v1)
Bool_t IsBuiltin(const std::string &type_name)
TCppIndex_t GetGlobalOperator(TCppType_t scope, TCppType_t lc, TCppScope_t rc, const std::string &op)
All ROOT classes may have RTTI (run time type identification) support added.
Bool_t IsMethodTemplate(TCppMethod_t)
Int_t GetNargs() const
Number of function arguments.
ptrdiff_t GetBaseOffset(TCppType_t derived, TCppType_t base, TCppObject_t address, int direction, bool rerror=false)
Bool_t IsPublicMethod(TCppMethod_t method)
static void copy_args(void *args_, void **vargs)
TCppIndex_t GetNumBases(TCppType_t type)
virtual Int_t GetMaxIndex(Int_t dim) const
Return maximum index for array dimension "dim".
Long_t Property() const
Set TObject::fBits and fStreamerType to cache information about the class.
TCppIndex_t GetMethodReqArgs(TCppMethod_t)
std::vector< TCppMethod_t > GetMethodsFromName(TCppScope_t scope, const std::string &name)
TList * GetListOfDataMembers(Bool_t load=kTRUE)
Return list containing the TDataMembers of a class.
Bool_t IsAbstract(TCppType_t type)
std::string GetFinalName(TCppType_t type)
std::string GetMethodSignature(TCppScope_t scope, TCppIndex_t imeth)
std::string CleanType(const char *typeDesc, int mode=0, const char **tail=0)
Cleanup type description, redundant blanks removed and redundant tail ignored return *tail = pointer ...
ptrdiff_t GetDatamemberOffset(TCppScope_t scope, TCppIndex_t idata)
struct staticInitHelper gbl
Bool_t IsaPointer() const
Return true if data member is a pointer.
static GlobalFuncs_t g_globalfuncs
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Bool_t IsEnumData(TCppScope_t scope, TCppIndex_t idata)
std::string GetDatamemberType(TCppScope_t scope, TCppIndex_t idata)
Each ROOT method (see TMethod) has a linked list of its arguments.
std::string GetReturnTypeNormalizedName() const
Get the normalized name of the return type.
TCppIndex_t GetNumScopes(TCppScope_t parent)
Bool_t FastCall(Cppyy::TCppMethod_t method, void *args_, void *self, void *result)
virtual Int_t GetArrayDim() const
Return number of array dimensions.
TCppObject_t CallO(TCppMethod_t method, TCppObject_t self, void *args, TCppType_t result_type)
Int_t GetDimensionSize(TCppScope_t scope, TCppIndex_t idata, int dimension)
Int_t GetMaxIndex(Int_t dim) const
Return maximum index for array dimension "dim".
virtual TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
#define CPPYY_IMP_CALL(typecode, rtype)
TCppObject_t CallConstructor(TCppMethod_t method, TCppType_t type, void *args)
std::string GetBaseName(TCppType_t type, TCppIndex_t ibase)
Char_t * CallS(TCppMethod_t method, TCppObject_t self, void *args)
TCppIndex_t GetMethodIndexAt(TCppScope_t scope, TCppIndex_t imeth)
static TFunction * type_get_method(Cppyy::TCppType_t klass, Cppyy::TCppIndex_t idx)
TCppIndex_t GetMethodNumTemplateArgs(TCppScope_t scope, TCppIndex_t imeth)
TCppType_t GetTemplate(const std::string &template_name)
const char * GetTrueTypeName() const
Get full type description of data member, e,g.: "class TDirectory*".
std::string ResolveName(const std::string &cppitem_name)
Bool_t HasComplexHierarchy(TCppType_t type)
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
TClass * GetActualClass(const void *object) const
Return a pointer the the real class of the object.
TCppMethPtrGetter_t GetMethPtrGetter(TCppScope_t scope, TCppIndex_t imeth)
std::string ResolveTypedef(const char *tname, bool resolveAll=false)
TCppIndex_t GetNumDatamembers(TCppScope_t scope)
const char * GetDefault() const
Get default value of method argument.
Bool_t IsConstData(TCppScope_t scope, TCppIndex_t idata)
static Method2CallFunc_t g_method2callfunc
void CallDestructor(TCppType_t type, TCppObject_t self)
Bool_t IsComplete(const std::string &type_name)
TCppMethod_t GetMethod(TCppScope_t scope, TCppIndex_t imeth)
size_t GetFunctionArgTypeoffset()
std::string GetMethodTemplateArgName(TCppScope_t scope, TCppIndex_t imeth, TCppIndex_t iarg)
virtual const char * GetFullTypeName() const
Get full type description of global variable, e,g.: "class TDirectory*".
TClass * GetBaseClass(const char *classname)
Return pointer to the base class "classname".
Bool_t IsConstructor(TCppMethod_t method)
TCppType_t GetActualClass(TCppType_t klass, TCppObject_t obj)
PyROOT::TParameter TParameter
Int_t GetNargsOpt() const
Number of function optional (default) arguments.
void AddSmartPtrType(const std::string &)
Bool_t IsPublicData(TCppScope_t scope, TCppIndex_t idata)
std::string GetMethodName(TCppMethod_t)
Basic data type descriptor (datatype information is obtained from CINT).
ClassInfo_t * GetClassInfo() const
Collection abstract base class.
void Destructor(void *obj, Bool_t dtorOnly=kFALSE)
Explicitly call destructor for object.
void * AllocateFunctionArgs(size_t nargs)
static CallFunc_t * GetCallFunc(Cppyy::TCppMethod_t method)
virtual const char * GetName() const
Returns name of object.
static GlobalVars_t g_globalvars
TCppIndex_t GetDatamemberIndex(TCppScope_t scope, const std::string &name)
The ROOT global object gROOT contains a list of all defined classes.
Long_t Property() const
Get property description word. For meaning of bits see EProperty.
Global variables class (global variables are obtained from CINT).
static const ClassRefs_t::size_type GLOBAL_HANDLE
Each class (see TClass) has a linked list of its base class(es).
void * CallR(TCppMethod_t method, TCppObject_t self, void *args)
Bool_t IsLoaded() const
Return true if the shared library of this class is currently in the a process's memory.
TClass * GetClass() const
Bool_t IsSubtype(TCppType_t derived, TCppType_t base)
static TClassRef & type_from_handle(Cppyy::TCppScope_t scope)
virtual Int_t GetSize() const
static T CallT(Cppyy::TCppMethod_t method, Cppyy::TCppObject_t self, void *args)
TCppScope_t GetScope(const std::string &scope_name)
TList * GetListOfMethodArgs()
Return list containing the TMethodArgs of a TFunction.
std::string GetMethodResultType(TCppMethod_t)
Long_t GetOffsetCint() const
Get offset from "this" using the information in CINT only.
std::string GetTypeNormalizedName() const
Get the normalized name of the return type.
virtual void * GetAddress() const
Return address of global.
double func(double *x, double *p)
TCppIndex_t GetMethodNumArgs(TCppMethod_t)
std::string GetMethodArgName(TCppMethod_t, int iarg)
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
void Deallocate(TCppType_t type, TCppObject_t instance)
TCppObject_t Allocate(TCppType_t type)
std::string GetMethodArgType(TCppMethod_t, int iarg)
Bool_t IsSmartPtr(const std::string &)
Bool_t IsStaticMethod(TCppMethod_t method)
std::string GetDatamemberName(TCppScope_t scope, TCppIndex_t idata)
void *(* TCppMethPtrGetter_t)(TCppObject_t)
Global functions class (global functions are obtained from CINT).
Int_t GetArrayDim() const
Return number of array dimensions.
TClass * GetClass() const
TClassRef is used to implement a permanent reference to a TClass object.
Bool_t IsStaticData(TCppScope_t scope, TCppIndex_t idata)
static Name2ClassRefIndex_t g_name2classrefidx
static ClassInfo_t * GetGlobalNamespaceInfo()
size_t SizeOf(TCppType_t klass)
Bool_t IsConstMethod(TCppMethod_t)
TCppIndex_t GetNumMethods(TCppScope_t scope)
Each ROOT class (see TClass) has a linked list of methods.
std::string ShortType(const char *typeDesc, int mode)
Return the absolute type of typeDesc.
void CallV(TCppMethod_t method, TCppObject_t self, void *args)
static Cppyy::TCppScope_t declaring_scope(Cppyy::TCppMethod_t method)
Bool_t IsBasic() const
Return true if data member is a basic type, e.g. char, int, long...
Long_t Property() const
Get property description word. For meaning of bits see EProperty.
std::map< Cppyy::TCppMethod_t, CallFunc_t * > Method2CallFunc_t
TCppObject_t Construct(TCppType_t type)
void Destruct(TCppType_t type, TCppObject_t instance)
TMethod * GetMethodAny(const char *method)
Return pointer to method without looking at parameters.
Long_t ExtraProperty() const
Get property description word. For meaning of bits see EProperty.
virtual Int_t IndexOf(const TObject *obj) const
R__EXTERN TInterpreter * gCling
TList * GetListOfMethods(Bool_t load=kTRUE)
Return list containing the TMethods of a class.
std::string GetMethodArgDefault(TCppMethod_t, int iarg)
Vc_ALWAYS_INLINE_L T *Vc_ALWAYS_INLINE_R malloc(size_t n)
Allocates memory on the Heap with alignment and padding suitable for vectorized access.
static char * At(UInt_t index)
Returns class at index from sorted class table.
void DeallocateFunctionArgs(void *args)
const char * cd(char *path=0)
Bool_t IsEnum(const std::string &type_name)
std::string GetScopeName(TCppScope_t parent, TCppIndex_t iscope)
virtual Long_t Property() const
Get property description word. For meaning of bits see EProperty.
Int_t Size() const
Return size of object of this class.
std::vector< TFunction > GlobalFuncs_t