fix num exp
[m6w6/ext-psi] / src / parser.h
index faa95e4931d9811788bf76e5decaa87a87fc08d6..2e551dc51e225193ea04d0cf544e47a7d4443a31 100644 (file)
@@ -576,10 +576,11 @@ typedef struct num_exp {
        token_t t;
        union {
                char *numb;
-               char *cnst;
+               constant *cnst;
                decl_var *dvar;
        } 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;
 
@@ -587,10 +588,8 @@ 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:
-               exp->u.numb = strdup(num);
-               break;
        case PSI_T_NSNAME:
-               exp->u.cnst = strdup(num);
+               exp->u.numb = strdup(num);
                break;
        case PSI_T_NAME:
                exp->u.dvar = num;
@@ -606,7 +605,6 @@ static inline void free_num_exp(num_exp *exp) {
                free(exp->u.numb);
                break;
        case PSI_T_NSNAME:
-               free(exp->u.cnst);
                break;
        case PSI_T_NAME:
                free_decl_var(exp->u.dvar);
@@ -730,6 +728,7 @@ static inline void free_set_func(set_func *func) {
 typedef struct set_value {
        set_func *func;
        decl_vars *vars;
+       num_exp *num;
        struct {
                struct set_value *set;
                impl_val *val;
@@ -1014,6 +1013,16 @@ static void free_impls(impls *impls) {
        free(impls);
 }
 
+static inline impl_val *struct_member_ref(decl_arg *set_arg, impl_val *struct_ptr, impl_val **to_free) {
+       void *ptr = (char *) struct_ptr->ptr + set_arg->layout->pos;
+       impl_val *val = enref_impl_val(ptr, set_arg->var);
+
+       if (val != ptr) {
+               *to_free = val;
+       }
+
+       return val;
+}
 
 #define PSI_ERROR 16
 #define PSI_WARNING 32