X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=src%2Ftypes%2Freturn_stmt.c;h=b4bcb523d6f42b2ed104d2a5eb9051f33a233014;hp=5df84814355635e6e748f2c4ebf020fd54b51385;hb=c9384515a81cb64d345b299908b2852f51bb8e6e;hpb=9bcb1df0786a8193d65949c857baaba2f4296e84 diff --git a/src/types/return_stmt.c b/src/types/return_stmt.c index 5df8481..b4bcb52 100644 --- a/src/types/return_stmt.c +++ b/src/types/return_stmt.c @@ -27,17 +27,17 @@ #include "data.h" #include "call.h" -struct psi_return_stmt *psi_return_stmt_init(struct psi_set_exp *val) +struct psi_return_stmt *psi_return_stmt_init(struct psi_return_exp *exp) { struct psi_return_stmt *ret = calloc(1, sizeof(*ret)); - ret->set = val; + ret->exp = exp; return ret; } void psi_return_stmt_exec(struct psi_return_stmt *ret, zval *return_value, struct psi_call_frame *frame) { - psi_set_exp_exec_ex(ret->set, return_value, frame->rpointer, frame); + psi_return_exp_exec(ret->exp, return_value, frame); } void psi_return_stmt_free(struct psi_return_stmt **ret_ptr) @@ -49,7 +49,7 @@ void psi_return_stmt_free(struct psi_return_stmt **ret_ptr) if (ret->token) { free(ret->token); } - psi_set_exp_free(&ret->set); + psi_return_exp_free(&ret->exp); free(ret); } } @@ -57,18 +57,17 @@ void psi_return_stmt_free(struct psi_return_stmt **ret_ptr) void psi_return_stmt_dump(int fd, struct psi_return_stmt *ret) { dprintf(fd, "\treturn "); - psi_set_exp_dump(fd, ret->set, 1, 1); + psi_return_exp_dump(fd, ret->exp); dprintf(fd, ";\n"); } -bool psi_return_stmt_validate(struct psi_data *data, struct psi_impl *impl) +bool psi_return_stmt_validate(struct psi_data *data, + struct psi_validate_scope *scope) { - size_t i = 0; - struct psi_decl *decl; struct psi_return_stmt *ret; - size_t count = psi_plist_count(impl->stmts.ret); + size_t count = psi_plist_count(scope->impl->stmts.ret); - psi_plist_get(impl->stmts.ret, 0, &ret); + psi_plist_get(scope->impl->stmts.ret, 0, &ret); /* * we must have exactly one ret stmt declaring the native func to call @@ -79,32 +78,18 @@ bool psi_return_stmt_validate(struct psi_data *data, struct psi_impl *impl) data->error(data, ret->token, PSI_WARNING, "Too many `return` statements for implementation %s;" " found %zu, exactly one is required", - impl->func->name, count); + scope->impl->func->name, count); return false; case 0: - data->error(data, impl->func->token, PSI_WARNING, + data->error(data, scope->impl->func->token, PSI_WARNING, "Missing `return` statement for implementation %s", - impl->func->name); + scope->impl->func->name); return false; case 1: break; } - while (psi_plist_get(data->decls, i++, &decl)) { - if (!strcmp(decl->func->var->name, ret->set->data.func->var->name)) { - impl->decl = decl; - break; - } - } - - if (!impl->decl) { - data->error(data, ret->token, PSI_WARNING, - "Missing declaration '%s' for `return` statement of implementation %s", - ret->set->data.func->var->name, impl->func->name); - return false; - } - - if (!psi_set_exp_validate(data, ret->set, impl, NULL)) { + if (!psi_return_exp_validate(data, ret->exp, scope)) { return false; }