X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=src%2Fparser.h;h=4df5354a6759180d1af0d1704284292a4da7d57e;hp=faa95e4931d9811788bf76e5decaa87a87fc08d6;hb=bd7cdec42afa560883c47f3803a30cb580cf152f;hpb=2421d323be79e4a811a4197914330a8c0124b130 diff --git a/src/parser.h b/src/parser.h index faa95e4..4df5354 100644 --- a/src/parser.h +++ b/src/parser.h @@ -26,6 +26,30 @@ typedef struct PSI_Token { char text[1]; } PSI_Token; +typedef union impl_val { + char cval; + int8_t i8; + uint8_t u8; + short sval; + int16_t i16; + uint16_t u16; + int ival; + int32_t i32; + uint32_t u32; + long lval; + int64_t i64; + uint64_t u64; + float fval; + double dval; + union { + zend_bool bval; + zend_long lval; + zend_string *str; + } zend; + void *ptr; + uint8_t _dbg[sizeof(void *)]; +} impl_val; + typedef struct decl_type { char *name; token_t type; @@ -136,6 +160,9 @@ typedef struct decl_arg { decl_var *var; decl_struct_layout *layout; struct let_stmt *let; + impl_val val; + void *ptr; + void *mem; } decl_arg; static inline decl_arg *init_decl_arg(decl_type *type, decl_var *var) { @@ -143,6 +170,7 @@ static inline decl_arg *init_decl_arg(decl_type *type, decl_var *var) { arg->type = type; arg->var = var; var->arg = arg; + arg->ptr = &arg->val; return arg; } @@ -330,55 +358,6 @@ static inline void free_decl_structs(decl_structs *ss) { free(ss); } -typedef union impl_val { - char cval; - int8_t i8; - uint8_t u8; - short sval; - int16_t i16; - uint16_t u16; - int ival; - int32_t i32; - uint32_t u32; - long lval; - int64_t i64; - uint64_t u64; - float fval; - double dval; - union { - zend_bool bval; - zend_long lval; - zend_string *str; - } zend; - void *ptr; - uint8_t _dbg[sizeof(void *)]; -} impl_val; - -static inline impl_val *deref_impl_val(impl_val *ret_val, decl_var *var) { - unsigned i; - - if (var->arg->var != var) for (i = 1; i < var->pointer_level; ++i) { - ret_val = *(void **) ret_val; - } - return ret_val; -} - -static inline impl_val *enref_impl_val(void *ptr, decl_var *var) { - impl_val *val, *val_ptr; - unsigned i; - - if (!var->pointer_level && real_decl_type(var->arg->type)->type != PSI_T_STRUCT) { - return ptr; - } - val = val_ptr = calloc(var->pointer_level + 1, sizeof(void *)); - for (i = 1; i < var->pointer_level; ++i) { - val_ptr->ptr = (void **) val_ptr + 1; - val_ptr = val_ptr->ptr; - } - val_ptr->ptr = ptr; - return val; -} - typedef struct impl_type { char *name; token_t type; @@ -576,10 +555,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 +567,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 +584,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); @@ -687,9 +664,7 @@ typedef struct let_stmt { decl_var *var; let_value *val; impl_arg *arg; - impl_val out; void *ptr; - void *mem; } let_stmt; static inline let_stmt *init_let_stmt(decl_var *var, let_value *val) { @@ -730,6 +705,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,11 +990,6 @@ static void free_impls(impls *impls) { free(impls); } - -#define PSI_ERROR 16 -#define PSI_WARNING 32 -typedef void (*psi_error_cb)(int type, const char *msg, ...); - typedef struct decl_file { char *ln; char *fn; @@ -1057,6 +1028,46 @@ static inline void add_decl_lib(decl_libs *libs, void *dlopened) { libs->dl[libs->count-1] = dlopened; } +static inline impl_val *deref_impl_val(impl_val *ret_val, decl_var *var) { + unsigned i; + + if (var->arg->var != var) for (i = 1; i < var->pointer_level; ++i) { + ret_val = *(void **) ret_val; + } + return ret_val; +} + +static inline impl_val *enref_impl_val(void *ptr, decl_var *var) { + impl_val *val, *val_ptr; + unsigned i; + + if (!var->pointer_level && real_decl_type(var->arg->type)->type != PSI_T_STRUCT) { + return ptr; + } + val = val_ptr = calloc(var->pointer_level + 1, sizeof(void *)); + for (i = 1; i < var->pointer_level; ++i) { + val_ptr->ptr = (void **) val_ptr + 1; + val_ptr = val_ptr->ptr; + } + val_ptr->ptr = ptr; + return val; +} + +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 +typedef void (*psi_error_cb)(int type, const char *msg, ...); + #define PSI_DATA(D) ((PSI_Data *) (D)) #define PSI_DATA_MEMBERS \ constants *consts; \