impl_val val = {0};
switch (psi_calc_num_exp(exp, ref, &val)) {
- case PSI_T_UINT8: val.u16 = val.u8;
- case PSI_T_UINT16: val.u32 = val.u16;
- case PSI_T_UINT32: val.u64 = val.u32;
- case PSI_T_UINT64: return val.u64;
- case PSI_T_INT8: val.i16 = val.i8;
- case PSI_T_INT16: val.i32 = val.i16;
- case PSI_T_INT32: val.i64 = val.i32;
+ case PSI_T_UINT8: return val.u8;
+ case PSI_T_UINT16: return val.u16;
+ case PSI_T_UINT32: return val.u32;
+ case PSI_T_UINT64: return val.u64; /* FIXME */
+ case PSI_T_INT8: return val.i8;
+ case PSI_T_INT16: return val.i16;
+ case PSI_T_INT32: return val.i32;
case PSI_T_INT64: return val.i64;
- case PSI_T_FLOAT: val.dval = val.fval;
+ case PSI_T_FLOAT: return val.fval;
case PSI_T_DOUBLE: return val.dval;
EMPTY_SWITCH_DEFAULT_CASE();
}
}
return 1;
}
-static inline decl_arg *locate_decl_var_arg(decl_var *var, decl_args *args) {
+static inline decl_arg *locate_decl_var_arg(decl_var *var, decl_args *args, decl_arg *func) {
size_t i;
for (i = 0; i < args->count; ++i) {
return var->arg = arg;
}
}
+ if (func && !strcmp(var->name, func->var->name)) {
+ return var->arg = func;
+ }
return NULL;
}
static inline decl_arg *locate_struct_member(decl_struct *s, decl_var *var) {
if (s->args) {
- return locate_decl_var_arg(var, s->args);
+ return locate_decl_var_arg(var, s->args, NULL);
}
return NULL;
return NULL;
}
-static inline int validate_num_exp(PSI_Data *data, decl_args *dargs, num_exp *exp) {
+static inline int validate_num_exp(PSI_Data *data, decl_args *dargs, decl_arg *func, num_exp *exp) {
if (exp->operand) {
switch (exp->operator) {
case PSI_T_PLUS:
break;
EMPTY_SWITCH_DEFAULT_CASE();
}
- if (!validate_num_exp(data, dargs, exp->operand)) {
+ if (!validate_num_exp(data, dargs, func, exp->operand)) {
return 0;
}
}
switch (exp->t) {
case PSI_T_NAME:
- if (!locate_decl_var_arg(exp->u.dvar, dargs)) {
+ if (!locate_decl_var_arg(exp->u.dvar, dargs, func)) {
data->error(PSI_WARNING, "Unknown variable '%s' in numeric expression",
exp->u.dvar->name);
return 0;
}
for (i = 1; i < set->vars->count; ++i) {
- if (!locate_decl_var_arg(set->vars->vars[i], ref_list)) {
+ if (!locate_decl_var_arg(set->vars->vars[i], ref_list, ref)) {
return 0;
}
}
}
}
if (set->num) {
- if (!validate_num_exp(data, ref_list, set->num)) {
+ if (!validate_num_exp(data, ref_list, ref, set->num)) {
return 0;
}
}
} else if (set->count == 1) {
/* to_array(ptr, to_string(*ptr)) */
decl_var *sub_var = set->inner[0]->vars->vars[0];
- decl_arg *sub_ref = locate_decl_var_arg(sub_var, ref_list);
+ decl_arg *sub_ref = locate_decl_var_arg(sub_var, ref_list, ref);
set->inner[0]->outer.set = set;
if (sub_ref) {
int check = 0;
if (let->val && let->val->func && let->val->func->alloc) {
- if (!validate_num_exp(data, impl->decl->args, let->val->func->alloc->nmemb)) {
+ if (!validate_num_exp(data, impl->decl->args, impl->decl->func, let->val->func->alloc->nmemb)) {
return 0;
}
- if (!validate_num_exp(data, impl->decl->args, let->val->func->alloc->size)) {
+ if (!validate_num_exp(data, impl->decl->args, impl->decl->func, let->val->func->alloc->size)) {
return 0;
}
}