OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
-#include "php_psi_stdinc.h"
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#else
+# include "php_config.h"
+#endif
#include "data.h"
struct psi_let_callback *psi_let_callback_init(struct psi_let_func *func,
struct psi_plist *args, struct psi_plist *cb_args)
{
- struct psi_let_callback *cb = calloc(1, sizeof(*cb));
+ struct psi_let_callback *cb = pecalloc(1, sizeof(*cb), 1);
cb->func = func;
cb->args = args;
cb->cb_args = cb_args;
if (cb->cb_args) {
psi_plist_free(cb->cb_args);
}
- if (cb->token) {
- free(cb->token);
- }
+ psi_token_free(&cb->token);
free(cb);
}
}
data->error(data, cb->token, PSI_WARNING,
"Argument count of callback statement of implementation '%s'"
"does not match argument count of callback declaration '%s'",
- impl->func->name, cb_decl->func->var->name);
+ impl->func->name->val, cb_decl->func->var->name->val);
return false;
}
return true;
}
-bool psi_let_callback_validate(struct psi_data *data, struct psi_let_exp *exp,
- struct psi_let_callback *cb, struct psi_impl *impl)
+bool psi_let_callback_validate(struct psi_data *data, struct psi_let_callback *cb,
+ struct psi_validate_scope *scope)
{
size_t i = 0;
struct psi_decl_type *cb_type;
+ struct psi_let_exp *exp = scope->current_let;
struct psi_decl_var *cb_var = exp->var;
- struct psi_set_exp *set_exp;
+ struct psi_set_exp *set_exp, *parent_set = scope->current_set;
cb_type = psi_decl_type_get_real(cb_var->arg->type);
if (cb_type->type != PSI_T_FUNCTION) {
data->error(data, cb_var->token, PSI_WARNING,
"Expected a function: %s",
- cb_var->name);
+ cb_var->name->val);
return false;
}
cb->decl = cb_type->real.func;
- if (!psi_decl_validate_nodl(data, cb->decl, NULL /* FIXME type_stack */)) {
+ if (!psi_decl_validate_nodl(data, cb->decl, scope)) {
return false;
}
- if (!psi_let_callback_validate_decl_args(data, cb, cb->decl, impl)) {
+ if (!psi_let_callback_validate_decl_args(data, cb, cb->decl, scope->impl)) {
return false;
}
while (psi_plist_get(cb->args, i++, &set_exp)) {
dvar->arg = cb_var->arg;
}
}
- if (!psi_set_exp_validate(data, set_exp, impl, cb->decl)) {
+
+ scope->current_set = set_exp;
+ scope->cb_decl = cb->decl;
+
+ if (!psi_set_exp_validate(data, set_exp, scope)) {
+ scope->cb_decl = NULL;
+ scope->current_set = parent_set;
return false;
}
+ scope->cb_decl = NULL;
+ scope->current_set = parent_set;
}
return true;
}
-void psi_let_callback_dump(int fd, struct psi_let_callback *callback,
+void psi_let_callback_dump(struct psi_dump *dump, struct psi_let_callback *callback,
unsigned level)
{
- dprintf(fd, "callback(");
+ PSI_DUMP(dump, "callback(");
if (callback->cb_args) {
size_t i = 0;
struct psi_decl_var *cb_arg;
while (psi_plist_get(callback->cb_args, i++, &cb_arg)) {
if (i > 1) {
- dprintf(fd, ", ");
+ PSI_DUMP(dump, ", ");
}
- psi_decl_var_dump(fd, cb_arg);
+ psi_decl_var_dump(dump, cb_arg);
}
}
- dprintf(fd, ") as %s(%s(",
- callback->func->name,
- callback->func->var->name);
+ PSI_DUMP(dump, ") as %s(%s(",
+ callback->func->name->val,
+ callback->func->var->name->val);
if (callback->args) {
size_t i = 0, last = psi_plist_count(callback->args);
struct psi_set_exp *set;
- dprintf(fd, "\n");
+ PSI_DUMP(dump, "\n");
++level;
while (psi_plist_get(callback->args, i++, &set)) {
- psi_set_exp_dump(fd, set, level, i == last);
- dprintf(fd, "\n");
+ psi_set_exp_dump(dump, set, level, i == last);
+ PSI_DUMP(dump, "\n");
}
--level;
- dprintf(fd, "%s", psi_t_indent(level));
+ PSI_DUMP(dump, "%s", psi_t_indent(level));
}
- dprintf(fd, "))");
+ PSI_DUMP(dump, "))");
}