Skip to content

Commit

Permalink
Generate arginfo from PHP stub files
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nikic committed Aug 9, 2019
1 parent 9b97355 commit 33886f7
Show file tree
Hide file tree
Showing 12 changed files with 1,484 additions and 578 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
# ------------------------------------------------------------------------------
Expand Down
189 changes: 25 additions & 164 deletions Zend/zend_builtin_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
};
/* }}} */
Expand Down
123 changes: 123 additions & 0 deletions Zend/zend_builtin_functions.stub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?php

function zend_version(): string {}

function func_num_args(): int {}

/** @return mixed */
function func_get_arg(int $arg_num) {}

/** @return array|false */
function func_get_args() {}

function strlen(string $str): int {}

function strcmp(string $str1, string $str2): int {}

/** @return int|false */
function strncmp(string $str1, string $str2, int $len) {}

function error_reporting($new_error_level = UNKNOWN): int {}

function define(string $constant_name, $value, bool $case_insensitive = false): bool {}

function defined(string $constant_name): bool {}

/** @return string|false */
function get_class(object $object = UNKNOWN) {}

/** @return string|false */
function get_called_class() {}

/** @return string|false */
function get_parent_class($object) {}

function is_subclass_of($object, string $class_name, bool $allow_string = true): bool {}

function is_a($object, string $class_name, bool $allow_string = false): bool {}

/** @return array|false */
function get_class_vars(string $class_name) {}

function get_object_vars(object $obj): array {}

function get_mangled_object_vars(object $obj): array {}

function get_class_methods($class): ?array {}

function method_exists($object_or_class, string $method): bool {}

function property_exists($object_or_class, string $property_name): ?bool {}

function class_exists(string $classname, bool $autoload = true): bool {}

function interface_exists(string $classname, bool $autoload = true): bool {}

function trait_exists(string $traitname, bool $autoload = true): bool {}

function function_exists(string $function_name): bool {}

function class_alias(string $user_class_name, string $alias_name, bool $autoload = true): bool {}

function get_included_files(): array {}

/** @alias get_included_files */
function get_required_files(): array {}

function trigger_error(string $message, int $error_type = E_USER_NOTICE): bool {}

/** @alias trigger_error */
function user_error(string $message, int $error_type = E_USER_NOTICE): bool {}

/** @return mixed */
function set_error_handler($error_handler, int $error_types = E_ALL) {}

function restore_error_handler(): bool {}

/** @return mixed */
function set_exception_handler($exception_handler) {}

function restore_exception_handler(): bool {}

function get_declared_classes(): array {}

function get_declared_traits(): array {}

function get_declared_interfaces(): array {}

function get_defined_functions(bool $exclude_disabled = false): array {}

function get_defined_vars(): ?array {}

function get_resource_type($res): string {}

function get_resources(string $type = UNKNOWN): array {}

function get_loaded_extensions(bool $zend_extensions = false): array {}

function get_defined_constants(bool $categorize = false): array {}

function debug_backtrace(int $options = DEBUG_BACKTRACE_PROVIDE_OBJECT, int $limit = 0): array {}

function debug_print_backtrace(int $options = 0, int $limit = 0): void {}

function extension_loaded(string $extension_name): bool {}

/** @return array|false */
function get_extension_funcs(string $extension_name) {}

#if ZEND_DEBUG && defined(ZTS)
function zend_thread_id(): int {}
#endif

function gc_mem_caches(): int {}

function gc_collect_cycles(): int {}

function gc_enabled(): bool {}

function gc_enable(): void {}

function gc_disable(): void {}

function gc_status(): array {}
Loading

0 comments on commit 33886f7

Please sign in to comment.