X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=src%2Ftypes%2Freturn_stmt.c;h=9dc62f703d9f5471ad4cbabc1dbe77ab71fdf497;hb=698841dfdd4d70d24e0b7af25ac7100bc2cb26a4;hp=c28ba751073e0e3051b1a678af9c0a55501ba79c;hpb=53495ef4bd0321f7f92dd05eef8e01b90d7b415a;p=m6w6%2Fext-psi diff --git a/src/types/return_stmt.c b/src/types/return_stmt.c index c28ba75..9dc62f7 100644 --- a/src/types/return_stmt.c +++ b/src/types/return_stmt.c @@ -23,23 +23,25 @@ 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" #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; + struct psi_return_stmt *ret = pecalloc(1, sizeof(*ret), 1); + ret->exp = exp; return ret; } void psi_return_stmt_exec(struct psi_return_stmt *ret, zval *return_value, struct psi_call_frame *frame) { - void *rpointer = psi_call_frame_get_rpointer(frame); - - psi_set_exp_exec_ex(ret->set, return_value, rpointer, frame); + psi_return_exp_exec(ret->exp, return_value, frame); } void psi_return_stmt_free(struct psi_return_stmt **ret_ptr) @@ -48,29 +50,26 @@ 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); } } -void psi_return_stmt_dump(int fd, struct psi_return_stmt *ret) +void psi_return_stmt_dump(struct psi_dump *dump, struct psi_return_stmt *ret) { - dprintf(fd, "\treturn "); - psi_set_exp_dump(fd, ret->set, 1, 1); - dprintf(fd, ";\n"); + PSI_DUMP(dump, "\treturn "); + psi_return_exp_dump(dump, ret->exp); + PSI_DUMP(dump, ";\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 @@ -81,32 +80,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; }