├── .editorconfig ├── .gdbinit ├── .gitattributes ├── .gitignore ├── .gitmodules ├── .travis.yml ├── AUTHORS ├── BUGS ├── CONTRIBUTING.md ├── CREDITS ├── EXPERIMENTAL ├── LICENSE ├── Makefile.frag ├── README.md ├── THANKS ├── TODO ├── config.m4 ├── m4 ├── ax │ ├── ax_check_compile_flag.m4 │ ├── ax_check_sign.m4 │ └── ax_pthread.m4 └── psi │ ├── psi.m4 │ ├── psi_const.m4 │ └── psi_type.m4 ├── package.xml ├── php_psi.h ├── php_psi_predef.h.in ├── psi.d ├── arpa_inet.psi ├── errno.psi ├── getopt.psi ├── glob.psi ├── netdb.psi ├── stat.psi ├── stdio.psi ├── stdlib.psi ├── string.psi ├── syslog.psi ├── time.psi └── uname.psi ├── scripts ├── _include.php ├── gen_calc_basic.php ├── gen_calc_bin.php ├── gen_calc_bool.php ├── gen_calc_cast.php ├── gen_calc_cmp.php ├── gen_calc_oper.php ├── gen_calc_unary.php ├── gen_package_xml.php └── gen_travis_yml.php ├── src ├── builtin.c ├── builtin.h ├── calc.h ├── calc │ ├── basic.h │ ├── bin.h │ ├── bool.h │ ├── cast.h │ ├── cmp.h │ ├── oper.h │ └── unary.h ├── call.c ├── call.h ├── context.c ├── context.h ├── cpp.c ├── cpp.h ├── cpp_tokiter.c ├── data.c ├── data.h ├── debug.c ├── debug.h ├── dl.h ├── dump.c ├── dump.h ├── error.c ├── error.h ├── libffi.c ├── libffi.h ├── libffi_compat.h ├── libjit.c ├── libjit.h ├── marshal.c ├── marshal.h ├── module.c ├── parser.c ├── parser.h ├── parser_proc.c ├── parser_proc.h ├── parser_proc_grammar.y ├── parser_scan.c ├── parser_scan.re ├── plist.c ├── plist.h ├── token.c ├── token.h ├── types.h ├── types │ ├── assert_stmt.c │ ├── assert_stmt.h │ ├── const.c │ ├── const.h │ ├── cpp_exp.c │ ├── cpp_exp.h │ ├── cpp_macro_call.c │ ├── cpp_macro_call.h │ ├── cpp_macro_decl.c │ ├── cpp_macro_decl.h │ ├── decl.c │ ├── decl.h │ ├── decl_abi.c │ ├── decl_abi.h │ ├── decl_arg.c │ ├── decl_arg.h │ ├── decl_enum.c │ ├── decl_enum.h │ ├── decl_enum_item.c │ ├── decl_enum_item.h │ ├── decl_extvar.c │ ├── decl_extvar.h │ ├── decl_file.c │ ├── decl_file.h │ ├── decl_struct.c │ ├── decl_struct.h │ ├── decl_type.c │ ├── decl_type.h │ ├── decl_union.c │ ├── decl_union.h │ ├── decl_var.c │ ├── decl_var.h │ ├── free_exp.c │ ├── free_exp.h │ ├── free_stmt.c │ ├── free_stmt.h │ ├── impl.c │ ├── impl.h │ ├── impl_arg.c │ ├── impl_arg.h │ ├── impl_def_val.c │ ├── impl_def_val.h │ ├── impl_func.c │ ├── impl_func.h │ ├── impl_type.c │ ├── impl_type.h │ ├── impl_val.h │ ├── impl_var.c │ ├── impl_var.h │ ├── layout.c │ ├── layout.h │ ├── let_callback.c │ ├── let_callback.h │ ├── let_calloc.c │ ├── let_calloc.h │ ├── let_exp.c │ ├── let_exp.h │ ├── let_func.c │ ├── let_func.h │ ├── let_stmt.c │ ├── let_stmt.h │ ├── num_exp.c │ ├── num_exp.h │ ├── number.c │ ├── number.h │ ├── return_exp.c │ ├── return_exp.h │ ├── return_stmt.c │ ├── return_stmt.h │ ├── set_exp.c │ ├── set_exp.h │ ├── set_func.c │ ├── set_func.h │ ├── set_stmt.c │ └── set_stmt.h ├── validate.c └── validate.h └── tests ├── arpa_inet ├── inet001.phpt ├── inet002.phpt └── ntoh001.phpt ├── calc ├── calc.psi └── calc001.phpt ├── div ├── div001.phpt ├── ldiv001.phpt └── lldiv001.phpt ├── getopt ├── getopt001.phpt └── getopt002.phpt ├── glob ├── glob001.phpt ├── glob002.phpt ├── glob003.phpt └── glob004.phpt ├── iconv ├── iconv.psi ├── iconv001.phpt └── iconv002.phpt ├── idn ├── idn.psi ├── idn001.phpt ├── idn002.phpt ├── idn003.phpt └── idn004.phpt ├── ndbm ├── gdbm.psi ├── ndbm.psi └── ndbm001.phpt ├── netdb └── gai001.phpt ├── parser ├── cpp001.phpt ├── cpp002.phpt ├── cpp003.phpt ├── cpp003 │ └── prescan.psi ├── cpp004.phpt ├── cpp004 │ ├── base_file.h │ ├── builtins.psi │ ├── include_level.h │ └── timestamp.h ├── cpp005.phpt ├── cpp005 │ └── expansion.psi ├── dump001.phpt ├── enum001.phpt ├── validate001.phpt ├── validate002.phpt ├── validate003.phpt ├── validate004.phpt ├── validate005.phpt ├── validate006.phpt └── validate007.phpt ├── pipe ├── pipe.psi └── pipe001.phpt ├── sqlite ├── sqlite.psi ├── sqlite001.db └── sqlite001.phpt ├── stat ├── stat001.phpt └── stat002.phpt ├── stdio ├── fopen001.phpt └── printf001.phpt ├── time ├── asc_gmtime001.phpt ├── gettimeofday001.phpt ├── nanosleep001.phpt ├── times001.phpt └── tzname001.phpt ├── uname ├── uname001.phpt └── uname002.phpt └── yaml ├── yaml.psi └── yaml001.phpt /.editorconfig: -------------------------------------------------------------------------------- 1 | ; see http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | end_of_line = lf 6 | insert_final_newline = true 7 | indent_style = tab 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | 14 | [*.json] 15 | indent_style = space 16 | indent_size = 4 17 | 18 | [package.xml] 19 | indent_style = space 20 | indent_size = 1 21 | 22 | [config.w32] 23 | end_of_line = crlf 24 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | /tests/sqlite/sqlite001.db binary 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.swp 3 | *.dSYM 4 | *.o 5 | *.lo 6 | *.loT 7 | *.la 8 | *.dep 9 | .libs 10 | acinclude.m4 11 | aclocal.m4 12 | autom4te.cache 13 | build 14 | config.guess 15 | config.h 16 | config.h.in 17 | config.log 18 | config.nice 19 | config.status 20 | config.sub 21 | configure 22 | configure.in 23 | include 24 | install-sh 25 | libtool 26 | ltmain.sh 27 | Makefile 28 | Makefile.fragments 29 | Makefile.global 30 | Makefile.objects 31 | missing 32 | mkinstalldirs 33 | modules 34 | run-tests.php 35 | tests/*/*.diff 36 | tests/*/*.out 37 | tests/*/*.php 38 | tests/*/*.exp 39 | tests/*/*.log 40 | tests/*/*.sh 41 | tests/*/*.mem 42 | /config.cache 43 | /*.c 44 | /*.diff 45 | /*.phar 46 | /tmp/ 47 | /context.h 48 | /libffi.h 49 | /libjit.h 50 | /calc.h 51 | /data.h 52 | /engine.h 53 | /error.h 54 | /libjit.h 55 | /marshal.h 56 | /parser.h 57 | /parser_def.h 58 | /parser_proc.h 59 | /token.h 60 | /types.h 61 | /src/parser_proc.output 62 | /php_psi_predef.h 63 | /types/ 64 | /calc/ 65 | *.bak 66 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "travis-pecl"] 2 | path = travis/pecl 3 | url = https://github.com/m6w6/travis-pecl.git 4 | branch = master 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # autogenerated file; do not edit 2 | language: c 3 | sudo: required 4 | dist: bionic 5 | 6 | addons: 7 | apt: 8 | packages: 9 | - php-cli 10 | - php-pear 11 | - valgrind 12 | - gdb 13 | - apport 14 | - re2c 15 | - libidn11-dev 16 | - libsqlite3-dev 17 | - libgdbm-dev 18 | - libgdbm-compat-dev 19 | 20 | env: 21 | matrix: 22 | - PHP=master enable_debug=no enable_psi=yes enable_psi_threaded_parser=no 23 | - PHP=master enable_debug=yes enable_psi=yes enable_psi_threaded_parser=no 24 | - PHP=master enable_debug=no enable_psi=yes enable_psi_threaded_parser=yes 25 | - PHP=master enable_debug=yes enable_psi=yes enable_psi_threaded_parser=yes 26 | 27 | before_install: 28 | # make sure we do not try to regenerate files with broken bison or old re2c 29 | - touch src/parser_proc_grammar.y 30 | - touch src/parser_proc.c 31 | - touch src/parser_proc.h 32 | - touch src/parser_scan.re 33 | - touch src/parser_scan.c 34 | - touch src/parser.h 35 | 36 | install: 37 | - make -f travis/pecl/Makefile php 38 | 39 | before_script: 40 | - ulimit -c unlimited -S 41 | - export TEST_PHP_ARGS="--no-clean" 42 | 43 | script: 44 | - make -f travis/pecl/Makefile ext PECL=psi 45 | - make -f travis/pecl/Makefile test 46 | 47 | after_failure: 48 | - cat config.log | curl -F 'sprunge=<-' http://sprunge.us 49 | - cat tests/parser/dump001.psi | curl -F 'sprunge=<-' http://sprunge.us 50 | - test -f core* && gdb -q -ex bt --batch $HOME/job-$TRAVIS_JOB_NUMBER/bin/php core* 51 | 52 | notifications: 53 | webhooks: 54 | urls: 55 | - https://webhooks.gitter.im/e/30aebb6c0b03f1117817 56 | on_success: change 57 | on_failure: always 58 | on_start: never 59 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Michael Wallner 2 | -------------------------------------------------------------------------------- /BUGS: -------------------------------------------------------------------------------- 1 | Yay, no known and unresolved issues yet! 2 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, and in the interest of 4 | fostering an open and welcoming community, we pledge to respect all people who 5 | contribute through reporting issues, posting feature requests, updating 6 | documentation, submitting pull requests or patches, and other activities. 7 | 8 | We are committed to making participation in this project a harassment-free 9 | experience for everyone, regardless of level of experience, gender, gender 10 | identity and expression, sexual orientation, disability, personal appearance, 11 | body size, race, ethnicity, age, religion, or nationality. 12 | 13 | Examples of unacceptable behavior by participants include: 14 | 15 | * The use of sexualized language or imagery 16 | * Personal attacks 17 | * Trolling or insulting/derogatory comments 18 | * Public or private harassment 19 | * Publishing other's private information, such as physical or electronic 20 | addresses, without explicit permission 21 | * Other unethical or unprofessional conduct. 22 | 23 | Project maintainers have the right and responsibility to remove, edit, or reject 24 | comments, commits, code, wiki edits, issues, and other contributions that are 25 | not aligned to this Code of Conduct. By adopting this Code of Conduct, project 26 | maintainers commit themselves to fairly and consistently applying these 27 | principles to every aspect of managing this project. Project maintainers who do 28 | not follow or enforce the Code of Conduct may be permanently removed from the 29 | project team. 30 | 31 | This code of conduct applies both within project spaces and in public spaces 32 | when an individual is representing the project or its community. 33 | 34 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 35 | reported by opening an issue or contacting one or more of the project maintainers. 36 | 37 | This Code of Conduct is adapted from the 38 | [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, 39 | available at http://contributor-covenant.org/version/1/2/0/. 40 | -------------------------------------------------------------------------------- /CREDITS: -------------------------------------------------------------------------------- 1 | psi 2 | Michael Wallner 3 | -------------------------------------------------------------------------------- /EXPERIMENTAL: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m6w6/ext-psi/0682ecb84dfe1de08b609c6c0ae641b06f3fa481/EXPERIMENTAL -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, Michael Wallner . 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 14 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 17 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 20 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 21 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | -------------------------------------------------------------------------------- /THANKS: -------------------------------------------------------------------------------- 1 | Thanks go to the following people, who have contributed to this project: 2 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | * avoid allocs inside structures by reallocating the whole structure 2 | * let the various list types be hashtables where appropriate 3 | * check out jit-dynamic 4 | * fix arginfo with nullable types 5 | * think about a better system for EXTVARs, separate \set and \get functions are clunky 6 | * fix right recursion of let_exp and set_exp 7 | * improve varargs support, currently it's impossible to map e.g. curl_easy_setopt 8 | * impl_var.name: remove leading '$' 9 | * really solve the array/pointer problem 10 | 11 | * variadic macros 12 | * predefined macros 13 | ... 14 | * builtins 15 | ... 16 | * int128 17 | * very small real numbers 18 | * cache tokens of files and copy tokens if used for further processing 19 | 20 | * optimized inlines like htonl 21 | * real integral type of enums 22 | 23 | * #pragma PSI lib "foo" instead of lib "foo"; 24 | * #line directive 25 | -------------------------------------------------------------------------------- /config.m4: -------------------------------------------------------------------------------- 1 | m4_foreach(incfile, [ 2 | [ax/ax_check_compile_flag.m4], 3 | [ax/ax_check_sign.m4], 4 | [ax/ax_pthread.m4], 5 | [psi/psi.m4], 6 | [psi/psi_type.m4]], [ 7 | dnl pecl build 8 | sinclude([m4/]incfile) 9 | dnl php-src build 10 | sinclude([ext/psi/m4/]incfile) 11 | ]) 12 | 13 | PHP_ARG_ENABLE(psi, whether to enable PHP System Interface support, 14 | [ --enable-psi Enable PSI (PHP System Interface) support]) 15 | 16 | if test "$PHP_PSI" != no; then 17 | 18 | PHP_ARG_ENABLE(psi-maintainer-mode, whether to enable maintainer mode, 19 | [ --enable-psi-maintainer-mode 20 | PSI: enable maintainer mode 21 | . make dependencies], [no], [no]) 22 | PHP_ARG_ENABLE(psi-threaded-parser, whether to enable threaded parser, 23 | [ --enable-psi-threaded-parser 24 | PSI: enable threads for startup parsing], [yes], [no]) 25 | 26 | PHP_ARG_WITH(psi-libjit, where to find libjit, 27 | [ --with-psi-libjit=DIR PSI: path to libjit], [ ], [ ]) 28 | 29 | PHP_ARG_WITH(psi-libffi, where to find libffi, 30 | [ --with-psi-libffi=DIR PSI: path to libffi], [ ], [ ]) 31 | 32 | AC_HEADER_ASSERT dnl # adds --disable-assert to define NDEBUG 33 | 34 | PSI_CONFIG_INIT 35 | 36 | PSI_CHECK_MAINTAINER_MODE 37 | PSI_CHECK_THREADED_PARSER 38 | 39 | dnl we cannot use AC_USE_SYSTEM_EXTENSIONS here, because we're way too late 40 | dnl in the game, and we're currently only targeting _GNU_SOURCE for now 41 | PSI_CHECK_GNU_SOURCE 42 | PSI_CHECK_CPP 43 | PSI_CHECK_STD_TYPES 44 | 45 | AC_HEADER_DIRENT 46 | AC_FUNC_FNMATCH 47 | AC_FUNC_MMAP 48 | AC_CHECK_FUNCS([mknodat eaccess]) 49 | 50 | PSI_CHECK_PTHREAD 51 | PSI_CHECK_LIBJIT 52 | PSI_CHECK_LIBFFI 53 | 54 | PSI_CONFIG_DONE 55 | 56 | AC_DEFINE_UNQUOTED(PHP_PSI_SHLIB_SUFFIX, ["$SHLIB_SUFFIX_NAME"], DL suffix) 57 | 58 | PHP_SUBST(PSI_SHARED_LIBADD) 59 | PHP_NEW_EXTENSION(psi, $PHP_PSI_SOURCES, $ext_shared) 60 | PHP_INSTALL_HEADERS(ext/psi, php_psi.h $PHP_PSI_HEADERS) 61 | 62 | PHP_ADD_MAKEFILE_FRAGMENT 63 | AC_MSG_RESULT() 64 | fi 65 | -------------------------------------------------------------------------------- /m4/ax/ax_check_compile_flag.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # Check whether the given FLAG works with the current language's compiler 12 | # or gives an error. (Warnings, however, are ignored) 13 | # 14 | # ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on 15 | # success/failure. 16 | # 17 | # If EXTRA-FLAGS is defined, it is added to the current language's default 18 | # flags (e.g. CFLAGS) when the check is done. The check is thus made with 19 | # the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to 20 | # force the compiler to issue an error when a bad flag is given. 21 | # 22 | # INPUT gives an alternative input source to AC_COMPILE_IFELSE. 23 | # 24 | # NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this 25 | # macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG. 26 | # 27 | # LICENSE 28 | # 29 | # Copyright (c) 2008 Guido U. Draheim 30 | # Copyright (c) 2011 Maarten Bosmans 31 | # 32 | # Copying and distribution of this file, with or without modification, are 33 | # permitted in any medium without royalty provided the copyright notice 34 | # and this notice are preserved. This file is offered as-is, without any 35 | # warranty. 36 | 37 | #serial 6 38 | 39 | AC_DEFUN([AX_CHECK_COMPILE_FLAG], 40 | [AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF 41 | AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl 42 | AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [ 43 | ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS 44 | _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1" 45 | AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])], 46 | [AS_VAR_SET(CACHEVAR,[yes])], 47 | [AS_VAR_SET(CACHEVAR,[no])]) 48 | _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags]) 49 | AS_VAR_IF(CACHEVAR,yes, 50 | [m4_default([$2], :)], 51 | [m4_default([$3], :)]) 52 | AS_VAR_POPDEF([CACHEVAR])dnl 53 | ])dnl AX_CHECK_COMPILE_FLAGS 54 | -------------------------------------------------------------------------------- /m4/ax/ax_check_sign.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # http://www.gnu.org/software/autoconf-archive/ax_check_sign.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_CHECK_SIGN (TYPE, [ACTION-IF-SIGNED], [ACTION-IF-UNSIGNED], [INCLUDES]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # Checks whether TYPE is signed or not. If no INCLUDES are specified, the 12 | # default includes are used. If ACTION-IF-SIGNED is given, it is 13 | # additional shell code to execute when the type is signed. If 14 | # ACTION-IF-UNSIGNED is given, it is executed when the type is unsigned. 15 | # 16 | # This macro assumes that the type exists. Therefore the existence of the 17 | # type should be checked before calling this macro. For example: 18 | # 19 | # AC_CHECK_HEADERS([wchar.h]) 20 | # AC_CHECK_TYPE([wchar_t],,[ AC_MSG_ERROR([Type wchar_t not found.]) ]) 21 | # AX_CHECK_SIGN([wchar_t], 22 | # [ AC_DEFINE(WCHAR_T_SIGNED, 1, [Define if wchar_t is signed]) ], 23 | # [ AC_DEFINE(WCHAR_T_UNSIGNED, 1, [Define if wchar_t is unsigned]) ], [ 24 | # #ifdef HAVE_WCHAR_H 25 | # #include 26 | # #endif 27 | # ]) 28 | # 29 | # LICENSE 30 | # 31 | # Copyright (c) 2008 Ville Laurikari 32 | # 33 | # Copying and distribution of this file, with or without modification, are 34 | # permitted in any medium without royalty provided the copyright notice 35 | # and this notice are preserved. This file is offered as-is, without any 36 | # warranty. 37 | 38 | #serial 6 39 | 40 | AC_DEFUN([AX_CHECK_SIGN], [ 41 | typename=`echo $1 | sed "s/@<:@^a-zA-Z0-9_@:>@/_/g"` 42 | AC_CACHE_CHECK([whether $1 is signed], ax_cv_decl_${typename}_signed, [ 43 | AC_TRY_COMPILE($4, 44 | [ int foo @<:@ 1 - 2 * !((($1) -1) < 0) @:>@ ], 45 | [ eval "ax_cv_decl_${typename}_signed=\"yes\"" ], 46 | [ eval "ax_cv_decl_${typename}_signed=\"no\"" ])]) 47 | symbolname=`echo $1 | sed "s/@<:@^a-zA-Z0-9_@:>@/_/g" | tr "a-z" "A-Z"` 48 | if eval "test \"\${ax_cv_decl_${typename}_signed}\" = \"yes\""; then 49 | $2 50 | elif eval "test \"\${ax_cv_decl_${typename}_signed}\" = \"no\""; then 51 | $3 52 | fi 53 | ]) 54 | -------------------------------------------------------------------------------- /m4/psi/psi_const.m4: -------------------------------------------------------------------------------- 1 | # psi_add_str_const(name, value) 2 | # Add a pre-defined string constant to $PSI_CONSTS_H 3 | psi_add_str_const() { 4 | PSI_CONSTS="$PSI_CONSTS 5 | {PSI_T_STRING, \"string\", \"psi\\\\$1\", {.ptr = $1}}," 6 | } 7 | 8 | # psi_add_int_const(name, value) 9 | # Add a pre-defined int constant to $PSI_CONSTS_H 10 | psi_add_int_const() { 11 | PSI_CONSTS="$PSI_CONSTS 12 | {PSI_T_INT, \"int\", \"psi\\\\$1\", {.zend.lval = (zend_long) $1}}," 13 | } 14 | 15 | dnl PSI_CONST(const name, type) 16 | dnl Check the value of a str/int constant and add it to the list of pre-defined 17 | dnl constants. 18 | AC_DEFUN(PSI_CONST, [ 19 | AC_CHECK_DECL($1, [ 20 | case $2 in 21 | str*) 22 | psi_add_str_const "$1" 23 | ;; 24 | int) 25 | psi_add_int_const "$1" 26 | ;; 27 | esac 28 | ]) 29 | ]) 30 | -------------------------------------------------------------------------------- /psi.d/arpa_inet.psi: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | function psi\htonl(int $l) : int { 4 | let l = intval($l); 5 | return htonl(l) as to_int(htonl); 6 | } 7 | function psi\htons(int $s) : int { 8 | let s = intval($s); 9 | return htons(s) as to_int(htons); 10 | } 11 | 12 | function psi\ntohl(int $l) : int { 13 | let l = intval($l); 14 | return ntohl(l) as to_int(ntohl); 15 | } 16 | function psi\ntohs(int $s) : int { 17 | let s = intval($s); 18 | return ntohs(s) as to_int(ntohs); 19 | } 20 | 21 | 22 | function psi\inet_addr(string $cp) : int { 23 | let cp = strval($cp); 24 | return inet_addr(cp) as to_int(inet_addr); 25 | } 26 | 27 | function psi\inet_ntoa(array $in) : string { 28 | let in = arrval($in, 29 | intval($s_addr) 30 | ); 31 | return inet_ntoa(in) as to_string(inet_ntoa); 32 | } 33 | 34 | function psi\inet_ntop(int $af, string $src) : string { 35 | let af = intval($af); 36 | let src = strval($src); 37 | let size = sizeof(struct sockaddr_storage); 38 | let dst = calloc(1, size); 39 | return inet_ntop(af, src, dst, size) as to_string(inet_ntop); 40 | } 41 | 42 | function psi\inet_pton(int $af, string $src, string &$dst) : int { 43 | let af = intval($af); 44 | let src = strval($src); 45 | let dst = calloc(1, sizeof(struct sockaddr_storage)); 46 | return inet_pton(af, src, dst) as to_int(inet_pton); 47 | set $dst = to_string(dst, sizeof(struct sockaddr_storage)); 48 | } 49 | -------------------------------------------------------------------------------- /psi.d/errno.psi: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifdef __GNUC__ 4 | # ifdef __linux__ 5 | function psi\errno() : int { 6 | return __errno_location() as to_int(*__errno_location); 7 | } 8 | # endif /* linux */ 9 | # ifdef __FreeBSD__ 10 | function psi\errno() : int { 11 | return __error() as to_int(*__error); 12 | } 13 | # endif /* __FreeBSD__ */ 14 | #endif /* __GNUC__ */ 15 | -------------------------------------------------------------------------------- /psi.d/getopt.psi: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | function psi\opterr(int $value) : void { 4 | let opterr = intval($value); 5 | return opterr_set(opterr) as void(opterr_set); 6 | } 7 | function psi\optind\get() : int { 8 | return optind_get() as to_int(optind_get); 9 | } 10 | function psi\optind\set(int $v) : void { 11 | let optind = intval($v); 12 | return optind_set(optind) as void(optind_set); 13 | } 14 | function psi\optopt() : int { 15 | return optopt_get() as to_int(optopt_get); 16 | } 17 | function psi\optarg() : string { 18 | return optarg_get() as to_string(optarg_get); 19 | } 20 | 21 | #ifdef _OPTRESET 22 | function psi\optreset() : void { 23 | let _v = 1; 24 | return optreset_set(_v) as void(optreset_set); 25 | } 26 | #endif 27 | 28 | static function psi\getopt(array &$argv, string $options) : int { 29 | let argc = count($argv); 30 | let argv = &arrval($argv, 31 | *argv = strval($argv) 32 | ); 33 | let optstring = strval($options); 34 | return getopt(argc, argv, optstring) as to_int(getopt); 35 | set $argv = to_array( 36 | *argv, 37 | argc, 38 | to_string(*argv) 39 | ); 40 | } 41 | -------------------------------------------------------------------------------- /psi.d/glob.psi: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | function psi\glob(string $pattern, int $flags, array &$glob = NULL, callable $errfn = NULL) : int { 4 | let path = strval($pattern); 5 | let flags = intval($flags); 6 | let err = callback( 7 | epath, 8 | eerrno 9 | ) as intval($errfn( 10 | to_string(epath), 11 | to_int(eerrno) 12 | )); 13 | let buf = &arrval($glob, 14 | intval($gl_matchc), 15 | intval($gl_pathc), 16 | intval($gl_offs), 17 | intval($gl_flags), 18 | &arrval($gl_pathv, 19 | strval($gl_pathv) 20 | ) 21 | ); 22 | return glob(path, flags, err, buf) as to_int(glob); 23 | set $glob = to_array(*buf, 24 | to_int(gl_matchc), 25 | to_int(gl_pathc), 26 | to_int(gl_offs), 27 | to_int(gl_flags), 28 | to_array(*gl_pathv, gl_pathc + gl_offs, to_string(*gl_pathv)) 29 | ); 30 | free globfree(buf); 31 | } 32 | -------------------------------------------------------------------------------- /psi.d/netdb.psi: -------------------------------------------------------------------------------- 1 | #ifdef __linux__ 2 | # pragma lib "anl" 3 | #endif 4 | 5 | #include 6 | 7 | function psi\endhostent() : void { 8 | return endhostent() as void(endhostent); 9 | } 10 | function psi\endnetent() : void { 11 | return endnetent() as void(endnetent); 12 | } 13 | function psi\endprotoent() : void { 14 | return endprotoent() as void(endprotoent); 15 | } 16 | function psi\endservent() : void { 17 | return endservent() as void(endservent); 18 | } 19 | 20 | function psi\sethostent(bool $stayopen) : void { 21 | let stayopen = intval($stayopen); 22 | return sethostent(stayopen) as void(sethostent); 23 | } 24 | function psi\setnetent(bool $stayopen) : void { 25 | let stayopen = intval($stayopen); 26 | return setnetent(stayopen) as void(setnetent); 27 | } 28 | function psi\setprotoent(bool $stayopen) : void { 29 | let stayopen = intval($stayopen); 30 | return setprotoent(stayopen) as void(setprotoent); 31 | } 32 | function psi\setservent(bool $stayopen) : void { 33 | let stayopen = intval($stayopen); 34 | return setservent(stayopen) as void(setservent); 35 | } 36 | 37 | function psi\gethostent() : array { 38 | return gethostent() as to_array(*gethostent, 39 | to_string(h_name), 40 | to_array(h_aliases, to_string(h_aliases)), 41 | to_int(h_addrtype), 42 | to_int(h_length), 43 | to_array(h_addr_list, to_string(h_addr_list, h_length)) 44 | ); 45 | } 46 | 47 | function psi\gai_strerror(int $errcode) : string { 48 | let errcode = intval($errcode); 49 | return gai_strerror(errcode) as to_string(gai_strerror); 50 | } 51 | 52 | // extern int getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) 53 | function psi\getaddrinfo(string $node, string $service, array $hints = NULL, object &$res = NULL) : int { 54 | let node = strval($node); 55 | let service = strval($service); 56 | let hints = &arrval($hints, 57 | intval($ai_flags), 58 | intval($ai_family), 59 | intval($ai_socktype), 60 | intval($ai_protocol) 61 | ); 62 | let res = &NULL; 63 | return getaddrinfo(node, service, hints, res) as to_int(getaddrinfo); 64 | set $res = to_array(**res, 65 | to_int(ai_flags), 66 | to_int(ai_family), 67 | to_int(ai_socktype), 68 | to_int(ai_protocol), 69 | to_int(ai_addrlen), 70 | to_string(ai_addr, ai_addrlen), 71 | to_string(ai_canonname), 72 | to_array(*ai_next, ...) 73 | ); 74 | free freeaddrinfo(*res); 75 | } 76 | 77 | // extern int getnameinfo(struct sockaddr *sa, socklen_t salen, char *host, socklen_t hostlen, char *serv, socklen_t servlen, int flags) 78 | function psi\getnameinfo(string $addr, string &$host = NULL, string &$service = NULL, int $flags = 0) : int { 79 | let sa = strval($addr); 80 | let salen = strlen($addr); 81 | let hostlen = NI_MAXHOST; 82 | let host = calloc(hostlen, sizeof(char)); 83 | let servlen = NI_MAXSERV; 84 | let serv = calloc(servlen, sizeof(char)); 85 | let flags = intval($flags); 86 | return getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) as to_int(getnameinfo); 87 | set $host = to_string(host); 88 | set $service = to_string(serv); 89 | } 90 | -------------------------------------------------------------------------------- /psi.d/stat.psi: -------------------------------------------------------------------------------- 1 | #include 2 | // extern int stat(char *path, struct stat *buf); 3 | function psi\stat(string $path, array &$buf = NULL) : int { 4 | let path = strval($path); 5 | let buf = calloc(1, sizeof(struct stat)); 6 | return stat(path, buf) as to_int(stat); 7 | set $buf = to_array(*buf, 8 | to_int(st_dev), 9 | to_int(st_ino), 10 | to_int(st_mode), 11 | to_int(st_nlink), 12 | to_int(st_uid), 13 | to_int(st_gid), 14 | to_int(st_rdev), 15 | to_int(st_size), 16 | to_array(st_atim, 17 | to_int(tv_sec), 18 | to_int(tv_nsec) 19 | ), 20 | to_array(st_atimespec, 21 | to_int(tv_sec), 22 | to_int(tv_nsec) 23 | ), 24 | to_array(st_mtim, 25 | to_int(tv_sec), 26 | to_int(tv_nsec) 27 | ), 28 | to_array(st_mtimespec, 29 | to_int(tv_sec), 30 | to_int(tv_nsec) 31 | ), 32 | to_array(st_ctim, 33 | to_int(tv_sec), 34 | to_int(tv_nsec) 35 | ), 36 | to_array(st_ctimespec, 37 | to_int(tv_sec), 38 | to_int(tv_nsec) 39 | ), 40 | to_array(st_birthtim, 41 | to_int(tv_sec), 42 | to_int(tv_nsec) 43 | ), 44 | to_array(st_birthtimespec, 45 | to_int(tv_sec), 46 | to_int(tv_nsec) 47 | ), 48 | to_int(st_blksize), 49 | to_int(st_blocks), 50 | to_int(st_flags), 51 | to_int(st_gen) 52 | ); 53 | } 54 | -------------------------------------------------------------------------------- /psi.d/stdio.psi: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | function psi\fopen(string $path, string $mode) : object { 4 | let path = pathval($path); 5 | let mode = strval($mode); 6 | return fopen(path, mode) 7 | as to_object(fopen); 8 | } 9 | 10 | function psi\fclose(object $stream) : int { 11 | let stream = objval($stream); 12 | return fclose(stream) as to_int(fclose); 13 | } 14 | 15 | function psi\fread(object $stream, string &$data = NULL, int $len = 1, int $n = 8192) : int { 16 | let len = intval($len); 17 | let n = intval($n); 18 | let stream = objval($stream); 19 | let buf = calloc(n, len); 20 | pre_assert stream != NULL; 21 | return fread(buf, len, n, stream) as to_int(fread); 22 | set $data = to_string(buf, fread * len); 23 | } 24 | 25 | function psi\feof(object $stream) : int { 26 | let stream = objval($stream); 27 | return feof(stream) as to_int(feof); 28 | } 29 | 30 | function psi\fileno(object $stream) : int { 31 | let stream = objval($stream); 32 | return fileno(stream) as to_int(fileno); 33 | } 34 | 35 | function psi\ferror(object $stream) : int { 36 | let stream = objval($stream); 37 | return ferror(stream) as to_int(ferror); 38 | } 39 | 40 | function psi\clearerr(object $stream) : void { 41 | let stream = objval($stream); 42 | return clearerr(stream) as void(clearerr); 43 | } 44 | 45 | function psi\fseek(object $stream, int $offset, int $whence) : int { 46 | let stream = objval($stream); 47 | let offset = intval($offset); 48 | let whence = intval($whence); 49 | return fseek(stream, offset, whence) as to_int(fseek); 50 | } 51 | 52 | function psi\ftell(object $stream) : int { 53 | let stream = objval($stream); 54 | return ftell(stream) as to_int(ftell); 55 | } 56 | 57 | function psi\rewind(object $stream) : void { 58 | let stream = objval($stream); 59 | return rewind(stream) as void(rewind); 60 | } 61 | 62 | function psi\printf(string $fmt, mixed ...$args) : int { 63 | let format = strval($fmt); 64 | return printf(format) as to_int(printf); 65 | } 66 | 67 | -------------------------------------------------------------------------------- /psi.d/stdlib.psi: -------------------------------------------------------------------------------- 1 | #ifdef __linux__ 2 | #pragma lib "crypt" 3 | #endif 4 | 5 | #include 6 | 7 | function psi\abs(int $i) : int { 8 | let n = intval($i); 9 | return abs(n) as to_int(abs); 10 | } 11 | 12 | function psi\div(int $numerator, int $denominator) : array { 13 | let numerator = intval($numerator); 14 | let denominator = intval($denominator); 15 | pre_assert denominator != 0; 16 | return div(numerator, denominator) 17 | as to_array(div, to_int(quot), to_int(rem)); 18 | } 19 | 20 | function psi\ldiv(int $numerator, int $denominator) : array { 21 | let numerator = intval($numerator); 22 | let denominator = intval($denominator); 23 | pre_assert denominator != 0; 24 | return ldiv(numerator, denominator) 25 | as to_array(ldiv, to_int(quot), to_int(rem)); 26 | } 27 | 28 | function psi\lldiv(int $numerator, int $denominator) : array { 29 | let numerator = intval($numerator); 30 | let denominator = intval($denominator); 31 | pre_assert denominator != 0; 32 | return lldiv(numerator, denominator) 33 | as to_array(lldiv, to_int(quot), to_int(rem)); 34 | } 35 | 36 | function psi\strtold(string $str, string &$end = null) : float { 37 | let nptr = strval($str); 38 | let endptr = &NULL; 39 | return strtold(nptr, endptr) 40 | as to_float(strtold); 41 | set $end = to_string(*endptr); 42 | } 43 | 44 | function psi\free(object $memory) : void { 45 | let ptr = objval($memory); 46 | return free(ptr) as void(free); 47 | } 48 | 49 | function psi\malloc(int $size) : object { 50 | let size = intval($size); 51 | pre_assert size >= 0; 52 | return malloc(size) as to_object(malloc); 53 | } 54 | 55 | function psi\calloc(int $nmemb, int $size) : object { 56 | let nmemb = intval($nmemb); 57 | let size = intval($size); 58 | pre_assert size >= 0; 59 | return calloc(nmemb, size) as to_object(calloc); 60 | } 61 | 62 | function psi\realloc(object $obj, int $size) : object { 63 | let ptr = objval($obj); 64 | let size = intval($size); 65 | pre_assert size >= 0; 66 | return realloc(ptr, size) as to_object(realloc); 67 | } 68 | -------------------------------------------------------------------------------- /psi.d/string.psi: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | function psi\strerror(int $errno) : string { 4 | let err = intval($errno); 5 | return strerror(err) as to_string(strerror); 6 | } 7 | -------------------------------------------------------------------------------- /psi.d/syslog.psi: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | function psi\openlog(string $ident, int $option, int $facility) : void { 4 | let ident = strval($ident); 5 | let option = intval($option); 6 | let facility = intval($facility); 7 | return openlog(ident, option, facility) as void(openlog); 8 | } 9 | 10 | function psi\closelog() : void { 11 | return void(closelog); 12 | } 13 | 14 | function psi\setlogmask(int $mask) : int { 15 | let mask = intval($mask); 16 | return setlogmask(mask) as to_int(setlogmask); 17 | } 18 | 19 | function psi\syslog(int $priority, string $format, mixed ...$args) : void { 20 | let priority = intval($priority); 21 | let format = strval($format); 22 | return syslog(priority, format) as void(syslog); 23 | } 24 | 25 | // redirected macro 26 | // extern int LOG_MASK(int pri); 27 | //function psi\LOG_MASK(int $pri) : int { 28 | // let pri = intval($pri); 29 | // return LOG_MASK(pri) as to_int(LOG_MASK); 30 | //} 31 | -------------------------------------------------------------------------------- /psi.d/uname.psi: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | function psi\uname(array &$u = NULL) : int { 4 | let name = calloc(1, sizeof(struct utsname)); 5 | return uname(name) as to_int(uname); 6 | set $u = to_array(*name, 7 | to_string(sysname), 8 | to_string(nodename), 9 | to_string(release), 10 | to_string(version), 11 | to_string(machine), 12 | to_string(domainname)); 13 | } 14 | -------------------------------------------------------------------------------- /scripts/_include.php: -------------------------------------------------------------------------------- 1 | "i8", 8 | "UINT8" => "u8", 9 | "INT16" => "i16", 10 | "UINT16" => "u16", 11 | "INT32" => "i32", 12 | "UINT32" => "u32", 13 | "INT64" => "i64", 14 | "UINT64" => "u64", 15 | "INT128" => "i128", 16 | "UINT128" => "u128", 17 | "FLOAT" => "fval", 18 | "DOUBLE" => "dval", 19 | "LONG_DOUBLE" => "ldval", 20 | ]; 21 | 22 | function t_is_int($t) { 23 | switch ($t{0}) { 24 | case "U": 25 | case "I": 26 | return true; 27 | default: 28 | return false; 29 | } 30 | } 31 | 32 | function t_is_special($t) { 33 | switch ($t) { 34 | case "INT128": 35 | case "UINT128": 36 | case "LONG_DOUBLE": 37 | return true; 38 | default: 39 | return false; 40 | } 41 | } 42 | 43 | ?> 44 | /******************************************************************************* 45 | Copyright (c) 2016, Michael Wallner . 46 | All rights reserved. 47 | 48 | Redistribution and use in source and binary forms, with or without 49 | modification, are permitted provided that the following conditions are met: 50 | 51 | * Redistributions of source code must retain the above copyright notice, 52 | this list of conditions and the following disclaimer. 53 | * Redistributions in binary form must reproduce the above copyright 54 | notice, this list of conditions and the following disclaimer in the 55 | documentation and/or other materials provided with the distribution. 56 | 57 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 58 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 59 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 60 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 61 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 62 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 63 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 64 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 65 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 66 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 67 | *******************************************************************************/ 68 | 69 | #include 70 | 71 | #include "token.h" -------------------------------------------------------------------------------- /scripts/gen_calc_basic.php: -------------------------------------------------------------------------------- 1 | "+", 7 | "sub" => "-", 8 | "mul" => "*", 9 | "div" => "/", 10 | ]; 11 | 12 | function t_for_res($t1, $t2) { 13 | global $types; 14 | 15 | $p = array_flip(array_keys($types)); 16 | 17 | if ($p[$t2] >= 8 || $p[$t1] >= 8) { 18 | if ($p[$t2] > $p[$t1]) { 19 | return $t2; 20 | } 21 | return $t1; 22 | } 23 | 24 | $u1 = $t1{0} === "U"; 25 | $s1 = substr($t1, $u1 ? 4 : 3); 26 | $u2 = $t2{0} === "U"; 27 | $s2 = substr($t2, $u2 ? 4 : 3); 28 | 29 | if ($u1 && $u2) { 30 | return "UINT".min(64,max($s1*2,$s2*2)); 31 | } else { 32 | return "INT".min(64,max($s1*2,$s2*2)); 33 | } 34 | 35 | } 36 | 37 | function v_for_res($t1, $t2) { 38 | global $types; 39 | 40 | return $types[t_for_res($t1, $t2)]; 41 | } 42 | 43 | ?> 44 | 45 | 46 | $op) : ?> 47 | static inline token_t psi_calc_(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) 48 | { 49 | 50 | switch (t1) { 51 | $v1) : ?> 52 | 53 | 54 | #if HAVE_ 55 | 56 | 57 | case PSI_T_: 58 | switch (t2) { 59 | $v2) : ?> 60 | 61 | 62 | # if HAVE_ 63 | 64 | 65 | case PSI_T_: 66 | res-> = v1-> v2->; 67 | return PSI_T_; 68 | 69 | 70 | # endif 71 | 72 | 73 | 74 | default: 75 | assert(0); 76 | break; 77 | } 78 | break; 79 | 80 | 81 | #endif 82 | 83 | 84 | 85 | default: 86 | assert(0); 87 | break; 88 | } 89 | 90 | return 0; 91 | } 92 | 93 | 94 | 95 | static inline token_t psi_calc_mod(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) 96 | { 97 | impl_val i1, i2; 98 | 99 | switch (t1) { 100 | $v1) : ?> 101 | 102 | 103 | #if HAVE_ 104 | 105 | 106 | case PSI_T_: 107 | i1.i64 = v1->; 108 | break; 109 | 110 | 111 | #endif 112 | 113 | 114 | 115 | default: 116 | assert(0); 117 | break; 118 | } 119 | 120 | switch (t2) { 121 | $v2) : ?> 122 | 123 | 124 | #if HAVE_ 125 | 126 | 127 | case PSI_T_: 128 | i2.i64 = v2->; 129 | break; 130 | 131 | 132 | #endif 133 | 134 | 135 | 136 | default: 137 | assert(0); 138 | break; 139 | } 140 | 141 | res->i64 = i1.i64 % i2.i64; 142 | return PSI_T_INT64; 143 | } 144 | -------------------------------------------------------------------------------- /scripts/gen_calc_bin.php: -------------------------------------------------------------------------------- 1 | "<<", 7 | "rshift" => ">>", 8 | "and" => "&", 9 | "xor" => "^", 10 | "or" => "|", 11 | ]; 12 | 13 | ?> 14 | 15 | $op) : ?> 16 | 17 | static inline token_t psi_calc_bin_(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) 18 | { 19 | impl_val i1, i2; 20 | 21 | switch (t1) { 22 | $v1) : ?> 23 | 24 | 25 | #if HAVE_ 26 | 27 | 28 | case PSI_T_: 29 | i1.u64 = v1->; 30 | break; 31 | 32 | 33 | #endif 34 | 35 | 36 | 37 | default: 38 | assert(0); 39 | break; 40 | } 41 | 42 | switch (t2) { 43 | $v2) : ?> 44 | 45 | 46 | #if HAVE_ 47 | 48 | 49 | case PSI_T_: 50 | i2.u64 = v2->; 51 | break; 52 | 53 | 54 | #endif 55 | 56 | 57 | 58 | default: 59 | assert(0); 60 | break; 61 | } 62 | 63 | res->u64 = i1.u64 i2.u64; 64 | return PSI_T_UINT64; 65 | } 66 | 67 | -------------------------------------------------------------------------------- /scripts/gen_calc_bool.php: -------------------------------------------------------------------------------- 1 | 4 | 5 | static inline token_t psi_calc_bool_or(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) 6 | { 7 | switch (t1) { 8 | $v1) : ?> 9 | 10 | 11 | #if HAVE_ 12 | 13 | 14 | case PSI_T_: 15 | if (v1->) 16 | goto return_true; 17 | break; 18 | 19 | 20 | #endif 21 | 22 | 23 | 24 | default: 25 | assert(0); 26 | break; 27 | } 28 | 29 | switch (t2) { 30 | $v2) : ?> 31 | 32 | 33 | #if HAVE_ 34 | 35 | 36 | case PSI_T_: 37 | if (v2->) 38 | goto return_true; 39 | break; 40 | 41 | 42 | #endif 43 | 44 | 45 | 46 | default: 47 | assert(0); 48 | break; 49 | } 50 | 51 | res->u8 = 0; 52 | return PSI_T_UINT8; 53 | 54 | return_true: 55 | res->u8 = 1; 56 | return PSI_T_UINT8; 57 | } 58 | 59 | static inline token_t psi_calc_bool_and(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) 60 | { 61 | switch (t1) { 62 | $v1) : ?> 63 | 64 | 65 | #if HAVE_ 66 | 67 | 68 | case PSI_T_: 69 | if (!v1->) 70 | goto return_false; 71 | break; 72 | 73 | 74 | #endif 75 | 76 | 77 | 78 | default: 79 | assert(0); 80 | break; 81 | } 82 | 83 | switch (t2) { 84 | $v2) : ?> 85 | 86 | 87 | #if HAVE_ 88 | 89 | 90 | case PSI_T_: 91 | if (!v2->) 92 | goto return_false; 93 | break; 94 | 95 | 96 | #endif 97 | 98 | 99 | 100 | default: 101 | assert(0); 102 | break; 103 | } 104 | 105 | res->u8 = 1; 106 | return PSI_T_UINT8; 107 | 108 | return_false: 109 | res->u8 = 0; 110 | return PSI_T_UINT8; 111 | } 112 | -------------------------------------------------------------------------------- /scripts/gen_calc_cast.php: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | static inline void psi_calc_cast(token_t in_type, impl_val *in_val, token_t out_type, impl_val *out_val) 7 | { 8 | switch (out_type) { 9 | $v) : ?> 10 | 11 | 12 | #if HAVE_ 13 | 14 | 15 | case PSI_T_: 16 | switch (in_type) { 17 | $v_in) : ?> 18 | 19 | 20 | # if HAVE_ 21 | 22 | 23 | case PSI_T_: 24 | out_val-> = in_val->; 25 | break; 26 | 27 | 28 | # endif 29 | 30 | 31 | 32 | default: 33 | assert(0); 34 | break; 35 | } 36 | break; 37 | 38 | 39 | #endif 40 | 41 | 42 | 43 | default: 44 | assert(0); 45 | break; 46 | } 47 | } 48 | 49 | -------------------------------------------------------------------------------- /scripts/gen_calc_cmp.php: -------------------------------------------------------------------------------- 1 | "==", 7 | "ne" => "!=", 8 | "lt" => "<", 9 | "gt" => ">", 10 | "le" => "<=", 11 | "ge" => ">=" 12 | ]; 13 | 14 | ?> 15 | 16 | $op) : ?> 17 | 18 | static inline token_t psi_calc_cmp_(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) 19 | { 20 | switch (t1) { 21 | $v1) : ?> 22 | 23 | 24 | #if HAVE_ 25 | 26 | 27 | case PSI_T_: 28 | switch (t2) { 29 | $v2) : ?> 30 | 31 | 32 | # if HAVE_ 33 | 34 | 35 | case PSI_T_: 36 | res->u8 = v1-> v2->; 37 | break; 38 | 39 | 40 | # endif 41 | 42 | 43 | 44 | default: 45 | assert(0); 46 | break; 47 | } 48 | break; 49 | 50 | 51 | #endif 52 | 53 | 54 | 55 | default: 56 | assert(0); 57 | break; 58 | } 59 | return PSI_T_UINT8; 60 | } 61 | 62 | -------------------------------------------------------------------------------- /scripts/gen_calc_oper.php: -------------------------------------------------------------------------------- 1 | 20 | 21 | 22 | static inline int psi_calc_oper(token_t op1, token_t op2) 23 | { 24 | if (PSI_T_LPAREN == op2) { 25 | return -1; 26 | } else if (PSI_T_LPAREN == op1) { 27 | return 1; 28 | } else if (op1 == op2) { 29 | return 0; 30 | } else if (!op1 || op1 == PSI_T_NUMBER) { 31 | return 1; 32 | } else if (!op2 || op2 == PSI_T_NUMBER) { 33 | return -1; 34 | } 35 | 36 | switch (op1) { 37 | $ops1) : ?> 38 | 39 | 40 | case PSI_T_: 41 | switch (op2) { 42 | $ops2) : ?> 43 | 44 | $prec2) : 48 | $ret = 1; 49 | else : 50 | $ret = -1; 51 | endif; 52 | ?> 53 | 54 | 55 | return ; 56 | 57 | 58 | 59 | case PSI_T_: 60 | 61 | 62 | 63 | return ; 64 | 65 | default: 66 | assert(0); 67 | break; 68 | } 69 | break; 70 | 71 | 72 | 73 | default: 74 | assert(0); 75 | break; 76 | } 77 | return 0; 78 | } 79 | -------------------------------------------------------------------------------- /scripts/gen_calc_unary.php: -------------------------------------------------------------------------------- 1 | 4 | 5 | static inline token_t psi_calc_minus(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) 6 | { 7 | (void) t2; 8 | (void) v2; 9 | 10 | switch (t1) { 11 | $v1) : ?> 12 | 13 | 14 | #if HAVE_ 15 | 16 | 17 | case PSI_T_: 18 | res-> = -v1->; 19 | break; 20 | 21 | 22 | #endif 23 | 24 | 25 | 26 | default: 27 | assert(0); 28 | break; 29 | } 30 | return t1; 31 | } 32 | 33 | 34 | static inline token_t psi_calc_bool_not(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) 35 | { 36 | (void) t2; 37 | (void) v2; 38 | 39 | switch (t1) { 40 | $v1) : ?> 41 | 42 | 43 | #if HAVE_ 44 | 45 | 46 | case PSI_T_: 47 | res->u8 = !v1->; 48 | break; 49 | 50 | 51 | #endif 52 | 53 | 54 | 55 | default: 56 | assert(0); 57 | break; 58 | } 59 | return PSI_T_UINT8; 60 | } 61 | 62 | 63 | static inline token_t psi_calc_bin_not(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) 64 | { 65 | impl_val i1; 66 | 67 | (void) t2; 68 | (void) v2; 69 | 70 | switch (t1) { 71 | $v1) : ?> 72 | 73 | 74 | #if HAVE_ 75 | 76 | 77 | case PSI_T_: 78 | i1.u64 = v1->; 79 | break; 80 | 81 | 82 | #endif 83 | 84 | 85 | 86 | default: 87 | assert(0); 88 | break; 89 | } 90 | 91 | res->u64 = ~i1.u64; 92 | return PSI_T_UINT64; 93 | } -------------------------------------------------------------------------------- /scripts/gen_package_xml.php: -------------------------------------------------------------------------------- 1 | ownerDocument; 5 | foreach (glob("$dir/$mask", GLOB_BRACE) as $file) { 6 | $fileNode = $doc->createElement("file"); 7 | $fileNode->setAttribute("role", $role); 8 | $fileNode->setAttribute("name", basename($file)); 9 | 10 | $node->appendChild($doc->createTextNode($indent)); 11 | $node->appendChild($fileNode); 12 | $node->appendChild($doc->createTextNode("\n")); 13 | } 14 | foreach (glob("$dir/*", GLOB_ONLYDIR) as $dir) { 15 | $dirNode = $doc->createElement("dir"); 16 | $dirNode->setAttribute("name", basename($dir)); 17 | $dirNode->appendChild($doc->createTextNode("\n")); 18 | 19 | add($dir, $mask, $role, $dirNode, "$indent "); 20 | 21 | $dirNode->appendChild($doc->createTextNode($indent)); 22 | 23 | $node->appendChild($doc->createTextNode($indent)); 24 | $node->appendChild($dirNode); 25 | $node->appendChild($doc->createTextNode("\n")); 26 | } 27 | } 28 | 29 | $doc = new DOMDocument; 30 | $doc->load(__DIR__."/../package.xml"); 31 | 32 | $m4 = $doc->createElement("dir"); 33 | $m4->setAttribute("name", "m4"); 34 | $m4->appendChild($doc->createTextNode("\n")); 35 | add(__DIR__."/../m4", "*.*", "src", $m4); 36 | $m4->appendChild($doc->createTextNode(" ")); 37 | 38 | $src = $doc->createElement("dir"); 39 | $src->setAttribute("name", "src"); 40 | $src->appendChild($doc->createTextNode("\n")); 41 | add(__DIR__."/../src", "*.{c,h,y,re,inc}", "src", $src); 42 | $src->appendChild($doc->createTextNode(" ")); 43 | 44 | $scripts = $doc->createElement("dir"); 45 | $scripts->setAttribute("name", "scripts"); 46 | $scripts->appendChild($doc->createTextNode("\n")); 47 | add(__DIR__."/../scripts", "*.*", "src", $scripts); 48 | $scripts->appendChild($doc->createTextNode(" ")); 49 | 50 | $psid = $doc->createElement("dir"); 51 | $psid->setAttribute("name", "psi.d"); 52 | $psid->appendChild($doc->createTextNode("\n")); 53 | add(__DIR__."/../psi.d", "*", "src", $psid); 54 | $psid->appendChild($doc->createTextNode(" ")); 55 | 56 | $tests = $doc->createElement("dir"); 57 | $tests->setAttribute("name", "tests"); 58 | $tests->appendChild($doc->createTextNode("\n")); 59 | add(__DIR__."/../tests", "*.{phpt,inc,psi}", "test", $tests); 60 | $tests->appendChild($doc->createTextNode(" ")); 61 | 62 | 63 | $xpath = new DOMXpath($doc); 64 | $xpath->registerNamespace("p", "http://pear.php.net/dtd/package-2.0"); 65 | $root = $xpath->query("/p:package/p:contents/p:dir[@name='/']")->item(0); 66 | 67 | $root->replaceChild($m4, 68 | $xpath->query("/p:package/p:contents/p:dir[@name='/']/p:dir[@name='m4']")->item(0)); 69 | $root->replaceChild($psid, 70 | $xpath->query("/p:package/p:contents/p:dir[@name='/']/p:dir[@name='psi.d']")->item(0)); 71 | $root->replaceChild($src, 72 | $xpath->query("/p:package/p:contents/p:dir[@name='/']/p:dir[@name='src']")->item(0)); 73 | $root->replaceChild($scripts, 74 | $xpath->query("/p:package/p:contents/p:dir[@name='/']/p:dir[@name='scripts']")->item(0)); 75 | $root->replaceChild($tests, 76 | $xpath->query("/p:package/p:contents/p:dir[@name='/']/p:dir[@name='tests']")->item(0)); 77 | 78 | $doc->save(__DIR__."/../package.xml"); -------------------------------------------------------------------------------- /scripts/gen_travis_yml.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | # autogenerated file; do not edit 3 | language: c 4 | sudo: required 5 | dist: bionic 6 | 7 | addons: 8 | apt: 9 | packages: 10 | - php-cli 11 | - php-pear 12 | - valgrind 13 | - gdb 14 | - apport 15 | - re2c 16 | - libidn11-dev 17 | - libsqlite3-dev 18 | - libgdbm-dev 19 | - libgdbm-compat-dev 20 | 21 | env: 22 | matrix: 23 | ["master"], 28 | "enable_debug", 29 | #"enable_maintainer_zts", 30 | "enable_psi" => ["yes"], 31 | "enable_psi_threaded_parser", 32 | ]); 33 | foreach ($env as $e) { 34 | printf(" - %s\n", $e); 35 | } 36 | 37 | ?> 38 | 39 | before_install: 40 | # make sure we do not try to regenerate files with broken bison or old re2c 41 | - touch src/parser_proc_grammar.y 42 | - touch src/parser_proc.c 43 | - touch src/parser_proc.h 44 | - touch src/parser_scan.re 45 | - touch src/parser_scan.c 46 | - touch src/parser.h 47 | 48 | install: 49 | - make -f travis/pecl/Makefile php 50 | 51 | before_script: 52 | - ulimit -c unlimited -S 53 | - export TEST_PHP_ARGS="--no-clean" 54 | 55 | script: 56 | - make -f travis/pecl/Makefile ext PECL=psi 57 | - make -f travis/pecl/Makefile test 58 | 59 | after_failure: 60 | - cat config.log | curl -F 'sprunge=<-' http://sprunge.us 61 | - cat tests/parser/dump001.psi | curl -F 'sprunge=<-' http://sprunge.us 62 | - test -f core* && gdb -q -ex bt --batch $HOME/job-$TRAVIS_JOB_NUMBER/bin/php core* 63 | 64 | notifications: 65 | webhooks: 66 | urls: 67 | - https://webhooks.gitter.im/e/30aebb6c0b03f1117817 68 | on_success: change 69 | on_failure: always 70 | on_start: never 71 | -------------------------------------------------------------------------------- /src/builtin.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2018, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_BUILTIN_H 27 | #define PSI_BUILTIN_H 28 | 29 | struct psi_cpp; 30 | struct psi_plist; 31 | struct psi_token; 32 | 33 | struct psi_builtin { 34 | zend_string *name; 35 | bool (*func)(struct psi_cpp *cpp, struct psi_token *target, struct psi_plist **args_list, struct psi_plist **res); 36 | struct psi_cpp_macro_decl *decl; 37 | }; 38 | 39 | bool psi_builtin_exists(zend_string *name); 40 | struct psi_builtin *psi_builtin_get(zend_string *name); 41 | 42 | uint16_t psi_swap16(uint16_t u); 43 | uint32_t psi_swap32(uint32_t u); 44 | uint64_t psi_swap64(uint64_t u); 45 | 46 | #endif /* PSI_BUILTIN_H */ 47 | -------------------------------------------------------------------------------- /src/calc.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_CALC_H 27 | #define PSI_CALC_H 28 | 29 | #include "token.h" 30 | #include "types/impl_val.h" 31 | 32 | #include 33 | 34 | #define PRIfmt_digits(digits) #digits 35 | #define PRIfmt(digits, fmt) "." PRIfmt_digits(digits) fmt 36 | #define PRIfval PRIfmt(FLT_DECIMAL_DIG, "g") 37 | #define PRIdval PRIfmt(DBL_DECIMAL_DIG, "g") 38 | #if HAVE_LONG_DOUBLE 39 | # define PRIldval PRIfmt(LDBL_DECIMAL_DIG, "Lg") 40 | #endif 41 | 42 | typedef token_t (*psi_calc)(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res); 43 | 44 | #include "calc/basic.h" 45 | #include "calc/bin.h" 46 | #include "calc/bool.h" 47 | #include "calc/unary.h" 48 | #include "calc/cast.h" 49 | #include "calc/cmp.h" 50 | #include "calc/oper.h" 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/debug.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2018, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifdef HAVE_CONFIG_H 27 | # include "config.h" 28 | #else 29 | # include "php_config.h" 30 | #endif 31 | 32 | #include "php.h" 33 | #include "debug.h" 34 | 35 | #if PSI_THREADED_PARSER 36 | 37 | # include 38 | 39 | static pthread_mutex_t debug_mutex; 40 | static pthread_mutexattr_t debug_attr; 41 | 42 | void psi_debug_lock(struct psi_data *data) 43 | { 44 | pthread_mutex_lock(&debug_mutex); 45 | } 46 | 47 | void psi_debug_unlock(struct psi_data *data) 48 | { 49 | pthread_mutex_unlock(&debug_mutex); 50 | } 51 | 52 | #endif 53 | 54 | PHP_MINIT_FUNCTION(psi_debug); 55 | PHP_MINIT_FUNCTION(psi_debug) 56 | { 57 | #if PSI_THREADED_PARSER 58 | pthread_mutexattr_init(&debug_attr); 59 | pthread_mutexattr_settype(&debug_attr, PTHREAD_MUTEX_RECURSIVE); 60 | pthread_mutex_init(&debug_mutex, &debug_attr); 61 | #endif 62 | 63 | return 0; 64 | } 65 | 66 | PHP_MSHUTDOWN_FUNCTION(psi_debug); 67 | PHP_MSHUTDOWN_FUNCTION(psi_debug) 68 | { 69 | #if PSI_THREADED_PARSER 70 | pthread_mutex_destroy(&debug_mutex); 71 | pthread_mutexattr_destroy(&debug_attr); 72 | #endif 73 | 74 | return 0; 75 | } 76 | -------------------------------------------------------------------------------- /src/debug.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2018, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_DEBUG_H 27 | #define PSI_DEBUG_H 28 | 29 | #include 30 | #include 31 | 32 | #include "data.h" 33 | 34 | #if PSI_THREADED_PARSER 35 | void psi_debug_lock(struct psi_data *data); 36 | void psi_debug_unlock(struct psi_data *data); 37 | #else 38 | # define psi_debug_lock(ctx) 39 | # define psi_debug_unlock(ctx) 40 | #endif 41 | 42 | #define PSI_DEBUG_LOCK(ctx, group_actions) do { \ 43 | if ((ctx) && (PSI_DATA(ctx)->flags & PSI_DEBUG)) { \ 44 | psi_debug_lock(PSI_DATA(ctx)); \ 45 | group_actions; \ 46 | psi_debug_unlock(PSI_DATA(ctx)); \ 47 | } \ 48 | } while(0) 49 | 50 | #define PSI_DEBUG_PRINT(ctx, ...) do { \ 51 | if ((ctx) && (PSI_DATA(ctx)->flags & PSI_DEBUG)) { \ 52 | psi_debug_lock(PSI_DATA(ctx)); \ 53 | dprintf(PSI_DATA(ctx)->debug_fd, __VA_ARGS__); \ 54 | psi_debug_unlock(PSI_DATA(ctx)); \ 55 | } \ 56 | } while(0) 57 | 58 | #define PSI_DEBUG_PRINTV(ctx, msg, argv) do { \ 59 | if ((ctx) && (PSI_DATA(ctx)->flags & PSI_DEBUG)) { \ 60 | psi_debug_lock(PSI_DATA(ctx)); \ 61 | vdprintf(PSI_DATA(ctx)->debug_fd, msg, argv); \ 62 | psi_debug_unlock(PSI_DATA(ctx)); \ 63 | } \ 64 | } while(0) 65 | 66 | #define PSI_DEBUG_DUMP(ctx, dump_func, ...) do { \ 67 | if ((ctx) && (PSI_DATA(ctx)->flags & PSI_DEBUG)) { \ 68 | struct psi_dump dump_ = {{ .fd = PSI_DATA(ctx)->debug_fd}, \ 69 | .fun = (psi_dump_cb) dprintf}; \ 70 | psi_debug_lock(PSI_DATA(ctx)); \ 71 | dump_func(&dump_, __VA_ARGS__); \ 72 | psi_debug_unlock(PSI_DATA(ctx)); \ 73 | } \ 74 | } while (0) 75 | 76 | #endif /* PSI_DEBUG_H */ 77 | -------------------------------------------------------------------------------- /src/dl.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2018, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_DLSYM_H 27 | #define PSI_DLSYM_H 28 | 29 | #include 30 | #include 31 | 32 | #ifndef RTLD_NEXT 33 | # define RTLD_NEXT ((void *) -1l) 34 | #endif 35 | #ifndef RTLD_DEFAULT 36 | # define RTLD_DEFAULT ((void *) 0) 37 | #endif 38 | 39 | #include "plist.h" 40 | 41 | static inline void *psi_dlsym(struct psi_plist *dllist, const char *name, const char *redir) 42 | { 43 | void *dl, *sym = NULL; 44 | const char *test = redir ?: name; 45 | 46 | again: 47 | if (dllist) { 48 | size_t i = 0; 49 | 50 | while (!sym && psi_plist_get(dllist, i++, &dl)) { 51 | sym = dlsym(dl, test); 52 | } 53 | } 54 | if (!sym) { 55 | sym = dlsym(RTLD_DEFAULT, test); 56 | } 57 | if (!sym && test == redir) { 58 | test = name; 59 | goto again; 60 | } 61 | 62 | return sym; 63 | } 64 | 65 | static inline size_t psi_dlname(char (*buf)[], size_t *len, const char *libname) 66 | { 67 | if (strchr(libname, '/')) { 68 | return snprintf(*buf, *len, "%s", libname); 69 | } else { 70 | return snprintf(*buf, *len, "lib%s.%s", libname, PHP_PSI_SHLIB_SUFFIX); 71 | } 72 | } 73 | 74 | static inline void *psi_dlopen(const char *libname) 75 | { 76 | return dlopen(libname, RTLD_LAZY | RTLD_LOCAL); 77 | } 78 | 79 | static inline void psi_dlclose(void *dl) 80 | { 81 | dlclose(dl); 82 | } 83 | 84 | static inline char *psi_dlerror() 85 | { 86 | return dlerror(); 87 | } 88 | 89 | #endif /* PSI_DLSYM_H */ 90 | -------------------------------------------------------------------------------- /src/dump.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2018, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifdef HAVE_CONFIG_H 27 | # include "config.h" 28 | #else 29 | # include "php_config.h" 30 | #endif 31 | 32 | #include "dump.h" 33 | 34 | const struct psi_dump psi_dump_stdout = { 35 | .ctx.fd = STDOUT_FILENO, 36 | .fun = (psi_dump_cb) dprintf 37 | }; 38 | 39 | const struct psi_dump psi_dump_stderr = { 40 | .ctx.fd = STDERR_FILENO, 41 | .fun = (psi_dump_cb) dprintf 42 | }; 43 | 44 | void psi_smart_str_printf(smart_str *ss, const char *fmt, ...) 45 | { 46 | va_list argv; 47 | char *buf; 48 | int len; 49 | 50 | va_start(argv, fmt); 51 | len = vasprintf(&buf, fmt, argv); 52 | va_end(argv); 53 | 54 | if (len != -1) { 55 | smart_str_appendl_ex(ss, buf, len, 1); 56 | free(buf); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/dump.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2018, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_DUMP_H 27 | #define PSI_DUMP_H 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #include 34 | 35 | union psi_dump_arg { 36 | void *hn; 37 | int fd; 38 | }; 39 | 40 | typedef int (*psi_dump_cb)(union psi_dump_arg, const char *msg, ...); 41 | 42 | struct psi_dump { 43 | union psi_dump_arg ctx; 44 | psi_dump_cb fun; 45 | }; 46 | 47 | extern const struct psi_dump psi_dump_stdout; 48 | extern const struct psi_dump psi_dump_stderr; 49 | 50 | #define PSI_DUMP(dump, ...) do { \ 51 | const struct psi_dump *_dump_ptr = dump; \ 52 | if (!_dump_ptr) { \ 53 | _dump_ptr = &psi_dump_stderr; \ 54 | } \ 55 | _dump_ptr->fun(_dump_ptr->ctx, __VA_ARGS__); \ 56 | } while(0) 57 | 58 | #if PSI_THREADED_PARSER 59 | void psi_smart_str_printf(smart_str *ss, const char *fmt, ...); 60 | #else 61 | # define psi_smart_str_printf smart_str_append_printf 62 | #endif 63 | 64 | 65 | #endif /* PSI_DUMP_H */ 66 | -------------------------------------------------------------------------------- /src/error.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_ERROR_H 27 | #define PSI_ERROR_H 28 | 29 | #include 30 | 31 | #define PSI_ERROR 16 32 | #define PSI_WARNING 32 33 | #define PSI_NOTICE 1024 34 | 35 | struct psi_data; 36 | struct psi_token; 37 | 38 | typedef void (*psi_error_cb)(struct psi_data *context, struct psi_token *token, int type, const char *msg, ...); 39 | 40 | void psi_error_wrapper(struct psi_data *context, struct psi_token *t, int type, const char *msg, ...); 41 | void psi_error(int type, const char *fn, unsigned ln, const char *msg, ...); 42 | void psi_verror(int type, const char *fn, unsigned ln, const char *msg, va_list argv); 43 | 44 | #endif /* PSI_ERROR_H */ 45 | -------------------------------------------------------------------------------- /src/libffi.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_LIBFFI_H 27 | #define PSI_LIBFFI_H 28 | 29 | #include "context.h" 30 | 31 | #ifdef HAVE_LIBFFI 32 | struct psi_context_ops *psi_libffi_ops(void); 33 | #endif 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /src/libjit.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_LIBJIT_H 27 | #define PSI_LIBJIT_H 28 | 29 | #include "context.h" 30 | 31 | #ifdef HAVE_LIBJIT 32 | struct psi_context_ops *psi_libjit_ops(void); 33 | #endif 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /src/parser.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_PARSER_H 27 | #define PSI_PARSER_H 28 | 29 | struct psi_parser; 30 | 31 | #include "parser_proc.h" 32 | #undef YYDEBUG 33 | 34 | #include "data.h" 35 | #include "token.h" 36 | #include "types.h" 37 | #include "cpp.h" 38 | 39 | struct psi_cpp; 40 | 41 | struct psi_parser_input { 42 | size_t length; 43 | zend_string *file; 44 | time_t lmod; 45 | char buffer[1]; 46 | }; 47 | 48 | struct psi_parser { 49 | PSI_DATA_MEMBERS; 50 | 51 | struct psi_cpp *preproc; 52 | struct psi_parser_input *input; 53 | }; 54 | 55 | static inline void psi_parser_input_free(struct psi_parser_input **I) { 56 | if (*I) { 57 | struct psi_parser_input *i = *I; 58 | 59 | *I = NULL; 60 | zend_string_release(i->file); 61 | free(i); 62 | } 63 | } 64 | 65 | struct psi_parser *psi_parser_init(struct psi_parser *P, psi_error_cb error, unsigned flags); 66 | struct psi_parser_input *psi_parser_open_file(struct psi_parser *P, const char *filename, bool report_errors); 67 | struct psi_parser_input *psi_parser_open_string(struct psi_parser *P, const char *string, size_t length); 68 | size_t psi_parser_maxfill(void); 69 | struct psi_plist *psi_parser_scan(struct psi_parser *P, struct psi_parser_input *I); 70 | struct psi_plist *psi_parser_preprocess(struct psi_parser *P, struct psi_plist **tokens); 71 | void psi_parser_postprocess(struct psi_parser *P); 72 | bool psi_parser_process(struct psi_parser *P, struct psi_plist *tokens, size_t *processed); 73 | bool psi_parser_parse(struct psi_parser *P, struct psi_parser_input *I); 74 | void psi_parser_dtor(struct psi_parser *P); 75 | void psi_parser_free(struct psi_parser **P); 76 | 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /src/types/assert_stmt.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2017, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_TYPES_ASSERT_STMT_H 27 | #define PSI_TYPES_ASSERT_STMT_H 28 | 29 | struct psi_token; 30 | struct psi_data; 31 | struct psi_impl; 32 | struct psi_num_exp; 33 | struct psi_call_frame; 34 | 35 | enum psi_assert_kind { 36 | PSI_ASSERT_PRE = PSI_T_PRE_ASSERT, 37 | PSI_ASSERT_POST = PSI_T_POST_ASSERT 38 | }; 39 | 40 | struct psi_assert_stmt { 41 | struct psi_token *token; 42 | struct psi_num_exp *exp; 43 | enum psi_assert_kind kind; 44 | }; 45 | 46 | struct psi_assert_stmt *psi_assert_stmt_init(enum psi_assert_kind kind, struct psi_num_exp *exp); 47 | bool psi_assert_stmt_exec(struct psi_assert_stmt *stmt, struct psi_call_frame *frame); 48 | 49 | void psi_assert_stmt_dump(struct psi_dump *dump, struct psi_assert_stmt *stmt); 50 | void psi_assert_stmt_free(struct psi_assert_stmt **stmt); 51 | 52 | bool psi_assert_stmts_validate(struct psi_data *data, struct psi_validate_scope *scope); 53 | 54 | void psi_assert_stmt_throw(struct psi_assert_stmt *stmt); 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /src/types/const.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifdef HAVE_CONFIG_H 27 | # include "config.h" 28 | #else 29 | # include "php_config.h" 30 | #endif 31 | #include "data.h" 32 | 33 | struct psi_const *psi_const_init(struct psi_impl_type *type, zend_string *name, 34 | struct psi_impl_def_val *val) 35 | { 36 | struct psi_const *c = pecalloc(1, sizeof(*c), 1); 37 | 38 | if (name->val[0] == '\\') { 39 | c->name = zend_string_init(&name->val[1], name->len-1, 1); 40 | } else { 41 | c->name = zend_string_copy(name); 42 | } 43 | c->type = type; 44 | c->val = val; 45 | return c; 46 | } 47 | 48 | void psi_const_free(struct psi_const **constant_ptr) 49 | { 50 | if (*constant_ptr) { 51 | struct psi_const *constant = *constant_ptr; 52 | 53 | *constant_ptr = NULL; 54 | psi_token_free(&constant->token); 55 | psi_impl_type_free(&constant->type); 56 | zend_string_release(constant->name); 57 | psi_impl_def_val_free(&constant->val); 58 | free(constant); 59 | } 60 | } 61 | 62 | void psi_const_dump(struct psi_dump *dump, struct psi_const *cnst) 63 | { 64 | PSI_DUMP(dump, "const "); 65 | if (cnst->type) { 66 | psi_impl_type_dump(dump, cnst->type); 67 | } 68 | PSI_DUMP(dump, " %s = ", cnst->name->val); 69 | psi_impl_def_val_dump(dump, cnst->val); 70 | PSI_DUMP(dump, ";"); 71 | } 72 | 73 | bool psi_const_validate(struct psi_data *data, struct psi_const *c, 74 | struct psi_validate_scope *scope) 75 | { 76 | if (!psi_impl_def_val_validate(data, c->val, c->type, scope)) { 77 | return false; 78 | } 79 | return true; 80 | } 81 | -------------------------------------------------------------------------------- /src/types/const.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_TYPES_CONST_H 27 | #define PSI_TYPES_CONST_H 28 | 29 | struct psi_data; 30 | struct psi_token; 31 | struct psi_impl_type; 32 | struct psi_impl_def_val; 33 | 34 | struct psi_const { 35 | struct psi_token *token; 36 | struct psi_impl_type *type; 37 | zend_string *name; 38 | struct psi_impl_def_val *val; 39 | }; 40 | 41 | struct psi_const *psi_const_init(struct psi_impl_type *type, zend_string *name, 42 | struct psi_impl_def_val *val); 43 | void psi_const_free(struct psi_const **constant_ptr); 44 | void psi_const_dump(struct psi_dump *dump, struct psi_const *cnst); 45 | bool psi_const_validate(struct psi_data *data, struct psi_const *c, 46 | struct psi_validate_scope *scope); 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /src/types/cpp_exp.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2017, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_TYPES_CPP_EXP_H 27 | #define PSI_TYPES_CPP_EXP_H 28 | 29 | #include "token.h" 30 | 31 | struct psi_cpp; 32 | struct psi_cpp_macro_decl; 33 | struct psi_cpp_macro_call; 34 | struct psi_num_exp; 35 | 36 | struct psi_cpp_exp { 37 | struct psi_token *token; 38 | token_t type; 39 | union { 40 | struct psi_cpp_macro_decl *decl; 41 | struct psi_num_exp *num; 42 | struct psi_token *tok; 43 | } data; 44 | }; 45 | 46 | struct psi_cpp_exp *psi_cpp_exp_init(token_t type, void *data); 47 | void psi_cpp_exp_free(struct psi_cpp_exp **exp_ptr); 48 | void psi_cpp_exp_dump(struct psi_dump *dump, struct psi_cpp_exp *exp); 49 | void psi_cpp_exp_exec(struct psi_cpp_exp *exp, struct psi_cpp *cpp, struct psi_data *D); 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /src/types/cpp_macro_call.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2017, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef CPP_MACRO_CALL_H 27 | #define CPP_MACRO_CALL_H 28 | 29 | struct psi_token; 30 | struct psi_plist; 31 | 32 | #include "builtin.h" 33 | 34 | struct psi_cpp_macro_call { 35 | struct psi_token *token; 36 | zend_string *name; 37 | struct psi_plist *args; 38 | struct psi_builtin *builtin; 39 | }; 40 | 41 | struct psi_cpp_macro_call *psi_cpp_macro_call_init(zend_string *name, 42 | struct psi_plist *args); 43 | struct psi_cpp_macro_call *psi_cpp_macro_call_copy( 44 | struct psi_cpp_macro_call *call); 45 | void psi_cpp_macro_call_free(struct psi_cpp_macro_call **call_ptr); 46 | void psi_cpp_macro_call_dump(struct psi_dump *dump, struct psi_cpp_macro_call *call); 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /src/types/cpp_macro_decl.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2017, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_TYPES_CPP_MACRO_DECL_H 27 | #define PSI_TYPES_CPP_MACRO_DECL_H 28 | 29 | struct psi_token; 30 | struct psi_plist; 31 | struct psi_num_exp; 32 | 33 | struct psi_cpp_macro_decl { 34 | struct psi_token *token; 35 | struct psi_num_exp *exp; 36 | struct psi_plist *sig; 37 | struct psi_plist *tokens; 38 | }; 39 | 40 | struct psi_cpp_macro_decl *psi_cpp_macro_decl_init(struct psi_plist *sig, 41 | struct psi_plist *tokens, struct psi_num_exp *exp); 42 | void psi_cpp_macro_decl_free(struct psi_cpp_macro_decl **macro_ptr); 43 | void psi_cpp_macro_decl_dump(struct psi_dump *dump, struct psi_cpp_macro_decl *decl); 44 | bool psi_cpp_macro_decl_equal(struct psi_cpp_macro_decl *d1, struct psi_cpp_macro_decl *d2); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /src/types/decl.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_TYPES_DECL_H 27 | #define PSI_TYPES_DECL_H 28 | 29 | struct psi_data; 30 | struct psi_plist; 31 | struct psi_decl_abi; 32 | struct psi_decl_arg; 33 | 34 | struct psi_decl { 35 | struct psi_decl_abi *abi; 36 | struct psi_decl_arg *func; 37 | struct psi_plist *args; 38 | zend_string *redir; 39 | void *sym; 40 | void *info; 41 | void *type; 42 | unsigned varargs:1; 43 | unsigned extvar:1; 44 | }; 45 | 46 | struct psi_decl *psi_decl_init(struct psi_decl_arg *func, struct psi_plist *args); 47 | void psi_decl_free(struct psi_decl **d_ptr); 48 | void psi_decl_dump(struct psi_dump *dump, struct psi_decl *decl); 49 | 50 | bool psi_decl_validate(struct psi_data *data, struct psi_decl *decl, struct psi_validate_scope *scope); 51 | bool psi_decl_validate_nodl(struct psi_data *data, struct psi_decl *decl, struct psi_validate_scope *scope); 52 | 53 | struct psi_decl_arg *psi_decl_get_arg(struct psi_decl *decl, struct psi_decl_var *var); 54 | 55 | bool psi_decl_is_blacklisted(const char *name); 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /src/types/decl_abi.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifdef HAVE_CONFIG_H 27 | # include "config.h" 28 | #else 29 | # include "php_config.h" 30 | #endif 31 | #include "data.h" 32 | 33 | struct psi_decl_abi *psi_decl_abi_init(zend_string *convention) 34 | { 35 | struct psi_decl_abi *abi = pecalloc(1, sizeof(*abi), 1); 36 | abi->convention = convention 37 | ? zend_string_copy(convention) 38 | : psi_string_init_interned(ZEND_STRL("default"), 1); 39 | return abi; 40 | } 41 | 42 | void psi_decl_abi_free(struct psi_decl_abi **abi_ptr) 43 | { 44 | if (*abi_ptr) { 45 | struct psi_decl_abi *abi = *abi_ptr; 46 | 47 | *abi_ptr = NULL; 48 | psi_token_free(&abi->token); 49 | zend_string_release(abi->convention); 50 | free(abi); 51 | } 52 | } 53 | 54 | void psi_decl_abi_dump(struct psi_dump *dump, struct psi_decl_abi *abi) 55 | { 56 | PSI_DUMP(dump, "%s", abi->convention->val); 57 | } 58 | 59 | static const char * const abi_ccs[] = { 60 | "default", /* \ */ 61 | "extern", /* > - all the same */ 62 | "cdecl", /* / */ 63 | "stdcall", 64 | "fastcall", 65 | }; 66 | 67 | bool psi_decl_abi_validate(struct psi_data *data, struct psi_decl_abi *abi) 68 | { 69 | size_t i; 70 | 71 | for (i = 0; i < sizeof(abi_ccs) / sizeof(char *); ++i) { 72 | if (!strcasecmp(abi->convention->val, abi_ccs[i])) { 73 | return true; 74 | } 75 | } 76 | return false; 77 | } 78 | -------------------------------------------------------------------------------- /src/types/decl_abi.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_TYPES_DECL_ABI_H 27 | #define PSI_TYPES_DECL_ABI_H 28 | 29 | struct psi_token; 30 | struct psi_data; 31 | 32 | struct psi_decl_abi { 33 | struct psi_token *token; 34 | zend_string *convention; 35 | }; 36 | 37 | struct psi_decl_abi *psi_decl_abi_init(zend_string *convention); 38 | void psi_decl_abi_free(struct psi_decl_abi **abi_ptr); 39 | void psi_decl_abi_dump(struct psi_dump *dump, struct psi_decl_abi *abi); 40 | bool psi_decl_abi_validate(struct psi_data *data, struct psi_decl_abi *abi); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/types/decl_arg.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | *Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | *Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_TYPES_DECL_ARG_H 27 | #define PSI_TYPES_DECL_ARG_H 28 | 29 | struct psi_data; 30 | struct psi_token; 31 | struct psi_plist; 32 | struct psi_decl_type; 33 | struct psi_decl_var; 34 | struct psi_layout; 35 | struct psi_validate_scope; 36 | 37 | struct psi_decl_arg { 38 | struct psi_token *token; 39 | struct psi_decl_type *type; 40 | struct psi_decl_var *var; 41 | struct psi_layout *layout; 42 | struct { 43 | void *info; 44 | void *type; 45 | } engine; 46 | }; 47 | 48 | struct psi_decl_arg *psi_decl_arg_init(struct psi_decl_type *type, struct psi_decl_var *var); 49 | void psi_decl_arg_free(struct psi_decl_arg **arg_ptr); 50 | void psi_decl_arg_dump(struct psi_dump *dump, struct psi_decl_arg *arg, unsigned level); 51 | 52 | bool psi_decl_arg_validate(struct psi_data *data, struct psi_decl_arg *arg, struct psi_validate_scope *scope); 53 | bool psi_decl_arg_validate_typedef(struct psi_data *data, struct psi_decl_arg *def, struct psi_validate_scope *scope); 54 | 55 | bool psi_decl_arg_is_pointer(struct psi_decl_arg *darg); 56 | 57 | size_t psi_decl_arg_align(struct psi_decl_arg *darg, size_t *pos, size_t *len); 58 | size_t psi_decl_arg_get_align(struct psi_decl_arg *darg); 59 | size_t psi_decl_arg_get_size(struct psi_decl_arg *darg); 60 | 61 | struct psi_decl_arg *psi_decl_arg_get_by_name(struct psi_plist *args, zend_string *name); 62 | struct psi_decl_arg *psi_decl_arg_get_by_var(struct psi_decl_var *var, struct psi_plist *args, struct psi_decl_arg *func); 63 | 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /src/types/decl_enum.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_TYPES_DECL_ENUM_H 27 | #define PSI_TYPES_DECL_ENUM_H 28 | 29 | struct psi_data; 30 | struct psi_token; 31 | struct psi_plist; 32 | 33 | struct psi_decl_enum { 34 | struct psi_token *token; 35 | zend_string *name; 36 | struct psi_plist *items; 37 | }; 38 | 39 | struct psi_decl_enum *psi_decl_enum_init(zend_string *name, struct psi_plist *l); 40 | void psi_decl_enum_free(struct psi_decl_enum **e_ptr); 41 | void psi_decl_enum_dump(struct psi_dump *dump, struct psi_decl_enum *e, unsigned level); 42 | bool psi_decl_enum_validate(struct psi_data *data, struct psi_decl_enum *e); 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /src/types/decl_enum_item.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_TYPES_DECL_ENUM_ITEM_H 27 | #define PSI_TYPES_DECL_ENUM_ITEM_H 28 | 29 | struct psi_data; 30 | struct psi_token; 31 | struct psi_num_exp; 32 | struct psi_decl_enum; 33 | 34 | struct psi_decl_enum_item { 35 | struct psi_token *token; 36 | zend_string *name; 37 | int64_t val; 38 | struct psi_num_exp inc; 39 | struct psi_num_exp *num; 40 | struct psi_decl_enum_item *prev; 41 | }; 42 | 43 | struct psi_decl_enum_item *psi_decl_enum_item_init(zend_string *name, struct psi_num_exp *num); 44 | void psi_decl_enum_item_free(struct psi_decl_enum_item **i_ptr); 45 | void psi_decl_enum_item_dump(struct psi_dump *dump, struct psi_decl_enum_item *item); 46 | bool psi_decl_enum_item_validate(struct psi_data *data, struct psi_decl_enum *enm, struct psi_decl_enum_item *item, size_t seq); 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /src/types/decl_extvar.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2017, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_TYPES_DECL_EXTVAR_H 27 | #define PSI_TYPES_DECL_EXTVAR_H 28 | 29 | struct psi_data; 30 | struct psi_token; 31 | struct psi_decl; 32 | struct psi_decl_arg; 33 | 34 | struct psi_decl_extvar { 35 | struct psi_token *token; 36 | struct psi_decl_arg *arg; 37 | struct psi_decl *getter; 38 | struct psi_decl *setter; 39 | size_t size; 40 | zend_string *redir; 41 | void *sym; 42 | void *info; 43 | }; 44 | 45 | struct psi_decl_extvar *psi_decl_extvar_init(struct psi_decl_arg *arg); 46 | void psi_decl_extvar_free(struct psi_decl_extvar **evar); 47 | bool psi_decl_extvar_validate(struct psi_data *data, struct psi_decl_extvar *evar, 48 | struct psi_validate_scope *scope); 49 | void psi_decl_extvar_dump(struct psi_dump *dump, struct psi_decl_extvar *evar); 50 | 51 | bool psi_decl_extvar_is_blacklisted(const char *name); 52 | 53 | struct psi_decl *psi_decl_extvar_setter(struct psi_decl_extvar *evar); 54 | void psi_decl_extvar_set(struct psi_decl_extvar *evar, void *ptr); 55 | struct psi_decl *psi_decl_extvar_getter(struct psi_decl_extvar *evar); 56 | void psi_decl_extvar_get(struct psi_decl_extvar *evar, void *ptr); 57 | 58 | #endif /* PSI_TYPES_DECL_EXTVAR_H */ 59 | -------------------------------------------------------------------------------- /src/types/decl_file.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_TYPES_DECL_FILE_H 27 | #define PSI_TYPES_DECL_FILE_H 28 | 29 | struct psi_data; 30 | 31 | struct psi_decl_file { 32 | zend_string *filename; 33 | struct psi_plist *libnames; 34 | struct psi_plist *dlopened; 35 | }; 36 | 37 | void psi_decl_file_dtor(struct psi_decl_file *file); 38 | bool psi_decl_file_validate(struct psi_data *dst, struct psi_data *src); 39 | 40 | void psi_libs_free(void **dlopened); 41 | void psi_names_free(zend_string **name); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/types/decl_struct.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_TYPES_DECL_STRUCT_H 27 | #define PSI_TYPES_DECL_STRUCT_H 28 | 29 | struct psi_data; 30 | struct psi_token; 31 | struct psi_plist; 32 | struct psi_decl_var; 33 | struct psi_validate_scope; 34 | 35 | struct psi_decl_struct { 36 | struct psi_token *token; 37 | zend_string *name; 38 | struct psi_plist *args; 39 | size_t size; 40 | size_t align; 41 | }; 42 | 43 | struct psi_decl_struct *psi_decl_struct_init(zend_string *name, struct psi_plist *args); 44 | void psi_decl_struct_free(struct psi_decl_struct **s_ptr); 45 | void psi_decl_struct_dump(struct psi_dump *dump, struct psi_decl_struct *strct); 46 | 47 | bool psi_decl_struct_validate(struct psi_data *data, struct psi_decl_struct *s, struct psi_validate_scope *scope); 48 | 49 | struct psi_decl_arg *psi_decl_struct_get_arg(struct psi_decl_struct *s, struct psi_decl_var *var); 50 | size_t psi_decl_struct_get_align(struct psi_decl_struct *s); 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/types/decl_union.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | #ifndef PSI_TYPES_DECL_UNION_H 26 | #define PSI_TYPES_DECL_UNION_H 27 | 28 | struct psi_data; 29 | struct psi_token; 30 | struct psi_plist; 31 | struct psi_decl_var; 32 | struct psi_validate_scope; 33 | 34 | struct psi_decl_union { 35 | struct psi_token *token; 36 | zend_string *name; 37 | struct psi_plist *args; 38 | size_t size; 39 | size_t align; 40 | }; 41 | 42 | struct psi_decl_union *psi_decl_union_init(zend_string *name, struct psi_plist *args); 43 | void psi_decl_union_free(struct psi_decl_union **u_ptr); 44 | void psi_decl_union_dump(struct psi_dump *dump, struct psi_decl_union *unn); 45 | 46 | bool psi_decl_union_validate(struct psi_data *data, struct psi_decl_union *u, struct psi_validate_scope *scope); 47 | 48 | size_t psi_decl_union_get_align(struct psi_decl_union *u); 49 | struct psi_decl_arg *psi_decl_union_get_arg(struct psi_decl_union *u, struct psi_decl_var *var); 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /src/types/decl_var.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_TYPES_DECL_VAR_H 27 | #define PSI_TYPES_DECL_VAR_H 28 | 29 | struct psi_data; 30 | struct psi_token; 31 | struct psi_decl_arg; 32 | struct psi_let_exp; 33 | struct psi_set_exp; 34 | struct psi_validate_scope; 35 | 36 | struct psi_decl_var { 37 | struct psi_token *token; 38 | zend_string *name, *fqn; 39 | unsigned pointer_level; 40 | unsigned array_size; 41 | struct psi_decl_arg *arg; 42 | }; 43 | 44 | struct psi_decl_var *psi_decl_var_init(zend_string *name, unsigned pl, unsigned as); 45 | struct psi_decl_var *psi_decl_var_copy(struct psi_decl_var *src); 46 | void psi_decl_var_free(struct psi_decl_var **var_ptr); 47 | void psi_decl_var_dump(struct psi_dump *dump, struct psi_decl_var *var); 48 | 49 | bool psi_decl_var_validate(struct psi_data *data, struct psi_decl_var *dvar, 50 | struct psi_validate_scope *scope); 51 | 52 | size_t psi_decl_var_get_size(struct psi_decl_var *var); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /src/types/free_exp.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_TYPES_FREE_EXP_H 27 | #define PSI_TYPES_FREE_EXP_H 28 | 29 | struct psi_data; 30 | struct psi_token; 31 | struct psi_plist; 32 | struct psi_impl; 33 | struct psi_decl; 34 | struct psi_let_stmt; 35 | struct psi_call_frame; 36 | 37 | struct psi_free_exp { 38 | struct psi_token *token; 39 | zend_string *func; 40 | struct psi_plist *vars; 41 | struct psi_decl *decl; 42 | struct psi_let_stmt **let; 43 | }; 44 | 45 | struct psi_free_exp *psi_free_exp_init(zend_string *func, struct psi_plist *vars); 46 | void psi_free_exp_free(struct psi_free_exp **f_ptr); 47 | void psi_free_exp_dump(struct psi_dump *dump, struct psi_free_exp *call); 48 | 49 | bool psi_free_exp_validate(struct psi_data *data, struct psi_free_exp *fc, struct psi_validate_scope *scope); 50 | 51 | void psi_free_exp_exec(struct psi_free_exp *f, struct psi_call_frame *frame); 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /src/types/free_stmt.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_TYPES_FREE_STMT_H 27 | #define PSI_TYPES_FREE_STMT_H 28 | 29 | struct psi_data; 30 | struct psi_plist; 31 | struct psi_impl; 32 | struct psi_call_frame; 33 | 34 | struct psi_free_stmt { 35 | struct psi_token *token; 36 | struct psi_plist *exps; 37 | }; 38 | 39 | struct psi_free_stmt *psi_free_stmt_init(struct psi_plist *calls); 40 | void psi_free_stmt_free(struct psi_free_stmt **f_ptr); 41 | void psi_free_stmt_dump(struct psi_dump *dump, struct psi_free_stmt *fre); 42 | 43 | bool psi_free_stmts_validate(struct psi_data *data, struct psi_validate_scope *scope); 44 | void psi_free_stmt_exec(struct psi_free_stmt *fre, struct psi_call_frame *frame); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /src/types/impl.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_TYPES_IMPL_H 27 | #define PSI_TYPES_IMPL_H 28 | 29 | struct psi_data; 30 | struct psi_token; 31 | struct psi_plist; 32 | struct psi_decl; 33 | struct psi_decl_var; 34 | struct psi_impl_var; 35 | struct psi_impl_func; 36 | 37 | struct psi_impl { 38 | struct psi_impl_func *func; 39 | struct psi_decl *decl; 40 | void *info; 41 | struct { 42 | struct psi_plist *ret; 43 | struct psi_plist *let; 44 | struct psi_plist *set; 45 | struct psi_plist *fre; 46 | struct psi_plist *ass; 47 | } stmts; 48 | }; 49 | 50 | struct psi_impl *psi_impl_init(struct psi_impl_func *func, struct psi_plist *stmts); 51 | void psi_impl_free(struct psi_impl **impl_ptr); 52 | void psi_impl_dump(struct psi_dump *dump, struct psi_impl *impl); 53 | bool psi_impl_validate(struct psi_data *data, struct psi_impl *impl, 54 | struct psi_validate_scope *scope); 55 | 56 | size_t psi_impl_num_min_args(struct psi_impl *impl); 57 | 58 | void psi_impl_stmt_free(struct psi_token ***abstract_stm); 59 | 60 | struct psi_let_stmt *psi_impl_get_let(struct psi_impl *impl, struct psi_decl_var *var); 61 | struct psi_impl_arg *psi_impl_get_arg(struct psi_impl *impl, struct psi_impl_var *var); 62 | 63 | struct psi_decl_arg *psi_impl_get_temp_let_arg(struct psi_impl *impl, 64 | struct psi_decl_var *var); 65 | 66 | struct psi_decl_arg *psi_impl_get_decl_arg(struct psi_impl *impl, 67 | struct psi_decl_var *var); 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /src/types/impl_arg.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifdef HAVE_CONFIG_H 27 | # include "config.h" 28 | #else 29 | # include "php_config.h" 30 | #endif 31 | #include "data.h" 32 | 33 | struct psi_impl_arg *psi_impl_arg_init(struct psi_impl_type *type, 34 | struct psi_impl_var *var, struct psi_impl_def_val *def) 35 | { 36 | struct psi_impl_arg *arg = pecalloc(1, sizeof(*arg), 1); 37 | arg->type = type; 38 | arg->var = var; 39 | arg->var->arg = arg; 40 | arg->def = def; 41 | return arg; 42 | } 43 | 44 | void psi_impl_arg_free(struct psi_impl_arg **arg_ptr) 45 | { 46 | if (*arg_ptr) { 47 | struct psi_impl_arg *arg = *arg_ptr; 48 | 49 | *arg_ptr = NULL; 50 | psi_impl_type_free(&arg->type); 51 | psi_impl_var_free(&arg->var); 52 | if (arg->def) { 53 | psi_impl_def_val_free(&arg->def); 54 | } 55 | free(arg); 56 | } 57 | } 58 | 59 | void psi_impl_arg_dump(struct psi_dump *dump, struct psi_impl_arg *iarg, bool vararg) 60 | { 61 | psi_impl_type_dump(dump, iarg->type); 62 | PSI_DUMP(dump, " "); 63 | psi_impl_var_dump(dump, iarg->var, vararg); 64 | if (iarg->def) { 65 | PSI_DUMP(dump, " = "); 66 | psi_impl_def_val_dump(dump, iarg->def); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/types/impl_arg.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_TYPES_IMPL_ARG_H 27 | #define PSI_TYPES_IMPL_ARG_H 28 | 29 | #include "token.h" 30 | 31 | struct psi_impl_type; 32 | struct psi_impl_var; 33 | struct psi_impl_def_val; 34 | 35 | struct psi_impl_arg { 36 | struct psi_impl_type *type; 37 | struct psi_impl_var *var; 38 | struct psi_impl_def_val *def; 39 | }; 40 | 41 | struct psi_impl_arg *psi_impl_arg_init(struct psi_impl_type *type, struct psi_impl_var *var, struct psi_impl_def_val *def); 42 | void psi_impl_arg_free(struct psi_impl_arg **arg_ptr); 43 | void psi_impl_arg_dump(struct psi_dump *dump, struct psi_impl_arg *iarg, bool vararg); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/types/impl_def_val.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_TYPES_IMPL_DEF_VAL_H 27 | #define PSI_TYPES_IMPL_DEF_VAL_H 28 | 29 | #include "token.h" 30 | #include "types/impl_val.h" 31 | 32 | struct psi_data; 33 | struct psi_impl_type; 34 | struct psi_dump; 35 | 36 | struct psi_impl_def_val { 37 | struct psi_token *token; 38 | token_t type; 39 | union { 40 | struct psi_num_exp *num; 41 | } data; 42 | token_t ityp; 43 | impl_val ival; 44 | }; 45 | 46 | struct psi_impl_def_val *psi_impl_def_val_init(token_t t, void *data); 47 | void psi_impl_def_val_free(struct psi_impl_def_val **def_ptr); 48 | void psi_impl_def_val_dump(struct psi_dump *dump, struct psi_impl_def_val *val); 49 | bool psi_impl_def_val_validate(struct psi_data *data, struct psi_impl_def_val *def, 50 | struct psi_impl_type *cmp, struct psi_validate_scope *scope); 51 | void psi_impl_def_val_get_zval(struct psi_impl_def_val *val, token_t typ, zval *z); 52 | #endif 53 | -------------------------------------------------------------------------------- /src/types/impl_func.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_TYPES_IMPL_FUNC_H 27 | #define PSI_TYPES_IMPL_FUNC_H 28 | 29 | struct psi_data; 30 | struct psi_token; 31 | struct psi_plist; 32 | struct psi_impl; 33 | struct psi_impl_arg; 34 | struct psi_impl_type; 35 | 36 | struct psi_impl_func { 37 | struct psi_token *token; 38 | zend_string *name; 39 | struct psi_plist *args; 40 | struct psi_impl_arg *vararg; 41 | struct psi_impl_type *return_type; 42 | unsigned return_reference:1; 43 | unsigned static_memory:1; 44 | }; 45 | 46 | struct psi_impl_func *psi_impl_func_init(zend_string *name, 47 | struct psi_plist *args, struct psi_impl_type *return_type); 48 | void psi_impl_func_free(struct psi_impl_func **f_ptr); 49 | void psi_impl_func_dump(struct psi_dump *dump, struct psi_impl_func *func); 50 | bool psi_impl_func_validate(struct psi_data *data, struct psi_impl_func *func, 51 | struct psi_validate_scope *scope); 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /src/types/impl_type.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifdef HAVE_CONFIG_H 27 | # include "config.h" 28 | #else 29 | # include "php_config.h" 30 | #endif 31 | #include "data.h" 32 | 33 | struct psi_impl_type *psi_impl_type_init(token_t type, zend_string *name) 34 | { 35 | struct psi_impl_type *t = pecalloc(1, sizeof(*t), 1); 36 | 37 | t->type = type; 38 | t->name = zend_string_copy(name); 39 | 40 | return t; 41 | } 42 | 43 | void psi_impl_type_dump(struct psi_dump *dump, struct psi_impl_type *type) 44 | { 45 | PSI_DUMP(dump, "%s", type->name->val); 46 | } 47 | 48 | void psi_impl_type_free(struct psi_impl_type **type_ptr) 49 | { 50 | if (*type_ptr) { 51 | struct psi_impl_type *type = *type_ptr; 52 | 53 | *type_ptr = NULL; 54 | psi_token_free(&type->token); 55 | zend_string_release(type->name); 56 | free(type); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/types/impl_type.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_TYPES_IMPL_TYPE_H 27 | #define PSI_TYPES_IMPL_TYPE_H 28 | 29 | #include "token.h" 30 | 31 | struct psi_impl_type { 32 | struct psi_token *token; 33 | zend_string *name; 34 | token_t type; 35 | }; 36 | 37 | struct psi_impl_type *psi_impl_type_init(token_t type, zend_string *name); 38 | void psi_impl_type_free(struct psi_impl_type **type_ptr); 39 | void psi_impl_type_dump(struct psi_dump *dump, struct psi_impl_type *type); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /src/types/impl_var.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_TYPES_IMPL_VAR_H 27 | #define PSI_TYPES_IMPL_VAR_H 28 | 29 | struct psi_token; 30 | struct psi_impl; 31 | struct psi_impl_arg; 32 | struct psi_validate_scope; 33 | 34 | struct psi_impl_var { 35 | struct psi_token *token; 36 | zend_string *name, *fqn; 37 | struct psi_impl_arg *arg; 38 | unsigned reference:1; 39 | }; 40 | 41 | struct psi_impl_var *psi_impl_var_init(zend_string *name, bool is_reference); 42 | struct psi_impl_var *psi_impl_var_copy(struct psi_impl_var *var); 43 | void psi_impl_var_free(struct psi_impl_var **var_ptr); 44 | void psi_impl_var_dump(struct psi_dump *dump, struct psi_impl_var *var, bool vararg); 45 | 46 | bool psi_impl_var_validate(struct psi_data *data, struct psi_impl_var *ivar, 47 | struct psi_validate_scope *scope); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /src/types/layout.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifdef HAVE_CONFIG_H 27 | # include "config.h" 28 | #else 29 | # include "php_config.h" 30 | #endif 31 | #include "data.h" 32 | 33 | #include 34 | 35 | struct psi_layout *psi_layout_init(size_t pos, size_t len, struct psi_layout *bfw) 36 | { 37 | struct psi_layout *l = pecalloc(1, sizeof(*l), 1); 38 | 39 | assert(pos + len + (intptr_t) bfw); 40 | 41 | l->pos = pos; 42 | l->len = len; 43 | l->bfw = bfw; 44 | 45 | return l; 46 | } 47 | 48 | void psi_layout_free(struct psi_layout **l_ptr) 49 | { 50 | if (*l_ptr) { 51 | struct psi_layout *l = *l_ptr; 52 | *l_ptr = NULL; 53 | 54 | if (l->bfw) { 55 | psi_layout_free(&l->bfw); 56 | } 57 | free(l); 58 | } 59 | } 60 | 61 | int psi_layout_sort_cmp(const void *_a, const void *_b) 62 | { 63 | struct psi_decl_arg *a = *(struct psi_decl_arg **) _a; 64 | struct psi_decl_arg *b = *(struct psi_decl_arg **) _b; 65 | 66 | if (a->layout->pos == b->layout->pos) { 67 | if (a->layout->len == b->layout->len) { 68 | return 0; 69 | } else if (a->layout->len > b->layout->len) { 70 | return -1; 71 | } else { 72 | return 1; 73 | } 74 | } else if (a->layout->pos > b->layout->pos) { 75 | return 1; 76 | } else { 77 | return -1; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/types/layout.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_TYPES_LAYOUT_H 27 | #define PSI_TYPES_LAYOUT_H 28 | 29 | struct psi_layout { 30 | size_t pos; 31 | size_t len; 32 | struct psi_layout *bfw; 33 | }; 34 | 35 | struct psi_layout *psi_layout_init(size_t pos, size_t len, struct psi_layout *bfw); 36 | void psi_layout_free(struct psi_layout **l_ptr); 37 | 38 | int psi_layout_sort_cmp(const void *_a, const void *_b); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /src/types/let_callback.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_TYPES_LET_CALLBACK_H 27 | #define PSI_TYPES_LET_CALLBACK_H 28 | 29 | struct psi_data; 30 | struct psi_impl; 31 | struct psi_decl; 32 | struct psi_plist; 33 | struct psi_let_exp; 34 | struct psi_let_func; 35 | 36 | struct psi_let_callback { 37 | struct psi_token *token; 38 | struct psi_let_func *func; 39 | struct psi_plist *args; 40 | struct psi_plist *cb_args; 41 | struct psi_decl *decl; 42 | void *info; 43 | }; 44 | 45 | struct psi_let_callback *psi_let_callback_init(struct psi_let_func *func, struct psi_plist *args, struct psi_plist *cb_args); 46 | void psi_let_callback_free(struct psi_let_callback **cb_ptr); 47 | void psi_let_callback_dump(struct psi_dump *dump, struct psi_let_callback *cb, unsigned level); 48 | bool psi_let_callback_validate(struct psi_data *data, struct psi_let_callback *cb, struct psi_validate_scope *scope); 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/types/let_calloc.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifdef HAVE_CONFIG_H 27 | # include "config.h" 28 | #else 29 | # include "php_config.h" 30 | #endif 31 | #include "data.h" 32 | 33 | struct psi_let_calloc *psi_let_calloc_init(struct psi_num_exp *nmemb, 34 | struct psi_num_exp *size) 35 | { 36 | struct psi_let_calloc *alloc = pecalloc(1, sizeof(*alloc), 1); 37 | 38 | alloc->nmemb = nmemb; 39 | alloc->size = size; 40 | 41 | return alloc; 42 | } 43 | 44 | void psi_let_calloc_free(struct psi_let_calloc **alloc_ptr) 45 | { 46 | if (*alloc_ptr) { 47 | struct psi_let_calloc *alloc = *alloc_ptr; 48 | 49 | *alloc_ptr = NULL; 50 | psi_num_exp_free(&alloc->nmemb); 51 | psi_num_exp_free(&alloc->size); 52 | psi_token_free(&alloc->token); 53 | free(alloc); 54 | } 55 | } 56 | 57 | void psi_let_calloc_dump(struct psi_dump *dump, struct psi_let_calloc *alloc) 58 | { 59 | PSI_DUMP(dump, "calloc("); 60 | psi_num_exp_dump(dump, alloc->nmemb); 61 | PSI_DUMP(dump, ", "); 62 | psi_num_exp_dump(dump, alloc->size); 63 | PSI_DUMP(dump, ")"); 64 | } 65 | -------------------------------------------------------------------------------- /src/types/let_calloc.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_TYPES_LET_CALLOC_H 27 | #define PSI_TYPES_LET_CALLOC_H 28 | 29 | struct psi_token; 30 | struct psi_num_exp; 31 | 32 | struct psi_let_calloc { 33 | struct psi_token *token; 34 | struct psi_num_exp *nmemb; 35 | struct psi_num_exp *size; 36 | unsigned static_memory:1; 37 | }; 38 | 39 | struct psi_let_calloc *psi_let_calloc_init(struct psi_num_exp *nmemb, struct psi_num_exp *size); 40 | void psi_let_calloc_free(struct psi_let_calloc **alloc_ptr); 41 | void psi_let_calloc_dump(struct psi_dump *dump, struct psi_let_calloc *alloc); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/types/let_stmt.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_TYPES_LET_STMT_H 27 | #define PSI_TYPES_LET_STMT_H 28 | 29 | struct psi_data; 30 | struct psi_token; 31 | struct psi_let_exp; 32 | struct psi_call_frame; 33 | struct psi_impl; 34 | 35 | struct psi_let_stmt { 36 | struct psi_token *token; 37 | struct psi_let_exp *exp; 38 | }; 39 | 40 | struct psi_let_stmt *psi_let_stmt_init(struct psi_let_exp *exp); 41 | void psi_let_stmt_free(struct psi_let_stmt **stmt_ptr); 42 | void psi_let_stmt_dump(struct psi_dump *dump, struct psi_let_stmt *stmt); 43 | 44 | void *psi_let_stmt_exec(struct psi_let_stmt *stmt, struct psi_call_frame *frame); 45 | bool psi_let_stmts_validate(struct psi_data *data, struct psi_validate_scope *scope); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /src/types/return_exp.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2017, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_TYPES_RETURN_EXP_H 27 | #define PSI_TYPES_RETURN_EXP_H 28 | 29 | struct psi_return_exp { 30 | struct psi_token *token; 31 | struct psi_decl_var *func; 32 | struct psi_plist *args; 33 | struct psi_set_exp *set; 34 | }; 35 | 36 | struct psi_return_exp *psi_return_exp_init(struct psi_decl_var *func, 37 | struct psi_plist *args, struct psi_set_exp *set); 38 | void psi_return_exp_free(struct psi_return_exp **exp_ptr); 39 | void psi_return_exp_dump(struct psi_dump *dump, struct psi_return_exp *exp); 40 | void psi_return_exp_exec(struct psi_return_exp *exp, zval *return_value, 41 | struct psi_call_frame *frame); 42 | bool psi_return_exp_validate(struct psi_data *data, struct psi_return_exp *exp, 43 | struct psi_validate_scope *scope); 44 | zend_string *psi_return_exp_get_decl_name(struct psi_return_exp *exp); 45 | 46 | #endif /* RETURN_EXP_H */ 47 | -------------------------------------------------------------------------------- /src/types/return_stmt.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_TYPES_RETURN_STMT_H 27 | #define PSI_TYPES_RETURN_STMT_H 28 | 29 | #include "Zend/zend_types.h" 30 | 31 | struct psi_data; 32 | struct psi_token; 33 | struct psi_call_frame; 34 | struct psi_impl; 35 | struct psi_set_exp; 36 | 37 | struct psi_return_stmt { 38 | struct psi_token *token; 39 | struct psi_return_exp *exp; 40 | }; 41 | 42 | struct psi_return_stmt *psi_return_stmt_init(struct psi_return_exp *exp); 43 | void psi_return_stmt_free(struct psi_return_stmt **ret_ptr); 44 | void psi_return_stmt_dump(struct psi_dump *dump, struct psi_return_stmt *ret); 45 | void psi_return_stmt_exec(struct psi_return_stmt *ret, zval *return_value, struct psi_call_frame *frame); 46 | bool psi_return_stmt_validate(struct psi_data *data, struct psi_validate_scope *impl); 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /src/types/set_exp.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_TYPES_SET_EXP_H 27 | #define PSI_TYPES_SET_EXP_H 28 | 29 | struct psi_data; 30 | struct psi_plist; 31 | struct psi_call_frame; 32 | struct psi_let_exp; 33 | struct psi_set_func; 34 | struct psi_num_exp; 35 | struct psi_impl; 36 | struct psi_decl; 37 | struct psi_validate_scope; 38 | 39 | enum psi_set_exp_kind { 40 | PSI_SET_FUNC, 41 | PSI_SET_NUMEXP, 42 | }; 43 | 44 | struct psi_set_exp { 45 | enum psi_set_exp_kind kind; 46 | struct psi_impl_var *var; 47 | struct psi_set_exp *outer; 48 | struct psi_plist *inner; 49 | union { 50 | struct psi_set_func *func; 51 | struct psi_num_exp *num; 52 | } data; 53 | }; 54 | 55 | struct psi_set_exp *psi_set_exp_init(enum psi_set_exp_kind kind, void *data); 56 | void psi_set_exp_free(struct psi_set_exp **exp_ptr); 57 | void psi_set_exp_dump(struct psi_dump *dump, struct psi_set_exp *set, unsigned level, int last); 58 | void psi_set_exp_exec(struct psi_set_exp *val, struct psi_call_frame *frame); 59 | void psi_set_exp_exec_ex(struct psi_set_exp *val, zval *zv, impl_val *iv, struct psi_call_frame *frame); 60 | bool psi_set_exp_validate(struct psi_data *data, struct psi_set_exp *set, struct psi_validate_scope *scope); 61 | 62 | struct psi_impl_var *psi_set_exp_get_impl_var(struct psi_set_exp *exp); 63 | struct psi_decl_var *psi_set_exp_get_decl_var(struct psi_set_exp *exp); 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /src/types/set_func.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_TYPES_SET_FUNC_H 27 | #define PSI_TYPES_SET_FUNC_H 28 | 29 | #include "token.h" 30 | #include "marshal.h" 31 | 32 | struct psi_plist; 33 | struct psi_decl_var; 34 | struct psi_validate_scope; 35 | 36 | struct psi_set_func { 37 | struct psi_token *token; 38 | token_t type; 39 | zend_string *name; 40 | struct psi_decl_var *var; 41 | psi_marshal_set handler; 42 | struct psi_plist *inner; 43 | unsigned recursive:1; 44 | }; 45 | 46 | struct psi_set_func *psi_set_func_init(token_t type, zend_string *name, struct psi_decl_var *var); 47 | void psi_set_func_free(struct psi_set_func **func_ptr); 48 | void psi_set_func_dump(struct psi_dump *dump, struct psi_set_func *func, unsigned level); 49 | bool psi_set_func_validate(struct psi_data *data, struct psi_set_func *func, 50 | struct psi_validate_scope *scope); 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/types/set_stmt.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) 2016, Michael Wallner . 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | *******************************************************************************/ 25 | 26 | #ifndef PSI_TYPES_SET_STMT_H 27 | #define PSI_TYPES_SET_STMT_H 28 | 29 | struct psi_data; 30 | struct psi_token; 31 | struct psi_call_frame; 32 | struct psi_impl; 33 | struct psi_set_exp; 34 | 35 | struct psi_set_stmt { 36 | struct psi_token *token; 37 | struct psi_set_exp *exp; 38 | }; 39 | 40 | struct psi_set_stmt *psi_set_stmt_init(struct psi_set_exp *val); 41 | void psi_set_stmt_free(struct psi_set_stmt **set_ptr); 42 | void psi_set_stmt_dump(struct psi_dump *dump, struct psi_set_stmt *set); 43 | void psi_set_stmt_exec(struct psi_set_stmt *set, struct psi_call_frame *frame); 44 | bool psi_set_stmts_validate(struct psi_data *data, struct psi_validate_scope *scope); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /tests/arpa_inet/inet001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | inet_ntop/inet_pton 3 | --INI-- 4 | psi.directory={PWD}/../../psi.d:{PWD} 5 | --FILE-- 6 | ===TEST=== 7 | 11 | ===DONE=== 12 | --EXPECT-- 13 | ===TEST=== 14 | int(1) 15 | string(9) "127.1.1.1" 16 | ===DONE=== 17 | -------------------------------------------------------------------------------- /tests/arpa_inet/inet002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | inet_addr/inet_ntoa 3 | --INI-- 4 | psi.directory={PWD}/../../psi.d:{PWD} 5 | --FILE-- 6 | ===TEST=== 7 | psi\inet_addr("217.0.0.1")])); 9 | ?> 10 | ===DONE=== 11 | --EXPECT-- 12 | ===TEST=== 13 | string(9) "217.0.0.1" 14 | ===DONE=== 15 | -------------------------------------------------------------------------------- /tests/arpa_inet/ntoh001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | arpa/inet 3 | --INI-- 4 | psi.directory={PWD}/../../psi.d:{PWD} 5 | --FILE-- 6 | ===TEST=== 7 | 13 | ===DONE=== 14 | --EXPECT-- 15 | ===TEST=== 16 | int(55) 17 | int(555555) 18 | int(14080) 19 | int(595200000) 20 | ===DONE=== 21 | -------------------------------------------------------------------------------- /tests/calc/calc.psi: -------------------------------------------------------------------------------- 1 | #ifdef __linux__ 2 | #pragma lib "crypt" 3 | #endif 4 | 5 | #include 6 | 7 | function test\calc1() : array { 8 | let numerator = 3 * 5 + 2; 9 | let denominator = 17; 10 | return div(numerator, denominator) as to_array(div, 11 | to_int(quot), 12 | to_int(rem) 13 | ); 14 | } 15 | 16 | function test\calc2() : array { 17 | let numerator = 4 + 5 * 2; 18 | let denominator = 14; 19 | return div(numerator, denominator) as to_array(div, 20 | to_int(quot), 21 | to_int(rem) 22 | ); 23 | } 24 | 25 | function test\calc3() : array { 26 | let numerator = -1 + 2 - 3 * 2; 27 | let denominator = -5; 28 | return div(numerator, denominator) as to_array(div, 29 | to_int(quot), 30 | to_int(rem) 31 | ); 32 | } 33 | 34 | function test\calc4() : array { 35 | let numerator = 1 * 5 / 5 * -1 / -1 * 10 / 5 + 4 * 2; 36 | let denominator = 10; 37 | return div(numerator, denominator) as to_array(div, 38 | to_int(quot), 39 | to_int(rem) 40 | ); 41 | } 42 | 43 | function test\calc5() : array { 44 | let numerator = 5 % 3; 45 | let denominator = 2; 46 | return div(numerator, denominator) as to_array(div, 47 | to_int(quot), 48 | to_int(rem) 49 | ); 50 | } 51 | 52 | function test\calc6() : array { 53 | let numerator = 5 % 3 + 1; 54 | let denominator = 3; 55 | return div(numerator, denominator) as to_array(div, 56 | to_int(quot), 57 | to_int(rem) 58 | ); 59 | } 60 | 61 | function test\calc7() : array { 62 | let numerator = 5 % (3 + 1); 63 | let denominator = 1; 64 | return div(numerator, denominator) as to_array(div, 65 | to_int(quot), 66 | to_int(rem) 67 | ); 68 | } 69 | 70 | function test\calc8() : array { 71 | let numerator = !0 + !0 + !0; 72 | let denominator = 3; 73 | return div(numerator, denominator) as to_array(div, 74 | to_int(quot), 75 | to_int(rem) 76 | ); 77 | } 78 | 79 | function test\calc9() : array { 80 | let numerator = 1 && 2; 81 | let denominator = 1; 82 | return div(numerator, denominator) as to_array(div, 83 | to_int(quot), 84 | to_int(rem) 85 | ); 86 | } 87 | 88 | function test\calc10() : array { 89 | let numerator = (1 | 2 | 4) & ~3; 90 | let denominator = 4; 91 | return div(numerator, denominator) as to_array(div, 92 | to_int(quot), 93 | to_int(rem) 94 | ); 95 | } 96 | 97 | function test\calc11() : array { 98 | let numerator = 1 + (1 + 1 < 2); 99 | let denominator = 1; 100 | return div(numerator, denominator) as to_array(div, 101 | to_int(quot), 102 | to_int(rem) 103 | ); 104 | } 105 | 106 | function test\calc12() : array { 107 | let numerator = 1 + (1 + 1 < 3); 108 | let denominator = 2; 109 | return div(numerator, denominator) as to_array(div, 110 | to_int(quot), 111 | to_int(rem) 112 | ); 113 | } 114 | -------------------------------------------------------------------------------- /tests/calc/calc001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | calc 3 | --INI-- 4 | psi.directory={PWD}/../../psi.d:{PWD} 5 | --FILE-- 6 | ===TEST=== 7 | 1, "rem"=>0]) { 13 | echo "yay-"; 14 | } else { 15 | var_dump($res); 16 | } 17 | } 18 | } 19 | ?> 20 | 21 | ===DONE=== 22 | --EXPECTREGEX-- 23 | ===TEST=== 24 | (yay-)+ 25 | ===DONE=== 26 | -------------------------------------------------------------------------------- /tests/div/div001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | div 3 | --INI-- 4 | psi.directory={PWD}:{PWD}/../../psi.d 5 | --FILE-- 6 | ===TEST=== 7 | 10 | ===DONE=== 11 | --EXPECT-- 12 | ===TEST=== 13 | array(2) { 14 | ["quot"]=> 15 | int(100) 16 | ["rem"]=> 17 | int(0) 18 | } 19 | ===DONE=== 20 | -------------------------------------------------------------------------------- /tests/div/ldiv001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ldiv 3 | --INI-- 4 | psi.directory={PWD}:{PWD}/../../psi.d 5 | --FILE-- 6 | ===TEST=== 7 | 10 | ===DONE=== 11 | --EXPECT-- 12 | ===TEST=== 13 | array(2) { 14 | ["quot"]=> 15 | int(100) 16 | ["rem"]=> 17 | int(0) 18 | } 19 | ===DONE=== 20 | -------------------------------------------------------------------------------- /tests/div/lldiv001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | lldiv 3 | --INI-- 4 | psi.directory={PWD}:{PWD}/../../psi.d 5 | display_startup_errors=0 6 | --FILE-- 7 | ===TEST=== 8 | 11 | ===DONE=== 12 | --EXPECT-- 13 | ===TEST=== 14 | array(2) { 15 | ["quot"]=> 16 | int(100) 17 | ["rem"]=> 18 | int(0) 19 | } 20 | ===DONE=== 21 | -------------------------------------------------------------------------------- /tests/getopt/getopt001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | getopt 3 | --INI-- 4 | psi.directory={PWD}:{PWD}/../../psi.d 5 | --SKIPIF-- 6 | 9 | --ENV-- 10 | POSIXLY_CORRECT= 11 | --FILE-- 12 | ===TEST=== 13 | 49 | ===DONE=== 50 | --EXPECT-- 51 | ===TEST=== 52 | got v 53 | got x: 1 54 | got s: foo 55 | arg: huh 56 | arg: -gotcha 57 | arg: --bar 58 | arg: baz 59 | got v 60 | got x: 1 61 | got s: foo 62 | arg: huh 63 | arg: -gotcha 64 | arg: --bar 65 | arg: baz 66 | got v 67 | got x: 1 68 | got s: foo 69 | arg: huh 70 | arg: -gotcha 71 | arg: --bar 72 | arg: baz 73 | array(11) { 74 | [0]=> 75 | string(8) "progname" 76 | [1]=> 77 | string(2) "-v" 78 | [2]=> 79 | string(2) "-x" 80 | [3]=> 81 | string(1) "1" 82 | [4]=> 83 | string(2) "-s" 84 | [5]=> 85 | string(3) "foo" 86 | [6]=> 87 | string(2) "--" 88 | [7]=> 89 | string(3) "huh" 90 | [8]=> 91 | string(7) "-gotcha" 92 | [9]=> 93 | string(5) "--bar" 94 | [10]=> 95 | string(3) "baz" 96 | } 97 | ===DONE=== 98 | -------------------------------------------------------------------------------- /tests/getopt/getopt002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | getopt 3 | --INI-- 4 | psi.directory={PWD}:{PWD}/../../psi.d 5 | --SKIPIF-- 6 | 9 | --ENV-- 10 | POSIXLY_CORRECT= 11 | --FILE-- 12 | ===TEST=== 13 | 50 | ===DONE=== 51 | --EXPECT-- 52 | ===TEST=== 53 | got v 54 | got x: 1 55 | got s: foo 56 | arg: huh 57 | arg: -gotcha 58 | arg: --bar 59 | arg: baz 60 | got v 61 | got x: 1 62 | got s: foo 63 | arg: huh 64 | arg: -gotcha 65 | arg: --bar 66 | arg: baz 67 | got v 68 | got x: 1 69 | got s: foo 70 | arg: huh 71 | arg: -gotcha 72 | arg: --bar 73 | arg: baz 74 | array(11) { 75 | [0]=> 76 | string(8) "progname" 77 | [1]=> 78 | string(2) "-v" 79 | [2]=> 80 | string(2) "-x" 81 | [3]=> 82 | string(1) "1" 83 | [4]=> 84 | string(2) "-s" 85 | [5]=> 86 | string(3) "foo" 87 | [6]=> 88 | string(2) "--" 89 | [7]=> 90 | string(3) "huh" 91 | [8]=> 92 | string(7) "-gotcha" 93 | [9]=> 94 | string(5) "--bar" 95 | [10]=> 96 | string(3) "baz" 97 | } 98 | ===DONE=== 99 | -------------------------------------------------------------------------------- /tests/glob/glob001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | glob 3 | --INI-- 4 | psi.directory={PWD}/../../psi.d:{PWD} 5 | --FILE-- 6 | ===TEST=== 7 | 15 | ===DONE=== 16 | --EXPECTF-- 17 | ===TEST=== 18 | int(0) 19 | ===DONE=== -------------------------------------------------------------------------------- /tests/glob/glob002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | glob 3 | --INI-- 4 | psi.directory={PWD}/../../psi.d:{PWD} 5 | --SKIPIF-- 6 | 9 | --FILE-- 10 | ===TEST=== 11 | 5]; 14 | var_dump(psi\glob("*002.php*", psi\GLOB_DOOFFS, $glob)); 15 | var_dump($glob); 16 | ?> 17 | ===DONE=== 18 | --EXPECTF-- 19 | ===TEST=== 20 | int(0) 21 | array(4) { 22 | ["gl_pathc"]=> 23 | int(2) 24 | ["gl_offs"]=> 25 | int(5) 26 | ["gl_flags"]=> 27 | int(%d) 28 | ["gl_pathv"]=> 29 | array(7) { 30 | [0]=> 31 | string(0) "" 32 | [1]=> 33 | string(0) "" 34 | [2]=> 35 | string(0) "" 36 | [3]=> 37 | string(0) "" 38 | [4]=> 39 | string(0) "" 40 | [5]=> 41 | string(11) "glob002.php" 42 | [6]=> 43 | string(12) "glob002.phpt" 44 | } 45 | } 46 | ===DONE=== 47 | -------------------------------------------------------------------------------- /tests/glob/glob003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | glob 3 | --INI-- 4 | psi.directory={PWD}/../../psi.d:{PWD} 5 | --SKIPIF-- 6 | 9 | --FILE-- 10 | ===TEST=== 11 | 3]; 14 | var_dump(psi\glob("*.php{,t}", psi\GLOB_BRACE|psi\GLOB_DOOFFS, $glob)); 15 | var_dump($glob); 16 | ?> 17 | ===DONE=== 18 | --EXPECTF-- 19 | ===TEST=== 20 | int(0) 21 | array(5) { 22 | ["gl_matchc"]=> 23 | int(5) 24 | ["gl_pathc"]=> 25 | int(5) 26 | ["gl_offs"]=> 27 | int(3) 28 | ["gl_flags"]=> 29 | int(386) 30 | ["gl_pathv"]=> 31 | array(8) { 32 | [0]=> 33 | string(0) "" 34 | [1]=> 35 | string(0) "" 36 | [2]=> 37 | string(0) "" 38 | [3]=> 39 | string(11) "glob003.php" 40 | [4]=> 41 | string(12) "glob001.phpt" 42 | [5]=> 43 | string(12) "glob002.phpt" 44 | [6]=> 45 | string(12) "glob003.phpt" 46 | [7]=> 47 | string(12) "glob004.phpt" 48 | } 49 | } 50 | ===DONE=== 51 | -------------------------------------------------------------------------------- /tests/glob/glob004.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | glob err 3 | --INI-- 4 | psi.directory={PWD}/../../psi.d:{PWD} 5 | --SKIPIF-- 6 | 9 | --FILE-- 10 | ===TEST=== 11 | 29 | ===DONE=== 30 | --EXPECTF-- 31 | ===TEST=== 32 | Permission denied: /etc/sudoers.d 33 | bool(true) 34 | array(4) { 35 | ["gl_pathc"]=> 36 | int(0) 37 | ["gl_offs"]=> 38 | int(0) 39 | ["gl_flags"]=> 40 | int(%d) 41 | ["gl_pathv"]=> 42 | array(0) { 43 | } 44 | } 45 | Permission denied: /etc/sudoers.d 46 | bool(true) 47 | array(4) { 48 | ["gl_pathc"]=> 49 | int(0) 50 | ["gl_offs"]=> 51 | int(0) 52 | ["gl_flags"]=> 53 | int(%d) 54 | ["gl_pathv"]=> 55 | array(0) { 56 | } 57 | } 58 | Permission denied: /etc/sudoers.d 59 | bool(false) 60 | array(4) { 61 | ["gl_pathc"]=> 62 | int(0) 63 | ["gl_offs"]=> 64 | int(0) 65 | ["gl_flags"]=> 66 | int(%d) 67 | ["gl_pathv"]=> 68 | array(0) { 69 | } 70 | } 71 | ===DONE=== 72 | -------------------------------------------------------------------------------- /tests/iconv/iconv.psi: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern void *iconv_open(char *tocode, char *fromcode); 4 | function psi\iconv_open(string $to, string $from) : object { 5 | let tocode = strval($to); 6 | let fromcode = strval($from); 7 | return to_object(iconv_open); 8 | } 9 | 10 | extern size_t iconv (void *cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft); 11 | function psi\iconv(object $iconv, string &$inbuf, string &$outbuf) : int { 12 | let cd = objval($iconv); 13 | let inbuf = &strval($inbuf); 14 | let inbytesleft = &strlen($inbuf); 15 | let outbytesleft = &8192; 16 | let outbuf = &calloc(1, 8192); 17 | temp result = *outbuf; 18 | return iconv(cd, inbuf, inbytesleft, outbuf, outbytesleft) as to_int(iconv); 19 | set $inbuf = to_string(*inbuf, *inbytesleft); 20 | set $outbuf = to_string(result, 8192 - *outbytesleft); 21 | } 22 | 23 | extern int iconv_close(void *cd); 24 | function psi\iconv_close(object $iconv) : int { 25 | let cd = objval($iconv); 26 | return to_int(iconv_close); 27 | } 28 | -------------------------------------------------------------------------------- /tests/iconv/iconv001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | iconv 3 | --INI-- 4 | psi.directory={PWD}/../../psi.d:{PWD} 5 | --FILE-- 6 | ===TEST=== 7 | 17 | ===DONE=== 18 | --EXPECT-- 19 | ===TEST=== 20 | int(0) 21 | ===DONE=== 22 | -------------------------------------------------------------------------------- /tests/iconv/iconv002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | iconv abstraction 3 | --INI-- 4 | psi.directory={PWD}/../../psi.d:{PWD} 5 | --FILE-- 6 | ===TEST=== 7 | cd = psi\iconv_open($to, $from)) { 14 | throw new Exception(psi\strerror(psi\errno())); 15 | } 16 | } 17 | 18 | function __destruct() { 19 | psi\iconv_close($this->cd); 20 | } 21 | 22 | function update(string $data) : string { 23 | if (0 > psi\iconv($this->cd, $data, $result)) { 24 | throw new Exception(psi\strerror(psi\errno())); 25 | } 26 | return $result; 27 | } 28 | } 29 | 30 | $ic = new iconv_stream("utf8", "latin1"); 31 | 32 | foreach (["föö", "bää", "baßß"] as $str) { 33 | var_dump(array_map("ord", str_split($ic->update($str)))); 34 | } 35 | 36 | $bc = new iconv_stream("latin1", "utf8"); 37 | foreach (["föö", "bää", "baßß"] as $str) { 38 | var_dump($bc->update($ic->update($str))); 39 | } 40 | 41 | ?> 42 | ===DONE=== 43 | --EXPECT-- 44 | ===TEST=== 45 | array(3) { 46 | [0]=> 47 | int(102) 48 | [1]=> 49 | int(246) 50 | [2]=> 51 | int(246) 52 | } 53 | array(3) { 54 | [0]=> 55 | int(98) 56 | [1]=> 57 | int(228) 58 | [2]=> 59 | int(228) 60 | } 61 | array(4) { 62 | [0]=> 63 | int(98) 64 | [1]=> 65 | int(97) 66 | [2]=> 67 | int(223) 68 | [3]=> 69 | int(223) 70 | } 71 | string(5) "föö" 72 | string(5) "bää" 73 | string(6) "baßß" 74 | ===DONE=== 75 | -------------------------------------------------------------------------------- /tests/idn/idn.psi: -------------------------------------------------------------------------------- 1 | #ifdef __linux__ 2 | #pragma lib "crypt" 3 | #endif 4 | 5 | #include 6 | 7 | #pragma lib "idn" 8 | #include 9 | 10 | function idn\utf8_to_ascii(string $host, string &$result, int $flags = 0) : int { 11 | let output = &NULL; 12 | let input = strval($host); 13 | let flags = intval($flags); 14 | set $result = to_string(*output); 15 | return to_int(idna_to_ascii_8z); 16 | free free(*output); 17 | } 18 | 19 | function idn\strerror(int $rc) : string { 20 | return to_string(idna_strerror); 21 | let rc = intval($rc); 22 | } 23 | -------------------------------------------------------------------------------- /tests/idn/idn001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | libidn 3 | --INI-- 4 | psi.directory={PWD}/../../psi.d:{PWD} 5 | --FILE-- 6 | ===TEST=== 7 | 13 | ===DONE=== 14 | --EXPECT-- 15 | ===TEST=== 16 | xn--flte-6qa.de 17 | Success 18 | ===DONE=== 19 | -------------------------------------------------------------------------------- /tests/idn/idn002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | libidn 3 | --INI-- 4 | psi.directory={PWD}/../../psi.d:{PWD} 5 | --FILE-- 6 | ===TEST=== 7 | 14 | ===DONE=== 15 | --EXPECT-- 16 | ===TEST=== 17 | 18 | Non-digit/letter/hyphen in input 19 | ===DONE=== 20 | -------------------------------------------------------------------------------- /tests/idn/idn003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | libidn 3 | --INI-- 4 | psi.directory={PWD}/../../psi.d:{PWD} 5 | --FILE-- 6 | ===TEST=== 7 | 15 | ===DONE=== 16 | --EXPECT-- 17 | ===TEST=== 18 | xn--bcher-kva.de 19 | Success 20 | ===DONE=== 21 | -------------------------------------------------------------------------------- /tests/idn/idn004.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | libidn 3 | --INI-- 4 | psi.directory={PWD}/../../psi.d:{PWD} 5 | --FILE-- 6 | ===TEST=== 7 | 19 | ===DONE=== 20 | --EXPECT-- 21 | ===TEST=== 22 | xn--bcher-kva.de 23 | Success 24 | xn--bcher2-3ya.de 25 | Success 26 | ===DONE=== 27 | -------------------------------------------------------------------------------- /tests/ndbm/gdbm.psi: -------------------------------------------------------------------------------- 1 | #pragma lib "gdbm" 2 | #include 3 | -------------------------------------------------------------------------------- /tests/ndbm/ndbm.psi: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #pragma lib "gdbm_compat" 4 | #include 5 | 6 | 7 | function psi\dbm_open(string $file, int $open_flags, int $file_mode) : object { 8 | let file = pathval($file); 9 | let open_flags = intval($open_flags); 10 | let file_mode = intval($file_mode); 11 | return dbm_open(file, open_flags, file_mode) as to_object(dbm_open); 12 | } 13 | 14 | function psi\dbm_store(object $db, string $key, string $data, int $mode) : int { 15 | let db = objval($db); 16 | let key = arrval($key, 17 | dptr = strval($0), 18 | dsize = strlen($0) 19 | ); 20 | let content = arrval($data, 21 | dptr = strval($0), 22 | dsize = strlen($0) 23 | ); 24 | let store_mode = intval($mode); 25 | return dbm_store(db, key, content, store_mode) as to_int(dbm_store); 26 | } 27 | 28 | function psi\dbm_fetch(object $db, array $key) : array { 29 | let db = objval($db); 30 | let key = arrval($key, 31 | dptr = strval($dptr), 32 | dsize = intval($dsize) 33 | ); 34 | return dbm_fetch(db, key) as to_array(dbm_fetch, 35 | to_int(dsize), 36 | to_string(dptr, dsize) 37 | ); 38 | } 39 | 40 | function psi\dbm_close(object $db) : void { 41 | let db = objval($db); 42 | return dbm_close(db) as void(dbm_close); 43 | } 44 | -------------------------------------------------------------------------------- /tests/ndbm/ndbm001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ndbm 3 | --INI-- 4 | psi.directory={PWD}:{PWD}/../../psi.d 5 | --FILE-- 6 | ===TEST=== 7 | db = psi\dbm_open($file, $o, $m)) { 13 | throw new Exception(psi\strerror(psi\errno())); 14 | } 15 | } 16 | 17 | function __destruct() { 18 | psi\dbm_close($this->db); 19 | array_map("unlink", glob(__DIR__."/ndbm001.db*")); 20 | } 21 | 22 | function __set($k, $v) { 23 | return psi\dbm_store($this->db, $k, $v, psi\DBM_REPLACE); 24 | } 25 | 26 | function __get($k) { 27 | $val = psi\dbm_fetch($this->db, [ 28 | "dptr" => $k, 29 | "dsize" => strlen($k) 30 | ]); 31 | if ($val) { 32 | return $val["dptr"]; 33 | } 34 | } 35 | } 36 | 37 | $db = new db(); 38 | $db->key = "data"; 39 | var_dump($db->key); 40 | ?> 41 | ===DONE=== 42 | --CLEAN-- 43 | 46 | --EXPECT-- 47 | ===TEST=== 48 | string(4) "data" 49 | ===DONE=== 50 | -------------------------------------------------------------------------------- /tests/netdb/gai001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | getaddrinfo 3 | --INI-- 4 | psi.directory={PWD}:{PWD}/../../psi.d 5 | --FILE-- 6 | ===TEST=== 7 | 25 | ===DONE=== 26 | --EXPECT-- 27 | ===TEST=== 28 | ===DONE=== 29 | -------------------------------------------------------------------------------- /tests/parser/cpp001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | CPP defines 3 | --FILE-- 4 | ===TEST=== 5 | 62 | ===DONE=== 63 | --EXPECT-- 64 | ===TEST=== 65 | bool(true) 66 | ===DONE=== 67 | -------------------------------------------------------------------------------- /tests/parser/cpp002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | CPP defines 3 | --FILE-- 4 | ===TEST=== 5 | 15 | ===DONE=== 16 | --EXPECT-- 17 | ===TEST=== 18 | 19 | Warning: 'FOO' redefined in on line 3 20 | 21 | Warning: 'FOO' previously defined in on line 2 22 | bool(true) 23 | ===DONE=== 24 | -------------------------------------------------------------------------------- /tests/parser/cpp003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | CPP argument prescan 3 | --INI-- 4 | psi.directory={PWD}/cpp003 5 | --FILE-- 6 | ===TEST=== 7 | 10 | ===DONE=== 11 | --EXPECT-- 12 | ===TEST=== 13 | int(111111) 14 | int(222222) 15 | ===DONE=== 16 | -------------------------------------------------------------------------------- /tests/parser/cpp003/prescan.psi: -------------------------------------------------------------------------------- 1 | #define AFTERX(x) X_ ## x 2 | #define XAFTERX(x) AFTERX(x) 3 | #define TABLESIZE 1024 4 | #define BUFSIZE TABLESIZE 5 | 6 | #define X_BUFSIZE 111110 + 1 7 | const int \CPP_TEST1 = AFTERX(BUFSIZE); // expands to X_BUFSIZE 8 | 9 | #define X_1024 222221 + 1 10 | const int \CPP_TEST2 = XAFTERX(BUFSIZE); // expands to X_1024 11 | 12 | -------------------------------------------------------------------------------- /tests/parser/cpp004.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | CPP builtins 3 | --INI-- 4 | psi.directory={PWD}/cpp004 5 | --ENV-- 6 | LC_TIME=C 7 | --FILE-- 8 | ===TEST=== 9 | 13 | ===DONE=== 14 | --EXPECTF-- 15 | ===TEST=== 16 | int(0) 17 | int(1) 18 | int(2) 19 | int(3003) 20 | int(4004) 21 | int(5005) 22 | string(%d) "%s/tests/parser/cpp004/builtins.psi" 23 | int(2) 24 | string(24) "%s %s %w%d %d:%d:%d %d" 25 | string(%d) "/%s/tests/parser/cpp004/include_level.h" 26 | int(3) 27 | string(11) "%s %d %d" 28 | string(8) "%d:%d:%d" 29 | ===DONE=== 30 | -------------------------------------------------------------------------------- /tests/parser/cpp004/base_file.h: -------------------------------------------------------------------------------- 1 | const \base_file = __BASE_FILE__; 2 | #include "include_level.h" 3 | -------------------------------------------------------------------------------- /tests/parser/cpp004/builtins.psi: -------------------------------------------------------------------------------- 1 | const \CPP_TEST0 = __COUNTER__; 2 | const \CPP_TEST1 = __COUNTER__; 3 | const \CPP_TEST2 = __COUNTER__; 4 | 5 | #define a(x,y) x ## y 6 | #define b(x,y) a(x,y) 7 | #define c(x) b(x, __COUNTER__) 8 | const \CPP_TEST3 = c(300); 9 | const \CPP_TEST4 = c(400); 10 | const \CPP_TEST5 = c(500); 11 | 12 | #include "base_file.h" // includes include_level.h 13 | #include "timestamp.h" 14 | 15 | const \date = __DATE__; 16 | const \time = __TIME__; 17 | -------------------------------------------------------------------------------- /tests/parser/cpp004/include_level.h: -------------------------------------------------------------------------------- 1 | const \include_level = __INCLUDE_LEVEL__; 2 | const \file = __FILE__; 3 | const \line = __LINE__; 4 | 5 | -------------------------------------------------------------------------------- /tests/parser/cpp004/timestamp.h: -------------------------------------------------------------------------------- 1 | const \timestamp = __TIMESTAMP__; 2 | -------------------------------------------------------------------------------- /tests/parser/cpp005.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | CPP expansion 3 | --INI-- 4 | psi.directory={PWD}/cpp005 5 | --FILE-- 6 | ===TEST=== 7 | 9 | ===DONE=== 10 | --EXPECTF-- 11 | Warning: PSI syntax error, unexpected NUMBER, expecting ) or "," at col 11 in %stests/parser/cpp005/expansion.psi on line 2 12 | 13 | Warning: PSI preceding token 'bar' at col 1 in %stests/parser/cpp005/expansion.psi on line 2 14 | 15 | Warning: PSI preceding token 'foo' at col 1 in %stests/parser/cpp005/expansion.psi on line 2 16 | 17 | Warning: PSI preceding token '(' at col 10 in %stests/parser/cpp005/expansion.psi on line 2 18 | 19 | Warning: PSI offending token '2' at col 11 in %stests/parser/cpp005/expansion.psi on line 2 20 | 21 | Warning: PSI following token ')' at col 12 in %stests/parser/cpp005/expansion.psi on line 2 22 | ===TEST=== 23 | ===DONE=== 24 | -------------------------------------------------------------------------------- /tests/parser/cpp005/expansion.psi: -------------------------------------------------------------------------------- 1 | #define foo(x) bar x 2 | foo(foo) (2) 3 | -------------------------------------------------------------------------------- /tests/parser/dump001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | parse dump 3 | --INI-- 4 | psi.directory={PWD}/../../psi.d 5 | --FILE-- 6 | ===TEST=== 7 | 19 | ===DONE=== 20 | --EXPECTF-- 21 | ===TEST=== 22 | bool(true) 23 | bool(true) 24 | int(%d) 25 | ===DONE=== 26 | --CLEAN-- 27 | 30 | -------------------------------------------------------------------------------- /tests/parser/enum001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | enum 3 | --FILE-- 4 | ===TEST=== 5 | 27 | ===DONE=== 28 | --EXPECT-- 29 | ===TEST=== 30 | bool(true) 31 | ===DONE=== 32 | -------------------------------------------------------------------------------- /tests/parser/validate001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | validate types 3 | --FILE-- 4 | ===TEST=== 5 | 39 | ===DONE=== 40 | --EXPECTF-- 41 | ===TEST=== 42 | ===DONE=== 43 | -------------------------------------------------------------------------------- /tests/parser/validate002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | validate types 3 | --FILE-- 4 | ===TEST=== 5 | 8 | ===DONE=== 9 | --EXPECTF-- 10 | ===TEST=== 11 | ===DONE=== 12 | -------------------------------------------------------------------------------- /tests/parser/validate003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | validate types 3 | --FILE-- 4 | ===TEST=== 5 | 9 | ===DONE=== 10 | --EXPECTF-- 11 | ===TEST=== 12 | 13 | Warning: PSI syntax error, unexpected ;, expecting %s at col 17 in %s on line 1 14 | 15 | Warning: PSI preceding token 'typedef' at col 1 in on line 1 16 | 17 | Warning: PSI preceding token 'long' at col 9 in on line 1 18 | 19 | Warning: PSI preceding token 'int' at col 14 in on line 1 20 | 21 | Warning: PSI offending token ';' at col 17 in on line 1 22 | ===DONE=== 23 | -------------------------------------------------------------------------------- /tests/parser/validate004.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | validate types 3 | --FILE-- 4 | ===TEST=== 5 | 8 | ===DONE=== 9 | --EXPECTF-- 10 | ===TEST=== 11 | ===DONE=== 12 | -------------------------------------------------------------------------------- /tests/parser/validate005.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | validate types 3 | --FILE-- 4 | ===TEST=== 5 | 16 | ===DONE=== 17 | --EXPECTF-- 18 | ===TEST=== 19 | 20 | Warning: Unknown variable 'X' in numeric expression in %s on line 4 21 | 22 | Warning: Invalid numeric expression: 'X' in %s on line 4 23 | ===DONE=== 24 | -------------------------------------------------------------------------------- /tests/parser/validate006.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | validate types 3 | --FILE-- 4 | ===TEST=== 5 | 8 | ===DONE=== 9 | --EXPECTF-- 10 | ===TEST=== 11 | ===DONE=== 12 | -------------------------------------------------------------------------------- /tests/parser/validate007.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | validate types 3 | --FILE-- 4 | ===TEST=== 5 | 38 | ===DONE=== 39 | --EXPECTF-- 40 | ===TEST=== 41 | ===DONE=== 42 | -------------------------------------------------------------------------------- /tests/pipe/pipe.psi: -------------------------------------------------------------------------------- 1 | #pragma lib "crypt" 2 | 3 | #include 4 | 5 | function \pipe(array &$fds = null) : int { 6 | return pipe(fildes) as to_int(pipe); 7 | let fildes = calloc(2, sizeof(int)); 8 | set $fds = to_array(*fildes, 2, to_int(*fildes)); 9 | } 10 | -------------------------------------------------------------------------------- /tests/pipe/pipe001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pipe 3 | --INI-- 4 | psi.directory={PWD} 5 | --FILE-- 6 | ===TEST=== 7 | 17 | ===DONE=== 18 | --EXPECT-- 19 | ===TEST=== 20 | int(0) 21 | string(13) "Hello World! 22 | " 23 | ===DONE=== -------------------------------------------------------------------------------- /tests/sqlite/sqlite.psi: -------------------------------------------------------------------------------- 1 | #pragma lib "sqlite3" 2 | 3 | #define NDEBUG 1 4 | 5 | typedef int (*my_sqlite3_callback)(void *data, int argc, char** argv, char** cols); 6 | extern int sqlite3_exec(sqlite3 *db, const char *sql, my_sqlite3_callback cb, void *data, char **errmsg); 7 | 8 | #include 9 | 10 | //extern const char *sqlite3_libversion(void); 11 | function sqlite3\version() : string { 12 | return to_string(sqlite3_libversion); 13 | } 14 | 15 | //extern const char *sqlite3_errstr(int err); 16 | function sqlite3\errstr(int $errno) : string { 17 | let err = intval($errno); 18 | return sqlite3_errstr(err) as to_string(sqlite3_errstr); 19 | } 20 | 21 | /* obviously fake, we ever always need a pointer to it */ 22 | //struct sqlite3; 23 | /* 24 | typedef struct sqlite3 sqlite3; 25 | 26 | typedef int64_t sqlite_int64; 27 | typedef uint64_t sqlite_uint64; 28 | 29 | typedef sqlite_int64 sqlite3_int64; 30 | typedef sqlite_uint64 sqlite3_uint64; 31 | 32 | extern void sqlite3_free(void *ptr); 33 | 34 | extern int sqlite3_close(sqlite3 *db); 35 | */ 36 | 37 | function sqlite3\close(object &$db) : int { 38 | let db = objval($db); 39 | return sqlite3_close(db) as to_int(sqlite3_close); 40 | // unset($db) as safe-guard 41 | set $db = void(db); 42 | } 43 | 44 | //extern int sqlite3_open(const char *filename, sqlite3 **db_ptr); 45 | function sqlite3\open(string $uri, object &$db) : int { 46 | let filename = pathval($uri); 47 | let db_ptr = &NULL; 48 | return sqlite3_open(filename, db_ptr) as to_int(sqlite3_open); 49 | set $db = to_object(*db_ptr); 50 | } 51 | 52 | 53 | function sqlite3\exec(object $db, string $sql, callable $cb, mixed $cd, string &$error = null) : int { 54 | let db = objval($db); 55 | let sql = strval($sql); 56 | let cb = callback(data, argc, argv, cols) as intval( 57 | $cb( 58 | zval(data), 59 | to_int(argc), 60 | to_array(*argv, argc, to_string(*argv)), 61 | to_array(*cols, argc, to_string(*cols)) 62 | ) 63 | ); 64 | let data = zval($cd); 65 | let errmsg = &NULL; 66 | return sqlite3_exec(db, sql, cb, data, errmsg) as to_int(sqlite3_exec); 67 | set $error = to_string(*errmsg); 68 | free sqlite3_free(*errmsg); 69 | } 70 | -------------------------------------------------------------------------------- /tests/sqlite/sqlite001.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m6w6/ext-psi/0682ecb84dfe1de08b609c6c0ae641b06f3fa481/tests/sqlite/sqlite001.db -------------------------------------------------------------------------------- /tests/sqlite/sqlite001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | sqlite3 3 | --INI-- 4 | psi.directory={PWD}:{PWD}/../../psi.d 5 | psi.blacklist.decls="sqlite3_str*,sqlite3_*serialize,sqlite3_stmt_scanstatus*,sqlite3_snapshot*,sqlite3_win32*,sqlite_normalize*" 6 | --FILE-- 7 | ===TEST=== 8 | row = $context->row ?? 0; 21 | 22 | for ($i = 0; $i < $argc; ++$i) { 23 | printf("%d: %s = %s\n", $context->row, $cols[$i], $argv[$i] ?? ""); 24 | } 25 | printf("\n"); 26 | ++$context->row; 27 | } 28 | 29 | $rc = sqlite3\exec($db, "SELECT * FROM test", "callback", new stdClass, $error); 30 | if ($rc) { 31 | printf("%s: '%s'\n", sqlite3\errstr($rc), $error); 32 | } 33 | 34 | $rc = sqlite3\exec($db, "INSERT INTO test VALUES (3,'three')", "callback", new stdClass, $error); 35 | if ($rc) { 36 | printf("%s: '%s'\n", sqlite3\errstr($rc), $error); 37 | } 38 | 39 | $rc = sqlite3\exec($db, "SELECT * FROM test", "callback", new stdClass, $error); 40 | if ($rc) { 41 | printf("%s: '%s'\n", sqlite3\errstr($rc), $error); 42 | } 43 | 44 | $rc = sqlite3\exec($db, "SELECT *", "callback", new stdClass, $error); 45 | if ($rc) { 46 | printf("%s: '%s'\n", sqlite3\errstr($rc), $error); 47 | } 48 | 49 | sqlite3\close($db); 50 | 51 | $rc = sqlite3\exec($db, "SELECT *", "callback", new stdClass, $error); 52 | if ($rc) { 53 | printf("%s: '%s'\n", sqlite3\errstr($rc), $error); 54 | } 55 | 56 | ?> 57 | ===DONE=== 58 | --EXPECTF-- 59 | ===TEST=== 60 | string(%d) "3.%d.%s" 61 | 0: id = 1 62 | 0: data = one 63 | 64 | 1: id = 2 65 | 1: data = two 66 | 67 | 0: id = 1 68 | 0: data = one 69 | 70 | 1: id = 2 71 | 1: data = two 72 | 73 | 2: id = 3 74 | 2: data = three 75 | 76 | SQL logic error%s 77 | %s: '' 78 | ===DONE=== 79 | --CLEAN-- 80 | 83 | -------------------------------------------------------------------------------- /tests/stat/stat001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | stat 3 | --INI-- 4 | psi.directory={PWD}/../../psi.d:{PWD} 5 | --SKIPIF-- 6 | 9 | --FILE-- 10 | ===TEST=== 11 | 14 | ===DONE=== 15 | --EXPECTF-- 16 | ===TEST=== 17 | int(0) 18 | array(13) { 19 | ["st_dev"]=> 20 | int(%d) 21 | ["st_ino"]=> 22 | int(%d) 23 | ["st_mode"]=> 24 | int(%d) 25 | ["st_nlink"]=> 26 | int(1) 27 | ["st_uid"]=> 28 | int(%d) 29 | ["st_gid"]=> 30 | int(%d) 31 | ["st_rdev"]=> 32 | int(%d) 33 | ["st_size"]=> 34 | int(75) 35 | ["st_atim"]=> 36 | array(2) { 37 | ["tv_sec"]=> 38 | int(1%d) 39 | ["tv_nsec"]=> 40 | int(%d) 41 | } 42 | ["st_mtim"]=> 43 | array(2) { 44 | ["tv_sec"]=> 45 | int(1%d) 46 | ["tv_nsec"]=> 47 | int(%d) 48 | } 49 | ["st_ctim"]=> 50 | array(2) { 51 | ["tv_sec"]=> 52 | int(1%d) 53 | ["tv_nsec"]=> 54 | int(%d) 55 | } 56 | ["st_blksize"]=> 57 | int(%d) 58 | ["st_blocks"]=> 59 | int(%d) 60 | } 61 | ===DONE=== 62 | -------------------------------------------------------------------------------- /tests/stat/stat002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | stat 3 | --INI-- 4 | psi.directory={PWD}/../../psi.d:{PWD} 5 | --SKIPIF-- 6 | 9 | --FILE-- 10 | ===TEST=== 11 | 14 | ===DONE=== 15 | --EXPECTF-- 16 | ===TEST=== 17 | int(0) 18 | array(20) { 19 | ["st_dev"]=> 20 | int(%d) 21 | ["st_ino"]=> 22 | int(%d) 23 | ["st_mode"]=> 24 | int(%d) 25 | ["st_nlink"]=> 26 | int(1) 27 | ["st_uid"]=> 28 | int(%d) 29 | ["st_gid"]=> 30 | int(%d) 31 | ["st_rdev"]=> 32 | int(%d) 33 | ["st_size"]=> 34 | int(75) 35 | ["st_atimespec"]=> 36 | array(2) { 37 | ["tv_sec"]=> 38 | int(1%d) 39 | ["tv_nsec"]=> 40 | int(%d) 41 | } 42 | ["st_atime"]=> 43 | int(1%d) 44 | ["st_mtimespec"]=> 45 | array(2) { 46 | ["tv_sec"]=> 47 | int(1%d) 48 | ["tv_nsec"]=> 49 | int(%d) 50 | } 51 | ["st_mtime"]=> 52 | int(1%d) 53 | ["st_ctimespec"]=> 54 | array(2) { 55 | ["tv_sec"]=> 56 | int(1%d) 57 | ["tv_nsec"]=> 58 | int(%d) 59 | } 60 | ["st_ctime"]=> 61 | int(1%d) 62 | ["st_birthtimespec"]=> 63 | array(2) { 64 | ["tv_sec"]=> 65 | int(1%d) 66 | ["tv_nsec"]=> 67 | int(%d) 68 | } 69 | ["st_birthtime"]=> 70 | int(1%d) 71 | ["st_blksize"]=> 72 | int(%d) 73 | ["st_blocks"]=> 74 | int(%d) 75 | ["st_flags"]=> 76 | int(%d) 77 | ["st_gen"]=> 78 | int(%d) 79 | } 80 | ===DONE=== 81 | -------------------------------------------------------------------------------- /tests/stdio/fopen001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | fopen 3 | --INI-- 4 | psi.directory={PWD}/../../psi.d:{PWD} 5 | --FILE-- 6 | ===TEST=== 7 | 13 | ===DONE=== 14 | --EXPECTF-- 15 | ===TEST=== 16 | bool(true) 17 | bool(true) 18 | int(0) 19 | ===DONE=== 20 | -------------------------------------------------------------------------------- /tests/stdio/printf001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | printf 3 | --ENV-- 4 | LC_ALL=C 5 | --INI-- 6 | psi.directory={PWD}/../../psi.d:{PWD} 7 | --FILE-- 8 | ===TEST=== 9 | 13 | ===DONE=== 14 | --EXPECT-- 15 | ===TEST=== 16 | hello 123456789 0.987654 17 | ===DONE=== 18 | -------------------------------------------------------------------------------- /tests/time/asc_gmtime001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | asctime/gmtime 3 | --ENV-- 4 | TZ=UTC 5 | --INI-- 6 | psi.directory = {PWD}/../../psi.d:{PWD} 7 | --FILE-- 8 | ===TEST=== 9 | getMessage(),"\n"; 14 | } 15 | var_dump(psi\gmtime(1)); 16 | var_dump(psi\asctime(psi\gmtime(1234567890))); 17 | var_dump(psi\asctime_r(psi\gmtime_r(1234567890))); 18 | ?> 19 | ===DONE=== 20 | --EXPECT-- 21 | ===TEST=== 22 | psi\asctime(): Argument #1 ($tm) must be of type array, null given 23 | array(9) { 24 | ["tm_sec"]=> 25 | int(1) 26 | ["tm_min"]=> 27 | int(0) 28 | ["tm_hour"]=> 29 | int(0) 30 | ["tm_mday"]=> 31 | int(1) 32 | ["tm_mon"]=> 33 | int(0) 34 | ["tm_year"]=> 35 | int(70) 36 | ["tm_wday"]=> 37 | int(4) 38 | ["tm_yday"]=> 39 | int(0) 40 | ["tm_isdst"]=> 41 | int(0) 42 | } 43 | string(25) "Fri Feb 13 23:31:30 2009 44 | " 45 | string(25) "Fri Feb 13 23:31:30 2009 46 | " 47 | ===DONE=== 48 | -------------------------------------------------------------------------------- /tests/time/gettimeofday001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | gettimeofday 3 | --INI-- 4 | psi.directory = {PWD}/../../psi.d:{PWD} 5 | --ENV-- 6 | TZ=UTC 7 | --FILE-- 8 | ===TEST=== 9 | 19 | ===DONE=== 20 | --EXPECTF-- 21 | ===TEST=== 22 | array(4) { 23 | ["sec"]=> 24 | int(1%d) 25 | ["usec"]=> 26 | int(%d) 27 | ["minuteswest"]=> 28 | int(%i) 29 | ["dsttime"]=> 30 | int(%i) 31 | } 32 | int(0) 33 | int(0) 34 | array(2) { 35 | ["tv_sec"]=> 36 | int(1%d) 37 | ["tv_usec"]=> 38 | int(%d) 39 | } 40 | bool(true) 41 | ===DONE=== 42 | -------------------------------------------------------------------------------- /tests/time/nanosleep001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | nanosleep 3 | --ENV-- 4 | TZ=UTC 5 | --INI-- 6 | psi.directory = {PWD}/../../psi.d:{PWD} 7 | --FILE-- 8 | ===TEST=== 9 | 10000000], $rm), $rm); 12 | var_dump(psi\gettimeofday($tv2), $tv2); 13 | var_dump($tv2["tv_usec"]-$tv1["tv_usec"]); 14 | ?> 15 | ===DONE=== 16 | --EXPECTF-- 17 | ===TEST=== 18 | int(0) 19 | array(2) { 20 | ["tv_sec"]=> 21 | int(1%d) 22 | ["tv_usec"]=> 23 | int(%d) 24 | } 25 | int(0) 26 | array(2) { 27 | ["tv_sec"]=> 28 | int(0) 29 | ["tv_nsec"]=> 30 | int(0) 31 | } 32 | int(0) 33 | array(2) { 34 | ["tv_sec"]=> 35 | int(%d) 36 | ["tv_usec"]=> 37 | int(%d) 38 | } 39 | int(%r\d\d\d\d\d%r) 40 | ===DONE=== 41 | -------------------------------------------------------------------------------- /tests/time/times001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | times 3 | --INI-- 4 | psi.directory={PWD}/../../psi.d:{PWD} 5 | --FILE-- 6 | ===TEST=== 7 | 12 | ===DONE=== 13 | --EXPECTF-- 14 | ===TEST=== 15 | int(%d) 16 | array(4) { 17 | ["tms_utime"]=> 18 | int(%d) 19 | ["tms_stime"]=> 20 | int(%d) 21 | ["tms_cutime"]=> 22 | int(%d) 23 | ["tms_cstime"]=> 24 | int(%d) 25 | } 26 | ===DONE=== 27 | -------------------------------------------------------------------------------- /tests/time/tzname001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | tzname 3 | --INI-- 4 | psi.directory={PWD}/../../psi.d:{PWD} 5 | date.timezone=CET 6 | --ENV-- 7 | TZ=CET 8 | --FILE-- 9 | ===TEST=== 10 | 13 | ===DONE=== 14 | --EXPECTF-- 15 | ===TEST=== 16 | NULL 17 | array(2) { 18 | [0]=> 19 | string(3) "CET" 20 | [1]=> 21 | string(4) "CEST" 22 | } 23 | ===DONE=== 24 | -------------------------------------------------------------------------------- /tests/uname/uname001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | uname 3 | --INI-- 4 | psi.directory={PWD}/../../psi.d:{PWD} 5 | --SKIPIF-- 6 | 9 | --FILE-- 10 | ===TEST=== 11 | 14 | ===DONE=== 15 | --EXPECTF-- 16 | ===TEST=== 17 | int(0) 18 | array(6) { 19 | ["sysname"]=> 20 | string(5) "Linux" 21 | ["nodename"]=> 22 | string(%d) "%s" 23 | ["release"]=> 24 | string(%d) "%s" 25 | ["version"]=> 26 | string(%d) "%s" 27 | ["machine"]=> 28 | string(%d) "%s" 29 | ["domainname"]=> 30 | string(%d) "%s" 31 | } 32 | ===DONE=== 33 | -------------------------------------------------------------------------------- /tests/uname/uname002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | uname 3 | --INI-- 4 | psi.directory={PWD}/../../psi.d:{PWD} 5 | --SKIPIF-- 6 | 9 | --FILE-- 10 | ===TEST=== 11 | 14 | ===DONE=== 15 | --EXPECTF-- 16 | ===TEST=== 17 | int(0) 18 | array(5) { 19 | ["sysname"]=> 20 | string(6) "Darwin" 21 | ["nodename"]=> 22 | string(%d) "%s" 23 | ["release"]=> 24 | string(%d) "%s" 25 | ["version"]=> 26 | string(%d) "%s" 27 | ["machine"]=> 28 | string(%d) "%s" 29 | } 30 | ===DONE=== 31 | -------------------------------------------------------------------------------- /tests/yaml/yaml.psi: -------------------------------------------------------------------------------- 1 | #pragma lib "yaml" 2 | #pragma lib "crypt" 3 | 4 | #include 5 | -------------------------------------------------------------------------------- /tests/yaml/yaml001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | yaml 3 | --INI-- 4 | psi.directory={PWD}:{PWD}/../../psi.d 5 | --FILE-- 6 | ===TEST=== 7 | ===DONE=== 8 | --EXPECT-- 9 | ===TEST=== 10 | ===DONE=== 11 | --------------------------------------------------------------------------------