X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=src%2Ftypes%2Fnum_exp.h;h=96fcee19fb2eb01de6e032e7ba7a44d511eef11d;hp=e1b3b223beab9635c27e86fd490ebfaea9fa095b;hb=c9384515a81cb64d345b299908b2852f51bb8e6e;hpb=2f5af21b263403997e154658635d6b6e6eaab453 diff --git a/src/types/num_exp.h b/src/types/num_exp.h index e1b3b22..96fcee1 100644 --- a/src/types/num_exp.h +++ b/src/types/num_exp.h @@ -23,39 +23,87 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ -#ifndef PSI_TYPES_NUM_EXP -#define PSI_TYPES_NUM_EXP +#ifndef PSI_TYPES_NUM_EXP_H +#define PSI_TYPES_NUM_EXP_H #include "token.h" +#include "Zend/zend_types.h" -#include "constant.h" -#include "decl_var.h" -#include "impl_val.h" +struct psi_data; +struct psi_token; +struct psi_impl; +struct psi_const; +struct psi_decl_enum_item; +struct psi_let_exp; +struct psi_set_exp; +struct psi_call_frame; +struct psi_validate_scope; -typedef struct num_exp { +struct psi_num_exp { struct psi_token *token; - token_t t; + token_t op; 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; - -num_exp *init_num_exp(token_t t, void *num); -num_exp *copy_num_exp(num_exp *exp); -void free_num_exp(num_exp *exp); -void dump_num_exp(int fd, num_exp *exp); + struct { + struct psi_num_exp *lhs; + struct psi_num_exp *rhs; + } b; + struct { + struct psi_decl_type *typ; + struct psi_num_exp *num; + } c; + struct { + struct psi_num_exp *cond; + struct psi_num_exp *truthy; + struct psi_num_exp *falsy; + } t; + struct psi_num_exp *u; + struct psi_number *n; + } data; + token_t (*calc)(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res); +}; -struct psi_data; -struct decl_args; -struct decl_arg; -struct decl_enum; +struct psi_num_exp *psi_num_exp_init_ternary(token_t op, + struct psi_num_exp *cond, struct psi_num_exp *truthy, + struct psi_num_exp *falsy); +struct psi_num_exp *psi_num_exp_init_binary(token_t op, + struct psi_num_exp *lhs, struct psi_num_exp *rhs); +struct psi_num_exp *psi_num_exp_init_unary(token_t op, + struct psi_num_exp *u); +struct psi_num_exp *psi_num_exp_init_num(struct psi_number *n); +struct psi_num_exp *psi_num_exp_init_cast(struct psi_decl_type *typ, + struct psi_num_exp *num); +void psi_num_exp_free(struct psi_num_exp **c_ptr); + +struct psi_num_exp *psi_num_exp_copy(struct psi_num_exp *exp); +void psi_num_exp_dump(int fd, struct psi_num_exp *exp); +bool psi_num_exp_validate(struct psi_data *data, struct psi_num_exp *exp, + struct psi_validate_scope *scope); + +token_t psi_num_exp_exec(struct psi_num_exp *exp, impl_val *res, + struct psi_call_frame *frame, HashTable *defs); + +struct psi_plist *psi_num_exp_tokens(struct psi_num_exp *exp, + struct psi_plist *list); + + +#include "calc.h" +static inline zend_long psi_num_exp_get_long(struct psi_num_exp *exp, + struct psi_call_frame *frame, HashTable *defs) { + impl_val res = {0}; + + psi_calc_cast(psi_num_exp_exec(exp, &res, frame, defs), &res, + PSI_T_INT64, &res); + + return res.i64; +} +static inline double psi_num_exp_get_double(struct psi_num_exp *exp, + struct psi_call_frame *frame, HashTable *defs) { + impl_val res = {0}; + + psi_calc_cast(psi_num_exp_exec(exp, &res, frame, defs), &res, + PSI_T_DOUBLE, &res); -int validate_num_exp(struct psi_data *data, num_exp *exp, struct decl_args *dargs, struct decl_arg *func, struct decl_enum *enm); + return res.dval; +} #endif