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 {
408inline QualKind operator|(QualKind a, QualKind b) {
409 return static_cast<QualKind
>(
static_cast<unsigned char>(a) |
410 static_cast<unsigned char>(b));
413enum class ValueKind : std::uint8_t {
433 void** m_Args =
nullptr;
434 size_t m_ArgSize = 0;
437 ArgList(
void** Args,
size_t ArgSize) : m_Args(Args), m_ArgSize(ArgSize) {}
443 using GenericCall = void (*)(
void*, size_t,
void**,
void*);
445 using ConstructorCall = void (*)(
void*, size_t, size_t,
void**,
void*);
447 using DestructorCall = void (*)(
void*, size_t, int);
451 GenericCall m_GenericCall;
452 ConstructorCall m_ConstructorCall;
453 DestructorCall m_DestructorCall;
457 JitCall() : m_GenericCall(nullptr), m_Kind(kUnknown), m_FD(nullptr) {}
458 JitCall(Kind K, GenericCall C, ConstFuncRef FD)
459 : m_GenericCall(C), m_Kind(K), m_FD(FD) {}
460 JitCall(Kind K, ConstructorCall C, ConstFuncRef Ctor)
461 : m_ConstructorCall(C), m_Kind(K), m_FD(Ctor) {}
462 JitCall(Kind K, DestructorCall C, ConstFuncRef Dtor)
463 : m_DestructorCall(C), m_Kind(K), m_FD(Dtor) {}
471 std::size_t nargs,
void* self);
474 unsigned long nary,
int withFree);
479 CPPINTEROP_API bool AreArgumentsValid(
void* result, ArgList args,
void* self,
483 [[nodiscard]] Kind getKind()
const {
return m_Kind; }
484 bool isValid()
const {
return getKind() != kUnknown; }
485 bool isInvalid()
const {
return !isValid(); }
486 explicit operator bool()
const {
return isValid(); }
489 void Invoke(ArgList args = {},
void* self =
nullptr)
const {
490 Invoke(
nullptr, args, self);
501 void Invoke(
void* result, ArgList args = {},
void* self =
nullptr)
const {
508 assert(0 &&
"Attempted to call an invalid function declaration");
513 assert(AreArgumentsValid(result, args, self, 1UL) &&
"Invalid args!");
516 fn(
this, result, args.m_Args, args.m_ArgSize, self);
517 m_GenericCall(self, args.m_ArgSize, args.m_Args, result);
518 if (
auto fn = ::CppInternal::DispatchRaw::
523 case kConstructorCall:
526 InvokeConstructor(result, 1UL, args, self);
528 case kDestructorCall:
530 assert(!args.m_Args &&
"Destructor called with arguments");
531 InvokeDestructor(result, 0UL,
true);
543 void InvokeDestructor(
void*
object,
unsigned long nary = 0,
544 int withFree =
true)
const {
545 assert(m_Kind == kDestructorCall &&
"Wrong overload!");
546 if (
auto fn = ::CppInternal::DispatchRaw::
548 fn(this, object, nary, withFree);
549 m_DestructorCall(
object, nary, withFree);
561 void InvokeConstructor(
void* result,
unsigned long nary = 1,
562 ArgList args = {},
void* is_arena =
nullptr)
const {
563 assert(m_Kind == kConstructorCall &&
"Wrong overload!");
564 assert(AreArgumentsValid(result, args,
nullptr, nary) &&
567 fn(
this, result, args.m_Args, args.m_ArgSize,
nullptr);
568 m_ConstructorCall(result, nary, args.m_ArgSize, args.m_Args, is_arena);
585using VTableOverlayDtorHook = void (*)(
void* inst,
void* cleanup_data);
588namespace DimensionValue {
597enum CaptureStreamKind :
char {
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