Skip to content

Generate zend class entries based on stubs #6685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions Zend/zend_attributes.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,12 @@ ZEND_API zend_internal_attribute *zend_internal_attribute_get(zend_string *lcnam
void zend_register_attribute_ce(void)
{
zend_internal_attribute *attr;
zend_class_entry ce;
zend_string *str;
zval tmp;

zend_hash_init(&internal_attributes, 8, NULL, free_internal_attribute, 1);

INIT_CLASS_ENTRY(ce, "Attribute", class_Attribute_methods);
zend_ce_attribute = zend_register_internal_class(&ce);
zend_ce_attribute->ce_flags |= ZEND_ACC_FINAL;
zend_ce_attribute = register_class_Attribute();
attr = zend_internal_attribute_register(zend_ce_attribute, ZEND_ATTRIBUTE_TARGET_CLASS);
attr->validator = validate_attribute;

zend_declare_class_constant_long(zend_ce_attribute, ZEND_STRL("TARGET_CLASS"), ZEND_ATTRIBUTE_TARGET_CLASS);
zend_declare_class_constant_long(zend_ce_attribute, ZEND_STRL("TARGET_FUNCTION"), ZEND_ATTRIBUTE_TARGET_FUNCTION);
Expand All @@ -281,14 +278,6 @@ void zend_register_attribute_ce(void)
zend_declare_class_constant_long(zend_ce_attribute, ZEND_STRL("TARGET_PARAMETER"), ZEND_ATTRIBUTE_TARGET_PARAMETER);
zend_declare_class_constant_long(zend_ce_attribute, ZEND_STRL("TARGET_ALL"), ZEND_ATTRIBUTE_TARGET_ALL);
zend_declare_class_constant_long(zend_ce_attribute, ZEND_STRL("IS_REPEATABLE"), ZEND_ATTRIBUTE_IS_REPEATABLE);

ZVAL_UNDEF(&tmp);
str = zend_string_init(ZEND_STRL("flags"), 1);
zend_declare_typed_property(zend_ce_attribute, str, &tmp, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_CODE(IS_LONG, 0, 0));
zend_string_release(str);

attr = zend_internal_attribute_register(zend_ce_attribute, ZEND_ATTRIBUTE_TARGET_CLASS);
attr->validator = validate_attribute;
}

void zend_attributes_shutdown(void)
Expand Down
4 changes: 3 additions & 1 deletion Zend/zend_attributes.stub.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

/** @generate-function-entries */
/** @generate-class-entries */

final class Attribute
{
public int $flags;

public function __construct(int $flags = Attribute::TARGET_ALL) {}
}
20 changes: 19 additions & 1 deletion Zend/zend_attributes_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 54eede8541597ec2ac5c04e31d14e2db7e8c5556 */
* Stub hash: 0183e750e66999862a7688ecb251017110d06d1f */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Attribute___construct, 0, 0, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "Attribute::TARGET_ALL")
Expand All @@ -13,3 +13,21 @@ static const zend_function_entry class_Attribute_methods[] = {
ZEND_ME(Attribute, __construct, arginfo_class_Attribute___construct, ZEND_ACC_PUBLIC)
ZEND_FE_END
};

zend_class_entry *register_class_Attribute()
{
zend_class_entry ce, *class_entry;

INIT_CLASS_ENTRY(ce, "Attribute", class_Attribute_methods);
class_entry = zend_register_internal_class_ex(&ce, NULL);
class_entry->ce_flags |= ZEND_ACC_FINAL;

zval property_flags_default_value;
ZVAL_UNDEF(&property_flags_default_value);
zend_string *property_flags_name = zend_string_init("flags", sizeof("flags") - 1, 1);
zend_declare_typed_property(class_entry, property_flags_name, &property_flags_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG));
zend_string_release(property_flags_name);

return class_entry;
}

2 changes: 1 addition & 1 deletion Zend/zend_builtin_functions.stub.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

/** @generate-function-entries */
/** @generate-class-entries */

function zend_version(): string {}

Expand Down
3 changes: 2 additions & 1 deletion Zend/zend_builtin_functions_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: b09e9199a21595a3b6f6c02db81c8e22c36c277f */
* Stub hash: b2216a294367f50c8b6208653ebf6fa43dc106d1 */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_version, 0, 0, IS_STRING, 0)
ZEND_END_ARG_INFO()
Expand Down Expand Up @@ -333,3 +333,4 @@ static const zend_function_entry ext_functions[] = {
ZEND_FE(gc_status, arginfo_gc_status)
ZEND_FE_END
};

6 changes: 1 addition & 5 deletions Zend/zend_closures.c
Original file line number Diff line number Diff line change
Expand Up @@ -629,11 +629,7 @@ ZEND_COLD ZEND_METHOD(Closure, __construct)

void zend_register_closure_ce(void) /* {{{ */
{
zend_class_entry ce;

INIT_CLASS_ENTRY(ce, "Closure", class_Closure_methods);
zend_ce_closure = zend_register_internal_class(&ce);
zend_ce_closure->ce_flags |= ZEND_ACC_FINAL;
zend_ce_closure = register_class_Closure();
zend_ce_closure->create_object = zend_closure_new;
zend_ce_closure->serialize = zend_class_serialize_deny;
zend_ce_closure->unserialize = zend_class_unserialize_deny;
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_closures.stub.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

/** @generate-function-entries */
/** @generate-class-entries */

final class Closure
{
Expand Down
14 changes: 13 additions & 1 deletion Zend/zend_closures_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 0a2dd53716d30893aa5dd92a9907b2298abb3f70 */
* Stub hash: 62da9b1e75331f30a0c63e82c9fd366e26b5724d */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Closure___construct, 0, 0, 0)
ZEND_END_ARG_INFO()
Expand Down Expand Up @@ -40,3 +40,15 @@ static const zend_function_entry class_Closure_methods[] = {
ZEND_ME(Closure, fromCallable, arginfo_class_Closure_fromCallable, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
ZEND_FE_END
};

zend_class_entry *register_class_Closure()
{
zend_class_entry ce, *class_entry;

INIT_CLASS_ENTRY(ce, "Closure", class_Closure_methods);
class_entry = zend_register_internal_class_ex(&ce, NULL);
class_entry->ce_flags |= ZEND_ACC_FINAL;

return class_entry;
}

30 changes: 12 additions & 18 deletions Zend/zend_interfaces.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,31 +596,25 @@ ZEND_METHOD(InternalIterator, rewind) {
/* {{{ zend_register_interfaces */
ZEND_API void zend_register_interfaces(void)
{
zend_class_entry ce;
zend_ce_traversable = register_class_Traversable();
zend_ce_traversable->interface_gets_implemented = zend_implement_traversable;

REGISTER_MAGIC_INTERFACE(traversable, Traversable);
zend_ce_aggregate = register_class_IteratorAggregate(zend_ce_traversable);
zend_ce_aggregate->interface_gets_implemented = zend_implement_aggregate;

REGISTER_MAGIC_INTERFACE(aggregate, IteratorAggregate);
REGISTER_MAGIC_IMPLEMENT(aggregate, traversable);
zend_ce_iterator = register_class_Iterator(zend_ce_traversable);
zend_ce_iterator->interface_gets_implemented = zend_implement_iterator;

REGISTER_MAGIC_INTERFACE(iterator, Iterator);
REGISTER_MAGIC_IMPLEMENT(iterator, traversable);
zend_ce_serializable = register_class_Serializable();
zend_ce_serializable->interface_gets_implemented = zend_implement_serializable;

REGISTER_MAGIC_INTERFACE(serializable, Serializable);
zend_ce_arrayaccess = register_class_ArrayAccess();

INIT_CLASS_ENTRY(ce, "ArrayAccess", class_ArrayAccess_methods);
zend_ce_arrayaccess = zend_register_internal_interface(&ce);
zend_ce_countable = register_class_Countable();

INIT_CLASS_ENTRY(ce, "Countable", class_Countable_methods);
zend_ce_countable = zend_register_internal_interface(&ce);
zend_ce_stringable = register_class_Stringable();

INIT_CLASS_ENTRY(ce, "Stringable", class_Stringable_methods);
zend_ce_stringable = zend_register_internal_interface(&ce);

INIT_CLASS_ENTRY(ce, "InternalIterator", class_InternalIterator_methods);
zend_ce_internal_iterator = zend_register_internal_class(&ce);
zend_class_implements(zend_ce_internal_iterator, 1, zend_ce_iterator);
zend_ce_internal_iterator->ce_flags |= ZEND_ACC_FINAL;
zend_ce_internal_iterator = register_class_InternalIterator(zend_ce_iterator);
zend_ce_internal_iterator->create_object = zend_internal_iterator_create;
zend_ce_internal_iterator->serialize = zend_class_serialize_deny;
zend_ce_internal_iterator->unserialize = zend_class_unserialize_deny;
Expand Down
11 changes: 0 additions & 11 deletions Zend/zend_interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,6 @@ ZEND_API zval* zend_call_method(zend_object *object, zend_class_entry *obj_ce, z
#define zend_call_method_with_2_params(obj, obj_ce, fn_proxy, function_name, retval, arg1, arg2) \
zend_call_method(obj, obj_ce, fn_proxy, function_name, sizeof(function_name)-1, retval, 2, arg1, arg2)

#define REGISTER_MAGIC_INTERFACE(class_name, class_name_str) \
{\
zend_class_entry ce;\
INIT_CLASS_ENTRY(ce, # class_name_str, class_ ## class_name_str ## _methods) \
zend_ce_ ## class_name = zend_register_internal_interface(&ce);\
zend_ce_ ## class_name->interface_gets_implemented = zend_implement_ ## class_name;\
}

#define REGISTER_MAGIC_IMPLEMENT(class_name, interface_name) \
zend_class_implements(zend_ce_ ## class_name, 1, zend_ce_ ## interface_name)

ZEND_API void zend_user_it_rewind(zend_object_iterator *_iter);
ZEND_API zend_result zend_user_it_valid(zend_object_iterator *_iter);
ZEND_API void zend_user_it_get_current_key(zend_object_iterator *_iter, zval *key);
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_interfaces.stub.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

/** @generate-function-entries */
/** @generate-class-entries */

interface Traversable {}

Expand Down
87 changes: 86 additions & 1 deletion Zend/zend_interfaces_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: c6ef101bd3881348a74b60cecd22d1d7f80017c8 */
* Stub hash: 34aa50c74f10106c6abd0ed2956d41c98aae6452 */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_IteratorAggregate_getIterator, 0, 0, 0)
ZEND_END_ARG_INFO()
Expand Down Expand Up @@ -119,3 +119,88 @@ static const zend_function_entry class_InternalIterator_methods[] = {
ZEND_ME(InternalIterator, rewind, arginfo_class_InternalIterator_rewind, ZEND_ACC_PUBLIC)
ZEND_FE_END
};

zend_class_entry *register_class_Traversable()
{
zend_class_entry ce, *class_entry;

INIT_CLASS_ENTRY(ce, "Traversable", class_Traversable_methods);
class_entry = zend_register_internal_interface(&ce);

return class_entry;
}

zend_class_entry *register_class_IteratorAggregate(zend_class_entry *class_entry_Traversable)
{
zend_class_entry ce, *class_entry;

INIT_CLASS_ENTRY(ce, "IteratorAggregate", class_IteratorAggregate_methods);
class_entry = zend_register_internal_interface(&ce);
zend_class_implements(class_entry, 1, class_entry_Traversable);

return class_entry;
}

zend_class_entry *register_class_Iterator(zend_class_entry *class_entry_Traversable)
{
zend_class_entry ce, *class_entry;

INIT_CLASS_ENTRY(ce, "Iterator", class_Iterator_methods);
class_entry = zend_register_internal_interface(&ce);
zend_class_implements(class_entry, 1, class_entry_Traversable);

return class_entry;
}

zend_class_entry *register_class_ArrayAccess()
{
zend_class_entry ce, *class_entry;

INIT_CLASS_ENTRY(ce, "ArrayAccess", class_ArrayAccess_methods);
class_entry = zend_register_internal_interface(&ce);

return class_entry;
}

zend_class_entry *register_class_Serializable()
{
zend_class_entry ce, *class_entry;

INIT_CLASS_ENTRY(ce, "Serializable", class_Serializable_methods);
class_entry = zend_register_internal_interface(&ce);

return class_entry;
}

zend_class_entry *register_class_Countable()
{
zend_class_entry ce, *class_entry;

INIT_CLASS_ENTRY(ce, "Countable", class_Countable_methods);
class_entry = zend_register_internal_interface(&ce);

return class_entry;
}

zend_class_entry *register_class_Stringable()
{
zend_class_entry ce, *class_entry;

INIT_CLASS_ENTRY(ce, "Stringable", class_Stringable_methods);
class_entry = zend_register_internal_interface(&ce);

return class_entry;
}

zend_class_entry *register_class_InternalIterator(zend_class_entry *class_entry_Iterator)
{
zend_class_entry ce, *class_entry;

INIT_CLASS_ENTRY(ce, "InternalIterator", class_InternalIterator_methods);
class_entry = zend_register_internal_class_ex(&ce, NULL);
class_entry->ce_flags |= ZEND_ACC_FINAL;
zend_class_implements(class_entry, 1, class_entry_Iterator);

return class_entry;
}

12 changes: 2 additions & 10 deletions Zend/zend_weakrefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,11 +597,7 @@ ZEND_METHOD(WeakMap, getIterator)

void zend_register_weakref_ce(void) /* {{{ */
{
zend_class_entry ce;

INIT_CLASS_ENTRY(ce, "WeakReference", class_WeakReference_methods);
zend_ce_weakref = zend_register_internal_class(&ce);
zend_ce_weakref->ce_flags |= ZEND_ACC_FINAL | ZEND_ACC_NO_DYNAMIC_PROPERTIES;
zend_ce_weakref = register_class_WeakReference();

zend_ce_weakref->create_object = zend_weakref_new;
zend_ce_weakref->serialize = zend_class_serialize_deny;
Expand All @@ -613,11 +609,7 @@ void zend_register_weakref_ce(void) /* {{{ */
zend_weakref_handlers.free_obj = zend_weakref_free;
zend_weakref_handlers.clone_obj = NULL;

INIT_CLASS_ENTRY(ce, "WeakMap", class_WeakMap_methods);
zend_ce_weakmap = zend_register_internal_class(&ce);
zend_ce_weakmap->ce_flags |= ZEND_ACC_FINAL | ZEND_ACC_NO_DYNAMIC_PROPERTIES;
zend_class_implements(
zend_ce_weakmap, 3, zend_ce_arrayaccess, zend_ce_countable, zend_ce_aggregate);
zend_ce_weakmap = register_class_WeakMap(zend_ce_arrayaccess, zend_ce_countable, zend_ce_aggregate);

zend_ce_weakmap->create_object = zend_weakmap_create_object;
zend_ce_weakmap->get_iterator = zend_weakmap_get_iterator;
Expand Down
4 changes: 3 additions & 1 deletion Zend/zend_weakrefs.stub.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php

/** @generate-function-entries */
/** @generate-class-entries */

/** @strict-properties */
final class WeakReference
{
public function __construct() {}
Expand All @@ -11,6 +12,7 @@ public static function create(object $object): WeakReference {}
public function get(): ?object {}
}

/** @strict-properties */
final class WeakMap implements ArrayAccess, Countable, IteratorAggregate
{
/**
Expand Down
26 changes: 25 additions & 1 deletion Zend/zend_weakrefs_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 0569bc7e10a1ec15a3a9eec481da27b647eb1d1d */
* Stub hash: 97fff017125955a3def85d9ed5a31746de7b808a */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_WeakReference___construct, 0, 0, 0)
ZEND_END_ARG_INFO()
Expand Down Expand Up @@ -63,3 +63,27 @@ static const zend_function_entry class_WeakMap_methods[] = {
ZEND_ME(WeakMap, getIterator, arginfo_class_WeakMap_getIterator, ZEND_ACC_PUBLIC)
ZEND_FE_END
};

zend_class_entry *register_class_WeakReference()
{
zend_class_entry ce, *class_entry;

INIT_CLASS_ENTRY(ce, "WeakReference", class_WeakReference_methods);
class_entry = zend_register_internal_class_ex(&ce, NULL);
class_entry->ce_flags |= ZEND_ACC_FINAL|ZEND_ACC_NO_DYNAMIC_PROPERTIES;

return class_entry;
}

zend_class_entry *register_class_WeakMap(zend_class_entry *class_entry_ArrayAccess, zend_class_entry *class_entry_Countable, zend_class_entry *class_entry_IteratorAggregate)
{
zend_class_entry ce, *class_entry;

INIT_CLASS_ENTRY(ce, "WeakMap", class_WeakMap_methods);
class_entry = zend_register_internal_class_ex(&ce, NULL);
class_entry->ce_flags |= ZEND_ACC_FINAL|ZEND_ACC_NO_DYNAMIC_PROPERTIES;
zend_class_implements(class_entry, 3, class_entry_ArrayAccess, class_entry_Countable, class_entry_IteratorAggregate);

return class_entry;
}