libGimbal
0.0.0 (PRERELEASE)
Ultimate C17/C++20 Core Utility Library and Cross-Language Runtime Framework
gimbal_api_generators.h
Go to the documentation of this file.
1
7
#ifndef GIMBAL_API_GENERATORS_H
8
#define GIMBAL_API_GENERATORS_H
9
10
#include <stdarg.h>
11
#include <stdio.h>
12
#include <stdint.h>
13
#include <limits.h>
14
#include <gimbal/core/gimbal_config.h>
15
#include "../preprocessor/gimbal_macro_sequences.h"
16
#include "../preprocessor/gimbal_macro_utils.h"
17
#include "../preprocessor/gimbal_macro_composition.h"
18
19
#ifdef __cplusplus
20
extern
"C"
{
21
#endif
22
23
#ifdef __cplusplus
24
# define GBL_DECLS_BEGIN extern "C"
{
25
# define GBL_DECLS_END }
26
#else
27
# define GBL_DECLS_BEGIN
28
# define GBL_DECLS_END
29
#endif
30
31
#define GBL_CLASS_IMPL_INTERFACE(iface) \
32
iface##Class iface##Impl;
33
34
#define GBL_CLASS_DERIVE_N(instance, baseKlass, ...) \
35
GBL_CLASS_DERIVE_2(instance, baseKlass) \
36
GBL_MAP(GBL_CLASS_IMPL_INTERFACE, __VA_ARGS__)
37
38
#define GBL_CLASS_DERIVE_2(instance, baseInstance) \
39
struct instance##Class; \
40
typedef struct instance##Class instance##Class; \
41
struct instance##Class { \
42
baseInstance##Class base;
43
44
#define GBL_CLASS_DERIVE_1(instance) \
45
GBL_CLASS_DERIVE_2(instance, Gbl)
46
47
#define GBL_CLASS_DERIVE(...) \
48
GBL_VA_OVERLOAD_CALL(GBL_CLASS_DERIVE, GBL_VA_OVERLOAD_SUFFIXER_2_N, __VA_ARGS__)
49
50
#define GBL_CLASS_BASE_N(instance, ...) \
51
GBL_CLASS_DERIVE_N(instance, Gbl, __VA_ARGS__)
52
53
#define GBL_CLASS_BASE_1(instance) \
54
GBL_CLASS_DERIVE_2(instance, Gbl)
55
56
#define GBL_CLASS_BASE(...) \
57
GBL_VA_OVERLOAD_CALL(GBL_CLASS_BASE, GBL_VA_OVERLOAD_SUFFIXER_1_N, __VA_ARGS__)
58
59
#define GBL_CLASS_BASE_EMPTY(...) \
60
GBL_CLASS_BASE(__VA_ARGS__) \
61
GBL_CLASS_END
62
63
#define GBL_CLASS_END };
64
65
#define GBL_CLASS_DERIVE_EMPTY(...) \
66
GBL_CLASS_DERIVE(__VA_ARGS__) \
67
GBL_CLASS_END
68
69
#define GBL_INTERFACE_DERIVE_N(instance, klass, baseClass, ...) \
70
GBL_INTERFACE_DERIVE_3(instance, klass, baseClass) \
71
GBL_MAP(GBL_CLASS_IMPL_INTERFACE, __VA_ARGS__)
72
73
#define GBL_INTERFACE_DERIVE_3(instance, klass, baseKlass) \
74
struct instance; \
75
typedef struct instance instance; \
76
struct klass; \
77
typedef struct klass klass; \
78
struct klass { \
79
baseKlass base;
80
81
#define GBL_INTERFACE_DERIVE_2(instance, klass) \
82
GBL_INTERFACE_DERIVE_3(instance, klass, GblInterface)
83
84
#define GBL_INTERFACE_DERIVE_1(instance) \
85
GBL_INTERFACE_DERIVE_2(instance, instance##Class)
86
87
#define GBL_INTERFACE_DERIVE(...) \
88
GBL_VA_OVERLOAD_CALL(GBL_INTERFACE_DERIVE, GBL_VA_OVERLOAD_SUFFIXER_3_N, __VA_ARGS__)
89
90
#define GBL_INTERFACE_END };
91
92
#define GBL_INSTANCE_DERIVE(derivedInstance, baseInstance) \
93
struct derivedInstance; \
94
typedef struct derivedInstance derivedInstance; \
95
struct derivedInstance { \
96
union { \
97
derivedInstance##Class* pClass; \
98
baseInstance base; \
99
};
100
101
#define GBL_INSTANCE_BASE(instance) \
102
struct instance; \
103
typedef struct instance instance; \
104
struct instance { \
105
union { \
106
instance##Class* pClass; \
107
GblInstance base; \
108
};
109
110
#define GBL_INSTANCE_BASE_EMPTY(instance) \
111
GBL_INSTANCE_BASE(instance) \
112
GBL_INSTANCE_END
113
114
#define GBL_INSTANCE_END };
115
116
#define GBL_INSTANCE_DERIVE_EMPTY(derived, base) \
117
GBL_INSTANCE_DERIVE(derived, base) \
118
GBL_INSTANCE_END
119
120
#define GBL_DECLARE_STRUCT_PUBLIC(S) \
121
struct S; \
122
typedef struct S S; \
123
struct S
124
125
#define GBL_FORWARD_DECLARE_STRUCT(S) \
126
struct S; \
127
typedef struct S S
128
129
#define GBL_FORWARD_DECLARE_STRUCT_PRIVATE(S) \
130
struct S##_; \
131
typedef struct S##_ S
132
133
#ifndef __cplusplus
134
# define GBL_DECLARE_ENUM(E) \
135
typedef GBL_ENUM E; \
136
enum E
137
#else
138
# define GBL_DECLARE_ENUM(E) \
139
enum E : GBL_ENUM
140
#endif
141
142
#ifndef __cplusplus
143
# define GBL_DECLARE_FLAGS(F) \
144
typedef GBL_FLAGS F; \
145
enum F
146
#else
147
# define GBL_DECLARE_FLAGS(F) \
148
enum F: GBL_FLAGS
149
#endif
150
151
#define GBL_FORWARD_DECLARE_ENUM(E) \
152
typedef GBL_ENUM E
153
154
#define GBL_FORWARD_DECLARE_FLAGS(F) \
155
typedef GBL_FLAGS F
156
157
#define GBL_HANDLE void*
158
159
#define GBL_DECLARE_HANDLE(S) \
160
typedef GBL_HANDLE S;
161
162
#define GBL_DECLARE_OPAQUE(S) \
163
struct S##_; \
164
typedef struct S##_* S
165
166
#define GBL_PRIVATE() struct {
167
168
#define GBL_PRIVATE_END } private_;
169
170
#define GBL_PRIV(a) (a).private_
171
#define GBL_PRIV_REF(a) (a)->private_
172
173
#define GBL_VSELF GBL_SELF_TYPE self
174
175
#define GBL_KLASS GBL_GLUE(GBL_SELF_TYPE, Class)* pSelf
176
#define GBL_CKLASS const GBL_KLASS
177
178
#define GBL_SELF GBL_SELF_TYPE* pSelf
179
#define GBL_CSELF const GBL_SELF
180
181
#define GBL_TYPEOF(instanceStruct) (instanceStruct##_type())
182
183
//sizeof(emptyStruct) is 1 in Cpp, 0 in C!
184
#define GBL_DEFINE_EMPTY_STRUCT(S) \
185
typedef struct S { \
186
char cppCompat; \
187
} S
188
189
#define GBL_UNUSED_(a) \
190
(void)(a)
191
192
#define GBL_UNUSED(...) GBL_MAP_LIST(GBL_UNUSED_, __VA_ARGS__)
193
194
#ifdef GBL_CTX_SHARED_LIB
195
# ifdef GBL_CTX_EXPORTS
196
# define GBL_EXPORT GBL_EXPORT_SHARED
197
# else
198
# define GBL_EXPORT GBL_IMPORT_SHARED
199
# endif
200
#else
201
# define GBL_EXPORT
202
#endif
203
204
//========== CLEAN THIS ENUM SHIT UP AND MAKE IT IN THE FORM OF ==============
205
206
//GBL_CTX_ENUM_GENERATE()
207
208
// ===== MISC META SHIT TO CLEAN LATER ====
209
#define GBL_DECL_VAR_TYPE(type, ...) \
210
type
211
#define GBL_DECL_VAR_NAME(type, name) \
212
name
213
214
#define GBL_DECL_VAR(type, name) \
215
GBL_DECL_VAR_TYPE(type, name) GBL_DECL_VAR_NAME(type, name)
216
217
#define GBL_DECL_VAR_PAIR_TYPE(pair) \
218
GBL_DECL_VAR_TYPE pair
219
220
#define GBL_DECL_VAR_PAIR_NAME(pair) \
221
GBL_DECL_VAR_NAME pair
222
223
#define GBL_DECL_VAR_PAIR(pair) \
224
GBL_DECL_VAR pair
225
226
227
// === ENUM SHIT CLEAN ME LATER!!!===========
228
229
#define GBL_ENUM_TABLE_DECL_ENUM(cName, value, name, string) \
230
cName = value,
231
232
233
#define GBL_ENUM_TABLE_DECLARE(table) \
234
GBL_DECLARE_ENUM(GBL_META_ENUM_TYPE_PROPERTY(table, CNAME)) { \
235
GBL_MAP_TUPLES(GBL_ENUM_TABLE_DECL_ENUM, GBL_MAP_TUPLES(GBL_EVAL, GBL_META_ENUM_TUPLE_VALUE_ARRAY table)) \
236
}; \
237
GBL_ENUM_TABLE_DECLARE_STRINGIFIER(table)
238
239
#define GBL_ENUM_TABLE_RETURN_STRING(cName, value, name, string) \
240
case value: return string;
241
242
#define GBL_ENUM_TABLE_TO_STRING(table, value) \
243
switch(value) { \
244
GBL_MAP_TUPLES(GBL_ENUM_TABLE_RETURN_STRING, GBL_MAP_TUPLES(GBL_EVAL, GBL_META_ENUM_TUPLE_VALUE_ARRAY table)) \
245
}
246
247
#define GBL_ENUM_TABLE_DECLARE_STRINGIFIER(table) \
248
GBL_INLINE GBL_CONSTEXPR const char* GBL_EVAL(GBL_META_ENUM_TYPE_PROPERTY(table, STRINGIFIER))(GBL_EVAL(GBL_META_ENUM_TYPE_PROPERTY(table, CNAME)) value) { \
249
GBL_EVAL(GBL_ENUM_TABLE_TO_STRING(table, value)); \
250
return ""
; \
251
}
252
253
254
//GBL_CTX_ENUM_TUPLE
255
256
#define GBL_META_ENUM_TUPLE(tuple)
257
258
#define GBL_META_ENUM_TUPLE_TYPE_INFO(typeInfo, valueTable) typeInfo
259
260
#define GBL_META_ENUM_TUPLE_TYPE_INFO_PROPERTY_CNAME(cName, name, description, stringifier) cName
261
#define GBL_META_ENUM_TUPLE_TYPE_INFO_PROPERTY_NAME(cName, name, description, stringifier) name
262
#define GBL_META_ENUM_TUPLE_TYPE_INFO_PROPERTY_DESCRIPTION(cName, name, description, stringifier) description
263
#define GBL_META_ENUM_TUPLE_TYPE_INFO_PROPERTY_STRINGIFIER(cName, name, description, stringifier) stringifier
264
265
#define GBL_META_ENUM_TUPLE_VALUE_ARRAY(typeInfo, valueArray) valueArray
266
267
#define GBL_META_ENUM_TUPLE_VALUE_ARRAY_TUPLE_VALUE(...) GBL_EVAL __VA_ARGS__
268
269
#define GBL_META_ENUM_TUPLE_VALUE_PROPERTY_CNAME(cName, value, name, string) cName
270
#define GBL_META_ENUM_TUPLE_VALUE_PROPERTY_NAME(cName, value, name, string) name
271
#define GBL_META_ENUM_TUPLE_VALUE_PROPERTY_VALUE(cName, value, name, string) value
272
#define GBL_META_ENUM_TUPLE_VALUE_PROPERTY_STRING(cName, value, name, string) string
273
274
#define GBL_META_ENUM_TYPE_PROPERTY(table, postfix) GBL_META_ENUM_TUPLE_TYPE_INFO_PROPERTY_##postfix GBL_META_ENUM_TUPLE_TYPE_INFO table
275
276
277
// @TODO: ADD META TUPLE SUPPORT FOR FLAGS, INCLUDING STRINGIFICATION AND VALIDATION!!
278
279
#ifdef __cplusplus
280
}
281
#endif
282
283
#endif
// GIMBAL_API_GENERATORS_H
lib
api
gimbal
core
gimbal_api_generators.h
Generated by
1.9.4