-
Notifications
You must be signed in to change notification settings - Fork 8
/
dl_reflect.h
executable file
·260 lines (218 loc) · 7.2 KB
/
dl_reflect.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/* copyright (c) 2010 Fredrik Kihlander, see LICENSE for more info */
#ifndef DL_DL_REFLECT_H_INCLUDED
#define DL_DL_REFLECT_H_INCLUDED
/*
File: dl_reflect.h
Functions used to get information about types and type-members. Mostly designed for
use when binding DL towards other languages.
*/
#include <dl/dl.h>
#include <stdint.h>
/*
Struct: dl_type_context_info_t
Struct used to retrieve information about the dl_context
*/
typedef struct dl_type_context_info
{
unsigned int num_types;
unsigned int num_enums;
} dl_type_context_info_t;
/*
Struct: dl_type_info_t
Struct used to retrieve information about a specific DL-type.
*/
typedef struct dl_type_info
{
dl_typeid_t tid;
const char* name;
const char* comment;
unsigned int size;
unsigned int alignment;
unsigned int member_count;
unsigned int metadata_count;
const dl_typeid_t* metadata_type_ids;
const void** metadata_instances;
unsigned int is_extern : 1;
unsigned int is_union : 1;
unsigned int should_verify : 1;
} dl_type_info_t;
/*
Struct: dl_member_info_t
Struct used to retrieve information about a specific DL-member.
*/
typedef struct dl_member_info
{
const char* name;
const char* comment;
dl_type_atom_t atom;
dl_type_storage_t storage;
dl_typeid_t type_id;
unsigned int size;
unsigned int alignment;
unsigned int offset;
unsigned int array_count;
unsigned short bitfield_bits;
unsigned short bitfield_offset;
unsigned int metadata_count;
const dl_typeid_t* metadata_type_ids;
const void** metadata_instances;
unsigned int is_const : 1;
unsigned int should_verify : 1;
} dl_member_info_t;
/*
Struct: dl_enum_info
Struct used to retrieve information about a specific DL-enum.
*/
typedef struct dl_enum_info
{
dl_typeid_t tid;
const char* name;
const char* comment;
dl_type_storage_t storage;
unsigned int value_count;
unsigned int metadata_count;
const dl_typeid_t* metadata_type_ids;
const void** metadata_instances;
unsigned int is_extern : 1;
} dl_enum_info_t;
/*
Struct: dl_enum_value_info
Struct used to retrieve information about a specific DL-enum-value.
*/
typedef struct dl_enum_value_info
{
const char* name;
const char* comment;
union
{
int8_t i8;
int16_t i16;
int32_t i32;
int64_t i64;
uint8_t u8;
uint16_t u16;
uint32_t u32;
uint64_t u64;
} value;
unsigned int metadata_count;
const dl_typeid_t* metadata_type_ids;
const void** metadata_instances;
} dl_enum_value_info_t;
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
/*
Function: dl_reflect_context_info
Get the info about the context and the typelibraries loaded into it.
Parameters:
dl_ctx - The dl-context to get info from.
info - Struct to fill.
Returns:
DL_ERROR_OK on success.
*/
dl_error_t DL_DLL_EXPORT dl_reflect_context_info( dl_ctx_t dl_ctx, dl_type_context_info_t* info );
/*
Function: dl_reflect_loaded_typeids
Get the typeid:s of all loaded types in the context.
Parameters:
dl_ctx - The dl-context to fetch loaded types from.
out_types - Buffer to return loaded types in.
out_types_size - Size of out_types.
Returns:
DL_ERROR_OK on success.
*/
dl_error_t DL_DLL_EXPORT dl_reflect_loaded_typeids( dl_ctx_t dl_ctx, dl_typeid_t* out_types, unsigned int out_types_size );
/*
Function: dl_reflect_loaded_types
Get the dl_type_info_t:s of all loaded types in the context.
Parameters:
dl_ctx - The dl-context to fetch loaded types from.
out_types - Buffer to return loaded types in.
out_types_size - Size of out_types.
Returns:
DL_ERROR_OK on success.
*/
dl_error_t DL_DLL_EXPORT dl_reflect_loaded_types( dl_ctx_t dl_ctx, dl_type_info_t* out_types, unsigned int out_types_size );
/*
Function: dl_reflect_loaded_enums
Get the typeid:s of all loaded enums in the context.
Parameters:
dl_ctx - The dl-context to fetch loaded enums from.
out_enums - Buffer to return loaded enums in.
out_enums_size - Size of out_enums.
Returns:
DL_ERROR_OK on success.
*/
dl_error_t DL_DLL_EXPORT dl_reflect_loaded_enumids( dl_ctx_t dl_ctx, dl_typeid_t* out_enums, unsigned int out_enums_size );
/*
Function: dl_reflect_loaded_enums
Get the dl_enum_info_t:s of all loaded enums in the context.
Parameters:
dl_ctx - The dl-context to fetch loaded enums from.
out_enums - Buffer to return loaded enums in.
out_enums_size - Size of out_enums.
Returns:
DL_ERROR_OK on success.
*/
dl_error_t DL_DLL_EXPORT dl_reflect_loaded_enums( dl_ctx_t dl_ctx, dl_enum_info_t* out_enums, unsigned int out_enums_size );
/*
Function: dl_reflect_get_type_id
Find typeid of a specified type by name.
Parameters:
dl_ctx - A valid handle to a DLContext to do the type-lookup in.
type_ame - Name of type to lookup.
out_type_id - TypeID returned here.
Returns:
DL_ERROR_OK on success.
*/
dl_error_t DL_DLL_EXPORT dl_reflect_get_type_id( dl_ctx_t dl_ctx, const char* type_name, dl_typeid_t* out_type );
/*
Function: dl_reflect_get_type_info
Retrieve information about a certain type in a type-library.
Parameters:
dl_ctx - A valid handle to a DLContext
type - TypeID of the type to get information about.
out_type_info - Ptr to struct to fill with type-information.
Returns:
DL_ERROR_OK on success.
*/
dl_error_t DL_DLL_EXPORT dl_reflect_get_type_info( dl_ctx_t dl_ctx, dl_typeid_t type, dl_type_info_t* out_type_info );
/*
Function: dl_reflect_get_enum_info
Retrieve information about a certain enum in a type-library.
Parameters:
dl_ctx - A valid handle to a DLContext
type - TypeID of the enum to get information about.
out_enum_info - Ptr to struct to fill with value-information.
Returns:
DL_ERROR_OK on success.
*/
dl_error_t DL_DLL_EXPORT dl_reflect_get_enum_info( dl_ctx_t dl_ctx, dl_typeid_t type, dl_enum_info_t* out_enum_info );
/*
Function: dl_reflect_get_type_members
Retrieve information about members of a type in a type-library.
Parameters:
dl_ctx - A valid handle to a DLContext
type - TypeID of the type to get information about.
out_members - Ptr to array to fill with information about the members of the type.
members_size - Size of _pMembers.
Returns:
DL_ERROR_OK on success, DL_ERROR_BUFFER_TOO_SMALL if out_members do not fit all members, or other error if appropriate!
*/
dl_error_t DL_DLL_EXPORT dl_reflect_get_type_members( dl_ctx_t dl_ctx, dl_typeid_t type, dl_member_info_t* out_members, unsigned int out_members_size );
/*
Function: dl_reflect_get_enum_values
Retrieve values of a certain enum.
Parameters:
dl_ctx - A valid handle to a DLContext
type - TypeID of the enum to get values of.
out_values - Ptr to array to fill with enum values.
out_values_size - Size of out_values.
Returns:
DL_ERROR_OK on success, DL_ERROR_BUFFER_TOO_SMALL if out_members do not fit all members, or other error if appropriate!
*/
dl_error_t DL_DLL_EXPORT dl_reflect_get_enum_values( dl_ctx_t dl_ctx, dl_typeid_t type, dl_enum_value_info_t* out_values, unsigned int out_values_size );
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // DL_DL_REFLECT_H_INCLUDED