+static inline int validate_let_func(PSI_Data *data, let_func *func, impl *impl) {
+ int check = 0;
+ size_t j;
+
+ if (impl->func->args) {
+ for (j = 0; j < impl->func->args->count; ++j) {
+ impl_arg *iarg = impl->func->args->args[j];
+
+ if (!strcmp(func->var->name, iarg->var->name)) {
+ func->arg = iarg;
+ check = 1;
+ break;
+ }
+ }
+ }
+ if (!check) {
+ data->error(data, func->var->token, PSI_WARNING, "Unknown value '$%s' of `let` statement"
+ " for cast '%s' of implementation '%s'",
+ func->var->name, func->name, impl->func->name);
+ return 0;
+ }
+ return 1;
+}
+
+static inline int validate_let_callback(PSI_Data *data, decl_var *let_var, let_callback *cb, impl *impl) {
+ decl_type *cb_type;
+ decl *cb_func;
+ size_t i;
+
+ if (!validate_let_func(data, cb->func, impl)) {
+ return 0;
+ }
+
+ cb_type = real_decl_type(let_var->arg->type);
+ if (cb_type->type != PSI_T_FUNCTION) {
+ data->error(data, let_var->token, PSI_WARNING, "Not a function: %s", let_var->name);
+ return 0;
+ }
+ cb_func = cb_type->func;
+ for (i = 0; i < cb->args->count; ++i) {
+ if (!validate_set_value(data, cb->args->vals[i], cb_func->args->count, cb_func->args->args, 0)) {
+ return 0;
+ }
+ }
+}
+