api refactoring
[m6w6/ext-psi] / src / types / decl_struct.h
1 #ifndef _PSI_TYPES_DECL_STRUCT_H
2 #define _PSI_TYPES_DECL_STRUCT_H
3
4 typedef struct decl_struct {
5 struct psi_token *token;
6 char *name;
7 decl_args *args;
8 size_t size;
9 size_t align;
10 struct {
11 void *type;
12 void (*dtor)(void *type);
13 } engine;
14 } decl_struct;
15
16 static inline decl_struct *init_decl_struct(const char *name, decl_args *args) {
17 decl_struct *s = calloc(1, sizeof(*s));
18 s->name = strdup(name);
19 s->args = args;
20 return s;
21 }
22
23 static inline void free_decl_struct(decl_struct *s) {
24 if (s->token) {
25 free(s->token);
26 }
27 if (s->args) {
28 free_decl_args(s->args);
29 }
30 if (s->engine.type && s->engine.dtor) {
31 s->engine.dtor(s->engine.type);
32 }
33 free(s->name);
34 free(s);
35 }
36
37 #endif