From 33886f710cd45fd883d85558197e2df4eaba9ea1 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 18 Jun 2019 11:33:07 +0200 Subject: Generate arginfo from PHP stub files Signature stubs for internal functions are specified in xyz.stub.php, from which we generate actual arginfo structures in xyz_arginfo.h. This file then needs to be included in the implementation appropriately. Arginfo from stubs can be regenerated using scripts/dev/gen_stub.php. However, this should also automatically happen when the stub file is modified. --- .gitignore | 3 + Zend/zend_builtin_functions.c | 189 ++----------- Zend/zend_builtin_functions.stub.php | 123 +++++++++ Zend/zend_builtin_functions_arginfo.h | 198 ++++++++++++++ build/Makefile.global | 6 + ext/date/php_date.c | 480 +++++---------------------------- ext/date/php_date.stub.php | 310 +++++++++++++++++++++ ext/date/php_date_arginfo.h | 356 ++++++++++++++++++++++++ ext/standard/basic_functions.c | 7 +- ext/standard/basic_functions.stub.php | 4 + ext/standard/basic_functions_arginfo.h | 6 + scripts/dev/gen_stub.php | 380 ++++++++++++++++++++++++++ 12 files changed, 1484 insertions(+), 578 deletions(-) create mode 100644 Zend/zend_builtin_functions.stub.php create mode 100644 Zend/zend_builtin_functions_arginfo.h create mode 100644 ext/date/php_date.stub.php create mode 100644 ext/date/php_date_arginfo.h create mode 100644 ext/standard/basic_functions.stub.php create mode 100644 ext/standard/basic_functions_arginfo.h create mode 100755 scripts/dev/gen_stub.php diff --git a/.gitignore b/.gitignore index 58cc8ecbb6..fbe8c113b2 100644 --- a/.gitignore +++ b/.gitignore @@ -80,6 +80,9 @@ include/ libs/ modules/ +# Used by scripts/dev/gen_stub.php +scripts/dev/PHP-Parser-* + # ------------------------------------------------------------------------------ # Configuration headers generated by the PHP build system # ------------------------------------------------------------------------------ diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index ce939f6489..be566ae681 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -85,154 +85,15 @@ static ZEND_FUNCTION(gc_enable); static ZEND_FUNCTION(gc_disable); static ZEND_FUNCTION(gc_status); -/* {{{ arginfo */ -ZEND_BEGIN_ARG_INFO(arginfo_zend__void, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_func_get_arg, 0, 0, 1) - ZEND_ARG_TYPE_INFO(0, arg_num, IS_LONG, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_strlen, 0, 1, IS_LONG, 0) - ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_strcmp, 0, 2, IS_LONG, 0) - ZEND_ARG_TYPE_INFO(0, str1, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, str2, IS_STRING, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_strncmp, 0, 0, 3) - ZEND_ARG_TYPE_INFO(0, str1, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, str2, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, len, IS_LONG, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_error_reporting, 0, 0, 0) - ZEND_ARG_INFO(0, new_error_level) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_define, 0, 0, 2) - ZEND_ARG_INFO(0, constant_name) - ZEND_ARG_INFO(0, value) - ZEND_ARG_INFO(0, case_insensitive) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_defined, 0, 0, 1) - ZEND_ARG_INFO(0, constant_name) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_get_class, 0, 0, 0) - ZEND_ARG_INFO(0, object) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_is_subclass_of, 0, 0, 2) - ZEND_ARG_INFO(0, object) - ZEND_ARG_INFO(0, class_name) - ZEND_ARG_INFO(0, allow_string) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_get_class_vars, 0, 0, 1) - ZEND_ARG_INFO(0, class_name) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_get_object_vars, 0, 1, IS_ARRAY, 0) - ZEND_ARG_INFO(0, obj) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_get_mangled_object_vars, 0, 0, 1) - ZEND_ARG_INFO(0, obj) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_get_class_methods, 0, 0, 1) - ZEND_ARG_INFO(0, class) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_method_exists, 0, 0, 2) - ZEND_ARG_INFO(0, object) - ZEND_ARG_INFO(0, method) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_property_exists, 0, 0, 2) - ZEND_ARG_INFO(0, object_or_class) - ZEND_ARG_INFO(0, property_name) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_class_exists, 0, 0, 1) - ZEND_ARG_INFO(0, classname) - ZEND_ARG_INFO(0, autoload) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_trait_exists, 0, 0, 1) - ZEND_ARG_INFO(0, traitname) - ZEND_ARG_INFO(0, autoload) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_function_exists, 0, 0, 1) - ZEND_ARG_INFO(0, function_name) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_class_alias, 0, 0, 2) - ZEND_ARG_INFO(0, user_class_name) - ZEND_ARG_INFO(0, alias_name) - ZEND_ARG_INFO(0, autoload) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_trigger_error, 0, 0, 1) - ZEND_ARG_INFO(0, message) - ZEND_ARG_INFO(0, error_type) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_set_error_handler, 0, 0, 1) - ZEND_ARG_INFO(0, error_handler) - ZEND_ARG_INFO(0, error_types) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_set_exception_handler, 0, 0, 1) - ZEND_ARG_INFO(0, exception_handler) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_get_defined_functions, 0, 0, 0) - ZEND_ARG_INFO(0, exclude_disabled) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_get_resource_type, 0, 0, 1) - ZEND_ARG_INFO(0, res) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_get_resources, 0, 0, 0) - ZEND_ARG_INFO(0, type) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_get_loaded_extensions, 0, 0, 0) - ZEND_ARG_INFO(0, zend_extensions) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_get_defined_constants, 0, 0, 0) - ZEND_ARG_INFO(0, categorize) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_debug_backtrace, 0, 0, 0) - ZEND_ARG_INFO(0, options) - ZEND_ARG_INFO(0, limit) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_debug_print_backtrace, 0, 0, 0) - ZEND_ARG_INFO(0, options) - ZEND_ARG_INFO(0, limit) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_extension_loaded, 0, 0, 1) - ZEND_ARG_INFO(0, extension_name) -ZEND_END_ARG_INFO() +#include "zend_builtin_functions_arginfo.h" /* }}} */ static const zend_function_entry builtin_functions[] = { /* {{{ */ - ZEND_FE(zend_version, arginfo_zend__void) - ZEND_FE(func_num_args, arginfo_zend__void) + ZEND_FE(zend_version, arginfo_zend_version) + ZEND_FE(func_num_args, arginfo_func_num_args) ZEND_FE(func_get_arg, arginfo_func_get_arg) - ZEND_FE(func_get_args, arginfo_zend__void) + ZEND_FE(func_get_args, arginfo_func_get_args) ZEND_FE(strlen, arginfo_strlen) ZEND_FE(strcmp, arginfo_strcmp) ZEND_FE(strncmp, arginfo_strncmp) @@ -242,51 +103,51 @@ static const zend_function_entry builtin_functions[] = { /* {{{ */ ZEND_FE(define, arginfo_define) ZEND_FE(defined, arginfo_defined) ZEND_FE(get_class, arginfo_get_class) - ZEND_FE(get_called_class, arginfo_zend__void) - ZEND_FE(get_parent_class, arginfo_get_class) + ZEND_FE(get_called_class, arginfo_get_called_class) + ZEND_FE(get_parent_class, arginfo_get_parent_class) ZEND_FE(method_exists, arginfo_method_exists) ZEND_FE(property_exists, arginfo_property_exists) ZEND_FE(class_exists, arginfo_class_exists) - ZEND_FE(interface_exists, arginfo_class_exists) + ZEND_FE(interface_exists, arginfo_interface_exists) ZEND_FE(trait_exists, arginfo_trait_exists) ZEND_FE(function_exists, arginfo_function_exists) ZEND_FE(class_alias, arginfo_class_alias) - ZEND_FE(get_included_files, arginfo_zend__void) - ZEND_FALIAS(get_required_files, get_included_files, arginfo_zend__void) + ZEND_FE(get_included_files, arginfo_get_included_files) + ZEND_FALIAS(get_required_files, get_included_files, arginfo_get_required_files) ZEND_FE(is_subclass_of, arginfo_is_subclass_of) - ZEND_FE(is_a, arginfo_is_subclass_of) + ZEND_FE(is_a, arginfo_is_a) ZEND_FE(get_class_vars, arginfo_get_class_vars) ZEND_FE(get_object_vars, arginfo_get_object_vars) ZEND_FE(get_mangled_object_vars, arginfo_get_mangled_object_vars) ZEND_FE(get_class_methods, arginfo_get_class_methods) ZEND_FE(trigger_error, arginfo_trigger_error) - ZEND_FALIAS(user_error, trigger_error, arginfo_trigger_error) + ZEND_FALIAS(user_error, trigger_error, arginfo_user_error) ZEND_FE(set_error_handler, arginfo_set_error_handler) - ZEND_FE(restore_error_handler, arginfo_zend__void) + ZEND_FE(restore_error_handler, arginfo_restore_error_handler) ZEND_FE(set_exception_handler, arginfo_set_exception_handler) - ZEND_FE(restore_exception_handler, arginfo_zend__void) - ZEND_FE(get_declared_classes, arginfo_zend__void) - ZEND_FE(get_declared_traits, arginfo_zend__void) - ZEND_FE(get_declared_interfaces, arginfo_zend__void) + ZEND_FE(restore_exception_handler, arginfo_restore_exception_handler) + ZEND_FE(get_declared_classes, arginfo_get_declared_classes) + ZEND_FE(get_declared_traits, arginfo_get_declared_traits) + ZEND_FE(get_declared_interfaces, arginfo_get_declared_interfaces) ZEND_FE(get_defined_functions, arginfo_get_defined_functions) - ZEND_FE(get_defined_vars, arginfo_zend__void) + ZEND_FE(get_defined_vars, arginfo_get_defined_vars) ZEND_FE(get_resource_type, arginfo_get_resource_type) ZEND_FE(get_resources, arginfo_get_resources) ZEND_FE(get_loaded_extensions, arginfo_get_loaded_extensions) ZEND_FE(extension_loaded, arginfo_extension_loaded) - ZEND_FE(get_extension_funcs, arginfo_extension_loaded) + ZEND_FE(get_extension_funcs, arginfo_get_extension_funcs) ZEND_FE(get_defined_constants, arginfo_get_defined_constants) ZEND_FE(debug_backtrace, arginfo_debug_backtrace) ZEND_FE(debug_print_backtrace, arginfo_debug_print_backtrace) #if ZEND_DEBUG && defined(ZTS) - ZEND_FE(zend_thread_id, NULL) + ZEND_FE(zend_thread_id, arginfo_zend_thread_id) #endif - ZEND_FE(gc_mem_caches, arginfo_zend__void) - ZEND_FE(gc_collect_cycles, arginfo_zend__void) - ZEND_FE(gc_enabled, arginfo_zend__void) - ZEND_FE(gc_enable, arginfo_zend__void) - ZEND_FE(gc_disable, arginfo_zend__void) - ZEND_FE(gc_status, arginfo_zend__void) + ZEND_FE(gc_mem_caches, arginfo_gc_mem_caches) + ZEND_FE(gc_collect_cycles, arginfo_gc_collect_cycles) + ZEND_FE(gc_enabled, arginfo_gc_enabled) + ZEND_FE(gc_enable, arginfo_gc_enable) + ZEND_FE(gc_disable, arginfo_gc_disable) + ZEND_FE(gc_status, arginfo_gc_status) ZEND_FE_END }; /* }}} */ diff --git a/Zend/zend_builtin_functions.stub.php b/Zend/zend_builtin_functions.stub.php new file mode 100644 index 0000000000..deb9ac9294 --- /dev/null +++ b/Zend/zend_builtin_functions.stub.php @@ -0,0 +1,123 @@ +/dev/null 2>/dev/null; then php scripts/dev/gen_stub.php $<; fi + +# As we don't track includes, this is just a heuristic +%.c: %_arginfo.h + touch $@ .PHONY: all clean install distclean test prof-gen prof-clean prof-use .NOEXPORT: diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 1335ce6858..aa457065d4 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -76,345 +76,7 @@ PHPAPI time_t php_time() #endif } -/* {{{ arginfo */ -ZEND_BEGIN_ARG_INFO_EX(arginfo_date, 0, 0, 1) - ZEND_ARG_INFO(0, format) - ZEND_ARG_INFO(0, timestamp) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_gmdate, 0, 0, 1) - ZEND_ARG_INFO(0, format) - ZEND_ARG_INFO(0, timestamp) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_idate, 0, 0, 1) - ZEND_ARG_INFO(0, format) - ZEND_ARG_INFO(0, timestamp) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_strtotime, 0, 0, 1) - ZEND_ARG_INFO(0, time) - ZEND_ARG_INFO(0, now) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_mktime, 0, 0, 1) - ZEND_ARG_INFO(0, hour) - ZEND_ARG_INFO(0, min) - ZEND_ARG_INFO(0, sec) - ZEND_ARG_INFO(0, mon) - ZEND_ARG_INFO(0, day) - ZEND_ARG_INFO(0, year) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_gmmktime, 0, 0, 1) - ZEND_ARG_INFO(0, hour) - ZEND_ARG_INFO(0, min) - ZEND_ARG_INFO(0, sec) - ZEND_ARG_INFO(0, mon) - ZEND_ARG_INFO(0, day) - ZEND_ARG_INFO(0, year) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_checkdate, 0) - ZEND_ARG_INFO(0, month) - ZEND_ARG_INFO(0, day) - ZEND_ARG_INFO(0, year) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_strftime, 0, 0, 1) - ZEND_ARG_INFO(0, format) - ZEND_ARG_INFO(0, timestamp) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_gmstrftime, 0, 0, 1) - ZEND_ARG_INFO(0, format) - ZEND_ARG_INFO(0, timestamp) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_time, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_localtime, 0, 0, 0) - ZEND_ARG_INFO(0, timestamp) - ZEND_ARG_INFO(0, associative_array) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_getdate, 0, 0, 0) - ZEND_ARG_INFO(0, timestamp) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_date_default_timezone_set, 0) - ZEND_ARG_INFO(0, timezone_identifier) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_date_default_timezone_get, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_sunrise, 0, 0, 1) - ZEND_ARG_INFO(0, time) - ZEND_ARG_INFO(0, format) - ZEND_ARG_INFO(0, latitude) - ZEND_ARG_INFO(0, longitude) - ZEND_ARG_INFO(0, zenith) - ZEND_ARG_INFO(0, gmt_offset) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_sunset, 0, 0, 1) - ZEND_ARG_INFO(0, time) - ZEND_ARG_INFO(0, format) - ZEND_ARG_INFO(0, latitude) - ZEND_ARG_INFO(0, longitude) - ZEND_ARG_INFO(0, zenith) - ZEND_ARG_INFO(0, gmt_offset) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_date_sun_info, 0) - ZEND_ARG_INFO(0, time) - ZEND_ARG_INFO(0, latitude) - ZEND_ARG_INFO(0, longitude) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_create, 0, 0, 0) - ZEND_ARG_INFO(0, time) - ZEND_ARG_INFO(0, timezone) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_create_from_format, 0, 0, 2) - ZEND_ARG_INFO(0, format) - ZEND_ARG_INFO(0, time) - ZEND_ARG_OBJ_INFO(0, object, DateTimeZone, 1) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_parse, 0, 0, 1) - ZEND_ARG_INFO(0, date) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_parse_from_format, 0, 0, 2) - ZEND_ARG_INFO(0, format) - ZEND_ARG_INFO(0, date) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_date_get_last_errors, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_format, 0, 0, 2) - ZEND_ARG_INFO(0, object) - ZEND_ARG_INFO(0, format) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_method_format, 0, 0, 1) - ZEND_ARG_INFO(0, format) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_modify, 0, 0, 2) - ZEND_ARG_INFO(0, object) - ZEND_ARG_INFO(0, modify) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_method_modify, 0, 0, 1) - ZEND_ARG_INFO(0, modify) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_add, 0, 0, 2) - ZEND_ARG_INFO(0, object) - ZEND_ARG_INFO(0, interval) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_method_add, 0, 0, 1) - ZEND_ARG_INFO(0, interval) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_sub, 0, 0, 2) - ZEND_ARG_INFO(0, object) - ZEND_ARG_INFO(0, interval) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_method_sub, 0, 0, 1) - ZEND_ARG_INFO(0, interval) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_timezone_get, 0, 0, 1) - ZEND_ARG_INFO(0, object) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_date_method_timezone_get, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_timezone_set, 0, 0, 2) - ZEND_ARG_INFO(0, object) - ZEND_ARG_INFO(0, timezone) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_method_timezone_set, 0, 0, 1) - ZEND_ARG_INFO(0, timezone) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_offset_get, 0, 0, 1) - ZEND_ARG_INFO(0, object) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_date_method_offset_get, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_diff, 0, 0, 2) - ZEND_ARG_INFO(0, object) - ZEND_ARG_INFO(0, object2) - ZEND_ARG_INFO(0, absolute) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_method_diff, 0, 0, 1) - ZEND_ARG_INFO(0, object) - ZEND_ARG_INFO(0, absolute) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_time_set, 0, 0, 3) - ZEND_ARG_INFO(0, object) - ZEND_ARG_INFO(0, hour) - ZEND_ARG_INFO(0, minute) - ZEND_ARG_INFO(0, second) - ZEND_ARG_INFO(0, microseconds) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_method_time_set, 0, 0, 2) - ZEND_ARG_INFO(0, hour) - ZEND_ARG_INFO(0, minute) - ZEND_ARG_INFO(0, second) - ZEND_ARG_INFO(0, microseconds) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_date_set, 0, 0, 4) - ZEND_ARG_INFO(0, object) - ZEND_ARG_INFO(0, year) - ZEND_ARG_INFO(0, month) - ZEND_ARG_INFO(0, day) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_method_date_set, 0, 0, 3) - ZEND_ARG_INFO(0, year) - ZEND_ARG_INFO(0, month) - ZEND_ARG_INFO(0, day) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_isodate_set, 0, 0, 3) - ZEND_ARG_INFO(0, object) - ZEND_ARG_INFO(0, year) - ZEND_ARG_INFO(0, week) - ZEND_ARG_INFO(0, day) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_method_isodate_set, 0, 0, 2) - ZEND_ARG_INFO(0, year) - ZEND_ARG_INFO(0, week) - ZEND_ARG_INFO(0, day) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_timestamp_set, 0, 0, 2) - ZEND_ARG_INFO(0, object) - ZEND_ARG_INFO(0, unixtimestamp) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_method_timestamp_set, 0, 0, 1) - ZEND_ARG_INFO(0, unixtimestamp) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_timestamp_get, 0, 0, 1) - ZEND_ARG_INFO(0, object) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_date_method_timestamp_get, 0) -ZEND_END_ARG_INFO() - - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_method_create_from_immutable, 0, 0, 1) - ZEND_ARG_INFO(0, DateTimeImmutable) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_method_create_from_mutable, 0, 0, 1) - ZEND_ARG_INFO(0, DateTime) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_timezone_open, 0, 0, 1) - ZEND_ARG_INFO(0, timezone) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_timezone_name_get, 0, 0, 1) - ZEND_ARG_INFO(0, object) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_timezone_method_name_get, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_timezone_name_from_abbr, 0, 0, 1) - ZEND_ARG_INFO(0, abbr) - ZEND_ARG_INFO(0, gmtoffset) - ZEND_ARG_INFO(0, isdst) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_timezone_offset_get, 0, 0, 2) - ZEND_ARG_OBJ_INFO(0, object, DateTimeZone, 0) - ZEND_ARG_OBJ_INFO(0, datetime, DateTimeInterface, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_timezone_method_offset_get, 0, 0, 1) - ZEND_ARG_INFO(0, object) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_timezone_transitions_get, 0, 0, 1) - ZEND_ARG_INFO(0, object) - ZEND_ARG_INFO(0, timestamp_begin) - ZEND_ARG_INFO(0, timestamp_end) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_timezone_method_transitions_get, 0, 0, 0) - ZEND_ARG_INFO(0, timestamp_begin) - ZEND_ARG_INFO(0, timestamp_end) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_timezone_location_get, 0, 0, 1) - ZEND_ARG_INFO(0, object) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_timezone_method_location_get, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_timezone_identifiers_list, 0, 0, 0) - ZEND_ARG_INFO(0, what) - ZEND_ARG_INFO(0, country) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_timezone_abbreviations_list, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_timezone_version_get, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_interval_create_from_date_string, 0, 0, 1) - ZEND_ARG_INFO(0, time) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_interval_format, 0, 0, 2) - ZEND_ARG_INFO(0, object) - ZEND_ARG_INFO(0, format) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_date_method_interval_format, 0) - ZEND_ARG_INFO(0, format) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_period_construct, 0, 0, 3) - ZEND_ARG_INFO(0, start) - ZEND_ARG_INFO(0, interval) - ZEND_ARG_INFO(0, end) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_set_state, 0, 0, 1) - ZEND_ARG_ARRAY_INFO(0, array, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_date_interval_construct, 0, 0, 1) - ZEND_ARG_INFO(0, interval_spec) -ZEND_END_ARG_INFO() -/* }}} */ +#include "php_date_arginfo.h" /* {{{ Function table */ static const zend_function_entry date_functions[] = { @@ -479,91 +141,91 @@ static const zend_function_entry date_functions[] = { }; static const zend_function_entry date_funcs_interface[] = { - PHP_ABSTRACT_ME(DateTimeInterface, format, arginfo_date_method_format) - PHP_ABSTRACT_ME(DateTimeInterface, getTimezone, arginfo_date_method_timezone_get) - PHP_ABSTRACT_ME(DateTimeInterface, getOffset, arginfo_date_method_offset_get) - PHP_ABSTRACT_ME(DateTimeInterface, getTimestamp, arginfo_date_method_timestamp_get) - PHP_ABSTRACT_ME(DateTimeInterface, diff, arginfo_date_method_diff) - PHP_ABSTRACT_ME(DateTimeInterface, __wakeup, NULL) + PHP_ABSTRACT_ME(DateTimeInterface, format, arginfo_DateTimeInterface_format) + PHP_ABSTRACT_ME(DateTimeInterface, getTimezone, arginfo_DateTimeInterface_getTimezone) + PHP_ABSTRACT_ME(DateTimeInterface, getOffset, arginfo_DateTimeInterface_getOffset) + PHP_ABSTRACT_ME(DateTimeInterface, getTimestamp, arginfo_DateTimeInterface_getTimestamp) + PHP_ABSTRACT_ME(DateTimeInterface, diff, arginfo_DateTimeInterface_diff) + PHP_ABSTRACT_ME(DateTimeInterface, __wakeup, arginfo_DateTimeInterface___wakeup) PHP_FE_END }; static const zend_function_entry date_funcs_date[] = { - PHP_ME(DateTime, __construct, arginfo_date_create, ZEND_ACC_PUBLIC) - PHP_ME(DateTime, __wakeup, NULL, ZEND_ACC_PUBLIC) - PHP_ME(DateTime, __set_state, arginfo_date_set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - PHP_ME(DateTime, createFromImmutable, arginfo_date_method_create_from_immutable, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - PHP_ME_MAPPING(createFromFormat, date_create_from_format, arginfo_date_create_from_format, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - PHP_ME_MAPPING(getLastErrors, date_get_last_errors, arginfo_date_get_last_errors, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - PHP_ME_MAPPING(format, date_format, arginfo_date_method_format, 0) - PHP_ME_MAPPING(modify, date_modify, arginfo_date_method_modify, 0) - PHP_ME_MAPPING(add, date_add, arginfo_date_method_add, 0) - PHP_ME_MAPPING(sub, date_sub, arginfo_date_method_sub, 0) - PHP_ME_MAPPING(getTimezone, date_timezone_get, arginfo_date_method_timezone_get, 0) - PHP_ME_MAPPING(setTimezone, date_timezone_set, arginfo_date_method_timezone_set, 0) - PHP_ME_MAPPING(getOffset, date_offset_get, arginfo_date_method_offset_get, 0) - PHP_ME_MAPPING(setTime, date_time_set, arginfo_date_method_time_set, 0) - PHP_ME_MAPPING(setDate, date_date_set, arginfo_date_method_date_set, 0) - PHP_ME_MAPPING(setISODate, date_isodate_set, arginfo_date_method_isodate_set, 0) - PHP_ME_MAPPING(setTimestamp, date_timestamp_set, arginfo_date_method_timestamp_set, 0) - PHP_ME_MAPPING(getTimestamp, date_timestamp_get, arginfo_date_method_timestamp_get, 0) - PHP_ME_MAPPING(diff, date_diff, arginfo_date_method_diff, 0) + PHP_ME(DateTime, __construct, arginfo_DateTime___construct, ZEND_ACC_PUBLIC) + PHP_ME(DateTime, __wakeup, arginfo_DateTimeInterface___wakeup, ZEND_ACC_PUBLIC) + PHP_ME(DateTime, __set_state, arginfo_DateTime___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + PHP_ME(DateTime, createFromImmutable, arginfo_DateTime_createFromImmutable, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + PHP_ME_MAPPING(createFromFormat, date_create_from_format, arginfo_DateTime_createFromFormat, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + PHP_ME_MAPPING(getLastErrors, date_get_last_errors, arginfo_DateTime_getLastErrors, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + PHP_ME_MAPPING(format, date_format, arginfo_DateTimeInterface_format, 0) + PHP_ME_MAPPING(modify, date_modify, arginfo_DateTime_modify, 0) + PHP_ME_MAPPING(add, date_add, arginfo_DateTime_add, 0) + PHP_ME_MAPPING(sub, date_sub, arginfo_DateTime_sub, 0) + PHP_ME_MAPPING(getTimezone, date_timezone_get, arginfo_DateTimeInterface_getTimezone, 0) + PHP_ME_MAPPING(setTimezone, date_timezone_set, arginfo_DateTime_setTimezone, 0) + PHP_ME_MAPPING(getOffset, date_offset_get, arginfo_DateTimeInterface_getOffset, 0) + PHP_ME_MAPPING(setTime, date_time_set, arginfo_DateTime_setTime, 0) + PHP_ME_MAPPING(setDate, date_date_set, arginfo_DateTime_setDate, 0) + PHP_ME_MAPPING(setISODate, date_isodate_set, arginfo_DateTime_setISODate, 0) + PHP_ME_MAPPING(setTimestamp, date_timestamp_set, arginfo_DateTime_setTimestamp, 0) + PHP_ME_MAPPING(getTimestamp, date_timestamp_get, arginfo_DateTimeInterface_getTimestamp, 0) + PHP_ME_MAPPING(diff, date_diff, arginfo_DateTimeInterface_diff, 0) PHP_FE_END }; static const zend_function_entry date_funcs_immutable[] = { - PHP_ME(DateTimeImmutable, __construct, arginfo_date_create, ZEND_ACC_PUBLIC) - PHP_ME(DateTime, __wakeup, NULL, ZEND_ACC_PUBLIC) - PHP_ME(DateTimeImmutable, __set_state, arginfo_date_set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + PHP_ME(DateTimeImmutable, __construct, arginfo_DateTimeImmutable___construct, ZEND_ACC_PUBLIC) + PHP_ME(DateTime, __wakeup, arginfo_DateTimeInterface___wakeup, ZEND_ACC_PUBLIC) + PHP_ME(DateTimeImmutable, __set_state, arginfo_DateTimeImmutable___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_ME_MAPPING(createFromFormat, date_create_immutable_from_format, arginfo_date_create_from_format, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_ME_MAPPING(getLastErrors, date_get_last_errors, arginfo_date_get_last_errors, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - PHP_ME_MAPPING(format, date_format, arginfo_date_method_format, 0) - PHP_ME_MAPPING(getTimezone, date_timezone_get, arginfo_date_method_timezone_get, 0) - PHP_ME_MAPPING(getOffset, date_offset_get, arginfo_date_method_offset_get, 0) - PHP_ME_MAPPING(getTimestamp, date_timestamp_get, arginfo_date_method_timestamp_get, 0) - PHP_ME_MAPPING(diff, date_diff, arginfo_date_method_diff, 0) - PHP_ME(DateTimeImmutable, modify, arginfo_date_method_modify, 0) - PHP_ME(DateTimeImmutable, add, arginfo_date_method_add, 0) - PHP_ME(DateTimeImmutable, sub, arginfo_date_method_sub, 0) - PHP_ME(DateTimeImmutable, setTimezone, arginfo_date_method_timezone_set, 0) - PHP_ME(DateTimeImmutable, setTime, arginfo_date_method_time_set, 0) - PHP_ME(DateTimeImmutable, setDate, arginfo_date_method_date_set, 0) - PHP_ME(DateTimeImmutable, setISODate, arginfo_date_method_isodate_set, 0) - PHP_ME(DateTimeImmutable, setTimestamp, arginfo_date_method_timestamp_set, 0) - PHP_ME(DateTimeImmutable, createFromMutable, arginfo_date_method_create_from_mutable, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + PHP_ME_MAPPING(format, date_format, arginfo_DateTimeInterface_format, 0) + PHP_ME_MAPPING(getTimezone, date_timezone_get, arginfo_DateTimeInterface_getTimezone, 0) + PHP_ME_MAPPING(getOffset, date_offset_get, arginfo_DateTimeInterface_getOffset, 0) + PHP_ME_MAPPING(getTimestamp, date_timestamp_get, arginfo_DateTimeInterface_getTimestamp, 0) + PHP_ME_MAPPING(diff, date_diff, arginfo_DateTimeInterface_diff, 0) + PHP_ME(DateTimeImmutable, modify, arginfo_DateTimeImmutable_modify, 0) + PHP_ME(DateTimeImmutable, add, arginfo_DateTimeImmutable_add, 0) + PHP_ME(DateTimeImmutable, sub, arginfo_DateTimeImmutable_sub, 0) + PHP_ME(DateTimeImmutable, setTimezone, arginfo_DateTimeImmutable_setTimezone, 0) + PHP_ME(DateTimeImmutable, setTime, arginfo_DateTimeImmutable_setTime, 0) + PHP_ME(DateTimeImmutable, setDate, arginfo_DateTimeImmutable_setDate, 0) + PHP_ME(DateTimeImmutable, setISODate, arginfo_DateTimeImmutable_setISODate, 0) + PHP_ME(DateTimeImmutable, setTimestamp, arginfo_DateTimeImmutable_setTimestamp, 0) + PHP_ME(DateTimeImmutable, createFromMutable, arginfo_DateTimeImmutable_createFromMutable, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_FE_END }; static const zend_function_entry date_funcs_timezone[] = { - PHP_ME(DateTimeZone, __construct, arginfo_timezone_open, ZEND_ACC_PUBLIC) - PHP_ME(DateTimeZone, __wakeup, NULL, ZEND_ACC_PUBLIC) - PHP_ME(DateTimeZone, __set_state, arginfo_date_set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - PHP_ME_MAPPING(getName, timezone_name_get, arginfo_timezone_method_name_get, 0) - PHP_ME_MAPPING(getOffset, timezone_offset_get, arginfo_timezone_method_offset_get, 0) - PHP_ME_MAPPING(getTransitions, timezone_transitions_get, arginfo_timezone_method_transitions_get, 0) - PHP_ME_MAPPING(getLocation, timezone_location_get, arginfo_timezone_method_location_get, 0) - PHP_ME_MAPPING(listAbbreviations, timezone_abbreviations_list, arginfo_timezone_abbreviations_list, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - PHP_ME_MAPPING(listIdentifiers, timezone_identifiers_list, arginfo_timezone_identifiers_list, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + PHP_ME(DateTimeZone, __construct, arginfo_DateTimeZone___construct, ZEND_ACC_PUBLIC) + PHP_ME(DateTimeZone, __wakeup, arginfo_DateTimeZone___wakeup, ZEND_ACC_PUBLIC) + PHP_ME(DateTimeZone, __set_state, arginfo_DateTimeZone___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + PHP_ME_MAPPING(getName, timezone_name_get, arginfo_DateTimeZone_getName, 0) + PHP_ME_MAPPING(getOffset, timezone_offset_get, arginfo_DateTimeZone_getOffset, 0) + PHP_ME_MAPPING(getTransitions, timezone_transitions_get, arginfo_DateTimeZone_getTransitions, 0) + PHP_ME_MAPPING(getLocation, timezone_location_get, arginfo_DateTimeZone_getLocation, 0) + PHP_ME_MAPPING(listAbbreviations, timezone_abbreviations_list, arginfo_DateTimeZone_listAbbreviations, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + PHP_ME_MAPPING(listIdentifiers, timezone_identifiers_list, arginfo_DateTimeZone_listIdentifiers, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_FE_END }; static const zend_function_entry date_funcs_interval[] = { - PHP_ME(DateInterval, __construct, arginfo_date_interval_construct, ZEND_ACC_PUBLIC) - PHP_ME(DateInterval, __wakeup, NULL, ZEND_ACC_PUBLIC) - PHP_ME(DateInterval, __set_state, arginfo_date_set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - PHP_ME_MAPPING(format, date_interval_format, arginfo_date_method_interval_format, 0) - PHP_ME_MAPPING(createFromDateString, date_interval_create_from_date_string, arginfo_date_interval_create_from_date_string, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + PHP_ME(DateInterval, __construct, arginfo_DateInterval___construct, ZEND_ACC_PUBLIC) + PHP_ME(DateInterval, __wakeup, arginfo_DateInterval___wakeup, ZEND_ACC_PUBLIC) + PHP_ME(DateInterval, __set_state, arginfo_DateInterval___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + PHP_ME_MAPPING(format, date_interval_format, arginfo_DateInterval_format, 0) + PHP_ME_MAPPING(createFromDateString, date_interval_create_from_date_string, arginfo_DateInterval_createFromDateString, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_FE_END }; static const zend_function_entry date_funcs_period[] = { - PHP_ME(DatePeriod, __construct, arginfo_date_period_construct, ZEND_ACC_PUBLIC) - PHP_ME(DatePeriod, __wakeup, NULL, ZEND_ACC_PUBLIC) - PHP_ME(DatePeriod, __set_state, arginfo_date_set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - PHP_ME(DatePeriod, getStartDate, NULL, ZEND_ACC_PUBLIC) - PHP_ME(DatePeriod, getEndDate, NULL, ZEND_ACC_PUBLIC) - PHP_ME(DatePeriod, getDateInterval, NULL, ZEND_ACC_PUBLIC) - PHP_ME(DatePeriod, getRecurrences, NULL, ZEND_ACC_PUBLIC) + PHP_ME(DatePeriod, __construct, arginfo_DatePeriod___construct, ZEND_ACC_PUBLIC) + PHP_ME(DatePeriod, __wakeup, arginfo_DatePeriod___wakeup, ZEND_ACC_PUBLIC) + PHP_ME(DatePeriod, __set_state, arginfo_DatePeriod___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + PHP_ME(DatePeriod, getStartDate, arginfo_DatePeriod_getStartDate, ZEND_ACC_PUBLIC) + PHP_ME(DatePeriod, getEndDate, arginfo_DatePeriod_getEndDate, ZEND_ACC_PUBLIC) + PHP_ME(DatePeriod, getDateInterval, arginfo_DatePeriod_getDateInterval, ZEND_ACC_PUBLIC) + PHP_ME(DatePeriod, getRecurrences, arginfo_DatePeriod_getRecurrences, ZEND_ACC_PUBLIC) PHP_FE_END }; @@ -4647,7 +4309,7 @@ PHP_METHOD(DatePeriod, getStartDate) dpobj = Z_PHPPERIOD_P(ZEND_THIS); - php_date_instantiate(dpobj->start_ce, return_value); + php_date_instantiate(dpobj->start_ce, return_value); dateobj = Z_PHPDATE_P(return_value); dateobj->time = timelib_time_ctor(); *dateobj->time = *dpobj->start; @@ -4699,9 +4361,9 @@ PHP_METHOD(DatePeriod, getDateInterval) php_period_obj *dpobj; php_interval_obj *diobj; - if (zend_parse_parameters_none() == FAILURE) { - return; - } + if (zend_parse_parameters_none() == FAILURE) { + return; + } dpobj = Z_PHPPERIOD_P(ZEND_THIS); @@ -4720,13 +4382,13 @@ PHP_METHOD(DatePeriod, getRecurrences) php_period_obj *dpobj; if (zend_parse_parameters_none() == FAILURE) { - return; + return; } dpobj = Z_PHPPERIOD_P(ZEND_THIS); if (0 == dpobj->recurrences - dpobj->include_start_date) { - return; + return; } RETURN_LONG(dpobj->recurrences - dpobj->include_start_date); @@ -4790,7 +4452,7 @@ PHP_FUNCTION(timezone_identifiers_list) } /* }}} */ -/* {{{ proto array timezone_version_get() +/* {{{ proto string timezone_version_get() Returns the Olson database version number. */ PHP_FUNCTION(timezone_version_get) diff --git a/ext/date/php_date.stub.php b/ext/date/php_date.stub.php new file mode 100644 index 0000000000..1d448b9102 --- /dev/null +++ b/ext/date/php_date.stub.php @@ -0,0 +1,310 @@ +getMessage()}\n"; + exit(1); +} + +if ($argc < 2) { + die("Usage: php gen_stub.php foobar.stub.php\n"); +} + +$stubFile = $argv[1]; +$arginfoFile = str_replace('.stub.php', '', $stubFile) . '_arginfo.h'; + +try { + $funcInfos = parseStubFile($stubFile); + $arginfoCode = generateArgInfoCode($funcInfos); + file_put_contents($arginfoFile, $arginfoCode); +} catch (Exception $e) { + echo "Caught {$e->getMessage()} while processing $stubFile\n"; + exit(1); +} + +class Type { + /** @var string */ + public $name; + /** @var bool */ + public $isBuiltin; + /** @var bool */ + public $isNullable; + + public function __construct(string $name, bool $isBuiltin, bool $isNullable = false) { + $this->name = $name; + $this->isBuiltin = $isBuiltin; + $this->isNullable = $isNullable; + } + + public static function fromNode(Node $node) { + if ($node instanceof Node\NullableType) { + $type = self::fromNode($node->type); + return new Type($type->name, $type->isBuiltin, true); + } + if ($node instanceof Node\Name) { + assert($node->isFullyQualified()); + return new Type($node->toString(), false); + } + if ($node instanceof Node\Identifier) { + return new Type($node->toString(), true); + } + throw new Exception("Unexpected node type"); + } + + public function toTypeCode() { + assert($this->isBuiltin); + switch (strtolower($this->name)) { + case "bool": + return "_IS_BOOL"; + case "int": + return "IS_LONG"; + case "float": + return "IS_DOUBLE"; + case "string": + return "IS_STRING"; + case "array": + return "IS_ARRAY"; + case "object": + return "IS_OBJECT"; + case "void": + return "IS_VOID"; + default: + throw new Exception("Not implemented: $this->name"); + } + } + + public static function equals(?Type $a, ?Type $b): bool { + if ($a === null || $b === null) { + return $a === $b; + } + + return $a->name === $b->name + && $a->isBuiltin === $b->isBuiltin + && $a->isNullable === $b->isNullable; + } +} + +class ArgInfo { + /** @var string */ + public $name; + /** @var bool */ + public $byRef; + /** @var bool */ + public $isVariadic; + /** @var Type|null */ + public $type; + + public function __construct(string $name, bool $byRef, bool $isVariadic, ?Type $type) { + $this->name = $name; + $this->byRef = $byRef; + $this->isVariadic = $isVariadic; + $this->type = $type; + } + + public function equals(ArgInfo $other): bool { + return $this->name === $other->name + && $this->byRef === $other->byRef + && $this->isVariadic === $other->isVariadic + && Type::equals($this->type, $other->type); + } +} + +class ReturnInfo { + /** @var bool */ + public $byRef; + /** @var Type|null */ + public $type; + + public function __construct(bool $byRef, ?Type $type) { + $this->byRef = $byRef; + $this->type = $type; + } + + public function equals(ReturnInfo $other): bool { + return $this->byRef === $other->byRef + && Type::equals($this->type, $other->type); + } +} + +class FuncInfo { + /** @var string */ + public $name; + /** @var ArgInfo[] */ + public $args; + /** @var ReturnInfo */ + public $return; + /** @var int */ + public $numRequiredArgs; + /** @var string|null */ + public $cond; + + public function __construct( + string $name, array $args, ReturnInfo $return, int $numRequiredArgs, ?string $cond + ) { + $this->name = $name; + $this->args = $args; + $this->return = $return; + $this->numRequiredArgs = $numRequiredArgs; + $this->cond = $cond; + } + + public function equalsApartFromName(FuncInfo $other): bool { + if (count($this->args) !== count($other->args)) { + return false; + } + + for ($i = 0; $i < count($this->args); $i++) { + if (!$this->args[$i]->equals($other->args[$i])) { + return false; + } + } + + return $this->return->equals($other->return) + && $this->numRequiredArgs === $other->numRequiredArgs + && $this->cond === $other->cond; + } +} + +function parseFunctionLike(string $name, Node\FunctionLike $func, ?string $cond): FuncInfo { + $args = []; + $numRequiredArgs = 0; + foreach ($func->getParams() as $i => $param) { + $args[] = new ArgInfo( + $param->var->name, + $param->byRef, + $param->variadic, + $param->type ? Type::fromNode($param->type) : null + ); + if (!$param->default && !$param->variadic) { + $numRequiredArgs = $i + 1; + } + } + + $returnType = $func->getReturnType(); + $return = new ReturnInfo( + $func->returnsByRef(), + $returnType ? Type::fromNode($returnType) : null); + return new FuncInfo($name, $args, $return, $numRequiredArgs, $cond); +} + +function parseClass(Stmt\Class_ $class): ClassInfo { + $funcs = []; + $className = $class->name->toString(); + foreach ($class as $stmt) { + if (!$stmt instanceof Stmt\ClassMethod) { + throw new Exception("Not implemented"); + } + + $funcs[] = parseFunctionLike($className . '_' . $stmt->name->toString(), $stmt); + } + return new ClassInfo($className, $funcs); +} + +/** @return FuncInfo[] */ +function parseStubFile(string $fileName) { + if (!file_exists($fileName)) { + throw new Exception("File $fileName does not exist"); + } + + $code = file_get_contents($fileName); + + $lexer = new PhpParser\Lexer(); + $parser = new PhpParser\Parser\Php7($lexer); + $nodeTraverser = new PhpParser\NodeTraverser; + $nodeTraverser->addVisitor(new PhpParser\NodeVisitor\NameResolver); + + $stmts = $parser->parse($code); + $nodeTraverser->traverse($stmts); + + $funcInfos = []; + $cond = null; + foreach ($stmts as $stmt) { + foreach ($stmt->getComments() as $comment) { + $text = trim($comment->getText()); + if (preg_match('/^#if\s+(.+)$/', $text, $matches)) { + if ($cond !== null) { + throw new Exception("Not implemented"); + } + $cond = $matches[1]; + } else if ($text === '#endif') { + $cond = null; + } + } + + if ($stmt instanceof Stmt\Nop) { + continue; + } + + if ($stmt instanceof Stmt\Function_) { + $funcInfos[] = parseFunctionLike($stmt->name->toString(), $stmt, $cond); + continue; + } + + if ($stmt instanceof Stmt\ClassLike) { + $className = $stmt->name->toString(); + foreach ($stmt->stmts as $classStmt) { + if ($classStmt instanceof Stmt\Nop) { + continue; + } + + if (!$classStmt instanceof Stmt\ClassMethod) { + throw new Exception("Not implemented {$classStmt->getType()}"); + } + + $funcInfos[] = parseFunctionLike( + $className . '_' . $classStmt->name->toString(), $classStmt, $cond); + } + continue; + } + + throw new Exception("Unexpected node {$stmt->getType()}"); + } + + return $funcInfos; +} + +function funcInfoToCode(FuncInfo $funcInfo): string { + $code = ''; + if ($funcInfo->cond) { + $code .= "#if {$funcInfo->cond}\n"; + } + if ($funcInfo->return->type) { + $returnType = $funcInfo->return->type; + if ($returnType->isBuiltin) { + $code .= sprintf( + "ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_%s, %d, %d, %s, %d)\n", + $funcInfo->name, $funcInfo->return->byRef, $funcInfo->numRequiredArgs, + $returnType->toTypeCode(), $returnType->isNullable + ); + } else { + throw new Exception("Not implemented"); + } + } else { + $code .= sprintf( + "ZEND_BEGIN_ARG_INFO_EX(arginfo_%s, 0, %d, %d)\n", + $funcInfo->name, $funcInfo->return->byRef, $funcInfo->numRequiredArgs + ); + } + + foreach ($funcInfo->args as $argInfo) { + if ($argInfo->isVariadic) { + if ($argInfo->type) { + throw new Exception("Not implemented"); + } + $code .= sprintf( + "\tZEND_ARG_VARIADIC_INFO(%d, %s)\n", + $argInfo->byRef, $argInfo->name + ); + } else if ($argInfo->type) { + if ($argInfo->type->isBuiltin) { + $code .= sprintf( + "\tZEND_ARG_TYPE_INFO(%d, %s, %s, %d)\n", + $argInfo->byRef, $argInfo->name, + $argInfo->type->toTypeCode(), $argInfo->type->isNullable + ); + } else { + $code .= sprintf( + "\tZEND_ARG_OBJ_INFO(%d, %s, %s, %d)\n", + $argInfo->byRef, $argInfo->name, + $argInfo->type->name, $argInfo->type->isNullable + ); + } + } else { + $code .= sprintf("\tZEND_ARG_INFO(%d, %s)\n", $argInfo->byRef, $argInfo->name); + } + } + + $code .= "ZEND_END_ARG_INFO()"; + if ($funcInfo->cond) { + $code .= "\n#endif"; + } + return $code; +} + +/** @param FuncInfo[] $funcInfos */ +function generateArginfoCode(array $funcInfos): string { + $code = "/* This is a generated file, edit the .stub.php file instead. */"; + $generatedFuncInfos = []; + foreach ($funcInfos as $funcInfo) { + /* If there already is an equivalent arginfo structure, only emit a #define */ + foreach ($generatedFuncInfos as $generatedFuncInfo) { + if ($generatedFuncInfo->equalsApartFromName($funcInfo)) { + $code .= sprintf( + "\n\n#define arginfo_%s arginfo_%s", + $funcInfo->name, $generatedFuncInfo->name + ); + continue 2; + } + } + + $code .= "\n\n" . funcInfoToCode($funcInfo); + $generatedFuncInfos[] = $funcInfo; + } + return $code . "\n"; +} + +function initPhpParser() { + $version = "4.2.2"; + $phpParserDir = __DIR__ . "/PHP-Parser-$version"; + if (!is_dir($phpParserDir)) { + $cwd = getcwd(); + chdir(__DIR__); + passthru("wget https://github.com/nikic/PHP-Parser/archive/v$version.tar.gz", $exit); + if ($exit !== 0) { + throw new Exception("Failed to download PHP-Parser tarball"); + } + if (!mkdir($phpParserDir)) { + throw new Exception("Failed to create directory $phpParserDir"); + } + passthru("tar xvzf v$version.tar.gz -C PHP-Parser-$version --strip-components 1", $exit); + if ($exit !== 0) { + throw new Exception("Failed to extract PHP-Parser tarball"); + } + unlink(__DIR__ . "/v$version.tar.gz"); + chdir($cwd); + } + + spl_autoload_register(function(string $class) use($phpParserDir) { + if (strpos($class, "PhpParser\\") === 0) { + $fileName = $phpParserDir . "/lib/" . str_replace("\\", "/", $class) . ".php"; + require $fileName; + } + }); +} -- cgit v1.2.1