X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=src%2Ftypes%2Fimpl_var.c;h=7b690bb0b074769e02a3a45cf07b2b92fe99d245;hp=487a99703cb6397458a913843f78d92e8903d7af;hb=c9384515a81cb64d345b299908b2852f51bb8e6e;hpb=2f5af21b263403997e154658635d6b6e6eaab453 diff --git a/src/types/impl_var.c b/src/types/impl_var.c index 487a997..7b690bb 100644 --- a/src/types/impl_var.c +++ b/src/types/impl_var.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,55 +21,79 @@ 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 + *******************************************************************************/ +#include "php_psi_stdinc.h" #include "data.h" -impl_var *init_impl_var(const char *name, int is_reference) { - impl_var *var = calloc(1, sizeof(*var)); +struct psi_impl_var *psi_impl_var_init(const char *name, bool is_reference) +{ + struct psi_impl_var *var = calloc(1, sizeof(*var)); + var->name = strdup(name); + var->fqn = strdup(name); + var->reference = is_reference; return var; } -impl_var *copy_impl_var(impl_var *var) { - impl_var *cpy = malloc(sizeof(*cpy)); - memcpy(cpy, var, sizeof(*cpy)); +struct psi_impl_var *psi_impl_var_copy(struct psi_impl_var *var) +{ + struct psi_impl_var *cpy = malloc(sizeof(*cpy)); + + *cpy = *var; + cpy->name = strdup(cpy->name); + cpy->fqn = strdup(cpy->fqn); + if (cpy->token) { cpy->token = psi_token_copy(cpy->token); } return cpy; } -void free_impl_var(impl_var *var) { - if (var->token) { - free(var->token); +void psi_impl_var_free(struct psi_impl_var **var_ptr) +{ + if (*var_ptr) { + struct psi_impl_var *var = *var_ptr; + + *var_ptr = NULL; + if (var->token) { + free(var->token); + } + free(var->name); + free(var->fqn); + free(var); } - free(var->name); - free(var); } -impl_arg *locate_impl_var_arg(impl_var *var, impl_args *args) { - size_t i; +void psi_impl_var_dump(int fd, struct psi_impl_var *var, bool vararg) +{ + dprintf(fd, "%s%s%s", + var->reference ? "&" : "", + vararg ? "..." : "", + var->name); +} + +bool psi_impl_var_validate(struct psi_data *data, struct psi_impl_var *ivar, + struct psi_validate_scope *scope) +{ + if (scope && scope->current_let) { + struct psi_let_exp *current_let_exp = scope->current_let; + + while ((current_let_exp = current_let_exp->outer)) { + struct psi_impl_var *svar = psi_let_exp_get_impl_var(current_let_exp); - for (i = 0; i < args->count; ++i) { - impl_arg *iarg = args->args[i]; + ivar->fqn = psi_impl_var_name_prepend(ivar->fqn, svar->name + 1); + } + } else if (scope && scope->current_set) { + struct psi_set_exp *current_set_exp = scope->current_set; + while ((current_set_exp = current_set_exp->outer)) { + struct psi_impl_var *svar = psi_set_exp_get_impl_var(current_set_exp); - if (!strcmp(var->name, iarg->var->name)) { - return var->arg = iarg; + ivar->fqn = psi_impl_var_name_prepend(ivar->fqn, svar->name + 1); } } - return NULL; + return true; }