X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=src%2Ftypes%2Freturn_stmt.c;h=8ff646d3d9448eea3f400df7c548ccab3e94283e;hp=8d32fc82f1907a2a580f8dfcd8e3b1bbc72b0b40;hb=2fa436074ca9a5e87f39b696de832fa2188fcfc6;hpb=2f5af21b263403997e154658635d6b6e6eaab453 diff --git a/src/types/return_stmt.c b/src/types/return_stmt.c index 8d32fc8..8ff646d 100644 --- a/src/types/return_stmt.c +++ b/src/types/return_stmt.c @@ -5,11 +5,11 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE @@ -21,86 +21,75 @@ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*******************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#else -# include "php_config.h" -#endif - -#include -#include + *******************************************************************************/ +#include "php_psi_stdinc.h" #include "data.h" +#include "call.h" -return_stmt *init_return_stmt(set_value *val) { - return_stmt *ret = calloc(1, sizeof(*ret)); - ret->set = val; +struct psi_return_stmt *psi_return_stmt_init(struct psi_return_exp *exp) +{ + struct psi_return_stmt *ret = calloc(1, sizeof(*ret)); + ret->exp = exp; return ret; } -void free_return_stmt(return_stmt *ret) { - if (ret->token) { - free(ret->token); - } - free_set_value(ret->set); - free(ret); -} - -void dump_return_stmt(int fd, return_stmt *ret) { - dprintf(fd, "\treturn "); - dump_set_value(fd, ret->set, 1, 0); +void psi_return_stmt_exec(struct psi_return_stmt *ret, zval *return_value, + struct psi_call_frame *frame) +{ + psi_return_exp_exec(ret->exp, return_value, frame); } -static inline decl *locate_impl_decl(decls *decls, return_stmt *ret) { - if (decls) { - size_t i; +void psi_return_stmt_free(struct psi_return_stmt **ret_ptr) +{ + if (*ret_ptr) { + struct psi_return_stmt *ret = *ret_ptr; - for (i = 0; i < decls->count; ++i) { - if (!strcmp(decls->list[i]->func->var->name, ret->set->vars->vars[0]->name)) { - ret->decl = decls->list[i]->func; - return decls->list[i]; - } - } + *ret_ptr = NULL; + psi_token_free(&ret->token); + psi_return_exp_free(&ret->exp); + free(ret); } +} - return NULL; +void psi_return_stmt_dump(int fd, struct psi_return_stmt *ret) +{ + dprintf(fd, "\treturn "); + psi_return_exp_dump(fd, ret->exp); + dprintf(fd, ";\n"); } -int validate_return_stmt(struct psi_data *data, impl *impl) { - return_stmt *ret; +bool psi_return_stmt_validate(struct psi_data *data, + struct psi_validate_scope *scope) +{ + struct psi_return_stmt *ret; + size_t count = psi_plist_count(scope->impl->stmts.ret); - /* we must have exactly one ret stmt delcaring the native func to call */ - /* and which type cast to apply */ - if (impl->stmts->ret.count != 1) { - if (impl->stmts->ret.count > 1) { - data->error(data, impl->stmts->ret.list[1]->token, PSI_WARNING, - "Too many `return` statements for implmentation %s;" - " found %zu, exactly one is needed", - impl->func->name, impl->stmts->ret.count); - } else { - data->error(data, impl->func->token, PSI_WARNING, - "Missing `return` statement for implementation %s", - impl->func->name); - } - return 0; - } + psi_plist_get(scope->impl->stmts.ret, 0, &ret); - ret = impl->stmts->ret.list[0]; - - if (!(impl->decl = locate_impl_decl(data->decls, ret))) { + /* + * we must have exactly one ret stmt declaring the native func to call + * and which type cast to apply + */ + switch (count) { + default: data->error(data, ret->token, PSI_WARNING, - "Missing declaration '%s' for `return` statment for implementation %s", - ret->set->vars->vars[0]->name, impl->func->name); - return 0; + "Too many `return` statements for implementation %s;" + " found %zu, exactly one is required", + scope->impl->func->name->val, count); + return false; + case 0: + data->error(data, scope->impl->func->token, PSI_WARNING, + "Missing `return` statement for implementation %s", + scope->impl->func->name->val); + return false; + case 1: + break; } - if (!validate_set_value(data, ret->set, 1, &ret->decl, impl->decl->args ? (int) impl->decl->args->count : 0, impl->decl->args ? impl->decl->args->args : NULL, 0)) { - return 0; + if (!psi_return_exp_validate(data, ret->exp, scope)) { + return false; } - //impl->decl->impl = impl; - - return 1; + return true; }