blob: 4f7b1aa9f9274cc20e628f35226016760dc85935 (
plain)
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
|
#ifndef DYNAMIC_TYPING_
#define DYNAMIC_TYPING_
enum TYPE_KIND {
TY_BASIC,
TY_ARRAY,
TY_POINTER,
TY_FUNCTION,
TY_STRUCT,
TY_UNION,
};
struct type {
enum TYPE_KIND kind;
unsigned long size;
// basic types:
const char *basic;
// array & pointer types:
struct type *base;
unsigned long length;
// struct & union types
struct type *members;
struct type *next_member;
unsigned long offset;
const char *field_name;
// function types:
struct type *return_type;
struct type *params;
struct type *next_param;
};
struct type *dynamic_typeof(void *ptr);
struct type *make_basic(const char *type, unsigned long size);
struct type *make_array(struct type *base, unsigned long len);
struct type *make_pointer(struct type *base);
// function not supported yet
// for struct & union, the members are initialized by the caller
struct type *make_struct(unsigned long size);
struct type *make_union(unsigned long size);
void prepend_member(struct type *aggregate, struct type *member, const char *name, unsigned long offset);
void annotate_type(void *ptr, struct type *type);
#endif
|