From: Michael Wallner Date: Fri, 30 Nov 2018 09:31:23 +0000 (+0100) Subject: fix clang build X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=d4bd55e7d9b1cf63cd6fdc96b70010a0c2aca963;p=m6w6%2Fext-psi fix clang build --- diff --git a/.gdbinit b/.gdbinit index 4e73683..5eacaad 100644 --- a/.gdbinit +++ b/.gdbinit @@ -83,12 +83,12 @@ define psi_let_calloc_dump echo \n end define psi_let_exp_dump - call psi_let_exp_dump((void*)0, $arg0, 0) - echo \n + call psi_let_exp_dump((void*)0, $arg0, 0, 0) + echo \n end define psi_let_func_dump call psi_let_func_dump((void*)0, $arg0, 0) - echo \n + echo \n end define psi_let_stmt_dump call psi_let_stmt_dump((void*)0, $arg0) @@ -108,7 +108,7 @@ define psi_return_stmt_dump end define psi_set_exp_dump call psi_set_exp_dump((void*)0, $arg0, 0, 0) - echo \n + echo \n end define psi_set_func_dump call psi_set_func_dump((void*)0, $arg0, 0) diff --git a/TODO b/TODO index ae6f541..ccfc46b 100644 --- a/TODO +++ b/TODO @@ -20,3 +20,4 @@ * cache tokens of files and copy tokens if used for further processing * optimized inlines like htonl +* real integral type of enums diff --git a/config.m4 b/config.m4 index 1a6fbec..f63f52d 100644 --- a/config.m4 +++ b/config.m4 @@ -1,12 +1,3 @@ -PHP_PSI_SRCDIR=PHP_EXT_SRCDIR(psi) - -case "PHP_EXT_BUILDDIR(psi)" in -""|.) PHP_PSI_BUILDDIR=$PHP_PSI_SRCDIR - ;; -*) PHP_PSI_BUILDDIR=PHP_EXT_BUILDDIR(psi) - ;; -esac - m4_foreach(incfile, [ [ax/ax_check_sign.m4], [ax/ax_pthread.m4], @@ -52,8 +43,16 @@ if test "$PHP_PSI" != no; then ]) AC_MSG_CHECKING([psi source dir]) + PHP_PSI_SRCDIR=PHP_EXT_SRCDIR(psi) AC_MSG_RESULT([$PHP_PSI_SRCDIR]) + AC_MSG_CHECKING([psi build dir]) + case "PHP_EXT_BUILDDIR(psi)" in + ""|.) PHP_PSI_BUILDDIR=$PHP_PSI_SRCDIR + ;; + *) PHP_PSI_BUILDDIR=PHP_EXT_BUILDDIR(psi) + ;; + esac AC_MSG_RESULT([$PHP_PSI_BUILDDIR]) PSI_CHECK_LIBJIT diff --git a/m4/psi/psi.m4 b/m4/psi/psi.m4 index 2ad2499..9701afc 100644 --- a/m4/psi/psi.m4 +++ b/m4/psi/psi.m4 @@ -195,23 +195,6 @@ typedef bool _Bool; #endif ]) -dnl PSI_LEMON() -dnl Declare $LEMON precious, and check for a `lemon` in $PATH. -AC_DEFUN(PSI_LEMON, [ - AC_ARG_VAR(LEMON, The lemon parser generator of the SQLite project) - if test -z "$LEMON" - then - AC_PATH_PROG(LEMON, lemon, $PHP_PSI_BUILDDIR/lemon) - if expr + "$LEMON" : "/" >/dev/null; then - LEMON_PATH= - else - LEMON_PATH=$abs_builddir/ - fi - fi - PHP_SUBST(LEMON_PATH) - PHP_SUBST(LEMON) -]) - dnl PSI_PKG_CONFIG() dnl Check for `pkg-config` and add possible libjit and libffi directories to dnl $PKG_CONFIG_PATH, because those libs often ship with headers etc. in diff --git a/m4/psi/psi_type.m4 b/m4/psi/psi_type.m4 index 2a107fd..6da73c5 100644 --- a/m4/psi/psi_type.m4 +++ b/m4/psi/psi_type.m4 @@ -1,10 +1,3 @@ -# psi_add_type(type triplet) -# Add a pre-defined type to $PSI_TYPES_H. -psi_add_type() { - PSI_TYPES="$PSI_TYPES - $1," -} - psi_add_stdtype() { PSI_STDTYPES="$PSI_STDTYPES $1," @@ -40,30 +33,6 @@ psi_type_pair() { esac } -dnl PSI_TYPE(type name, basic type) -dnl Check for a specific type, optionally referring to a basic type. -dnl Calls AC_TYPE_ (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_H. -AC_DEFUN(PSI_TYPE, [ - ifdef(AS_TR_CPP(AC_TYPE_$1), AS_TR_CPP(AC_TYPE_$1)) - PSI_CHECK_SIZEOF($1) - psi_basic_type=AS_TR_SH($2) - case $psi_basic_type in - int) - AX_CHECK_SIGN($1, :, [psi_basic_type=uint], PSI_INCLUDES) - ;; - sint) - psi_basic_type=int - ;; - esac - if test "$2" && PSI_SH_TEST_SIZEOF($1); then - AS_TR_SH(psi_basic_type_$1)=$psi_basic_type - psi_add_type "{`psi_type_pair $psi_basic_type PSI_SH_SIZEOF($1)`, \"$1\"}" - fi -]) - AC_DEFUN(PSI_STDTYPE, [ ifdef(AS_TR_CPP(AC_TYPE_$1), AS_TR_CPP(AC_TYPE_$1)) PSI_CHECK_SIZEOF($1) @@ -81,115 +50,6 @@ AC_DEFUN(PSI_STDTYPE, [ fi ]) -dnl PSI_SH_BASIC_TYPE(type) -dnl Expand to the basic type (int/uint) of a distinct type -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_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)) - PSI_CHECK_SIZEOF($1) - if PSI_SH_TEST_SIZEOF($1); then - psi_type_class= - AC_CACHE_CHECK(kind of $1, AS_TR_SH([psi_cv_type_class_]$1), [ - AC_TRY_COMPILE(PSI_INCLUDES, [char test@<:@($1)1@:>@;], [ - psi_type_class=scalar - ], [ - AC_TRY_COMPILE(PSI_INCLUDES, [$1 test = 0;], [ - AC_TRY_COMPILE(PSI_INCLUDES, [$1 test = (($1)0)+1;], [ - psi_type_class="pointer of known type" - ], [ - psi_type_class="pointer of opaque type" - ]) - ], [ - psi_type_class=struct - ]) - ]) - AS_TR_SH([psi_cv_type_class_]$1)="$psi_type_class" - ]) - case "$AS_TR_SH([psi_cv_type_class_]$1)" in - scalar) - AX_CHECK_SIGN($1, [psi_basic_type=int], [psi_basic_type=uint], PSI_INCLUDES) - psi_add_type "{`psi_type_pair $psi_basic_type PSI_SH_SIZEOF($1)`, \"$1\"}" - ;; - struct) - PSI_STRUCT($1) - ;; - pointer*) - psi_add_type "{PSI_T_POINTER, \"void\", \"$1\"}" - ;; - *) - AC_MSG_WARN(could not detect kind of $1) - ;; - esac - fi -]) - -dnl PSI_FUNCTOR_TYPE(type functor_name, args) -dnl Forwards to PSI_DECL_TYPE. -AC_DEFUN(PSI_FUNCTOR_TYPE, [ - dnl psi_add_type "{PSI_T_POINTER, \"void\", \"PSI_VAR_NAME($1)\"}" - AS_TR_SH([ac_cv_sizeof_]PSI_VAR_NAME($1))=PSI_SH_SIZEOF(void *) - PSI_DECL_TYPE([$1], [$2]) - AC_CHECK_TYPE(PSI_VAR_NAME($1), [], [ - psi_add_macro ["#undef ]PSI_VAR_NAME($1)["] - psi_add_macro ["typedef ]PSI_VAR_TYPE($1)[ (*]PSI_VAR_NAME($1)[)]$2;" - ]) -]) - -dnl PSI_VAR_TYPE(decl arg) -dnl Extracts the type of a decl arg, e.g. dnl unsigned char* buf[16] -> unsigned char*. -AC_DEFUN(PSI_VAR_TYPE, [m4_bregexp([$1], [^\(const \)?\(.*\) \([*]*\)[^ ]+$], [\2\3])]) - -dnl PSI_VAR_TYPE_RETURN(decl arg) -dnl Extracts the type of a decl arg usable for return types, e.g. dnl unsigned char* buf[16] -> unsigned char**. -AC_DEFUN(PSI_VAR_TYPE_RETURN, [PSI_VAR_TYPE(m4_bpatsubst([$1], [\([^ ]+\) *@<:@[0-9]+@:>@], [* \1]))]) - -dnl PSI_VAR_NAME(decl arg) -dnl Extracts the var name of a decl arg, e.g. unsigned char* buf[16] -> buf. -AC_DEFUN(PSI_VAR_NAME, [m4_bregexp(m4_bregexp([$1], [\([^ ]+\)$], [\1]), [\w+], [\&])]) - -dnl PSI_TYPE_INDIRECTION(decl arg, size, pointer_level_var, array_size_var) -dnl Calculates and assigns pointer_level and array_size of a decl arg to sh vars. -AC_DEFUN(PSI_TYPE_INDIRECTION, [ - m4_define([psi_pointer_level], m4_len(m4_bpatsubst([PSI_VAR_TYPE($1)], [[^*]]))) - m4_define([psi_array_size], [m4_bregexp([PSI_VAR_TYPE($1)], [@<:@\([0-9]+\)@:>@], [\1])]) - - ifelse(psi_array_size.$2,0., [ - AC_MSG_ERROR([cannot compute dynamic array size of a non-struct member]) - ], [ - ifelse(psi_pointer_level,0,[ - m4_define([psi_type_size],[$]AS_TR_SH([ac_cv_sizeof_]m4_bregexp(PSI_VAR_TYPE([$1]), [^\( \|\w\)+], [\&]))) - ],[ - m4_define([psi_type_size],$ac_cv_sizeof_void_p) - ]) - ]) - - m4_case(psi_array_size,,[ - $3=psi_pointer_level - $4=0] - ,0,[ - $3=m4_incr(psi_pointer_level) - $4="`expr $2 / psi_type_size`" - ], [ - $3=m4_incr(psi_pointer_level) - $4=psi_array_size - ]) -]) - -dnl PSI_TYPE_PAIR(type) -dnl Expand to a PSI_T_, \\"\\" tuple. -dnl FIXME: There is also psi_type_pair()? -AC_DEFUN(PSI_TYPE_PAIR, [m4_case(m4_bregexp([$1], [^\w+], [\&]), - [void], [PSI_T_VOID, \"void\"], - [struct], [PSI_T_STRUCT, \"m4_bregexp([$1], [^struct \(\w+\)], [\1])\"], - [union], [PSI_T_UNION, \"m4_bregexp([$1], [^union \(\w+\)], [\1])\"], - [PSI_T_NAME, \"m4_bregexp([$1], [^\(\w+ \)*\w+], [\&])\"])]) - dnl PSI_CHECK_STD_TYPES() dnl Checks for standard ANSI-C, stdint and stdbool types. AC_DEFUN(PSI_CHECK_STD_TYPES, [ diff --git a/src/builtin.c b/src/builtin.c index 0eedec2..2d92432 100644 --- a/src/builtin.c +++ b/src/builtin.c @@ -36,6 +36,7 @@ HashTable psi_builtins; static bool has_include(struct psi_cpp *cpp, struct psi_token *target, struct psi_plist **args, struct psi_plist **res); static bool has_include_next(struct psi_cpp *cpp, struct psi_token *target, struct psi_plist **args, struct psi_plist **res); +static bool has_feature(struct psi_cpp *cpp, struct psi_token *target, struct psi_plist **args, struct psi_plist **res); static bool builtin_constant_p(struct psi_cpp *cpp, struct psi_token *target, struct psi_plist **args, struct psi_plist **res); static bool COUNTER__(struct psi_cpp *cpp, struct psi_token *target, struct psi_plist **args, struct psi_plist **res); @@ -92,7 +93,9 @@ PHP_MINIT_FUNCTION(psi_builtin) zend_hash_init(&psi_builtins, 0, NULL, free_builtin, 1); PSI_BUILTIN(has_include, PSI_T_CPP_HEADER); PSI_BUILTIN(has_include_next, PSI_T_CPP_HEADER); + PSI_BUILTIN(has_feature, PSI_T_NAME); PSI_BUILTIN(builtin_constant_p, PSI_T_NAME); + PSI_BUILTIN(COUNTER__, -1); return SUCCESS; @@ -158,6 +161,12 @@ static bool has_include_next(struct psi_cpp *cpp, struct psi_token *target, return false; } +static bool has_feature(struct psi_cpp *cpp, struct psi_token *target, + struct psi_plist **args, struct psi_plist **res_ptr) +{ + return false; +} + static bool builtin_constant_p(struct psi_cpp *cpp, struct psi_token *target, struct psi_plist **args, struct psi_plist **res_ptr) { diff --git a/src/error.c b/src/error.c index af336a2..48a41ac 100644 --- a/src/error.c +++ b/src/error.c @@ -71,6 +71,10 @@ void psi_error_wrapper(struct psi_data *context, struct psi_token *t, int type, va_start(argv, msg); psi_verror(type, fn, ln, msg, argv); +#ifdef __clang__ + va_end(argv); + va_start(argv, msg); +#endif PSI_DEBUG_PRINTV(context, msg, argv); va_end(argv); diff --git a/tests/iconv/iconv.psi b/tests/iconv/iconv.psi index e414dc0..1bcf000 100644 --- a/tests/iconv/iconv.psi +++ b/tests/iconv/iconv.psi @@ -13,7 +13,7 @@ function psi\iconv(object $iconv, string &$inbuf, string &$outbuf) : int { let outbytesleft = &8192; let outbuf = &calloc(1, 8192); temp result = *outbuf; - return to_int(iconv); + return iconv(cd, inbuf, inbytesleft, outbuf, outbytesleft) as to_int(iconv); set $inbuf = to_string(*inbuf, *inbytesleft); set $outbuf = to_string(result, 8192 - *outbytesleft); }