15#ifndef CPPINTEROP_CPPINTEROPTYPES_H
16#define CPPINTEROP_CPPINTEROPTYPES_H
19#if defined _WIN32 || defined __CYGWIN__
20#define CPPINTEROP_API __declspec(dllexport)
23#define CPPINTEROP_API __attribute__((__visibility__("default")))
33#define CPPINTEROP_DEPRECATED(msg) __declspec(deprecated(msg))
34#elif defined(__GNUC__) || defined(__clang__)
35#define CPPINTEROP_DEPRECATED(msg) __attribute__((deprecated(msg)))
37#define CPPINTEROP_DEPRECATED(msg)
97 DeclRef() : data(
nullptr) {}
98 DeclRef(
void* P) : data(P) {}
99 DeclRef(
decltype(
nullptr)) : data(
nullptr) {}
100 explicit operator bool()
const {
return data !=
nullptr; }
101 friend bool operator==(DeclRef a, DeclRef b) {
return a.data == b.data; }
102 friend bool operator!=(DeclRef a, DeclRef b) {
return !(a == b); }
107 TypeRef() : data(nullptr) {}
108 TypeRef(
void* P) : data(P) {}
109 TypeRef(
decltype(
nullptr)) : data(nullptr) {}
110 explicit operator bool()
const {
return data !=
nullptr; }
111 friend bool operator==(TypeRef a, TypeRef b) {
return a.data == b.data; }
112 friend bool operator!=(TypeRef a, TypeRef b) {
return !(a == b); }
117 FuncRef() : data(nullptr) {}
118 FuncRef(
void* P) : data(P) {}
119 FuncRef(
decltype(
nullptr)) : data(nullptr) {}
120 explicit operator bool()
const {
return data !=
nullptr; }
121 friend bool operator==(FuncRef a, FuncRef b) {
return a.data == b.data; }
122 friend bool operator!=(FuncRef a, FuncRef b) {
return !(a == b); }
127 ObjectRef() : data(nullptr) {}
128 ObjectRef(
void* P) : data(P) {}
129 ObjectRef(
decltype(
nullptr)) : data(nullptr) {}
130 explicit operator bool()
const {
return data !=
nullptr; }
131 friend bool operator==(ObjectRef a, ObjectRef b) {
return a.data == b.data; }
132 friend bool operator!=(ObjectRef a, ObjectRef b) {
return !(a == b); }
137 InterpRef() : data(nullptr) {}
138 InterpRef(
void* P) : data(P) {}
139 InterpRef(
decltype(
nullptr)) : data(nullptr) {}
140 explicit operator bool()
const {
return data !=
nullptr; }
141 friend bool operator==(InterpRef a, InterpRef b) {
return a.data == b.data; }
142 friend bool operator!=(InterpRef a, InterpRef b) {
return !(a == b); }
150 ConstDeclRef() : data(nullptr) {}
151 ConstDeclRef(
const void* P) : data(P) {}
152 ConstDeclRef(DeclRef d) : data(d.data) {}
153 ConstDeclRef(
decltype(
nullptr)) : data(nullptr) {}
154 explicit operator bool()
const {
return data !=
nullptr; }
155 friend bool operator==(ConstDeclRef a, ConstDeclRef b) {
156 return a.data == b.data;
158 friend bool operator!=(ConstDeclRef a, ConstDeclRef b) {
return !(a == b); }
163 ConstTypeRef() : data(nullptr) {}
164 ConstTypeRef(
const void* P) : data(P) {}
165 ConstTypeRef(TypeRef d) : data(d.data) {}
166 ConstTypeRef(
decltype(
nullptr)) : data(nullptr) {}
167 explicit operator bool()
const {
return data !=
nullptr; }
168 friend bool operator==(ConstTypeRef a, ConstTypeRef b) {
169 return a.data == b.data;
171 friend bool operator!=(ConstTypeRef a, ConstTypeRef b) {
return !(a == b); }
176 ConstFuncRef() : data(nullptr) {}
177 ConstFuncRef(
const void* P) : data(P) {}
178 ConstFuncRef(FuncRef d) : data(d.data) {}
179 ConstFuncRef(
decltype(
nullptr)) : data(nullptr) {}
180 explicit operator bool()
const {
return data !=
nullptr; }
181 friend bool operator==(ConstFuncRef a, ConstFuncRef b) {
182 return a.data == b.data;
184 friend bool operator!=(ConstFuncRef a, ConstFuncRef b) {
return !(a == b); }
199template <>
struct std::hash<
Cpp::DeclRef> {
200 std::size_t operator()(
const Cpp::DeclRef& obj)
const {
201 return std::hash<void*>{}(obj.data);
204template <>
struct std::hash<
Cpp::TypeRef> {
205 std::size_t operator()(
const Cpp::TypeRef& obj)
const {
206 return std::hash<void*>{}(obj.data);
209template <>
struct std::hash<
Cpp::FuncRef> {
210 std::size_t operator()(
const Cpp::FuncRef& obj)
const {
211 return std::hash<void*>{}(obj.data);
214template <>
struct std::hash<
Cpp::ObjectRef> {
215 std::size_t operator()(
const Cpp::ObjectRef& obj)
const {
216 return std::hash<void*>{}(obj.data);
224namespace DispatchRaw {
229 const Cpp::JitCall* JC,
void*
result,
void** args, std::size_t nargs,
232 const Cpp::JitCall* JC,
void* object,
unsigned long nary,
int withFree);
234 const Cpp::JitCall* JC,
void*
result);
274using ::CppInterOpArray;
275using ::CppInterOpStringArray;
276using ::TemplateArgInfo;
278static_assert(
sizeof(DeclRef) ==
sizeof(ConstDeclRef),
279 "Const/mutable handle ABI mismatch");
280static_assert(
sizeof(TypeRef) ==
sizeof(ConstTypeRef),
281 "Const/mutable handle ABI mismatch");
282static_assert(
sizeof(FuncRef) ==
sizeof(ConstFuncRef),
283 "Const/mutable handle ABI mismatch");
285enum Operator :
unsigned char {
315 OP_GreaterGreaterEqual,
334enum OperatorArity :
unsigned char { kUnary = 1, kBinary, kBoth };
335enum Signedness :
unsigned char { kSigned = 1, kUnsigned };
338enum QualKind :
unsigned char {
342 All = Const | Volatile | Restrict
346enum class InterpreterLanguage :
unsigned char {
363enum class InterpreterLanguageStandard :
unsigned char {
409enum class AllocType :
unsigned char {
418inline QualKind operator|(QualKind a, QualKind b) {
419 return static_cast<QualKind
>(
static_cast<unsigned char>(a) |
420 static_cast<unsigned char>(b));
423enum class ValueKind : std::uint8_t {
443 void** m_Args =
nullptr;
444 size_t m_ArgSize = 0;
447 ArgList(
void** Args,
size_t ArgSize) : m_Args(Args), m_ArgSize(ArgSize) {}
453 using GenericCall = void (*)(
void*, size_t,
void**,
void*);
455 using ConstructorCall = void (*)(
void*, size_t, size_t,
void**,
void*);
457 using DestructorCall = void (*)(
void*, size_t, int);
461 GenericCall m_GenericCall;
462 ConstructorCall m_ConstructorCall;
463 DestructorCall m_DestructorCall;
467 JitCall() : m_GenericCall(nullptr), m_Kind(kUnknown), m_FD(nullptr) {}
468 JitCall(Kind K, GenericCall C, ConstFuncRef FD)
469 : m_GenericCall(C), m_Kind(K), m_FD(FD) {}
470 JitCall(Kind K, ConstructorCall C, ConstFuncRef Ctor)
471 : m_ConstructorCall(C), m_Kind(K), m_FD(Ctor) {}
472 JitCall(Kind K, DestructorCall C, ConstFuncRef Dtor)
473 : m_DestructorCall(C), m_Kind(K), m_FD(Dtor) {}
481 std::size_t nargs,
void* self);
484 unsigned long nary,
int withFree);
493 [[nodiscard]] Kind getKind()
const {
return m_Kind; }
494 bool isValid()
const {
return getKind() != kUnknown; }
495 bool isInvalid()
const {
return !isValid(); }
496 explicit operator bool()
const {
return isValid(); }
499 void Invoke(ArgList args = {},
void* self =
nullptr)
const {
500 Invoke(
nullptr, args, self);
511 void Invoke(
void*
result, ArgList args = {},
void* self =
nullptr)
const {
518 assert(0 &&
"Attempted to call an invalid function declaration");
523 assert(AreArgumentsValid(
result, args, self, 1UL) &&
"Invalid args!");
526 fn(
this,
result, args.m_Args, args.m_ArgSize, self);
527 m_GenericCall(self, args.m_ArgSize, args.m_Args,
result);
528 if (
auto fn = ::CppInternal::DispatchRaw::
533 case kConstructorCall:
536 InvokeConstructor(
result, 1UL, args, self);
538 case kDestructorCall:
540 assert(!args.m_Args &&
"Destructor called with arguments");
541 InvokeDestructor(
result, 0UL,
true);
553 void InvokeDestructor(
void*
object,
unsigned long nary = 0,
554 int withFree =
true)
const {
555 assert(m_Kind == kDestructorCall &&
"Wrong overload!");
556 if (
auto fn = ::CppInternal::DispatchRaw::
558 fn(this, object, nary, withFree);
559 m_DestructorCall(
object, nary, withFree);
571 void InvokeConstructor(
void*
result,
unsigned long nary = 1,
572 ArgList args = {},
void* is_arena =
nullptr)
const {
573 assert(m_Kind == kConstructorCall &&
"Wrong overload!");
574 assert(AreArgumentsValid(
result, args,
nullptr, nary) &&
577 fn(
this,
result, args.m_Args, args.m_ArgSize,
nullptr);
578 m_ConstructorCall(
result, nary, args.m_ArgSize, args.m_Args, is_arena);
595using VTableOverlayDtorHook = void (*)(
void* inst,
void* cleanup_data);
598namespace DimensionValue {
607enum CaptureStreamKind :
char {
std::optional< AllocType > result
void(* CppInterOpTraceJitCallInvokeImpl)(const Cpp::JitCall *, void *, void **, std::size_t, void *)
void(* CppInterOpTraceJitCallInvokeReturnImpl)(const Cpp::JitCall *, void *)
void(* CppInterOpTraceJitCallInvokeDestructorImpl)(const Cpp::JitCall *, void *, unsigned long, int)
JitCall MakeFunctionCallable(InterpRef I, ConstFuncRef func)
Opaque handle types for the CppInterOp C and C++ API.
C-compatible array of opaque pointers, returned by generated C API wrappers for functions that produc...
C-compatible array of strings, returned by generated C API wrappers for functions that produce string...
Holds information for instantiating a template.
const char * m_IntegralValue