From: Michael Wallner Date: Fri, 3 Feb 2017 10:34:58 +0000 (+0100) Subject: configure: generate less files, and do that in build dir X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=894e0ce93f9ce82109e904ae35c249bf6abe54f1;p=m6w6%2Fext-psi configure: generate less files, and do that in build dir --- diff --git a/Makefile.frag b/Makefile.frag index 2898211..4d3d726 100644 --- a/Makefile.frag +++ b/Makefile.frag @@ -57,12 +57,9 @@ $(PHP_PSI_SRCDIR)/src/parser.re: $(PHP_PSI_SRCDIR)/src/parser_proc.h $(PHP_PSI_SRCDIR)/src/parser.c: $(PHP_PSI_SRCDIR)/src/parser.re $(RE2C) -o $@ $< -$(PHP_PSI_SRCDIR)/src/types/decl.c: $(PHP_PSI_SRCDIR)/php_psi_macros.h $(PHP_PSI_SRCDIR)/php_psi_redirs.h -$(PHP_PSI_SRCDIR)/src/context.c: $(PHP_PSI_SRCDIR)/php_psi_consts.h $(PHP_PSI_SRCDIR)/php_psi_decls.h $(PHP_PSI_SRCDIR)/php_psi_fn_decls.h $(PHP_PSI_SRCDIR)/php_psi_structs.h $(PHP_PSI_SRCDIR)/php_psi_types.h $(PHP_PSI_SRCDIR)/php_psi_unions.h $(PHP_PSI_SRCDIR)/php_psi_va_decls.h - # -- deps -PHP_PSI_DEPEND = $(PHP_PSI_BUILDDIR)/php_psi.dep $(patsubst $(PHP_PSI_SRCDIR)/%,$(PHP_PSI_BUILDDIR)/%,$(PHP_PSI_SOURCES:.c=.dep)) +PHP_PSI_DEPEND = $(patsubst $(PHP_PSI_SRCDIR)/%,$(PHP_PSI_BUILDDIR)/%,$(PHP_PSI_SOURCES:.c=.dep)) .PHONY: psi-clean-depend psi-clean-depend: @@ -75,6 +72,8 @@ $(PHP_PSI_BUILDDIR)/%.dep: $(PHP_PSI_SRCDIR)/%.c $(CPPFLAGS) $(DEFS) $(INCLUDES) $< \ || touch $@ +php_psi_stdinc.h: + ifneq ($(findstring clean,$(MAKECMDGOALS)),clean) ifneq ($(PSI_DEPS),) -include $(PHP_PSI_DEPEND) diff --git a/config.m4 b/config.m4 index a873ab9..be38dcf 100644 --- a/config.m4 +++ b/config.m4 @@ -15,7 +15,7 @@ m4_foreach(incfile, [ [psi/psi_const.m4], [psi/psi_decl.m4], [psi/psi_macro.m4], - [psi/psi_struct.m4], + [psi/psi_composite.m4], [posix/errno.m4], [posix/fcntl.m4], [posix/glob.m4], @@ -139,19 +139,10 @@ if test "$PHP_PSI" != no; then AC_DEFINE_UNQUOTED(PHP_PSI_SHLIB_SUFFIX, ["$SHLIB_SUFFIX_NAME"], DL suffix) - AC_DEFINE_UNQUOTED([PSI_STDINC], ["$PSI_STDINC"], [Standard includes]) - AC_DEFINE_UNQUOTED([PSI_TYPES], ["$PSI_TYPES"], [Predefined types]) - AC_DEFINE_UNQUOTED([PSI_STRUCTS], ["$PSI_STRUCTS"], [Predefined structs]) - AC_DEFINE_UNQUOTED([PSI_UNIONS], ["$PSI_UNIONS"], [Predefined structs]) - AC_DEFINE_UNQUOTED([PSI_CONSTS], ["$PSI_CONSTS"], [Predefined constants]) - AC_DEFINE_UNQUOTED([PSI_MACROS], ["$PSI_MACROS"], [Redirected Macros]) - AC_DEFINE_UNQUOTED([PSI_REDIRS], ["$PSI_REDIRS"], [Redirected functions]) - AC_DEFINE_UNQUOTED([PSI_DECLS], ["$PSI_DECLS"], [Predefined functions]) - AC_DEFINE_UNQUOTED([PSI_VA_DECLS], ["$PSI_VA_DECLS"], [Predefined vararg functions]) - PHP_ADD_INCLUDE($PHP_PSI_SRCDIR) PHP_ADD_INCLUDE($PHP_PSI_SRCDIR/src) PHP_ADD_INCLUDE($PHP_PSI_SRCDIR/src/types) + PHP_ADD_INCLUDE($PHP_PSI_BUILDDIR) PHP_ADD_BUILD_DIR($PHP_PSI_BUILDDIR/src) PHP_ADD_BUILD_DIR($PHP_PSI_BUILDDIR/src/types) diff --git a/m4/psi/psi.m4 b/m4/psi/psi.m4 index b979719..b0e30f4 100644 --- a/m4/psi/psi.m4 +++ b/m4/psi/psi.m4 @@ -1,15 +1,3 @@ -dnl Generated headers with pre-defined types, structs, consts and decls. -PSI_STDINC=$PHP_PSI_SRCDIR/php_psi_stdinc.h -PSI_STDTYPES=$PHP_PSI_SRCDIR/php_psi_stdtypes.h -PSI_TYPES=$PHP_PSI_SRCDIR/php_psi_types.h -PSI_STRUCTS=$PHP_PSI_SRCDIR/php_psi_structs.h -PSI_UNIONS=$PHP_PSI_SRCDIR/php_psi_unions.h -PSI_CONSTS=$PHP_PSI_SRCDIR/php_psi_consts.h -PSI_REDIRS=$PHP_PSI_SRCDIR/php_psi_redirs.h -PSI_MACROS=$PHP_PSI_SRCDIR/php_psi_macros.h -PSI_DECLS=$PHP_PSI_SRCDIR/php_psi_decls.h -PSI_VA_DECLS=$PHP_PSI_SRCDIR/php_psi_va_decls.h -PSI_FN_DECLS=$PHP_PSI_SRCDIR/php_psi_fn_decls.h dnl PSI_CONFIG_INIT() dnl Creates stubs of the headers with pre-defined types etc. @@ -37,108 +25,26 @@ AC_DEFUN(PSI_CONFIG_INIT, [ fi fi - cat >$PHP_PSI_BUILDDIR/php_psi.dep <>$PHP_PSI_BUILDDIR/php_psi.dep <$i <>$PSI_STDTYPES <@ = { - {PSI_T_INT8, "int8_t", NULL}, - {PSI_T_INT16, "int16_t", NULL}, - {PSI_T_INT32, "int32_t", NULL}, - {PSI_T_INT64, "int64_t", NULL}, - {PSI_T_UINT8, "uint8_t", NULL}, - {PSI_T_UINT16, "uint16_t", NULL}, - {PSI_T_UINT32, "uint32_t", NULL}, - {PSI_T_UINT64, "uint64_t", NULL}, -EOF - cat >>$PSI_TYPES <@ = { -EOF - cat >>$PSI_STRUCTS <@ = { -EOF - cat >>$PSI_UNIONS <@ = { -EOF - cat >>$PSI_CONSTS <@ = { -EOF - cat >>$PSI_REDIRS <@ = { -EOF - cat >>$PSI_MACROS <>$PSI_DECLS <@ = { -EOF - cat >>$PSI_VA_DECLS <@ = { -EOF - cat >>$PSI_FN_DECLS <@ = { -EOF + PSI_STDTYPES= + PSI_TYPES= + PSI_COMPOSITES= + PSI_CONSTS= + PSI_REDIRS= + PSI_MACROS= + PSI_DECLS= + + AC_CONFIG_FILES( + [$PHP_PSI_BUILDDIR/php_psi_stdinc.h:$PHP_PSI_SRCDIR/php_psi_stdinc.h.in] + [$PHP_PSI_BUILDDIR/php_psi_posix.h:$PHP_PSI_SRCDIR/php_psi_posix.h.in] + ) + ]) dnl PSI_CONFIG_DONE() dnl Finish the headers with the pre-defined types etc. AC_DEFUN(PSI_CONFIG_DONE, [ - - wait - if $PSI_FAST_CONFIG; then + wait for conf_env in $PSI_CONFIG_TMP/*/conf.env; do source $conf_env done @@ -148,33 +54,15 @@ AC_DEFUN(PSI_CONFIG_DONE, [ LIBS=$psi_save_LIBS PHP_EVAL_LIBLINE($psi_eval_LIBS, PSI_SHARED_LIBADD) - cat >$PSI_STDINC <>$i <$PSI_CONFIG_TMP/AS_TR_SH([$1])/conf.env <>$PSI_CONFIG_TMP/AS_TR_SH([$1])/conf.env <&66 ) & @@ -410,7 +314,7 @@ AC_DEFUN([PSI_SH_TEST_ALIGNOF], [test -n "$AS_TR_SH([ac_cv_alignof_]$1)" && test dnl PSI_CHECK_SIZEOF(type, special-includes) dnl AC_CHECK_SIZEOF wrapper with PSI_INCLUDES -dnl Defines psi\\SIZEOF_ pre-defined constant in $PSI_CONSTS. +dnl Defines psi\\SIZEOF_ pre-defined constant in $PSI_CONSTS_H. AC_DEFUN(PSI_CHECK_SIZEOF, [ AC_CHECK_SIZEOF($1, [], PSI_INCLUDES $2) @@ -421,7 +325,7 @@ AC_DEFUN(PSI_CHECK_SIZEOF, [ dnl PSI_CHECK_ALIGNOF(type, special-includes) dnl AC_CHECK_ALIGNOF wrapper with PSI_INCLUDES -dnl Defines psi\\ALIGNOF_ pre-defined constant in $PSI_CONSTS. +dnl Defines psi\\ALIGNOF_ pre-defined constant in $PSI_CONSTS_H. AC_DEFUN(PSI_CHECK_ALIGNOF, [ AC_CHECK_ALIGNOF($1, PSI_INCLUDES $2) diff --git a/m4/psi/psi_composite.m4 b/m4/psi/psi_composite.m4 new file mode 100644 index 0000000..ddd5d0d --- /dev/null +++ b/m4/psi/psi_composite.m4 @@ -0,0 +1,77 @@ +# psi_add_composite(composite members) +# Add a pre-defined composite (struct or union) +psi_add_composite() { + PSI_COMPOSITES="$PSI_COMPOSITES + $1, {0}," +} + +dnl PSI_COMPOSITE_MEMBER(composite name, decl member) +dnl INTERNAL: build $psi_composite_members +AC_DEFUN(PSI_COMPOSITE_MEMBER, [ + m4_define([member_name], PSI_VAR_NAME($2)) + m4_define([member_type], PSI_VAR_TYPE($2)) + PSI_CHECK_SIZEOF(AS_TR_SH($1)[_]member_name, + [#define ]AS_TR_SH($1)[_]member_name (($1 *)0)->member_name + ) + if PSI_SH_TEST_SIZEOF($1 member_name); then + PSI_CHECK_OFFSETOF($1, member_name) + PSI_TYPE_INDIRECTION($2, [PSI_SH_SIZEOF([$1 member_name])], pl, as) + + psi_member_sizeof=PSI_SH_SIZEOF($1 member_name) + psi_member_offsetof=PSI_SH_OFFSETOF($1 member_name) + + if test $pl -gt 0 && test $as -eq 0; then + check_size=PSI_SH_SIZEOF(void *) + elif test $pl -eq 1 && test $as -gt 0; then + check_size=`expr PSI_SH_SIZEOF(member_type) \* $as` + else + check_size=PSI_SH_SIZEOF(member_type) + fi + if test $psi_member_sizeof != "$check_size"; then + psi_member_basic_type=PSI_SH_BASIC_TYPE(member_type) + psi_member_type_pair="`psi_type_pair $psi_member_basic_type $psi_member_sizeof`" + psi_composite_members="$psi_composite_members, {$psi_member_type_pair, \"[]member_name[]\", $psi_member_offsetof, $psi_member_sizeof, $pl, $as}" + AC_MSG_WARN(pre-defined size $check_size of $2 in $1 does not match computed size $psi_member_sizeof; adjusting to $psi_member_type_pair) + else + psi_composite_members="[$psi_composite_members, {]PSI_TYPE_PAIR(member_type)[, \"]member_name[\", $psi_member_offsetof, $psi_member_sizeof, $pl, $as}]" + fi + fi +]) + +dnl PSI_STRUCT(struct name, struct members) +dnl Check a struct and its members and add a pre-defined struct and possibly a +dnl pre-defined type for this struct. +dnl Calls PSI_CHECK_SIZEOF and PSI_CHECK_ALIGNOF for the struct. +dnl Calls PSI_CHECK_SIZEOF, PSI_CHECK_OFFSETOF and PSI_TYPE_INDIRECTON for each member. +AC_DEFUN(PSI_STRUCT, [ + PSI_CHECK_SIZEOF($1) + if PSI_SH_TEST_SIZEOF($1); then + PSI_CHECK_ALIGNOF($1) + psi_composite_name=m4_bregexp([$1], [^\(struct \)?\(\w+\)], [\2]) + psi_composite_members="{PSI_T_STRUCT, \"struct\", \"$psi_composite_name\", PSI_SH_ALIGNOF($1), PSI_SH_SIZEOF($1), 0, 0}" + ifelse([$2],,,[m4_map_args_sep([PSI_COMPOSITE_MEMBER($1, m4_normalize(], [))], [], $2)]) + psi_add_composite "$psi_composite_members" + if test "$1" = "$psi_composite_name"; then + psi_add_type "{PSI_T_STRUCT, \"$1\", \"$1\"}" + fi + fi +]) + +dnl PSI_UNION(union name, union/struct members) +dnl Check a union and its members and add a pre-defined union and possibly a +dnl pre-defined type for this union. +dnl Calls PSI_CHECK_SIZEOF for the union and each member. +dnl Calls PSI_CHECK_OFFSETOF and PSI_TYPE_INDIRECTON for each member. +AC_DEFUN(PSI_UNION, [ + PSI_CHECK_SIZEOF($1) + if PSI_SH_TEST_SIZEOF($1); then + PSI_CHECK_ALIGNOF($1) + psi_composite_name=m4_bregexp([$1], [^\(union \)?\(\w+\)], [\2]) + psi_composite_members="{PSI_T_UNION, \"union\", \"$psi_composite_name\", PSI_SH_ALIGNOF($1), PSI_SH_SIZEOF($1), 0, 0}" + ifelse([$2],,,[m4_map_args_sep([PSI_COMPOSITE_MEMBER($1, m4_normalize(], [))], [], $2)]) + psi_add_composite "$psi_composite_members" + if test "$1" = "$psi_composite_name"; then + psi_add_type "{PSI_T_UNION, \"$1\", \"$1\"}" + fi + fi +]) diff --git a/m4/psi/psi_const.m4 b/m4/psi/psi_const.m4 index f0345ad..e0b67a3 100644 --- a/m4/psi/psi_const.m4 +++ b/m4/psi/psi_const.m4 @@ -1,19 +1,16 @@ # psi_add_str_const(name, value) -# Add a pre-defined string constant to $PSI_CONSTS +# Add a pre-defined string constant to $PSI_CONSTS_H psi_add_str_const() { - grep -Fq "\"psi\\\\$1\"" $PSI_CONSTS \ - || cat >>$PSI_CONSTS <>$PSI_CONSTS <>$PSI_REDIRS <>$PSI_FN_DECLS <>$PSI_VA_DECLS <>$PSI_DECLS <>$PSI_MACROS <>$PSI_STRUCTS <>$PSI_UNIONS <member_name - ) - if PSI_SH_TEST_SIZEOF($1 member_name); then - PSI_CHECK_OFFSETOF($1, member_name) - PSI_TYPE_INDIRECTION($2, [PSI_SH_SIZEOF([$1 member_name])], pl, as) - - psi_member_sizeof=PSI_SH_SIZEOF($1 member_name) - psi_member_offsetof=PSI_SH_OFFSETOF($1 member_name) - - if test $pl -gt 0 && test $as -eq 0; then - check_size=PSI_SH_SIZEOF(void *) - elif test $pl -eq 1 && test $as -gt 0; then - check_size=`expr PSI_SH_SIZEOF(member_type) \* $as` - else - check_size=PSI_SH_SIZEOF(member_type) - fi - if test $psi_member_sizeof != "$check_size"; then - psi_member_basic_type=PSI_SH_BASIC_TYPE(member_type) - psi_member_type_pair="`psi_type_pair $psi_member_basic_type $psi_member_sizeof`" - psi_struct_members="$psi_struct_members, {$psi_member_type_pair, \"[]member_name[]\", $psi_member_offsetof, $psi_member_sizeof, $pl, $as}" - AC_MSG_WARN(pre-defined size $check_size of $2 in $1 does not match computed size $psi_member_sizeof; adjusting to $psi_member_type_pair) - else - psi_struct_members="[$psi_struct_members, {]PSI_TYPE_PAIR(member_type)[, \"]member_name[\", $psi_member_offsetof, $psi_member_sizeof, $pl, $as}]" - fi - fi -]) - -dnl PSI_STRUCT(struct name, struct members) -dnl Check a struct and its members and add a pre-defined struct and possibly a -dnl pre-defined type for this struct. -dnl Calls PSI_CHECK_SIZEOF and PSI_CHECK_ALIGNOF for the struct. -dnl Calls PSI_CHECK_SIZEOF, PSI_CHECK_OFFSETOF and PSI_TYPE_INDIRECTON for each member. -AC_DEFUN(PSI_STRUCT, [ - PSI_CHECK_SIZEOF($1) - if PSI_SH_TEST_SIZEOF($1); then - PSI_CHECK_ALIGNOF($1) - psi_struct_name=m4_bregexp([$1], [^\(struct \)?\(\w+\)], [\2]) - psi_struct_members="{PSI_T_STRUCT, \"struct\", \"$psi_struct_name\", PSI_SH_ALIGNOF($1), PSI_SH_SIZEOF($1), 0, 0}" - ifelse([$2],,,[m4_map_args_sep([PSI_STRUCT_MEMBER($1, m4_normalize(], [))], [], $2)]) - psi_add_struct "$psi_struct_members" - if test "$1" = "$psi_struct_name"; then - psi_add_type "{PSI_T_STRUCT, \"$1\", \"$1\"}" - fi - fi -]) - -dnl PSI_UNION(union name, union/struct members) -dnl Check a union and its members and add a pre-defined union and possibly a -dnl pre-defined type for this union. -dnl Calls PSI_CHECK_SIZEOF for the union and each member. -dnl Calls PSI_CHECK_OFFSETOF and PSI_TYPE_INDIRECTON for each member. -AC_DEFUN(PSI_UNION, [ - PSI_CHECK_SIZEOF($1) - if PSI_SH_TEST_SIZEOF($1); then - PSI_CHECK_ALIGNOF($1) - psi_struct_name=m4_bregexp([$1], [^\(union \)?\(\w+\)], [\2]) - psi_struct_members="{PSI_T_UNION, \"union\", \"$psi_struct_name\", PSI_SH_ALIGNOF($1), PSI_SH_SIZEOF($1), 0, 0}" - ifelse([$2],,,[m4_map_args_sep([PSI_STRUCT_MEMBER($1, m4_normalize(], [))], [], $2)]) - psi_add_union "$psi_struct_members" - if test "$1" = "$psi_struct_name"; then - psi_add_type "{PSI_T_UNION, \"$1\", \"$1\"}" - fi - fi -]) diff --git a/m4/psi/psi_type.m4 b/m4/psi/psi_type.m4 index a55e6af..502c48a 100644 --- a/m4/psi/psi_type.m4 +++ b/m4/psi/psi_type.m4 @@ -1,15 +1,13 @@ # psi_add_type(type triplet) -# Add a pre-defined type to $PSI_TYPES. +# Add a pre-defined type to $PSI_TYPES_H. psi_add_type() { - cat >>$PSI_TYPES <>$PSI_STDTYPES < (if defined) and PSI_CHECK_SIZEOF. dnl If the basic type is just specified as "int" (in contrast to "sint" or dnl "uint"), AX_CHECK_SIGN is used to discover signedness of the type. -dnl Defines a pre-defined type in $PSI_TYPES. +dnl Defines a pre-defined type in $PSI_TYPES_H. AC_DEFUN(PSI_TYPE, [ ifdef(AS_TR_CPP(AC_TYPE_$1), AS_TR_CPP(AC_TYPE_$1)) PSI_CHECK_SIZEOF($1) @@ -90,7 +88,7 @@ AC_DEFUN(PSI_SH_BASIC_TYPE, [$AS_TR_SH([psi_basic_type_]$1)]) dnl PSI_OPAQUE_TYPE(type name) dnl Checks a type for being a scalar, a struct or a pointer type. dnl Calls AC_TYPE_ (if defined) and PSI_CHECK_SIZEOF. -dnl Defines a pre-defined type in $PSI_TYPES and a pre-defined struct in +dnl Defines a pre-defined type in $PSI_TYPES_H and a pre-defined struct in dnl $PSI_STRUCTS if the type is a struct. AC_DEFUN(PSI_OPAQUE_TYPE, [ ifdef(AS_TR_CPP(AC_TYPE_$1), AS_TR_CPP(AC_TYPE_$1)) diff --git a/php_psi_posix.h.in b/php_psi_posix.h.in new file mode 100644 index 0000000..4cd316c --- /dev/null +++ b/php_psi_posix.h.in @@ -0,0 +1,96 @@ +/* generated by configure */ +#ifndef PSI_POSIX_H +#define PSI_POSIX_H + +#include "php_psi_stdinc.h" + +#ifdef PSI_STD_TYPES +static struct psi_std_type { + token_t type_tag; + const char *type_name; + const char *alias; +} psi_std_types[] = { + {PSI_T_INT8, "int8_t", NULL}, + {PSI_T_INT16, "int16_t", NULL}, + {PSI_T_INT32, "int32_t", NULL}, + {PSI_T_INT64, "int64_t", NULL}, + {PSI_T_UINT8, "uint8_t", NULL}, + {PSI_T_UINT16, "uint16_t", NULL}, + {PSI_T_UINT32, "uint32_t", NULL}, + {PSI_T_UINT64, "uint64_t", NULL}, +@PSI_STDTYPES@ + {0} +}; +#endif + +#ifdef PSI_PREDEF_TYPES +static struct psi_predef_type { + token_t type_tag; + const char *type_name; + const char *alias; +} psi_predef_types[] = { +@PSI_TYPES@ + {0} +}; +#endif + +#ifdef PSI_PREDEF_COMPOSITES +static struct psi_predef_composite { + 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_composites[] = { +@PSI_COMPOSITES@ + {0} +}; +#endif + +#ifdef PSI_PREDEF_CONSTS +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} +}; +#endif + +#ifdef PSI_PREDEF_DECLS +static struct psi_predef_decl { + enum { + DECL_KIND_STD, + DECL_KIND_VARARG, + DECL_KIND_FUNCTOR + } kind; + 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} +}; +#endif + +#ifdef PSI_FUNC_REDIRS +@PSI_MACROS@ + +typedef void (*psi_func_ptr)(); +static struct psi_func_redir { + const char *name; + psi_func_ptr func; +} psi_func_redirs[] = { +@PSI_REDIRS@ + {0} +}; +#endif + +#endif diff --git a/php_psi_stdinc.h.in b/php_psi_stdinc.h.in new file mode 100644 index 0000000..55c2f09 --- /dev/null +++ b/php_psi_stdinc.h.in @@ -0,0 +1,20 @@ +/* generated by configure */ +#ifndef PSI_STDINC_H +#define PSI_STDINC_H + +#ifdef HAVE_CONFIG_H +# include "config.h" +#else +# include "php_config.h" +#endif + +#ifndef _GNU_SOURCE +# define _GNU_SOURCE +#endif +#ifndef _REENTRANT +# define _REENTRANT +#endif + +@PSI_INCLUDES@ + +#endif \ No newline at end of file diff --git a/src/context.c b/src/context.c index b4e73ad..b98ecc2 100644 --- a/src/context.c +++ b/src/context.c @@ -56,21 +56,18 @@ #include "token.h" #include "parser.h" -#include "php_psi_types.h" -#include "php_psi_consts.h" -#include "php_psi_decls.h" -#include "php_psi_va_decls.h" -#include "php_psi_fn_decls.h" -#include "php_psi_structs.h" -#include "php_psi_unions.h" +#define PSI_PREDEF_TYPES +#define PSI_PREDEF_CONSTS +#define PSI_PREDEF_COMPOSITES +#define PSI_PREDEF_DECLS +#include "php_psi_posix.h" struct psi_context *psi_context_init(struct psi_context *C, struct psi_context_ops *ops, psi_error_cb error, unsigned flags) { struct psi_data T; struct psi_predef_type *predef_type; struct psi_predef_const *predef_const; - struct psi_predef_struct *predef_struct; - struct psi_predef_union *predef_union; + struct psi_predef_composite *predef_composite; struct psi_predef_decl *predef_decl; if (!C) { @@ -106,36 +103,27 @@ struct psi_context *psi_context_init(struct psi_context *C, struct psi_context_o T.consts = psi_plist_add(T.consts, &constant); } - for (predef_struct = &psi_predef_structs[0]; predef_struct->type_tag; ++predef_struct) { - struct psi_predef_struct *member; + for (predef_composite = &psi_predef_composites[0]; predef_composite->type_tag; ++predef_composite) { + struct psi_predef_composite *member; + struct psi_decl_struct *dstruct; + struct psi_decl_union *dunion; struct psi_plist *dargs = psi_plist_init((psi_plist_dtor) psi_decl_arg_free); - struct psi_decl_struct *dstruct = psi_decl_struct_init(predef_struct->var_name, dargs); - dstruct->size = predef_struct->size; - dstruct->align = predef_struct->offset; - for (member = &predef_struct[1]; member->type_tag; ++member) { - struct psi_decl_type *type; - struct psi_decl_var *dvar; - struct psi_decl_arg *darg; - - type = psi_decl_type_init(member->type_tag, member->type_name); - dvar = psi_decl_var_init(member->var_name, member->pointer_level, member->array_size); - darg = psi_decl_arg_init(type, dvar); - darg->layout = psi_layout_init(member->offset, member->size); - dstruct->args = psi_plist_add(dstruct->args, &darg); + switch (predef_composite->type_tag) { + case PSI_T_STRUCT: + dstruct = psi_decl_struct_init(predef_composite->var_name, dargs); + dstruct->size = predef_composite->size; + dstruct->align = predef_composite->offset; + break; + case PSI_T_UNION: + dunion = psi_decl_union_init(predef_composite->var_name, dargs); + dunion->size = predef_composite->size; + dunion->align = predef_composite->offset; + break; + default: + assert(0); } - - T.structs = psi_plist_add(T.structs, &dstruct); - predef_struct = member; - } - for (predef_union = &psi_predef_unions[0]; predef_union->type_tag; ++predef_union) { - struct psi_predef_union *member; - struct psi_plist *dargs = psi_plist_init((psi_plist_dtor) psi_decl_arg_free); - struct psi_decl_union *dunion = psi_decl_union_init(predef_union->var_name, dargs); - - dunion->size = predef_union->size; - dunion->align = predef_union->offset; - for (member = &predef_union[1]; member->type_tag; ++member) { + for (member = &predef_composite[1]; member->type_tag; ++member) { struct psi_decl_type *type; struct psi_decl_var *dvar; struct psi_decl_arg *darg; @@ -144,52 +132,32 @@ struct psi_context *psi_context_init(struct psi_context *C, struct psi_context_o dvar = psi_decl_var_init(member->var_name, member->pointer_level, member->array_size); darg = psi_decl_arg_init(type, dvar); darg->layout = psi_layout_init(member->offset, member->size); - dunion->args = psi_plist_add(dunion->args, &darg); - } - T.unions = psi_plist_add(T.unions, &dunion); - predef_union = member; - } - for (predef_decl = &psi_predef_decls[0]; predef_decl->type_tag; ++predef_decl) { - struct psi_predef_decl *farg; - struct psi_decl_type *ftype = psi_decl_type_init(predef_decl->type_tag, predef_decl->type_name); - struct psi_decl_var *fname = psi_decl_var_init(predef_decl->var_name, predef_decl->pointer_level, predef_decl->array_size); - struct psi_decl_arg *func = psi_decl_arg_init(ftype, fname); - struct psi_plist *args = psi_plist_init((psi_plist_dtor) psi_decl_arg_free); - struct psi_decl *decl = psi_decl_init(psi_decl_abi_init("default"), func, args); - - for (farg = &predef_decl[1]; farg->type_tag; ++farg) { - struct psi_decl_type *arg_type = psi_decl_type_init(farg->type_tag, farg->type_name); - struct psi_decl_var *arg_var = psi_decl_var_init(farg->var_name, farg->pointer_level, farg->array_size); - struct psi_decl_arg *darg = psi_decl_arg_init(arg_type, arg_var); - decl->args = psi_plist_add(decl->args, &darg); + switch (predef_composite->type_tag) { + case PSI_T_STRUCT: + dstruct->args = psi_plist_add(dstruct->args, &darg); + break; + case PSI_T_UNION: + dunion->args = psi_plist_add(dunion->args, &darg); + break; + default: + assert(0); + } } - - T.decls = psi_plist_add(T.decls, &decl); - predef_decl = farg; - } - - for (predef_decl = &psi_predef_vararg_decls[0]; predef_decl->type_tag; ++predef_decl) { - struct psi_predef_decl *farg; - struct psi_decl_type *ftype = psi_decl_type_init(predef_decl->type_tag, predef_decl->type_name); - struct psi_decl_var *fname = psi_decl_var_init(predef_decl->var_name, predef_decl->pointer_level, predef_decl->array_size); - struct psi_decl_arg *func = psi_decl_arg_init(ftype, fname); - struct psi_plist *args = psi_plist_init((psi_plist_dtor) psi_decl_arg_free); - struct psi_decl *decl = psi_decl_init(psi_decl_abi_init("default"), func, args); - - for (farg = &predef_decl[1]; farg->type_tag; ++farg) { - struct psi_decl_type *arg_type = psi_decl_type_init(farg->type_tag, farg->type_name); - struct psi_decl_var *arg_var = psi_decl_var_init(farg->var_name, farg->pointer_level, farg->array_size); - struct psi_decl_arg *darg = psi_decl_arg_init(arg_type, arg_var); - decl->args = psi_plist_add(decl->args, &darg); + switch (predef_composite->type_tag) { + case PSI_T_STRUCT: + T.structs = psi_plist_add(T.structs, &dstruct); + break; + case PSI_T_UNION: + T.unions = psi_plist_add(T.unions, &dunion); + break; + default: + assert(0); } - decl->varargs = 1; - T.decls = psi_plist_add(T.decls, &decl); - predef_decl = farg; + predef_composite = member; } - - for (predef_decl = &psi_predef_functor_decls[0]; predef_decl->type_tag; ++predef_decl) { + for (predef_decl = &psi_predef_decls[0]; predef_decl->type_tag; ++predef_decl) { struct psi_predef_decl *farg; struct psi_decl_type *dtype, *ftype = psi_decl_type_init(predef_decl->type_tag, predef_decl->type_name); struct psi_decl_var *fname = psi_decl_var_init(predef_decl->var_name, predef_decl->pointer_level, predef_decl->array_size); @@ -204,10 +172,22 @@ struct psi_context *psi_context_init(struct psi_context *C, struct psi_context_o decl->args = psi_plist_add(decl->args, &darg); } - dtype = psi_decl_type_init(PSI_T_FUNCTION, fname->name); - dtype->real.func = decl; - tdef = psi_decl_arg_init(dtype, psi_decl_var_copy(fname)); - T.types = psi_plist_add(T.types, &tdef); + switch (predef_decl->kind) { + case DECL_KIND_VARARG: + decl->varargs = 1; + /* no break */ + case DECL_KIND_STD: + T.decls = psi_plist_add(T.decls, &decl); + break; + case DECL_KIND_FUNCTOR: + dtype = psi_decl_type_init(PSI_T_FUNCTION, fname->name); + dtype->real.func = decl; + tdef = psi_decl_arg_init(dtype, psi_decl_var_copy(fname)); + T.types = psi_plist_add(T.types, &tdef); + break; + default: + assert(0); + } predef_decl = farg; } @@ -305,6 +285,12 @@ zend_function_entry *psi_context_compile(struct psi_context *C) while (psi_plist_get(C->consts, i++, &c)) { zc.name = zend_string_init(c->name + (c->name[0] == '\\'), strlen(c->name) - (c->name[0] == '\\'), 1); + + if (zend_get_constant(zc.name)) { + zend_string_release(zc.name); + continue; + } + ZVAL_NEW_STR(&zc.value, zend_string_init(c->val->text, strlen(c->val->text), 1)); switch (c->type->type) { diff --git a/src/types/decl.c b/src/types/decl.c index 5ab3664..b4685f6 100644 --- a/src/types/decl.c +++ b/src/types/decl.c @@ -25,19 +25,12 @@ #include "php_psi_stdinc.h" -#if __GNUC__ >= 5 -# pragma GCC diagnostic ignored "-Wdiscarded-qualifiers" -#endif -#include "php_psi_macros.h" -#include "php_psi_redirs.h" -#if __GNUC__ >= 5 -# pragma GCC diagnostic pop -#endif - #include - #include "data.h" +#define PSI_FUNC_REDIRS +#include "php_psi_posix.h" + struct psi_decl *psi_decl_init(struct psi_decl_abi *abi, struct psi_decl_arg *func, struct psi_plist *args) { diff --git a/src/types/decl_type.c b/src/types/decl_type.c index 4f494d6..f3b500a 100644 --- a/src/types/decl_type.c +++ b/src/types/decl_type.c @@ -25,9 +25,11 @@ #include "php_psi_stdinc.h" #include "token.h" -#include "php_psi_stdtypes.h" #include "data.h" +#define PSI_STD_TYPES +#include "php_psi_posix.h" + struct psi_decl_type *psi_decl_type_init(token_t type, const char *name) { struct psi_decl_type *t = calloc(1, sizeof(*t));