X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=src%2Ftypes%2Freturn_stmt.c;h=8ff646d3d9448eea3f400df7c548ccab3e94283e;hb=09529efcde471127419e141807b83b37077003a0;hp=5df84814355635e6e748f2c4ebf020fd54b51385;hpb=9bcb1df0786a8193d65949c857baaba2f4296e84;p=m6w6%2Fext-psi diff --git a/src/types/return_stmt.c b/src/types/return_stmt.c index 5df8481..8ff646d 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) @@ -46,10 +46,8 @@ void psi_return_stmt_free(struct psi_return_stmt **ret_ptr) struct psi_return_stmt *ret = *ret_ptr; *ret_ptr = NULL; - if (ret->token) { - free(ret->token); - } - psi_set_exp_free(&ret->set); + psi_token_free(&ret->token); + psi_return_exp_free(&ret->exp); free(ret); } } @@ -57,18 +55,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 +76,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->val, 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->val); 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; }