+typedef struct num_exp {
+ PSI_Token *token;
+ token_t t;
+ union {
+ char *numb;
+ constant *cnst;
+ decl_var *dvar;
+ struct decl_enum_item *enm;
+ } u;
+ token_t operator;
+ int (*calculator)(int t1, impl_val *v1, int t2, impl_val *v2, impl_val *res);
+ struct num_exp *operand;
+} num_exp;
+
+static inline num_exp *init_num_exp(token_t t, void *num) {
+ num_exp *exp = calloc(1, sizeof(*exp));
+ switch (exp->t = t) {
+ case PSI_T_NUMBER:
+ case PSI_T_NSNAME:
+ exp->u.numb = strdup(num);
+ break;
+ case PSI_T_NAME:
+ exp->u.dvar = num;
+ break;
+ EMPTY_SWITCH_DEFAULT_CASE();
+ }
+ return exp;
+}
+
+static inline num_exp *copy_num_exp(num_exp *exp) {
+ decl_var *dvar;
+ num_exp *num = calloc(1, sizeof(*num));
+
+ memcpy(num, exp, sizeof(*num));
+
+ if (num->token) {
+ num->token = PSI_TokenCopy(num->token);
+ }
+ if (num->operand) {
+ num->operand = copy_num_exp(num->operand);
+ }
+ switch (num->t) {
+ case PSI_T_NUMBER:
+ case PSI_T_NSNAME:
+ num->u.numb = strdup(num->u.numb);
+ break;
+ case PSI_T_NAME:
+ dvar = init_decl_var(num->u.dvar->name, num->u.dvar->pointer_level, num->u.dvar->array_size);
+ dvar->arg = num->u.dvar->arg;
+ if (num->u.dvar->token) {
+ dvar->token = PSI_TokenCopy(num->u.dvar->token);
+ }
+ num->u.dvar = dvar;
+ break;
+ }
+ return num;
+}
+
+static inline void free_num_exp(num_exp *exp) {
+ if (exp->token) {
+ free(exp->token);
+ }
+ switch (exp->t) {
+ case PSI_T_NUMBER:
+ free(exp->u.numb);
+ break;
+ case PSI_T_NSNAME:
+ break;
+ case PSI_T_NAME:
+ free_decl_var(exp->u.dvar);
+ break;
+ case PSI_T_ENUM:
+ break;
+ EMPTY_SWITCH_DEFAULT_CASE();
+ }
+ if (exp->operand) {
+ free_num_exp(exp->operand);
+ }
+ free(exp);
+}
+
+typedef struct decl_enum_item {
+ PSI_Token *token;
+ char *name;
+ num_exp *num;
+ num_exp inc;
+ struct decl_enum_item *prev;
+} decl_enum_item;
+
+static inline decl_enum_item *init_decl_enum_item(const char *name, num_exp *num) {
+ decl_enum_item *i = calloc(1, sizeof(*i));
+
+ i->name = strdup(name);
+ i->num = num;
+ return i;
+}
+
+static inline void free_decl_enum_item(decl_enum_item *i) {
+ if (i->token) {
+ free(i->token);
+ }
+ if (i->num && i->num != &i->inc) {
+ free_num_exp(i->num);
+ }
+ free(i->name);
+ free(i);
+}
+
+typedef struct decl_enum_items {
+ decl_enum_item **list;
+ size_t count;
+} decl_enum_items;
+
+static inline decl_enum_items *init_decl_enum_items(decl_enum_item *i) {
+ decl_enum_items *l = calloc(1, sizeof(*l));
+
+ if (i) {
+ l->count = 1;
+ l->list = calloc(1, sizeof(*l->list));
+ l->list[0] = i;
+ }
+ return l;
+}
+
+static inline decl_enum_items *add_decl_enum_item(decl_enum_items *l, decl_enum_item *i) {
+ l->list = realloc(l->list, sizeof(*l->list) * (l->count + 1));
+ l->list[l->count] = i;
+ if (l->count) {
+ i->prev = l->list[l->count - 1];
+ }
+ ++l->count;
+ return l;
+}
+
+static inline void free_decl_enum_items(decl_enum_items *l) {
+ if (l->list) {
+ size_t j;
+
+ for (j = 0; j < l->count; ++j) {
+ free_decl_enum_item(l->list[j]);
+ }
+ free(l->list);
+ }
+ free(l);
+}
+
+typedef struct decl_enum {
+ PSI_Token *token;
+ char *name;
+ decl_enum_items *items;
+} decl_enum;
+
+static inline decl_enum *init_decl_enum(const char *name, decl_enum_items *l) {
+ decl_enum *e = calloc(1, sizeof(*e));
+
+ e->name = strdup(name);
+ e->items = l;
+ return e;
+}
+
+static inline void free_decl_enum(decl_enum *e) {
+ if (e->token) {
+ free(e->token);
+ }
+ if (e->items) {
+ free_decl_enum_items(e->items);
+ }
+ free(e->name);
+ free(e);
+}
+
+typedef struct decl_enums {
+ decl_enum **list;
+ size_t count;
+} decl_enums;
+
+static inline decl_enums* add_decl_enum(decl_enums *es, decl_enum *e) {
+ if (!es) {
+ es = calloc(1, sizeof(*es));
+ }
+ es->list = realloc(es->list, ++es->count * sizeof(*es->list));
+ es->list[es->count-1] = e;
+ return es;
+}
+
+static inline void free_decl_enums(decl_enums *es) {
+ if (es->list) {
+ size_t j;
+
+ for (j = 0; j < es->count; ++j) {
+ free_decl_enum(es->list[j]);
+ }
+ }
+ free(es->list);
+ free(es);
+}
+
+typedef struct let_calloc {
+ num_exp *nmemb;
+ num_exp *size;
+} let_calloc;
+
+static inline let_calloc *init_let_calloc(num_exp *nmemb, num_exp *size) {
+ let_calloc *alloc = calloc(1, sizeof(*alloc));
+ alloc->nmemb = nmemb;
+ alloc->size = size;
+ return alloc;
+}
+
+static inline void free_let_calloc(let_calloc *alloc) {
+ free_num_exp(alloc->nmemb);
+ free_num_exp(alloc->size);
+ free(alloc);
+}
+
+typedef struct let_callback {
+ struct let_func *func;
+ struct set_values *args;
+ decl *decl;
+} let_callback;
+
+static inline void free_let_func(struct let_func *func);
+static inline void free_set_values(struct set_values *vals);
+static inline let_callback *init_let_callback(struct let_func *func, struct set_values *args) {
+ let_callback *cb = calloc(1, sizeof(*cb));
+
+ cb->func = func;
+ cb->args = args;
+ return cb;
+}
+
+static inline void free_let_callback(let_callback *cb) {
+ free_let_func(cb->func);
+ free_set_values(cb->args);
+ free(cb);
+}
+
+typedef impl_val *(*let_func_handler)(impl_val *tmp, decl_type *type, impl_arg *iarg, void **to_free);
+