X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=src%2Ftypes%2Fimpl_func.c;h=a701134e4a54ea9bc34abdcf4147a83e9f649d24;hp=b728b0ccc92400d3675d3c0cca4aa331729b8207;hb=d2e0af1718294569a84c3c15616c74e4d55ea579;hpb=f74ce3f29e2dadd9f839c33ad5292e56e9203efd diff --git a/src/types/impl_func.c b/src/types/impl_func.c index b728b0c..a701134 100644 --- a/src/types/impl_func.c +++ b/src/types/impl_func.c @@ -23,15 +23,19 @@ 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_impl_func *psi_impl_func_init(const char *name, +struct psi_impl_func *psi_impl_func_init(zend_string *name, struct psi_plist *args, struct psi_impl_type *type) { - struct psi_impl_func *func = calloc(1, sizeof(*func)); + struct psi_impl_func *func = pecalloc(1, sizeof(*func), 1); - func->name = strdup(name); + func->name = zend_string_copy(name); func->args = args ? : psi_plist_init((psi_plist_dtor) psi_impl_arg_free); func->return_type = type; @@ -45,9 +49,7 @@ void psi_impl_func_free(struct psi_impl_func **f_ptr) struct psi_impl_func *f = *f_ptr; *f_ptr = NULL; - if (f->token) { - free(f->token); - } + psi_token_free(&f->token); psi_impl_type_free(&f->return_type); psi_plist_free(f->args); @@ -56,12 +58,13 @@ void psi_impl_func_free(struct psi_impl_func **f_ptr) psi_impl_arg_free(&f->vararg); } - free(f->name); + zend_string_release(f->name); free(f); } } -bool psi_impl_func_validate(struct psi_data *data, struct psi_impl_func *func) +bool psi_impl_func_validate(struct psi_data *data, struct psi_impl_func *func, + struct psi_validate_scope *scope) { int def = 0; size_t i = 0; @@ -70,7 +73,7 @@ bool psi_impl_func_validate(struct psi_data *data, struct psi_impl_func *func) while (psi_plist_get(func->args, i++, &iarg)) { if (iarg->def) { def = 1; - if (!psi_impl_def_val_validate(data, iarg->def, iarg->type->type, iarg->type->name)) { + if (!psi_impl_def_val_validate(data, iarg->def, iarg->type, scope)) { return 0; } } else if (def) { @@ -78,7 +81,7 @@ bool psi_impl_func_validate(struct psi_data *data, struct psi_impl_func *func) "Non-optional argument %zu '$%s' of implementation '%s'" " follows optional argument", i + 1, - iarg->var->name, func->name); + iarg->var->name->val, func->name->val); return false; } } @@ -86,25 +89,25 @@ bool psi_impl_func_validate(struct psi_data *data, struct psi_impl_func *func) return true; } -void psi_impl_func_dump(int fd, struct psi_impl_func *func) +void psi_impl_func_dump(struct psi_dump *dump, struct psi_impl_func *func) { - dprintf(fd, "function %s(", func->name); + PSI_DUMP(dump, "function %s(", func->name->val); if (func->args) { size_t i = 0; struct psi_impl_arg *iarg; while (psi_plist_get(func->args, i++, &iarg)) { if (i > 1) { - dprintf(fd, ", "); + PSI_DUMP(dump, ", "); } - psi_impl_arg_dump(fd, iarg, false); + psi_impl_arg_dump(dump, iarg, false); } if (func->vararg) { - dprintf(fd, ", "); - psi_impl_arg_dump(fd, func->vararg, true); + PSI_DUMP(dump, ", "); + psi_impl_arg_dump(dump, func->vararg, true); } } - dprintf(fd, ") : %s%s", func->return_reference ? "&" : "", - func->return_type->name); + PSI_DUMP(dump, ") : %s%s", func->return_reference ? "&" : "", + func->return_type->name->val); }