From 469fe3395cb9696e32bcd64639f22113d8fb2ec6 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Mon, 9 Nov 2015 21:38:16 +0100 Subject: [PATCH] flush --- config.m4 | 253 ++++++++++++++++++++++++++++++++++++++++------ src/context.c | 60 +++++++++-- src/libffi.c | 14 +-- src/libjit.c | 14 +-- src/module.c | 69 +++++-------- src/parser.h | 26 ++--- src/parser.re | 8 +- src/parser_proc.h | 74 +++++++------- src/parser_proc.y | 21 +--- 9 files changed, 358 insertions(+), 181 deletions(-) diff --git a/config.m4 b/config.m4 index d2cf073..d372f5d 100644 --- a/config.m4 +++ b/config.m4 @@ -82,17 +82,39 @@ if test "$PHP_PSI" != "no"; then PHP_SUBST(PSI_SHARED_LIBADD) + dnl PSI_INCLUDES_DEFAULT(include, defines) + AC_DEFUN(PSI_INCLUDES_DEFAULT, [ + AC_INCLUDES_DEFAULT() + $2 + m4_ifnblank($1, + m4_expand([#include <]$1[>]) + ) + ]) + + psi_type_pair() { # (type, size) + local psi_type_lower=`tr A-Z a-z <<<$1` + case $psi_type_lower in + int*|uint*) + local psi_type_upper=`tr a-z A-Z <<<$1` + local psi_type_bits=`expr $2 \* 8` + echo "PSI_T_${psi_type_upper}${psi_type_bits}, \"${psi_type_lower}${psi_type_bits}_t\"" + ;; + struct*) + echo "PSI_T_STRUCT, \"$2\"" + ;; + *) + echo "PSI_T_NAME, \"$1\"" + ;; + esac + } + PSI_TYPES="" - dnl PSI_TYPE(type name, basic type, whether to check alignmnet) + dnl PSI_TYPE(type name, basic type, includes) AC_DEFUN(PSI_TYPE, [ - AC_CHECK_SIZEOF($1) - if test "$3" && test "$3" != "no" - then - AC_CHECK_ALIGNOF($1) - fi + ifdef(AC_TYPE_[]patsubst(translit($1,a-z,A-Z),\W,_),AC_TYPE_[]patsubst(translit($1,a-z,A-Z),\W,_)) + AC_CHECK_SIZEOF($1, [], PSI_INCLUDES_DEFAULT($3)) if test "$2" && test "$ac_cv_sizeof_[]$1" -gt 0; then - psi_type_bits=`expr ${AS_TR_SH(ac_cv_sizeof_[]$1)} \* 8` - PSI_TYPES="{PSI_T_[]translit($2,a-z,A-Z)[]${psi_type_bits}, \""$2[]${psi_type_bits}[]_t"\", \""$1"\"}, $PSI_TYPES" + PSI_TYPES="{`psi_type_pair $2 $ac_cv_sizeof_[]$1`, \""$1"\"}, $PSI_TYPES" fi ]) @@ -112,32 +134,33 @@ if test "$PHP_PSI" != "no"; then dnl PSI_CONST(const name, type, headers to include) AC_DEFUN(PSI_CONST, [ - AC_MSG_CHECKING(value of $1) - PSI_INCLUDES= - if test "$3" + AC_CACHE_CHECK(value of $1, psi_cv_const_$1, [ + case $2 in + str*|quoted_str*) + if test "$cross_compiling" = "yes" + then + AC_TRY_CPP(PSI_INCLUDES_DEFAULT($3)$1, psi_const_val=`eval "$ac_try|tail -n1"`, psi_const_val=) + else + PSI_COMPUTE_STR(psi_const_val, $1, PSI_INCLUDES_DEFAULT($3)) + fi + ;; + *) + AC_COMPUTE_INT(psi_const_val, $1, PSI_INCLUDES_DEFAULT($3)) + ;; + esac + psi_cv_const_$1=$psi_const_val + ]) + if test "$psi_cv_const_$1" then - for i in $3 - do - PSI_INCLUDES="$PSI_INCLUDES -#include <$i>" - done + case $2 in + str*|quoted_str*) + PSI_CONSTS="{PSI_T_STRING, \"string\", \"$1\", $psi_cv_const_$1, PSI_T_QUOTED_STRING}, $PSI_CONSTS" + ;; + *) + PSI_CONSTS="{PSI_T_INT, \"int\", \"$1\", \"$psi_cv_const_$1\", PSI_T_NUMBER}, $PSI_CONSTS" + ;; + esac fi - case $2 in - str*|quoted_str*) - PSI_COMPUTE_STR(psi_const_val, $1, AC_INCLUDES_DEFAULT()$PSI_INCLUDES) - if test "$psi_const_val"; then - PSI_CONSTS="{PSI_T_STRING, \"string\", \"$1\", $psi_const_val, PSI_T_QUOTED_STRING}, $PSI_CONSTS" - fi - ;; - *) - AC_COMPUTE_INT(psi_const_val, $1, AC_INCLUDES_DEFAULT()$PSI_INCLUDES) - if test "$psi_const_val"; then - PSI_CONSTS="{PSI_T_INT, \"int\", \"$1\", \"$psi_const_val\", PSI_T_NUMBER}, $PSI_CONSTS" - fi - ;; - esac - - AC_MSG_RESULT($psi_const_val) ]) AC_DEFUN([AX_CHECK_SIGN], [ @@ -154,6 +177,68 @@ if test "$PHP_PSI" != "no"; then $3 fi ]) + dnl PSI_CHECK_OFFSETOF(struct, member, include) + dnl[AS_LITERAL_IF([$1], [], [m4_fatal([$0: requires literal arguments])])]dnl + dnl[AS_LITERAL_IF([$2], [], [m4_fatal([$0: requires literal arguments])])]dnl + AC_DEFUN(PSI_CHECK_OFFSETOF, [ + _AC_CACHE_CHECK_INT( + [offset of $2 in $1], + [AS_TR_SH([ac_cv_offsetof_$1_$2])], + [(long int) (offsetof ($1, $2))], + [AC_INCLUDES_DEFAULT([$3])], + [AC_MSG_FAILURE([cannot compute offsetof ($1, $2)])] + ) + AC_DEFINE_UNQUOTED( + AS_TR_CPP(offsetof_$1_$2), + $AS_TR_SH([ac_cv_offsetof_$1_$2]), + [The offset of `$1' in `$2', as computed by offsetof.] + ) + ]) + + dnl PSI_STRUCT(name, members, member type cases, includes) + PSI_STRUCTS= + AC_DEFUN(PSI_STRUCT, [ + psi_struct_members= + m4_foreach(member, [$2], [ + AC_CHECK_MEMBER(struct $1.member, [ + case member in + $3 + *) psi_member_type=int ;; + esac + AC_CHECK_SIZEOF(struct_$1[_]member, [], PSI_INCLUDES_DEFAULT($4, + [#define struct_$1_]member ((struct $1 *)0)->member + )) + PSI_CHECK_OFFSETOF(struct $1, member, PSI_INCLUDES_DEFAULT($4)) + # pointer level + psi_struct_member_pl=`echo $psi_member_type | tr -cd '*' | wc -c` + # array size + psi_struct_member_as=`echo $psi_member_type | $AWK -F'\x5b\x5d\x5b\x5d' 'END {print 0} /\\x5b\x5b\x5b:digit:\x5d\x5d+\\x5d/ {print$[]2; exit}'` + if test $psi_struct_member_as -gt 0 + then + psi_struct_member_pl=`expr $psi_struct_member_pl + 1` + fi + psi_struct_members="{`psi_type_pair $psi_member_type $ac_cv_sizeof_struct_$1[]_[]member`, \"[]member[]\", $ac_cv_offsetof_struct_$1[]_[]member, $ac_cv_sizeof_struct_$1[]_[]member, $psi_struct_member_pl, $psi_struct_member_as}, $psi_struct_members" + ], [], PSI_INCLUDES_DEFAULT($4)) + ]) + PSI_STRUCTS="{\"$1\", {$psi_struct_members}}, $PSI_STRUCTS" + ]) + + AC_TYPE_INT8_T + AC_CHECK_ALIGNOF(int8_t) + AC_TYPE_UINT8_T + AC_CHECK_ALIGNOF(uint8_t) + AC_TYPE_INT16_T + AC_CHECK_ALIGNOF(int16_t) + AC_TYPE_UINT16_T + AC_CHECK_ALIGNOF(uint16_t) + AC_TYPE_INT32_T + AC_CHECK_ALIGNOF(int32_t) + AC_TYPE_UINT32_T + AC_CHECK_ALIGNOF(uint32_t) + AC_TYPE_INT64_T + AC_CHECK_ALIGNOF(int64_t) + AC_TYPE_UINT64_T + AC_CHECK_ALIGNOF(uint64_t) PSI_TYPE(char, int) PSI_TYPE(short, int) @@ -162,13 +247,86 @@ if test "$PHP_PSI" != "no"; then PSI_TYPE(float) PSI_TYPE(double) PSI_TYPE(void *) + + dnl stdint.h + PSI_TYPE(int_least8_t, int) + PSI_TYPE(int_least16_t, int) + PSI_TYPE(int_least32_t, int) + PSI_TYPE(int_least64_t, int) + PSI_TYPE(uint_least8_t, uint) + PSI_TYPE(uint_least16_t, uint) + PSI_TYPE(uint_least32_t, uint) + PSI_TYPE(uint_least64_t, uint) + PSI_TYPE(int_fast8_t, int) + PSI_TYPE(int_fast16_t, int) + PSI_TYPE(int_fast32_t, int) + PSI_TYPE(int_fast64_t, int) + PSI_TYPE(uint_fast8_t, uint) + PSI_TYPE(uint_fast16_t, uint) + PSI_TYPE(uint_fast32_t, uint) + PSI_TYPE(uint_fast64_t, uint) + PSI_TYPE(intptr_t, int) + PSI_TYPE(uintptr_t, uint) + PSI_TYPE(intmax_t, int) + PSI_TYPE(uintmax_t, uint) + + PSI_CONST(INT8_MIN, int) + PSI_CONST(INT8_MAX, int) + PSI_CONST(UINT8_MAX, int) + PSI_CONST(INT16_MIN, int) + PSI_CONST(INT16_MAX, int) + PSI_CONST(UINT16_MAX, int) + PSI_CONST(INT32_MIN, int) + PSI_CONST(INT32_MAX, int) + PSI_CONST(UINT32_MAX, int) + PSI_CONST(INT64_MIN, int) + PSI_CONST(INT64_MAX, int) + PSI_CONST(UINT64_MAX, int) + + PSI_CONST(INT_LEAST8_MIN, int) + PSI_CONST(INT_LEAST8_MAX, int) + PSI_CONST(UINT_LEAST8_MAX, int) + PSI_CONST(INT_LEAST16_MIN, int) + PSI_CONST(INT_LEAST16_MAX, int) + PSI_CONST(UINT_LEAST16_MAX, int) + PSI_CONST(INT_LEAST32_MIN, int) + PSI_CONST(INT_LEAST32_MAX, int) + PSI_CONST(UINT_LEAST32_MAX, int) + PSI_CONST(INT_LEAST64_MIN, int) + PSI_CONST(INT_LEAST64_MAX, int) + PSI_CONST(UINT_LEAST64_MAX, int) + + PSI_CONST(INT_FAST8_MIN, int) + PSI_CONST(INT_FAST8_MAX, int) + PSI_CONST(UINT_FAST8_MAX, int) + PSI_CONST(INT_FAST16_MIN, int) + PSI_CONST(INT_FAST16_MAX, int) + PSI_CONST(UINT_FAST16_MAX, int) + PSI_CONST(INT_FAST32_MIN, int) + PSI_CONST(INT_FAST32_MAX, int) + PSI_CONST(UINT_FAST32_MAX, int) + PSI_CONST(INT_FAST64_MIN, int) + PSI_CONST(INT_FAST64_MAX, int) + PSI_CONST(UINT_FAST64_MAX, int) + + PSI_CONST(INTPTR_MIN, int) + PSI_CONST(INTPTR_MAX, int) + PSI_CONST(UINTPTR_MAX, int) + PSI_CONST(INTMAX_MIN, int) + PSI_CONST(INTMAX_MAX, int) + PSI_CONST(UINTMAX_MAX, int) dnl stddef.h PSI_TYPE(ptrdiff_t, int) + PSI_CONST(PTRDIFF_MIN, int) + PSI_CONST(PTRDIFF_MAX, int) PSI_TYPE(size_t, uint) + PSI_CONST(SIZE_MAX, int) AC_CHECK_TYPE(wchar_t, [ AX_CHECK_SIGN(wchar_t, psi_wchar_t=int, psi_wchar_t=uint) PSI_TYPE(wchar_t, $psi_wchar_t) + PSI_CONST(WCHAR_MIN, int) + PSI_CONST(WCHAR_MAX, int) ]) dnl stdio.h @@ -191,6 +349,23 @@ if test "$PHP_PSI" != "no"; then PSI_CONST(EXIT_SUCCESS, int) PSI_CONST(RAND_MAX, int) PSI_CONST(MB_CUR_MAX, int) + dnl sys/stat.h + PSI_STRUCT(stat, [ + [st_dev], + [st_ino], + [st_mode], + [st_nlink], + [st_uid], + [st_gid], + [st_rdev], + [st_size], + [st_atim], + [st_mtim], + [st_ctim], + [st_blksize], + [st_blocks]], [ + st_?tim) psi_member_type="struct timespec" ;; + ], sys/stat.h) dnl sys/time.h PSI_CONST(ITIMER_REAL, int, sys/time.h) PSI_CONST(ITIMER_VIRTUAL, int, sys/time.h) @@ -216,9 +391,23 @@ if test "$PHP_PSI" != "no"; then PSI_TYPE(time_t, int) PSI_TYPE(timer_t, int) PSI_TYPE(uid_t) + + dnl wchar.h + AC_CHECK_TYPE(wint_t, [ + AX_CHECK_SIGN(wint_t, psi_wint_t=int, psi_wint_t=uint) + PSI_TYPE(wint_t, $psi_wint_t, wchar.h) + PSI_CONST(WINT_MIN, int, wchar.h) + PSI_CONST(WINT_MAX, int, wchar.h) + PSI_CONST(WEOF, int, wchar.h) + ], [], [ + AC_INCLUDES_DEFAULT() + #include + ]) + AC_DEFINE_UNQUOTED(PHP_PSI_TYPES, $PSI_TYPES, Predefined types) AC_DEFINE_UNQUOTED(PHP_PSI_CONSTS, $PSI_CONSTS, Predefined constants) + AC_DEFINE_UNQUOTED(PHP_PSI_STRUCTS, $PSI_STRUCTS, Predefined structs) PHP_PSI_SRCDIR=PHP_EXT_SRCDIR(psi) PHP_PSI_BUILDDIR=PHP_EXT_BUILDDIR(psi) diff --git a/src/context.c b/src/context.c index a051697..2d821ad 100644 --- a/src/context.c +++ b/src/context.c @@ -13,16 +13,16 @@ #include "parser.h" #include "validator.h" -#define psi_predef_count(s) (sizeof(psi_predef_ ##s## s)/sizeof(psi_predef ##s)) +#define psi_predef_count(of) ((sizeof(psi_predef ##of## s)/sizeof(psi_predef ##of))-1) typedef struct psi_predef_type { token_t type_tag; const char *type_name; const char *alias; } psi_predef_type; -#define psi_predef_type_count() psi_predef_count(type) -static const psi_predef_types[] = { - PHP_PSI_TYPES +static const psi_predef_type psi_predef_types[] = { + PHP_PSI_TYPES{0} }; +#define psi_predef_type_count() psi_predef_count(_type) typedef struct psi_predef_const { token_t type_tag; @@ -31,14 +31,33 @@ typedef struct psi_predef_const { const char *val_text; token_t val_type_tag; } psi_predef_const; -#define psi_predef_const_count() psi_predef_count(const) -static const psi_predef_consts[] = { - PHP_PSI_CONSTS +static const psi_predef_const psi_predef_consts[] = { + PHP_PSI_CONSTS{0} }; +#define psi_predef_const_count() psi_predef_count(_const) + +typedef struct psi_predef_struct_member { + token_t type_tag; + const char *type_name; + const char *name; + size_t off; + size_t len; + size_t pointer_level; + size_t array_size; +} psi_predef_struct_member; +#define PSI_PREDEF_STRUCT_MEMBERS 32 +typedef struct psi_predef_struct { + const char *name; + psi_predef_struct_member members[PSI_PREDEF_STRUCT_MEMBERS]; +} psi_predef_struct; +static const psi_predef_struct psi_predef_structs[] = { + PHP_PSI_STRUCTS{0} +}; +#define psi_predef_struct_count() psi_predef_count(_struct) PSI_Context *PSI_ContextInit(PSI_Context *C, PSI_ContextOps *ops, PSI_ContextErrorFunc error) { - size_t i; + size_t i, j; PSI_Data data; if (!C) { @@ -52,20 +71,41 @@ PSI_Context *PSI_ContextInit(PSI_Context *C, PSI_ContextOps *ops, PSI_ContextErr memset(&data, 0, sizeof(data)); for (i = 0; i < psi_predef_type_count(); ++i) { - psi_predef_type *pre = &psi_predef_types[i]; + const psi_predef_type *pre = &psi_predef_types[i]; decl_type *type = init_decl_type(pre->type_tag, pre->type_name); decl_typedef *def = init_decl_typedef(pre->alias, type); data.defs = add_decl_typedef(data.defs, def); } for (i = 0; i < psi_predef_const_count(); ++i) { - psi_predef_const *pre = psi_predef_const[i]; + const psi_predef_const *pre = &psi_predef_consts[i]; impl_def_val *val = init_impl_def_val(pre->val_type_tag, pre->val_text); const_type *type = init_const_type(pre->type_tag, pre->type_name); constant *constant = init_constant(type, pre->name, val); data.consts = add_constant(data.consts, constant); } + for (i = 0; i < psi_predef_struct_count(); ++i) { + const psi_predef_struct *pre = &psi_predef_structs[i]; + decl_args *dargs = init_decl_args(NULL); + + for (j = 0; j < PSI_PREDEF_STRUCT_MEMBERS; ++j) { + const psi_predef_struct_member *member = &pre->members[j]; + decl_type *type; + decl_var *dvar; + + if (!member->name) { + break; + } + + type = init_decl_type(member->type_tag, member->type_name); + dvar = init_decl_var(member->name, member->pointer_level, member->array_size); + dargs = add_decl_arg(dargs, init_decl_arg(type, dvar)); + } + + data.structs = add_decl_struct(data.structs, + init_decl_struct(pre->name, dargs)); + } return C; } diff --git a/src/libffi.c b/src/libffi.c index b0100f6..25456d2 100644 --- a/src/libffi.c +++ b/src/libffi.c @@ -60,32 +60,26 @@ static inline ffi_type *psi_ffi_type(token_t t) { /* no break */ case PSI_T_VOID: return &ffi_type_void; - case PSI_T_SINT8: + case PSI_T_INT8: return &ffi_type_sint8; case PSI_T_UINT8: return &ffi_type_uint8; - case PSI_T_SINT16: + case PSI_T_INT16: return &ffi_type_sint16; case PSI_T_UINT16: return &ffi_type_uint16; - case PSI_T_SINT32: + case PSI_T_INT32: return &ffi_type_sint32; case PSI_T_UINT32: return &ffi_type_uint32; - case PSI_T_SINT64: + case PSI_T_INT64: return &ffi_type_sint64; case PSI_T_UINT64: return &ffi_type_uint64; case PSI_T_BOOL: return &ffi_type_uchar; - case PSI_T_CHAR: - return &ffi_type_schar; - case PSI_T_SHORT: - return &ffi_type_sshort; case PSI_T_INT: return &ffi_type_sint; - case PSI_T_LONG: - return &ffi_type_slong; case PSI_T_FLOAT: return &ffi_type_float; case PSI_T_DOUBLE: diff --git a/src/libjit.c b/src/libjit.c index fd68c50..055ba1b 100644 --- a/src/libjit.c +++ b/src/libjit.c @@ -16,32 +16,26 @@ static inline jit_type_t psi_jit_type(token_t t) { /* no break */ case PSI_T_VOID: return jit_type_void; - case PSI_T_SINT8: + case PSI_T_INT8: return jit_type_sbyte; case PSI_T_UINT8: return jit_type_ubyte; - case PSI_T_SINT16: + case PSI_T_INT16: return jit_type_short; case PSI_T_UINT16: return jit_type_ushort; - case PSI_T_SINT32: + case PSI_T_INT32: return jit_type_int; case PSI_T_UINT32: return jit_type_uint; - case PSI_T_SINT64: + case PSI_T_INT64: return jit_type_long; case PSI_T_UINT64: return jit_type_ulong; case PSI_T_BOOL: return jit_type_sys_bool; - case PSI_T_CHAR: - return jit_type_sys_char; - case PSI_T_SHORT: - return jit_type_sys_short; case PSI_T_INT: return jit_type_sys_int; - case PSI_T_LONG: - return jit_type_sys_long; case PSI_T_FLOAT: return jit_type_sys_float; case PSI_T_DOUBLE: diff --git a/src/module.c b/src/module.c index 03d9d83..628694b 100644 --- a/src/module.c +++ b/src/module.c @@ -38,7 +38,6 @@ int psi_internal_type(impl_type *type) case PSI_T_BOOL: return _IS_BOOL; case PSI_T_INT: - case PSI_T_LONG: return IS_LONG; case PSI_T_FLOAT: case PSI_T_DOUBLE: @@ -128,8 +127,7 @@ void psi_to_double(zval *return_value, token_t t, impl_val *ret_val, decl_var *v void psi_to_string(zval *return_value, token_t t, impl_val *ret_val, decl_var *var) { switch (t) { - case PSI_T_CHAR: - case PSI_T_SINT8: + case PSI_T_INT8: case PSI_T_UINT8: if (!var->arg->var->pointer_level) { RETVAL_STRINGL(&ret_val->cval, 1); @@ -174,37 +172,25 @@ size_t psi_t_alignment(token_t t) PSI_TAS_C(T); \ } switch (t) { - case PSI_T_CHAR: - PSI_TAS_CASE(char); - break; - case PSI_T_SINT8: + case PSI_T_INT8: PSI_TAS_CASE(int8_t); break; case PSI_T_UINT8: PSI_TAS_CASE(uint8_t); break; - case PSI_T_SHORT: - PSI_TAS_CASE(short); - break; - case PSI_T_SINT16: + case PSI_T_INT16: PSI_TAS_CASE(int16_t); break; case PSI_T_UINT16: PSI_TAS_CASE(uint16_t); break; - case PSI_T_INT: - PSI_TAS_CASE(int); - break; - case PSI_T_SINT32: + case PSI_T_INT32: PSI_TAS_CASE(int32_t); break; case PSI_T_UINT32: PSI_TAS_CASE(uint32_t); break; - case PSI_T_LONG: - PSI_TAS_CASE(long); - break; - case PSI_T_SINT64: + case PSI_T_INT64: PSI_TAS_CASE(int64_t); break; case PSI_T_UINT64: @@ -216,9 +202,6 @@ size_t psi_t_alignment(token_t t) case PSI_T_DOUBLE: PSI_TAS_CASE(double); break; - case PSI_T_SIZE_T: - PSI_TAS_CASE(size_t); - break; case PSI_T_POINTER: { PSI_TAS_P(char); @@ -236,31 +219,22 @@ size_t psi_t_size(token_t t) size_t size; switch (t) { - case PSI_T_CHAR: - size = sizeof(char); - break; - case PSI_T_SINT8: + case PSI_T_INT8: case PSI_T_UINT8: size = 1; break; - case PSI_T_SHORT: - size = sizeof(short); - break; - case PSI_T_SINT16: + case PSI_T_INT16: case PSI_T_UINT16: size = 2; break; case PSI_T_INT: size = sizeof(int); break; - case PSI_T_SINT32: + case PSI_T_INT32: case PSI_T_UINT32: size = 4; break; - case PSI_T_LONG: - size = sizeof(long); - break; - case PSI_T_SINT64: + case PSI_T_INT64: case PSI_T_UINT64: size = 8; break; @@ -270,9 +244,6 @@ size_t psi_t_size(token_t t) case PSI_T_DOUBLE: size = sizeof(double); break; - case PSI_T_SIZE_T: - size = sizeof(size_t); - break; case PSI_T_POINTER: size = sizeof(char *); break; @@ -307,8 +278,7 @@ void psi_from_zval(impl_val *mem, decl_arg *spec, zval *zv, void **tmp) case PSI_T_DOUBLE: mem->dval = zval_get_double(zv); break; - case PSI_T_CHAR: - case PSI_T_SINT8: + case PSI_T_INT8: case PSI_T_UINT8: if (spec->var->pointer_level) { zend_string *zs = zval_get_string(zv); @@ -371,14 +341,23 @@ void psi_to_array(zval *return_value, token_t t, impl_val *ret_val, decl_var *va memset(&tmp, 0, sizeof(tmp)); memcpy(&tmp, ptr, layout.len); switch (real_decl_type(darg->type)->type) { - case PSI_T_CHAR: + case PSI_T_FLOAT: + case PSI_T_DOUBLE: + psi_to_double(&ztmp, real_decl_type(darg->type)->type, &tmp, darg->var); + break; + case PSI_T_INT8: + case PSI_T_UINT8: if (darg->var->pointer_level) { psi_to_string(&ztmp, real_decl_type(darg->type)->type, &tmp, darg->var); break; } /* no break */ - case PSI_T_INT: - case PSI_T_LONG: + case PSI_T_INT16: + case PSI_T_UINT16: + case PSI_T_INT32: + case PSI_T_UINT32: + case PSI_T_INT64: + case PSI_T_UINT64: psi_to_int(&ztmp, real_decl_type(darg->type)->type, &tmp, darg->var); break; default: @@ -428,7 +407,7 @@ ZEND_RESULT_CODE psi_parse_args(zend_execute_data *execute_data, impl *impl) iarg->val.zend.bval = iarg->def->type == PSI_T_TRUE ? 1 : 0; } Z_PARAM_BOOL(iarg->val.zend.bval); - } else if (PSI_T_INT == iarg->type->type || PSI_T_LONG == iarg->type->type) { + } else if (PSI_T_INT == iarg->type->type) { if (iarg->def) { iarg->val.zend.lval = zend_atol(iarg->def->text, strlen(iarg->def->text)); } @@ -515,7 +494,7 @@ void *psi_do_let(decl_arg *darg) } break; case PSI_T_INTVAL: - if (iarg->type->type == PSI_T_INT || iarg->type->type == PSI_T_LONG) { + if (iarg->type->type == PSI_T_INT) { arg_val->lval = iarg->val.zend.lval; } else { arg_val->lval = zval_get_long(iarg->_zv); diff --git a/src/parser.h b/src/parser.h index 9ec15b9..cb069c9 100644 --- a/src/parser.h +++ b/src/parser.h @@ -32,7 +32,7 @@ typedef struct decl_type { struct decl_struct *strct; } decl_type; -static inline decl_type *init_decl_type(token_t type, char *name) { +static inline decl_type *init_decl_type(token_t type, const char *name) { decl_type *t = calloc(1, sizeof(*t)); t->type = type; t->name = strdup(name); @@ -56,7 +56,7 @@ typedef struct decl_typedef { decl_type *type; } decl_typedef; -static inline decl_typedef *init_decl_typedef(char *name, decl_type *type) { +static inline decl_typedef *init_decl_typedef(const char *name, decl_type *type) { decl_typedef *t = calloc(1, sizeof(*t)); t->alias = strdup(name); t->type = type; @@ -100,7 +100,7 @@ typedef struct decl_var { struct decl_arg *arg; } decl_var; -static inline decl_var *init_decl_var(char *name, unsigned pl, unsigned as) { +static inline decl_var *init_decl_var(const char *name, unsigned pl, unsigned as) { decl_var *v = calloc(1, sizeof(*v)); v->name = (char *) strdup((const char *) name); v->pointer_level = pl; @@ -195,7 +195,7 @@ typedef struct decl_abi { char *convention; } decl_abi; -static inline decl_abi *init_decl_abi(char *convention) { +static inline decl_abi *init_decl_abi(const char *convention) { decl_abi *abi = calloc(1, sizeof(*abi)); abi->convention = strdup(convention); return abi; @@ -265,7 +265,7 @@ typedef struct decl_struct { decl_struct_layout *layout; } decl_struct; -static inline decl_struct *init_decl_struct(char *name, decl_args *args) { +static inline decl_struct *init_decl_struct(const char *name, decl_args *args) { decl_struct *s = calloc(1, sizeof(*s)); s->name = strdup(name); s->args = args; @@ -347,11 +347,11 @@ typedef struct impl_type { token_t type; } impl_type; -static inline impl_type *init_impl_type(token_t type, char *name) { +static inline impl_type *init_impl_type(token_t type, const char *name) { impl_type *t = calloc(1, sizeof(*t)); t->type = type; - t->name = (char *) strdup((const char *) name); + t->name = strdup(name); return t; } @@ -365,7 +365,7 @@ typedef struct impl_var { unsigned reference:1; } impl_var; -static inline impl_var *init_impl_var(char *name, int is_reference) { +static inline impl_var *init_impl_var(const char *name, int is_reference) { impl_var *var = calloc(1, sizeof(*var)); var->name = strdup(name); var->reference = is_reference; @@ -382,7 +382,7 @@ typedef struct impl_def_val { char *text; } impl_def_val; -static inline impl_def_val *init_impl_def_val(token_t t, char *text) { +static inline impl_def_val *init_impl_def_val(token_t t, const char *text) { impl_def_val *def = calloc(1, sizeof(*def)); def->type = t; def->text = strdup(text); @@ -499,7 +499,7 @@ typedef struct let_func { let_calloc *alloc; } let_func; -static inline let_func *init_let_func(token_t type, char *name, let_calloc *alloc) { +static inline let_func *init_let_func(token_t type, const char *name, let_calloc *alloc) { let_func *func = calloc(1, sizeof(*func)); func->type = type; func->name = strdup(name); @@ -568,10 +568,10 @@ typedef struct set_func { char *name; } set_func; -static inline set_func *init_set_func(token_t type, char *name) { +static inline set_func *init_set_func(token_t type, const char *name) { set_func *func = calloc(1, sizeof(*func)); func->type = type; - func->name = (char *) strdup((const char *) name); + func->name = strdup(name); return func; } @@ -823,7 +823,7 @@ typedef struct constant { impl_def_val *val; } constant; -static inline constant *init_constant(const_type *type, char *name, impl_def_val *val) { +static inline constant *init_constant(const_type *type, const char *name, impl_def_val *val) { constant *c = calloc(1, sizeof(*c)); c->type = type; c->name = strdup(name); diff --git a/src/parser.re b/src/parser.re index 0782b8f..831b218 100644 --- a/src/parser.re +++ b/src/parser.re @@ -204,13 +204,13 @@ token_t PSI_ParserScan(PSI_Parser *P) 'INT' {RETURN(PSI_T_INT);} 'FLOAT' {RETURN(PSI_T_FLOAT);} 'DOUBLE' {RETURN(PSI_T_DOUBLE);} - 'INT8_T' {RETURN(PSI_T_SINT8);} + 'INT8_T' {RETURN(PSI_T_INT8);} 'UINT8_T' {RETURN(PSI_T_UINT8);} - 'INT16_T' {RETURN(PSI_T_SINT16);} + 'INT16_T' {RETURN(PSI_T_INT16);} 'UINT16_T' {RETURN(PSI_T_UINT16);} - 'INT32_T' {RETURN(PSI_T_SINT32);} + 'INT32_T' {RETURN(PSI_T_INT32);} 'UINT32_T' {RETURN(PSI_T_UINT32);} - 'INT64_T' {RETURN(PSI_T_SINT64);} + 'INT64_T' {RETURN(PSI_T_INT64);} 'UINT64_T' {RETURN(PSI_T_UINT64);} 'STRING' {RETURN(PSI_T_STRING);} 'ARRAY' {RETURN(PSI_T_ARRAY);} diff --git a/src/parser_proc.h b/src/parser_proc.h index 5940f92..95f1821 100644 --- a/src/parser_proc.h +++ b/src/parser_proc.h @@ -21,42 +21,38 @@ #define PSI_T_RBRACKET 21 #define PSI_T_COMMA 22 #define PSI_T_VOID 23 -#define PSI_T_CHAR 24 -#define PSI_T_SHORT 25 -#define PSI_T_LONG 26 -#define PSI_T_DOUBLE 27 -#define PSI_T_SIZE_T 28 -#define PSI_T_SINT8 29 -#define PSI_T_UINT8 30 -#define PSI_T_SINT16 31 -#define PSI_T_UINT16 32 -#define PSI_T_SINT32 33 -#define PSI_T_UINT32 34 -#define PSI_T_SINT64 35 -#define PSI_T_UINT64 36 -#define PSI_T_FUNCTION 37 -#define PSI_T_COLON 38 -#define PSI_T_REFERENCE 39 -#define PSI_T_NULL 40 -#define PSI_T_TRUE 41 -#define PSI_T_FALSE 42 -#define PSI_T_DOLLAR 43 -#define PSI_T_LET 44 -#define PSI_T_CALLOC 45 -#define PSI_T_STRLEN 46 -#define PSI_T_STRVAL 47 -#define PSI_T_INTVAL 48 -#define PSI_T_FLOATVAL 49 -#define PSI_T_BOOLVAL 50 -#define PSI_T_ARRVAL 51 -#define PSI_T_SET 52 -#define PSI_T_TO_ARRAY 53 -#define PSI_T_TO_STRING 54 -#define PSI_T_TO_INT 55 -#define PSI_T_TO_FLOAT 56 -#define PSI_T_TO_BOOL 57 -#define PSI_T_RETURN 58 -#define PSI_T_FREE 59 -#define PSI_T_MIXED 60 -#define PSI_T_ARRAY 61 -#define PSI_T_POINTER 62 +#define PSI_T_DOUBLE 24 +#define PSI_T_INT8 25 +#define PSI_T_UINT8 26 +#define PSI_T_INT16 27 +#define PSI_T_UINT16 28 +#define PSI_T_INT32 29 +#define PSI_T_UINT32 30 +#define PSI_T_INT64 31 +#define PSI_T_UINT64 32 +#define PSI_T_FUNCTION 33 +#define PSI_T_COLON 34 +#define PSI_T_REFERENCE 35 +#define PSI_T_NULL 36 +#define PSI_T_TRUE 37 +#define PSI_T_FALSE 38 +#define PSI_T_DOLLAR 39 +#define PSI_T_LET 40 +#define PSI_T_CALLOC 41 +#define PSI_T_STRLEN 42 +#define PSI_T_STRVAL 43 +#define PSI_T_INTVAL 44 +#define PSI_T_FLOATVAL 45 +#define PSI_T_BOOLVAL 46 +#define PSI_T_ARRVAL 47 +#define PSI_T_SET 48 +#define PSI_T_TO_ARRAY 49 +#define PSI_T_TO_STRING 50 +#define PSI_T_TO_INT 51 +#define PSI_T_TO_FLOAT 52 +#define PSI_T_TO_BOOL 53 +#define PSI_T_RETURN 54 +#define PSI_T_FREE 55 +#define PSI_T_MIXED 56 +#define PSI_T_ARRAY 57 +#define PSI_T_POINTER 58 diff --git a/src/parser_proc.y b/src/parser_proc.y index b606cf0..2fb309e 100644 --- a/src/parser_proc.y +++ b/src/parser_proc.y @@ -179,22 +179,6 @@ decl_type(type_) ::= VOID(T). { type_ = init_decl_type(T->type, T->text); free(T); } -decl_type(type_) ::= CHAR(T). { - type_ = init_decl_type(T->type, T->text); - free(T); -} -decl_type(type_) ::= SHORT(T). { - type_ = init_decl_type(T->type, T->text); - free(T); -} -decl_type(type_) ::= INT(T). { - type_ = init_decl_type(T->type, T->text); - free(T); -} -decl_type(type_) ::= LONG(T). { - type_ = init_decl_type(T->type, T->text); - free(T); -} decl_type(type_) ::= FLOAT(T). { type_ = init_decl_type(T->type, T->text); free(T); @@ -203,8 +187,9 @@ decl_type(type_) ::= DOUBLE(T). { type_ = init_decl_type(T->type, T->text); free(T); } -decl_type(type_) ::= SIZE_T(T). { - type_ = init_decl_type(T->type, T->text); +/* we have to support plain int here because we have it in our lexer rules */ +decl_type(type_) ::= INT(T). { + type_ = init_decl_type(PSI_T_NAME, T->text); free(T); } decl_type(type_) ::= INT8(T). { -- 2.30.2