Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
clingwrapper.cxx
Go to the documentation of this file.
1// Bindings
2#include "capi.h"
3#include "cpp_cppyy.h"
4#include "callcontext.h"
5
6// ROOT
7#include "TBaseClass.h"
8#include "TClass.h"
9#include "TClassRef.h"
10#include "TClassTable.h"
11#include "TClassEdit.h"
12#include "TCollection.h"
13#include "TDataMember.h"
14#include "TDataType.h"
15#include "TEnum.h"
16#include "TEnumConstant.h"
17#include "TEnv.h"
18#include "TError.h"
19#include "TException.h"
20#include "TFunction.h"
21#include "TFunctionTemplate.h"
22#include "TGlobal.h"
23#include "THashList.h"
24#include "TInterpreter.h"
25#include "TList.h"
26#include "TListOfDataMembers.h"
27#include "TListOfEnums.h"
28#include "TMethod.h"
29#include "TMethodArg.h"
30#include "TROOT.h"
31#include "TSystem.h"
32
33// Standard
34#include <assert.h>
35#include <algorithm> // for std::count, std::remove
36#include <climits>
37#include <stdexcept>
38#include <map>
39#include <new>
40#include <set>
41#include <sstream>
42#include <signal.h>
43#include <stdlib.h> // for getenv
44#include <string.h>
45#include <typeinfo>
46
47// temp
48#include <iostream>
50// --temp
51
52
53// small number that allows use of stack for argument passing
54const int SMALL_ARGS_N = 8;
55
56// data for life time management ---------------------------------------------
57typedef std::vector<TClassRef> ClassRefs_t;
59static const ClassRefs_t::size_type GLOBAL_HANDLE = 1;
60static const ClassRefs_t::size_type STD_HANDLE = GLOBAL_HANDLE + 1;
61
62typedef std::map<std::string, ClassRefs_t::size_type> Name2ClassRefIndex_t;
64
65namespace {
66
67static inline Cppyy::TCppType_t find_memoized(const std::string& name)
68{
69 auto icr = g_name2classrefidx.find(name);
70 if (icr != g_name2classrefidx.end())
71 return (Cppyy::TCppType_t)icr->second;
72 return (Cppyy::TCppType_t)0;
73}
74
75class CallWrapper {
76public:
77 typedef const void* DeclId_t;
78
79public:
80 CallWrapper(TFunction* f) : fDecl(f->GetDeclId()), fName(f->GetName()), fTF(nullptr) {}
81 CallWrapper(DeclId_t fid, const std::string& n) : fDecl(fid), fName(n), fTF(nullptr) {}
82 ~CallWrapper() {
83 if (fTF && fDecl == fTF->GetDeclId())
84 delete fTF;
85 }
86
87public:
89 DeclId_t fDecl;
90 std::string fName;
91 TFunction* fTF;
92};
93
94}
95
96static std::vector<CallWrapper*> gWrapperHolder;
97static inline CallWrapper* new_CallWrapper(TFunction* f)
98{
99 CallWrapper* wrap = new CallWrapper(f);
100 gWrapperHolder.push_back(wrap);
101 return wrap;
102}
103
104static inline CallWrapper* new_CallWrapper(CallWrapper::DeclId_t fid, const std::string& n)
105{
106 CallWrapper* wrap = new CallWrapper(fid, n);
107 gWrapperHolder.push_back(wrap);
108 return wrap;
109}
110
111typedef std::vector<TGlobal*> GlobalVars_t;
113
114static std::set<std::string> gSTLNames;
115
116
117// data ----------------------------------------------------------------------
119
120// builtin types (including a few common STL templates as long as they live in
121// the global namespace b/c of choices upstream)
122static std::set<std::string> g_builtins =
123 {"bool", "char", "signed char", "unsigned char", "wchar_t", "short", "unsigned short",
124 "int", "unsigned int", "long", "unsigned long", "long long", "unsigned long long",
125 "float", "double", "long double", "void",
126 "allocator", "array", "basic_string", "complex", "initializer_list", "less", "list",
127 "map", "pair", "set", "vector"};
128
129// smart pointer types
130static std::set<std::string> gSmartPtrTypes =
131 {"auto_ptr", "std::auto_ptr", "shared_ptr", "std::shared_ptr",
132 "unique_ptr", "std::unique_ptr", "weak_ptr", "std::weak_ptr"};
133
134// to filter out ROOT names
135static std::set<std::string> gInitialNames;
136static std::set<std::string> gRootSOs;
137
138// configuration
139static bool gEnableFastPath = true;
140
141
142// global initialization -----------------------------------------------------
143namespace {
144
145// names copied from TUnixSystem
146#ifdef WIN32
147const int SIGBUS = 0; // simple placeholders for ones that don't exist
148const int SIGSYS = 0;
149const int SIGPIPE = 0;
150const int SIGQUIT = 0;
151const int SIGWINCH = 0;
152const int SIGALRM = 0;
153const int SIGCHLD = 0;
154const int SIGURG = 0;
155const int SIGUSR1 = 0;
156const int SIGUSR2 = 0;
157#endif
158
159static struct Signalmap_t {
160 int fCode;
161 const char *fSigName;
162} gSignalMap[kMAXSIGNALS] = { // the order of the signals should be identical
163 { SIGBUS, "bus error" }, // to the one in TSysEvtHandler.h
164 { SIGSEGV, "segmentation violation" },
165 { SIGSYS, "bad argument to system call" },
166 { SIGPIPE, "write on a pipe with no one to read it" },
167 { SIGILL, "illegal instruction" },
168 { SIGABRT, "abort" },
169 { SIGQUIT, "quit" },
170 { SIGINT, "interrupt" },
171 { SIGWINCH, "window size change" },
172 { SIGALRM, "alarm clock" },
173 { SIGCHLD, "death of a child" },
174 { SIGURG, "urgent data arrived on an I/O channel" },
175 { SIGFPE, "floating point exception" },
176 { SIGTERM, "termination signal" },
177 { SIGUSR1, "user-defined signal 1" },
178 { SIGUSR2, "user-defined signal 2" }
179};
180
181static void inline do_trace(int sig) {
182 std::cerr << " *** Break *** " << (sig < kMAXSIGNALS ? gSignalMap[sig].fSigName : "") << std::endl;
184}
185
186class TExceptionHandlerImp : public TExceptionHandler {
187public:
188 void HandleException(Int_t sig) override {
189 if (TROOT::Initialized()) {
190 if (gException) {
191 gInterpreter->RewindDictionary();
192 gInterpreter->ClearFileBusy();
193 }
194
195 if (!getenv("CPPYY_CRASH_QUIET"))
196 do_trace(sig);
197
198 // jump back, if catch point set
199 Throw(sig);
200 }
201
202 do_trace(sig);
203 gSystem->Exit(128 + sig);
204 }
205};
206
207class ApplicationStarter {
208public:
209 ApplicationStarter() {
210 // initialize ROOT early to guarantee proper order of shutdown later on (gROOT is a
211 // macro that resolves to the ROOT::GetROOT() function call)
212 (void)gROOT;
213
214 // setup dummy holders for global and std namespaces
215 assert(g_classrefs.size() == GLOBAL_HANDLE);
217 g_classrefs.push_back(TClassRef(""));
218
219 // aliases for std (setup already in pythonify)
221 g_name2classrefidx["::std"] = g_name2classrefidx["std"];
222 g_classrefs.push_back(TClassRef("std"));
223
224 // add a dummy global to refer to as null at index 0
225 g_globalvars.push_back(nullptr);
226
227 // disable fast path if requested
228 if (getenv("CPPYY_DISABLE_FASTPATH")) gEnableFastPath = false;
229
230 // fill the set of STL names
231 const char* stl_names[] = {"allocator", "auto_ptr", "bad_alloc", "bad_cast",
232 "bad_exception", "bad_typeid", "basic_filebuf", "basic_fstream", "basic_ifstream",
233 "basic_ios", "basic_iostream", "basic_istream", "basic_istringstream",
234 "basic_ofstream", "basic_ostream", "basic_ostringstream", "basic_streambuf",
235 "basic_string", "basic_stringbuf", "basic_stringstream", "binary_function",
236 "binary_negate", "bitset", "byte", "char_traits", "codecvt_byname", "codecvt", "collate",
237 "collate_byname", "compare", "complex", "ctype_byname", "ctype", "default_delete",
238 "deque", "divides", "domain_error", "equal_to", "exception", "forward_list", "fpos",
239 "function", "greater_equal", "greater", "gslice_array", "gslice", "hash", "indirect_array",
240 "integer_sequence", "invalid_argument", "ios_base", "istream_iterator", "istreambuf_iterator",
241 "istrstream", "iterator_traits", "iterator", "length_error", "less_equal", "less",
242 "list", "locale", "localedef utility", "locale utility", "logic_error", "logical_and",
243 "logical_not", "logical_or", "map", "mask_array", "mem_fun", "mem_fun_ref", "messages",
244 "messages_byname", "minus", "modulus", "money_get", "money_put", "moneypunct",
245 "moneypunct_byname", "multimap", "multiplies", "multiset", "negate", "not_equal_to",
246 "num_get", "num_put", "numeric_limits", "numpunct", "numpunct_byname",
247 "ostream_iterator", "ostreambuf_iterator", "ostrstream", "out_of_range",
248 "overflow_error", "pair", "plus", "pointer_to_binary_function",
249 "pointer_to_unary_function", "priority_queue", "queue", "range_error",
250 "raw_storage_iterator", "reverse_iterator", "runtime_error", "set", "shared_ptr",
251 "slice_array", "slice", "stack", "string", "strstream", "strstreambuf",
252 "time_get_byname", "time_get", "time_put_byname", "time_put", "unary_function",
253 "unary_negate", "unique_ptr", "underflow_error", "unordered_map", "unordered_multimap",
254 "unordered_multiset", "unordered_set", "valarray", "vector", "weak_ptr", "wstring"};
255 for (auto& name : stl_names)
256 gSTLNames.insert(name);
257
258 // set opt level (default to 2 if not given; Cling itself defaults to 0)
259 int optLevel = 2;
260 if (getenv("CPPYY_OPT_LEVEL")) optLevel = atoi(getenv("CPPYY_OPT_LEVEL"));
261 if (optLevel != 0) {
262 std::ostringstream s;
263 s << "#pragma cling optimize " << optLevel;
264 gInterpreter->ProcessLine(s.str().c_str());
265 }
266
267 // load frequently used headers
268 const char* code =
269 "#include <iostream>\n"
270 "#include <string>\n"
271 "#include <DllImport.h>\n" // defines R__EXTERN
272 "#include <vector>\n"
273 "#include <utility>";
274 gInterpreter->ProcessLine(code);
275
276 // create helpers for comparing thingies
277 gInterpreter->Declare(
278 "namespace __cppyy_internal { template<class C1, class C2>"
279 " bool is_equal(const C1& c1, const C2& c2) { return (bool)(c1 == c2); } }");
280 gInterpreter->Declare(
281 "namespace __cppyy_internal { template<class C1, class C2>"
282 " bool is_not_equal(const C1& c1, const C2& c2) { return (bool)(c1 != c2); } }");
283
284 // retrieve all initial (ROOT) C++ names in the global scope to allow filtering later
285 if (!getenv("CPPYY_NO_ROOT_FILTER")) {
286 gROOT->GetListOfGlobals(true); // force initialize
287 gROOT->GetListOfGlobalFunctions(true); // id.
288 std::set<std::string> initial;
290 gInitialNames = initial;
291
292#ifndef WIN32
293 gRootSOs.insert("libCore.so ");
294 gRootSOs.insert("libRIO.so ");
295 gRootSOs.insert("libThread.so ");
296 gRootSOs.insert("libMathCore.so ");
297#else
298 gRootSOs.insert("libCore.dll ");
299 gRootSOs.insert("libRIO.dll ");
300 gRootSOs.insert("libThread.dll ");
301 gRootSOs.insert("libMathCore.dll ");
302#endif
303 }
304
305 // start off with a reasonable size placeholder for wrappers
306 gWrapperHolder.reserve(1024);
307
308 // create an exception handler to process signals
309 gExceptionHandler = new TExceptionHandlerImp{};
310 }
311
312 ~ApplicationStarter() {
313 for (auto wrap : gWrapperHolder)
314 delete wrap;
315 delete gExceptionHandler; gExceptionHandler = nullptr;
316 }
317} _applicationStarter;
318
319} // unnamed namespace
320
321
322// local helpers -------------------------------------------------------------
323static inline
325{
326 assert((ClassRefs_t::size_type)scope < g_classrefs.size());
327 return g_classrefs[(ClassRefs_t::size_type)scope];
328}
329
330static inline
332 CallWrapper* wrap = ((CallWrapper*)method);
333 if (!wrap->fTF || wrap->fTF->GetDeclId() != wrap->fDecl) {
334 MethodInfo_t* mi = gInterpreter->MethodInfo_Factory(wrap->fDecl);
335 wrap->fTF = new TFunction(mi);
336 }
337 return wrap->fTF;
338}
339
340static inline
341CallWrapper::DeclId_t m2d(Cppyy::TCppMethod_t method) {
342 CallWrapper* wrap = ((CallWrapper*)method);
343 if (!wrap->fTF || wrap->fTF->GetDeclId() != wrap->fDecl) {
344 MethodInfo_t* mi = gInterpreter->MethodInfo_Factory(wrap->fDecl);
345 wrap->fTF = new TFunction(mi);
346 }
347 return wrap->fDecl;
348}
349
350static inline
351char* cppstring_to_cstring(const std::string& cppstr)
352{
353 char* cstr = (char*)malloc(cppstr.size()+1);
354 memcpy(cstr, cppstr.c_str(), cppstr.size()+1);
355 return cstr;
356}
357
358static inline
359bool match_name(const std::string& tname, const std::string fname)
360{
361// either match exactly, or match the name as template
362 if (fname.rfind(tname, 0) == 0) {
363 if ((tname.size() == fname.size()) ||
364 (tname.size() < fname.size() && fname[tname.size()] == '<'))
365 return true;
366 }
367 return false;
368}
369
370static inline
371bool is_missclassified_stl(const std::string& name)
372{
373 std::string::size_type pos = name.find('<');
374 if (pos != std::string::npos)
375 return gSTLNames.find(name.substr(0, pos)) != gSTLNames.end();
376 return gSTLNames.find(name) != gSTLNames.end();
377}
378
379
380// direct interpreter access -------------------------------------------------
381bool Cppyy::Compile(const std::string& code)
382{
383 return gInterpreter->Declare(code.c_str());
384}
385
386
387// name to opaque C++ scope representation -----------------------------------
388std::string Cppyy::ResolveName(const std::string& cppitem_name)
389{
390// Fully resolve the given name to the final type name.
391
392// try memoized type cache, in case seen before
393 TCppType_t klass = find_memoized(cppitem_name);
394 if (klass) return GetScopedFinalName(klass);
395
396// remove global scope '::' if present
397 std::string tclean = cppitem_name.compare(0, 2, "::") == 0 ?
398 cppitem_name.substr(2, std::string::npos) : cppitem_name;
399
400// classes (most common)
401 tclean = TClassEdit::CleanType(tclean.c_str());
402 if (tclean.empty() /* unknown, eg. an operator */) return cppitem_name;
403
404// reduce [N] to []
405 if (tclean[tclean.size()-1] == ']')
406 tclean = tclean.substr(0, tclean.rfind('[')) + "[]";
407
408 if (tclean.rfind("byte", 0) == 0 || tclean.rfind("std::byte", 0) == 0)
409 return tclean;
410
411// check data types list (accept only builtins as typedefs will
412// otherwise not be resolved)
413 TDataType* dt = gROOT->GetType(tclean.c_str());
414 if (dt && dt->GetType() != kOther_t) return dt->GetFullTypeName();
415
416// special case for enums
417 if (IsEnum(cppitem_name))
418 return ResolveEnum(cppitem_name);
419
420// special case for clang's builtin __type_pack_element (which does not resolve)
421 if (cppitem_name.rfind("__type_pack_element", 0) != std::string::npos) {
422 // shape is "__type_pack_element<index,type1,type2,...,typeN>cpd": extract
423 // first the index, and from there the indexed type; finally, restore the
424 // qualifiers
425 const char* str = cppitem_name.c_str();
426 char* endptr = nullptr;
427 unsigned long index = strtoul(str+20, &endptr, 0);
428
429 std::string tmplvars{endptr};
430 auto start = tmplvars.find(',') + 1;
431 auto end = tmplvars.find(',', start);
432 while (index != 0) {
433 start = end+1;
434 end = tmplvars.find(',', start);
435 if (end == std::string::npos) end = tmplvars.rfind('>');
436 --index;
437 }
438
439 std::string resolved = tmplvars.substr(start, end-start);
440 auto cpd = tmplvars.rfind('>');
441 if (cpd != std::string::npos && cpd+1 != tmplvars.size())
442 return resolved + tmplvars.substr(cpd+1, std::string::npos);
443 return resolved;
444 }
445
446// typedefs
447 return TClassEdit::ResolveTypedef(tclean.c_str(), true);
448}
449
450static std::map<std::string, std::string> resolved_enum_types;
451std::string Cppyy::ResolveEnum(const std::string& enum_type)
452{
453// The underlying type of a an enum may be any kind of integer.
454// Resolve that type via a workaround (note: this function assumes
455// that the enum_type name is a valid enum type name)
456 auto res = resolved_enum_types.find(enum_type);
457 if (res != resolved_enum_types.end())
458 return res->second;
459
460// desugar the type before resolving
461 std::string et_short = TClassEdit::ShortType(enum_type.c_str(), 1);
462 if (et_short.find("(unnamed") == std::string::npos) {
463 std::ostringstream decl;
464 // TODO: now presumed fixed with https://sft.its.cern.ch/jira/browse/ROOT-6988
465 for (auto& itype : {"unsigned int"}) {
466 decl << "std::is_same<"
467 << itype
468 << ", std::underlying_type<"
469 << et_short
470 << ">::type>::value;";
471 if (gInterpreter->ProcessLine(decl.str().c_str())) {
472 // TODO: "re-sugaring" like this is brittle, but the top
473 // should be re-translated into AST-based code anyway
474 std::string resugared;
475 if (et_short.size() != enum_type.size()) {
476 auto pos = enum_type.find(et_short);
477 if (pos != std::string::npos) {
478 resugared = enum_type.substr(0, pos) + itype;
479 if (pos+et_short.size() < enum_type.size())
480 resugared += enum_type.substr(pos+et_short.size(), std::string::npos);
481 }
482 }
483 if (resugared.empty()) resugared = itype;
484 resolved_enum_types[enum_type] = resugared;
485 return resugared;
486 }
487 }
488 }
489
490// failed or anonymous ... signal upstream to special case this
491 int ipos = (int)enum_type.size()-1;
492 for (; 0 <= ipos; --ipos) {
493 char c = enum_type[ipos];
494 if (isspace(c)) continue;
495 if (isalnum(c) || c == '_' || c == '>' || c == ')') break;
496 }
497 bool isConst = enum_type.find("const ", 6) != std::string::npos;
498 std::string restype = isConst ? "const " : "";
499 restype += "internal_enum_type_t"+enum_type.substr((std::string::size_type)ipos+1, std::string::npos);
500 resolved_enum_types[enum_type] = restype;
501 return restype; // should default to some int variant
502}
503
504Cppyy::TCppScope_t Cppyy::GetScope(const std::string& sname)
505{
506// First, try cache
507 TCppType_t result = find_memoized(sname);
508 if (result) return result;
509
510// Second, skip builtins before going through the more expensive steps of resolving
511// typedefs and looking up TClass
512 if (g_builtins.find(sname) != g_builtins.end())
513 return (TCppScope_t)0;
514
515// TODO: scope_name should always be final already?
516// Resolve name fully before lookup to make sure all aliases point to the same scope
517 std::string scope_name = ResolveName(sname);
518 bool bHasAlias = sname != scope_name;
519 if (bHasAlias) {
520 result = find_memoized(scope_name);
521 if (result) return result;
522 }
523
524// both failed, but may be STL name that's missing 'std::' now, but didn't before
525 bool b_scope_name_missclassified = is_missclassified_stl(scope_name);
526 if (b_scope_name_missclassified) {
527 result = find_memoized("std::"+scope_name);
528 if (result) g_name2classrefidx["std::"+scope_name] = (ClassRefs_t::size_type)result;
529 }
530 bool b_sname_missclassified = bHasAlias ? is_missclassified_stl(sname) : false;
531 if (b_sname_missclassified) {
532 if (!result) result = find_memoized("std::"+sname);
533 if (result) g_name2classrefidx["std::"+sname] = (ClassRefs_t::size_type)result;
534 }
535
536 if (result) return result;
537
538// use TClass directly, to enable auto-loading; class may be stubbed (eg. for
539// function returns) or forward declared, leading to a non-null TClass that is
540// otherwise invalid/unusable
541 TClassRef cr(TClass::GetClass(scope_name.c_str(), true /* load */, true /* silent */));
542 if (!cr.GetClass())
543 return (TCppScope_t)0;
544
545// memoize found/created TClass
546 ClassRefs_t::size_type sz = g_classrefs.size();
547 g_name2classrefidx[scope_name] = sz;
548 if (bHasAlias) g_name2classrefidx[sname] = sz;
549 g_classrefs.push_back(TClassRef(scope_name.c_str()));
550
551// TODO: make ROOT/meta NOT remove std :/
552 if (b_scope_name_missclassified)
553 g_name2classrefidx["std::"+scope_name] = sz;
554 if (b_sname_missclassified)
555 g_name2classrefidx["std::"+sname] = sz;
556
557 return (TCppScope_t)sz;
558}
559
560bool Cppyy::IsTemplate(const std::string& template_name)
561{
562 return (bool)gInterpreter->CheckClassTemplate(template_name.c_str());
563}
564
565namespace {
566 class AutoCastRTTI {
567 public:
568 virtual ~AutoCastRTTI() {}
569 };
570}
571
573{
574 TClassRef& cr = type_from_handle(klass);
575 if (!cr.GetClass() || !obj) return klass;
576
577#ifdef _WIN64
578// Cling does not provide a consistent ImageBase address for calculating relative addresses
579// as used in Windows 64b RTTI. So, check for our own RTTI extension instead. If that fails,
580// see whether the unmangled raw_name is available (e.g. if this is an MSVC compiled rather
581// than JITed class) and pass on if it is.
582 volatile const char* raw = nullptr; // to prevent too aggressive reordering
583 try {
584 // this will filter those objects that do not have RTTI to begin with (throws)
585 AutoCastRTTI* pcst = (AutoCastRTTI*)obj;
586 raw = typeid(*pcst).raw_name();
587
588 // check the signature id (0 == absolute, 1 == relative, 2 == ours)
589 void* vfptr = *(void**)((intptr_t)obj);
590 void* meta = (void*)((intptr_t)*((void**)((intptr_t)vfptr-sizeof(void*))));
591 if (*(intptr_t*)meta == 2) {
592 // access the extra data item which is an absolute pointer to the RTTI
593 void* ptdescr = (void*)((intptr_t)meta + 4*sizeof(unsigned long)+sizeof(void*));
594 if (ptdescr && *(void**)ptdescr) {
595 auto rtti = *(std::type_info**)ptdescr;
596 raw = rtti->raw_name();
597 if (raw && raw[0] != '\0') // likely unnecessary
598 return (TCppType_t)GetScope(rtti->name());
599 }
600
601 return klass; // do not fall through if no RTTI info available
602 }
603
604 // if the raw name is the empty string (no guarantees that this is so as truly, the
605 // address is corrupt, but it is common to be empty), then there is no accessible RTTI
606 // and getting the unmangled name will crash ...
607 if (!raw)
608 return klass;
609 } catch (std::bad_typeid) {
610 return klass; // can't risk passing to ROOT/meta as it may do RTTI
611 }
612#endif
613
614 TClass* clActual = cr->GetActualClass((void*)obj);
615 if (clActual && clActual != cr.GetClass()) {
616 auto itt = g_name2classrefidx.find(clActual->GetName());
617 if (itt != g_name2classrefidx.end())
618 return (TCppType_t)itt->second;
619 return (TCppType_t)GetScope(clActual->GetName());
620 }
621
622 return klass;
623}
624
626{
627 TClassRef& cr = type_from_handle(klass);
628 if (cr.GetClass() && cr->GetClassInfo())
629 return (size_t)gInterpreter->ClassInfo_Size(cr->GetClassInfo());
630 return (size_t)0;
631}
632
633size_t Cppyy::SizeOf(const std::string& type_name)
634{
635 TDataType* dt = gROOT->GetType(type_name.c_str());
636 if (dt) return dt->Size();
637 return SizeOf(GetScope(type_name));
638}
639
640bool Cppyy::IsBuiltin(const std::string& type_name)
641{
642 TDataType* dt = gROOT->GetType(TClassEdit::CleanType(type_name.c_str(), 1).c_str());
643 if (dt) return dt->GetType() != kOther_t;
644 return false;
645}
646
647bool Cppyy::IsComplete(const std::string& type_name)
648{
649// verify whether the dictionary of this class is fully available
650 bool b = false;
651
652 int oldEIL = gErrorIgnoreLevel;
653 gErrorIgnoreLevel = 3000;
654 TClass* klass = TClass::GetClass(TClassEdit::ShortType(type_name.c_str(), 1).c_str());
655 if (klass && klass->GetClassInfo()) // works for normal case w/ dict
656 b = gInterpreter->ClassInfo_IsLoaded(klass->GetClassInfo());
657 else { // special case for forward declared classes
658 ClassInfo_t* ci = gInterpreter->ClassInfo_Factory(type_name.c_str());
659 if (ci) {
660 b = gInterpreter->ClassInfo_IsLoaded(ci);
661 gInterpreter->ClassInfo_Delete(ci); // we own the fresh class info
662 }
663 }
664 gErrorIgnoreLevel = oldEIL;
665 return b;
666}
667
668// memory management ---------------------------------------------------------
670{
672 return (TCppObject_t)malloc(gInterpreter->ClassInfo_Size(cr->GetClassInfo()));
673}
674
676{
677 ::operator delete(instance);
678}
679
681{
683 return (TCppObject_t)cr->New();
684}
685
686static std::map<Cppyy::TCppType_t, bool> sHasOperatorDelete;
688{
691 cr->Destructor((void*)instance);
692 else {
693 ROOT::DelFunc_t fdel = cr->GetDelete();
694 if (fdel) fdel((void*)instance);
695 else {
696 auto ib = sHasOperatorDelete.find(type);
697 if (ib == sHasOperatorDelete.end()) {
699 ib = sHasOperatorDelete.find(type);
700 }
701 ib->second ? cr->Destructor((void*)instance) : free((void*)instance);
702 }
703 }
704}
705
706
707// method/function dispatching -----------------------------------------------
709{
710// TODO: method should be a callfunc, so that no mapping would be needed.
711 CallWrapper* wrap = (CallWrapper*)method;
712
713 CallFunc_t* callf = gInterpreter->CallFunc_Factory();
714 MethodInfo_t* meth = gInterpreter->MethodInfo_Factory(wrap->fDecl);
715 gInterpreter->CallFunc_SetFunc(callf, meth);
716 gInterpreter->MethodInfo_Delete(meth);
717
718 if (!(callf && gInterpreter->CallFunc_IsValid(callf))) {
719 // TODO: propagate this error to caller w/o use of Python C-API
720 /*
721 PyErr_Format(PyExc_RuntimeError, "could not resolve %s::%s(%s)",
722 const_cast<TClassRef&>(klass).GetClassName(),
723 wrap.fName, callString.c_str()); */
724 std::cerr << "TODO: report unresolved function error to Python\n";
725 if (callf) gInterpreter->CallFunc_Delete(callf);
727 }
728
729// generate the wrapper and JIT it; ignore wrapper generation errors (will simply
730// result in a nullptr that is reported upstream if necessary; often, however,
731// there is a different overload available that will do)
732 auto oldErrLvl = gErrorIgnoreLevel;
734 wrap->fFaceptr = gInterpreter->CallFunc_IFacePtr(callf);
735 gErrorIgnoreLevel = oldErrLvl;
736
737 gInterpreter->CallFunc_Delete(callf); // does not touch IFacePtr
738 return wrap->fFaceptr;
739}
740
741static inline
742bool copy_args(Parameter* args, size_t nargs, void** vargs)
743{
744 bool runRelease = false;
745 for (size_t i = 0; i < nargs; ++i) {
746 switch (args[i].fTypeCode) {
747 case 'X': /* (void*)type& with free */
748 runRelease = true;
749 case 'V': /* (void*)type& */
750 vargs[i] = args[i].fValue.fVoidp;
751 break;
752 case 'r': /* const type& */
753 vargs[i] = args[i].fRef;
754 break;
755 default: /* all other types in union */
756 vargs[i] = (void*)&args[i].fValue.fVoidp;
757 break;
758 }
759 }
760 return runRelease;
761}
762
763static inline
764void release_args(Parameter* args, size_t nargs) {
765 for (size_t i = 0; i < nargs; ++i) {
766 if (args[i].fTypeCode == 'X')
767 free(args[i].fValue.fVoidp);
768 }
769}
770
771static inline bool WrapperCall(Cppyy::TCppMethod_t method, size_t nargs, void* args_, void* self, void* result)
772{
773 Parameter* args = (Parameter*)args_;
774
775 CallWrapper* wrap = (CallWrapper*)method;
776 const TInterpreter::CallFuncIFacePtr_t& faceptr = wrap->fFaceptr.fGeneric ? wrap->fFaceptr : GetCallFunc(method);
777 if (!faceptr.fGeneric)
778 return false; // happens with compilation error
779
781 bool runRelease = false;
782 if (nargs <= SMALL_ARGS_N) {
783 void* smallbuf[SMALL_ARGS_N];
784 if (nargs) runRelease = copy_args(args, nargs, smallbuf);
785 faceptr.fGeneric(self, (int)nargs, smallbuf, result);
786 } else {
787 std::vector<void*> buf(nargs);
788 runRelease = copy_args(args, nargs, buf.data());
789 faceptr.fGeneric(self, (int)nargs, buf.data(), result);
790 }
791 if (runRelease) release_args(args, nargs);
792 return true;
793 }
794
796 bool runRelease = false;
797 if (nargs <= SMALL_ARGS_N) {
798 void* smallbuf[SMALL_ARGS_N];
799 if (nargs) runRelease = copy_args(args, nargs, (void**)smallbuf);
800 faceptr.fCtor((void**)smallbuf, result, (unsigned long)nargs);
801 } else {
802 std::vector<void*> buf(nargs);
803 runRelease = copy_args(args, nargs, buf.data());
804 faceptr.fCtor(buf.data(), result, (unsigned long)nargs);
805 }
806 if (runRelease) release_args(args, nargs);
807 return true;
808 }
809
811 std::cerr << " DESTRUCTOR NOT IMPLEMENTED YET! " << std::endl;
812 return false;
813 }
814
815 return false;
816}
817
818template<typename T>
819static inline
820T CallT(Cppyy::TCppMethod_t method, Cppyy::TCppObject_t self, size_t nargs, void* args)
821{
822 T t{};
823 if (WrapperCall(method, nargs, args, (void*)self, &t))
824 return t;
825 return (T)-1;
826}
827
828#define CPPYY_IMP_CALL(typecode, rtype) \
829rtype Cppyy::Call##typecode(TCppMethod_t method, TCppObject_t self, size_t nargs, void* args)\
830{ \
831 return CallT<rtype>(method, self, nargs, args); \
832}
833
834void Cppyy::CallV(TCppMethod_t method, TCppObject_t self, size_t nargs, void* args)
835{
836 if (!WrapperCall(method, nargs, args, (void*)self, nullptr))
837 return /* TODO ... report error */;
838}
839
840CPPYY_IMP_CALL(B, unsigned char)
847CPPYY_IMP_CALL(D, double )
849
850void* Cppyy::CallR(TCppMethod_t method, TCppObject_t self, size_t nargs, void* args)
851{
852 void* r = nullptr;
853 if (WrapperCall(method, nargs, args, (void*)self, &r))
854 return r;
855 return nullptr;
856}
857
859 TCppMethod_t method, TCppObject_t self, size_t nargs, void* args, size_t* length)
860{
861 char* cstr = nullptr;
862 TClassRef cr("std::string");
863 std::string* cppresult = (std::string*)malloc(sizeof(std::string));
864 if (WrapperCall(method, nargs, args, self, (void*)cppresult)) {
865 cstr = cppstring_to_cstring(*cppresult);
866 *length = cppresult->size();
867 cppresult->std::string::~basic_string();
868 } else
869 *length = 0;
870 free((void*)cppresult);
871 return cstr;
872}
873
875 TCppMethod_t method, TCppType_t /* klass */, size_t nargs, void* args)
876{
877 void* obj = nullptr;
878 if (WrapperCall(method, nargs, args, nullptr, &obj))
879 return (TCppObject_t)obj;
880 return (TCppObject_t)0;
881}
882
884{
886 cr->Destructor((void*)self, true);
887}
888
890 TCppObject_t self, size_t nargs, void* args, TCppType_t result_type)
891{
892 TClassRef& cr = type_from_handle(result_type);
893 void* obj = ::operator new(gInterpreter->ClassInfo_Size(cr->GetClassInfo()));
894 if (WrapperCall(method, nargs, args, self, obj))
895 return (TCppObject_t)obj;
896 ::operator delete(obj);
897 return (TCppObject_t)0;
898}
899
901{
902 if (check_enabled && !gEnableFastPath) return (TCppFuncAddr_t)nullptr;
903 TFunction* f = m2f(method);
904 TCppFuncAddr_t pf = gInterpreter->FindSym(f->GetMangledName());
905 if (pf) return pf;
906
907 int ierr = 0;
908 const char* fn = TClassEdit::DemangleName(f->GetMangledName(), ierr);
909 if (ierr || !fn)
910 return pf;
911
912 // TODO: the following attempts are all brittle and leak transactions, but
913 // each properly exposes the symbol so subsequent lookups will succeed
914 if (strstr(f->GetName(), "<")) {
915 // force explicit instantiation and try again
916 std::ostringstream sig;
917 sig << "template " << fn << ";";
918 gInterpreter->ProcessLine(sig.str().c_str());
919 } else {
920 std::string sfn(fn);
921 std::string addrstr;
922 addrstr.reserve(128);
923 addrstr.push_back('(');
924 addrstr.append(Cppyy::GetMethodResultType(method));
925 addrstr.append(" (");
926
927 if (gInterpreter->FunctionDeclId_IsMethod(m2d(method))) {
928 std::string::size_type colon = sfn.rfind("::");
929 if (colon != std::string::npos) addrstr.append(sfn.substr(0, colon+2));
930 }
931
932 addrstr.append("*)");
933 addrstr.append(Cppyy::GetMethodSignature(method, false));
934 addrstr.append(") &");
935
936 addrstr.append(sfn.substr(0, sfn.find('(')));
937
938 gInterpreter->Calc(addrstr.c_str());
939 }
940
941 return (TCppFuncAddr_t)gInterpreter->FindSym(f->GetMangledName());
942}
943
944
945// handling of function argument buffer --------------------------------------
947{
948 return new Parameter[nargs];
949}
950
952{
953 delete [] (Parameter*)args;
954}
955
957{
958 return sizeof(Parameter);
959}
960
962{
963 return offsetof(Parameter, fTypeCode);
964}
965
966
967// scope reflection information ----------------------------------------------
969{
970// Test if this scope represents a namespace.
971 if (scope == GLOBAL_HANDLE)
972 return true;
973 TClassRef& cr = type_from_handle(scope);
974 if (cr.GetClass())
975 return cr->Property() & kIsNamespace;
976 return false;
977}
978
980{
981// Test if this type may not be instantiated.
982 TClassRef& cr = type_from_handle(klass);
983 if (cr.GetClass())
984 return cr->Property() & kIsAbstract;
985 return false;
986}
987
988bool Cppyy::IsEnum(const std::string& type_name)
989{
990 if (type_name.empty()) return false;
991 std::string tn_short = TClassEdit::ShortType(type_name.c_str(), 1);
992 if (tn_short.empty()) return false;
993 return gInterpreter->ClassInfo_IsEnum(tn_short.c_str());
994}
995
997{
998// Test if this type is an aggregate type
999 TClassRef& cr = type_from_handle(klass);
1000 if (cr.GetClass())
1001 return cr->ClassProperty() & kClassIsAggregate;
1002 return false;
1003}
1004
1005// helpers for stripping scope names
1006static
1007std::string outer_with_template(const std::string& name)
1008{
1009// Cut down to the outer-most scope from <name>, taking proper care of templates.
1010 int tpl_open = 0;
1011 for (std::string::size_type pos = 0; pos < name.size(); ++pos) {
1012 std::string::value_type c = name[pos];
1013
1014 // count '<' and '>' to be able to skip template contents
1015 if (c == '<')
1016 ++tpl_open;
1017 else if (c == '>')
1018 --tpl_open;
1019
1020 // collect name up to "::"
1021 else if (tpl_open == 0 && \
1022 c == ':' && pos+1 < name.size() && name[pos+1] == ':') {
1023 // found the extend of the scope ... done
1024 return name.substr(0, pos-1);
1025 }
1026 }
1027
1028// whole name is apparently a single scope
1029 return name;
1030}
1031
1032static
1033std::string outer_no_template(const std::string& name)
1034{
1035// Cut down to the outer-most scope from <name>, drop templates
1036 std::string::size_type first_scope = name.find(':');
1037 if (first_scope == std::string::npos)
1038 return name.substr(0, name.find('<'));
1039 std::string::size_type first_templ = name.find('<');
1040 if (first_templ == std::string::npos)
1041 return name.substr(0, first_scope);
1042 return name.substr(0, std::min(first_templ, first_scope));
1043}
1044
1045#define FILL_COLL(type, filter) { \
1046 TIter itr{coll}; \
1047 type* obj = nullptr; \
1048 while ((obj = (type*)itr.Next())) { \
1049 const char* nm = obj->GetName(); \
1050 if (nm && nm[0] != '_' && !(obj->Property() & (filter))) { \
1051 if (gInitialNames.find(nm) == gInitialNames.end()) \
1052 cppnames.insert(nm); \
1053 }}}
1054
1055static inline
1056void cond_add(Cppyy::TCppScope_t scope, const std::string& ns_scope,
1057 std::set<std::string>& cppnames, const char* name, bool nofilter = false)
1058{
1059 if (!name || name[0] == '_' || strstr(name, ".h") != 0 || strncmp(name, "operator", 8) == 0)
1060 return;
1061
1062 if (scope == GLOBAL_HANDLE) {
1063 std::string to_add = outer_no_template(name);
1064 if ((nofilter || gInitialNames.find(to_add) == gInitialNames.end()) && !is_missclassified_stl(name))
1065 cppnames.insert(outer_no_template(name));
1066 } else if (scope == STD_HANDLE) {
1067 if (strncmp(name, "std::", 5) == 0) {
1068 name += 5;
1069#ifdef __APPLE__
1070 if (strncmp(name, "__1::", 5) == 0) name += 5;
1071#endif
1072 } else if (!is_missclassified_stl(name))
1073 return;
1074 cppnames.insert(outer_no_template(name));
1075 } else {
1076 if (strncmp(name, ns_scope.c_str(), ns_scope.size()) == 0)
1077 cppnames.insert(outer_with_template(name + ns_scope.size()));
1078 }
1079}
1080
1081void Cppyy::GetAllCppNames(TCppScope_t scope, std::set<std::string>& cppnames)
1082{
1083// Collect all known names of C++ entities under scope. This is useful for IDEs
1084// employing tab-completion, for example. Note that functions names need not be
1085// unique as they can be overloaded.
1086 TClassRef& cr = type_from_handle(scope);
1087 if (scope != GLOBAL_HANDLE && !(cr.GetClass() && cr->Property()))
1088 return;
1089
1090 std::string ns_scope = GetFinalName(scope);
1091 if (scope != GLOBAL_HANDLE) ns_scope += "::";
1092
1093// add existing values from read rootmap files if within this scope
1094 TCollection* coll = gInterpreter->GetMapfile()->GetTable();
1095 {
1096 TIter itr{coll};
1097 TEnvRec* ev = nullptr;
1098 while ((ev = (TEnvRec*)itr.Next())) {
1099 // TEnv contains rootmap entries and user-side rootmap files may be already
1100 // loaded on startup. Thus, filter on file name rather than load time.
1101 if (gRootSOs.find(ev->GetValue()) == gRootSOs.end())
1102 cond_add(scope, ns_scope, cppnames, ev->GetName(), true);
1103 }
1104 }
1105
1106// do we care about the class table or are the rootmap and list of types enough?
1107/*
1108 gClassTable->Init();
1109 const int N = gClassTable->Classes();
1110 for (int i = 0; i < N; ++i)
1111 cond_add(scope, ns_scope, cppnames, gClassTable->Next());
1112*/
1113
1114// any other types (e.g. that may have come from parsing headers)
1115 coll = gROOT->GetListOfTypes();
1116 {
1117 TIter itr{coll};
1118 TDataType* dt = nullptr;
1119 while ((dt = (TDataType*)itr.Next())) {
1120 if (!(dt->Property() & kIsFundamental)) {
1121 cond_add(scope, ns_scope, cppnames, dt->GetName());
1122 }
1123 }
1124 }
1125
1126// add functions
1127 coll = (scope == GLOBAL_HANDLE) ?
1128 gROOT->GetListOfGlobalFunctions() : cr->GetListOfMethods();
1129 {
1130 TIter itr{coll};
1131 TFunction* obj = nullptr;
1132 while ((obj = (TFunction*)itr.Next())) {
1133 const char* nm = obj->GetName();
1134 // skip templated functions, adding only the un-instantiated ones
1135 if (nm && nm[0] != '_' && strstr(nm, "<") == 0 && strncmp(nm, "operator", 8) != 0) {
1136 if (gInitialNames.find(nm) == gInitialNames.end())
1137 cppnames.insert(nm);
1138 }
1139 }
1140 }
1141
1142// add uninstantiated templates
1143 coll = (scope == GLOBAL_HANDLE) ?
1144 gROOT->GetListOfFunctionTemplates() : cr->GetListOfFunctionTemplates();
1146
1147// add (global) data members
1148 if (scope == GLOBAL_HANDLE) {
1149 coll = gROOT->GetListOfGlobals();
1151 } else {
1152 coll = cr->GetListOfDataMembers();
1154 coll = cr->GetListOfUsingDataMembers();
1156 }
1157
1158// add enums values only for user classes/namespaces
1159 if (scope != GLOBAL_HANDLE && scope != STD_HANDLE) {
1160 coll = cr->GetListOfEnums();
1162 }
1163
1164#ifdef __APPLE__
1165// special case for Apple, add version namespace '__1' entries to std
1166 if (scope == STD_HANDLE)
1167 GetAllCppNames(GetScope("std::__1"), cppnames);
1168#endif
1169}
1170
1171
1172// class reflection information ----------------------------------------------
1173std::vector<Cppyy::TCppScope_t> Cppyy::GetUsingNamespaces(TCppScope_t scope)
1174{
1175 std::vector<Cppyy::TCppScope_t> res;
1176 if (!IsNamespace(scope))
1177 return res;
1178
1179#ifdef __APPLE__
1180 if (scope == STD_HANDLE) {
1181 res.push_back(GetScope("__1"));
1182 return res;
1183 }
1184#endif
1185
1186 TClassRef& cr = type_from_handle(scope);
1187 if (!cr.GetClass() || !cr->GetClassInfo())
1188 return res;
1189
1190 const std::vector<std::string>& v = gInterpreter->GetUsingNamespaces(cr->GetClassInfo());
1191 res.reserve(v.size());
1192 for (const auto& uid : v) {
1193 Cppyy::TCppScope_t uscope = GetScope(uid);
1194 if (uscope) res.push_back(uscope);
1195 }
1196
1197 return res;
1198}
1199
1200
1201// class reflection information ----------------------------------------------
1203{
1204 if (klass == GLOBAL_HANDLE)
1205 return "";
1206 TClassRef& cr = type_from_handle(klass);
1207 std::string clName = cr->GetName();
1208// TODO: why is this template splitting needed?
1209 std::string::size_type pos = clName.substr(0, clName.find('<')).rfind("::");
1210 if (pos != std::string::npos)
1211 return clName.substr(pos+2, std::string::npos);
1212 return clName;
1213}
1214
1216{
1217 if (klass == GLOBAL_HANDLE)
1218 return "";
1219 TClassRef& cr = type_from_handle(klass);
1220 if (cr.GetClass()) {
1221 std::string name = cr->GetName();
1223 return std::string("std::")+cr->GetName();
1224 return cr->GetName();
1225 }
1226 return "";
1227}
1228
1230{
1231 TClassRef& cr = type_from_handle(klass);
1232 if (!cr.GetClass())
1233 return false;
1234
1235 TFunction* f = cr->GetMethod(("~"+GetFinalName(klass)).c_str(), "");
1236 if (f && (f->Property() & kIsVirtual))
1237 return true;
1238
1239 return false;
1240}
1241
1243{
1244 int is_complex = 1;
1245 size_t nbases = 0;
1246
1247 TClassRef& cr = type_from_handle(klass);
1248 if (cr.GetClass() && cr->GetListOfBases() != 0)
1249 nbases = GetNumBases(klass);
1250
1251 if (1 < nbases)
1252 is_complex = 1;
1253 else if (nbases == 0)
1254 is_complex = 0;
1255 else { // one base class only
1256 TBaseClass* base = (TBaseClass*)cr->GetListOfBases()->At(0);
1257 if (base->Property() & kIsVirtualBase)
1258 is_complex = 1; // TODO: verify; can be complex, need not be.
1259 else
1260 is_complex = HasComplexHierarchy(GetScope(base->GetName()));
1261 }
1262
1263 return is_complex;
1264}
1265
1267{
1268// Get the total number of base classes that this class has.
1269 TClassRef& cr = type_from_handle(klass);
1270 if (cr.GetClass() && cr->GetListOfBases() != 0)
1271 return (TCppIndex_t)cr->GetListOfBases()->GetSize();
1272 return (TCppIndex_t)0;
1273}
1274
1275////////////////////////////////////////////////////////////////////////////////
1276/// \fn Cppyy::TCppIndex_t GetLongestInheritancePath(TClass *klass)
1277/// \brief Retrieve number of base classes in the longest branch of the
1278/// inheritance tree of the input class.
1279/// \param[in] klass The class to start the retrieval process from.
1280///
1281/// This is a helper function for Cppyy::GetNumBasesLongestBranch.
1282/// Given an inheritance tree, the function assigns weight 1 to each class that
1283/// has at least one base. Starting from the input class, the function is
1284/// called recursively on all the bases. For each base the return value is one
1285/// (the weight of the base itself) plus the maximum value retrieved for their
1286/// bases in turn. For example, given the following inheritance tree:
1287///
1288/// ~~~{.cpp}
1289/// class A {}; class B: public A {};
1290/// class X {}; class Y: public X {}; class Z: public Y {};
1291/// class C: public B, Z {};
1292/// ~~~
1293///
1294/// calling this function on an instance of `C` will return 3, the steps
1295/// required to go from C to X.
1297{
1298
1299 auto directbases = klass->GetListOfBases();
1300 if (!directbases) {
1301 // This is a leaf with no bases
1302 return 0;
1303 }
1304 auto ndirectbases = directbases->GetSize();
1305 if (ndirectbases == 0) {
1306 // This is a leaf with no bases
1307 return 0;
1308 } else {
1309 // If there is at least one direct base
1310 std::vector<Cppyy::TCppIndex_t> nbases_branches;
1311 nbases_branches.reserve(ndirectbases);
1312
1313 // Traverse all direct bases of the current class and call the function
1314 // recursively
1315 for (auto baseclass : TRangeDynCast<TBaseClass>(directbases)) {
1316 if (!baseclass)
1317 continue;
1318 if (auto baseclass_tclass = baseclass->GetClassPointer()) {
1319 nbases_branches.emplace_back(GetLongestInheritancePath(baseclass_tclass));
1320 }
1321 }
1322
1323 // Get longest path among the direct bases of the current class
1324 auto longestbranch = std::max_element(std::begin(nbases_branches), std::end(nbases_branches));
1325
1326 // Add 1 to include the current class in the count
1327 return 1 + *longestbranch;
1328 }
1329}
1330
1331////////////////////////////////////////////////////////////////////////////////
1332/// \fn Cppyy::TCppIndex_t Cppyy::GetNumBasesLongestBranch(TCppType_t klass)
1333/// \brief Retrieve number of base classes in the longest branch of the
1334/// inheritance tree.
1335/// \param[in] klass The class to start the retrieval process from.
1336///
1337/// The function converts the input class to a `TClass *` and calls
1338/// GetLongestInheritancePath.
1340{
1341
1342 const auto &cr = type_from_handle(klass);
1343
1344 if (auto klass_tclass = cr.GetClass()) {
1345 return GetLongestInheritancePath(klass_tclass);
1346 }
1347
1348 // In any other case, return zero
1349 return 0;
1350}
1351
1353{
1354 TClassRef& cr = type_from_handle(klass);
1355 return ((TBaseClass*)cr->GetListOfBases()->At((int)ibase))->GetName();
1356}
1357
1359{
1360 if (derived == base)
1361 return true;
1362 TClassRef& derived_type = type_from_handle(derived);
1363 TClassRef& base_type = type_from_handle(base);
1364 return derived_type->GetBaseClass(base_type) != 0;
1365}
1366
1368{
1369 TClassRef& cr = type_from_handle(klass);
1370 const std::string& tn = cr->GetName();
1371 if (gSmartPtrTypes.find(tn.substr(0, tn.find("<"))) != gSmartPtrTypes.end())
1372 return true;
1373 return false;
1374}
1375
1377 const std::string& tname, TCppType_t* raw, TCppMethod_t* deref)
1378{
1379 const std::string& rn = ResolveName(tname);
1380 if (gSmartPtrTypes.find(rn.substr(0, rn.find("<"))) != gSmartPtrTypes.end()) {
1381 if (!raw && !deref) return true;
1382
1383 TClassRef& cr = type_from_handle(GetScope(tname));
1384 if (cr.GetClass()) {
1385 TFunction* func = cr->GetMethod("operator->", "");
1386 if (!func) {
1387 gInterpreter->UpdateListOfMethods(cr.GetClass());
1388 func = cr->GetMethod("operator->", "");
1389 }
1390 if (func) {
1391 if (deref) *deref = (TCppMethod_t)new_CallWrapper(func);
1392 if (raw) *raw = GetScope(TClassEdit::ShortType(
1393 func->GetReturnTypeNormalizedName().c_str(), 1));
1394 return (!deref || *deref) && (!raw || *raw);
1395 }
1396 }
1397 }
1398
1399 return false;
1400}
1401
1402void Cppyy::AddSmartPtrType(const std::string& type_name)
1403{
1404 gSmartPtrTypes.insert(ResolveName(type_name));
1405}
1406
1407
1408// type offsets --------------------------------------------------------------
1410 TCppObject_t address, int direction, bool rerror)
1411{
1412// calculate offsets between declared and actual type, up-cast: direction > 0; down-cast: direction < 0
1413 if (derived == base || !(base && derived))
1414 return (ptrdiff_t)0;
1415
1416 TClassRef& cd = type_from_handle(derived);
1417 TClassRef& cb = type_from_handle(base);
1418
1419 if (!cd.GetClass() || !cb.GetClass())
1420 return (ptrdiff_t)0;
1421
1422 ptrdiff_t offset = -1;
1423 if (!(cd->GetClassInfo() && cb->GetClassInfo())) { // gInterpreter requirement
1424 // would like to warn, but can't quite determine error from intentional
1425 // hiding by developers, so only cover the case where we really should have
1426 // had a class info, but apparently don't:
1427 if (cd->IsLoaded()) {
1428 // warn to allow diagnostics
1429 std::ostringstream msg;
1430 msg << "failed offset calculation between " << cb->GetName() << " and " << cd->GetName();
1431 // TODO: propagate this warning to caller w/o use of Python C-API
1432 // PyErr_Warn(PyExc_RuntimeWarning, const_cast<char*>(msg.str().c_str()));
1433 std::cerr << "Warning: " << msg.str() << '\n';
1434 }
1435
1436 // return -1 to signal caller NOT to apply offset
1437 return rerror ? (ptrdiff_t)offset : 0;
1438 }
1439
1440 offset = gInterpreter->ClassInfo_GetBaseOffset(
1441 cd->GetClassInfo(), cb->GetClassInfo(), (void*)address, direction > 0);
1442 if (offset == -1) // Cling error, treat silently
1443 return rerror ? (ptrdiff_t)offset : 0;
1444
1445 return (ptrdiff_t)(direction < 0 ? -offset : offset);
1446}
1447
1448
1449// method/function reflection information ------------------------------------
1451{
1452 if (IsNamespace(scope))
1453 return (TCppIndex_t)0; // enforce lazy
1454
1455 TClassRef& cr = type_from_handle(scope);
1456 if (cr.GetClass() && cr->GetListOfMethods(true)) {
1457 Cppyy::TCppIndex_t nMethods = (TCppIndex_t)cr->GetListOfMethods(false)->GetSize();
1458 if (nMethods == (TCppIndex_t)0) {
1459 std::string clName = GetScopedFinalName(scope);
1460 if (clName.find('<') != std::string::npos) {
1461 // chicken-and-egg problem: TClass does not know about methods until
1462 // instantiation, so force it
1463 if (clName.find("std::", 0, 5) == std::string::npos && \
1464 is_missclassified_stl(clName)) {
1465 // TODO: this is too simplistic for template arguments missing std::
1466 clName = "std::" + clName;
1467 }
1468 std::ostringstream stmt;
1469 stmt << "template class " << clName << ";";
1470 gInterpreter->Declare(stmt.str().c_str());
1471
1472 // now reload the methods
1473 return (TCppIndex_t)cr->GetListOfMethods(true)->GetSize();
1474 }
1475 }
1476 return nMethods;
1477 }
1478
1479 return (TCppIndex_t)0; // unknown class?
1480}
1481
1482std::vector<Cppyy::TCppIndex_t> Cppyy::GetMethodIndicesFromName(
1483 TCppScope_t scope, const std::string& name)
1484{
1485 std::vector<TCppIndex_t> indices;
1486 TClassRef& cr = type_from_handle(scope);
1487 if (cr.GetClass()) {
1488 gInterpreter->UpdateListOfMethods(cr.GetClass());
1489 int imeth = 0;
1490 TFunction* func = nullptr;
1491 TIter next(cr->GetListOfMethods());
1492 while ((func = (TFunction*)next())) {
1493 if (match_name(name, func->GetName())) {
1494 if (func->Property() & kIsPublic)
1495 indices.push_back((TCppIndex_t)imeth);
1496 }
1497 ++imeth;
1498 }
1499 } else if (scope == GLOBAL_HANDLE) {
1500 TCollection* funcs = gROOT->GetListOfGlobalFunctions(true);
1501
1502 // tickle deserialization
1503 if (!funcs->FindObject(name.c_str()))
1504 return indices;
1505
1506 TFunction* func = nullptr;
1507 TIter ifunc(funcs);
1508 while ((func = (TFunction*)ifunc.Next())) {
1509 if (match_name(name, func->GetName()))
1510 indices.push_back((TCppIndex_t)new_CallWrapper(func));
1511 }
1512 }
1513
1514 return indices;
1515}
1516
1518{
1519 TClassRef& cr = type_from_handle(scope);
1520 if (cr.GetClass()) {
1521 TFunction* f = (TFunction*)cr->GetListOfMethods(false)->At((int)idx);
1522 if (f) return (Cppyy::TCppMethod_t)new_CallWrapper(f);
1523 return (Cppyy::TCppMethod_t)nullptr;
1524 }
1525
1526 assert(klass == (Cppyy::TCppType_t)GLOBAL_HANDLE);
1527 return (Cppyy::TCppMethod_t)idx;
1528}
1529
1531{
1532 if (method) {
1533 const std::string& name = ((CallWrapper*)method)->fName;
1534
1535 if (name.compare(0, 8, "operator") != 0)
1536 // strip template instantiation part, if any
1537 return name.substr(0, name.find('<'));
1538 return name;
1539 }
1540 return "<unknown>";
1541}
1542
1544{
1545 if (method) {
1546 std::string name = ((CallWrapper*)method)->fName;
1547 name.erase(std::remove(name.begin(), name.end(), ' '), name.end());
1548 return name;
1549 }
1550 return "<unknown>";
1551}
1552
1554{
1555 if (method)
1556 return m2f(method)->GetMangledName();
1557 return "<unknown>";
1558}
1559
1561{
1562 if (method) {
1563 TFunction* f = m2f(method);
1564 if (f->ExtraProperty() & kIsConstructor)
1565 return "constructor";
1566 std::string restype = f->GetReturnTypeName();
1567 // TODO: this is ugly, but we can't use GetReturnTypeName() for ostreams
1568 // and maybe others, whereas GetReturnTypeNormalizedName() has proven to
1569 // be save in all cases (Note: 'int8_t' covers 'int8_t' and 'uint8_t')
1570 if (restype.find("int8_t") != std::string::npos)
1571 return restype;
1572 restype = f->GetReturnTypeNormalizedName();
1573 if (restype == "(lambda)") {
1574 std::ostringstream s;
1575 // TODO: what if there are parameters to the lambda?
1576 s << "__cling_internal::FT<decltype("
1577 << GetMethodFullName(method) << "(";
1578 for (Cppyy::TCppIndex_t i = 0; i < Cppyy::GetMethodNumArgs(method); ++i) {
1579 if (i != 0) s << ", ";
1580 s << Cppyy::GetMethodArgType(method, i) << "{}";
1581 }
1582 s << "))>::F";
1583 TClass* cl = TClass::GetClass(s.str().c_str());
1584 if (cl) return cl->GetName();
1585 // TODO: signal some type of error (or should that be upstream?
1586 }
1587 return restype;
1588 }
1589 return "<unknown>";
1590}
1591
1593{
1594 if (method)
1595 return m2f(method)->GetNargs();
1596 return 0;
1597}
1598
1600{
1601 if (method) {
1602 TFunction* f = m2f(method);
1603 return (TCppIndex_t)(f->GetNargs() - f->GetNargsOpt());
1604 }
1605 return (TCppIndex_t)0;
1606}
1607
1609{
1610 if (method) {
1611 TFunction* f = m2f(method);
1612 TMethodArg* arg = (TMethodArg*)f->GetListOfMethodArgs()->At((int)iarg);
1613 return arg->GetName();
1614 }
1615 return "<unknown>";
1616}
1617
1619{
1620 if (method) {
1621 TFunction* f = m2f(method);
1622 TMethodArg* arg = (TMethodArg*)f->GetListOfMethodArgs()->At((int)iarg);
1623 return arg->GetTypeNormalizedName();
1624 }
1625 return "<unknown>";
1626}
1627
1629{
1630 if (method) {
1631 TFunction* f = m2f(method);
1632 TMethodArg* arg = (TMethodArg *)f->GetListOfMethodArgs()->At((int)iarg);
1633 void *argqtp = gInterpreter->TypeInfo_QualTypePtr(arg->GetTypeInfo());
1634
1635 TypeInfo_t *reqti = gInterpreter->TypeInfo_Factory(req_type.c_str());
1636 void *reqqtp = gInterpreter->TypeInfo_QualTypePtr(reqti);
1637
1638 // This scoring is not based on any particular rules
1639 if (gInterpreter->IsSameType(argqtp, reqqtp))
1640 return 0; // Best match
1641 else if ((gInterpreter->IsSignedIntegerType(argqtp) && gInterpreter->IsSignedIntegerType(reqqtp)) ||
1642 (gInterpreter->IsUnsignedIntegerType(argqtp) && gInterpreter->IsUnsignedIntegerType(reqqtp)) ||
1643 (gInterpreter->IsFloatingType(argqtp) && gInterpreter->IsFloatingType(reqqtp)))
1644 return 1;
1645 else if ((gInterpreter->IsSignedIntegerType(argqtp) && gInterpreter->IsUnsignedIntegerType(reqqtp)) ||
1646 (gInterpreter->IsFloatingType(argqtp) && gInterpreter->IsUnsignedIntegerType(reqqtp)))
1647 return 2;
1648 else if ((gInterpreter->IsIntegerType(argqtp) && gInterpreter->IsIntegerType(reqqtp)))
1649 return 3;
1650 else if ((gInterpreter->IsVoidPointerType(argqtp) && gInterpreter->IsPointerType(reqqtp)))
1651 return 4;
1652 else
1653 return 10; // Penalize heavily for no possible match
1654 }
1655 return INT_MAX; // Method is not valid
1656}
1657
1659{
1660 if (method) {
1661 TFunction* f = m2f(method);
1662 TMethodArg* arg = (TMethodArg*)f->GetListOfMethodArgs()->At((int)iarg);
1663 const char* def = arg->GetDefault();
1664 if (def)
1665 return def;
1666 }
1667
1668 return "";
1669}
1670
1671std::string Cppyy::GetMethodSignature(TCppMethod_t method, bool show_formalargs, TCppIndex_t maxargs)
1672{
1673 TFunction* f = m2f(method);
1674 if (f) {
1675 std::ostringstream sig;
1676 sig << "(";
1677 int nArgs = f->GetNargs();
1678 if (maxargs != (TCppIndex_t)-1) nArgs = std::min(nArgs, (int)maxargs);
1679 for (int iarg = 0; iarg < nArgs; ++iarg) {
1680 TMethodArg* arg = (TMethodArg*)f->GetListOfMethodArgs()->At(iarg);
1681 sig << arg->GetFullTypeName();
1682 if (show_formalargs) {
1683 const char* argname = arg->GetName();
1684 if (argname && argname[0] != '\0') sig << " " << argname;
1685 const char* defvalue = arg->GetDefault();
1686 if (defvalue && defvalue[0] != '\0') sig << " = " << defvalue;
1687 }
1688 if (iarg != nArgs-1) sig << (show_formalargs ? ", " : ",");
1689 }
1690 sig << ")";
1691 return sig.str();
1692 }
1693 return "<unknown>";
1694}
1695
1696std::string Cppyy::GetMethodPrototype(TCppScope_t scope, TCppMethod_t method, bool show_formalargs)
1697{
1698 std::string scName = GetScopedFinalName(scope);
1699 TFunction* f = m2f(method);
1700 if (f) {
1701 std::ostringstream sig;
1702 sig << f->GetReturnTypeName() << " "
1703 << scName << "::" << f->GetName();
1704 sig << GetMethodSignature(method, show_formalargs);
1705 return sig.str();
1706 }
1707 return "<unknown>";
1708}
1709
1711{
1712 if (method) {
1713 TFunction* f = m2f(method);
1714 return f->Property() & kIsConstMethod;
1715 }
1716 return false;
1717}
1718
1720{
1721 if (scope == (TCppScope_t)GLOBAL_HANDLE) {
1722 TCollection* coll = gROOT->GetListOfFunctionTemplates();
1723 if (coll) return (TCppIndex_t)coll->GetSize();
1724 } else {
1725 TClassRef& cr = type_from_handle(scope);
1726 if (cr.GetClass()) {
1727 TCollection* coll = cr->GetListOfFunctionTemplates(true);
1728 if (coll) return (TCppIndex_t)coll->GetSize();
1729 }
1730 }
1731
1732// failure ...
1733 return (TCppIndex_t)0;
1734}
1735
1737{
1738 if (scope == (TCppScope_t)GLOBAL_HANDLE)
1739 return ((THashList*)gROOT->GetListOfFunctionTemplates())->At((int)imeth)->GetName();
1740 else {
1741 TClassRef& cr = type_from_handle(scope);
1742 if (cr.GetClass())
1743 return cr->GetListOfFunctionTemplates(false)->At((int)imeth)->GetName();
1744 }
1745
1746// failure ...
1747 assert(!"should not be called unless GetNumTemplatedMethods() succeeded");
1748 return "";
1749}
1750
1752{
1753 if (scope == (TCppScope_t)GLOBAL_HANDLE)
1754 return false;
1755
1756 TClassRef& cr = type_from_handle(scope);
1757 if (cr.GetClass()) {
1759 return f->ExtraProperty() & kIsConstructor;
1760 }
1761
1762 return false;
1763}
1764
1765bool Cppyy::ExistsMethodTemplate(TCppScope_t scope, const std::string& name)
1766{
1767 if (scope == (TCppScope_t)GLOBAL_HANDLE)
1768 return (bool)gROOT->GetFunctionTemplate(name.c_str());
1769 else {
1770 TClassRef& cr = type_from_handle(scope);
1771 if (cr.GetClass())
1772 return (bool)cr->GetFunctionTemplate(name.c_str());
1773 }
1774
1775// failure ...
1776 return false;
1777}
1778
1780{
1781 TClassRef& cr = type_from_handle(scope);
1782 if (cr.GetClass()) {
1783 TFunction* f = (TFunction*)cr->GetListOfMethods(false)->At((int)idx);
1784 if (f && strstr(f->GetName(), "<")) return true;
1785 return false;
1786 }
1787
1788 assert(scope == (Cppyy::TCppType_t)GLOBAL_HANDLE);
1789 if (((CallWrapper*)idx)->fName.find('<') != std::string::npos) return true;
1790 return false;
1791}
1792
1793// helpers for Cppyy::GetMethodTemplate()
1794static std::map<TDictionary::DeclId_t, CallWrapper*> gMethodTemplates;
1795
1797 TCppScope_t scope, const std::string& name, const std::string& proto)
1798{
1799// There is currently no clean way of extracting a templated method out of ROOT/meta
1800// for a variety of reasons, none of them fundamental. The game played below is to
1801// first get any pre-existing functions already managed by ROOT/meta, but if that fails,
1802// to do an explicit lookup that ignores the prototype (i.e. the full name should be
1803// enough), and finally to ignore the template arguments part of the name as this fails
1804// in cling if there are default parameters.
1805// It would be possible to get the prototype from the created functions and use that to
1806// do a new lookup, after which ROOT/meta will manage the function. However, neither
1807// TFunction::GetPrototype() nor TFunction::GetSignature() is of the proper form, so
1808// we'll/ manage the new TFunctions instead and will assume that they are cached on the
1809// calling side to prevent multiple creations.
1810 TFunction* func = nullptr; ClassInfo_t* cl = nullptr;
1811 if (scope == (cppyy_scope_t)GLOBAL_HANDLE) {
1812 func = gROOT->GetGlobalFunctionWithPrototype(name.c_str(), proto.c_str());
1813 if (func && name.back() == '>' && name != func->GetName())
1814 func = nullptr; // happens if implicit conversion matches the overload
1815 } else {
1816 TClassRef& cr = type_from_handle(scope);
1817 if (cr.GetClass()) {
1818 func = cr->GetMethodWithPrototype(name.c_str(), proto.c_str());
1819 if (!func) {
1820 cl = cr->GetClassInfo();
1821 // try base classes to cover a common 'using' case (TODO: this is stupid and misses
1822 // out on base classes; fix that with improved access to Cling)
1823 TCppIndex_t nbases = GetNumBases(scope);
1824 for (TCppIndex_t i = 0; i < nbases; ++i) {
1825 TClassRef& base = type_from_handle(GetScope(GetBaseName(scope, i)));
1826 if (base.GetClass()) {
1827 func = base->GetMethodWithPrototype(name.c_str(), proto.c_str());
1828 if (func) break;
1829 }
1830 }
1831 }
1832 }
1833 }
1834
1835 if (!func && name.back() == '>' && (cl || scope == (cppyy_scope_t)GLOBAL_HANDLE)) {
1836 // try again, ignoring proto in case full name is complete template
1837 auto declid = gInterpreter->GetFunction(cl, name.c_str());
1838 if (declid) {
1839 auto existing = gMethodTemplates.find(declid);
1840 if (existing == gMethodTemplates.end()) {
1841 auto cw = new_CallWrapper(declid, name);
1842 existing = gMethodTemplates.insert(std::make_pair(declid, cw)).first;
1843 }
1844 return (TCppMethod_t)existing->second;
1845 }
1846 }
1847
1848 if (func) {
1849 // make sure we didn't match a non-templated overload
1850 if (func->ExtraProperty() & kIsTemplateSpec)
1851 return (TCppMethod_t)new_CallWrapper(func);
1852
1853 // disregard this non-templated method as it will be considered when appropriate
1854 return (TCppMethod_t)nullptr;
1855 }
1856
1857// try again with template arguments removed from name, if applicable
1858 if (name.back() == '>') {
1859 auto pos = name.find('<');
1860 if (pos != std::string::npos) {
1861 TCppMethod_t cppmeth = GetMethodTemplate(scope, name.substr(0, pos), proto);
1862 if (cppmeth) {
1863 // allow if requested template names match up to the result
1864 const std::string& alt = GetMethodFullName(cppmeth);
1865 if (name.size() < alt.size() && alt.find('<') == pos) {
1866 const std::string& partial = name.substr(pos, name.size()-1-pos);
1867 if (strncmp(partial.c_str(), alt.substr(pos, alt.size()-1-pos).c_str(), partial.size()) == 0)
1868 return cppmeth;
1869 }
1870 }
1871 }
1872 }
1873
1874// failure ...
1875 return (TCppMethod_t)nullptr;
1876}
1877
1878static inline
1879std::string type_remap(const std::string& n1, const std::string& n2)
1880{
1881// Operator lookups of (C++ string, Python str) should succeeded, for the combos of
1882// string/str, wstring/str, string/unicode and wstring/unicode; since C++ does not have a
1883// operator+(std::string, std::wstring), we'll have to look up the same type and rely on
1884// the converters in CPyCppyy/_cppyy.
1885 if (n1 == "str") {
1886 if (n2 == "std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >")
1887 return n2; // match like for like
1888 return "std::string"; // probably best bet
1889 } else if (n1 == "float")
1890 return "double"; // debatable, but probably intended
1891 return n1;
1892}
1893
1895 TCppType_t scope, const std::string& lc, const std::string& rc, const std::string& opname)
1896{
1897// Find a global operator function with a matching signature; prefer by-ref, but
1898// fall back on by-value if that fails.
1899 std::string lcname1 = TClassEdit::CleanType(lc.c_str());
1900 const std::string& rcname = rc.empty() ? rc : type_remap(TClassEdit::CleanType(rc.c_str()), lcname1);
1901 const std::string& lcname = type_remap(lcname1, rcname);
1902
1903 std::string proto = lcname + "&" + (rc.empty() ? rc : (", " + rcname + "&"));
1904 if (scope == (cppyy_scope_t)GLOBAL_HANDLE) {
1905 TFunction* func = gROOT->GetGlobalFunctionWithPrototype(opname.c_str(), proto.c_str());
1906 if (func) return (TCppIndex_t)new_CallWrapper(func);
1907 proto = lcname + (rc.empty() ? rc : (", " + rcname));
1908 func = gROOT->GetGlobalFunctionWithPrototype(opname.c_str(), proto.c_str());
1909 if (func) return (TCppIndex_t)new_CallWrapper(func);
1910 } else {
1911 TClassRef& cr = type_from_handle(scope);
1912 if (cr.GetClass()) {
1913 TFunction* func = cr->GetMethodWithPrototype(opname.c_str(), proto.c_str());
1914 if (func) return (TCppIndex_t)cr->GetListOfMethods()->IndexOf(func);
1915 proto = lcname + (rc.empty() ? rc : (", " + rcname));
1916 func = cr->GetMethodWithPrototype(opname.c_str(), proto.c_str());
1917 if (func) return (TCppIndex_t)cr->GetListOfMethods()->IndexOf(func);
1918 }
1919 }
1920
1921// failure ...
1922 return (TCppIndex_t)-1;
1923}
1924
1925// method properties ---------------------------------------------------------
1927{
1928 if (method) {
1929 TFunction* f = m2f(method);
1930 return f->Property() & kIsPublic;
1931 }
1932 return false;
1933}
1934
1936{
1937 if (method) {
1938 TFunction* f = m2f(method);
1939 return f->Property() & kIsProtected;
1940 }
1941 return false;
1942}
1943
1945{
1946 if (method) {
1947 TFunction* f = m2f(method);
1948 return f->ExtraProperty() & kIsConstructor;
1949 }
1950 return false;
1951}
1952
1954{
1955 if (method) {
1956 TFunction* f = m2f(method);
1957 return f->ExtraProperty() & kIsDestructor;
1958 }
1959 return false;
1960}
1961
1963{
1964 if (method) {
1965 TFunction* f = m2f(method);
1966 return f->Property() & kIsStatic;
1967 }
1968 return false;
1969}
1970
1971// data member reflection information ----------------------------------------
1973{
1974 if (IsNamespace(scope))
1975 return (TCppIndex_t)0; // enforce lazy
1976
1977 TClassRef& cr = type_from_handle(scope);
1978 if (cr.GetClass()) {
1980 if (cr->GetListOfDataMembers())
1981 sum = cr->GetListOfDataMembers()->GetSize();
1982 if (cr->GetListOfUsingDataMembers())
1984 return sum;
1985 }
1986
1987 return (TCppIndex_t)0; // unknown class?
1988}
1989
1991{
1992 if (!cr.GetClass() || !cr->GetListOfDataMembers())
1993 return nullptr;
1994
1995 int numDMs = cr->GetListOfDataMembers()->GetSize();
1996 if ((int)idata < numDMs)
1997 return (TDataMember*)cr->GetListOfDataMembers()->At((int)idata);
1998 return (TDataMember*)cr->GetListOfUsingDataMembers()->At((int)idata - numDMs);
1999}
2000
2002{
2003 TClassRef& cr = type_from_handle(scope);
2004 if (cr.GetClass()) {
2005 TDataMember *m = GetDataMemberByIndex(cr, (int)idata);
2006 return m->GetName();
2007 }
2008 assert(scope == GLOBAL_HANDLE);
2009 TGlobal* gbl = g_globalvars[idata];
2010 return gbl->GetName();
2011}
2012
2014{
2015 if (scope == GLOBAL_HANDLE) {
2016 TGlobal* gbl = g_globalvars[idata];
2017 std::string fullType = gbl->GetFullTypeName();
2018
2019 if ((int)gbl->GetArrayDim() > 1)
2020 fullType.append("*");
2021 else if ((int)gbl->GetArrayDim() == 1) {
2022 std::ostringstream s;
2023 s << '[' << gbl->GetMaxIndex(0) << ']' << std::ends;
2024 fullType.append(s.str());
2025 }
2026 return fullType;
2027 }
2028
2029 TClassRef& cr = type_from_handle(scope);
2030 if (cr.GetClass()) {
2031 TDataMember* m = GetDataMemberByIndex(cr, (int)idata);
2032 // TODO: fix this upstream. Usually, we want m->GetFullTypeName(), because it does
2033 // not resolve typedefs, but it looses scopes for inner classes/structs, so in that
2034 // case m->GetTrueTypeName() should be used (this also cleans up the cases where
2035 // the "full type" retains spurious "struct" or "union" in the name).
2036 std::string fullType = m->GetFullTypeName();
2037 if (fullType != m->GetTrueTypeName()) {
2038 const std::string& trueName = m->GetTrueTypeName();
2039 if (fullType.find("::") == std::string::npos && trueName.find("::") != std::string::npos)
2040 fullType = trueName;
2041 }
2042
2043 if ((int)m->GetArrayDim() > 1 || (!m->IsBasic() && m->IsaPointer()))
2044 fullType.append("*");
2045 else if ((int)m->GetArrayDim() == 1) {
2046 std::ostringstream s;
2047 s << '[' << m->GetMaxIndex(0) << ']' << std::ends;
2048 fullType.append(s.str());
2049 }
2050 return fullType;
2051 }
2052
2053 return "<unknown>";
2054}
2055
2057{
2058 if (scope == GLOBAL_HANDLE) {
2059 TGlobal* gbl = g_globalvars[idata];
2060 if (!gbl->GetAddress() || gbl->GetAddress() == (void*)-1) {
2061 // CLING WORKAROUND: make sure variable is loaded
2062 intptr_t addr = (intptr_t)gInterpreter->ProcessLine((std::string("&")+gbl->GetName()+";").c_str());
2063 if (gbl->GetAddress() && gbl->GetAddress() != (void*)-1)
2064 return (intptr_t)gbl->GetAddress(); // now loaded!
2065 return addr; // last resort ...
2066 }
2067 return (intptr_t)gbl->GetAddress();
2068 }
2069
2070 TClassRef& cr = type_from_handle(scope);
2071 if (cr.GetClass()) {
2072 TDataMember* m = GetDataMemberByIndex(cr, (int)idata);
2073 // CLING WORKAROUND: the following causes templates to be instantiated first within the proper
2074 // scope, making the lookup succeed and preventing spurious duplicate instantiations later. Also,
2075 // if the variable is not yet loaded, pull it in through gInterpreter.
2076 if (m->Property() & kIsStatic) {
2077 if (strchr(cr->GetName(), '<'))
2078 gInterpreter->ProcessLine(((std::string)cr->GetName()+"::"+m->GetName()+";").c_str());
2079 if ((intptr_t)m->GetOffsetCint() == (intptr_t)-1)
2080 return (intptr_t)gInterpreter->ProcessLine((std::string("&")+cr->GetName()+"::"+m->GetName()+";").c_str());
2081 }
2082 return (intptr_t)m->GetOffsetCint(); // yes, CINT (GetOffset() is both wrong
2083 // and caches that wrong result!
2084 }
2085
2086 return (intptr_t)-1;
2087}
2088
2090{
2091 if (scope == GLOBAL_HANDLE) {
2092 TGlobal* gb = (TGlobal*)gROOT->GetListOfGlobals(false /* load */)->FindObject(name.c_str());
2093 if (!gb) gb = (TGlobal*)gROOT->GetListOfGlobals(true /* load */)->FindObject(name.c_str());
2094 if (!gb) {
2095 // some enums are not loaded as they are not considered part of
2096 // the global scope, but of the enum scope; get them w/o checking
2097 TDictionary::DeclId_t did = gInterpreter->GetDataMember(nullptr, name.c_str());
2098 if (did) {
2099 DataMemberInfo_t* t = gInterpreter->DataMemberInfo_Factory(did, nullptr);
2100 ((TListOfDataMembers*)gROOT->GetListOfGlobals())->Get(t, true);
2101 gb = (TGlobal*)gROOT->GetListOfGlobals(false /* load */)->FindObject(name.c_str());
2102 }
2103 }
2104
2105 if (gb && strcmp(gb->GetFullTypeName(), "(lambda)") == 0) {
2106 // lambdas use a compiler internal closure type, so we wrap
2107 // them, then return the wrapper's type
2108 // TODO: this current leaks the std::function; also, if possible,
2109 // should instantiate through TClass rather then ProcessLine
2110 std::ostringstream s;
2111 s << "auto __cppyy_internal_wrap_" << name << " = "
2112 "new __cling_internal::FT<decltype(" << name << ")>::F"
2113 "{" << name << "};";
2114 gInterpreter->ProcessLine(s.str().c_str());
2115 TGlobal* wrap = (TGlobal*)gROOT->GetListOfGlobals(true)->FindObject(
2116 ("__cppyy_internal_wrap_"+name).c_str());
2117 if (wrap && wrap->GetAddress()) gb = wrap;
2118 }
2119
2120 if (gb) {
2121 // TODO: do we ever need a reverse lookup?
2122 g_globalvars.push_back(gb);
2123 return TCppIndex_t(g_globalvars.size() - 1);
2124 }
2125
2126 } else {
2127 TClassRef& cr = type_from_handle(scope);
2128 if (cr.GetClass()) {
2129 TDataMember* dm =
2131 // TODO: turning this into an index is silly ...
2132 if (dm) return (TCppIndex_t)cr->GetListOfDataMembers()->IndexOf(dm);
2134 if (dm)
2135 return (TCppIndex_t)cr->GetListOfDataMembers()->IndexOf(dm)
2136 + cr->GetListOfDataMembers()->GetSize();
2137 }
2138 }
2139
2140 return (TCppIndex_t)-1;
2141}
2142
2143
2144// data member properties ----------------------------------------------------
2146{
2147 if (scope == GLOBAL_HANDLE)
2148 return true;
2149 TClassRef& cr = type_from_handle(scope);
2150 if (cr->Property() & kIsNamespace)
2151 return true;
2152 TDataMember* m = GetDataMemberByIndex(cr, (int)idata);
2153 return m->Property() & kIsPublic;
2154}
2155
2157{
2158 if (scope == GLOBAL_HANDLE)
2159 return true;
2160 TClassRef& cr = type_from_handle(scope);
2161 if (cr->Property() & kIsNamespace)
2162 return true;
2163 TDataMember* m = GetDataMemberByIndex(cr, (int)idata);
2164 return m->Property() & kIsProtected;
2165}
2166
2168{
2169 if (scope == GLOBAL_HANDLE)
2170 return true;
2171 TClassRef& cr = type_from_handle(scope);
2172 if (cr->Property() & kIsNamespace)
2173 return true;
2174 TDataMember* m = GetDataMemberByIndex(cr, (int)idata);
2175 return m->Property() & kIsStatic;
2176}
2177
2179{
2180 if (scope == GLOBAL_HANDLE) {
2181 TGlobal* gbl = g_globalvars[idata];
2182 return gbl->Property() & kIsConstant;
2183 }
2184 TClassRef& cr = type_from_handle(scope);
2185 if (cr.GetClass()) {
2186 TDataMember* m = GetDataMemberByIndex(cr, (int)idata);
2187 return m->Property() & kIsConstant;
2188 }
2189 return false;
2190}
2191
2193{
2194// TODO: currently, ROOT/meta does not properly distinguish between variables of enum
2195// type, and values of enums. The latter are supposed to be const. This code relies on
2196// odd features (bugs?) to figure out the difference, but this should really be fixed
2197// upstream and/or deserves a new API.
2198
2199 if (scope == GLOBAL_HANDLE) {
2200 TGlobal* gbl = g_globalvars[idata];
2201
2202 // make use of an oddity: enum global variables do not have their kIsStatic bit
2203 // set, whereas enum global values do
2204 return (gbl->Property() & kIsEnum) && (gbl->Property() & kIsStatic);
2205 }
2206
2207 TClassRef& cr = type_from_handle(scope);
2208 if (cr.GetClass()) {
2209 TDataMember* m = GetDataMemberByIndex(cr, (int)idata);
2210 std::string ti = m->GetTypeName();
2211
2212 // can't check anonymous enums by type name, so just accept them as enums
2213 if (ti.rfind("(unnamed)") != std::string::npos)
2214 return m->Property() & kIsEnum;
2215
2216 // since there seems to be no distinction between data of enum type and enum values,
2217 // check the list of constants for the type to see if there's a match
2218 if (ti.rfind(cr->GetName(), 0) != std::string::npos) {
2219 std::string::size_type s = strlen(cr->GetName())+2;
2220 if (s < ti.size()) {
2221 TEnum* ee = ((TListOfEnums*)cr->GetListOfEnums())->GetObject(ti.substr(s, std::string::npos).c_str());
2222 if (ee) return ee->GetConstant(m->GetName());
2223 }
2224 }
2225 }
2226
2227// this default return only means that the data will be writable, not that it will
2228// be unreadable or otherwise misrepresented
2229 return false;
2230}
2231
2232int Cppyy::GetDimensionSize(TCppScope_t scope, TCppIndex_t idata, int dimension)
2233{
2234 if (scope == GLOBAL_HANDLE) {
2235 TGlobal* gbl = g_globalvars[idata];
2236 return gbl->GetMaxIndex(dimension);
2237 }
2238 TClassRef& cr = type_from_handle(scope);
2239 if (cr.GetClass()) {
2240 TDataMember* m = GetDataMemberByIndex(cr, (int)idata);
2241 return m->GetMaxIndex(dimension);
2242 }
2243 return -1;
2244}
2245
2246
2247// enum properties -----------------------------------------------------------
2248Cppyy::TCppEnum_t Cppyy::GetEnum(TCppScope_t scope, const std::string& enum_name)
2249{
2250 if (scope == GLOBAL_HANDLE)
2251 return (TCppEnum_t)gROOT->GetListOfEnums(kTRUE)->FindObject(enum_name.c_str());
2252
2253 TClassRef& cr = type_from_handle(scope);
2254 if (cr.GetClass())
2255 return (TCppEnum_t)cr->GetListOfEnums(kTRUE)->FindObject(enum_name.c_str());
2256
2257 return (TCppEnum_t)0;
2258}
2259
2261{
2262 return (TCppIndex_t)((TEnum*)etype)->GetConstants()->GetSize();
2263}
2264
2266{
2267 return ((TEnumConstant*)((TEnum*)etype)->GetConstants()->At(idata))->GetName();
2268}
2269
2271{
2272 TEnumConstant* ecst = (TEnumConstant*)((TEnum*)etype)->GetConstants()->At(idata);
2273 return (long long)ecst->GetValue();
2274}
2275
2276
2277//- C-linkage wrappers -------------------------------------------------------
2278
2279extern "C" {
2280/* direct interpreter access ---------------------------------------------- */
2281int cppyy_compile(const char* code) {
2282 return Cppyy::Compile(code);
2283}
2284
2285
2286/* name to opaque C++ scope representation -------------------------------- */
2287char* cppyy_resolve_name(const char* cppitem_name) {
2288 return cppstring_to_cstring(Cppyy::ResolveName(cppitem_name));
2289}
2290
2291char* cppyy_resolve_enum(const char* enum_type) {
2292 return cppstring_to_cstring(Cppyy::ResolveEnum(enum_type));
2293}
2294
2295cppyy_scope_t cppyy_get_scope(const char* scope_name) {
2296 return cppyy_scope_t(Cppyy::GetScope(scope_name));
2297}
2298
2300 return cppyy_type_t(Cppyy::GetActualClass(klass, (void*)obj));
2301}
2302
2304 return Cppyy::SizeOf(klass);
2305}
2306
2307size_t cppyy_size_of_type(const char* type_name) {
2308 return Cppyy::SizeOf(type_name);
2309}
2310
2311
2312/* memory management ------------------------------------------------------ */
2315}
2316
2318 Cppyy::Deallocate(type, (void*)self);
2319}
2320
2323}
2324
2326 Cppyy::Destruct(type, (void*)self);
2327}
2328
2329
2330/* method/function dispatching -------------------------------------------- */
2331/* Exception types:
2332 1: default (unknown exception)
2333 2: standard exception
2334*/
2335#define CPPYY_HANDLE_EXCEPTION \
2336 catch (std::exception& e) { \
2337 cppyy_exctype_t* etype = (cppyy_exctype_t*)((Parameter*)args+nargs); \
2338 *etype = (cppyy_exctype_t)2; \
2339 *((char**)(etype+1)) = cppstring_to_cstring(e.what()); \
2340 } \
2341 catch (...) { \
2342 cppyy_exctype_t* etype = (cppyy_exctype_t*)((Parameter*)args+nargs); \
2343 *etype = (cppyy_exctype_t)1; \
2344 *((char**)(etype+1)) = \
2345 cppstring_to_cstring("unhandled, unknown C++ exception"); \
2346 }
2347
2348void cppyy_call_v(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
2349 try {
2350 Cppyy::CallV(method, (void*)self, nargs, args);
2352}
2353
2354unsigned char cppyy_call_b(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
2355 try {
2356 return (unsigned char)Cppyy::CallB(method, (void*)self, nargs, args);
2358 return (unsigned char)-1;
2359}
2360
2361char cppyy_call_c(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
2362 try {
2363 return (char)Cppyy::CallC(method, (void*)self, nargs, args);
2365 return (char)-1;
2366}
2367
2368short cppyy_call_h(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
2369 try {
2370 return (short)Cppyy::CallH(method, (void*)self, nargs, args);
2372 return (short)-1;
2373}
2374
2375int cppyy_call_i(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
2376 try {
2377 return (int)Cppyy::CallI(method, (void*)self, nargs, args);
2379 return (int)-1;
2380}
2381
2382long cppyy_call_l(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
2383 try {
2384 return (long)Cppyy::CallL(method, (void*)self, nargs, args);
2386 return (long)-1;
2387}
2388
2389long long cppyy_call_ll(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
2390 try {
2391 return (long long)Cppyy::CallLL(method, (void*)self, nargs, args);
2393 return (long long)-1;
2394}
2395
2396float cppyy_call_f(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
2397 try {
2398 return (float)Cppyy::CallF(method, (void*)self, nargs, args);
2400 return (float)-1;
2401}
2402
2403double cppyy_call_d(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
2404 try {
2405 return (double)Cppyy::CallD(method, (void*)self, nargs, args);
2407 return (double)-1;
2408}
2409
2410long double cppyy_call_ld(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
2411 try {
2412 return (long double)Cppyy::CallLD(method, (void*)self, nargs, args);
2414 return (long double)-1;
2415}
2416
2417double cppyy_call_nld(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
2418 return (double)cppyy_call_ld(method, self, nargs, args);
2419}
2420
2421void* cppyy_call_r(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
2422 try {
2423 return (void*)Cppyy::CallR(method, (void*)self, nargs, args);
2425 return (void*)nullptr;
2426}
2427
2429 cppyy_method_t method, cppyy_object_t self, int nargs, void* args, size_t* lsz) {
2430 try {
2431 return Cppyy::CallS(method, (void*)self, nargs, args, lsz);
2433 return (char*)nullptr;
2434}
2435
2437 cppyy_method_t method, cppyy_type_t klass, int nargs, void* args) {
2438 try {
2439 return cppyy_object_t(Cppyy::CallConstructor(method, klass, nargs, args));
2441 return (cppyy_object_t)0;
2442}
2443
2445 Cppyy::CallDestructor(klass, self);
2446}
2447
2449 int nargs, void* args, cppyy_type_t result_type) {
2450 try {
2451 return cppyy_object_t(Cppyy::CallO(method, (void*)self, nargs, args, result_type));
2453 return (cppyy_object_t)0;
2454}
2455
2457 return cppyy_funcaddr_t(Cppyy::GetFunctionAddress(method, true));
2458}
2459
2460
2461/* handling of function argument buffer ----------------------------------- */
2463// for calls through C interface, require extra space for reporting exceptions
2464 return malloc(nargs*sizeof(Parameter)+sizeof(cppyy_exctype_t)+sizeof(char**));
2465}
2466
2468 free(args);
2469}
2470
2472 return (size_t)Cppyy::GetFunctionArgSizeof();
2473}
2474
2476 return (size_t)Cppyy::GetFunctionArgTypeoffset();
2477}
2478
2479
2480/* scope reflection information ------------------------------------------- */
2482 return (int)Cppyy::IsNamespace(scope);
2483}
2484
2485int cppyy_is_template(const char* template_name) {
2486 return (int)Cppyy::IsTemplate(template_name);
2487}
2488
2490 return (int)Cppyy::IsAbstract(type);
2491}
2492
2493int cppyy_is_enum(const char* type_name) {
2494 return (int)Cppyy::IsEnum(type_name);
2495}
2496
2498 return (int)Cppyy::IsAggregate(type);
2499}
2500
2501const char** cppyy_get_all_cpp_names(cppyy_scope_t scope, size_t* count) {
2502 std::set<std::string> cppnames;
2503 Cppyy::GetAllCppNames(scope, cppnames);
2504 const char** c_cppnames = (const char**)malloc(cppnames.size()*sizeof(const char*));
2505 int i = 0;
2506 for (const auto& name : cppnames) {
2507 c_cppnames[i] = cppstring_to_cstring(name);
2508 ++i;
2509 }
2510 *count = cppnames.size();
2511 return c_cppnames;
2512}
2513
2514
2515/* namespace reflection information --------------------------------------- */
2517 const std::vector<Cppyy::TCppScope_t>& uv = Cppyy::GetUsingNamespaces((Cppyy::TCppScope_t)scope);
2518
2519 if (uv.empty())
2520 return (cppyy_index_t*)nullptr;
2521
2522 cppyy_scope_t* llresult = (cppyy_scope_t*)malloc(sizeof(cppyy_scope_t)*(uv.size()+1));
2523 for (int i = 0; i < (int)uv.size(); ++i) llresult[i] = uv[i];
2524 llresult[uv.size()] = (cppyy_scope_t)0;
2525 return llresult;
2526}
2527
2528
2529/* class reflection information ------------------------------------------- */
2532}
2533
2536}
2537
2539 return (int)Cppyy::HasVirtualDestructor(type);
2540}
2541
2543 return (int)Cppyy::HasComplexHierarchy(type);
2544}
2545
2547 return (int)Cppyy::GetNumBases(type);
2548}
2549
2552}
2553
2554char* cppyy_base_name(cppyy_type_t type, int base_index) {
2555 return cppstring_to_cstring(Cppyy::GetBaseName (type, base_index));
2556}
2557
2559 return (int)Cppyy::IsSubtype(derived, base);
2560}
2561
2563 return (int)Cppyy::IsSmartPtr(type);
2564}
2565
2566int cppyy_smartptr_info(const char* name, cppyy_type_t* raw, cppyy_method_t* deref) {
2567 return (int)Cppyy::GetSmartPtrInfo(name, raw, deref);
2568}
2569
2570void cppyy_add_smartptr_type(const char* type_name) {
2571 Cppyy::AddSmartPtrType(type_name);
2572}
2573
2574
2575/* calculate offsets between declared and actual type, up-cast: direction > 0; down-cast: direction < 0 */
2576ptrdiff_t cppyy_base_offset(cppyy_type_t derived, cppyy_type_t base, cppyy_object_t address, int direction) {
2577 return (ptrdiff_t)Cppyy::GetBaseOffset(derived, base, (void*)address, direction, 0);
2578}
2579
2580
2581/* method/function reflection information --------------------------------- */
2583 return (int)Cppyy::GetNumMethods(scope);
2584}
2585
2587{
2588 std::vector<cppyy_index_t> result = Cppyy::GetMethodIndicesFromName(scope, name);
2589
2590 if (result.empty())
2591 return (cppyy_index_t*)nullptr;
2592
2593 cppyy_index_t* llresult = (cppyy_index_t*)malloc(sizeof(cppyy_index_t)*(result.size()+1));
2594 for (int i = 0; i < (int)result.size(); ++i) llresult[i] = result[i];
2595 llresult[result.size()] = -1;
2596 return llresult;
2597}
2598
2600 return cppyy_method_t(Cppyy::GetMethod(scope, idx));
2601}
2602
2605}
2606
2609}
2610
2613}
2614
2617}
2618
2620 return (int)Cppyy::GetMethodNumArgs((Cppyy::TCppMethod_t)method);
2621}
2622
2624 return (int)Cppyy::GetMethodReqArgs((Cppyy::TCppMethod_t)method);
2625}
2626
2627char* cppyy_method_arg_name(cppyy_method_t method, int arg_index) {
2629}
2630
2631char* cppyy_method_arg_type(cppyy_method_t method, int arg_index) {
2633}
2634
2635char* cppyy_method_arg_default(cppyy_method_t method, int arg_index) {
2637}
2638
2639char* cppyy_method_signature(cppyy_method_t method, int show_formalargs) {
2640 return cppstring_to_cstring(Cppyy::GetMethodSignature((Cppyy::TCppMethod_t)method, (bool)show_formalargs));
2641}
2642
2643char* cppyy_method_signature_max(cppyy_method_t method, int show_formalargs, int maxargs) {
2644 return cppstring_to_cstring(Cppyy::GetMethodSignature((Cppyy::TCppMethod_t)method, (bool)show_formalargs, (Cppyy::TCppIndex_t)maxargs));
2645}
2646
2647char* cppyy_method_prototype(cppyy_scope_t scope, cppyy_method_t method, int show_formalargs) {
2649 (Cppyy::TCppScope_t)scope, (Cppyy::TCppMethod_t)method, (bool)show_formalargs));
2650}
2651
2653 return (int)Cppyy::IsConstMethod(method);
2654}
2655
2657 return (int)Cppyy::GetNumTemplatedMethods(scope);
2658}
2659
2662}
2663
2666}
2667
2669 return (int)Cppyy::ExistsMethodTemplate(scope, name);
2670}
2671
2673 return (int)Cppyy::IsMethodTemplate(scope, idx);
2674}
2675
2678}
2679
2682}
2683
2684
2685/* method properties ------------------------------------------------------ */
2687 return (int)Cppyy::IsPublicMethod((Cppyy::TCppMethod_t)method);
2688}
2689
2691 return (int)Cppyy::IsProtectedMethod((Cppyy::TCppMethod_t)method);
2692}
2693
2695 return (int)Cppyy::IsConstructor((Cppyy::TCppMethod_t)method);
2696}
2697
2699 return (int)Cppyy::IsDestructor((Cppyy::TCppMethod_t)method);
2700}
2701
2703 return (int)Cppyy::IsStaticMethod((Cppyy::TCppMethod_t)method);
2704}
2705
2706
2707/* data member reflection information ------------------------------------- */
2709 return (int)Cppyy::GetNumDatamembers(scope);
2710}
2711
2712char* cppyy_datamember_name(cppyy_scope_t scope, int datamember_index) {
2713 return cppstring_to_cstring(Cppyy::GetDatamemberName(scope, datamember_index));
2714}
2715
2716char* cppyy_datamember_type(cppyy_scope_t scope, int datamember_index) {
2717 return cppstring_to_cstring(Cppyy::GetDatamemberType(scope, datamember_index));
2718}
2719
2720intptr_t cppyy_datamember_offset(cppyy_scope_t scope, int datamember_index) {
2721 return intptr_t(Cppyy::GetDatamemberOffset(scope, datamember_index));
2722}
2723
2725 return (int)Cppyy::GetDatamemberIndex(scope, name);
2726}
2727
2728
2729
2730/* data member properties ------------------------------------------------- */
2732 return (int)Cppyy::IsPublicData(type, datamember_index);
2733}
2734
2736 return (int)Cppyy::IsProtectedData(type, datamember_index);
2737}
2738
2740 return (int)Cppyy::IsStaticData(type, datamember_index);
2741}
2742
2744 return (int)Cppyy::IsConstData(scope, idata);
2745}
2746
2748 return (int)Cppyy::IsEnumData(scope, idata);
2749}
2750
2751int cppyy_get_dimension_size(cppyy_scope_t scope, cppyy_index_t idata, int dimension) {
2752 return Cppyy::GetDimensionSize(scope, idata, dimension);
2753}
2754
2755
2756/* misc helpers ----------------------------------------------------------- */
2758void* cppyy_load_dictionary(const char* lib_name) {
2759 int result = gSystem->Load(lib_name);
2760 return (void*)(result == 0 /* success */ || result == 1 /* already loaded */);
2761}
2762
2763#if defined(_MSC_VER)
2764long long cppyy_strtoll(const char* str) {
2765 return _strtoi64(str, NULL, 0);
2766}
2767
2768extern "C" {
2769unsigned long long cppyy_strtoull(const char* str) {
2770 return _strtoui64(str, NULL, 0);
2771}
2772}
2773#else
2774long long cppyy_strtoll(const char* str) {
2775 return strtoll(str, NULL, 0);
2776}
2777
2778extern "C" {
2779unsigned long long cppyy_strtoull(const char* str) {
2780 return strtoull(str, NULL, 0);
2781}
2782}
2783#endif
2784
2785void cppyy_free(void* ptr) {
2786 free(ptr);
2787}
2788
2789cppyy_object_t cppyy_charp2stdstring(const char* str, size_t sz) {
2790 return (cppyy_object_t)new std::string(str, sz);
2791}
2792
2793const char* cppyy_stdstring2charp(cppyy_object_t ptr, size_t* lsz) {
2794 *lsz = ((std::string*)ptr)->size();
2795 return ((std::string*)ptr)->data();
2796}
2797
2799 return (cppyy_object_t)new std::string(*(std::string*)ptr);
2800}
2801
2803 return (double)*(long double*)p;
2804}
2805
2806void cppyy_double2longdouble(double d, void* p) {
2807 *(long double*)p = d;
2808}
2809
2811 return (int)(*(std::vector<bool>*)ptr)[idx];
2812}
2813
2815 (*(std::vector<bool>*)ptr)[idx] = (bool)value;
2816}
2817
2818} // end C-linkage wrappers
#define d(i)
Definition RSha256.hxx:102
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define c(i)
Definition RSha256.hxx:101
static Roo_reg_AGKInteg1D instance
int Int_t
Definition RtypesCore.h:45
long double LongDouble_t
Definition RtypesCore.h:61
long long Long64_t
Definition RtypesCore.h:80
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
@ kMAXSIGNALS
Definition Rtypes.h:59
@ kOther_t
Definition TDataType.h:32
@ kIsDestructor
@ kIsTemplateSpec
@ kIsConstructor
@ kClassIsAggregate
@ kClassHasExplicitDtor
@ kClassHasImplicitDtor
@ kIsPublic
Definition TDictionary.h:75
@ kIsConstant
Definition TDictionary.h:88
@ kIsConstMethod
Definition TDictionary.h:96
@ kIsEnum
Definition TDictionary.h:68
@ kIsPrivate
Definition TDictionary.h:77
@ kIsFundamental
Definition TDictionary.h:70
@ kIsAbstract
Definition TDictionary.h:71
@ kIsStatic
Definition TDictionary.h:80
@ kIsProtected
Definition TDictionary.h:76
@ kIsVirtual
Definition TDictionary.h:72
@ kIsNamespace
Definition TDictionary.h:95
@ kIsVirtualBase
Definition TDictionary.h:89
constexpr Int_t kFatal
Definition TError.h:49
Int_t gErrorIgnoreLevel
Error handling routines.
Definition TError.cxx:31
R__EXTERN TExceptionHandler * gExceptionHandler
Definition TException.h:84
R__EXTERN ExceptionContext_t * gException
Definition TException.h:74
R__EXTERN void Throw(int code)
If an exception context has been set (using the TRY and RETRY macros) jump back to where it was set.
winID h TVirtualViewer3D TVirtualGLPainter p
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 offset
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 r
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 char Point_t Rectangle_t WindowAttributes_t index
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 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 req_type
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void funcs
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:110
#define gInterpreter
#define gROOT
Definition TROOT.h:406
R__EXTERN TSystem * gSystem
Definition TSystem.h:560
static struct Signalmap_t gSignalMap[kMAXSIGNALS]
size_t cppyy_scope_t
Definition capi.h:12
cppyy_scope_t cppyy_type_t
Definition capi.h:13
intptr_t cppyy_method_t
Definition capi.h:15
size_t cppyy_index_t
Definition capi.h:17
void * cppyy_object_t
Definition capi.h:14
unsigned long cppyy_exctype_t
Definition capi.h:20
void * cppyy_funcaddr_t
Definition capi.h:18
const char * proto
Definition civetweb.c:17536
#define free
Definition civetweb.c:1539
#define malloc
Definition civetweb.c:1536
Each class (see TClass) has a linked list of its base class(es).
Definition TBaseClass.h:33
Long_t Property() const override
Get property description word. For meaning of bits see EProperty.
TClassRef is used to implement a permanent reference to a TClass object.
Definition TClassRef.h:28
TClass * GetClass() const
Definition TClassRef.h:70
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
TList * GetListOfUsingDataMembers(Bool_t load=kTRUE)
Return list containing the TDataMembers of using declarations of a class.
Definition TClass.cxx:3786
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
Definition TClass.cxx:4978
TMethod * GetMethod(const char *method, const char *params, Bool_t objectIsConst=kFALSE)
Find the best method (if there is one) matching the parameters.
Definition TClass.cxx:4411
TMethod * GetMethodWithPrototype(const char *method, const char *proto, Bool_t objectIsConst=kFALSE, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
Find the method with a given prototype.
Definition TClass.cxx:4456
const TList * GetListOfAllPublicMethods(Bool_t load=kTRUE)
Returns a list of all public methods of this class and its base classes.
Definition TClass.cxx:3845
void Destructor(void *obj, Bool_t dtorOnly=kFALSE)
Explicitly call destructor for object.
Definition TClass.cxx:5400
TList * GetListOfFunctionTemplates(Bool_t load=kTRUE)
Return TListOfFunctionTemplates for a class.
Definition TClass.cxx:3798
TList * GetListOfEnums(Bool_t load=kTRUE)
Return a list containing the TEnums of a class.
Definition TClass.cxx:3686
TList * GetListOfMethods(Bool_t load=kTRUE)
Return list containing the TMethods of a class.
Definition TClass.cxx:3812
TClass * GetBaseClass(const char *classname)
Return pointer to the base class "classname".
Definition TClass.cxx:2655
TList * GetListOfDataMembers(Bool_t load=kTRUE)
Return list containing the TDataMembers of a class.
Definition TClass.cxx:3770
TList * GetListOfBases()
Return list containing the TBaseClass(es) of a class.
Definition TClass.cxx:3636
Bool_t IsLoaded() const
Return true if the shared library of this class is currently in the a process's memory.
Definition TClass.cxx:5912
ClassInfo_t * GetClassInfo() const
Definition TClass.h:431
Long_t ClassProperty() const
Return the C++ property of this class, eg.
Definition TClass.cxx:2396
Long_t Property() const override
Returns the properties of the TClass as a bit field stored as a Long_t value.
Definition TClass.cxx:6086
ROOT::DelFunc_t GetDelete() const
Return the wrapper around delete ThiObject.
Definition TClass.cxx:7463
TClass * GetActualClass(const void *object) const
Return a pointer to the real class of the object.
Definition TClass.cxx:2607
TFunctionTemplate * GetFunctionTemplate(const char *name)
Definition TClass.cxx:3607
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.
Definition TClass.cxx:2968
Collection abstract base class.
Definition TCollection.h:65
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
All ROOT classes may have RTTI (run time type identification) support added.
Definition TDataMember.h:31
Basic data type descriptor (datatype information is obtained from CINT).
Definition TDataType.h:44
Int_t GetType() const
Definition TDataType.h:68
const char * GetFullTypeName() const
Get full type description of typedef, e,g.: "class TDirectory*".
Long_t Property() const override
Get property description word. For meaning of bits see EProperty.
Int_t Size() const
Get size of basic typedef'ed type.
const void * DeclId_t
The TEnumConstant class implements the constants of the enum type.
Long64_t GetValue() const
The TEnum class implements the enum type.
Definition TEnum.h:33
const TEnumConstant * GetConstant(const char *name) const
Definition TEnum.h:64
Definition TEnv.h:86
const char * GetValue() const
Definition TEnv.h:110
const char * GetName() const override
Returns name of object.
Definition TEnv.h:109
virtual void HandleException(int sig)=0
Dictionary for function template This class describes one single function template.
Global functions class (global functions are obtained from CINT).
Definition TFunction.h:30
virtual const char * GetMangledName() const
Returns the mangled name as defined by CINT, or 0 in case of error.
Long_t Property() const override
Get property description word. For meaning of bits see EProperty.
Int_t GetNargs() const
Number of function arguments.
Long_t ExtraProperty() const
Get property description word. For meaning of bits see EProperty.
std::string GetReturnTypeNormalizedName() const
Get the normalized name of the return type.
Global variables class (global variables are obtained from CINT).
Definition TGlobal.h:28
virtual Int_t GetArrayDim() const
Return number of array dimensions.
Definition TGlobal.cxx:89
virtual Int_t GetMaxIndex(Int_t dim) const
Return maximum index for array dimension "dim".
Definition TGlobal.cxx:105
Long_t Property() const override
Get property description word. For meaning of bits see EProperty.
Definition TGlobal.cxx:152
virtual void * GetAddress() const
Return address of global.
Definition TGlobal.cxx:81
virtual const char * GetFullTypeName() const
Get full type description of global variable, e,g.: "class TDirectory*".
Definition TGlobal.cxx:124
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition THashList.h:34
TObject * Next()
A collection of TDataMember objects designed for fast access given a DeclId_t and for keep track of T...
A collection of TEnum objects designed for fast access given a DeclId_t and for keep track of TEnum t...
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
Definition TList.cxx:578
TObject * At(Int_t idx) const override
Returns the object at position idx. Returns 0 if idx is out of range.
Definition TList.cxx:357
Each ROOT method (see TMethod) has a linked list of its arguments.
Definition TMethodArg.h:36
const char * GetFullTypeName() const
Get full type description of method argument, e.g.: "class TDirectory*".
TypeInfo_t * GetTypeInfo() const
Get the TypeInfo of the method argument.
const char * GetDefault() const
Get default value of method argument.
std::string GetTypeNormalizedName() const
Get the normalized name of the return type.
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:439
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
Definition TObject.cxx:403
static Bool_t Initialized()
Return kTRUE if the TROOT object has been initialized.
Definition TROOT.cxx:2848
virtual Int_t IndexOf(const TObject *obj) const
Return index of object in collection.
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition TSystem.cxx:1845
virtual void Exit(int code, Bool_t mode=kTRUE)
Exit the application.
Definition TSystem.cxx:704
virtual void StackTrace()
Print a stack trace.
Definition TSystem.cxx:722
char * cppyy_method_mangled_name(cppyy_method_t method)
int cppyy_is_staticdata(cppyy_type_t type, cppyy_index_t datamember_index)
int cppyy_vectorbool_getitem(cppyy_object_t ptr, int idx)
int cppyy_has_virtual_destructor(cppyy_type_t type)
int cppyy_is_publicmethod(cppyy_method_t method)
void * cppyy_call_r(cppyy_method_t method, cppyy_object_t self, int nargs, void *args)
cppyy_object_t cppyy_constructor(cppyy_method_t method, cppyy_type_t klass, int nargs, void *args)
void * cppyy_load_dictionary(const char *lib_name)
static void cond_add(Cppyy::TCppScope_t scope, const std::string &ns_scope, std::set< std::string > &cppnames, const char *name, bool nofilter=false)
size_t cppyy_function_arg_typeoffset()
int cppyy_exists_method_template(cppyy_scope_t scope, const char *name)
int cppyy_get_num_templated_methods(cppyy_scope_t scope)
char * cppyy_call_s(cppyy_method_t method, cppyy_object_t self, int nargs, void *args, size_t *lsz)
char * cppyy_resolve_enum(const char *enum_type)
cppyy_object_t cppyy_charp2stdstring(const char *str, size_t sz)
static Name2ClassRefIndex_t g_name2classrefidx
int cppyy_is_constructor(cppyy_method_t method)
int cppyy_is_enum_data(cppyy_scope_t scope, cppyy_index_t idata)
#define FILL_COLL(type, filter)
char * cppyy_scoped_final_name(cppyy_type_t type)
int cppyy_num_bases(cppyy_type_t type)
const int SMALL_ARGS_N
static std::string outer_with_template(const std::string &name)
cppyy_method_t cppyy_get_method_template(cppyy_scope_t scope, const char *name, const char *proto)
static std::string outer_no_template(const std::string &name)
int cppyy_is_smartptr(cppyy_type_t type)
static std::string type_remap(const std::string &n1, const std::string &n2)
static std::map< Cppyy::TCppType_t, bool > sHasOperatorDelete
long long cppyy_strtoll(const char *str)
static std::set< std::string > gRootSOs
int cppyy_is_subtype(cppyy_type_t derived, cppyy_type_t base)
static TClassRef & type_from_handle(Cppyy::TCppScope_t scope)
double cppyy_call_nld(cppyy_method_t method, cppyy_object_t self, int nargs, void *args)
void cppyy_free(void *ptr)
int cppyy_smartptr_info(const char *name, cppyy_type_t *raw, cppyy_method_t *deref)
unsigned long long cppyy_strtoull(const char *str)
char * cppyy_method_arg_type(cppyy_method_t method, int arg_index)
cppyy_object_t cppyy_stdstring2stdstring(cppyy_object_t ptr)
char * cppyy_base_name(cppyy_type_t type, int base_index)
cppyy_scope_t * cppyy_get_using_namespaces(cppyy_scope_t scope)
static bool copy_args(Parameter *args, size_t nargs, void **vargs)
int cppyy_num_bases_longest_branch(cppyy_type_t type)
static TInterpreter::CallFuncIFacePtr_t GetCallFunc(Cppyy::TCppMethod_t method)
int cppyy_is_publicdata(cppyy_type_t type, cppyy_index_t datamember_index)
CPyCppyy::Parameter Parameter
intptr_t cppyy_datamember_offset(cppyy_scope_t scope, int datamember_index)
char * cppyy_datamember_type(cppyy_scope_t scope, int datamember_index)
static bool is_missclassified_stl(const std::string &name)
std::map< std::string, ClassRefs_t::size_type > Name2ClassRefIndex_t
void cppyy_destructor(cppyy_type_t klass, cppyy_object_t self)
static const ClassRefs_t::size_type STD_HANDLE
char cppyy_call_c(cppyy_method_t method, cppyy_object_t self, int nargs, void *args)
ptrdiff_t cppyy_base_offset(cppyy_type_t derived, cppyy_type_t base, cppyy_object_t address, int direction)
long double cppyy_call_ld(cppyy_method_t method, cppyy_object_t self, int nargs, void *args)
int cppyy_is_const_data(cppyy_scope_t scope, cppyy_index_t idata)
const char ** cppyy_get_all_cpp_names(cppyy_scope_t scope, size_t *count)
void cppyy_call_v(cppyy_method_t method, cppyy_object_t self, int nargs, void *args)
static std::set< std::string > gSmartPtrTypes
double cppyy_longdouble2double(void *p)
int cppyy_method_req_args(cppyy_method_t method)
int cppyy_is_staticmethod(cppyy_method_t method)
static GlobalVars_t g_globalvars
cppyy_index_t * cppyy_method_indices_from_name(cppyy_scope_t scope, const char *name)
static char * cppstring_to_cstring(const std::string &cppstr)
char * cppyy_method_signature(cppyy_method_t method, int show_formalargs)
int cppyy_is_abstract(cppyy_type_t type)
static void release_args(Parameter *args, size_t nargs)
int cppyy_call_i(cppyy_method_t method, cppyy_object_t self, int nargs, void *args)
static std::set< std::string > g_builtins
unsigned char cppyy_call_b(cppyy_method_t method, cppyy_object_t self, int nargs, void *args)
int cppyy_is_template(const char *template_name)
char * cppyy_method_result_type(cppyy_method_t method)
cppyy_type_t cppyy_actual_class(cppyy_type_t klass, cppyy_object_t obj)
int cppyy_is_templated_constructor(cppyy_scope_t scope, cppyy_index_t imeth)
char * cppyy_method_name(cppyy_method_t method)
int cppyy_is_protectedmethod(cppyy_method_t method)
char * cppyy_final_name(cppyy_type_t type)
char * cppyy_get_templated_method_name(cppyy_scope_t scope, cppyy_index_t imeth)
char * cppyy_method_full_name(cppyy_method_t method)
long cppyy_call_l(cppyy_method_t method, cppyy_object_t self, int nargs, void *args)
void cppyy_double2longdouble(double d, void *p)
void cppyy_deallocate_function_args(void *args)
int cppyy_method_is_template(cppyy_scope_t scope, cppyy_index_t idx)
static std::vector< CallWrapper * > gWrapperHolder
static bool gEnableFastPath
void cppyy_destruct(cppyy_type_t type, cppyy_object_t self)
int cppyy_is_enum(const char *type_name)
size_t cppyy_size_of_type(const char *type_name)
int cppyy_is_destructor(cppyy_method_t method)
cppyy_object_t cppyy_allocate(cppyy_type_t type)
char * cppyy_datamember_name(cppyy_scope_t scope, int datamember_index)
cppyy_object_t cppyy_construct(cppyy_type_t type)
static ClassRefs_t g_classrefs(1)
static bool WrapperCall(Cppyy::TCppMethod_t method, size_t nargs, void *args_, void *self, void *result)
static std::map< std::string, std::string > resolved_enum_types
int cppyy_is_namespace(cppyy_scope_t scope)
cppyy_object_t cppyy_call_o(cppyy_method_t method, cppyy_object_t self, int nargs, void *args, cppyy_type_t result_type)
long long cppyy_call_ll(cppyy_method_t method, cppyy_object_t self, int nargs, void *args)
cppyy_scope_t cppyy_get_scope(const char *scope_name)
void cppyy_vectorbool_setitem(cppyy_object_t ptr, int idx, int value)
static CallWrapper * new_CallWrapper(TFunction *f)
void cppyy_add_smartptr_type(const char *type_name)
void * cppyy_allocate_function_args(int nargs)
float cppyy_call_f(cppyy_method_t method, cppyy_object_t self, int nargs, void *args)
short cppyy_call_h(cppyy_method_t method, cppyy_object_t self, int nargs, void *args)
int cppyy_is_protecteddata(cppyy_type_t type, cppyy_index_t datamember_index)
static std::set< std::string > gSTLNames
static const ClassRefs_t::size_type GLOBAL_HANDLE
int cppyy_get_dimension_size(cppyy_scope_t scope, cppyy_index_t idata, int dimension)
char * cppyy_method_signature_max(cppyy_method_t method, int show_formalargs, int maxargs)
double cppyy_call_d(cppyy_method_t method, cppyy_object_t self, int nargs, void *args)
int cppyy_num_methods(cppyy_scope_t scope)
char * cppyy_method_prototype(cppyy_scope_t scope, cppyy_method_t method, int show_formalargs)
std::vector< TGlobal * > GlobalVars_t
char * cppyy_resolve_name(const char *cppitem_name)
cppyy_method_t cppyy_get_method(cppyy_scope_t scope, cppyy_index_t idx)
std::vector< TClassRef > ClassRefs_t
size_t cppyy_function_arg_sizeof()
int cppyy_is_const_method(cppyy_method_t method)
static std::map< TDictionary::DeclId_t, CallWrapper * > gMethodTemplates
int cppyy_num_datamembers(cppyy_scope_t scope)
#define CPPYY_HANDLE_EXCEPTION
size_t cppyy_size_of_klass(cppyy_type_t klass)
static bool match_name(const std::string &tname, const std::string fname)
int cppyy_datamember_index(cppyy_scope_t scope, const char *name)
cppyy_index_t cppyy_get_global_operator(cppyy_scope_t scope, cppyy_scope_t lc, cppyy_scope_t rc, const char *op)
static TFunction * m2f(Cppyy::TCppMethod_t method)
void cppyy_deallocate(cppyy_type_t type, cppyy_object_t self)
const char * cppyy_stdstring2charp(cppyy_object_t ptr, size_t *lsz)
int cppyy_compile(const char *code)
static CallWrapper::DeclId_t m2d(Cppyy::TCppMethod_t method)
int cppyy_is_aggregate(cppyy_type_t type)
static TDataMember * GetDataMemberByIndex(TClassRef cr, int idata)
#define CPPYY_IMP_CALL(typecode, rtype)
int cppyy_method_num_args(cppyy_method_t method)
static std::set< std::string > gInitialNames
char * cppyy_method_arg_default(cppyy_method_t method, int arg_index)
static T CallT(Cppyy::TCppMethod_t method, Cppyy::TCppObject_t self, size_t nargs, void *args)
cppyy_funcaddr_t cppyy_function_address(cppyy_method_t method)
int cppyy_has_complex_hierarchy(cppyy_type_t type)
Cppyy::TCppIndex_t GetLongestInheritancePath(TClass *klass)
Retrieve number of base classes in the longest branch of the inheritance tree of the input class.
char * cppyy_method_arg_name(cppyy_method_t method, int arg_index)
const Int_t n
Definition legend1.C:16
#define F(x, y, z)
#define I(x, y, z)
#define H(x, y, z)
size_t TCppIndex_t
Definition cpp_cppyy.h:24
RPY_EXPORTED TCppIndex_t GetNumMethods(TCppScope_t scope)
RPY_EXPORTED std::string GetMethodMangledName(TCppMethod_t)
RPY_EXPORTED TCppObject_t CallO(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args, TCppType_t result_type)
RPY_EXPORTED int CallI(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
RPY_EXPORTED TCppIndex_t CompareMethodArgType(TCppMethod_t, TCppIndex_t iarg, const std::string &req_type)
RPY_EXPORTED ptrdiff_t GetBaseOffset(TCppType_t derived, TCppType_t base, TCppObject_t address, int direction, bool rerror=false)
RPY_EXPORTED void DeallocateFunctionArgs(void *args)
RPY_EXPORTED bool IsEnumData(TCppScope_t scope, TCppIndex_t idata)
RPY_EXPORTED unsigned char CallB(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
RPY_EXPORTED bool IsAbstract(TCppType_t type)
RPY_EXPORTED size_t SizeOf(TCppType_t klass)
RPY_EXPORTED TCppObject_t CallConstructor(TCppMethod_t method, TCppType_t type, size_t nargs, void *args)
intptr_t TCppMethod_t
Definition cpp_cppyy.h:22
RPY_EXPORTED void * AllocateFunctionArgs(size_t nargs)
RPY_EXPORTED bool IsTemplate(const std::string &template_name)
RPY_EXPORTED TCppIndex_t GetMethodReqArgs(TCppMethod_t)
RPY_EXPORTED bool IsEnum(const std::string &type_name)
RPY_EXPORTED TCppObject_t Construct(TCppType_t type)
RPY_EXPORTED std::vector< TCppIndex_t > GetMethodIndicesFromName(TCppScope_t scope, const std::string &name)
RPY_EXPORTED bool ExistsMethodTemplate(TCppScope_t scope, const std::string &name)
RPY_EXPORTED std::string GetMethodName(TCppMethod_t)
RPY_EXPORTED bool IsConstData(TCppScope_t scope, TCppIndex_t idata)
RPY_EXPORTED void AddSmartPtrType(const std::string &)
RPY_EXPORTED void CallDestructor(TCppType_t type, TCppObject_t self)
RPY_EXPORTED TCppScope_t gGlobalScope
Definition cpp_cppyy.h:51
RPY_EXPORTED bool IsProtectedData(TCppScope_t scope, TCppIndex_t idata)
RPY_EXPORTED std::string GetMethodSignature(TCppMethod_t, bool show_formalargs, TCppIndex_t maxargs=(TCppIndex_t) -1)
RPY_EXPORTED int GetDimensionSize(TCppScope_t scope, TCppIndex_t idata, int dimension)
RPY_EXPORTED bool IsSubtype(TCppType_t derived, TCppType_t base)
RPY_EXPORTED TCppMethod_t GetMethodTemplate(TCppScope_t scope, const std::string &name, const std::string &proto)
void * TCppObject_t
Definition cpp_cppyy.h:21
RPY_EXPORTED bool IsConstructor(TCppMethod_t method)
RPY_EXPORTED bool GetSmartPtrInfo(const std::string &, TCppType_t *raw, TCppMethod_t *deref)
RPY_EXPORTED char CallC(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
RPY_EXPORTED std::string GetMethodArgName(TCppMethod_t, TCppIndex_t iarg)
RPY_EXPORTED double CallD(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
RPY_EXPORTED size_t GetFunctionArgTypeoffset()
RPY_EXPORTED TCppObject_t Allocate(TCppType_t type)
RPY_EXPORTED void Destruct(TCppType_t type, TCppObject_t instance)
RPY_EXPORTED std::string ResolveName(const std::string &cppitem_name)
TCppScope_t TCppType_t
Definition cpp_cppyy.h:19
RPY_EXPORTED std::string ResolveEnum(const std::string &enum_type)
RPY_EXPORTED long long GetEnumDataValue(TCppEnum_t, TCppIndex_t idata)
RPY_EXPORTED bool IsAggregate(TCppType_t type)
RPY_EXPORTED TCppIndex_t GetMethodNumArgs(TCppMethod_t)
RPY_EXPORTED TCppType_t GetActualClass(TCppType_t klass, TCppObject_t obj)
RPY_EXPORTED std::string GetBaseName(TCppType_t type, TCppIndex_t ibase)
RPY_EXPORTED bool IsNamespace(TCppScope_t scope)
void * TCppEnum_t
Definition cpp_cppyy.h:20
RPY_EXPORTED float CallF(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
RPY_EXPORTED std::string GetScopedFinalName(TCppType_t type)
RPY_EXPORTED void Deallocate(TCppType_t type, TCppObject_t instance)
RPY_EXPORTED bool IsPublicData(TCppScope_t scope, TCppIndex_t idata)
RPY_EXPORTED std::string GetMethodArgType(TCppMethod_t, TCppIndex_t iarg)
RPY_EXPORTED long CallL(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
RPY_EXPORTED void * CallR(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
RPY_EXPORTED std::string GetEnumDataName(TCppEnum_t, TCppIndex_t idata)
RPY_EXPORTED void GetAllCppNames(TCppScope_t scope, std::set< std::string > &cppnames)
RPY_EXPORTED bool IsComplete(const std::string &type_name)
RPY_EXPORTED bool IsBuiltin(const std::string &type_name)
RPY_EXPORTED bool IsStaticMethod(TCppMethod_t method)
RPY_EXPORTED TCppIndex_t GetDatamemberIndex(TCppScope_t scope, const std::string &name)
RPY_EXPORTED void CallV(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
RPY_EXPORTED bool IsStaticData(TCppScope_t scope, TCppIndex_t idata)
RPY_EXPORTED std::string GetDatamemberType(TCppScope_t scope, TCppIndex_t idata)
RPY_EXPORTED TCppMethod_t GetMethod(TCppScope_t scope, TCppIndex_t imeth)
RPY_EXPORTED bool IsDestructor(TCppMethod_t method)
RPY_EXPORTED bool IsSmartPtr(TCppType_t type)
RPY_EXPORTED LongDouble_t CallLD(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
RPY_EXPORTED std::string GetTemplatedMethodName(TCppScope_t scope, TCppIndex_t imeth)
RPY_EXPORTED size_t GetFunctionArgSizeof()
RPY_EXPORTED TCppScope_t GetScope(const std::string &scope_name)
RPY_EXPORTED bool HasVirtualDestructor(TCppType_t type)
RPY_EXPORTED bool IsConstMethod(TCppMethod_t)
RPY_EXPORTED bool HasComplexHierarchy(TCppType_t type)
RPY_EXPORTED std::vector< TCppScope_t > GetUsingNamespaces(TCppScope_t)
size_t TCppScope_t
Definition cpp_cppyy.h:18
RPY_EXPORTED bool IsTemplatedConstructor(TCppScope_t scope, TCppIndex_t imeth)
RPY_EXPORTED TCppIndex_t GetNumDatamembers(TCppScope_t scope)
RPY_EXPORTED TCppIndex_t GetGlobalOperator(TCppType_t scope, const std::string &lc, const std::string &rc, const std::string &op)
RPY_EXPORTED TCppFuncAddr_t GetFunctionAddress(TCppMethod_t method, bool check_enabled=true)
RPY_EXPORTED TCppIndex_t GetNumEnumData(TCppEnum_t)
RPY_EXPORTED TCppIndex_t GetNumBases(TCppType_t type)
RPY_EXPORTED TCppIndex_t GetNumBasesLongestBranch(TCppType_t type)
Retrieve number of base classes in the longest branch of the inheritance tree.
RPY_EXPORTED TCppIndex_t GetNumTemplatedMethods(TCppScope_t scope)
RPY_EXPORTED std::string GetMethodPrototype(TCppScope_t scope, TCppMethod_t, bool show_formalargs)
RPY_EXPORTED std::string GetMethodResultType(TCppMethod_t)
RPY_EXPORTED std::string GetFinalName(TCppType_t type)
RPY_EXPORTED char * CallS(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args, size_t *length)
RPY_EXPORTED std::string GetMethodArgDefault(TCppMethod_t, TCppIndex_t iarg)
RPY_EXPORTED bool IsMethodTemplate(TCppScope_t scope, TCppIndex_t imeth)
RPY_EXPORTED std::string GetDatamemberName(TCppScope_t scope, TCppIndex_t idata)
RPY_EXPORTED bool IsPublicMethod(TCppMethod_t method)
RPY_EXPORTED intptr_t GetDatamemberOffset(TCppScope_t scope, TCppIndex_t idata)
void * TCppFuncAddr_t
Definition cpp_cppyy.h:25
RPY_EXPORTED std::string GetMethodFullName(TCppMethod_t)
RPY_EXPORTED short CallH(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
RPY_EXPORTED bool IsProtectedMethod(TCppMethod_t method)
RPY_EXPORTED bool Compile(const std::string &code)
RPY_EXPORTED Long64_t CallLL(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
RPY_EXPORTED TCppEnum_t GetEnum(TCppScope_t scope, const std::string &enum_name)
void(* DelFunc_t)(void *)
Definition Rtypes.h:111
std::string ResolveTypedef(const char *tname, bool resolveAll=false)
std::string CleanType(const char *typeDesc, int mode=0, const char **tail=nullptr)
Cleanup type description, redundant blanks removed and redundant tail ignored return *tail = pointer ...
std::string ShortType(const char *typeDesc, int mode)
Return the absolute type of typeDesc.
char * DemangleName(const char *mangled_name, int &errorCode)
Definition TClassEdit.h:208
#define RPY_EXTERN
union CPyCppyy::Parameter::Value fValue
const char * fSigName
TMarker m
Definition textangle.C:8
static uint64_t sum(uint64_t i)
Definition Factory.cxx:2345