api refactoring
[m6w6/ext-psi] / src / types / decl_type.h
1 #ifndef _PSI_TYPES_DECL_TYPE_H
2 #define _PSI_TYPES_DECL_TYPE_H
3
4 #include "parser_proc.h"
5
6 typedef struct decl_type {
7 struct psi_token *token;
8 char *name;
9 token_t type;
10 union {
11 struct decl_arg *def;
12 struct decl_struct *strct;
13 struct decl_union *unn;
14 struct decl_enum *enm;
15 struct decl *func;
16 } real;
17 } decl_type;
18
19 static inline decl_type *init_decl_type(token_t type, const char *name) {
20 decl_type *t = calloc(1, sizeof(*t));
21 t->type = type;
22 t->name = strdup(name);
23 return t;
24 }
25
26 static inline void free_decl(struct decl *decl);
27 static inline void free_decl_type(decl_type *type) {
28 if (type->token) {
29 free(type->token);
30 }
31 if (type->type == PSI_T_FUNCTION) {
32 free_decl(type->real.func);
33 }
34 free(type->name);
35 free(type);
36 }
37
38
39 #endif