Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
clingwrapper.cxx
Go to the documentation of this file.
1#ifndef WIN32
2#ifndef _CRT_SECURE_NO_WARNINGS
3// silence warnings about getenv, strncpy, etc.
4#define _CRT_SECURE_NO_WARNINGS
5#endif
6#endif
7
8// Bindings
9#include "precommondefs.h"
10#include "cpp_cppyy.h"
11#include "callcontext.h"
12
13// ROOT
14#include "TBaseClass.h"
15#include "TClass.h"
16#include "TClassRef.h"
17#include "TClassTable.h"
18#include "TClassEdit.h"
19#include "TCollection.h"
20#include "TDataMember.h"
21#include "TDataType.h"
22#include "TEnum.h"
23#include "TEnumConstant.h"
24#include "TEnv.h"
25#include "TError.h"
26#include "TException.h"
27#include "TFunction.h"
28#include "TFunctionTemplate.h"
29#include "TGlobal.h"
30#include "THashList.h"
31#include "TInterpreter.h"
32#include "TList.h"
33#include "TListOfDataMembers.h"
34#include "TListOfEnums.h"
35#include "TMethod.h"
36#include "TMethodArg.h"
37#include "TROOT.h"
38#include "TSystem.h"
39#include "TThread.h"
40
41// Standard
42#include <cassert>
43#include <algorithm> // for std::count, std::remove
44#include <climits>
45#include <stdexcept>
46#include <map>
47#include <new>
48#include <set>
49#include <sstream>
50#include <csignal>
51#include <cstdlib> // for getenv
52#include <cstring>
53#include <typeinfo>
54
55#if defined(__arm64__)
56#include <exception>
57#include <setjmp.h>
58#define CLING_CATCH_UNCAUGHT_ \
59ARMUncaughtException guard; \
60if (setjmp(gExcJumBuf) == 0) {
61#define _CLING_CATCH_UNCAUGHT \
62} else { \
63 if (!std::getenv("CPPYY_UNCAUGHT_QUIET")) \
64 std::cerr << "Warning: uncaught exception in JIT is rethrown; resources may leak" \
65 << " (suppress with \"CPPYY_UNCAUGHT_QUIET=1\")" << std::endl;\
66 std::rethrow_exception(std::current_exception()); \
67}
68#else
69#define CLING_CATCH_UNCAUGHT_
70#define _CLING_CATCH_UNCAUGHT
71#endif
72
73#if 0
74// force std::string and allocator instantation, otherwise Clang 13+ fails to JIT
75// symbols that rely on some private helpers (e.g. _M_use_local_data) when used in
76// in conjunction with the PCH; hat tip:
77// https://github.com/sxs-collaboration/spectre/pull/5222/files#diff-093aadf224e5fee0d33ae1810f2f1c23304fb5ca398ba6b96c4e7918e0811729
78#if defined(__GLIBCXX__) && __GLIBCXX__ >= 20220506
79template class std::allocator<char>;
80template class std::basic_string<char>;
81template class std::basic_string<wchar_t>;
82#endif
83
84using namespace CppyyLegacy;
85#endif
86
87// temp
88#include <iostream>
90// --temp
91
92#if 0
93#if defined(__arm64__)
94namespace {
95
96// Trap uncaught exceptions and longjump back to the point of JIT wrapper entry
97jmp_buf gExcJumBuf;
98
99void arm_uncaught_exception() {
100 longjmp(gExcJumBuf, 1);
101}
102
103class ARMUncaughtException {
104 std::terminate_handler m_Handler;
105public:
106 ARMUncaughtException() { m_Handler = std::set_terminate(arm_uncaught_exception); }
107 ~ARMUncaughtException() { std::set_terminate(m_Handler); }
108};
109
110} // unnamed namespace
111#endif // __arm64__
112#endif
113
114// small number that allows use of stack for argument passing
115const int SMALL_ARGS_N = 8;
116
117// convention to pass flag for direct calls (similar to Python's vector calls)
118#define DIRECT_CALL ((size_t)1 << (8 * sizeof(size_t) - 1))
119static inline size_t CALL_NARGS(size_t nargs) {
120 return nargs & ~DIRECT_CALL;
121}
122
123// data for life time management ---------------------------------------------
124typedef std::vector<TClassRef> ClassRefs_t;
126static const ClassRefs_t::size_type GLOBAL_HANDLE = 1;
127static const ClassRefs_t::size_type STD_HANDLE = GLOBAL_HANDLE + 1;
128
129typedef std::map<std::string, ClassRefs_t::size_type> Name2ClassRefIndex_t;
131
132static std::map<std::string, std::string> resolved_enum_types;
133
134namespace {
135
136static inline
137Cppyy::TCppType_t find_memoized_scope(const std::string& name)
138{
139 auto icr = g_name2classrefidx.find(name);
140 if (icr != g_name2classrefidx.end())
141 return (Cppyy::TCppType_t)icr->second;
142 return (Cppyy::TCppType_t)0;
143}
144
145static inline
146std::string find_memoized_resolved_name(const std::string& name)
147{
148// resolved class types
149 Cppyy::TCppType_t klass = find_memoized_scope(name);
150 if (klass) return Cppyy::GetScopedFinalName(klass);
151
152// resolved enum types
153 auto res = resolved_enum_types.find(name);
154 if (res != resolved_enum_types.end())
155 return res->second;
156
157// unknown ...
158 return "";
159}
160
161class CallWrapper {
162public:
163 typedef const void* DeclId_t;
164
165public:
166 CallWrapper(TFunction* f) : fDecl(f->GetDeclId()), fName(f->GetName()), fTF(new TFunction(*f)) {}
167 CallWrapper(DeclId_t fid, const std::string& n) : fDecl(fid), fName(n), fTF(nullptr) {}
168 ~CallWrapper() {
169 delete fTF;
170 }
171
172public:
174 DeclId_t fDecl;
175 std::string fName;
176 TFunction* fTF;
177};
178
179}
180
181static std::vector<CallWrapper*> gWrapperHolder;
182
183static inline
185{
186 CallWrapper* wrap = new CallWrapper(f);
187 gWrapperHolder.push_back(wrap);
188 return wrap;
189}
190
191static inline
192CallWrapper* new_CallWrapper(CallWrapper::DeclId_t fid, const std::string& n)
193{
194 CallWrapper* wrap = new CallWrapper(fid, n);
195 gWrapperHolder.push_back(wrap);
196 return wrap;
197}
198
199typedef std::vector<TGlobal*> GlobalVars_t;
200typedef std::map<TGlobal*, GlobalVars_t::size_type> GlobalVarsIndices_t;
201
204
205static std::set<std::string> gSTLNames;
206
207
208// data ----------------------------------------------------------------------
210
211// builtin types (including a few common STL templates as long as they live in
212// the global namespace b/c of choices upstream)
213static std::set<std::string> g_builtins =
214 {"bool", "char", "signed char", "unsigned char", "wchar_t", "short", "unsigned short",
215 "int", "unsigned int", "long", "unsigned long", "long long", "unsigned long long",
216 "float", "double", "long double", "void",
217 "allocator", "array", "basic_string", "complex", "initializer_list", "less", "list",
218 "map", "pair", "set", "vector"};
219
220// smart pointer types
221static std::set<std::string> gSmartPtrTypes =
222 {"auto_ptr", "std::auto_ptr", "shared_ptr", "std::shared_ptr",
223 "unique_ptr", "std::unique_ptr", "weak_ptr", "std::weak_ptr"};
224
225// to filter out ROOT names
226static std::set<std::string> gInitialNames;
227static std::set<std::string> gRootSOs;
228
229// configuration
230static bool gEnableFastPath = true;
231
232
233// global initialization -----------------------------------------------------
234namespace {
235
236// names copied from TUnixSystem
237#ifdef WIN32
238const int SIGBUS = 0; // simple placeholders for ones that don't exist
239const int SIGSYS = 0;
240const int SIGPIPE = 0;
241const int SIGQUIT = 0;
242const int SIGWINCH = 0;
243const int SIGALRM = 0;
244const int SIGCHLD = 0;
245const int SIGURG = 0;
246const int SIGUSR1 = 0;
247const int SIGUSR2 = 0;
248#endif
249
250static struct Signalmap_t {
251 int fCode;
252 const char *fSigName;
253} gSignalMap[kMAXSIGNALS] = { // the order of the signals should be identical
254 { SIGBUS, "bus error" }, // to the one in TSysEvtHandler.h
255 { SIGSEGV, "segmentation violation" },
256 { SIGSYS, "bad argument to system call" },
257 { SIGPIPE, "write on a pipe with no one to read it" },
258 { SIGILL, "illegal instruction" },
259 { SIGABRT, "abort" },
260 { SIGQUIT, "quit" },
261 { SIGINT, "interrupt" },
262 { SIGWINCH, "window size change" },
263 { SIGALRM, "alarm clock" },
264 { SIGCHLD, "death of a child" },
265 { SIGURG, "urgent data arrived on an I/O channel" },
266 { SIGFPE, "floating point exception" },
267 { SIGTERM, "termination signal" },
268 { SIGUSR1, "user-defined signal 1" },
269 { SIGUSR2, "user-defined signal 2" }
270};
271
272static void inline do_trace(int sig) {
273 std::cerr << " *** Break *** " << (sig < kMAXSIGNALS ? gSignalMap[sig].fSigName : "") << std::endl;
275}
276
277class TExceptionHandlerImp : public TExceptionHandler {
278public:
279 void HandleException(Int_t sig) override {
280 if (TROOT::Initialized()) {
281 if (gException) {
282 gInterpreter->RewindDictionary();
283 gInterpreter->ClearFileBusy();
284 }
285
286 if (!std::getenv("CPPYY_CRASH_QUIET"))
287 do_trace(sig);
288
289 // jump back, if catch point set
290 Throw(sig);
291 }
292
293 do_trace(sig);
294 gSystem->Exit(128 + sig);
295 }
296};
297
298class ApplicationStarter {
299public:
300 ApplicationStarter() {
301 // initialize ROOT early to guarantee proper order of shutdown later on (gROOT is a
302 // macro that resolves to the ::CppyyLegacy::GetROOT() function call)
303 (void)gROOT;
304
305 // setup dummy holders for global and std namespaces
306 assert(g_classrefs.size() == GLOBAL_HANDLE);
308 g_classrefs.push_back(TClassRef(""));
309
310 // aliases for std (setup already in pythonify)
312 g_name2classrefidx["::std"] = g_name2classrefidx["std"];
313 g_classrefs.push_back(TClassRef("std"));
314
315 // add a dummy global to refer to as null at index 0
316 g_globalvars.push_back(nullptr);
317 g_globalidx[nullptr] = 0;
318
319 // fill out the builtins
320 std::set<std::string> bi{g_builtins};
321 for (const auto& name : bi) {
322 for (const char* a : {"*", "&", "*&", "[]", "*[]"})
323 g_builtins.insert(name+a);
324 }
325
326 // disable fast path if requested
327 if (std::getenv("CPPYY_DISABLE_FASTPATH")) gEnableFastPath = false;
328
329 // fill the set of STL names
330 const char* stl_names[] = {"allocator", "auto_ptr", "bad_alloc", "bad_cast",
331 "bad_exception", "bad_typeid", "basic_filebuf", "basic_fstream", "basic_ifstream",
332 "basic_ios", "basic_iostream", "basic_istream", "basic_istringstream",
333 "basic_ofstream", "basic_ostream", "basic_ostringstream", "basic_streambuf",
334 "basic_string", "basic_stringbuf", "basic_stringstream", "binary_function",
335 "binary_negate", "bitset", "byte", "char_traits", "codecvt_byname", "codecvt", "collate",
336 "collate_byname", "compare", "complex", "ctype_byname", "ctype", "default_delete",
337 "deque", "divides", "domain_error", "equal_to", "exception", "forward_list", "fpos",
338 "function", "greater_equal", "greater", "gslice_array", "gslice", "hash", "indirect_array",
339 "integer_sequence", "invalid_argument", "ios_base", "istream_iterator", "istreambuf_iterator",
340 "istrstream", "iterator_traits", "iterator", "length_error", "less_equal", "less",
341 "list", "locale", "localedef utility", "locale utility", "logic_error", "logical_and",
342 "logical_not", "logical_or", "map", "mask_array", "mem_fun", "mem_fun_ref", "messages",
343 "messages_byname", "minus", "modulus", "money_get", "money_put", "moneypunct",
344 "moneypunct_byname", "multimap", "multiplies", "multiset", "negate", "not_equal_to",
345 "num_get", "num_put", "numeric_limits", "numpunct", "numpunct_byname",
346 "ostream_iterator", "ostreambuf_iterator", "ostrstream", "out_of_range",
347 "overflow_error", "pair", "plus", "pointer_to_binary_function",
348 "pointer_to_unary_function", "priority_queue", "queue", "range_error",
349 "raw_storage_iterator", "reverse_iterator", "runtime_error", "set", "shared_ptr",
350 "slice_array", "slice", "stack", "string", "strstream", "strstreambuf",
351 "time_get_byname", "time_get", "time_put_byname", "time_put", "unary_function",
352 "unary_negate", "unique_ptr", "underflow_error", "unordered_map", "unordered_multimap",
353 "unordered_multiset", "unordered_set", "valarray", "vector", "weak_ptr", "wstring",
354 "__hash_not_enabled"};
355 for (auto& name : stl_names)
356 gSTLNames.insert(name);
357
358 // set opt level (default to 2 if not given; Cling itself defaults to 0)
359 int optLevel = 2;
360 if (std::getenv("CPPYY_OPT_LEVEL")) optLevel = atoi(std::getenv("CPPYY_OPT_LEVEL"));
361 if (optLevel != 0) {
362 std::ostringstream s;
363 s << "#pragma cling optimize " << optLevel;
364 gInterpreter->ProcessLine(s.str().c_str());
365 }
366
367 // load frequently used headers
368 const char* code =
369 "#include <iostream>\n"
370 "#include <string>\n"
371 "#include <DllImport.h>\n" // defines R__EXTERN
372 "#include <vector>\n"
373 "#include <utility>";
374 gInterpreter->ProcessLine(code);
375
376 // create helpers for comparing thingies
377 gInterpreter->Declare(
378 "namespace __cppyy_internal { template<class C1, class C2>"
379 " bool is_equal(const C1& c1, const C2& c2) { return (bool)(c1 == c2); } }");
380 gInterpreter->Declare(
381 "namespace __cppyy_internal { template<class C1, class C2>"
382 " bool is_not_equal(const C1& c1, const C2& c2) { return (bool)(c1 != c2); } }");
383
384 // helper for multiple inheritance
385 gInterpreter->Declare("namespace __cppyy_internal { struct Sep; }");
386
387 // retrieve all initial (ROOT) C++ names in the global scope to allow filtering later
388 gROOT->GetListOfGlobals(true); // force initialize
389 gROOT->GetListOfGlobalFunctions(true); // id.
390 std::set<std::string> initial;
392 gInitialNames = initial;
393
394#ifndef WIN32
395 gRootSOs.insert("libCore.so ");
396 gRootSOs.insert("libRIO.so ");
397 gRootSOs.insert("libThread.so ");
398 gRootSOs.insert("libMathCore.so ");
399#else
400 gRootSOs.insert("libCore.dll ");
401 gRootSOs.insert("libRIO.dll ");
402 gRootSOs.insert("libThread.dll ");
403 gRootSOs.insert("libMathCore.dll ");
404#endif
405
406 // start off with a reasonable size placeholder for wrappers
407 gWrapperHolder.reserve(1024);
408
409 // create an exception handler to process signals
410 gExceptionHandler = new TExceptionHandlerImp{};
411 }
412
413 ~ApplicationStarter() {
414 for (auto wrap : gWrapperHolder)
415 delete wrap;
416 delete gExceptionHandler; gExceptionHandler = nullptr;
417 }
418} _applicationStarter;
419
420} // unnamed namespace
421
422
423// local helpers -------------------------------------------------------------
424static inline
426{
427 assert((ClassRefs_t::size_type)scope < g_classrefs.size());
428 return g_classrefs[(ClassRefs_t::size_type)scope];
429}
430
431static inline
433 CallWrapper* wrap = ((CallWrapper*)method);
434 if (!wrap->fTF) {
435 MethodInfo_t* mi = gInterpreter->MethodInfo_Factory(wrap->fDecl);
436 wrap->fTF = new TFunction(mi);
437 }
438 return wrap->fTF;
439}
440
441/*
442static inline
443CallWrapper::DeclId_t m2d(Cppyy::TCppMethod_t method) {
444 CallWrapper* wrap = ((CallWrapper*)method);
445 if (!wrap->fTF || wrap->fTF->GetDeclId() != wrap->fDecl) {
446 MethodInfo_t* mi = gInterpreter->MethodInfo_Factory(wrap->fDecl);
447 wrap->fTF = new TFunction(mi);
448 }
449 return wrap->fDecl;
450}
451*/
452
453static inline
454char* cppstring_to_cstring(const std::string& cppstr)
455{
456 char* cstr = (char*)malloc(cppstr.size()+1);
457 memcpy(cstr, cppstr.c_str(), cppstr.size()+1);
458 return cstr;
459}
460
461static inline
462bool match_name(const std::string& tname, const std::string fname)
463{
464// either match exactly, or match the name as template
465 if (fname.rfind(tname, 0) == 0) {
466 if ((tname.size() == fname.size()) ||
467 (tname.size() < fname.size() && fname[tname.size()] == '<'))
468 return true;
469 }
470 return false;
471}
472
473static inline
474bool is_missclassified_stl(const std::string& name)
475{
476 std::string::size_type pos = name.find('<');
477 if (pos != std::string::npos)
478 return gSTLNames.find(name.substr(0, pos)) != gSTLNames.end();
479 return gSTLNames.find(name) != gSTLNames.end();
480}
481
482
483// direct interpreter access -------------------------------------------------
484bool Cppyy::Compile(const std::string& code, bool /*silent*/)
485{
486 return gInterpreter->Declare(code.c_str());
487}
488
490{
491 if (klass && obj && !IsNamespace((TCppScope_t)klass))
492 return gInterpreter->ToString(GetScopedFinalName(klass).c_str(), (void*)obj);
493 return "";
494}
495
496
497// name to opaque C++ scope representation -----------------------------------
498std::string Cppyy::ResolveName(const std::string& cppitem_name)
499{
500// Fully resolve the given name to the final type name.
501
502// try memoized type cache, in case seen before
503 std::string memoized = find_memoized_resolved_name(cppitem_name);
504 if (!memoized.empty()) return memoized;
505
506// remove global scope '::' if present
507 std::string tclean = cppitem_name.compare(0, 2, "::") == 0 ?
508 cppitem_name.substr(2, std::string::npos) : cppitem_name;
509
510// classes (most common)
511 tclean = TClassEdit::CleanType(tclean.c_str());
512 if (tclean.empty() /* unknown, eg. an operator */) return cppitem_name;
513
514// reduce [N] to []
515 if (tclean[tclean.size()-1] == ']')
516 tclean = tclean.substr(0, tclean.rfind('[')) + "[]";
517
518 if (tclean.rfind("byte", 0) == 0 || tclean.rfind("std::byte", 0) == 0)
519 return tclean;
520
521// remove __restrict and __restrict__
522 auto pos = tclean.rfind("__restrict");
523 if (pos != std::string::npos)
524 tclean = tclean.substr(0, pos);
525
526 if (tclean.compare(0, 9, "std::byte") == 0)
527 return tclean;
528
529// check data types list (accept only builtins as typedefs will
530// otherwise not be resolved)
531 if (IsBuiltin(tclean)) return tclean;
532
533// special case for enums
534 if (IsEnum(cppitem_name))
535 return ResolveEnum(cppitem_name);
536
537// special case for clang's builtin __type_pack_element (which does not resolve)
538 pos = cppitem_name.size() > 20 ? \
539 cppitem_name.rfind("__type_pack_element", 5) : std::string::npos;
540 if (pos != std::string::npos) {
541 // shape is "[std::]__type_pack_element<index,type1,type2,...,typeN>cpd": extract
542 // first the index, and from there the indexed type; finally, restore the
543 // qualifiers
544 const char* str = cppitem_name.c_str();
545 char* endptr = nullptr;
546 unsigned long index = strtoul(str+20+pos, &endptr, 0);
547
548 std::string tmplvars{endptr};
549 auto start = tmplvars.find(',') + 1;
550 auto end = tmplvars.find(',', start);
551 while (index != 0) {
552 start = end+1;
553 end = tmplvars.find(',', start);
554 if (end == std::string::npos) end = tmplvars.rfind('>');
555 --index;
556 }
557
558 std::string resolved = tmplvars.substr(start, end-start);
559 auto cpd = tmplvars.rfind('>');
560 if (cpd != std::string::npos && cpd+1 != tmplvars.size())
561 return resolved + tmplvars.substr(cpd+1, std::string::npos);
562 return resolved;
563 }
564
565// typedefs etc. (and a couple of hacks around TClassEdit-isms, fixing of which
566// in ResolveTypedef itself is a TODO ...)
567 tclean = TClassEdit::ResolveTypedef(tclean.c_str(), true);
568 pos = 0;
569 while ((pos = tclean.find("::::", pos)) != std::string::npos) {
570 tclean.replace(pos, 4, "::");
571 pos += 2;
572 }
573
574 if (tclean.compare(0, 6, "const ") != 0)
575 return TClassEdit::ShortType(tclean.c_str(), 2);
576 return "const " + TClassEdit::ShortType(tclean.c_str(), 2);
577}
578
579#if 0
580//----------------------------------------------------------------------------
581static std::string extract_namespace(const std::string& name)
582{
583// Find the namespace the named class lives in, take care of templates
584// Note: this code also lives in CPyCppyy (TODO: refactor?)
585 if (name.empty())
586 return name;
587
588 int tpl_open = 0;
589 for (std::string::size_type pos = name.size()-1; 0 < pos; --pos) {
590 std::string::value_type c = name[pos];
591
592 // count '<' and '>' to be able to skip template contents
593 if (c == '>')
594 ++tpl_open;
595 else if (c == '<')
596 --tpl_open;
597
598 // collect name up to "::"
599 else if (tpl_open == 0 && c == ':' && name[pos-1] == ':') {
600 // found the extend of the scope ... done
601 return name.substr(0, pos-1);
602 }
603 }
604
605// no namespace; assume outer scope
606 return "";
607}
608#endif
609
610std::string Cppyy::ResolveEnum(const std::string& enum_type)
611{
612// The underlying type of a an enum may be any kind of integer.
613// Resolve that type via a workaround (note: this function assumes
614// that the enum_type name is a valid enum type name)
615 auto res = resolved_enum_types.find(enum_type);
616 if (res != resolved_enum_types.end())
617 return res->second;
618
619// desugar the type before resolving
620 std::string et_short = TClassEdit::ShortType(enum_type.c_str(), 1);
621 if (et_short.find("(unnamed") == std::string::npos) {
622 std::ostringstream decl;
623 // TODO: now presumed fixed with https://sft.its.cern.ch/jira/browse/ROOT-6988
624 for (auto& itype : {"unsigned int"}) {
625 decl << "std::is_same<"
626 << itype
627 << ", std::underlying_type<"
628 << et_short
629 << ">::type>::value;";
630 if (gInterpreter->ProcessLine(decl.str().c_str())) {
631 // TODO: "re-sugaring" like this is brittle, but the top
632 // should be re-translated into AST-based code anyway
633 std::string resugared;
634 if (et_short.size() != enum_type.size()) {
635 auto pos = enum_type.find(et_short);
636 if (pos != std::string::npos) {
637 resugared = enum_type.substr(0, pos) + itype;
638 if (pos+et_short.size() < enum_type.size())
639 resugared += enum_type.substr(pos+et_short.size(), std::string::npos);
640 }
641 }
642 if (resugared.empty()) resugared = itype;
643 resolved_enum_types[enum_type] = resugared;
644 return resugared;
645 }
646 }
647 }
648
649// failed or anonymous ... signal upstream to special case this
650 int ipos = (int)enum_type.size()-1;
651 for (; 0 <= ipos; --ipos) {
652 char c = enum_type[ipos];
653 if (isspace(c)) continue;
654 if (isalnum(c) || c == '_' || c == '>' || c == ')') break;
655 }
656 bool isConst = enum_type.find("const ", 6) != std::string::npos;
657 std::string restype = isConst ? "const " : "";
658 restype += "internal_enum_type_t"+enum_type.substr((std::string::size_type)ipos+1, std::string::npos);
659 resolved_enum_types[enum_type] = restype;
660 return restype; // should default to some int variant
661}
662
663#if 0
664static Cppyy::TCppIndex_t ArgSimilarityScore(void *argqtp, void *reqqtp)
665{
666// This scoring is not based on any particular rules
667 if (gInterpreter->IsSameType(argqtp, reqqtp))
668 return 0; // Best match
669 else if ((gInterpreter->IsSignedIntegerType(argqtp) && gInterpreter->IsSignedIntegerType(reqqtp)) ||
670 (gInterpreter->IsUnsignedIntegerType(argqtp) && gInterpreter->IsUnsignedIntegerType(reqqtp)) ||
671 (gInterpreter->IsFloatingType(argqtp) && gInterpreter->IsFloatingType(reqqtp)))
672 return 1;
673 else if ((gInterpreter->IsSignedIntegerType(argqtp) && gInterpreter->IsUnsignedIntegerType(reqqtp)) ||
674 (gInterpreter->IsFloatingType(argqtp) && gInterpreter->IsUnsignedIntegerType(reqqtp)))
675 return 2;
676 else if ((gInterpreter->IsIntegerType(argqtp) && gInterpreter->IsIntegerType(reqqtp)))
677 return 3;
678 else if ((gInterpreter->IsIntegralType(argqtp) && gInterpreter->IsIntegralType(reqqtp)))
679 return 4;
680 else if ((gInterpreter->IsVoidPointerType(argqtp) && gInterpreter->IsPointerType(reqqtp)))
681 return 5;
682 else
683 return 10; // Penalize heavily for no possible match
684}
685#endif
686
687Cppyy::TCppScope_t Cppyy::GetScope(const std::string& sname)
688{
689// First, try cache
690 TCppType_t result = find_memoized_scope(sname);
691 if (result) return result;
692
693// Second, skip builtins before going through the more expensive steps of resolving
694// typedefs and looking up TClass
695 if (g_builtins.find(sname) != g_builtins.end())
696 return (TCppScope_t)0;
697
698// TODO: scope_name should always be final already?
699// Resolve name fully before lookup to make sure all aliases point to the same scope
700 std::string scope_name = ResolveName(sname);
701 bool bHasAlias1 = sname != scope_name;
702 if (bHasAlias1) {
703 result = find_memoized_scope(scope_name);
704 if (result) {
705 g_name2classrefidx[sname] = result;
706 return result;
707 }
708 }
709
710// both failed, but may be STL name that's missing 'std::' now, but didn't before
711 bool b_scope_name_missclassified = is_missclassified_stl(scope_name);
712 if (b_scope_name_missclassified) {
713 result = find_memoized_scope("std::"+scope_name);
714 if (result) g_name2classrefidx["std::"+scope_name] = (ClassRefs_t::size_type)result;
715 }
716 bool b_sname_missclassified = bHasAlias1 ? is_missclassified_stl(sname) : false;
717 if (b_sname_missclassified) {
718 if (!result) result = find_memoized_scope("std::"+sname);
719 if (result) g_name2classrefidx["std::"+sname] = (ClassRefs_t::size_type)result;
720 }
721
722 if (result) return result;
723
724// use TClass directly, to enable auto-loading; class may be stubbed (eg. for
725// function returns) or forward declared, leading to a non-null TClass that is
726// otherwise invalid/unusable
727 TClassRef cr(TClass::GetClass(scope_name.c_str(), true /* load */, true /* silent */));
728 if (!cr.GetClass())
729 return (TCppScope_t)0;
730
731// memoize found/created TClass
732 bool bHasAlias2 = cr->GetName() != scope_name;
733 if (bHasAlias2) {
734 result = find_memoized_scope(cr->GetName());
735 if (result) {
736 g_name2classrefidx[scope_name] = result;
737 if (bHasAlias1) g_name2classrefidx[sname] = result;
738 return result;
739 }
740 }
741
742 ClassRefs_t::size_type sz = g_classrefs.size();
743 g_name2classrefidx[scope_name] = sz;
744 if (bHasAlias1) g_name2classrefidx[sname] = sz;
745 if (bHasAlias2) g_name2classrefidx[cr->GetName()] = sz;
746// TODO: make ROOT/meta NOT remove std :/
747 if (b_scope_name_missclassified)
748 g_name2classrefidx["std::"+scope_name] = sz;
749 if (b_sname_missclassified)
750 g_name2classrefidx["std::"+sname] = sz;
751
752 g_classrefs.push_back(TClassRef(scope_name.c_str()));
753
754 return (TCppScope_t)sz;
755}
756
757bool Cppyy::IsTemplate(const std::string& template_name)
758{
759 return (bool)gInterpreter->CheckClassTemplate(template_name.c_str());
760}
761
762namespace {
763 class AutoCastRTTI {
764 public:
765 virtual ~AutoCastRTTI() {}
766 };
767}
768
770{
771 TClassRef& cr = type_from_handle(klass);
772 if (!cr.GetClass() || !obj) return klass;
773
774 if (!(cr->ClassProperty() & kClassHasVirtual))
775 return klass; // not polymorphic: no RTTI info available
776
777// TODO: ios class casting (ostream, streambuf, etc.) fails with a crash in GetActualClass()
778// below on Mac ARM (it's likely that the found actual class was replaced, maybe because
779// there are duplicates from pcm/pch?); filter them out for now as it's usually unnecessary
780// anyway to autocast these
781 std::string clName = cr->GetName();
782 if (clName.find("std::", 0, 5) == 0 && clName.find("stream") != std::string::npos)
783 return klass;
784
785#ifdef _WIN64
786// Cling does not provide a consistent ImageBase address for calculating relative addresses
787// as used in Windows 64b RTTI. So, check for our own RTTI extension instead. If that fails,
788// see whether the unmangled raw_name is available (e.g. if this is an MSVC compiled rather
789// than JITed class) and pass on if it is.
790 volatile const char* raw = nullptr; // to prevent too aggressive reordering
791 try {
792 // this will filter those objects that do not have RTTI to begin with (throws)
793 AutoCastRTTI* pcst = (AutoCastRTTI*)obj;
794 raw = typeid(*pcst).raw_name();
795
796 // check the signature id (0 == absolute, 1 == relative, 2 == ours)
797 void* vfptr = *(void**)((intptr_t)obj);
798 void* meta = (void*)((intptr_t)*((void**)((intptr_t)vfptr-sizeof(void*))));
799 if (*(intptr_t*)meta == 2) {
800 // access the extra data item which is an absolute pointer to the RTTI
801 void* ptdescr = (void*)((intptr_t)meta + 4*sizeof(unsigned long)+sizeof(void*));
802 if (ptdescr && *(void**)ptdescr) {
803 auto rtti = *(std::type_info**)ptdescr;
804 raw = rtti->raw_name();
805 if (raw && raw[0] != '\0') // likely unnecessary
806 return (TCppType_t)GetScope(rtti->name());
807 }
808
809 return klass; // do not fall through if no RTTI info available
810 }
811
812 // if the raw name is the empty string (no guarantees that this is so as truly, the
813 // address is corrupt, but it is common to be empty), then there is no accessible RTTI
814 // and getting the unmangled name will crash ...
815 if (!raw)
816 return klass;
817 } catch (std::bad_typeid) {
818 return klass; // can't risk passing to ROOT/meta as it may do RTTI
819 }
820#endif
821
822 TClass* clActual = cr->GetActualClass((void*)obj);
823 // The additional check using TClass::GetClassInfo is to prevent returning classes of which the Interpreter has no info (see https://github.com/root-project/root/pull/16177)
824 if (clActual && clActual != cr.GetClass() && clActual->GetClassInfo()) {
825 auto itt = g_name2classrefidx.find(clActual->GetName());
826 if (itt != g_name2classrefidx.end())
827 return (TCppType_t)itt->second;
828 return (TCppType_t)GetScope(clActual->GetName());
829 }
830
831 return klass;
832}
833
835{
836 TClassRef& cr = type_from_handle(klass);
837 if (cr.GetClass() && cr->GetClassInfo())
838 return (size_t)gInterpreter->ClassInfo_Size(cr->GetClassInfo());
839 return (size_t)0;
840}
841
842size_t Cppyy::SizeOf(const std::string& type_name)
843{
844 TDataType* dt = gROOT->GetType(type_name.c_str());
845 if (dt) return dt->Size();
846 return SizeOf(GetScope(type_name));
847}
848
849bool Cppyy::IsBuiltin(const std::string& type_name)
850{
851 if (g_builtins.find(type_name) != g_builtins.end())
852 return true;
853
854 const std::string& tclean = TClassEdit::CleanType(type_name.c_str(), 1);
855 if (g_builtins.find(tclean) != g_builtins.end())
856 return true;
857
858 if (strstr(tclean.c_str(), "std::complex"))
859 return true;
860
861 return false;
862}
863
864bool Cppyy::IsComplete(const std::string& type_name)
865{
866// verify whether the dictionary of this class is fully available
867 bool b = false;
868
869 int oldEIL = gErrorIgnoreLevel;
870 gErrorIgnoreLevel = 3000;
871 TClass* klass = TClass::GetClass(type_name.c_str());
872 if (klass && klass->GetClassInfo()) // works for normal case w/ dict
873 b = gInterpreter->ClassInfo_IsLoaded(klass->GetClassInfo());
874 else { // special case for forward declared classes
875 ClassInfo_t* ci = gInterpreter->ClassInfo_Factory(type_name.c_str());
876 if (ci) {
877 b = gInterpreter->ClassInfo_IsLoaded(ci);
878 gInterpreter->ClassInfo_Delete(ci); // we own the fresh class info
879 }
880 }
881 gErrorIgnoreLevel = oldEIL;
882 return b;
883}
884
885// memory management ---------------------------------------------------------
887{
889 return (TCppObject_t)::operator new(gInterpreter->ClassInfo_Size(cr->GetClassInfo()));
890}
891
893{
894 ::operator delete(instance);
895}
896
898{
900 if (arena)
901 return (TCppObject_t)cr->New(arena, TClass::kRealNew);
902 return (TCppObject_t)cr->New(TClass::kRealNew);
903}
904
905static std::map<Cppyy::TCppType_t, bool> sHasOperatorDelete;
907{
910 cr->Destructor((void*)instance);
911 else {
912 ROOT::DelFunc_t fdel = cr->GetDelete();
913 if (fdel) fdel((void*)instance);
914 else {
915 auto ib = sHasOperatorDelete.find(type);
916 if (ib == sHasOperatorDelete.end()) {
917 TFunction *f = (TFunction *)cr->GetMethodAllAny("operator delete");
918 sHasOperatorDelete[type] = (bool)(f && (f->Property() & kIsPublic));
919 ib = sHasOperatorDelete.find(type);
920 }
921 ib->second ? cr->Destructor((void*)instance) : ::operator delete((void*)instance);
922 }
923 }
924}
925
926
927// method/function dispatching -----------------------------------------------
929{
930// TODO: method should be a callfunc, so that no mapping would be needed.
931 CallWrapper* wrap = (CallWrapper*)method;
932
933 CallFunc_t* callf = gInterpreter->CallFunc_Factory();
934 MethodInfo_t* meth = gInterpreter->MethodInfo_Factory(wrap->fDecl);
935 gInterpreter->CallFunc_SetFunc(callf, meth);
936 gInterpreter->MethodInfo_Delete(meth);
937
938 if (!(callf && gInterpreter->CallFunc_IsValid(callf))) {
939 // TODO: propagate this error to caller w/o use of Python C-API
940 /*
941 PyErr_Format(PyExc_RuntimeError, "could not resolve %s::%s(%s)",
942 const_cast<TClassRef&>(klass).GetClassName(),
943 wrap.fName, callString.c_str()); */
944 std::cerr << "TODO: report unresolved function error to Python\n";
945 if (callf) gInterpreter->CallFunc_Delete(callf);
947 }
948
949// generate the wrapper and JIT it; ignore wrapper generation errors (will simply
950// result in a nullptr that is reported upstream if necessary; often, however,
951// there is a different overload available that will do)
952 auto oldErrLvl = gErrorIgnoreLevel;
954 wrap->fFaceptr = gInterpreter->CallFunc_IFacePtr(callf);
955 gErrorIgnoreLevel = oldErrLvl;
956
957 gInterpreter->CallFunc_Delete(callf); // does not touch IFacePtr
958 return wrap->fFaceptr;
959}
960
961static inline
962bool copy_args(Parameter* args, size_t nargs, void** vargs)
963{
964 bool runRelease = false;
965 for (size_t i = 0; i < nargs; ++i) {
966 switch (args[i].fTypeCode) {
967 case 'X': /* (void*)type& with free */
968 runRelease = true;
969 case 'V': /* (void*)type& */
970 vargs[i] = args[i].fValue.fVoidp;
971 break;
972 case 'r': /* const type& */
973 vargs[i] = args[i].fRef;
974 break;
975 default: /* all other types in union */
976 vargs[i] = (void*)&args[i].fValue.fVoidp;
977 break;
978 }
979 }
980 return runRelease;
981}
982
983static inline
984void release_args(Parameter* args, size_t nargs)
985{
986 for (size_t i = 0; i < nargs; ++i) {
987 if (args[i].fTypeCode == 'X')
988 free(args[i].fValue.fVoidp);
989 }
990}
991
992static inline bool WrapperCall(Cppyy::TCppMethod_t method, size_t nargs, void* args_, void* self, void* result)
993{
994 Parameter* args = (Parameter*)args_;
995 //bool is_direct = nargs & DIRECT_CALL;
996 nargs = CALL_NARGS(nargs);
997
998 CallWrapper* wrap = (CallWrapper*)method;
999 const TInterpreter::CallFuncIFacePtr_t& faceptr = wrap->fFaceptr.fGeneric ? wrap->fFaceptr : GetCallFunc(method);
1000 if (!faceptr.fGeneric)
1001 return false; // happens with compilation error
1002
1004 bool runRelease = false;
1005 if (nargs <= SMALL_ARGS_N) {
1006 void* smallbuf[SMALL_ARGS_N];
1007 if (nargs) runRelease = copy_args(args, nargs, smallbuf);
1008 faceptr.fGeneric(self, (int)nargs, smallbuf, result);
1009 } else {
1010 std::vector<void*> buf(nargs);
1011 runRelease = copy_args(args, nargs, buf.data());
1012 faceptr.fGeneric(self, (int)nargs, buf.data(), result);
1013 }
1014 if (runRelease) release_args(args, nargs);
1015 return true;
1016 }
1017
1019 bool runRelease = false;
1020 if (nargs <= SMALL_ARGS_N) {
1021 void* smallbuf[SMALL_ARGS_N];
1022 if (nargs) runRelease = copy_args(args, nargs, (void**)smallbuf);
1023 faceptr.fCtor((void**)smallbuf, result, (unsigned long)nargs);
1024 } else {
1025 std::vector<void*> buf(nargs);
1026 runRelease = copy_args(args, nargs, buf.data());
1027 faceptr.fCtor(buf.data(), result, (unsigned long)nargs);
1028 }
1029 if (runRelease) release_args(args, nargs);
1030 return true;
1031 }
1032
1034 std::cerr << " DESTRUCTOR NOT IMPLEMENTED YET! " << std::endl;
1035 return false;
1036 }
1037
1038 return false;
1039}
1040
1041template<typename T>
1042static inline
1043T CallT(Cppyy::TCppMethod_t method, Cppyy::TCppObject_t self, size_t nargs, void* args)
1044{
1045 T t{};
1046 if (WrapperCall(method, nargs, args, (void*)self, &t))
1047 return t;
1048 return (T)-1;
1049}
1050
1051#define CPPYY_IMP_CALL(typecode, rtype) \
1052rtype Cppyy::Call##typecode(TCppMethod_t method, TCppObject_t self, size_t nargs, void* args)\
1053{ \
1054 return CallT<rtype>(method, self, nargs, args); \
1055}
1056
1057void Cppyy::CallV(TCppMethod_t method, TCppObject_t self, size_t nargs, void* args)
1058{
1059 if (!WrapperCall(method, nargs, args, (void*)self, nullptr))
1060 return /* TODO ... report error */;
1061}
1062
1063CPPYY_IMP_CALL(B, unsigned char)
1072
1073void* Cppyy::CallR(TCppMethod_t method, TCppObject_t self, size_t nargs, void* args)
1074{
1075 void* r = nullptr;
1076 if (WrapperCall(method, nargs, args, (void*)self, &r))
1077 return r;
1078 return nullptr;
1079}
1080
1082 TCppMethod_t method, TCppObject_t self, size_t nargs, void* args, size_t* length)
1083{
1084 char* cstr = nullptr;
1085 TClassRef cr("std::string");
1086 std::string* cppresult = (std::string*)malloc(sizeof(std::string));
1087 if (WrapperCall(method, nargs, args, self, (void*)cppresult)) {
1088 cstr = cppstring_to_cstring(*cppresult);
1089 *length = cppresult->size();
1090 cppresult->std::string::~basic_string();
1091 } else
1092 *length = 0;
1093 free((void*)cppresult);
1094 return cstr;
1095}
1096
1098 TCppMethod_t method, TCppType_t /* klass */, size_t nargs, void* args)
1099{
1100 void* obj = nullptr;
1101 if (WrapperCall(method, nargs, args, nullptr, &obj))
1102 return (TCppObject_t)obj;
1103 return (TCppObject_t)0;
1104}
1105
1107{
1109 cr->Destructor((void*)self, true);
1110}
1111
1113 TCppObject_t self, size_t nargs, void* args, TCppType_t result_type)
1114{
1115 TClassRef& cr = type_from_handle(result_type);
1116 auto *classInfo = cr->GetClassInfo();
1117 // If the class info is missing, we better return null and let cppyy
1118 // handle the error, before we step into undefined behavior
1119 if(!classInfo)
1120 return (TCppObject_t)0;
1121 auto classSize = gInterpreter->ClassInfo_Size(classInfo);
1122 // ClassInfo_Size returns -1 in case of invalid info, and 0 for
1123 // forward-declared classes, which we can't use.
1124 if (classSize <= 0)
1125 return (TCppObject_t)0;
1126 void* obj = ::operator new(classSize);
1127 if (WrapperCall(method, nargs, args, self, obj))
1128 return (TCppObject_t)obj;
1129 ::operator delete(obj);
1130 return (TCppObject_t)0;
1131}
1132
1134{
1135 if (check_enabled && !gEnableFastPath) return (TCppFuncAddr_t)nullptr;
1136 TFunction* f = m2f(method);
1137
1138 TCppFuncAddr_t pf = (TCppFuncAddr_t)gInterpreter->FindSym(f->GetMangledName());
1139 if (pf) return pf;
1140
1141 int ierr = 0;
1142 const char* fn = TClassEdit::DemangleName(f->GetMangledName(), ierr);
1143 if (ierr || !fn)
1144 return pf;
1145
1146 // TODO: the following attempts are all brittle and leak transactions, but
1147 // each properly exposes the symbol so subsequent lookups will succeed
1148 if (strstr(f->GetName(), "<")) {
1149 // force explicit instantiation and try again
1150 std::ostringstream sig;
1151 sig << "template " << fn << ";";
1152 gInterpreter->ProcessLine(sig.str().c_str());
1153 } else {
1154 std::ostringstream sig;
1155
1156 std::string sfn = fn;
1157 std::string::size_type pos = sfn.find('(');
1158 if (pos != std::string::npos) sfn = sfn.substr(0, pos);
1159
1160 // start cast
1161 sig << '(' << f->GetReturnTypeName() << " (";
1162
1163 // add scope for methods
1164 pos = sfn.rfind(':');
1165 if (pos != std::string::npos) {
1166 std::string scope_name = sfn.substr(0, pos-1);
1167 TCppScope_t scope = GetScope(scope_name);
1168 if (scope && !IsNamespace(scope))
1169 sig << scope_name << "::";
1170 }
1171
1172 // finalize cast
1173 sig << "*)" << GetMethodSignature(method, false)
1174 << ((f->Property() & kIsConstMethod) ? " const" : "")
1175 << ')';
1176
1177 // load address
1178 sig << '&' << sfn;
1179 gInterpreter->Calc(sig.str().c_str());
1180 }
1181
1182 return (TCppFuncAddr_t)gInterpreter->FindSym(f->GetMangledName());
1183}
1184
1185
1186// handling of function argument buffer --------------------------------------
1188{
1189 return new Parameter[nargs];
1190}
1191
1193{
1194 delete [] (Parameter*)args;
1195}
1196
1198{
1199 return sizeof(Parameter);
1200}
1201
1203{
1204 return offsetof(Parameter, fTypeCode);
1205}
1206
1207
1208// scope reflection information ----------------------------------------------
1210{
1211// Test if this scope represents a namespace.
1212 if (scope == GLOBAL_HANDLE)
1213 return true;
1214 TClassRef& cr = type_from_handle(scope);
1215 if (cr.GetClass())
1216 return cr->Property() & kIsNamespace;
1217 return false;
1218}
1219
1221{
1222// Test if this type may not be instantiated.
1223 TClassRef& cr = type_from_handle(klass);
1224 if (cr.GetClass())
1225 return cr->Property() & kIsAbstract;
1226 return false;
1227}
1228
1229bool Cppyy::IsEnum(const std::string& type_name)
1230{
1231 if (type_name.empty()) return false;
1232
1233 if (type_name.rfind("enum ", 0) == 0)
1234 return true; // by definition (C-style)
1235
1236 std::string tn_short = TClassEdit::ShortType(type_name.c_str(), 1);
1237 if (tn_short.empty()) return false;
1238 return gInterpreter->ClassInfo_IsEnum(tn_short.c_str());
1239}
1240
1242{
1243// Test if this type is a "plain old data" type
1245 if (cr.GetClass())
1246 return cr->ClassProperty() & kClassIsAggregate;
1247 return false;
1248}
1249
1251{
1252// Test if this type has a default constructor or is a "plain old data" type
1254 if (cr.GetClass())
1255 return cr->HasDefaultConstructor() || (cr->ClassProperty() & kClassIsAggregate);
1256 return true;
1257}
1258
1259// helpers for stripping scope names
1260static
1261std::string outer_with_template(const std::string& name)
1262{
1263// Cut down to the outer-most scope from <name>, taking proper care of templates.
1264 int tpl_open = 0;
1265 for (std::string::size_type pos = 0; pos < name.size(); ++pos) {
1266 std::string::value_type c = name[pos];
1267
1268 // count '<' and '>' to be able to skip template contents
1269 if (c == '<')
1270 ++tpl_open;
1271 else if (c == '>')
1272 --tpl_open;
1273
1274 // collect name up to "::"
1275 else if (tpl_open == 0 && \
1276 c == ':' && pos+1 < name.size() && name[pos+1] == ':') {
1277 // found the extend of the scope ... done
1278 return name.substr(0, pos-1);
1279 }
1280 }
1281
1282// whole name is apparently a single scope
1283 return name;
1284}
1285
1286static
1287std::string outer_no_template(const std::string& name)
1288{
1289// Cut down to the outer-most scope from <name>, drop templates
1290 std::string::size_type first_scope = name.find(':');
1291 if (first_scope == std::string::npos)
1292 return name.substr(0, name.find('<'));
1293 std::string::size_type first_templ = name.find('<');
1294 if (first_templ == std::string::npos)
1295 return name.substr(0, first_scope);
1296 return name.substr(0, std::min(first_templ, first_scope));
1297}
1298
1299#define FILL_COLL(type, filter) { \
1300 TIter itr{coll}; \
1301 type* obj = nullptr; \
1302 while ((obj = (type*)itr.Next())) { \
1303 const char* nm = obj->GetName(); \
1304 if (nm && nm[0] != '_' && !(obj->Property() & (filter))) { \
1305 if (gInitialNames.find(nm) == gInitialNames.end()) \
1306 cppnames.insert(nm); \
1307 }}}
1308
1309static inline
1310void cond_add(Cppyy::TCppScope_t scope, const std::string& ns_scope,
1311 std::set<std::string>& cppnames, const char* name, bool nofilter = false)
1312{
1313 if (!name || strstr(name, ".h") != 0)
1314 return;
1315
1316 if (scope == GLOBAL_HANDLE) {
1317 std::string to_add = outer_no_template(name);
1318 if ((nofilter || gInitialNames.find(to_add) == gInitialNames.end()) && !is_missclassified_stl(name))
1319 cppnames.insert(outer_no_template(name));
1320 } else if (scope == STD_HANDLE) {
1321 if (strncmp(name, "std::", 5) == 0) {
1322 name += 5;
1323#ifdef __APPLE__
1324 if (strncmp(name, "__1::", 5) == 0) name += 5;
1325#endif
1326 } else if (!is_missclassified_stl(name))
1327 return;
1328 cppnames.insert(outer_no_template(name));
1329 } else {
1330 if (strncmp(name, ns_scope.c_str(), ns_scope.size()) == 0)
1331 cppnames.insert(outer_with_template(name + ns_scope.size()));
1332 }
1333}
1334
1335void Cppyy::GetAllCppNames(TCppScope_t scope, std::set<std::string>& cppnames)
1336{
1337// Collect all known names of C++ entities under scope. This is useful for IDEs
1338// employing tab-completion, for example. Note that functions names need not be
1339// unique as they can be overloaded.
1340 TClassRef& cr = type_from_handle(scope);
1341 if (scope != GLOBAL_HANDLE && !(cr.GetClass() && cr->Property()))
1342 return;
1343
1344 std::string ns_scope = GetFinalName(scope);
1345 if (scope != GLOBAL_HANDLE) ns_scope += "::";
1346
1347// add existing values from read rootmap files if within this scope
1348 TCollection* coll = gInterpreter->GetMapfile()->GetTable();
1349 {
1350 TIter itr{coll};
1351 TEnvRec* ev = nullptr;
1352 while ((ev = (TEnvRec*)itr.Next())) {
1353 // TEnv contains rootmap entries and user-side rootmap files may be already
1354 // loaded on startup. Thus, filter on file name rather than load time.
1355 if (gRootSOs.find(ev->GetValue()) == gRootSOs.end())
1356 cond_add(scope, ns_scope, cppnames, ev->GetName(), true);
1357 }
1358 }
1359
1360// do we care about the class table or are the rootmap and list of types enough?
1361/*
1362 gClassTable->Init();
1363 const int N = gClassTable->Classes();
1364 for (int i = 0; i < N; ++i)
1365 cond_add(scope, ns_scope, cppnames, gClassTable->Next());
1366*/
1367
1368#if 0
1369// add interpreted classes (no load)
1370 {
1371 ClassInfo_t* ci = gInterpreter->ClassInfo_FactoryWithScope(
1372 false /* all */, scope == GLOBAL_HANDLE ? nullptr : cr->GetName());
1373 while (gInterpreter->ClassInfo_Next(ci)) {
1374 const char* className = gInterpreter->ClassInfo_FullName(ci);
1375 if (strstr(className, "(anonymous)") || strstr(className, "(unnamed)"))
1376 continue;
1377 cond_add(scope, ns_scope, cppnames, className);
1378 }
1379 gInterpreter->ClassInfo_Delete(ci);
1380 }
1381#endif
1382
1383// any other types (e.g. that may have come from parsing headers)
1384 coll = gROOT->GetListOfTypes();
1385 {
1386 TIter itr{coll};
1387 TDataType* dt = nullptr;
1388 while ((dt = (TDataType*)itr.Next())) {
1389 if (!(dt->Property() & kIsFundamental)) {
1390 cond_add(scope, ns_scope, cppnames, dt->GetName());
1391 }
1392 }
1393 }
1394
1395// add functions
1396 coll = (scope == GLOBAL_HANDLE) ?
1397 gROOT->GetListOfGlobalFunctions(true) : cr->GetListOfMethods(true);
1398 {
1399 TIter itr{coll};
1400 TFunction* obj = nullptr;
1401 while ((obj = (TFunction*)itr.Next())) {
1402 const char* nm = obj->GetName();
1403 // skip templated functions, adding only the un-instantiated ones
1404 if (nm && gInitialNames.find(nm) == gInitialNames.end())
1405 cppnames.insert(nm);
1406 }
1407 }
1408
1409// add uninstantiated templates
1410 coll = (scope == GLOBAL_HANDLE) ?
1411 gROOT->GetListOfFunctionTemplates() : cr->GetListOfFunctionTemplates(true);
1413
1414// add (global) data members
1415 if (scope == GLOBAL_HANDLE) {
1416 coll = gROOT->GetListOfGlobals();
1418 } else {
1419 coll = cr->GetListOfDataMembers();
1421 coll = cr->GetListOfUsingDataMembers();
1423 }
1424
1425// add enums values only for user classes/namespaces
1426 if (scope != GLOBAL_HANDLE && scope != STD_HANDLE) {
1427 coll = cr->GetListOfEnums();
1429 }
1430
1431#ifdef __APPLE__
1432// special case for Apple, add version namespace '__1' entries to std
1433 if (scope == STD_HANDLE)
1434 GetAllCppNames(GetScope("std::__1"), cppnames);
1435#endif
1436}
1437
1438
1439// class reflection information ----------------------------------------------
1440std::vector<Cppyy::TCppScope_t> Cppyy::GetUsingNamespaces(TCppScope_t scope)
1441{
1442 std::vector<Cppyy::TCppScope_t> res;
1443 if (!IsNamespace(scope))
1444 return res;
1445
1446#ifdef __APPLE__
1447 if (scope == STD_HANDLE) {
1448 res.push_back(GetScope("__1"));
1449 return res;
1450 }
1451#endif
1452
1453 TClassRef& cr = type_from_handle(scope);
1454 if (!cr.GetClass() || !cr->GetClassInfo())
1455 return res;
1456
1457 const std::vector<std::string>& v = gInterpreter->GetUsingNamespaces(cr->GetClassInfo());
1458 res.reserve(v.size());
1459 for (const auto& uid : v) {
1460 Cppyy::TCppScope_t uscope = GetScope(uid);
1461 if (uscope) res.push_back(uscope);
1462 }
1463
1464 return res;
1465}
1466
1467
1468// class reflection information ----------------------------------------------
1470{
1471 if (klass == GLOBAL_HANDLE)
1472 return "";
1473 TClassRef& cr = type_from_handle(klass);
1474 std::string clName = cr->GetName();
1475// TODO: why is this template splitting needed?
1476 std::string::size_type pos = clName.substr(0, clName.find('<')).rfind("::");
1477 if (pos != std::string::npos)
1478 return clName.substr(pos+2, std::string::npos);
1479 return clName;
1480}
1481
1483{
1484 if (klass == GLOBAL_HANDLE)
1485 return "";
1486 TClassRef& cr = type_from_handle(klass);
1487 if (cr.GetClass()) {
1488 std::string name = cr->GetName();
1490 return std::string("std::")+cr->GetName();
1491 return cr->GetName();
1492 }
1493 return "<unknown>";
1494}
1495
1497{
1498 TClassRef& cr = type_from_handle(klass);
1499 if (!cr.GetClass())
1500 return false;
1501
1502 TFunction* f = cr->GetMethod(("~"+GetFinalName(klass)).c_str(), "");
1503 if (f && (f->Property() & kIsVirtual))
1504 return true;
1505
1506 return false;
1507}
1508
1510{
1511 int is_complex = 1;
1512 size_t nbases = 0;
1513
1514 TClassRef& cr = type_from_handle(klass);
1515 if (cr.GetClass() && cr->GetListOfBases() != 0)
1516 nbases = GetNumBases(klass);
1517
1518 if (1 < nbases)
1519 is_complex = 1;
1520 else if (nbases == 0)
1521 is_complex = 0;
1522 else { // one base class only
1523 TBaseClass* base = (TBaseClass*)cr->GetListOfBases()->At(0);
1524 if (base->Property() & kIsVirtualBase)
1525 is_complex = 1; // TODO: verify; can be complex, need not be.
1526 else
1527 is_complex = HasComplexHierarchy(GetScope(base->GetName()));
1528 }
1529
1530 return is_complex;
1531}
1532
1534{
1535// Get the total number of base classes that this class has.
1536 TClassRef& cr = type_from_handle(klass);
1537 if (cr.GetClass() && cr->GetListOfBases() != 0)
1538 return (TCppIndex_t)cr->GetListOfBases()->GetSize();
1539 return (TCppIndex_t)0;
1540}
1541
1542////////////////////////////////////////////////////////////////////////////////
1543/// \fn Cppyy::TCppIndex_t GetLongestInheritancePath(TClass *klass)
1544/// \brief Retrieve number of base classes in the longest branch of the
1545/// inheritance tree of the input class.
1546/// \param[in] klass The class to start the retrieval process from.
1547///
1548/// This is a helper function for Cppyy::GetNumBasesLongestBranch.
1549/// Given an inheritance tree, the function assigns weight 1 to each class that
1550/// has at least one base. Starting from the input class, the function is
1551/// called recursively on all the bases. For each base the return value is one
1552/// (the weight of the base itself) plus the maximum value retrieved for their
1553/// bases in turn. For example, given the following inheritance tree:
1554///
1555/// ~~~{.cpp}
1556/// class A {}; class B: public A {};
1557/// class X {}; class Y: public X {}; class Z: public Y {};
1558/// class C: public B, Z {};
1559/// ~~~
1560///
1561/// calling this function on an instance of `C` will return 3, the steps
1562/// required to go from C to X.
1564{
1565
1566 auto directbases = klass->GetListOfBases();
1567 if (!directbases) {
1568 // This is a leaf with no bases
1569 return 0;
1570 }
1571 auto ndirectbases = directbases->GetSize();
1572 if (ndirectbases == 0) {
1573 // This is a leaf with no bases
1574 return 0;
1575 } else {
1576 // If there is at least one direct base
1577 std::vector<Cppyy::TCppIndex_t> nbases_branches;
1578 nbases_branches.reserve(ndirectbases);
1579
1580 // Traverse all direct bases of the current class and call the function
1581 // recursively
1582 for (auto baseclass : TRangeDynCast<TBaseClass>(directbases)) {
1583 if (!baseclass)
1584 continue;
1585 if (auto baseclass_tclass = baseclass->GetClassPointer()) {
1587 }
1588 }
1589
1590 // Get longest path among the direct bases of the current class
1591 auto longestbranch = std::max_element(std::begin(nbases_branches), std::end(nbases_branches));
1592
1593 // Add 1 to include the current class in the count
1594 return 1 + *longestbranch;
1595 }
1596}
1597
1598////////////////////////////////////////////////////////////////////////////////
1599/// \fn Cppyy::TCppIndex_t Cppyy::GetNumBasesLongest(TCppType_t klass)
1600/// \brief Retrieve number of base classes in the longest branch of the
1601/// inheritance tree.
1602/// \param[in] klass The class to start the retrieval process from.
1603///
1604/// The function converts the input class to a `TClass *` and calls
1605/// GetLongestInheritancePath.
1607{
1608
1609 const auto &cr = type_from_handle(klass);
1610
1611 if (auto klass_tclass = cr.GetClass()) {
1613 }
1614
1615 // In any other case, return zero
1616 return 0;
1617}
1618
1620{
1622 return ((TBaseClass*)cr->GetListOfBases()->At((int)ibase))->GetName();
1623}
1624
1626{
1627 if (derived == base)
1628 return true;
1631 if (derived_type.GetClass() && base_type.GetClass())
1632 return derived_type->GetBaseClass(base_type) != 0;
1633 return false;
1634}
1635
1637{
1639 const std::string& tn = cr->GetName();
1640 if (gSmartPtrTypes.find(tn.substr(0, tn.find("<"))) != gSmartPtrTypes.end())
1641 return true;
1642 return false;
1643}
1644
1646 const std::string& tname, TCppType_t* raw, TCppMethod_t* deref)
1647{
1648 const std::string& rn = ResolveName(tname);
1649 if (gSmartPtrTypes.find(rn.substr(0, rn.find("<"))) != gSmartPtrTypes.end()) {
1650 if (!raw && !deref) return true;
1651
1653 if (cr.GetClass()) {
1654 TFunction* func = cr->GetMethod("operator->", "");
1655 if (!func)
1656 func = cr->GetMethod("operator->", "");
1657 if (func) {
1658 if (deref) *deref = (TCppMethod_t)new_CallWrapper(func);
1659 if (raw) *raw = GetScope(TClassEdit::ShortType(
1660 func->GetReturnTypeNormalizedName().c_str(), 1));
1661 return (!deref || *deref) && (!raw || *raw);
1662 }
1663 }
1664 }
1665
1666 return false;
1667}
1668
1669void Cppyy::AddSmartPtrType(const std::string& type_name)
1670{
1672}
1673
1674void Cppyy::AddTypeReducer(const std::string& /*reducable*/, const std::string& /*reduced*/)
1675{
1676 // This function is deliberately left empty, because it is not used in
1677 // PyROOT, and synchronizing it with cppyy-backend upstream would require
1678 // patches to ROOT meta.
1679}
1680
1681
1682// type offsets --------------------------------------------------------------
1684 TCppObject_t address, int direction, bool rerror)
1685{
1686// calculate offsets between declared and actual type, up-cast: direction > 0; down-cast: direction < 0
1687 if (derived == base || !(base && derived))
1688 return (ptrdiff_t)0;
1689
1691 TClassRef& cb = type_from_handle(base);
1692
1693 if (!cd.GetClass() || !cb.GetClass())
1694 return (ptrdiff_t)0;
1695
1696 ptrdiff_t offset = -1;
1697 if (!(cd->GetClassInfo() && cb->GetClassInfo())) { // gInterpreter requirement
1698 // would like to warn, but can't quite determine error from intentional
1699 // hiding by developers, so only cover the case where we really should have
1700 // had a class info, but apparently don't:
1701 if (cd->IsLoaded()) {
1702 // warn to allow diagnostics
1703 std::ostringstream msg;
1704 msg << "failed offset calculation between " << cb->GetName() << " and " << cd->GetName();
1705 // TODO: propagate this warning to caller w/o use of Python C-API
1706 // PyErr_Warn(PyExc_RuntimeWarning, const_cast<char*>(msg.str().c_str()));
1707 std::cerr << "Warning: " << msg.str() << '\n';
1708 }
1709
1710 // return -1 to signal caller NOT to apply offset
1711 return rerror ? (ptrdiff_t)offset : 0;
1712 }
1713
1714 offset = gInterpreter->ClassInfo_GetBaseOffset(
1715 cd->GetClassInfo(), cb->GetClassInfo(), (void*)address, direction > 0);
1716 if (offset == -1) // Cling error, treat silently
1717 return rerror ? (ptrdiff_t)offset : 0;
1718
1719 return (ptrdiff_t)(direction < 0 ? -offset : offset);
1720}
1721
1722
1723// method/function reflection information ------------------------------------
1725{
1727 return (TCppIndex_t)0; // enforce lazy
1728
1729 if (scope == GLOBAL_HANDLE)
1730 return gROOT->GetListOfGlobalFunctions(true)->GetSize();
1731
1733 if (cr.GetClass() && cr->GetListOfMethods(true)) {
1734 Cppyy::TCppIndex_t nMethods = (TCppIndex_t)cr->GetListOfMethods(false)->GetSize();
1735 if (nMethods == (TCppIndex_t)0) {
1736 std::string clName = GetScopedFinalName(scope);
1737 if (clName.find('<') != std::string::npos) {
1738 // chicken-and-egg problem: TClass does not know about methods until
1739 // instantiation, so force it
1740 std::ostringstream stmt;
1741 stmt << "template class " << clName << ";";
1742 gInterpreter->Declare(stmt.str().c_str()/*, silent = true*/);
1743
1744 // now reload the methods
1745 return (TCppIndex_t)cr->GetListOfMethods(true)->GetSize();
1746 }
1747 }
1748 return nMethods;
1749 }
1750
1751 return (TCppIndex_t)0; // unknown class?
1752}
1753
1754std::vector<Cppyy::TCppIndex_t> Cppyy::GetMethodIndicesFromName(
1755 TCppScope_t scope, const std::string& name)
1756{
1757 std::vector<TCppIndex_t> indices;
1759 if (cr.GetClass()) {
1760 gInterpreter->UpdateListOfMethods(cr.GetClass());
1761 int imeth = 0;
1762 TFunction* func = nullptr;
1763 TIter next(cr->GetListOfMethods());
1764 while ((func = (TFunction*)next())) {
1765 if (match_name(name, func->GetName())) {
1766 // C++ functions should be public to allow access; C functions have no access
1767 // specifier and should always be accepted
1768 auto prop = func->Property();
1769 if ((prop & kIsPublic) || !(prop & (kIsPrivate | kIsProtected | kIsPublic)))
1770 indices.push_back((TCppIndex_t)imeth);
1771 }
1772 ++imeth;
1773 }
1774 } else if (scope == GLOBAL_HANDLE) {
1775 TCollection* funcs = gROOT->GetListOfGlobalFunctions(true);
1776
1777 // tickle deserialization
1778 if (!funcs->FindObject(name.c_str()))
1779 return indices;
1780
1781 TFunction* func = nullptr;
1782 TIter ifunc(funcs);
1783 while ((func = (TFunction*)ifunc.Next())) {
1784 if (match_name(name, func->GetName()))
1785 indices.push_back((TCppIndex_t)new_CallWrapper(func));
1786 }
1787 }
1788
1789 return indices;
1790}
1791
1793{
1795 if (cr.GetClass()) {
1796 TFunction* f = (TFunction*)cr->GetListOfMethods(false)->At((int)idx);
1797 if (f) return (Cppyy::TCppMethod_t)new_CallWrapper(f);
1798 return (Cppyy::TCppMethod_t)nullptr;
1799 }
1800
1802 return (Cppyy::TCppMethod_t)idx;
1803}
1804
1806{
1807 if (method) {
1808 const std::string& name = ((CallWrapper*)method)->fName;
1809
1810 if (name.compare(0, 8, "operator") != 0)
1811 // strip template instantiation part, if any
1812 return name.substr(0, name.find('<'));
1813 return name;
1814 }
1815 return "<unknown>";
1816}
1817
1819{
1820 if (method) {
1821 std::string name = ((CallWrapper*)method)->fName;
1822 name.erase(std::remove(name.begin(), name.end(), ' '), name.end());
1823 return name;
1824 }
1825 return "<unknown>";
1826}
1827
1829{
1830 if (method)
1831 return m2f(method)->GetMangledName();
1832 return "<unknown>";
1833}
1834
1836{
1837 if (method) {
1838 TFunction* f = m2f(method);
1839 if (f->ExtraProperty() & kIsConstructor)
1840 return "constructor";
1841 std::string restype = f->GetReturnTypeName();
1842 // TODO: this is ugly; GetReturnTypeName() keeps typedefs, but may miss scopes
1843 // for some reason; GetReturnTypeNormalizedName() has been modified to return
1844 // the canonical type to guarantee correct namespaces. Sometimes typedefs look
1845 // better, sometimes not, sometimes it's debatable (e.g. vector<int>::size_type).
1846 // So, for correctness sake, GetReturnTypeNormalizedName() is used, except for a
1847 // special case of uint8_t/int8_t that must propagate as their typedefs.
1848 if (restype.find("int8_t") != std::string::npos)
1849 return restype;
1850 restype = f->GetReturnTypeNormalizedName();
1851 if (restype == "(lambda)") {
1852 std::ostringstream s;
1853 // TODO: what if there are parameters to the lambda?
1854 s << "__cling_internal::FT<decltype("
1855 << GetMethodFullName(method) << "(";
1856 for (Cppyy::TCppIndex_t i = 0; i < Cppyy::GetMethodNumArgs(method); ++i) {
1857 if (i != 0) s << ", ";
1858 s << Cppyy::GetMethodArgType(method, i) << "{}";
1859 }
1860 s << "))>::F";
1861 TClass* cl = TClass::GetClass(s.str().c_str());
1862 if (cl) return cl->GetName();
1863 // TODO: signal some type of error (or should that be upstream?
1864 }
1865 return restype;
1866 }
1867 return "<unknown>";
1868}
1869
1871{
1872 if (method)
1873 return m2f(method)->GetNargs();
1874 return 0;
1875}
1876
1878{
1879 if (method) {
1880 TFunction* f = m2f(method);
1881 return (TCppIndex_t)(f->GetNargs() - f->GetNargsOpt());
1882 }
1883 return (TCppIndex_t)0;
1884}
1885
1887{
1888 if (method) {
1889 TFunction* f = m2f(method);
1890 TMethodArg* arg = (TMethodArg*)f->GetListOfMethodArgs()->At((int)iarg);
1891 return arg->GetName();
1892 }
1893 return "<unknown>";
1894}
1895
1897{
1898 if (method) {
1899 TFunction* f = m2f(method);
1900 TMethodArg* arg = (TMethodArg*)f->GetListOfMethodArgs()->At((int)iarg);
1901 std::string ft = arg->GetFullTypeName();
1902 if (ft.rfind("enum ", 0) != std::string::npos) { // special case to preserve 'enum' tag
1903 std::string arg_type = arg->GetTypeNormalizedName();
1904 return arg_type.insert(arg_type.rfind("const ", 0) == std::string::npos ? 0 : 6, "enum ");
1905 } else if (g_builtins.find(ft) != g_builtins.end() || ft.find("int8_t") != std::string::npos)
1906 return ft; // do not resolve int8_t and uint8_t typedefs
1907
1908 return arg->GetTypeNormalizedName();
1909 }
1910 return "<unknown>";
1911}
1912
1914{
1915 if (method) {
1916 TFunction* f = m2f(method);
1917 TMethodArg* arg = (TMethodArg *)f->GetListOfMethodArgs()->At((int)iarg);
1918 void *argqtp = gInterpreter->TypeInfo_QualTypePtr(arg->GetTypeInfo());
1919
1920 TypeInfo_t *reqti = gInterpreter->TypeInfo_Factory(req_type.c_str());
1921 void *reqqtp = gInterpreter->TypeInfo_QualTypePtr(reqti);
1922
1923 // This scoring is not based on any particular rules
1924 if (gInterpreter->IsSameType(argqtp, reqqtp))
1925 return 0; // Best match
1926 else if ((gInterpreter->IsSignedIntegerType(argqtp) && gInterpreter->IsSignedIntegerType(reqqtp)) ||
1927 (gInterpreter->IsUnsignedIntegerType(argqtp) && gInterpreter->IsUnsignedIntegerType(reqqtp)) ||
1928 (gInterpreter->IsFloatingType(argqtp) && gInterpreter->IsFloatingType(reqqtp)))
1929 return 1;
1930 else if ((gInterpreter->IsSignedIntegerType(argqtp) && gInterpreter->IsUnsignedIntegerType(reqqtp)) ||
1931 (gInterpreter->IsFloatingType(argqtp) && gInterpreter->IsUnsignedIntegerType(reqqtp)))
1932 return 2;
1933 else if ((gInterpreter->IsIntegerType(argqtp) && gInterpreter->IsIntegerType(reqqtp)))
1934 return 3;
1935 else if ((gInterpreter->IsVoidPointerType(argqtp) && gInterpreter->IsPointerType(reqqtp)))
1936 return 4;
1937 else
1938 return 10; // Penalize heavily for no possible match
1939 }
1940 return INT_MAX; // Method is not valid
1941}
1942
1944{
1945 if (method) {
1946 TFunction* f = m2f(method);
1947 TMethodArg* arg = (TMethodArg*)f->GetListOfMethodArgs()->At((int)iarg);
1948 const char* def = arg->GetDefault();
1949 if (def)
1950 return def;
1951 }
1952
1953 return "";
1954}
1955
1957{
1958 TFunction* f = m2f(method);
1959 if (f) {
1960 std::ostringstream sig;
1961 sig << "(";
1962 int nArgs = f->GetNargs();
1963 if (maxargs != (TCppIndex_t)-1) nArgs = std::min(nArgs, (int)maxargs);
1964 for (int iarg = 0; iarg < nArgs; ++iarg) {
1965 TMethodArg* arg = (TMethodArg*)f->GetListOfMethodArgs()->At(iarg);
1966 sig << arg->GetFullTypeName();
1967 if (show_formalargs) {
1968 const char* argname = arg->GetName();
1969 if (argname && argname[0] != '\0') sig << " " << argname;
1970 const char* defvalue = arg->GetDefault();
1971 if (defvalue && defvalue[0] != '\0') sig << " = " << defvalue;
1972 }
1973 if (iarg != nArgs-1) sig << (show_formalargs ? ", " : ",");
1974 }
1975 sig << ")";
1976 return sig.str();
1977 }
1978 return "<unknown>";
1979}
1980
1982{
1983 std::string scName = GetScopedFinalName(scope);
1984 TFunction* f = m2f(method);
1985 if (f) {
1986 std::ostringstream sig;
1987 sig << f->GetReturnTypeName() << " "
1988 << scName << "::" << f->GetName();
1990 return sig.str();
1991 }
1992 return "<unknown>";
1993}
1994
1996{
1997 if (method) {
1998 TFunction* f = m2f(method);
1999 return f->Property() & kIsConstMethod;
2000 }
2001 return false;
2002}
2003
2005{
2007 return (TCppIndex_t)0; // enforce lazy
2008
2009 if (scope == GLOBAL_HANDLE) {
2010 TCollection* coll = gROOT->GetListOfFunctionTemplates();
2011 if (coll) return (TCppIndex_t)coll->GetSize();
2012 } else {
2014 if (cr.GetClass()) {
2015 TCollection* coll = cr->GetListOfFunctionTemplates(true);
2016 if (coll) return (TCppIndex_t)coll->GetSize();
2017 }
2018 }
2019
2020// failure ...
2021 return (TCppIndex_t)0;
2022}
2023
2025{
2027 return ((THashList*)gROOT->GetListOfFunctionTemplates())->At((int)imeth)->GetName();
2028 else {
2030 if (cr.GetClass())
2031 return cr->GetListOfFunctionTemplates(false)->At((int)imeth)->GetName();
2032 }
2033
2034// failure ...
2035 assert(!"should not be called unless GetNumTemplatedMethods() succeeded");
2036 return "";
2037}
2038
2040{
2042 return false;
2043
2045 if (cr.GetClass()) {
2046 TFunctionTemplate* f = (TFunctionTemplate*)cr->GetListOfFunctionTemplates(false)->At((int)imeth);
2047 return f->ExtraProperty() & kIsConstructor;
2048 }
2049
2050 return false;
2051}
2052
2054{
2056 return (bool)gROOT->GetFunctionTemplate(name.c_str());
2057 else {
2059 if (cr.GetClass())
2060 return (bool)cr->GetFunctionTemplate(name.c_str());
2061 }
2062
2063// failure ...
2064 return false;
2065}
2066
2068{
2069 TFunctionTemplate* tf = nullptr;
2071 tf = gROOT->GetFunctionTemplate(name.c_str());
2072 else {
2074 if (cr.GetClass())
2075 tf = cr->GetFunctionTemplate(name.c_str());
2076 }
2077
2078 if (!tf) return false;
2079
2080 return (bool)(tf->Property() & kIsStatic);
2081}
2082
2084{
2086 if (cr.GetClass()) {
2087 TFunction* f = (TFunction*)cr->GetListOfMethods(false)->At((int)idx);
2088 if (f && strstr(f->GetName(), "<")) return true;
2089 return false;
2090 }
2091
2093 if (((CallWrapper*)idx)->fName.find('<') != std::string::npos) return true;
2094 return false;
2095}
2096
2097// helpers for Cppyy::GetMethodTemplate()
2098static std::map<TDictionary::DeclId_t, CallWrapper*> gMethodTemplates;
2099
2100static inline
2101void remove_space(std::string& n) {
2102 std::string::iterator pos = std::remove_if(n.begin(), n.end(), isspace);
2103 n.erase(pos, n.end());
2104}
2105
2106static inline
2107bool template_compare(std::string n1, std::string n2) {
2108 if (n1.back() == '>') n1 = n1.substr(0, n1.size()-1);
2111 return n2.compare(0, n1.size(), n1) == 0;
2112}
2113
2115 TCppScope_t scope, const std::string& name, const std::string& proto)
2116{
2117// There is currently no clean way of extracting a templated method out of ROOT/meta
2118// for a variety of reasons, none of them fundamental. The game played below is to
2119// first get any pre-existing functions already managed by ROOT/meta, but if that fails,
2120// to do an explicit lookup that ignores the prototype (i.e. the full name should be
2121// enough), and finally to ignore the template arguments part of the name as this fails
2122// in cling if there are default parameters.
2123 TFunction* func = nullptr; ClassInfo_t* cl = nullptr;
2125 func = gROOT->GetGlobalFunctionWithPrototype(name.c_str(), proto.c_str());
2126 if (func && name.back() == '>') {
2127 // make sure that all template parameters match (more are okay, e.g. defaults or
2128 // ones derived from the arguments or variadic templates)
2129 if (!template_compare(name, func->GetName()))
2130 func = nullptr; // happens if implicit conversion matches the overload
2131 }
2132 } else {
2134 if (cr.GetClass()) {
2135 func = cr->GetMethodWithPrototype(name.c_str(), proto.c_str());
2136 if (!func) {
2137 cl = cr->GetClassInfo();
2138 // try base classes to cover a common 'using' case (TODO: this is stupid and misses
2139 // out on base classes; fix that with improved access to Cling)
2141 for (TCppIndex_t i = 0; i < nbases; ++i) {
2143 if (base.GetClass()) {
2144 func = base->GetMethodWithPrototype(name.c_str(), proto.c_str());
2145 if (func) break;
2146 }
2147 }
2148 }
2149 }
2150 }
2151
2152 if (!func && name.back() == '>' && (cl || scope == (TCppScope_t)GLOBAL_HANDLE)) {
2153 // try again, ignoring proto in case full name is complete template
2154 auto declid = gInterpreter->GetFunction(cl, name.c_str());
2155 if (declid) {
2156 auto existing = gMethodTemplates.find(declid);
2157 if (existing == gMethodTemplates.end()) {
2158 auto cw = new_CallWrapper(declid, name);
2159 existing = gMethodTemplates.insert(std::make_pair(declid, cw)).first;
2160 }
2161 return (TCppMethod_t)existing->second;
2162 }
2163 }
2164
2165 if (func) {
2166 // make sure we didn't match a non-templated overload
2167 if (func->ExtraProperty() & kIsTemplateSpec)
2168 return (TCppMethod_t)new_CallWrapper(func);
2169
2170 // disregard this non-templated method as it will be considered when appropriate
2171 return (TCppMethod_t)nullptr;
2172 }
2173
2174// try again with template arguments removed from name, if applicable
2175 if (name.back() == '>') {
2176 auto pos = name.find('<');
2177 if (pos != std::string::npos) {
2179 if (cppmeth) {
2180 // allow if requested template names match up to the result
2181 const std::string& alt = GetMethodFullName(cppmeth);
2182 if (name.size() < alt.size() && alt.find('<') == pos) {
2184 return cppmeth;
2185 }
2186 }
2187 }
2188 }
2189
2190// failure ...
2191 return (TCppMethod_t)nullptr;
2192}
2193
2194static inline
2195std::string type_remap(const std::string& n1, const std::string& n2)
2196{
2197// Operator lookups of (C++ string, Python str) should succeed for the combos of
2198// string/str, wstring/str, string/unicode and wstring/unicode; since C++ does not have a
2199// operator+(std::string, std::wstring), we'll have to look up the same type and rely on
2200// the converters in CPyCppyy/_cppyy.
2201 if (n1 == "str" || n1 == "unicode") {
2202 if (n2 == "std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >")
2203 return n2; // match like for like
2204 return "std::string"; // probably best bet
2205 } else if (n1 == "float") {
2206 return "double"; // debatable, but probably intended
2207 } else if (n1 == "complex") {
2208 return "std::complex<double>";
2209 }
2210 return n1;
2211}
2212
2214 TCppType_t scope, const std::string& lc, const std::string& rc, const std::string& opname)
2215{
2216// Find a global operator function with a matching signature; prefer by-ref, but
2217// fall back on by-value if that fails.
2218 std::string lcname1 = TClassEdit::CleanType(lc.c_str());
2219 const std::string& rcname = rc.empty() ? rc : type_remap(TClassEdit::CleanType(rc.c_str()), lcname1);
2220 const std::string& lcname = type_remap(lcname1, rcname);
2221
2222 std::string proto = lcname + "&" + (rc.empty() ? rc : (", " + rcname + "&"));
2224 TFunction* func = gROOT->GetGlobalFunctionWithPrototype(opname.c_str(), proto.c_str());
2225 if (func) return (TCppIndex_t)new_CallWrapper(func);
2226 proto = lcname + (rc.empty() ? rc : (", " + rcname));
2227 func = gROOT->GetGlobalFunctionWithPrototype(opname.c_str(), proto.c_str());
2228 if (func) return (TCppIndex_t)new_CallWrapper(func);
2229 } else {
2231 if (cr.GetClass()) {
2232 TFunction* func = cr->GetMethodWithPrototype(opname.c_str(), proto.c_str());
2233 if (func) return (TCppIndex_t)cr->GetListOfMethods()->IndexOf(func);
2234 proto = lcname + (rc.empty() ? rc : (", " + rcname));
2235 func = cr->GetMethodWithPrototype(opname.c_str(), proto.c_str());
2236 if (func) return (TCppIndex_t)cr->GetListOfMethods()->IndexOf(func);
2237 }
2238 }
2239
2240// failure ...
2241 return (TCppIndex_t)-1;
2242}
2243
2244// method properties ---------------------------------------------------------
2245
2247{
2248 if (!method)
2249 return false;
2250 TFunction *f = m2f(method);
2251 return f->Property() & prop;
2252}
2253
2255{
2256 if (!method)
2257 return false;
2258 TFunction *f = m2f(method);
2259 return f->ExtraProperty() & prop;
2260}
2261
2266
2271
2276
2281
2286
2291
2292// data member reflection information ----------------------------------------
2294{
2296 return (TCppIndex_t)0; // enforce lazy
2297
2298 if (scope == GLOBAL_HANDLE)
2299 return gROOT->GetListOfGlobals(true)->GetSize();
2300
2302 if (cr.GetClass() && cr->GetListOfDataMembers())
2303 return cr->GetListOfDataMembers()->GetSize();
2304
2305 return (TCppIndex_t)0; // unknown class?
2306}
2307
2309{
2311 if (cr.GetClass()) {
2312 TDataMember* m = (TDataMember*)cr->GetListOfDataMembers()->At((int)idata);
2313 return m->GetName();
2314 }
2317 return gbl->GetName();
2318}
2319
2320static inline
2321int count_scopes(const std::string& tpname)
2322{
2323 int count = 0;
2324 std::string::size_type pos = tpname.find("::", 0);
2325 while (pos != std::string::npos) {
2326 count++;
2327 pos = tpname.find("::", pos+1);
2328 }
2329 return count;
2330}
2331
2333{
2334 if (scope == GLOBAL_HANDLE) {
2336 std::string fullType = gbl->GetFullTypeName();
2337
2338 if ((int)gbl->GetArrayDim()) {
2339 std::ostringstream s;
2340 for (int i = 0; i < (int)gbl->GetArrayDim(); ++i)
2341 s << '[' << gbl->GetMaxIndex(i) << ']';
2342 fullType.append(s.str());
2343 }
2344 return fullType;
2345 }
2346
2348 if (cr.GetClass()) {
2349 TDataMember* m = (TDataMember*)cr->GetListOfDataMembers()->At((int)idata);
2350 // TODO: fix this upstream ... Usually, we want m->GetFullTypeName(), because it
2351 // does not resolve typedefs, but it looses scopes for inner classes/structs, it
2352 // doesn't resolve constexpr (leaving unresolved names), leaves spurious "struct"
2353 // or "union" in the name, and can not handle anonymous unions. In that case
2354 // m->GetTrueTypeName() should be used. W/o clear criteria to determine all these
2355 // cases, the general rules are to prefer the true name if the full type does not
2356 // exist as a type for classes, and the most scoped name otherwise.
2357 const char* ft = m->GetFullTypeName(); std::string fullType = ft ? ft : "";
2358 const char* tn = m->GetTrueTypeName(); std::string trueName = tn ? tn : "";
2359 if (!trueName.empty() && fullType != trueName && !IsBuiltin(trueName)) {
2360 if ( (!TClass::GetClass(fullType.c_str()) && TClass::GetClass(trueName.c_str())) || \
2362 bool is_enum_tag = fullType.rfind("enum ", 0) != std::string::npos;
2364 if (is_enum_tag)
2365 fullType.insert(fullType.rfind("const ", 0) == std::string::npos ? 0 : 6, "enum ");
2366 }
2367 }
2368
2369 if ((int)m->GetArrayDim()) {
2370 std::ostringstream s;
2371 for (int i = 0; i < (int)m->GetArrayDim(); ++i)
2372 s << '[' << m->GetMaxIndex(i) << ']';
2373 fullType.append(s.str());
2374 }
2375
2376#if 0
2377 // this is the only place where anonymous structs are uniquely identified, so setup
2378 // a class if needed, such that subsequent GetScope() and GetScopedFinalName() calls
2379 // return the uniquely named class
2380 auto declid = m->GetTagDeclId(); //GetDeclId();
2381 if (declid && (m->Property() & (kIsClass | kIsStruct | kIsUnion)) &&\
2382 (fullType.find("(anonymous)") != std::string::npos || fullType.find("(unnamed)") != std::string::npos)) {
2383
2384 // use the (fixed) decl id address to guarantee a unique name, even when there
2385 // are multiple anonymous structs in the parent scope
2386 std::ostringstream fulls;
2387 fulls << fullType << "@" << (void*)declid;
2388 fullType = fulls.str();
2389
2391 ClassInfo_t* ci = gInterpreter->ClassInfo_Factory(declid);
2392 TClass* cl = gInterpreter->GenerateTClass(ci, kTRUE /* silent */);
2393 gInterpreter->ClassInfo_Delete(ci);
2394 if (cl) cl->SetName(fullType.c_str());
2396 g_classrefs.emplace_back(cl);
2397 }
2398 }
2399#endif
2400 return fullType;
2401 }
2402
2403 return "<unknown>";
2404}
2405
2407{
2408 if (scope == GLOBAL_HANDLE) {
2410 if (!gbl->GetAddress() || gbl->GetAddress() == (void*)-1) {
2411 // CLING WORKAROUND: make sure variable is loaded
2412 intptr_t addr = (intptr_t)gInterpreter->ProcessLine((std::string("&")+gbl->GetName()+";").c_str());
2413 if (gbl->GetAddress() && gbl->GetAddress() != (void*)-1)
2414 return (intptr_t)gbl->GetAddress(); // now loaded!
2415 return addr; // last resort ...
2416 }
2417 return (intptr_t)gbl->GetAddress();
2418 }
2419
2421 if (cr.GetClass()) {
2422 TDataMember* m = (TDataMember*)cr->GetListOfDataMembers()->At((int)idata);
2423 // CLING WORKAROUND: the following causes templates to be instantiated first within the proper
2424 // scope, making the lookup succeed and preventing spurious duplicate instantiations later. Also,
2425 // if the variable is not yet loaded, pull it in through gInterpreter.
2426 intptr_t offset = (intptr_t)-1;
2427 if (m->Property() & kIsStatic) {
2428 if (strchr(cr->GetName(), '<'))
2429 gInterpreter->ProcessLine(((std::string)cr->GetName()+"::"+m->GetName()+";").c_str());
2430 offset = (intptr_t)m->GetOffsetCint(); // yes, CINT (GetOffset() is both wrong
2431 // and caches that wrong result!
2432 if (offset == (intptr_t)-1)
2433 return (intptr_t)gInterpreter->ProcessLine((std::string("&")+cr->GetName()+"::"+m->GetName()+";").c_str());
2434 } else
2435 offset = (intptr_t)m->GetOffsetCint(); // yes, CINT, see above
2436 return offset;
2437 }
2438
2439 return (intptr_t)-1;
2440}
2441
2442static inline
2444{
2445 if (!gb) return (Cppyy::TCppIndex_t)-1;
2446
2447 auto pidx = g_globalidx.find(gb);
2448 if (pidx == g_globalidx.end()) {
2449 auto idx = g_globalvars.size();
2450 g_globalvars.push_back(gb);
2451 g_globalidx[gb] = idx;
2452 return (Cppyy::TCppIndex_t)idx;
2453 }
2454 return (Cppyy::TCppIndex_t)pidx->second;
2455}
2456
2458{
2459 if (scope == GLOBAL_HANDLE) {
2460 TGlobal* gb = (TGlobal*)gROOT->GetListOfGlobals(false /* load */)->FindObject(name.c_str());
2461 if (!gb) gb = (TGlobal*)gROOT->GetListOfGlobals(true /* load */)->FindObject(name.c_str());
2462 if (!gb) {
2463 // some enums are not loaded as they are not considered part of
2464 // the global scope, but of the enum scope; get them w/o checking
2465 TDictionary::DeclId_t did = gInterpreter->GetDataMember(nullptr, name.c_str());
2466 if (did) {
2467 DataMemberInfo_t* t = gInterpreter->DataMemberInfo_Factory(did, nullptr);
2468 ((TListOfDataMembers*)gROOT->GetListOfGlobals())->Get(t, true);
2469 gb = (TGlobal*)gROOT->GetListOfGlobals(false /* load */)->FindObject(name.c_str());
2470 }
2471 }
2472
2473 if (gb && strcmp(gb->GetFullTypeName(), "(lambda)") == 0) {
2474 // lambdas use a compiler internal closure type, so we wrap
2475 // them, then return the wrapper's type
2476 // TODO: this current leaks the std::function; also, if possible,
2477 // should instantiate through TClass rather then ProcessLine
2478 std::ostringstream s;
2479 s << "auto __cppyy_internal_wrap_" << name << " = "
2480 "new __cling_internal::FT<decltype(" << name << ")>::F"
2481 "{" << name << "};";
2482 gInterpreter->ProcessLine(s.str().c_str());
2483 TGlobal* wrap = (TGlobal*)gROOT->GetListOfGlobals(true)->FindObject(
2484 ("__cppyy_internal_wrap_"+name).c_str());
2485 if (wrap && wrap->GetAddress()) gb = wrap;
2486 }
2487
2488 return gb2idx(gb);
2489
2490 } else {
2492 if (cr.GetClass()) {
2493 TDataMember* dm =
2494 (TDataMember*)cr->GetListOfDataMembers()->FindObject(name.c_str());
2495 // TODO: turning this into an index is silly ...
2496 if (dm) return (TCppIndex_t)cr->GetListOfDataMembers()->IndexOf(dm);
2497 }
2498 }
2499
2500 return (TCppIndex_t)-1;
2501}
2502
2504{
2505 if (scope == GLOBAL_HANDLE) {
2506 TGlobal* gb = (TGlobal*)((THashList*)gROOT->GetListOfGlobals(false /* load */))->At((int)idata);
2507 return gb2idx(gb);
2508 }
2509
2510 return idata;
2511}
2512
2513
2514// data member properties ----------------------------------------------------
2516{
2517 if (scope == GLOBAL_HANDLE)
2518 return true;
2520 if (cr->Property() & kIsNamespace)
2521 return true;
2522 TDataMember* m = (TDataMember*)cr->GetListOfDataMembers()->At((int)idata);
2523 return m->Property() & kIsPublic;
2524}
2525
2527{
2528 if (scope == GLOBAL_HANDLE)
2529 return true;
2531 if (cr->Property() & kIsNamespace)
2532 return true;
2533 TDataMember* m = (TDataMember*)cr->GetListOfDataMembers()->At((int)idata);
2534 return m->Property() & kIsProtected;
2535}
2536
2538{
2539 if (scope == GLOBAL_HANDLE)
2540 return true;
2542 if (cr->Property() & kIsNamespace)
2543 return true;
2544 TDataMember* m = (TDataMember*)cr->GetListOfDataMembers()->At((int)idata);
2545 return m->Property() & kIsStatic;
2546}
2547
2549{
2550 Long_t property = 0;
2551 if (scope == GLOBAL_HANDLE) {
2553 property = gbl->Property();
2554 }
2556 if (cr.GetClass()) {
2557 TDataMember* m = (TDataMember*)cr->GetListOfDataMembers()->At((int)idata);
2558 property = m->Property();
2559 }
2560
2561// if the data type is const, but the data member is a pointer/array, the data member
2562// itself is not const; alternatively it is a pointer that is constant
2564}
2565
2567{
2568// TODO: currently, ROOT/meta does not properly distinguish between variables of enum
2569// type, and values of enums. The latter are supposed to be const. This code relies on
2570// odd features (bugs?) to figure out the difference, but this should really be fixed
2571// upstream and/or deserves a new API.
2572
2573 if (scope == GLOBAL_HANDLE) {
2575
2576 // make use of an oddity: enum global variables do not have their kIsStatic bit
2577 // set, whereas enum global values do
2578 return (gbl->Property() & kIsEnum) && (gbl->Property() & kIsStatic);
2579 }
2580
2582 if (cr.GetClass()) {
2583 TDataMember* m = (TDataMember*)cr->GetListOfDataMembers()->At((int)idata);
2584 std::string ti = m->GetTypeName();
2585
2586 // can't check anonymous enums by type name, so just accept them as enums
2587 if (ti.rfind("(anonymous)") != std::string::npos || ti.rfind("(unnamed)") != std::string::npos)
2588 return m->Property() & kIsEnum;
2589
2590 // since there seems to be no distinction between data of enum type and enum values,
2591 // check the list of constants for the type to see if there's a match
2592 if (ti.rfind(cr->GetName(), 0) != std::string::npos) {
2593 std::string::size_type s = strlen(cr->GetName())+2;
2594 if (s < ti.size()) {
2595 TEnum* ee = ((TListOfEnums*)cr->GetListOfEnums())->GetObject(ti.substr(s, std::string::npos).c_str());
2596 if (ee) return ee->GetConstant(m->GetName());
2597 }
2598 }
2599 }
2600
2601// this default return only means that the data will be writable, not that it will
2602// be unreadable or otherwise misrepresented
2603 return false;
2604}
2605
2607{
2608 if (scope == GLOBAL_HANDLE) {
2610 return gbl->GetMaxIndex(dimension);
2611 }
2613 if (cr.GetClass()) {
2614 TDataMember* m = (TDataMember*)cr->GetListOfDataMembers()->At((int)idata);
2615 return m->GetMaxIndex(dimension);
2616 }
2617 return -1;
2618}
2619
2620
2621// enum properties -----------------------------------------------------------
2623{
2624 if (scope == GLOBAL_HANDLE)
2625 return (TCppEnum_t)gROOT->GetListOfEnums(kTRUE)->FindObject(enum_name.c_str());
2626
2628 if (cr.GetClass())
2629 return (TCppEnum_t)cr->GetListOfEnums(kTRUE)->FindObject(enum_name.c_str());
2630
2631 return (TCppEnum_t)0;
2632}
2633
2635{
2636 return (TCppIndex_t)((TEnum*)etype)->GetConstants()->GetSize();
2637}
2638
2640{
2641 return ((TEnumConstant*)((TEnum*)etype)->GetConstants()->At((int)idata))->GetName();
2642}
2643
2645{
2646 TEnumConstant* ecst = (TEnumConstant*)((TEnum*)etype)->GetConstants()->At((int)idata);
2647 return (long long)ecst->GetValue();
2648}
2649
2650
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
static Roo_reg_AGKInteg1D instance
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:68
long double LongDouble_t
Long Double (not portable)
Definition RtypesCore.h:75
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:83
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
@ kMAXSIGNALS
Definition Rtypes.h:60
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
EFunctionProperty
@ kIsDestructor
@ kIsTemplateSpec
@ kIsConstructor
@ kClassIsAggregate
@ kClassHasVirtual
@ kClassHasExplicitDtor
@ kClassHasImplicitDtor
EProperty
Definition TDictionary.h:64
@ kIsPublic
Definition TDictionary.h:75
@ kIsPointer
Definition TDictionary.h:78
@ kIsConstant
Definition TDictionary.h:88
@ kIsConstMethod
Definition TDictionary.h:96
@ kIsClass
Definition TDictionary.h:65
@ kIsEnum
Definition TDictionary.h:68
@ kIsPrivate
Definition TDictionary.h:77
@ kIsConstPointer
Definition TDictionary.h:90
@ kIsFundamental
Definition TDictionary.h:70
@ kIsAbstract
Definition TDictionary.h:71
@ kIsArray
Definition TDictionary.h:79
@ kIsStatic
Definition TDictionary.h:80
@ kIsExplicit
Definition TDictionary.h:94
@ kIsStruct
Definition TDictionary.h:66
@ kIsProtected
Definition TDictionary.h:76
@ kIsVirtual
Definition TDictionary.h:72
@ kIsUnion
Definition TDictionary.h:67
@ kIsNamespace
Definition TDictionary.h:95
@ kIsVirtualBase
Definition TDictionary.h:89
constexpr Int_t kFatal
Definition TError.h:50
Int_t gErrorIgnoreLevel
errors with level below this value will be ignored. Default is kUnset.
Definition TError.cxx:33
R__EXTERN TExceptionHandler * gExceptionHandler
Definition TException.h:79
R__EXTERN ExceptionContext_t * gException
Definition TException.h:69
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.
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 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 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 prop
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 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
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 property
char name[80]
Definition TGX11.cxx:110
#define gInterpreter
#define gROOT
Definition TROOT.h:411
R__EXTERN TSystem * gSystem
Definition TSystem.h:572
static struct Signalmap_t gSignalMap[kMAXSIGNALS]
const char * proto
Definition civetweb.c:18822
#define free
Definition civetweb.c:1578
#define malloc
Definition civetweb.c:1575
const_iterator begin() const
const_iterator end() const
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:29
TClass * GetClass() const
Definition TClassRef.h:67
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
TList * GetListOfUsingDataMembers(Bool_t load=kTRUE)
Return list containing the TDataMembers of using declarations of a class.
Definition TClass.cxx:3813
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
Definition TClass.cxx:5017
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:4438
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:4483
void Destructor(void *obj, Bool_t dtorOnly=kFALSE)
Explicitly call destructor for object.
Definition TClass.cxx:5439
TList * GetListOfFunctionTemplates(Bool_t load=kTRUE)
Return TListOfFunctionTemplates for a class.
Definition TClass.cxx:3825
TList * GetListOfEnums(Bool_t load=kTRUE)
Return a list containing the TEnums of a class.
Definition TClass.cxx:3713
TList * GetListOfMethods(Bool_t load=kTRUE)
Return list containing the TMethods of a class.
Definition TClass.cxx:3839
TList * GetListOfDataMembers(Bool_t load=kTRUE)
Return list containing the TDataMembers of a class.
Definition TClass.cxx:3797
@ kRealNew
Definition TClass.h:110
TList * GetListOfBases()
Return list containing the TBaseClass(es) of a class.
Definition TClass.cxx:3663
Bool_t IsLoaded() const
Return true if the shared library of this class is currently in the a process's memory.
Definition TClass.cxx:5954
ClassInfo_t * GetClassInfo() const
Definition TClass.h:445
Long_t ClassProperty() const
Return the C++ property of this class, eg.
Definition TClass.cxx:2401
Long_t Property() const override
Returns the properties of the TClass as a bit field stored as a Long_t value.
Definition TClass.cxx:6128
Bool_t HasDefaultConstructor(Bool_t testio=kFALSE) const
Return true if we have access to a constructor usable for I/O.
Definition TClass.cxx:7490
TMethod * GetMethodAllAny(const char *method)
Return pointer to method without looking at parameters.
Definition TClass.cxx:4411
ROOT::DelFunc_t GetDelete() const
Return the wrapper around delete ThisObject.
Definition TClass.cxx:7568
TClass * GetActualClass(const void *object) const
Return a pointer to the real class of the object.
Definition TClass.cxx:2612
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:2973
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
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.
The TEnum class implements the enum type.
Definition TEnum.h:33
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
Dictionary for function template This class describes one single function template.
Global functions class (global functions are obtained from CINT).
Definition TFunction.h:30
Long_t Property() const override
Get property description word. For meaning of bits see EProperty.
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
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition THashList.h:34
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 * At(Int_t idx) const override
Returns the object at position idx. Returns 0 if idx is out of range.
Definition TList.cxx:354
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:49
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:149
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:457
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
Definition TObject.cxx:421
static Bool_t Initialized()
Return kTRUE if the TROOT object has been initialized.
Definition TROOT.cxx:2915
virtual void Exit(int code, Bool_t mode=kTRUE)
Exit the application.
Definition TSystem.cxx:725
virtual void StackTrace()
Print a stack trace.
Definition TSystem.cxx:743
static void cond_add(Cppyy::TCppScope_t scope, const std::string &ns_scope, std::set< std::string > &cppnames, const char *name, bool nofilter=false)
static bool testMethodProperty(Cppyy::TCppMethod_t method, EProperty prop)
static Name2ClassRefIndex_t g_name2classrefidx
#define FILL_COLL(type, filter)
static void remove_space(std::string &n)
const int SMALL_ARGS_N
static std::string outer_with_template(const std::string &name)
static std::string outer_no_template(const std::string &name)
static std::string type_remap(const std::string &n1, const std::string &n2)
static std::map< Cppyy::TCppType_t, bool > sHasOperatorDelete
static std::set< std::string > gRootSOs
static bool template_compare(std::string n1, std::string n2)
static TClassRef & type_from_handle(Cppyy::TCppScope_t scope)
static bool copy_args(Parameter *args, size_t nargs, void **vargs)
static TInterpreter::CallFuncIFacePtr_t GetCallFunc(Cppyy::TCppMethod_t method)
CPyCppyy::Parameter Parameter
static bool is_missclassified_stl(const std::string &name)
std::map< std::string, ClassRefs_t::size_type > Name2ClassRefIndex_t
static const ClassRefs_t::size_type STD_HANDLE
static std::set< std::string > gSmartPtrTypes
static GlobalVars_t g_globalvars
static char * cppstring_to_cstring(const std::string &cppstr)
static void release_args(Parameter *args, size_t nargs)
static std::set< std::string > g_builtins
static std::vector< CallWrapper * > gWrapperHolder
static bool gEnableFastPath
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
static Cppyy::TCppIndex_t gb2idx(TGlobal *gb)
static size_t CALL_NARGS(size_t nargs)
static CallWrapper * new_CallWrapper(TFunction *f)
static std::set< std::string > gSTLNames
static const ClassRefs_t::size_type GLOBAL_HANDLE
static GlobalVarsIndices_t g_globalidx
static bool testMethodExtraProperty(Cppyy::TCppMethod_t method, EFunctionProperty prop)
static int count_scopes(const std::string &tpname)
std::vector< TGlobal * > GlobalVars_t
std::map< TGlobal *, GlobalVars_t::size_type > GlobalVarsIndices_t
std::vector< TClassRef > ClassRefs_t
static std::map< TDictionary::DeclId_t, CallWrapper * > gMethodTemplates
static bool match_name(const std::string &tname, const std::string fname)
static TFunction * m2f(Cppyy::TCppMethod_t method)
#define CPPYY_IMP_CALL(typecode, rtype)
static std::set< std::string > gInitialNames
static T CallT(Cppyy::TCppMethod_t method, Cppyy::TCppObject_t self, size_t nargs, void *args)
Cppyy::TCppIndex_t GetLongestInheritancePath(TClass *klass)
Retrieve number of base classes in the longest branch of the inheritance tree of the input class.
const Int_t n
Definition legend1.C:16
#define I(x, y, z)
#define H(x, y, z)
size_t TCppIndex_t
Definition cpp_cppyy.h:40
RPY_EXPORTED TCppIndex_t GetNumTemplatedMethods(TCppScope_t scope, bool accept_namespace=false)
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 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 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:38
RPY_EXPORTED void * AllocateFunctionArgs(size_t nargs)
RPY_EXPORTED bool IsDefaultConstructable(TCppType_t type)
RPY_EXPORTED bool IsTemplate(const std::string &template_name)
RPY_EXPORTED TCppIndex_t GetDatamemberIndexEnumerated(TCppScope_t scope, TCppIndex_t idata)
RPY_EXPORTED TCppIndex_t GetMethodReqArgs(TCppMethod_t)
RPY_EXPORTED bool IsEnum(const std::string &type_name)
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 TCppIndex_t GetNumDatamembers(TCppScope_t scope, bool accept_namespace=false)
RPY_EXPORTED std::string ToString(TCppType_t klass, TCppObject_t obj)
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 bool Compile(const std::string &code, bool silent=false)
RPY_EXPORTED void CallDestructor(TCppType_t type, TCppObject_t self)
RPY_EXPORTED TCppScope_t gGlobalScope
Definition cpp_cppyy.h:69
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:37
RPY_EXPORTED bool IsConstructor(TCppMethod_t method)
RPY_EXPORTED TCppIndex_t GetNumMethods(TCppScope_t scope, bool accept_namespace=false)
RPY_EXPORTED TCppObject_t Construct(TCppType_t type, void *arena=nullptr)
RPY_EXPORTED bool GetSmartPtrInfo(const std::string &, TCppType_t *raw, TCppMethod_t *deref)
RPY_EXPORTED std::string GetMethodArgName(TCppMethod_t, TCppIndex_t iarg)
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:35
RPY_EXPORTED void AddTypeReducer(const std::string &reducable, const std::string &reduced)
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:36
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 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 IsStaticTemplate(TCppScope_t scope, const std::string &name)
RPY_EXPORTED bool IsDestructor(TCppMethod_t method)
RPY_EXPORTED bool IsSmartPtr(TCppType_t type)
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:34
RPY_EXPORTED bool IsTemplatedConstructor(TCppScope_t scope, TCppIndex_t imeth)
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)
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 bool IsExplicit(TCppMethod_t method)
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:41
RPY_EXPORTED std::string GetMethodFullName(TCppMethod_t)
RPY_EXPORTED bool IsProtectedMethod(TCppMethod_t method)
RPY_EXPORTED TCppEnum_t GetEnum(TCppScope_t scope, const std::string &enum_name)
void(* DelFunc_t)(void *)
Definition Rtypes.h:117
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:255
union CPyCppyy::Parameter::Value fValue
const char * fSigName
TMarker m
Definition textangle.C:8