Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
interop_wrapper.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#include "precommondefs.h" // This defines several system feature macros and should be included before any system header.
9
10// Bindings
11#include "cppjit_interop.h"
12
13using namespace cppjit;
14#include "callcontext.h"
15
16// ROOT
17#include "TClass.h"
18#include "TInterpreter.h"
19#include "TROOT.h"
20#include "TSystem.h"
21
23
24static inline size_t CALL_NARGS(size_t nargs) { return nargs & ~DIRECT_CALL; }
25
26// Standard
27#include <algorithm> // for std::count, std::remove
28#include <array>
29#include <cassert>
30#include <csignal>
31#include <cstdlib> // for getenv
32#include <cstring>
33#include <iostream>
34#include <map>
35#include <mutex>
36#include <new>
37#include <regex>
38#include <set>
39#include <sstream>
40#include <stdexcept>
41#include <typeinfo>
42#include <vector>
43
44// Take ROOT's interpreter lock (when it exists) around every CppInterOp
45// entry point, so Python-side reflection serializes against TCling users on
46// other threads (I/O, RDataFrame workers).
47// The private recursive mutex still serializes concurrent Python-side callers
48// when ROOT thread safety is not enabled. Lock order is global-then-local; no
49// deadlock is possible since threads coming through TCling only ever take the
50// global mutex.
52public:
53 void lock() {
54 // gInterpreterMutex may get created at any point (by
55 // ROOT::EnableThreadSafety), so remember for each acquisition what was
56 // actually locked, to release exactly that in unlock().
58 if (global)
59 global->Lock();
60 fLocal.lock();
61 fGlobalLocked.push_back(global);
62 }
63
64 void unlock() {
65 TVirtualMutex* global = fGlobalLocked.back();
66 fGlobalLocked.pop_back();
67 fLocal.unlock();
68 if (global)
69 global->UnLock();
70 }
71
72private:
73 std::recursive_mutex fLocal;
74 // Lock/unlock pairs are properly nested per thread, so a per-thread stack
75 // suffices to match each unlock() to its lock().
76 static thread_local std::vector<TVirtualMutex*> fGlobalLocked;
77};
78
79thread_local std::vector<TVirtualMutex*> RInterOpMutex::fGlobalLocked;
80
82
83// builtin types
84static std::set<std::string> g_builtins = {"bool",
85 "char",
86 "signed char",
87 "unsigned char",
88 "wchar_t",
89 "short",
90 "unsigned short",
91 "int",
92 "unsigned int",
93 "long",
94 "unsigned long",
95 "long long",
96 "unsigned long long",
97 "float",
98 "double",
99 "long double",
100 "void"};
101
102// configuration
103static bool gEnableFastPath = true;
104
105// global initialization -----------------------------------------------------
106namespace {
107
108static inline bool is_integral(std::string& s) {
109 if (s == "false") {
110 s = "0";
111 return true;
112 } else if (s == "true") {
113 s = "1";
114 return true;
115 }
116 return !s.empty() && std::find_if(s.begin(), s.end(), [](unsigned char c) {
117 return !std::isdigit(c);
118 }) == s.end();
119}
120
121struct InterOpPaths {
122 std::string Library;
123 std::vector<std::string> IncludeDirs;
124 std::string ClangIncludeDir; // empty when no usable resource dir is known
125};
126
127// In ROOT the dispatch API comes from libCling (loadDispatchAPI) and the
128// CppInterOp headers are staged under ROOT's etc directory, etc/cppinterop
129// in the build tree and in the install tree alike, so TROOT::GetEtcDir()
130// locates them in both.
131static InterOpPaths cppinterop_paths() {
132 InterOpPaths Paths;
133 std::string dir = TROOT::GetEtcDir().Data();
134 dir += "/cppinterop";
135 if (gSystem->AccessPathName(dir.c_str()))
136 std::cerr << "[cppjit] CppInterOp headers not found in " << dir
137 << std::endl;
138 Paths.IncludeDirs.push_back(dir);
139 return Paths;
140}
141
142// The one place the dispatch source is dlopen'd. In ROOT, CppInterOp is
143// compiled into libCling, so the dispatch API is loaded from there instead of
144// from a standalone libclangCppInterOp.
145static bool loadDispatchAPI(const InterOpPaths& /*Paths*/) {
146 (void)gROOT;
147 char* libcling = gSystem->DynamicPathName("libCling");
148
149 if (!libcling) {
150 std::cerr << "[cppjit] Failed to find libCling" << std::endl;
151 return false;
152 }
153 if (!Cpp::LoadDispatchAPI(libcling)) {
154 std::cerr << "[cppjit] Failed to load CppInterOp" << std::endl;
155 return false;
156 }
157 return true;
158}
159
160// CppInterOp itself appends CPPINTEROP_EXTRA_INTERPRETER_ARGS inside
161// CreateInterpreter, so nothing needs to be forwarded from here.
163acquireOrCreateInterpreter(const InterOpPaths& Paths) {
164 if (auto existingInterp = Cpp::GetInterpreter())
165 return existingInterp;
166
167 std::vector<const char*> args = {"-std=c++17"};
168#if !(defined(__arm64__) && defined(__APPLE__))
169 // apple silicon clang rejects -march=native
170 args.push_back("-march=native");
171#endif
172 // Without clang's builtin headers the interpreter fails at its first
173 // #include. Prefer the bundled copy: it matches the build clang and
174 // needs no LLVM on the host. DetectResourceDir refuses version
175 // mismatches, and CppInterOp itself probes only bare `clang`.
176 std::string resourceDir = Paths.ClangIncludeDir;
177 if (resourceDir.empty())
178 resourceDir = Cpp::DetectResourceDir("clang-" CPPJIT_CLANG_MAJOR);
179 if (!resourceDir.empty()) {
180 args.push_back("-resource-dir");
181 args.push_back(resourceDir.c_str());
182 }
183 return Cpp::CreateInterpreter(args, /*GpuArgs=*/{});
184}
185
186static void configureInterpreter(const InterOpPaths& Paths) {
187 std::set<std::string> bi{g_builtins};
188 for (const auto& name : bi) {
189 for (const char* a : {"*", "&", "*&", "[]", "*[]"})
190 g_builtins.insert(name + a);
191 }
192
193 if (getenv("CPPJIT_DISABLE_FASTPATH"))
194 gEnableFastPath = false;
195
196 // set opt level (default to 2 if not given; Cling itself defaults to 0)
197 int optLevel = 2;
198
199 if (getenv("CPPJIT_OPT_LEVEL"))
200 optLevel = atoi(getenv("CPPJIT_OPT_LEVEL"));
201
202 if (optLevel != 0) {
203 std::ostringstream s;
204 s << "#pragma cling optimize " << optLevel;
205 Cpp::Process(s.str().c_str());
206 }
207
208 for (const std::string& dir : Paths.IncludeDirs)
209 Cpp::AddIncludePath(dir.c_str());
210 Cpp::LoadLibrary("libstdc++", /* lookup= */ true);
211}
212
213static bool preloadHeaders() {
214 const char* code = "#include <algorithm>\n"
215 "#include <numeric>\n"
216 "#include <complex>\n"
217 "#include <iostream>\n"
218 "#include <string.h>\n" // for strcpy
219 "#include <string>\n"
220 "#include <vector>\n"
221 "#include <utility>\n"
222 "#include <memory>\n"
223 "#include <functional>\n" // for the dispatcher code to
224 // use std::function
225 "#include <map>\n" // FIXME: Replace with modules
226 "#include <sstream>\n" // FIXME: Replace with modules
227 "#include <array>\n" // FIXME: Replace with modules
228 "#include <list>\n" // FIXME: Replace with modules
229 "#include <deque>\n" // FIXME: Replace with modules
230 "#include <tuple>\n" // FIXME: Replace with modules
231 "#include <set>\n" // FIXME: Replace with modules
232 "#include <chrono>\n" // FIXME: Replace with modules
233 "#include <cmath>\n" // FIXME: Replace with modules
234 "#if __has_include(<optional>)\n"
235 "#include <optional>\n"
236 "#endif\n"
237 "#include <CppInterOp/Dispatch.h>\n";
238 return Cpp::Process(code) == 0;
239}
240
241static void defineRuntimeHelpers() {
242 Cpp::Declare("namespace __cppjit_internal { template<class C1, class C2>"
243 " bool is_equal(const C1& c1, const C2& c2) { return "
244 "(bool)(c1 == c2); } }",
245 /*silent=*/false);
246 Cpp::Declare("namespace __cppjit_internal { template<class C1, class C2>"
247 " bool is_not_equal(const C1& c1, const C2& c2) { return "
248 "(bool)(c1 != c2); } }",
249 /*silent=*/false);
250
251 // helper for multiple inheritance
252 Cpp::Declare("namespace __cppjit_internal { struct Sep; }",
253 /*silent=*/false);
254}
255
256} // unnamed namespace
257
258// Load CppInterOp and set up the interpreter. A dlopen during static
259// initialization is unsafe, so _cpython_cppjit.py calls this explicitly
260// before the first libcppjit use. Thread-safe and idempotent; returns 1 on
261// success.
262extern "C" {
264}
265
266extern "C" int LoadCppInterOp() {
267 static std::once_flag Once;
268 static int Loaded = 0;
269 std::call_once(Once, [] {
270 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
271 const InterOpPaths Paths = cppinterop_paths();
272 if (!loadDispatchAPI(Paths))
273 return;
274
275 if (!acquireOrCreateInterpreter(Paths)) {
276 std::cerr << "[cppjit] Failed to create the C++ interpreter" << std::endl;
277 return;
278 }
279 configureInterpreter(Paths);
280 if (!preloadHeaders()) {
281 std::cerr << "[cppjit] The C++ standard headers do not parse, see the "
282 "diagnostic above. Install a C++ toolchain such as g++ or "
283 "the conda package cxx-compiler."
284 << std::endl;
285 return;
286 }
287 defineRuntimeHelpers();
288
289 Loaded = 1;
290 });
291 return Loaded;
292}
293
294// local helpers -------------------------------------------------------------
295static inline char* cppstring_to_cstring(const std::string& cppstr) {
296 char* cstr = (char*)malloc(cppstr.size() + 1);
297 memcpy(cstr, cppstr.c_str(), cppstr.size() + 1);
298 return cstr;
299}
300
301// direct interpreter access -------------------------------------------------
302// Returns false on failure and true on success
303bool interop::Compile(const std::string& code, bool silent) {
304 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
305 // Declare returns an enum which equals 0 on success
306 return !Cpp::Declare(code.c_str(), silent);
307}
308
310
312
314 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
315 if (klass && obj && !Cpp::IsNamespace(klass))
316 return Cpp::ObjToString(Cpp::GetQualifiedCompleteName(klass).c_str(),
317 obj.data);
318 return "";
319}
320
321// // name to opaque C++ scope representation
322// -----------------------------------
323std::string interop::ResolveName(const std::string& name) {
324 if (!name.empty()) {
326 interop::GetType(name, /*enable_slow_lookup=*/true))
328 return name;
329 }
330 return "";
331}
332
334 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
335 if (Cpp::GetValueKind(type) != Cpp::ValueKind::LValue)
336 return type;
337
338 TCppType_t nonReferenceType = Cpp::GetNonReferenceType(type);
339 if (Cpp::IsEnumType(nonReferenceType)) {
340 TCppType_t underlying_type =
341 Cpp::GetIntegerTypeFromEnumType(nonReferenceType);
342 return Cpp::GetReferencedType(underlying_type, /*rvalue=*/false);
343 }
344 return type;
345}
346
348 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
349 if (!Cpp::IsPointerType(type))
350 return type;
351
352 TCppType_t PointeeType = Cpp::GetPointeeType(type);
353 if (Cpp::IsEnumType(PointeeType)) {
354 TCppType_t underlying_type = Cpp::GetIntegerTypeFromEnumType(PointeeType);
355 return Cpp::GetPointerType(underlying_type);
356 }
357 return type;
358}
359
361 interop::TCppType_t check_int_typedefs = type;
362 if (Cpp::IsPointerType(check_int_typedefs))
363 check_int_typedefs = Cpp::GetPointeeType(check_int_typedefs);
364 if (Cpp::IsReferenceType(check_int_typedefs))
365 check_int_typedefs =
366 Cpp::GetReferencedType(check_int_typedefs, /*rvalue=*/false);
367
368 if (Cpp::GetTypeAsString(check_int_typedefs) == "int8_t" ||
369 Cpp::GetTypeAsString(check_int_typedefs) == "uint8_t")
370 return check_int_typedefs;
371 return nullptr;
372}
373
375 if (!type)
376 return type;
377
378 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
379
380 TCppType_t check_int_typedefs = int_like_type(type);
381 if (check_int_typedefs)
382 return type;
383
384 interop::TCppType_t canonType = Cpp::GetCanonicalType(type);
385
386 if (Cpp::IsEnumType(canonType)) {
387 if (Cpp::GetTypeAsString(type) != "std::byte")
388 return Cpp::GetIntegerTypeFromEnumType(canonType);
389 }
390 if (Cpp::HasTypeQualifier(canonType, Cpp::QualKind::Restrict)) {
391 return Cpp::RemoveTypeQualifier(canonType, Cpp::QualKind::Restrict);
392 }
393
394 return canonType;
395}
396
398 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
399 TCppType_t check_int_typedefs = int_like_type(type);
400 if (check_int_typedefs)
401 return check_int_typedefs;
402 return Cpp::GetUnderlyingType(type);
403}
404
406 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
407 return Cpp::GetPointerType(type);
408}
409
411 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
412 return Cpp::GetReferencedType(type, rvalue);
413}
414
416 return Cpp::GetValueKind(type) == Cpp::ValueKind::RValue;
417}
418
420 return Cpp::GetValueKind(type) == Cpp::ValueKind::LValue;
421}
422
423// Whether the callee can rebind a pointer through this reference (T*&);
424// false for T* const& and for references to non-pointers.
426 if (!Cpp::IsReferenceType(type))
427 return false;
428 TCppType_t nonref = Cpp::GetNonReferenceType(type);
429 return Cpp::IsPointerType(nonref) &&
430 !Cpp::HasTypeQualifier(nonref, Cpp::QualKind::Const);
431}
432
433bool interop::IsClassType(TCppType_t type) { return Cpp::IsRecordType(type); }
434
435bool interop::IsIntegerType(TCppType_t type, bool* is_signed /*= nullptr*/) {
436 if (is_signed) {
437 Cpp::Signedness sign;
438 bool res = Cpp::IsIntegerType(type, &sign);
439 *is_signed = (sign == Cpp::Signedness::kSigned);
440 return res;
441 }
442 return Cpp::IsIntegerType(type, nullptr);
443}
444
446 return Cpp::IsPointerType(type);
447}
448
450 return Cpp::IsFunctionPointerType(type);
451}
452
453std::string trim(const std::string& line) {
454 if (line.empty())
455 return "";
456 const char* WhiteSpace = " \t\v\r\n";
457 std::size_t start = line.find_first_not_of(WhiteSpace);
458 std::size_t end = line.find_last_not_of(WhiteSpace);
459 return line.substr(start, end - start + 1);
460}
461
462// returns false of angular brackets dont match, else true
463bool split_comma_saparated_types(const std::string& name,
464 std::vector<std::string>& types) {
465 std::string trimed_name = trim(name);
466 size_t start_pos = 0;
467 size_t end_pos = 0;
468 int matching_angular_brackets = 0;
469 while (end_pos < trimed_name.size()) {
470 switch (trimed_name[end_pos]) {
471 case ',': {
472 if (!matching_angular_brackets) {
473 if (end_pos > start_pos)
474 types.push_back(
475 trim(trimed_name.substr(start_pos, end_pos - start_pos)));
476 start_pos = end_pos + 1;
477 }
478 break;
479 }
480 case '<': {
481 matching_angular_brackets++;
482 break;
483 }
484 case '>': {
485 matching_angular_brackets--;
486 break;
487 }
488 }
489 end_pos++;
490 }
491 if (start_pos < trimed_name.size())
492 types.push_back(trim(trimed_name.substr(start_pos, end_pos - start_pos)));
493 return true;
494}
495
497 std::string delim = "::";
498 size_t start = 0;
499 size_t end = name.find(delim);
500 interop::TCppScope_t curr_scope;
501 while (end != std::string::npos) {
502 curr_scope = Cpp::GetNamed(name.substr(start, end - start), curr_scope);
503 start = end + delim.length();
504 end = name.find(delim, start);
505 }
506 return Cpp::GetNamed(name.substr(start, end), curr_scope);
507}
508static bool is_identifier(std::string_view s) {
509 if (s.empty())
510 return false;
511 auto is_valid_start = [](unsigned char c) {
512 return std::isalpha(c) || c == '_';
513 };
514 auto is_valid_body = [](unsigned char c) {
515 return std::isalnum(c) || c == '_';
516 };
517 return is_valid_start(s[0]) &&
518 std::all_of(s.begin() + 1, s.end(), is_valid_body);
519};
520
521// returns true if no new type was added.
522bool interop::AppendTypesSlow(const std::string& name,
523 std::vector<Cpp::TemplateArgInfo>& types,
524 interop::TCppScope_t parent) {
525
526 // Add no new type if string is empty
527 if (name.empty())
528 return true;
529
530 // The ast printer gave us garbage.
531 if (name == "<unnamed>")
532 return true;
533
534 // A type inside an anonymous namespace cannot be spelled in injected
535 // code; attempting it crashes codegen on the ill-formed recovery (e.g.
536 // auto-downcasting to an anonymous FuncExporter<...> instantiation).
537 if (name.find("(anonymous namespace)") != std::string::npos)
538 return true;
539
540 auto replace_all = [](std::string& str, const std::string& from,
541 const std::string& to) {
542 if (from.empty())
543 return;
544 size_t start_pos = 0;
545 while ((start_pos = str.find(from, start_pos)) != std::string::npos) {
546 str.replace(start_pos, from.length(), to);
547 start_pos += to.length();
548 }
549 };
550
551 std::string resolved_name = name;
552 replace_all(resolved_name, "std::initializer_list<",
553 "std::vector<"); // replace initializer_list with vector
554
555 // If we have a single identifier, we don't need anything complicated.
556 // Try scoped lookup first (catches type aliases / nested types declared
557 // inside `parent`), then fall back to TU (catches typedefs declared
558 // outside the query scope, e.g. `typedef Foo Bar;` at TU consulted
559 // from a method on Foo).
560 if (is_identifier(name)) {
561 TCppType_t type = parent ? Cpp::GetType(name, parent) : nullptr;
562 if (!type)
563 type = Cpp::GetType(name);
564 if (type) {
565 types.emplace_back(type.data);
566 return false;
567 }
568 if (!parent || parent == Cpp::GetGlobalScope())
569 return true;
570 // Fall through: the name may live in a scope enclosing `parent` (e.g.
571 // "RVecF" from within ROOT::RDF::RInterface<...> resolves to
572 // ROOT::RVecF); the trampoline below applies real unqualified lookup.
573 }
574
575 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
576
577 // Every lookup below declares code through the interpreter, which parses,
578 // commits a transaction and leaves a new declaration in the AST, so each one
579 // costs more than the last. The same names come back constantly (overload
580 // ranking resolves every argument type of every candidate on each call that
581 // is not memoized), so remember what a name resolved to. A name that fails
582 // may still resolve once more declarations are available, so only successes
583 // are cached.
584 using SlowTypesKey = std::pair<std::string, const void*>;
585 static std::map<SlowTypesKey, std::vector<Cpp::TemplateArgInfo>> s_cache;
586 const SlowTypesKey cache_key{name, parent.data};
587 // the integral values are strings whose ownership passes to the caller
588 // (which frees them), so the cache keeps and hands out copies of its own
589 auto copy_of = [](const Cpp::TemplateArgInfo& info) {
590 return Cpp::TemplateArgInfo(info.m_Type, info.m_IntegralValue
591 ? strdup(info.m_IntegralValue)
592 : nullptr);
593 };
594 if (auto cached = s_cache.find(cache_key); cached != s_cache.end()) {
595 for (const Cpp::TemplateArgInfo& info : cached->second)
596 types.push_back(copy_of(info));
597 return false;
598 }
599 const size_t n_types_before = types.size();
600 auto remember = [&] {
601 std::vector<Cpp::TemplateArgInfo> resolved;
602 for (size_t i = n_types_before; i < types.size(); ++i)
603 resolved.push_back(copy_of(types[i]));
604 s_cache.emplace(cache_key, std::move(resolved));
605 };
606
607 // We might have an entire expression such as int, double.
608 static unsigned long long struct_count = 0;
609 std::string code =
610 "template<typename ...T> struct __cppjit_interop_AppendTypesSlow {};\n";
611 if (!struct_count)
612 Cpp::Declare(code.c_str(), /*silent=*/true); // initialize the trampoline
613
614 // Perform the lookup from within the innermost (reopenable) namespace
615 // enclosing `parent` -- `parent` itself if it is a namespace, else the
616 // namespace its class chain lives in -- by reopening that namespace around
617 // the trampoline declaration: the compiler then applies real C++ name
618 // lookup, walking outward with proper shadowing of outer names, which a
619 // global declaration with a parent-qualified fallback cannot emulate (e.g.
620 // "RVecF" from within ROOT::RDF::RInterface<...> resolves to ROOT::RVecF).
621 std::string lookup_ns;
622 TCppScope_t lookup_scope = nullptr;
623 for (TCppScope_t s = parent; s && s != Cpp::GetGlobalScope();
624 s = Cpp::GetParentScope(s)) {
625 if (!Cpp::IsNamespace(s))
626 continue;
627 std::string qname = Cpp::GetQualifiedName(s);
628 if (!qname.empty() && qname.find('(') == std::string::npos) { // unnamed?
629 lookup_ns = qname;
630 lookup_scope = s;
631 }
632 break;
633 }
634
635 // The reopened namespace doesn't see names nested in a class parent, so a
636 // name written relative to it (e.g. a nested type) won't resolve. Try the
637 // name as given, then qualified by the parent.
638 std::vector<std::string> candidates = {resolved_name};
639 if (parent && parent != Cpp::GetGlobalScope() && parent != lookup_scope &&
640 (interop::IsNamespace(parent) || interop::IsClass(parent)))
641 candidates.push_back(Cpp::GetQualifiedCompleteName(parent) +
642 "::" + resolved_name);
643
644 for (const std::string& candidate : candidates) {
645 std::string var = "__cppjit_interop_s" + std::to_string(struct_count++);
646 // nodebug: with -g the variable's debug info would carry the full DIE
647 // tree of every template argument (all member declarations included) --
648 // a large, uncacheable per-lookup cost on heavyweight types.
649 std::string decl = "__cppjit_interop_AppendTypesSlow<" + candidate +
650 "> __attribute__((nodebug)) " + var + ";\n";
651 if (!lookup_ns.empty())
652 decl = "namespace " + lookup_ns + " { " + decl + "}\n";
653 if (!Cpp::Declare(decl.c_str(), /*silent=*/true)) {
654 TCppType_t varN = Cpp::GetVariableType(Cpp::GetNamed(
655 var.c_str(), lookup_ns.empty() ? nullptr : lookup_scope));
656 TCppScope_t instance_class = Cpp::GetScopeFromType(varN);
657 if (!instance_class)
658 continue; // recovered-but-broken decl; try next candidate or split path
659 size_t oldSize = types.size();
660 Cpp::GetClassTemplateInstantiationArgs(instance_class, types);
661 if (oldSize == types.size())
662 return true;
663 remember();
664 return false;
665 }
666 }
667
668 // We split each individual types based on , and resolve it
669 // FIXME: see discussion on should we support template instantiation with
670 // string:
671 // https://github.com/compiler-research/cppyy-backend/pull/137#discussion_r2079357491
672 // We should consider eliminating the `split_comma_saparated_types` and
673 // `is_integral` string parsing.
674 std::vector<std::string> individual_types;
675 if (!split_comma_saparated_types(resolved_name, individual_types))
676 return true;
677
678 for (std::string& i : individual_types) {
679 // Try going via interop::GetType first.
680 const char* integral_value = nullptr;
681 interop::TCppType_t type = nullptr;
682
683 if (!lookup_ns.empty()) {
684 // resolve from within the parent namespace, honouring C++ name lookup
685 // and shadowing (see the trampoline declaration above)
686 std::string id = "__cppjit_interop_s" + std::to_string(struct_count++);
687 if (!Cpp::Declare(("namespace " + lookup_ns + " { using " + id +
688 " = __typeof__(" + i + "); }\n")
689 .c_str(),
690 /*silent=*/true))
691 type = Cpp::GetCanonicalType(
692 Cpp::GetTypeFromScope(Cpp::GetNamed(id, lookup_scope)));
693 } else {
694 type = GetType(i, /*enable_slow_lookup=*/true);
695 if (!type && parent &&
696 (interop::IsNamespace(parent) || interop::IsClass(parent))) {
697 type =
698 interop::GetTypeFromScope(interop::GetNamed(resolved_name, parent));
699 }
700 }
701
702 if (!type) {
703 types.clear();
704 return true;
705 }
706
707 if (is_integral(i))
708 integral_value = strdup(i.c_str());
710 if (Cpp::IsEnumConstant(scope))
711 integral_value =
712 strdup(std::to_string(Cpp::GetEnumConstantValue(scope)).c_str());
713 types.emplace_back(type.data, integral_value);
714 }
715 remember();
716 return false;
717}
718
720 bool enable_slow_lookup /* = false */) {
721 // The ast printer gave us garbage.
722 if (name == "<unnamed>")
723 return nullptr;
724 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
725
726 if (auto type = Cpp::GetType(name))
727 return type;
728
729 // Plain identifiers don't need the heavy __typeof__ trampoline:
730 // Cpp::GetType above already covers builtin types and named
731 // scopes. Exception: the three identifier-shaped C++ value-
732 // literals -- `true`, `false`, `nullptr` -- aren't reachable by
733 // name (no type called "false") but appear as non-type template
734 // args in libstdc++ types like _Node_iterator<..., false, false>;
735 // map them to their underlying type directly so the per-chunk
736 // fallback in AppendTypesSlow gets a real type without paying
737 // the trampoline cost.
738 if (is_identifier(name)) {
739 if (name == "true" || name == "false")
740 return Cpp::GetType("bool");
741 if (name == "nullptr")
742 return Cpp::GetType("nullptr_t", Cpp::GetNamed("std"));
743 return nullptr;
744 }
745
746 if (!enable_slow_lookup) {
747 if (name.find("::") != std::string::npos)
748 throw std::runtime_error(
749 "Calling interop::GetType with qualified name '" + name + "'\n");
750 return nullptr;
751 }
752
753 // Here we might need to deal with integral types such as 3.14.
754
755 // Declaring the trampoline parses and compiles code, and each one adds a
756 // new alias to the AST, so memoize the resolved types by name. A name that
757 // fails to resolve may succeed once more declarations are available, so
758 // failures are retried.
759 static std::map<std::string, TCppType_t> s_slow_type_cache;
760 auto cached = s_slow_type_cache.find(name);
761 if (cached != s_slow_type_cache.end())
762 return cached->second;
763
764 static unsigned long long var_count = 0;
765 std::string id = "__cppjit_interop_GetType_" + std::to_string(var_count++);
766 std::string using_clause = "using " + id + " = __typeof__(" + name + ");\n";
767
768 if (!Cpp::Declare(using_clause.c_str(), /*silent=*/true)) {
769 TCppScope_t lookup = Cpp::GetNamed(id);
770 TCppType_t lookup_ty = Cpp::GetTypeFromScope(lookup);
771 TCppType_t result = Cpp::GetCanonicalType(lookup_ty);
772 if (result)
773 s_slow_type_cache.emplace(name, result);
774 return result;
775 }
776 return nullptr;
777}
778
780 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
781 return Cpp::GetComplexType(Cpp::GetType(name));
782}
783
785 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
786 std::string type =
787 Cpp::GetTypeAsString(Cpp::GetIntegerTypeFromEnumScope(handle));
788 if (type == "signed char")
789 return "char";
790 return type;
791}
792
794 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
795 return Cpp::GetUnderlyingScope(scope);
796}
797
799 TCppScope_t parent_scope) {
800 std::unique_lock<RInterOpMutex> Lock(InterOpMutex);
801 // Resolving a templated name below declares a new variable in the
802 // interpreter (see AppendTypesSlow), so remember the result to not declare
803 // one, and grow the memory, on every lookup of the same name.
804 static std::map<std::pair<void*, std::string>, TCppScope_t> template_scopes;
805 const bool is_template = name.find('<') != std::string::npos;
806 const auto key = std::make_pair(parent_scope.data, name);
807 if (is_template)
808 if (auto it = template_scopes.find(key); it != template_scopes.end())
809 return it->second;
810
811 // CppInterOp directly looks at the AST which is not enough.
812 // We require lazy module loading that ROOT relies on, so we do it here
813 // first. Use TClass::GetClass to trigger auto-loading of dictionaries and
814 // modules.
815 // This also covers nested names: declarations come from the C++ modules,
816 // so e.g. ROOT::RDF can be used before its libraries are loaded, and the
817 // JIT then finds their symbols only by scanning every library on the
818 // search path (about half a second).
819 if (!parent_scope || parent_scope == Cpp::GetGlobalScope())
820 TClass::GetClass(name.c_str(), true /* load */, true /* silent */);
821 else if (Cpp::IsNamespace(parent_scope) || Cpp::IsClass(parent_scope))
823 (Cpp::GetQualifiedCompleteName(parent_scope) + "::" + name).c_str(),
824 true /* load */, true /* silent */);
825
826 if (interop::TCppScope_t scope = Cpp::GetScope(name, parent_scope))
827 return scope;
828 if (!parent_scope || parent_scope == Cpp::GetGlobalScope()) {
829 if (interop::TCppScope_t scope = Cpp::GetScopeFromCompleteName(name))
830 return scope;
831 } else if (name.find('<') == std::string::npos) {
832 // Cpp::GetScope handles single identifiers only, so walk the components
833 // of a qualified name. Templated names take the branch below: "::" inside
834 // a template argument list cannot be split naively.
835 TCppScope_t curr = parent_scope;
836 size_t start = 0, end;
837 while (curr && (end = name.find("::", start)) != std::string::npos) {
838 curr = Cpp::GetScope(name.substr(start, end - start), curr);
839 start = end + 2;
840 }
841 if (curr && curr != parent_scope)
842 if (interop::TCppScope_t scope = Cpp::GetScope(name.substr(start), curr))
843 return scope;
844 }
845
846 // FIXME: avoid string parsing here
847 if (is_template) {
848 // Templated type; may need instantiation. Resolve the whole type
849 // expression (e.g. "std::array<float, 3>") and read back its scope.
850 // Splitting off the argument list and resolving it directly cannot
851 // represent non-type arguments such as the `3` in std::array<float, 3>.
852 std::vector<Cpp::TemplateArgInfo> types;
853 Lock.unlock(); // unlock to allow AppendTypesSlow
854 bool added_new_type =
855 !interop::AppendTypesSlow(name, types, /*parent=*/parent_scope);
856 Lock.lock();
857 if (added_new_type && types.size() == 1) {
858 // A pointer or reference spelling (e.g. "std::chrono::nanoseconds *",
859 // the return type of std::array<nanoseconds, N>::begin()) does not
860 // name a scope; GetScopeFromType would silently strip the pointer and
861 // return the pointee's scope, misclassifying the name.
862 if (Cpp::IsPointerType(types[0].m_Type) ||
863 Cpp::IsReferenceType(types[0].m_Type))
864 return nullptr;
865 TCppScope_t scope = Cpp::GetScopeFromType(types[0].m_Type);
866 // Naming the type as a template argument above does not instantiate
867 // it, so the specialization may still be declared-but-undefined.
868 // Force its definition: callers expect a complete scope, e.g. to
869 // walk its base classes.
870 if (scope) {
871 Cpp::IsComplete(scope);
872 template_scopes[key] = scope;
873 }
874 return scope;
875 }
876 }
877 return nullptr;
878}
879
883
885 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
886 return Cpp::GetScopeFromType(Cpp::GetVariableType(var));
887}
888
890 TCppScope_t parent_scope) {
891 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
892 if (TCppScope_t named = Cpp::GetNamed(name, parent_scope))
893 return named;
894
895 // Rootmaps don't forward declare enums and variables. If TClass::GetClass
896 // looked one up before its header was parsed, clang cached that miss and
897 // won't ask TCling to autoparse it again (#24176).
898 if (parent_scope && Cpp::IsNamespace(parent_scope)) {
899 const std::string qualified_name =
900 Cpp::GetQualifiedCompleteName(parent_scope) + "::" + name;
901 if (gInterpreter->AutoParse(qualified_name.c_str()))
902 if (TCppScope_t named = Cpp::GetNamed(name, parent_scope))
903 return named;
904 }
905
906 // "gROOT" is a macro expanding to ROOT::GetROOT(); ROOT master exposed it
907 // to cppyy as a TGlobalMappedFunction, a mechanism this backend does not
908 // consult. Resolve it to the underlying variable instead (making sure it
909 // has been initialized first).
910 if (name == "gROOT" &&
911 (!parent_scope || parent_scope == Cpp::GetGlobalScope())) {
913 return Cpp::GetNamed(
914 "gROOTLocal",
915 Cpp::GetNamed("Internal", Cpp::GetNamed("ROOT", nullptr)));
916 }
917
918 return nullptr;
919}
920
921bool interop::IsVisibleName(const std::string& name, TCppScope_t parent_scope) {
922 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
923 return Cpp::IsVisibleName(name, parent_scope);
924}
925
927 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
928 return Cpp::GetParentScope(scope);
929}
930
932 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
933 return Cpp::GetScopeFromType(type);
934}
935
937 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
938 return Cpp::GetTypeFromScope(klass);
939}
940
942 // The global scope (the first declaration of the interpreter's translation
943 // unit) never changes, but this is called on every method call that
944 // receives 'self' as its first argument, so avoid the lock and the query.
945 static const TCppScope_t s_global = [] {
946 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
947 return Cpp::GetGlobalScope();
948 }();
949 return s_global;
950}
951
952bool interop::IsTemplate(TCppScope_t handle) { return Cpp::IsTemplate(handle); }
953
955 return Cpp::IsTemplateSpecialization(handle);
956}
957
959 return Cpp::IsTypedefed(handle);
960}
961
962namespace {
963class AutoCastRTTI {
964public:
965 virtual ~AutoCastRTTI() {}
966};
967} // namespace
968
970 TCppObject_t obj) {
971 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
972
973 if (!obj || !Cpp::IsClassPolymorphic(klass))
974 return klass;
975
976 // Skip the std stream hierarchy: autocasting it is not useful, and on MSVC
977 // its virtual inheritance puts the vbptr, not a vfptr, at offset 0, so the
978 // RTTI probe below follows a garbage pointer.
979 static const std::array<TCppScope_t, 3> stream_bases = {
980 interop::GetScope("std::ios_base"), interop::GetScope("std::streambuf"),
981 interop::GetScope("std::wstreambuf")};
982 for (TCppScope_t base : stream_bases)
983 if (base && interop::IsSubclass(klass, base))
984 return klass;
985
986 // This is hit for every polymorphic object handed to Python, and the name
987 // lookups below cost microseconds, so their outcomes are memoized. Keyed on
988 // (static class, dynamic type). Only outcomes that cannot change later are
989 // cached; a failed lookup may succeed once more declarations are available,
990 // so failures are retried.
991 static std::map<std::pair<const void*, const std::type_info*>, TCppScope_t>
992 s_actual_class_cache;
993 const std::type_info* typ = &typeid(*(AutoCastRTTI*)obj.data);
994 if (!typ)
995 return klass;
996 const auto cacheKey = std::make_pair((const void*)klass.data, typ);
997 auto cached = s_actual_class_cache.find(cacheKey);
998 if (cached != s_actual_class_cache.end())
999 return cached->second;
1000
1001#ifdef _WIN32
1002 // MSVC's type_info::name() is already human-readable, but prefixed with
1003 // the tag kind ("class TWinNTSystem"), which plain name lookup does not
1004 // accept. Strip the prefix by hand; respelling through type resolution
1005 // would JIT an uncached declaration per downcast. Template arguments
1006 // keep their tags, which is harmless as templated names go through type
1007 // resolution rather than plain lookup.
1008 std::string demangled_name = typ->name();
1009 for (const char* prefix : {"class ", "struct ", "union ", "enum "}) {
1010 if (demangled_name.compare(0, strlen(prefix), prefix) == 0) {
1011 demangled_name = demangled_name.substr(strlen(prefix));
1012 break;
1013 }
1014 }
1015#else
1016 std::string mangled_name = typ->name();
1017 std::string demangled_name = Cpp::Demangle(mangled_name);
1018#endif
1019
1020 // A type in an anonymous namespace cannot be named in injected code and
1021 // has no dictionary, so looking it up would fail; worse, its unspellable
1022 // name crashes the interpreter ("(anonymous namespace)" on Itanium,
1023 // "`anonymous namespace'" on MSVC). Keep the base type.
1024 if (demangled_name.find("anonymous namespace") != std::string::npos)
1025 return klass;
1026
1027 if (TCppScope_t scope = interop::GetScope(demangled_name)) {
1028 // A type inside an anonymous namespace cannot be spelled in injected
1029 // code (e.g. the dispatcher's), so it is unusable as a cast target;
1030 // keep the static type. Anonymous namespaces are the ones without a
1031 // name of their own.
1032 for (TCppScope_t p = Cpp::GetParentScope(scope); p;
1033 p = Cpp::GetParentScope(p))
1034 if (Cpp::IsNamespace(p) && Cpp::GetName(p).empty())
1035 return klass;
1036 // Only return the derived type once it has a complete definition. Under
1037 // runtime_cxxmodules=OFF, autoloading the dictionary registers only a
1038 // forward declaration, so force the definition into the AST here. Internal
1039 // classes like TCling have no header and cannot be completed (their
1040 // CXXRecordDecl has no DefinitionData); GetOrForceDefinition returns null
1041 // for them and we fall back to the base type, avoiding a crash when
1042 // querying offsets.
1043 if (Cpp::GetOrForceDefinition(scope)) {
1044 s_actual_class_cache.emplace(cacheKey, scope);
1045 return scope;
1046 }
1047 }
1048
1049 return klass;
1050}
1051
1053 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1054 return Cpp::SizeOf(klass);
1055}
1056
1058 if (!klass)
1059 return 0;
1060 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1061 return Cpp::GetSizeOfType(klass);
1062}
1063
1064bool interop::IsBuiltin(const std::string& type_name) {
1065 static std::set<std::string> s_builtins = {"bool",
1066 "char",
1067 "signed char",
1068 "unsigned char",
1069 "wchar_t",
1070 "short",
1071 "unsigned short",
1072 "int",
1073 "unsigned int",
1074 "long",
1075 "unsigned long",
1076 "long long",
1077 "unsigned long long",
1078 "float",
1079 "double",
1080 "long double",
1081 "void"};
1082 if (s_builtins.find(trim(type_name)) != s_builtins.end())
1083 return true;
1084
1085 if (strstr(type_name.c_str(), "std::complex"))
1086 return true;
1087
1088 return false;
1089}
1090
1091bool interop::IsBuiltin(TCppType_t type) { return Cpp::IsBuiltin(type); }
1092
1094 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1095 return Cpp::IsComplete(scope);
1096}
1097
1098// // memory management
1099// ---------------------------------------------------------
1101 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1102 return Cpp::Allocate(scope, /*count=*/1);
1103}
1104
1106 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1107 Cpp::Deallocate(scope, instance, /*count=*/1);
1108}
1109
1110// Constructors and destructors are resolved (and JIT-compiled) under the
1111// lock and run without it, as WrapperCall does: their bodies are user code.
1113 void* arena /*=nullptr*/) {
1114 std::unique_lock<RInterOpMutex> Lock(InterOpMutex);
1115 if (!Cpp::HasDefaultConstructor(scope))
1116 return nullptr;
1117 Cpp::JitCall JC =
1118 Cpp::MakeFunctionCallable(Cpp::GetDefaultConstructor(scope));
1119 Lock.unlock();
1120 if (!JC)
1121 return nullptr;
1122 void* result = arena;
1123 JC.InvokeConstructor(&result, /*nary=*/1, /*args=*/{},
1124 /*is_arena=*/arena ? reinterpret_cast<void*>(1)
1125 : nullptr);
1126 return result;
1127}
1128
1129static Cpp::JitCall destructor_callable(interop::TCppScope_t scope) {
1130 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1131 return Cpp::MakeFunctionCallable(Cpp::GetDestructor(scope));
1132}
1133
1135 if (Cpp::JitCall JC = destructor_callable(scope))
1136 JC.InvokeDestructor(instance.data, /*nary=*/0, /*withFree=*/true);
1137}
1138
1139static inline bool copy_args(Parameter* args, size_t nargs, void** vargs) {
1140 bool runRelease = false;
1141 for (size_t i = 0; i < nargs; ++i) {
1142 switch (args[i].fTypeCode) {
1143 case 'X': /* (void*)type& with free */
1144 runRelease = true;
1145 case 'V': /* (void*)type& */
1146 vargs[i] = args[i].fValue.fVoidp;
1147 break;
1148 case 'r': /* const type& */
1149 vargs[i] = args[i].fRef;
1150 break;
1151 default: /* all other types in union */
1152 vargs[i] = (void*)&args[i].fValue.fVoidp;
1153 break;
1154 }
1155 }
1156 return runRelease;
1157}
1158
1159static inline void release_args(Parameter* args, size_t nargs) {
1160 for (size_t i = 0; i < nargs; ++i) {
1161 if (args[i].fTypeCode == 'X')
1162 free(args[i].fValue.fVoidp);
1163 }
1164}
1165
1166static inline bool WrapperCall(interop::TCppMethod_t method, size_t nargs,
1167 void* args_, void* self, void* result) {
1168 Parameter* args = (Parameter*)args_;
1169 // bool is_direct = nargs & DIRECT_CALL;
1170 nargs = CALL_NARGS(nargs);
1171
1172 // if (!is_ready(wrap, is_direct))
1173 // return false; // happens with compilation error
1175 if (Cpp::JitCall JC = Cpp::MakeFunctionCallable(method)) {
1177 bool runRelease = false;
1178 // const auto& fgen = /* is_direct ? faceptr.fDirect : */ faceptr;
1179 if (nargs <= cpyrt::SMALL_ARGS_N) {
1180 void* smallbuf[cpyrt::SMALL_ARGS_N];
1181 if (nargs)
1182 runRelease = copy_args(args, nargs, smallbuf);
1183 // CLING_CATCH_UNCAUGHT_
1184 JC.Invoke(result, {smallbuf, nargs}, self);
1185 // _CLING_CATCH_UNCAUGHT
1186 } else {
1187 std::vector<void*> buf(nargs);
1188 runRelease = copy_args(args, nargs, buf.data());
1189 // CLING_CATCH_UNCAUGHT_
1190 JC.Invoke(result, {buf.data(), nargs}, self);
1191 // _CLING_CATCH_UNCAUGHT
1192 }
1193 if (runRelease)
1194 release_args(args, nargs);
1195 return true;
1196 }
1198 return false;
1199}
1200
1201template <typename T>
1203 size_t nargs, void* args) {
1204 T t{};
1205 if (WrapperCall(method, nargs, args, self.data, &t))
1206 return t;
1207 throw std::runtime_error("failed to resolve function");
1208 return (T)-1;
1209}
1210
1211#ifdef PRINT_DEBUG
1212#define _IMP_CALL_PRINT_STMT(type) printf("IMP CALL with type: %s\n", #type);
1213#else
1214#define _IMP_CALL_PRINT_STMT(type)
1215#endif
1216
1217#define CPPJIT_IMP_CALL(typecode, rtype) \
1218 rtype interop::Call##typecode(TCppMethod_t method, TCppObject_t self, \
1219 size_t nargs, void* args) { \
1220 _IMP_CALL_PRINT_STMT(rtype) \
1221 return CallT<rtype>(method, self, nargs, args); \
1222 }
1223
1224void interop::CallV(TCppMethod_t method, TCppObject_t self, size_t nargs,
1225 void* args) {
1226 if (!WrapperCall(method, nargs, args, self.data, nullptr))
1227 return /* TODO ... report error */;
1228}
1229
1230// clang-format off
1231CPPJIT_IMP_CALL(B, unsigned char)
1236CPPJIT_IMP_CALL(LL, long long )
1239CPPJIT_IMP_CALL(LD, long double )
1240// clang-format on
1241
1242void* interop::CallR(TCppMethod_t method, TCppObject_t self, size_t nargs,
1243 void* args) {
1244 void* r = nullptr;
1245 if (WrapperCall(method, nargs, args, self.data, &r))
1246 return r;
1247 return nullptr;
1248}
1249
1250char* interop::CallS(TCppMethod_t method, TCppObject_t self, size_t nargs,
1251 void* args, size_t* length) {
1252 char* cstr = nullptr;
1253 // TClassRef cr("std::string"); // TODO: Why is this required?
1254 std::string* cppresult = (std::string*)malloc(sizeof(std::string));
1255 if (WrapperCall(method, nargs, args, self.data, (void*)cppresult)) {
1256 cstr = cppstring_to_cstring(*cppresult);
1257 *length = cppresult->size();
1258 cppresult->std::string::~basic_string();
1259 } else
1260 *length = 0;
1261 free((void*)cppresult);
1262 return cstr;
1263}
1264
1266 TCppScope_t /*klass*/,
1267 size_t nargs, void* args) {
1268 void* obj = nullptr;
1269 WrapperCall(method, nargs, args, nullptr, &obj);
1270 return (TCppObject_t)obj;
1271}
1272
1274 if (Cpp::JitCall JC = destructor_callable(scope))
1275 JC.InvokeDestructor(self.data, /*nary=*/0, /*withFree=*/false);
1276}
1277
1279 size_t nargs, void* args,
1280 TCppType_t result_type) {
1281 size_t size = interop::SizeOfType(result_type);
1282 if (size == 0)
1283 return TCppObject_t{}; // unsizable return type; the caller reports
1284 void* obj = ::operator new(size);
1285 if (WrapperCall(method, nargs, args, self.data, obj))
1286 return (TCppObject_t)obj;
1287 ::operator delete(obj);
1288 return TCppObject_t{};
1289}
1290
1292 bool /*check_enabled*/) {
1293 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1294 return Cpp::GetFunctionAddress(method);
1295}
1296
1297// handling of function argument buffer --------------------------------------
1299 return new Parameter[nargs];
1300}
1301
1302void interop::DeallocateFunctionArgs(void* args) { delete[] (Parameter*)args; }
1303
1304size_t interop::GetFunctionArgSizeof() { return sizeof(Parameter); }
1305
1307 return offsetof(Parameter, fTypeCode);
1308}
1309
1310// scope reflection information ----------------------------------------------
1312 if (!scope)
1313 return false;
1314
1315 // Test if this scope represents a namespace.
1316 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1317 return Cpp::IsNamespace(scope) || Cpp::GetGlobalScope() == scope;
1318}
1319
1321 // Test if this scope represents a namespace.
1322 return Cpp::IsClass(scope);
1323}
1324//
1326 // Test if this type may not be instantiated.
1327 return Cpp::IsAbstract(scope);
1328}
1329
1330bool interop::IsEnumScope(TCppScope_t scope) { return Cpp::IsEnumScope(scope); }
1331
1333 return Cpp::IsEnumConstant(interop::GetUnderlyingScope(scope));
1334}
1335
1336bool interop::IsEnumType(TCppType_t type) { return Cpp::IsEnumType(type); }
1337
1339 // Test if this type is a "plain old data" type
1340 return Cpp::IsAggregate(type);
1341}
1342
1344 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1345 // Test if this type has a default constructor or is a "plain old data" type
1346 return Cpp::HasDefaultConstructor(scope);
1347}
1348
1349bool interop::IsVariable(TCppScope_t scope) { return Cpp::IsVariable(scope); }
1350
1352 std::set<std::string>& cppnames) {
1353 // Collect all known names of C++ entities under scope. This is useful for
1354 // IDEs employing tab-completion, for example. Note that functions names need
1355 // not be unique as they can be overloaded.
1356 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1357 Cpp::GetAllCppNames(scope, cppnames);
1358}
1359
1360// class reflection information ----------------------------------------------
1361std::vector<interop::TCppScope_t>
1363 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1364 return Cpp::GetUsingNamespaces(scope);
1365}
1366
1367// Normalize a type or scope name to cppyy's canonical form: no space after
1368// the commas separating template arguments, and pointers/references attached
1369// to the type. This is the form cpyrt itself constructs (e.g. when
1370// looking up cached template instantiations by name, see
1371// Utility::ConstructTemplateArgs) and the convention that user code and the
1372// test suite inherited from upstream cppyy; clang's printer instead emits
1373// "a, b", "T *" and "T &".
1374static std::string cppyy_normalize_name(std::string name) {
1375 std::string::size_type pos = 0;
1376 while ((pos = name.find(", ", pos)) != std::string::npos)
1377 name.erase(pos + 1, 1);
1378 pos = 0;
1379 while ((pos = name.find(" *", pos)) != std::string::npos)
1380 name.erase(pos, 1);
1381 pos = 0;
1382 while ((pos = name.find(" &", pos)) != std::string::npos)
1383 name.erase(pos, 1);
1384 return name;
1385}
1386
1387// class reflection information ----------------------------------------------
1389 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1390 return cppyy_normalize_name(
1391 Cpp::GetCompleteName(Cpp::GetUnderlyingScope(klass)));
1392}
1393
1395 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1396 return cppyy_normalize_name(Cpp::GetQualifiedCompleteName(klass));
1397}
1398
1400 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1401 TCppMethod_t func = Cpp::GetDestructor(scope);
1402 return Cpp::IsVirtualMethod(func);
1403}
1404
1406 // Get the total number of base classes that this class has.
1407 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1408 // Autoloading may have registered only a forward declaration of the class;
1409 // complete it, or the proxy is built without its bases.
1410 Cpp::GetOrForceDefinition(klass);
1411 // Cpp::GetNumBases() instantiates a class template specialization with
1412 // diagnostics, printing an error for one that can't be defined, e.g. a
1413 // specialization of a template that is only declared. IsComplete()
1414 // instantiates it silently.
1415 if (!Cpp::IsComplete(klass))
1416 return 0;
1417 return Cpp::GetNumBases(klass);
1418}
1419
1420////////////////////////////////////////////////////////////////////////////////
1421/// \fn interop::TCppIndex_t interop::GetNumBasesLongestBranch(TCppScope_t
1422/// klass) \brief Retrieve number of base classes in the longest branch of the
1423/// inheritance tree of the input class.
1424/// \param[in] klass The class to start the retrieval process from.
1425///
1426/// This is a helper function for interop::GetNumBasesLongestBranch.
1427/// Given an inheritance tree, the function assigns weight 1 to each class that
1428/// has at least one base. Starting from the input class, the function is
1429/// called recursively on all the bases. For each base the return value is one
1430/// (the weight of the base itself) plus the maximum value retrieved for their
1431/// bases in turn. For example, given the following inheritance tree:
1432///
1433/// ~~~{.cpp}
1434/// class A {}; class B: public A {};
1435/// class X {}; class Y: public X {}; class Z: public Y {};
1436/// class C: public B, Z {};
1437/// ~~~
1438///
1439/// calling this function on an instance of `C` will return 3, the steps
1440/// required to go from C to X.
1442 std::vector<size_t> num;
1443 for (TCppIndex_t ibase = 0; ibase < GetNumBases(klass); ++ibase)
1444 num.push_back(
1446 if (num.empty())
1447 return 0;
1448 return *std::max_element(num.begin(), num.end()) + 1;
1449}
1450
1452 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1453 return Cpp::GetName(Cpp::GetBaseClass(klass, ibase));
1454}
1455
1457 TCppIndex_t ibase) {
1458 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1459 return Cpp::GetBaseClass(klass, ibase);
1460}
1461
1463 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1464 // Checked on every method call that receives 'self' as its first argument
1465 // (e.g. from pythonizations and protocol slots), so memoize per class
1466 // pair. A class that is still incomplete can gain bases once its
1467 // definition is loaded, so a negative answer is only cached for complete
1468 // classes.
1469 static std::map<std::pair<const void*, const void*>, bool> s_subclass_cache;
1470 const auto cacheKey = std::make_pair(derived.data, base.data);
1471 auto cached = s_subclass_cache.find(cacheKey);
1472 if (cached != s_subclass_cache.end())
1473 return cached->second;
1474 bool result = Cpp::IsSubclass(derived, base);
1475 if (result || (Cpp::IsComplete(derived) && Cpp::IsComplete(base)))
1476 s_subclass_cache.emplace(cacheKey, result);
1477 return result;
1478}
1479
1480static std::set<std::string> gSmartPtrTypes = {
1481 "std::auto_ptr", "std::shared_ptr", "std::unique_ptr", "std::weak_ptr"};
1482
1484 const std::string& rn = interop::GetScopedFinalName(klass);
1485 if (gSmartPtrTypes.find(rn.substr(0, rn.find("<"))) != gSmartPtrTypes.end())
1486 return true;
1487 return false;
1488}
1489
1491 TCppMethod_t* deref) {
1493 if (!scope || !interop::IsSmartPtr(scope))
1494 return false;
1495
1496 if (!raw && !deref)
1497 return true;
1498
1499 std::vector<TCppMethod_t> ops;
1500 {
1501 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1502 // the operator can only be found once the specialization is instantiated
1503 if (!Cpp::IsComplete(scope))
1504 return false;
1505 Cpp::GetOperator(scope, Cpp::Operator::OP_Arrow, ops,
1506 /*kind=*/Cpp::OperatorArity::kBoth);
1507 if (ops.size() != 1)
1508 return false;
1509
1510 // The dereference operator can be a member template: MSVC's
1511 // std::shared_ptr::operator-> is SFINAE-constrained on the element
1512 // type not being an array. Its return type is dependent, so it has
1513 // to be instantiated (it takes no arguments) before the pointee
1514 // type can be determined - and before it can be called.
1515 if (Cpp::IsTemplatedFunction(ops[0]))
1516 ops[0] = Cpp::BestOverloadFunctionMatch(ops, {}, {});
1517 if (!ops[0])
1518 return false;
1519 }
1520
1521 if (deref)
1522 *deref = ops[0];
1523 if (raw)
1525 return (!deref || *deref) && (!raw || *raw);
1526}
1527
1528// type offsets --------------------------------------------------------------
1530 TCppObject_t address, int direction,
1531 bool rerror) {
1532 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1533
1534 // Up-casts may start from a subobject whose complete type is unknown. For
1535 // down-casts, callers obtain the complete type with GetActualClass, so use
1536 // its static layout; address points to the base rather than the derived type.
1537 const void* object = direction > 0 ? address.data : nullptr;
1538
1539 // Queried for every downcast object handed to Python; computing it walks
1540 // the inheritance paths, so memoize per class pair. Only the static layout
1541 // (no object address) is fixed per pair once both records are complete; an
1542 // offset read from the object's vtable is not cached.
1543 static std::map<std::pair<const void*, const void*>, intptr_t>
1544 s_base_offset_cache;
1545 const auto cacheKey = std::make_pair(derived.data, base.data);
1546 auto cached =
1547 object ? s_base_offset_cache.end() : s_base_offset_cache.find(cacheKey);
1548 intptr_t offset = 0;
1549 if (cached != s_base_offset_cache.end()) {
1550 offset = cached->second;
1551 } else {
1552 // An incomplete record has no walkable bases (GetBaseClassOffset would
1553 // read an empty base path), and the answer may change once the
1554 // definition is loaded, so treat it like the error case below and retry
1555 // next time instead of caching.
1556 if (!Cpp::IsComplete(derived) || !Cpp::IsComplete(base))
1557 return rerror ? (ptrdiff_t)-1 : 0;
1558
1559 offset = Cpp::GetBaseClassOffset(derived, base, object);
1560
1561 if (offset == -1) // Cling error, treat silently
1562 return rerror ? (ptrdiff_t)offset : 0;
1563
1564 if (!object)
1565 s_base_offset_cache.emplace(cacheKey, offset);
1566 }
1567
1568 return (ptrdiff_t)(direction < 0 ? -offset : offset);
1569}
1570
1571// method/function reflection information ------------------------------------
1572// A deleted overload is not callable, and leaving it in the set adds a
1573// spurious conversion error to every failed-call report.
1574static void
1575remove_deleted_methods(std::vector<interop::TCppMethod_t>& methods) {
1576 methods.erase(std::remove_if(methods.begin(), methods.end(),
1578 return Cpp::IsFunctionDeleted(m);
1579 }),
1580 methods.end());
1581}
1582
1584 std::vector<interop::TCppMethod_t>& methods) {
1585 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1586 Cpp::GetClassMethods(scope, methods);
1587 remove_deleted_methods(methods);
1588}
1589
1590std::vector<interop::TCppMethod_t>
1592 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1593 std::vector<interop::TCppMethod_t> methods =
1594 Cpp::GetFunctionsUsingName(scope, name);
1595 remove_deleted_methods(methods);
1596 return methods;
1597}
1598
1599std::string interop::GetName(TCppScope_t method) {
1600 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1601 return Cpp::GetName(method);
1602}
1603
1605 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1606 return cppyy_normalize_name(Cpp::GetCompleteName(method));
1607}
1608
1610 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1611 return Cpp::GetFunctionReturnType(method);
1612}
1613
1615 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1616 TCppType_t ret = Cpp::GetCanonicalType(Cpp::GetFunctionReturnType(method));
1617 // C++ deletes top-level cv-qualifiers on non-class return types from the
1618 // function type ([dcl.fct]); mirror that so name matching sees the plain
1619 // type, e.g. "unsigned long" for `static const size_t size()`. Class
1620 // types keep the qualifier: it stays part of the function type there
1621 // (e.g. for override matching in the dispatcher).
1622 if (ret && !Cpp::IsRecordType(ret))
1623 ret = Cpp::RemoveTypeQualifier(ret,
1624 Cpp::QualKind::Const | Cpp::QualKind::Volatile);
1625 return Cpp::GetTypeAsString(ret);
1626}
1627
1629 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1630 return Cpp::GetFunctionNumArgs(method);
1631}
1632
1634 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1635 return Cpp::GetFunctionRequiredArgs(method);
1636}
1637
1639 if (!method)
1640 return "<unknown>";
1641
1642 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1643 return Cpp::GetFunctionArgName(method, iarg);
1644}
1645
1647 TCppIndex_t iarg) {
1648 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1649 return Cpp::GetFunctionArgType(method, iarg);
1650}
1651
1653 TCppIndex_t iarg) {
1654 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1655 return Cpp::GetTypeAsString(Cpp::RemoveTypeQualifier(
1656 Cpp::GetFunctionArgType(method, iarg), Cpp::QualKind::Const));
1657}
1658
1660 TCppIndex_t iarg) {
1661 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1662 return Cpp::GetTypeAsString(
1663 Cpp::GetCanonicalType(Cpp::GetFunctionArgType(method, iarg)));
1664}
1665
1667 TCppIndex_t iarg) {
1668 if (!method)
1669 return "";
1670
1671 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1672 return Cpp::GetFunctionArgDefault(method, iarg);
1673}
1674
1677 const std::string& /*req_type*/) {
1678 // if (method) {
1679 // TFunction* f = m2f(method);
1680 // TMethodArg* arg = (TMethodArg
1681 // *)f->GetListOfMethodArgs()->At((int)iarg); void *argqtp =
1682 // gInterpreter->TypeInfo_QualTypePtr(arg->GetTypeInfo());
1683
1684 // TypeInfo_t *reqti = gInterpreter->TypeInfo_Factory(req_type.c_str());
1685 // void *reqqtp = gInterpreter->TypeInfo_QualTypePtr(reqti);
1686
1687 // if (ArgSimilarityScore(argqtp, reqqtp) < 10) {
1688 // return ArgSimilarityScore(argqtp, reqqtp);
1689 // }
1690 // else { // Match using underlying types
1691 // if(gInterpreter->IsPointerType(argqtp))
1692 // argqtp =
1693 // gInterpreter->TypeInfo_QualTypePtr(gInterpreter->GetPointerType(argqtp));
1694
1695 // // Handles reference types and strips qualifiers
1696 // TypeInfo_t *arg_ul = gInterpreter->GetNonReferenceType(argqtp);
1697 // TypeInfo_t *req_ul = gInterpreter->GetNonReferenceType(reqqtp);
1698 // argqtp =
1699 // gInterpreter->TypeInfo_QualTypePtr(gInterpreter->GetUnqualifiedType(gInterpreter->TypeInfo_QualTypePtr(arg_ul)));
1700 // reqqtp =
1701 // gInterpreter->TypeInfo_QualTypePtr(gInterpreter->GetUnqualifiedType(gInterpreter->TypeInfo_QualTypePtr(req_ul)));
1702
1703 // return ArgSimilarityScore(argqtp, reqqtp);
1704 // }
1705 // }
1706 return 0; // Method is not valid
1707}
1708
1710 bool show_formal_args,
1711 TCppIndex_t max_args) {
1712 std::ostringstream sig;
1713 sig << "(";
1714 int nArgs = GetMethodNumArgs(method);
1715 if (max_args != (TCppIndex_t)-1)
1716 nArgs = std::min(nArgs, (int)max_args);
1717 for (int iarg = 0; iarg < nArgs; ++iarg) {
1718 sig << cppyy_normalize_name(
1719 interop::GetMethodArgTypeAsString(method, iarg));
1720 if (show_formal_args) {
1721 std::string argname = interop::GetMethodArgName(method, iarg);
1722 if (!argname.empty())
1723 sig << " " << argname;
1724 std::string defvalue = interop::GetMethodArgDefault(method, iarg);
1725 if (!defvalue.empty())
1726 sig << " = " << defvalue;
1727 }
1728 if (iarg != nArgs - 1)
1729 sig << ", ";
1730 }
1731 sig << ")";
1732 return sig.str();
1733}
1734
1736 fn_type = Cpp::IsReferenceType(fn_type) ? Cpp::GetNonReferenceType(fn_type)
1737 : fn_type;
1738 fn_type =
1739 Cpp::IsPointerType(fn_type) ? Cpp::GetPointeeType(fn_type) : fn_type;
1740 TCppScope_t scope = Cpp::GetScopeFromType(fn_type);
1741 std::vector<Cpp::TemplateArgInfo> args;
1742 Cpp::GetClassTemplateArgs(scope, args);
1743 assert(args.size() == 1);
1744 if (args.size() == 1)
1745 return args[0].m_Type;
1746 return nullptr;
1747}
1748
1750 std::vector<TCppType_t>& arg_types) {
1751 if (!fn_type)
1752 return;
1753 fn_type = Cpp::IsReferenceType(fn_type) ? Cpp::GetNonReferenceType(fn_type)
1754 : fn_type;
1755 fn_type =
1756 Cpp::IsPointerType(fn_type) ? Cpp::GetPointeeType(fn_type) : fn_type;
1757 // Cpp::GetFnTypeSignature() requires a function prototype: anything else
1758 // (e.g. a member function pointer, or a plain object type) yields nothing
1759 if (!Cpp::IsFunctionProtoType(fn_type))
1760 return;
1761 Cpp::GetFnTypeSignature(fn_type, arg_types);
1762}
1763
1764bool interop::GetFnTypeSigAsString(TCppType_t fn_type, std::string& ret_type,
1765 std::string& signature) {
1766 // the first entry is the return type, followed by the argument types
1767 std::vector<TCppType_t> types;
1768 GetFnTypeSig(fn_type, types);
1769 if (types.empty())
1770 return false;
1771
1772 ret_type = GetTypeAsString(types[0]);
1773
1774 std::ostringstream sig;
1775 sig << "(";
1776 for (std::size_t iarg = 1; iarg < types.size(); ++iarg) {
1777 if (iarg != 1)
1778 sig << ", ";
1779 sig << GetTypeAsString(types[iarg]);
1780 }
1781 sig << ")";
1782 signature = sig.str();
1783 return true;
1784}
1785
1787 return Cpp::IsSameType(typ1, typ2);
1788}
1789
1791 typ = Cpp::IsReferenceType(typ) ? Cpp::GetNonReferenceType(typ) : typ;
1792 typ = Cpp::IsPointerType(typ) ? Cpp::GetPointeeType(typ) : typ;
1793 return Cpp::IsFunctionProtoType(typ);
1794}
1795
1797 typ1 = Cpp::IsReferenceType(typ1) ? Cpp::GetNonReferenceType(typ1) : typ1;
1798 typ2 = Cpp::IsReferenceType(typ2) ? Cpp::GetNonReferenceType(typ2) : typ2;
1799 typ1 = Cpp::IsPointerType(typ1) ? Cpp::GetPointeeType(typ1) : typ1;
1800 typ2 = Cpp::IsPointerType(typ2) ? Cpp::GetPointeeType(typ2) : typ2;
1801 return Cpp::IsSameType(typ1, typ2);
1802}
1803
1804std::string interop::GetDoxygenComment(TCppScope_t scope, bool strip_markers) {
1805 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1806 return Cpp::GetDoxygenComment(scope, strip_markers);
1807}
1808
1810 if (!method)
1811 return false;
1812 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1813 return Cpp::IsConstMethod(method);
1814}
1815
1817 std::vector<interop::TCppMethod_t>& methods) {
1818 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1819 Cpp::GetFunctionTemplatedDecls(scope, methods);
1820}
1821
1823interop::GetNumTemplatedMethods(TCppScope_t scope, bool /*accept_namespace*/) {
1824 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1825 std::vector<interop::TCppMethod_t> mc;
1826 Cpp::GetFunctionTemplatedDecls(scope, mc);
1827 return mc.size();
1828}
1829
1831 TCppIndex_t imeth) {
1832 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1833 std::vector<interop::TCppMethod_t> mc;
1834 Cpp::GetFunctionTemplatedDecls(scope, mc);
1835
1836 if (imeth < mc.size())
1837 return Cpp::GetName(TCppScope_t(mc[imeth].data));
1838
1839 return "";
1840}
1841
1842bool interop::ExistsMethodTemplate(TCppScope_t scope, const std::string& name) {
1843 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1844 return Cpp::ExistsFunctionTemplate(name, scope);
1845}
1846
1848 return Cpp::IsTemplatedFunction(method);
1849}
1850
1851bool interop::IsStaticTemplate(TCppScope_t scope, const std::string& name) {
1852 std::vector<TCppMethod_t> candidate_methods;
1853 Cpp::GetClassTemplatedMethods(name, scope, candidate_methods);
1854 bool is_static = true;
1855 for (auto i : candidate_methods) {
1856 if (!Cpp::IsStaticMethod(i)) {
1857 is_static = false;
1858 break;
1859 }
1860 }
1861 return is_static;
1862}
1863
1865 const std::string& name,
1866 const std::string& proto) {
1867 std::string pureName;
1868 std::string explicit_params;
1869
1870 if ((name.find("operator<") != 0) && (name.find('<') != std::string::npos)) {
1871 pureName = name.substr(0, name.find('<'));
1872 size_t start = name.find('<');
1873 size_t end = name.rfind('>');
1874 explicit_params = name.substr(start + 1, end - start - 1);
1875 } else {
1876 pureName = name;
1877 }
1878
1879 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1880
1881 std::vector<interop::TCppMethod_t> unresolved_candidate_methods;
1882 Cpp::GetClassTemplatedMethods(pureName, scope, unresolved_candidate_methods);
1883 if (unresolved_candidate_methods.empty() && name.find("operator") == 0) {
1884 // try operators
1885 interop::GetClassOperators(scope, pureName, unresolved_candidate_methods);
1886 }
1887
1888 // cpyrt assumes that we attempt instantiation here
1889 std::vector<Cpp::TemplateArgInfo> arg_types;
1890 std::vector<Cpp::TemplateArgInfo> templ_params;
1891 interop::AppendTypesSlow(proto, arg_types, scope);
1892 interop::AppendTypesSlow(explicit_params, templ_params, scope);
1893 interop::TCppMethod_t cppmeth = nullptr;
1894 cppmeth = Cpp::BestOverloadFunctionMatch(unresolved_candidate_methods,
1895 templ_params, arg_types);
1896
1897 // If overload resolution failed but explicit template arguments were
1898 // supplied, fall back to direct template-argument substitution: ask Sema
1899 // to instantiate each candidate with the explicit args. Sema's SFINAE
1900 // rejects overloads whose substitution fails (e.g. the initializer_list
1901 // form of std::make_any with non-init-list explicit args), so iterating
1902 // gives back exactly the viable specialisation. The wrapper-side argument
1903 // conversion then handles e.g. taking the address of an instance when the
1904 // substituted parameter is a pointer.
1905 if (!cppmeth && !templ_params.empty()) {
1906 for (const auto& cand : unresolved_candidate_methods) {
1907 if (Cpp::DeclRef spec = Cpp::InstantiateTemplate(
1908 TCppScope_t(cand.data), templ_params.data(), templ_params.size(),
1909 /*instantiate_body=*/false)) {
1910 cppmeth = spec.data;
1911 break;
1912 }
1913 }
1914 }
1915
1916 return TCppMethod_t(cppmeth.data);
1917 // if it fails, use Sema to propogate info about why it failed (DeductionInfo)
1918}
1919
1920static inline bool is_basic_string_of(const std::string& n, const char* charT) {
1921 // Match "std::basic_string<charT" whether or not the default template
1922 // arguments (char_traits, allocator) are spelled out; the character type
1923 // must be followed by ',' or '>' so that e.g. "char" does not match
1924 // "char16_t".
1925 std::string prefix = "std::basic_string<";
1926 prefix += charT;
1927 if (n.compare(0, prefix.size(), prefix) != 0)
1928 return false;
1929 return n.size() > prefix.size() &&
1930 (n[prefix.size()] == ',' || n[prefix.size()] == '>');
1931}
1932
1933static inline std::string type_remap(const std::string& n1,
1934 const std::string& n2) {
1935 // Operator lookups of (C++ string, Python str) should succeed for the
1936 // combos of string/str, wstring/str, string/unicode and wstring/unicode;
1937 // since C++ does not have a operator+(std::string, std::wstring), we'll
1938 // have to look up the same type and rely on the converters in
1939 // cpyrt/_cppjit.
1940 if (n1 == "str" || n1 == "unicode" || is_basic_string_of(n1, "char")) {
1941 if (is_basic_string_of(n2, "wchar_t"))
1942 return "std::basic_string<wchar_t>&"; // match like for like
1943 return "std::basic_string<char>&"; // probably best bet
1944 } else if (is_basic_string_of(n1, "wchar_t")) {
1945 return "std::basic_string<wchar_t>&";
1946 } else if (n1 == "complex") {
1947 return "std::complex<double>";
1948 }
1949 return n1;
1950}
1951
1953 const std::string& opname,
1954 std::vector<TCppMethod_t>& operators) {
1955 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
1956 std::string op = opname.substr(8);
1957 Cpp::GetOperator(klass, Cpp::GetOperatorFromSpelling(op), operators,
1958 /*kind=*/Cpp::OperatorArity::kBoth);
1959}
1960
1962 const std::string& lc,
1963 const std::string& rc,
1964 const std::string& opname) {
1965 std::string rc_type = type_remap(rc, lc);
1966 std::string lc_type = type_remap(lc, rc);
1967
1968 std::vector<TCppMethod_t> overloads;
1969 Cpp::GetOperator(scope, Cpp::GetOperatorFromSpelling(opname), overloads,
1970 /*kind=*/Cpp::OperatorArity::kBoth);
1971
1972 // Avoid pushing nullptr into arg_types which would crash
1973 // BestOverloadFunctionMatch when it dereferences each entry's QualType.
1974 auto resolve_arg_type = [](const std::string& name) -> interop::TCppType_t {
1975 if (auto s = interop::GetScope(name))
1976 if (auto t = interop::GetTypeFromScope(s))
1978 return interop::GetType(name, /*enable_slow_lookup=*/true);
1979 };
1980
1981 std::vector<Cpp::TemplateArgInfo> arg_types;
1982 if (auto l = resolve_arg_type(lc_type))
1983 arg_types.emplace_back(l.data);
1984 else
1985 return nullptr;
1986
1987 if (!rc_type.empty()) {
1988 if (auto r = resolve_arg_type(rc_type))
1989 arg_types.emplace_back(r.data);
1990 else
1991 return nullptr;
1992 }
1993 interop::TCppMethod_t cppmeth =
1994 Cpp::BestOverloadFunctionMatch(overloads, {}, arg_types);
1995 if (cppmeth)
1996 return cppmeth;
1997 return nullptr;
1998}
1999
2000// method properties ---------------------------------------------------------
2002 return Cpp::IsFunctionDeleted(method);
2003}
2004
2006 return Cpp::IsPublicMethod(method);
2007}
2008
2010 return Cpp::IsProtectedMethod(method);
2011}
2012
2014 return Cpp::IsPrivateMethod(method);
2015}
2016
2018 return Cpp::IsConstructor(method);
2019}
2020
2022 return Cpp::IsDestructor(method);
2023}
2024
2026 return Cpp::IsStaticMethod(method);
2027}
2028
2030 return Cpp::IsExplicit(method);
2031}
2032
2033// data member reflection information ----------------------------------------
2035 std::vector<TCppScope_t>& datamembers) {
2036 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
2037 Cpp::GetDatamembers(scope, datamembers);
2038 Cpp::GetStaticDatamembers(scope, datamembers);
2039 Cpp::GetEnumConstantDatamembers(scope, datamembers, false);
2040}
2041
2042bool interop::CheckDatamember(TCppScope_t scope, const std::string& name) {
2043 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
2044 return (bool)Cpp::LookupDatamember(name, scope);
2045}
2046
2048 return Cpp::IsLambdaClass(type);
2049}
2050
2052 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
2053 std::ostringstream code;
2054 std::string name = interop::GetFinalName(var);
2055 code << "namespace __cppjit_internal_wrap_g {\n"
2056 << " " << "std::function " << name
2057 << " = ::" << Cpp::GetQualifiedName(var) << ";\n"
2058 << "}\n";
2059
2060 if (interop::Compile(code.str().c_str())) {
2061 TCppScope_t res = Cpp::GetNamed(
2062 name, Cpp::GetScope("__cppjit_internal_wrap_g", /*parent=*/nullptr));
2063 if (res)
2064 return res;
2065 }
2066 return var;
2067}
2068
2071 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
2072
2073 std::string fn_name = Cpp::GetQualifiedCompleteName(TCppScope_t(fn.data));
2074 std::string signature = interop::GetMethodSignature(fn, true);
2075
2076 std::ostringstream call;
2077 call << "(";
2078 for (size_t i = 0, n = interop::GetMethodNumArgs(fn); i < n; i++) {
2079 call << interop::GetMethodArgName(fn, i);
2080 if (i != n - 1)
2081 call << ", ";
2082 }
2083 call << ")";
2084
2085 std::ostringstream code;
2086 static int i = 0;
2087 std::string name = "lambda_return_convert_" + std::to_string(++i);
2088 code << "namespace __cppjit_internal_wrap_g {\n"
2089 << "auto " << name << signature << "{" << "return std::function("
2090 << fn_name << call.str() << "); }\n"
2091 << "}\n";
2092 if (interop::Compile(code.str().c_str())) {
2093 TCppScope_t res = Cpp::GetNamed(
2094 name, Cpp::GetScope("__cppjit_internal_wrap_g", /*parent=*/nullptr));
2095 if (res)
2096 return TCppMethod_t(res.data);
2097 }
2098 return fn;
2099}
2100
2102 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
2103 return Cpp::GetVariableType(Cpp::GetUnderlyingScope(var));
2104}
2105
2107 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
2108 return Cpp::GetTypeAsString(
2109 Cpp::GetVariableType(Cpp::GetUnderlyingScope(scope)));
2110}
2111
2113 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
2114 return Cpp::GetTypeAsString(type);
2115}
2116
2118 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
2119 return Cpp::GetVariableOffset(Cpp::GetUnderlyingScope(var), klass);
2120}
2121
2122// data member properties ----------------------------------------------------
2124 return Cpp::IsPublicVariable(datamem);
2125}
2126
2128 return Cpp::IsProtectedVariable(datamem);
2129}
2130
2132 return Cpp::IsPrivateVariable(datamem);
2133}
2134
2136 return Cpp::IsStaticVariable(interop::GetUnderlyingScope(var));
2137}
2138
2139bool interop::IsConstVar(TCppScope_t var) { return Cpp::IsConstVariable(var); }
2140
2142 TCppType_t reduce) {
2143 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
2144
2145 std::string fn_name = Cpp::GetQualifiedCompleteName(TCppScope_t(fn.data));
2146 std::string signature = interop::GetMethodSignature(fn, true);
2147 std::string result_type = interop::GetTypeAsString(reduce);
2148
2149 std::ostringstream call;
2150 call << "(";
2151 for (size_t i = 0, n = interop::GetMethodNumArgs(fn); i < n; i++) {
2152 call << interop::GetMethodArgName(fn, i);
2153 if (i != n - 1)
2154 call << ", ";
2155 }
2156 call << ")";
2157
2158 std::ostringstream code;
2159 static int i = 0;
2160 std::string name = "reduced_function_" + std::to_string(++i);
2161 code << "namespace __cppjit_internal_wrap_g {\n"
2162 << result_type << " " << name << signature << "{" << "return ("
2163 << result_type << ")::" << fn_name << call.str() << "; }\n"
2164 << "}\n";
2165 if (interop::Compile(code.str().c_str())) {
2166 TCppScope_t res = Cpp::GetNamed(
2167 name, Cpp::GetScope("__cppjit_internal_wrap_g", /*parent=*/nullptr));
2168 if (res)
2169 return TCppMethod_t(res.data);
2170 }
2171 return fn;
2172}
2173
2175 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
2176 return Cpp::GetDimensions(type);
2177}
2178
2179// enum properties -----------------------------------------------------------
2180std::vector<interop::TCppScope_t> interop::GetEnumConstants(TCppScope_t scope) {
2181 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
2182 return Cpp::GetEnumConstants(scope);
2183}
2184
2186 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
2187 return Cpp::GetEnumConstantType(Cpp::GetUnderlyingScope(scope));
2188}
2189
2191 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
2192 return Cpp::GetEnumConstantValue(scope);
2193}
2194
2196 Cpp::TemplateArgInfo* args,
2197 size_t args_size) {
2198 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
2199 return Cpp::InstantiateTemplate(tmpl, args, args_size,
2200 /*instantiate_body=*/false);
2201}
2202
2204 std::lock_guard<RInterOpMutex> Lock(InterOpMutex);
2205 Cpp::DumpScope(scope);
2206}
free(fBuffer)
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
static Roo_reg_AGKInteg1D instance
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
static void GetTypeAsString(QualType QT, string &type_name, ASTContext &C, PrintingPolicy Policy)
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h 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 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 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 Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:142
R__EXTERN TVirtualMutex * gInterpreterMutex
#define gInterpreter
#define gROOT
Definition TROOT.h:417
R__EXTERN TSystem * gSystem
Definition TSystem.h:582
std::recursive_mutex fLocal
static thread_local std::vector< TVirtualMutex * > fGlobalLocked
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:2999
static const TString & GetEtcDir()
Get the sysconfig directory in the installation. Static utility function.
Definition TROOT.cxx:3397
const char * Data() const
Definition TString.h:385
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition TSystem.cxx:1318
char * DynamicPathName(const char *lib, Bool_t quiet=kFALSE)
Find a dynamic library called lib using the system search paths.
Definition TSystem.cxx:2042
This class implements a mutex interface.
virtual Int_t UnLock()=0
virtual Int_t Lock()=0
TLine * line
std::string trim(const std::string &line)
static std::string type_remap(const std::string &n1, const std::string &n2)
static bool is_identifier(std::string_view s)
static bool copy_args(Parameter *args, size_t nargs, void **vargs)
interop::TCppType_t int_like_type(interop::TCppType_t type)
static std::set< std::string > gSmartPtrTypes
interop::TCppScope_t GetEnumFromCompleteName(const std::string &name)
static char * cppstring_to_cstring(const std::string &cppstr)
static void release_args(Parameter *args, size_t nargs)
static bool WrapperCall(interop::TCppMethod_t method, size_t nargs, void *args_, void *self, void *result)
static std::set< std::string > g_builtins
cppjit::cpyrt::Parameter Parameter
static bool is_basic_string_of(const std::string &n, const char *charT)
static bool gEnableFastPath
static T CallT(interop::TCppMethod_t method, interop::TCppObject_t self, size_t nargs, void *args)
static void remove_deleted_methods(std::vector< interop::TCppMethod_t > &methods)
#define CPPJIT_IMP_CALL(typecode, rtype)
static Cpp::JitCall destructor_callable(interop::TCppScope_t scope)
bool split_comma_saparated_types(const std::string &name, std::vector< std::string > &types)
static size_t CALL_NARGS(size_t nargs)
int LoadCppInterOp()
static std::string cppyy_normalize_name(std::string name)
RInterOpMutex InterOpMutex
const Int_t n
Definition legend1.C:16
TROOT * GetROOT()
Definition TROOT.cxx:550
const int SMALL_ARGS_N
Definition callcontext.h:14
bool IsConstVar(TCppScope_t var)
Cpp::TypeRef TCppType_t
Definition API.h:42
TCppScope_t GetFullScope(const std::string &scope_name)
void GetDatamembers(TCppScope_t scope, std::vector< TCppScope_t > &datamembers)
Cpp::ObjectRef TCppObject_t
Definition API.h:43
TCppType_t GetTypeFromScope(TCppScope_t klass)
std::string GetTypeAsString(TCppType_t type)
TCppType_t GetDatamemberType(TCppScope_t data)
TCppType_t ResolveEnumPointerType(TCppType_t type)
bool ExistsMethodTemplate(TCppScope_t scope, const std::string &name)
bool IsFunctionType(TCppType_t typ)
TCppScope_t WrapLambdaFromVariable(TCppScope_t var)
void DeallocateFunctionArgs(void *args)
bool IsBuiltin(const std::string &type_name)
void CallV(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args)
std::string GetName(TCppScope_t)
std::string ToString(TCppScope_t klass, TCppObject_t obj)
bool IsClassType(TCppType_t type)
void CallDestructor(TCppScope_t type, TCppObject_t self)
bool CheckDatamember(TCppScope_t scope, const std::string &name)
TCppMethod_t GetMethodTemplate(TCppScope_t scope, const std::string &name, const std::string &proto)
bool IsTemplateInstantiation(TCppScope_t scope)
TCppMethod_t AdaptFunctionForLambdaReturn(TCppMethod_t fn)
bool IsStaticTemplate(TCppScope_t scope, const std::string &name)
bool IsConstructor(TCppMethod_t method)
std::string GetMethodArgCanonTypeAsString(TCppMethod_t method, TCppIndex_t iarg)
bool HasVirtualDestructor(TCppScope_t type)
TCppIndex_t GetNumTemplatedMethods(TCppScope_t scope, bool accept_namespace=false)
TCppScope_t GetActualClass(TCppScope_t klass, TCppObject_t obj)
void GetTemplatedMethods(TCppScope_t scope, std::vector< TCppMethod_t > &methods)
std::string ResolveName(const std::string &cppitem_name)
std::string GetMethodArgTypeAsString(TCppMethod_t method, TCppIndex_t iarg)
TCppIndex_t GetMethodReqArgs(TCppMethod_t)
bool AppendTypesSlow(const std::string &name, std::vector< Cpp::TemplateArgInfo > &types, TCppScope_t parent=nullptr)
bool IsAbstract(TCppScope_t scope)
TCppScope_t GetParentScope(TCppScope_t scope)
std::string GetMethodReturnTypeAsString(TCppMethod_t)
TCppType_t GetReferencedType(TCppType_t type, bool rvalue=false)
TCppIndex_t GetMethodNumArgs(TCppMethod_t)
bool IsStaticDatamember(TCppScope_t var)
bool IsProtectedMethod(TCppMethod_t method)
Cpp::InterpRef TInterp_t
bool IsClass(TCppScope_t scope)
bool GetFnTypeSigAsString(TCppType_t fn_type, std::string &ret_type, std::string &signature)
Spells out a function type, or a pointer or reference to one, as the return type and the parenthesize...
void Destruct(TCppScope_t scope, TCppObject_t instance)
TCppIndex_t GetNumBases(TCppScope_t klass)
TCppIndex_t CompareMethodArgType(TCppMethod_t, TCppIndex_t iarg, const std::string &req_type)
bool IsSubclass(TCppScope_t derived, TCppScope_t base)
TCppScope_t GetNamed(const std::string &scope_name, TCppScope_t parent_scope=TCppScope_t{})
intptr_t GetDatamemberOffset(TCppScope_t var, TCppScope_t klass=nullptr)
size_t SizeOfType(TCppType_t type)
Cpp::FuncRef TCppMethod_t
Definition API.h:44
bool IsPublicData(TCppScope_t var)
TCppType_t GetMethodArgType(TCppMethod_t, TCppIndex_t iarg)
TCppScope_t GetBaseScope(TCppScope_t klass, TCppIndex_t ibase)
bool IsIntegerType(TCppType_t type, bool *is_signed=nullptr)
bool IsFunctionPointerType(TCppType_t type)
bool IsTypedefed(TCppScope_t scope)
bool IsPrivateMethod(TCppMethod_t method)
TCppObject_t Allocate(TCppScope_t scope)
bool IsEnumScope(TCppScope_t scope)
bool IsSimilarFnTypes(TCppType_t typ1, TCppType_t typ2)
void GetClassMethods(TCppScope_t scope, std::vector< TCppMethod_t > &methods)
TCppMethod_t GetGlobalOperator(TCppScope_t scope, const std::string &lc, const std::string &rc, const std::string &op)
bool GetSmartPtrInfo(TCppScope_t klass, TCppScope_t *raw, TCppMethod_t *deref)
TCppMethod_t ReduceReturnType(TCppMethod_t fn, TCppType_t reduce)
void * AllocateFunctionArgs(size_t nargs)
void GetClassOperators(TCppScope_t klass, const std::string &opname, std::vector< TCppMethod_t > &operators)
TCppObject_t CallO(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args, TCppType_t result_type)
bool IsPointerType(TCppType_t type)
std::string GetMethodArgName(TCppMethod_t, TCppIndex_t iarg)
void GetFnTypeSig(TCppType_t fn_type, std::vector< TCppType_t > &arg_types)
TCppFuncAddr_t GetFunctionAddress(TCppMethod_t method, bool check_enabled=true)
long long GetEnumDataValue(TCppScope_t scope)
size_t SizeOf(TCppScope_t klass)
std::string GetDoxygenComment(TCppScope_t scope, bool strip_markers=true)
TCppType_t GetMethodReturnType(TCppMethod_t)
TCppType_t ResolveType(TCppType_t cppitem_name)
TCppScope_t GetUnderlyingScope(TCppScope_t scope)
std::string GetMethodSignature(TCppMethod_t, bool show_formal_args, TCppIndex_t max_args=(TCppIndex_t) -1)
bool IsExplicit(TCppMethod_t method)
TCppScope_t GetGlobalScope()
std::string GetTemplatedMethodName(TCppScope_t scope, TCppIndex_t imeth)
bool IsVisibleName(const std::string &name, TCppScope_t parent_scope=TCppScope_t{})
std::string GetFullName(TCppScope_t)
TCppScope_t GetTypeScope(TCppScope_t klass)
bool IsTemplate(TCppScope_t scope)
bool IsDestructor(TCppMethod_t method)
std::vector< TCppScope_t > GetEnumConstants(TCppScope_t scope)
bool Compile(const std::string &code, bool silent=false)
TCppType_t GetPointerType(TCppType_t type)
std::vector< TCppMethod_t > GetMethodsFromName(TCppScope_t scope, const std::string &name)
std::string ResolveEnum(TCppScope_t enum_scope)
size_t TCppIndex_t
Definition API.h:45
bool IsDefaultConstructable(TCppScope_t scope)
TCppObject_t CallConstructor(TCppMethod_t method, TCppScope_t klass, size_t nargs, void *args)
bool IsDeletedMethod(TCppMethod_t method)
bool IsLValueReferenceType(TCppType_t type)
bool IsNamespace(TCppScope_t scope)
bool IsTemplatedMethod(TCppMethod_t method)
void DumpScope(TCppScope_t scope)
TCppScope_t GetScopeFromType(TCppType_t type)
TCppType_t GetFnTypeFromStdFn(TCppType_t fn_type)
std::string GetBaseName(TCppScope_t klass, TCppIndex_t ibase)
TCppType_t GetRealType(TCppType_t type)
TCppIndex_t GetNumBasesLongestBranch(TCppScope_t klass)
TCppScope_t GetScope(const std::string &scope_name, TCppScope_t parent_scope=TCppScope_t{})
TCppType_t GetEnumConstantType(TCppScope_t scope)
bool IsSameType(TCppType_t typ1, TCppType_t typ2)
bool IsEnumConstant(TCppScope_t scope)
std::string GetFinalName(TCppScope_t type)
bool IsProtectedData(TCppScope_t var)
bool IsLambdaClass(TCppType_t type)
bool IsConstMethod(TCppMethod_t)
ptrdiff_t GetBaseOffset(TCppScope_t derived, TCppScope_t base, TCppObject_t address, int direction, bool rerror=false)
TCppObject_t Construct(TCppScope_t scope, void *arena=nullptr)
bool IsPrivateData(TCppScope_t var)
void Deallocate(TCppScope_t scope, TCppObject_t instance)
void * TCppFuncAddr_t
Definition API.h:46
bool IsMutablePtrRefType(TCppType_t type)
bool IsVariable(TCppScope_t scope)
bool IsSmartPtr(TCppScope_t klass)
std::string GetMethodArgDefault(TCppMethod_t, TCppIndex_t iarg)
bool IsStaticMethod(TCppMethod_t method)
char * CallS(TCppMethod_t method, TCppObject_t self, size_t nargs, void *args, size_t *length)
bool IsRValueReferenceType(TCppType_t type)
TCppType_t GetComplexType(const std::string &element_type)
std::vector< TCppScope_t > GetUsingNamespaces(TCppScope_t)
bool IsPublicMethod(TCppMethod_t method)
TCppType_t GetType(const std::string &name, bool enable_slow_lookup=false)
bool IsAggregate(TCppScope_t type)
std::string GetScopedFinalName(TCppScope_t type)
void GetAllCppNames(TCppScope_t scope, std::set< std::string > &cppnames)
size_t GetFunctionArgTypeoffset()
std::string GetDatamemberTypeAsString(TCppScope_t var)
TCppType_t ResolveEnumReferenceType(TCppType_t type)
Cpp::DeclRef TCppScope_t
Definition API.h:41
std::vector< long int > GetDimensions(TCppType_t type)
bool IsEnumType(TCppType_t type)
bool IsComplete(TCppScope_t type)
TCppScope_t InstantiateTemplate(TCppScope_t tmpl, Cpp::TemplateArgInfo *args, size_t args_size)
Definition API.cxx:34
#define RPY_EXPORTED
union cppjit::cpyrt::Parameter::Value fValue
TMarker m
Definition textangle.C:8
TLine l
Definition textangle.C:4