X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=src%2Fcontext.c;h=d2293fe7bf4f360de6bd5bf19e4551e489e2559c;hp=c3f1cb11ac5e57221909d8bc2a3301153c646a44;hb=81b71a515e2024cee739deb6e207eb3b0e7c5d64;hpb=cfebc76ed7426836f21296cca9a14b422bfa04cf diff --git a/src/context.c b/src/context.c index c3f1cb1..d2293fe 100644 --- a/src/context.c +++ b/src/context.c @@ -4,85 +4,7 @@ #include "php.h" -#include -#ifdef HAVE_SYS_TYPES_H -# include -#endif -#ifdef HAVE_SYS_STAT_H -# include -#endif -#ifdef STDC_HEADERS -# include -# include -#else -# ifdef HAVE_STDLIB_H -# include -# endif -#endif -#ifdef HAVE_STRING_H -# if !defined STDC_HEADERS && defined HAVE_MEMORY_H -# include -# endif -# include -#endif -#ifdef HAVE_STRINGS_H -# include -#endif -#ifdef HAVE_INTTYPES_H -# include -#endif -#ifdef HAVE_STDINT_H -# include -#endif -#ifdef HAVE_UNISTD_H -# include -#endif - -#ifdef HAVE_ERRNO_H -# include -#endif -#ifdef HAVE_GLOB_H -# include -#endif -#ifdef HAVE_NETINET_IN_H -# include -#endif -#ifdef HAVE_ARPA_NAMESER_H -# include -#endif -#ifdef HAVE_NETDB_H -# include -#endif -#ifdef HAVE_RESOLV_H -# include -#endif -#ifdef HAVE_SYS_SELECT_H -# include -#endif -#ifdef HAVE_SYS_SOCKET_H -# include -#endif -#ifdef HAVE_SYS_TIME_H -# include -#endif -#ifdef HAVE_SYS_TIMES_H -# include -#endif -#ifdef HAVE_SYS_UIO_H -# include -#endif -#ifdef HAVE_SYS_UTSNAME_H -# include -#endif -#ifdef HAVE_TIME_H -# include -#endif -#ifdef HAVE_SYSLOG_H -# include -#endif -#ifdef HAVE_WCHAR_H -# include -#endif +#include "php_psi_stdinc.h" #ifdef HAVE_DIRENT_H # include @@ -129,84 +51,13 @@ static struct psi_std_type { {0} }; -static struct psi_predef_type { - token_t type_tag; - const char *type_name; - const char *alias; -} psi_predef_types[] = { - PSI_TYPES - {0} -}; - -static struct psi_predef_const { - token_t type_tag; - const char *type_name; - const char *var_name; - const char *val_text; - token_t val_type_tag; -} psi_predef_consts[] = { - PSI_CONSTS - {0} -}; - -PSI_MACROS - -struct utsname *uname2() { - struct utsname *u = calloc(1, sizeof(*u)); - uname(u); - return u; -} - -int psi_glob(const char *pattern, int flags, - int (*errfunc) (const char *epath, int eerrno), - glob_t *pglob) { - size_t offs = flags & GLOB_DOOFFS ? pglob->gl_offs : 0; - int rv = glob(pattern, flags, errfunc, pglob); - if (pglob->gl_pathv) { - while (offs--) { - pglob->gl_pathv[offs] = NULL; - } - } - return rv; -} - -static struct psi_func_redir { - const char *name; - void (*func)(void); -} psi_func_redirs[] = { - {"glob", (void (*)(void)) psi_glob}, - {"uname2", (void (*)(void)) uname2}, - PSI_REDIRS - {0} -}; - -static struct psi_predef_decl { - token_t type_tag; - const char *type_name; - const char *var_name; - size_t pointer_level; - size_t array_size; -} psi_predef_decls[] = { - PSI_DECLS - {0} -}; -static struct psi_predef_decl psi_predef_vararg_decls[] = { - PSI_VA_DECLS - {0} -}; - -static struct psi_predef_struct { - token_t type_tag; - const char *type_name; - const char *var_name; - size_t offset; - size_t size; - size_t pointer_level; - size_t array_size; -} psi_predef_structs[] = { - PSI_STRUCTS - {0} -}; +#include "php_psi_types.h" +#include "php_psi_consts.h" +#include "php_psi_macros.h" +#include "php_psi_redirs.h" +#include "php_psi_decls.h" +#include "php_psi_va_decls.h" +#include "php_psi_structs.h" static int validate_lib(PSI_Data *data, void **dlopened) { char lib[MAXPATHLEN]; @@ -957,6 +808,33 @@ static inline int validate_impl_stmts(PSI_Data *data, impl *impl) { return 1; } +static inline int validate_impl_args(PSI_Data *data, impl *impl) { + int def = 0; + size_t i; + + for (i = 0; i < impl->func->args->count; ++i) { + impl_arg *iarg = impl->func->args->args[i]; + + if (iarg->def) { + def = 1; + } else if (def) { + data->error(impl->func->token, PSI_WARNING, + "Non-optional argument %zu '$%s' of implementation '%s'" + " follows optional argument", + i+1, iarg->var->name, impl->func->name); + return 0; + } + } + + return 1; +} +static inline int validate_impl(PSI_Data *data, impl *impl) { + if (!validate_impl_args(data, impl)) { + return 0; + } + return validate_impl_stmts(data, impl); +} + PSI_Context *PSI_ContextInit(PSI_Context *C, PSI_ContextOps *ops, PSI_ContextErrorFunc error) { size_t i; @@ -1153,7 +1031,7 @@ int PSI_ContextValidate(PSI_Context *C, PSI_Parser *P) size_t i; for (i = 0; i < D->impls->count; ++i) { - if (validate_impl_stmts(PSI_DATA(C), D->impls->list[i])) { + if (validate_impl(PSI_DATA(C), D->impls->list[i])) { C->impls = add_impl(C->impls, D->impls->list[i]); } }