api refactoring
[m6w6/ext-psi] / src / types / impl_stmt.h
1 #ifndef _PSI_TYPES_IMPL_STMT_H
2 #define _PSI_TYPES_IMPL_STMT_H
3
4 typedef struct impl_stmt {
5 token_t type;
6 union {
7 let_stmt *let;
8 set_stmt *set;
9 return_stmt *ret;
10 free_stmt *fre;
11 void *ptr;
12 } s;
13 } impl_stmt;
14
15 static inline impl_stmt *init_impl_stmt(token_t type, void *ptr) {
16 impl_stmt *stmt = calloc(1, sizeof(*stmt));
17 stmt->type = type;
18 stmt->s.ptr = ptr;
19 return stmt;
20 }
21
22 static inline void free_impl_stmt(impl_stmt *stmt) {
23 switch (stmt->type) {
24 case PSI_T_LET:
25 free_let_stmt(stmt->s.let);
26 break;
27 case PSI_T_SET:
28 free_set_stmt(stmt->s.set);
29 break;
30 case PSI_T_RETURN:
31 free_return_stmt(stmt->s.ret);
32 break;
33 case PSI_T_FREE:
34 free_free_stmt(stmt->s.fre);
35 break;
36 }
37 free(stmt);
38 }
39
40 #endif