-static inline int psi_calc_num_exp_value(num_exp *exp, impl_val *strct, impl_val *res) {
- impl_val *ref, *tmp = NULL;
-
- switch (exp->t) {
- case PSI_T_NUMBER:
- switch (is_numeric_string(exp->u.numb, strlen(exp->u.numb), (zend_long *) res, (double *) res, 0)) {
- case IS_LONG:
- return PSI_T_INT64;
- case IS_DOUBLE:
- return PSI_T_DOUBLE;
- }
- break;
-
- case PSI_T_NSNAME:
- switch (exp->u.cnst->type->type) {
- case PSI_T_INT:
- res->i64 = zend_get_constant_str(exp->u.cnst->name, strlen(exp->u.cnst->name))->value.lval;
- return PSI_T_INT64;
- case PSI_T_FLOAT:
- res->dval = zend_get_constant_str(exp->u.cnst->name, strlen(exp->u.cnst->name))->value.dval;
- return PSI_T_DOUBLE;
- default:
- return 0;
- }
- break;
-
- case PSI_T_ENUM:
- return psi_calc_num_exp(exp->u.enm->num ?: &exp->u.enm->inc, NULL, res);
- break;
-
- case PSI_T_NAME:
- if (strct) {
- ref = struct_member_ref(exp->u.dvar->arg, strct, &tmp);
- } else {
- ref = exp->u.dvar->arg->let;
- }
- switch (real_decl_type(exp->u.dvar->arg->type)->type) {
- case PSI_T_INT8:
- case PSI_T_UINT8:
- case PSI_T_INT16:
- case PSI_T_UINT16:
- case PSI_T_INT32:
- case PSI_T_UINT32:
- case PSI_T_INT64:
- case PSI_T_UINT64:
- memcpy(res, deref_impl_val(ref, exp->u.dvar), sizeof(*res));
- if (tmp) {
- free(tmp);
- }
- return real_decl_type(exp->u.dvar->arg->type)->type;
-
- case PSI_T_FLOAT:
- case PSI_T_DOUBLE:
- memcpy(res, deref_impl_val(ref, exp->u.dvar), sizeof(*res));
- if (tmp) {
- free(tmp);
- }
- return real_decl_type(exp->u.dvar->arg->type)->type;
-
- EMPTY_SWITCH_DEFAULT_CASE();
- }
- break;
-
- EMPTY_SWITCH_DEFAULT_CASE();
- }
- return 0;
-}
-
-int psi_calc_num_exp(num_exp *exp, impl_val *strct, impl_val *res) {
- impl_val num = {0};
- int num_type = psi_calc_num_exp_value(exp, strct, &num);
-
- if (exp->operand) {
- impl_val tmp = {0};
- int tmp_type = psi_calc_num_exp(exp->operand, strct, &tmp);
-
- return exp->calculator(num_type, &num, tmp_type, &tmp, res);
- }
-
- memcpy(res, &num, sizeof(*res));
- return num_type;
-}
-