1
0
Fork 0

PHP_5_4: improves traits support

git-svn-id: svn://svn.lighttpd.net/xcache/trunk@837 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
This commit is contained in:
Xuefer 2012-03-25 02:14:44 +00:00
parent adff8d2eab
commit 00228b0cd6
3 changed files with 104 additions and 88 deletions

View File

@ -5,6 +5,11 @@ BEGIN {
incomment = 0;
buffer_len = 0;
}
function printstruct(structname) {
printf "define(`ELEMENTSOF_%s', `%s')\n", structname, ELEMENTSOF[structname];
printf "define(`COUNTOF_%s', `%s')\n", structname, COUNTOF[structname];
printf "define(`SIZEOF_%s', `( %s )')\n", structname, SIZEOF[structname];
}
# multiline comment handling
{
@ -34,11 +39,12 @@ incomment {
/^}.*;/ {
if (instruct) {
sub(";", "");
if (instruct == 1 && $2) {
instruct = $2;
structname = instruct;
if (structname == 1 && $2) {
structname = $2;
}
if (instruct in typedefs) {
instruct = typedefs[instruct];
if (structname in typedefs) {
structname = typedefs[structname];
}
sizeinfo = "";
elms = "";
@ -46,7 +52,7 @@ incomment {
if (i) {
sizeinfo = sizeinfo " + ";
}
sizeinfo = sizeinfo "sizeof(((" instruct "*)NULL)->" buffer[i] ")";
sizeinfo = sizeinfo "sizeof(((" structname "*)NULL)->" buffer[i] ")";
if (i == 0) {
elms = "\"" buffer[i] "\"";
@ -55,9 +61,10 @@ incomment {
elms = elms "," "\"" buffer[i] "\"";
}
}
printf "define(`ELEMENTSOF_%s', `%s')\n", instruct, elms;
printf "define(`COUNTOF_%s', `%s')\n", instruct, i;
printf "define(`SIZEOF_%s', `( %s )')\n", instruct, sizeinfo;
ELEMENTSOF[structname] = elms;
COUNTOF[structname] = i;
SIZEOF[structname] = sizeinfo;
printstruct(structname);
print "\n";
for (i in buffer) {
delete buffer[i];
@ -148,7 +155,17 @@ incomment {
/^typedef struct [^{]*;/ {
sub(";", "");
typedefs[$3] = $4;
typename=$3;
newtypename=$4;
typedefs[typename] = newtypename;
if (ELEMENTSOF[typename]) {
ELEMENTSOF[newtypename] = ELEMENTSOF[typename];
COUNTOF[newtypename] = COUNTOF[typename];
sub(/.*/, SIZEOF[typename]);
gsub(typename, newtypename);
SIZEOF[newtypename] = $0;
printstruct(newtypename);
}
next;
}
/^typedef struct .*\{[^}]*$/ {

View File

@ -180,6 +180,7 @@ dnl {{{ COPYNULL_EX(1:dst, 2:elm-name)
define(`COPYNULL_EX', `
IFDASM(`add_assoc_null_ex(dst, ZEND_STRS("$2"));')
IFNOTMEMCPY(`IFCOPY(`$1 = NULL;')')
assert(patsubst($1, dst, src) == NULL);
')
dnl }}}
dnl {{{ COPYNULL(1:elm)

View File

@ -15,17 +15,15 @@ DECL_STRUCT_P_FUNC(`zend_property_info')
#endif
/* }}} */
dnl ====================================================
dnl {{{ zend_compiled_variable
#ifdef IS_CV
DEF_STRUCT_P_FUNC(`zend_compiled_variable', , `
DEF_STRUCT_P_FUNC(`zend_compiled_variable', , `dnl {{{
DISPATCH(int, name_len)
PROC_ZSTRING_L(, name, name_len)
DISPATCH(ulong, hash_value)
')
#endif
dnl }}}
dnl {{{ zend_uint
DEF_STRUCT_P_FUNC(`zend_uint', , `
#endif
DEF_STRUCT_P_FUNC(`zend_uint', , `dnl {{{
IFCOPY(`dst[0] = src[0];')
IFDPRINT(`
INDENT()
@ -34,9 +32,8 @@ DEF_STRUCT_P_FUNC(`zend_uint', , `
DONE_SIZE(sizeof(src[0]))
')
dnl }}}
dnl {{{ int
#ifndef ZEND_ENGINE_2
DEF_STRUCT_P_FUNC(`int', , `
DEF_STRUCT_P_FUNC(`int', , `dnl {{{
IFCOPY(`*dst = *src;')
IFDPRINT(`
INDENT()
@ -44,18 +41,16 @@ DEF_STRUCT_P_FUNC(`int', , `
')
DONE_SIZE(sizeof(src[0]))
')
#endif
dnl }}}
dnl {{{ zend_try_catch_element
#endif
#ifdef ZEND_ENGINE_2
DEF_STRUCT_P_FUNC(`zend_try_catch_element', , `
DEF_STRUCT_P_FUNC(`zend_try_catch_element', , `dnl {{{
DISPATCH(zend_uint, try_op)
DISPATCH(zend_uint, catch_op)
')
#endif /* ifdef ZEND_ENGINE_2 */
dnl }}}
dnl {{{ zend_brk_cont_element
DEF_STRUCT_P_FUNC(`zend_brk_cont_element', , `
#endif
DEF_STRUCT_P_FUNC(`zend_brk_cont_element', , `dnl {{{
#ifdef ZEND_ENGINE_2_2
DISPATCH(int, start)
#endif
@ -226,9 +221,8 @@ DEF_STRUCT_P_FUNC(`zval_ptr_nullable', , `dnl {{{
DONE_SIZE(sizeof(zval_ptr_nullable))
')
dnl }}}
dnl {{{ zend_arg_info
#ifdef ZEND_ENGINE_2
DEF_STRUCT_P_FUNC(`zend_arg_info', , `
DEF_STRUCT_P_FUNC(`zend_arg_info', , `dnl {{{
DISPATCH(zend_uint, name_len)
PROC_ZSTRING_L(, name, name_len)
DISPATCH(zend_uint, class_name_len)
@ -245,8 +239,8 @@ DEF_STRUCT_P_FUNC(`zend_arg_info', , `
DISPATCH(int, required_num_args)
#endif
')
#endif
dnl }}}
#endif
#ifdef HAVE_XCACHE_CONSTANT
DEF_STRUCT_P_FUNC(`zend_constant', , `dnl {{{
STRUCT(zval, value)
@ -280,9 +274,8 @@ DEF_STRUCT_P_FUNC(`zend_function', , `dnl {{{
DONE_SIZE(sizeof(src[0]))
')
dnl }}}
dnl {{{ zend_property_info
#ifdef ZEND_ENGINE_2
DEF_STRUCT_P_FUNC(`zend_property_info', , `
DEF_STRUCT_P_FUNC(`zend_property_info', , `dnl {{{
DISPATCH(zend_uint, flags)
DISPATCH(int, name_length)
PROC_ZSTRING_L(, name, name_length)
@ -299,8 +292,58 @@ DEF_STRUCT_P_FUNC(`zend_property_info', , `
PROC_CLASS_ENTRY_P(ce)
#endif
')
#endif
dnl }}}
#endif
#ifdef ZEND_ENGINE_2_4
DEF_STRUCT_P_FUNC(`zend_trait_method_reference', , `dnl {{{
DISPATCH(unsigned int, mname_len)
PROC_STRING_L(method_name, mname_len)
COPYNULL(ce)
DISPATCH(unsigned int, cname_len)
PROC_STRING_L(class_name, cname_len)
')
dnl }}}
DEF_STRUCT_P_FUNC(`zend_trait_alias', , `dnl {{{
STRUCT_P(zend_trait_method_reference, trait_method)
DISPATCH(unsigned int, alias_len)
PROC_STRING_L(alias, alias_len)
DISPATCH(zend_uint, modifiers)
COPYNULL(function)
')
dnl }}}
DEF_STRUCT_P_FUNC(`zend_trait_precedence', , `dnl {{{
STRUCT_P(zend_trait_method_reference, trait_method)
COPYNULL(exclude_from_classes)
COPYNULL(function)
')
dnl }}}
DEF_STRUCT_P_FUNC(`zend_trait_alias_ptr', , `dnl {{{
IFDASM(`
pushdefFUNC_NAME(`zend_trait_alias')
FUNC_NAME (dst, src[0] TSRMLS_CC);
popdef(`FUNC_NAME')
', `
ALLOC(dst[0], zend_trait_alias)
STRUCT_P_EX(zend_trait_alias, dst[0], src[0], `[0]', `', ` ')
FIXPOINTER_EX(zend_trait_alias, dst[0])
')
DONE_SIZE(sizeof(zend_trait_alias))
')
dnl }}}
DEF_STRUCT_P_FUNC(`zend_trait_precedence_ptr', , `dnl {{{
IFDASM(`
pushdefFUNC_NAME(`zend_trait_precedence')
FUNC_NAME (dst, src[0] TSRMLS_CC);
popdef(`FUNC_NAME')
', `
ALLOC(dst[0], zend_trait_precedence)
STRUCT_P_EX(zend_trait_precedence, dst[0], src[0], `[0]', `', ` ')
FIXPOINTER_EX(zend_trait_precedence, dst[0])
')
DONE_SIZE(sizeof(zend_trait_precedence))
')
dnl }}}
#endif
DEF_STRUCT_P_FUNC(`zend_class_entry', , `dnl {{{
IFCALCCOPY(`
processor->active_class_entry_src = src;
@ -358,8 +401,17 @@ DEF_STRUCT_P_FUNC(`zend_class_entry', , `dnl {{{
#ifdef ZEND_ENGINE_2
STRUCT(HashTable, constants_table, HashTable_zval_ptr)
#ifdef ZEND_ENGINE_2_2
dnl runtime binding: ADD_INTERFACE will deal with it
COPYNULL(`interfaces')
COPYNULL(`num_interfaces')
# ifdef ZEND_ENGINE_2_4
dnl runtime binding: ADD_TRAIT will deal with it
COPYNULL(traits)
COPYNULL(num_traits)
# endif
#else
IFRESTORE(`
if (src->num_interfaces) {
CALLOC(dst->interfaces, zend_class_entry*, src->num_interfaces)
@ -368,66 +420,13 @@ DEF_STRUCT_P_FUNC(`zend_class_entry', , `dnl {{{
else {
COPYNULL(`interfaces')
}
# ifdef ZEND_ENGINE_2_4
if (src->num_traits) {
CALLOC(dst->traits, zend_class_entry*, src->num_traits)
DONE(`traits')
DONE(`trait_aliases')
DONE(`trait_precedences')
}
else {
COPYNULL(`traits')
COPYNULL(`trait_aliases')
COPYNULL(`trait_precedences')
}
# endif
')
IFDASM(`
if (src->num_interfaces) {
/*
int i;
zval *arr;
ALLOC_INIT_ZVAL(arr);
array_init(arr);
for (i = 0; i < src->num_interfaces; i ++) {
zval *zv;
ALLOC_INIT_ZVAL(zv);
ZVAL_STRING(src->num_interfaces);
}
add_assoc_zval_ex(dst, ZEND_STRS("interfaces"), arr);
*/
DONE(`interfaces')
}
else {
COPYNULL(`interfaces')
}
# ifdef ZEND_ENGINE_2_4
if (src->num_traits) {
DONE(`traits')
DONE(`trait_aliases')
DONE(`trait_precedences')
}
else {
COPYNULL(`traits')
COPYNULL(`trait_aliases')
COPYNULL(`trait_precedences')
}
# endif
')
IFRESTORE(`', `
IFDASM(`', `
DONE(`interfaces')
# ifdef ZEND_ENGINE_2_4
DONE(`traits')
DONE(`trait_aliases')
DONE(`trait_precedences')
# endif
')
', `
DONE(`interfaces')
')
DISPATCH(zend_uint, num_interfaces)
# ifdef ZEND_ENGINE_2_4
DISPATCH(zend_uint, num_traits)
# endif
#endif
STRUCT_ARRAY(, zend_trait_alias_ptr, trait_aliases)
STRUCT_ARRAY(, zend_trait_precedence_ptr, trait_precedences)
# ifdef ZEND_ENGINE_2_4
DISABLECHECK(`
@ -1138,8 +1137,7 @@ DEF_STRUCT_P_FUNC(`xc_entry_data_var_t', , `dnl {{{
DONE(value)
')
dnl }}}
dnl {{{ xc_entry_t
DEF_STRUCT_P_FUNC(`xc_entry_t', , `
DEF_STRUCT_P_FUNC(`xc_entry_t', , `dnl {{{
DISPATCH(xc_entry_type_t, type)
DISPATCH(size_t, size)