erwin/typeinfo.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 #ifdef ERWIN_DEBUG_INCLUDE
52 #warning "Including typeinfo.h."
53 #endif
54
55 #ifndef Global_ERWIN_TYPEINFO_H
56 #define Global_ERWIN_TYPEINFO_H
57
58 #ifdef ERWIN_DEBUG_INCLUDE
59 #warning "First inclusion of typeinfo.h."
60 #endif
61
62 #ifdef Global_ERWIN_COMPILING
63 # include "--INCPREF2B--erwin/defs.h"
64 #else
65 # include <--INCPREF2B--erwin/defs.h>
66 #endif
67
68 #if Global_ERWIN_TYPE_INFO && !defined(TYPE_INFO_T)
69
70 #define Global_erwin_kind_t_defined 1
71 enum _Global_erwin_kind_t {
72 Global_KIND_VOID,
73 Global_KIND_SINT,
74 Global_KIND_UINT,
75 Global_KIND_ENUM,
76 Global_KIND_FLOAT,
77 Global_KIND_STRUCT,
78 Global_KIND_ARRAY,
79 Global_KIND_UNION,
80 Global_KIND_POINTER,
81 Global_KIND_REF,
82 Global_KIND_STRING,
83 Global_KIND_VECTOR,
84 Global_KIND_FUNCTION,
85 Global_KIND_TUPLE
86 };
87
88 ERWIN_KIND_TYPEDEFS(enum, Global_erwin_kind_t)
89 ERWIN_KIND_TYPEDEFS(struct, Global_erwin_type_t)
90 ERWIN_KIND_TYPEDEFS(struct, Global_erwin_slot_t)
91
92
93 #define Global_erwin_slot_t_defined 1
94 struct _Global_erwin_slot_t {
95 char const *name;
96 size_t value;
97
98
99
100 Global_erwin_type_t_const_p type;
101
102
103 };
104
105
106 #define Global_erwin_type_t_defined 1
107 struct _Global_erwin_type_t {
108 Global_erwin_kind_t kind;
109 char const *name;
110 size_t size;
111
112
113
114 size_t nentries;
115
116
117
118
119
120
121 Global_erwin_type_t_const_p element;
122
123
124 Global_erwin_slot_t_const_p slot;
125
126
127
128
129 };
130
131
132 #ifndef TYPE_INFO_NAME_RAW
133 #define TYPE_INFO_NAME_RAW(X) ERWIN_CONCAT_TOKEN (X, _type_info)
134 #endif
135
136 #ifndef TYPE_STRUCT_SLOTS_NAME_RAW
137 #define TYPE_STRUCT_SLOTS_NAME_RAW(X) ERWIN_CONCAT_TOKEN (X, _ti_struct_slots)
138 #endif
139
140 #ifndef TYPE_ENUM_VALUES_NAME_RAW
141 #define TYPE_ENUM_VALUES_NAME_RAW(X) ERWIN_CONCAT_TOKEN (X, _ti_enum_values)
142 #endif
143
144 #ifndef TYPE_UNION_CHOICES_NAME_RAW
145 #define TYPE_UNION_CHOICES_NAME_RAW(X) ERWIN_CONCAT_TOKEN (X, _ti_union_choices)
146 #endif
147
148
149
150 #define TYPE_STRUCT_T(X) Global_erwin_slot_t TYPE_STRUCT_SLOTS(X)[]
151 #define TYPE_UNION_T(X) Global_erwin_slot_t TYPE_UNION_CHOICES(X)[]
152 #define TYPE_ENUM_T(X) Global_erwin_slot_t TYPE_ENUM_VALUES(X)[]
153
154 #define TYPE_INFO_T(X) Global_erwin_type_t TYPE_INFO(X)
155
156
157 #define TYPE_INFO_SINT(Type) { Global_KIND_SINT, #Type, sizeof(Type), 0, NULL, NULL }
158 #define TYPE_INFO_UINT(Type) { Global_KIND_UINT, #Type, sizeof(Type), 0, NULL, NULL }
159 #define TYPE_INFO_FLOAT(Type) { Global_KIND_FLOAT, #Type, sizeof(Type), 0, NULL, NULL }
160
161 #define TYPE_INFO_VOID(Type) { Global_KIND_VOID, #Type, 0, 0, NULL, NULL }
162
163
164 #define TYPE_STRUCT_BEGIN(Container) {
165
166 #define TYPE_STRUCT_SLOT(Container,QElement,slot) \
167 { #slot, \
168 Global_ERWIN_OFFSETOF(Container, slot), \
169 &TYPE_INFO(QElement) \
170 },
171
172
173 #define TYPE_SUPER(Container,Super) \
174 { #Super, \
175 0 \
176 &TYPE_INFO(Super) \
177 },
178
179 #define TYPE_STRUCT_END }
180
181 #define TYPE_INFO_STRUCT(Type,Slots) \
182 { \
183 Global_KIND_STRUCT, \
184 #Type, \
185 sizeof(Type), \
186 sizeof(TYPE_STRUCT_SLOTS(Slots)) / sizeof(TYPE_STRUCT_SLOTS(Slots)[0]), \
187 NULL, \
188 TYPE_STRUCT_SLOTS(Slots) \
189 }
190
191
192 #define TYPE_ENUM_BEGIN(Container) {
193 #define TYPE_ENUM_VALUE(Container,Value) { #Value, (int)Value, NULL },
194 #define TYPE_ENUM_END }
195
196 #define TYPE_INFO_ENUM(Type,Slots) \
197 { \
198 Global_KIND_ENUM, \
199 #Type, \
200 sizeof(Type), \
201 sizeof(TYPE_ENUM_VALUES(Slots)) / sizeof(TYPE_ENUM_VALUES(Slots)[0]), \
202 NULL, \
203 TYPE_ENUM_VALUES(Slots) \
204 }
205
206
207 #define TYPE_INFO_UNION(Type,Slots) \
208 { \
209 Global_KIND_UNION, \
210 #Type \
211 sizeof(Type), \
212 sizeof(TYPE_UNION_CHOICES(Slots)) / sizeof(TYPE_UNION_CHOICES(Slots)[0]), \
213 NULL, \
214 TYPE_UNION_CHOICES(Slots) \
215 }
216
217
218 #define TYPE_INFO_POINTER(Type,Element) \
219 { \
220 Global_KIND_POINTER, \
221 #Type, \
222 sizeof(Type), \
223 0, \
224 &TYPE_INFO(Element), \
225 NULL \
226 }
227
228
229 #define TYPE_INFO_REF(Type,Element) \
230 { \
231 Global_KIND_REF, \
232 #Type, \
233 sizeof(Type), \
234 0, \
235 &TYPE_INFO(Element), \
236 NULL \
237 }
238
239
240 #define TYPE_INFO_VECTOR(Type,Element,Container,slot) \
241 { \
242 Global_KIND_VECTOR, \
243 #Type, \
244 Global_ERWIN_SIZEOF_MEMBER(Container, slot), \
245 Global_ERWIN_OFFSETOF(Container, slot), \
246 &TYPE_INFO(Element), \
247 NULL \
248 }
249
250
251 #define TYPE_INFO_STRING(Type,Element) \
252 { \
253 Global_KIND_STRING, \
254 #Type, \
255 0, \
256 0, \
257 &TYPE_INFO(Element), \
258 NULL \
259 }
260
261
262 #define TYPE_INFO_ARRAY(Type,Element,NEntries) \
263 { \
264 Global_KIND_ARRAY, \
265 #Type, \
266 0, \
267 NEntries, \
268 &TYPE_INFO(Element), \
269 NULL \
270 }
271
272 #endif
273
274
275
276 #if defined(TYPE_INFO_T)
277
278
279 #define TYPE_INFO_NAME(X) ERWIN_IDENTITY(TYPE_INFO_NAME_RAW(X))
280 #define TYPE_STRUCT_SLOTS_NAME(X) ERWIN_IDENTITY(TYPE_STRUCT_SLOTS_NAME_RAW(X))
281 #define TYPE_ENUM_VALUES_NAME(X) ERWIN_IDENTITY(TYPE_ENUM_VALUES_NAME_RAW(X))
282 #define TYPE_UNION_CHOICES_NAME(X) ERWIN_IDENTITY(TYPE_UNION_CHOICES_NAME_RAW(X))
283
284 #define TYPE_INFO3(X) ERWIN_IDENTITY(X##_TYPE_INFO)
285 #define TYPE_INFO2(X) ERWIN_IDENTITY(TYPE_INFO3 (X))
286 #define TYPE_INFO(X) ERWIN_IDENTITY(TYPE_INFO2 (X))
287
288 #define TYPE_STRUCT_SLOTS(X) ERWIN_IDENTITY(TYPE_STRUCT_SLOTS_NAME(X))
289 #define TYPE_ENUM_VALUES(X) ERWIN_IDENTITY(TYPE_ENUM_VALUES_NAME(X))
290 #define TYPE_UNION_CHOICES(X) ERWIN_IDENTITY(TYPE_UNION_CHOICES_NAME(X))
291
292
293
294
295
296
297
298
299 #define Global_ERWIN_BOOL_KIND ENUM
300 #define Global_ERWIN_BOOL_TYPE_INFO TYPE_INFO_NAME(Global_ERWIN_BOOL)
301 extern TYPE_INFO_T(Global_ERWIN_BOOL);
302
303
304 #ifdef __cplusplus
305 #define ?bool_KIND ENUM
306 #define ?bool_TYPE_INFO TYPE_INFO_NAME(Global_erwininternalbool)
307 #define ?bool_TYPE_INFO Global_erwininternalbool_TYPE_INFO
308 extern TYPE_INFO_T(Global_erwininternalbool);
309 #endif
310
311 #ifdef __CHAR_UNSIGNED__
312 #define ?char_KIND UINT
313 #else
314 #define ?char_KIND SINT
315 #endif
316 #define Global_erwininternalchar_TYPE_INFO TYPE_INFO_NAME(Global_erwininternalchar)
317 #define ?char_TYPE_INFO Global_erwininternalchar_TYPE_INFO
318 extern TYPE_INFO_T(Global_erwininternalchar);
319
320 #define ?int_KIND SINT
321 #define Global_erwininternalint_TYPE_INFO TYPE_INFO_NAME(Global_erwininternalint)
322 #define ?int_TYPE_INFO Global_erwininternalint_TYPE_INFO
323 extern TYPE_INFO_T(Global_erwininternalint);
324
325 #define ?float_KIND FLOAT
326 #define Global_erwininternalfloat_TYPE_INFO TYPE_INFO_NAME(Global_erwininternalfloat)
327 #define ?float_TYPE_INFO Global_erwininternalfloat_TYPE_INFO
328 extern TYPE_INFO_T(Global_erwininternalfloat);
329
330 #define ?double_KIND FLOAT
331 #define Global_erwininternaldouble_TYPE_INFO TYPE_INFO_NAME(Global_erwininternaldouble)
332 #define ?double_TYPE_INFO Global_erwininternaldouble_TYPE_INFO
333 extern TYPE_INFO_T(Global_erwininternaldouble);
334
335 #define ?short_KIND SINT
336 #define Global_erwininternalshort_TYPE_INFO TYPE_INFO_NAME(Global_erwininternalshort)
337 #define ?short_TYPE_INFO Global_erwininternalshort_TYPE_INFO
338 extern TYPE_INFO_T(Global_erwininternalshort);
339
340 #define ?long_KIND SINT
341 #define Global_erwininternallong_TYPE_INFO TYPE_INFO_NAME(Global_erwininternallong)
342 #define ?long_TYPE_INFO Global_erwininternallong_TYPE_INFO
343 extern TYPE_INFO_T(Global_erwininternallong);
344
345 #ifdef ERWIN_LONG_LONG
346 #define ?ERWIN_LONG_LONG_KIND SINT
347 #define Global_erwininternalERWIN_LONG_LONG_TYPE_INFO TYPE_INFO_NAME(Global_erwininternalERWIN_LONG_LONG)
348 #define ?ERWIN_LONG_LONG_TYPE_INFO Global_erwininternalERWIN_LONG_LONG_TYPE_INFO
349 extern TYPE_INFO_T(Global_erwininternalERWIN_LONG_LONG);
350 #endif
351
352 #define ?unsigned_char_KIND UINT
353 #define Global_erwininternalunsigned_char_TYPE_INFO TYPE_INFO_NAME(Global_erwininternalunsigned_char)
354 #define ?unsigned_char_TYPE_INFO Global_erwininternalunsigned_char_TYPE_INFO
355 extern TYPE_INFO_T(Global_erwininternalunsigned_char);
356
357 #define ?unsigned_KIND UINT
358 #define Global_erwininternalunsigned_TYPE_INFO TYPE_INFO_NAME(Global_erwininternalunsigned)
359 #define ?unsigned_TYPE_INFO Global_erwininternalunsigned_TYPE_INFO
360 extern TYPE_INFO_T(Global_erwininternalunsigned);
361
362 #define ?unsigned_short_KIND UINT
363 #define Global_erwininternalunsigned_short_TYPE_INFO TYPE_INFO_NAME(Global_erwininternalunsigned_short)
364 #define ?unsigned_short_TYPE_INFO Global_erwininternalunsigned_short_TYPE_INFO
365 extern TYPE_INFO_T(Global_erwininternalunsigned_short);
366
367 #define ?unsigned_long_KIND UINT
368 #define Global_erwininternalunsigned_long_TYPE_INFO TYPE_INFO_NAME(Global_erwininternalunsigned_long)
369 #define ?unsigned_long_TYPE_INFO Global_erwininternalunsigned_long_TYPE_INFO
370 extern TYPE_INFO_T(Global_erwininternalunsigned_long);
371
372 #ifdef ERWIN_UNSIGNED_LONG_LONG
373 #define ?ERWIN_UNSIGNED_LONG_LONG_KIND UINT
374 #define Global_erwininternalERWIN_UNSIGNED_LONG_LONG_TYPE_INFO TYPE_INFO_NAME(Global_erwininternalERWIN_UNSIGNED_LONG_LONG)
375 #define ?ERWIN_UNSIGNED_LONG_LONG_TYPE_INFO Global_erwininternalERWIN_UNSIGNED_LONG_LONG_TYPE_INFO
376 extern TYPE_INFO_T(Global_erwininternalERWIN_UNSIGNED_LONG_LONG);
377 #endif
378
379 #define ?signed_char_KIND SINT
380 #define Global_erwininternalsigned_char_TYPE_INFO TYPE_INFO_NAME(Global_erwininternalsigned_char)
381 #define ?signed_char_TYPE_INFO Global_erwininternalsigned_char_TYPE_INFO
382 extern TYPE_INFO_T(Global_erwininternalsigned_char);
383
384 #define ?size_t_KIND UINT
385 #define Global_erwininternalsize_t_TYPE_INFO TYPE_INFO_NAME(Global_erwininternalsize_t)
386 #define ?size_t_TYPE_INFO Global_erwininternalsize_t_TYPE_INFO
387 extern TYPE_INFO_T(Global_erwininternalsize_t);
388
389 #define ?void_KIND VOID
390 #define Global_erwininternalvoid_TYPE_INFO TYPE_INFO_NAME(Global_erwininternalvoid)
391 #define ?void_TYPE_INFO Global_erwininternalvoid_TYPE_INFO
392 extern TYPE_INFO_T(Global_erwininternalvoid);
393
394
395
396 #define ?char_string_KIND VECTOR
397 #define Global_erwininternalchar_string_TYPE_INFO TYPE_INFO_NAME(Global_erwininternalchar_string)
398 #define ?char_string_TYPE_INFO Global_erwininternalchar_string_TYPE_INFO
399 extern TYPE_INFO_T(Global_erwininternalchar_string);
400
401 #define ?char_p_KIND POINTER
402 #define Global_erwininternalchar_p_TYPE_INFO TYPE_INFO_NAME(Global_erwininternalchar_p)
403 #define ?char_p_TYPE_INFO Global_erwininternalchar_p_TYPE_INFO
404 extern TYPE_INFO_T(Global_erwininternalchar_p);
405
406 #define ?char_const_p_KIND POINTER
407 #define Global_erwininternalchar_const_p_TYPE_INFO TYPE_INFO_NAME(Global_erwininternalchar_const_p)
408 #define ?char_const_p_TYPE_INFO Global_erwininternalchar_const_p_TYPE_INFO
409 extern TYPE_INFO_T(Global_erwininternalchar_const_p);
410
411 #define ?void_p_KIND POINTER
412 #define Global_erwininternalvoid_p_TYPE_INFO TYPE_INFO_NAME(Global_erwininternalvoid_p)
413 #define ?void_p_TYPE_INFO Global_erwininternalvoid_p_TYPE_INFO
414 extern TYPE_INFO_T(Global_erwininternalvoid_p);
415
416 #define ?void_const_p_KIND POINTER
417 #define Global_erwininternalvoid_const_p_TYPE_INFO TYPE_INFO_NAME(Global_erwininternalvoid_const_p)
418 #define ?void_const_p_TYPE_INFO Global_erwininternalvoid_const_p_TYPE_INFO
419 extern TYPE_INFO_T(Global_erwininternalvoid_const_p);
420
421 #define ?short_int_TYPE_INFO short_TYPE_INFO
422 #define ?long_int_TYPE_INFO long_TYPE_INFO
423 #define ?unsigned_short_int_TYPE_INFO unsigned_short_TYPE_INFO
424 #define ?unsigned_long_int_TYPE_INFO unsigned_long_TYPE_INFO
425 #define ?signed_int_TYPE_INFO int_TYPE_INFO
426 #define ?signed_short_TYPE_INFO short_TYPE_INFO
427 #define ?signed_short_int_TYPE_INFO short_TYPE_INFO
428 #define ?signed_long_TYPE_INFO long_TYPE_INFO
429 #define ?signed_long_int_TYPE_INFO long_TYPE_INFO
430 #define ?charp_TYPE_INFO char_p_TYPE_INFO
431 #define ?char_constp_TYPE_INFO char_const_p_TYPE_INFO
432 #define ?const_char_p_TYPE_INFO char_const_p_TYPE_INFO
433 #define ?const_charp_TYPE_INFO char_const_p_TYPE_INFO
434 #define ?voidp_TYPE_INFO void_p_TYPE_INFO
435 #define ?void_constp_TYPE_INFO void_const_p_TYPE_INFO
436 #define ?const_void_p_TYPE_INFO void_const_p_TYPE_INFO
437 #define ?const_voidp_TYPE_INFO void_const_p_TYPE_INFO
438
439 #if defined(Global_erwin_kind_t_defined)
440
441 extern char const *Global_erwin_kind_to_string (Global_erwin_kind_t) ATTR_PURE;
442
443 #endif
444
445 #ifdef __cplusplus
446 #ifdef Global_erwin_type_t_defined
447
448 #define Global_ERWIN_DEF_TYPE(Type, Which) \
449 ERWIN_WRAPPER \
450 Global_erwin_type_t const *Global_erwin_type (Type) ATTR_CONST; \
451 ERWIN_WRAPPER \
452 Global_erwin_type_t const *Global_erwin_type (Type) \
453 { return &Which##_TYPE_INFO; }
454
455 Global_ERWIN_DEF_TYPE(void, void)
456
457 Global_ERWIN_DEF_TYPE(char, char)
458 Global_ERWIN_DEF_TYPE(signed char, signed_char)
459 Global_ERWIN_DEF_TYPE(unsigned char, unsigned_char)
460
461 Global_ERWIN_DEF_TYPE(short, short)
462 Global_ERWIN_DEF_TYPE(unsigned short, unsigned_short)
463
464 Global_ERWIN_DEF_TYPE(int, int)
465 Global_ERWIN_DEF_TYPE(unsigned, unsigned)
466
467 Global_ERWIN_DEF_TYPE(long, long)
468 Global_ERWIN_DEF_TYPE(unsigned long, unsigned_long)
469
470 Global_ERWIN_DEF_TYPE(char *, char_p)
471 Global_ERWIN_DEF_TYPE(char const *, char_p)
472
473 Global_ERWIN_DEF_TYPE(void *, void_p)
474 Global_ERWIN_DEF_TYPE(void const *, void_p)
475
476 #ifdef ERWIN_UNSIGNED_LONG_LONG
477 Global_ERWIN_DEF_TYPE(ERWIN_LONG_LONG, ERWIN_LONG_LONG)
478 Global_ERWIN_DEF_TYPE(ERWIN_UNSIGNED_LONG_LONG, ERWIN_UNSIGNED_LONG_LONG)
479 #endif
480
481 #endif
482 #endif
483
484
485
486
487 #endif
488
489 #endif