com php-src: Remove dead code: Zend/zend_compile.c Zend/z end_compile.h
| From: | Nikita Popov | Date: | Sat, 19 Jul 2014 11:00:57 +0000 |
| Subject: | com php-src: Remove dead code: Zend/zend_compile.c Zend/z end_compile.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-80987@lists.php.net to get a copy of this message | ||
Commit: 09309a543f154dd1c755b4e8fe692fe0dbf4a843
Author: Nikita Popov <nikic@php.net> Sat, 19 Jul 2014 13:00:57 +0200
Parents: 74dba7e4dbac69531ed1fe896dcc20177247d02f
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=09309a543f154dd1c755b4e8fe692fe0dbf4a843
Log:
Remove dead code
Changed paths:
M Zend/zend_compile.c
M Zend/zend_compile.h
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index ef0f878..d54ee6e 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -710,263 +710,6 @@ int zend_do_verify_access_types(const znode *current_access_type, const znode *n } /* }}} */ -void zend_do_begin_function_declaration(znode *function_token, znode *function_name, int is_method, int return_reference, znode *fn_flags_znode TSRMLS_DC) /* {{{ */ -{ - zend_op_array op_array; - zend_string *name = Z_STR(function_name->u.constant); - int function_begin_line = function_token->EA; - zend_uint fn_flags; - zend_string *lcname; - zend_bool orig_interactive; - ALLOCA_FLAG(use_heap) - - if (is_method) { - if (CG(active_class_entry)->ce_flags & ZEND_ACC_INTERFACE) { - if ((Z_LVAL(fn_flags_znode->u.constant) & ~(ZEND_ACC_STATIC|ZEND_ACC_PUBLIC))) { - zend_error_noreturn(E_COMPILE_ERROR, "Access type for interface method %s::%s() must be omitted", CG(active_class_entry)->name->val, Z_STRVAL(function_name->u.constant)); - } - Z_LVAL(fn_flags_znode->u.constant) |= ZEND_ACC_ABSTRACT; /* propagates to the rest of the parser */ - } - fn_flags = Z_LVAL(fn_flags_znode->u.constant); /* must be done *after* the above check */ - } else { - fn_flags = 0; - } - if ((fn_flags & ZEND_ACC_STATIC) && (fn_flags & ZEND_ACC_ABSTRACT) && !(CG(active_class_entry)->ce_flags & ZEND_ACC_INTERFACE)) { - zend_error(E_STRICT, "Static function %s%s%s() should not be abstract", is_method ? CG(active_class_entry)->name->val : "", is_method ? "::" : "", Z_STRVAL(function_name->u.constant)); - } - - function_token->u.op_array = CG(active_op_array); - - orig_interactive = CG(interactive); - CG(interactive) = 0; - init_op_array(&op_array, ZEND_USER_FUNCTION, INITIAL_OP_ARRAY_SIZE TSRMLS_CC); - CG(interactive) = orig_interactive; - - op_array.function_name = name; - if (return_reference) { - op_array.fn_flags |= ZEND_ACC_RETURN_REFERENCE; - } - op_array.fn_flags |= fn_flags; - - op_array.scope = is_method?CG(active_class_entry):NULL; - op_array.prototype = NULL; - - op_array.line_start = zend_get_compiled_lineno(TSRMLS_C); - - if (is_method) { - lcname = STR_ALLOC(name->len, 0); - zend_str_tolower_copy(lcname->val, name->val, name->len); - lcname = zend_new_interned_string(lcname TSRMLS_CC); - CG(active_op_array) = emalloc(sizeof(zend_op_array)); - memcpy(CG(active_op_array), &op_array, sizeof(zend_op_array)); - if (zend_hash_add_ptr(&CG(active_class_entry)->function_table, lcname, CG(active_op_array)) == NULL) { - zend_error_noreturn(E_COMPILE_ERROR, "Cannot redeclare %s::%s()", CG(active_class_entry)->name->val, name->val); - } - - zend_stack_push(&CG(context_stack), (void *) &CG(context)); - zend_init_compiler_context(TSRMLS_C); - - if (fn_flags & ZEND_ACC_ABSTRACT) { - CG(active_class_entry)->ce_flags |= ZEND_ACC_IMPLICIT_ABSTRACT_CLASS; - } - - if (!(fn_flags & ZEND_ACC_PPP_MASK)) { - fn_flags |= ZEND_ACC_PUBLIC; - } - - if (CG(active_class_entry)->ce_flags & ZEND_ACC_INTERFACE) { - if ((name->len == sizeof(ZEND_CALL_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME)-1))) { - if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) { - zend_error(E_WARNING, "The magic method __call() must have public visibility and cannot be static"); - } - } else if ((name->len == sizeof(ZEND_CALLSTATIC_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_CALLSTATIC_FUNC_NAME, sizeof(ZEND_CALLSTATIC_FUNC_NAME)-1))) { - if ((fn_flags & (ZEND_ACC_PPP_MASK ^ ZEND_ACC_PUBLIC)) || (fn_flags & ZEND_ACC_STATIC) == 0) { - zend_error(E_WARNING, "The magic method __callStatic() must have public visibility and be static"); - } - } else if ((name->len == sizeof(ZEND_GET_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_GET_FUNC_NAME, sizeof(ZEND_GET_FUNC_NAME)-1))) { - if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) { - zend_error(E_WARNING, "The magic method __get() must have public visibility and cannot be static"); - } - } else if ((name->len == sizeof(ZEND_SET_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_SET_FUNC_NAME, sizeof(ZEND_SET_FUNC_NAME)-1))) { - if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) { - zend_error(E_WARNING, "The magic method __set() must have public visibility and cannot be static"); - } - } else if ((name->len == sizeof(ZEND_UNSET_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_UNSET_FUNC_NAME, sizeof(ZEND_UNSET_FUNC_NAME)-1))) { - if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) { - zend_error(E_WARNING, "The magic method __unset() must have public visibility and cannot be static"); - } - } else if ((name->len == sizeof(ZEND_ISSET_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_ISSET_FUNC_NAME, sizeof(ZEND_ISSET_FUNC_NAME)-1))) { - if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) { - zend_error(E_WARNING, "The magic method __isset() must have public visibility and cannot be static"); - } - } else if ((name->len == sizeof(ZEND_TOSTRING_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_TOSTRING_FUNC_NAME, sizeof(ZEND_TOSTRING_FUNC_NAME)-1))) { - if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) { - zend_error(E_WARNING, "The magic method __toString() must have public visibility and cannot be static"); - } - } else if ((name->len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1))) { - if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) { - zend_error(E_WARNING, "The magic method __invoke() must have public visibility and cannot be static"); - } - - } else if ((name->len == sizeof(ZEND_DEBUGINFO_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_DEBUGINFO_FUNC_NAME, sizeof(ZEND_DEBUGINFO_FUNC_NAME)-1))) { - if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) { - zend_error(E_WARNING, "The magic method __debugInfo() must have public visibility and cannot be static"); - } - } - } else { - char *class_lcname; - - class_lcname = do_alloca(CG(active_class_entry)->name->len + 1, use_heap); - zend_str_tolower_copy(class_lcname, CG(active_class_entry)->name->val, CG(active_class_entry)->name->len); - /* Improve after RC: cache the lowercase class name */ - - if ((CG(active_class_entry)->name->len == name->len) && ((CG(active_class_entry)->ce_flags & ZEND_ACC_TRAIT) != ZEND_ACC_TRAIT) && (!memcmp(class_lcname, lcname->val, name->len))) { - if (!CG(active_class_entry)->constructor) { - CG(active_class_entry)->constructor = (zend_function *) CG(active_op_array); - } - } else if ((name->len == sizeof(ZEND_CONSTRUCTOR_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_CONSTRUCTOR_FUNC_NAME, sizeof(ZEND_CONSTRUCTOR_FUNC_NAME)-1))) { - if (CG(active_class_entry)->constructor) { - zend_error(E_STRICT, "Redefining already defined constructor for class %s", CG(active_class_entry)->name->val); - } - CG(active_class_entry)->constructor = (zend_function *) CG(active_op_array); - } else if ((name->len == sizeof(ZEND_DESTRUCTOR_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_DESTRUCTOR_FUNC_NAME, sizeof(ZEND_DESTRUCTOR_FUNC_NAME)-1))) { - CG(active_class_entry)->destructor = (zend_function *) CG(active_op_array); - } else if ((name->len == sizeof(ZEND_CLONE_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_CLONE_FUNC_NAME, sizeof(ZEND_CLONE_FUNC_NAME)-1))) { - CG(active_class_entry)->clone = (zend_function *) CG(active_op_array); - } else if ((name->len == sizeof(ZEND_CALL_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME)-1))) { - if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) { - zend_error(E_WARNING, "The magic method __call() must have public visibility and cannot be static"); - } - CG(active_class_entry)->__call = (zend_function *) CG(active_op_array); - } else if ((name->len == sizeof(ZEND_CALLSTATIC_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_CALLSTATIC_FUNC_NAME, sizeof(ZEND_CALLSTATIC_FUNC_NAME)-1))) { - if ((fn_flags & (ZEND_ACC_PPP_MASK ^ ZEND_ACC_PUBLIC)) || (fn_flags & ZEND_ACC_STATIC) == 0) { - zend_error(E_WARNING, "The magic method __callStatic() must have public visibility and be static"); - } - CG(active_class_entry)->__callstatic = (zend_function *) CG(active_op_array); - } else if ((name->len == sizeof(ZEND_GET_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_GET_FUNC_NAME, sizeof(ZEND_GET_FUNC_NAME)-1))) { - if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) { - zend_error(E_WARNING, "The magic method __get() must have public visibility and cannot be static"); - } - CG(active_class_entry)->__get = (zend_function *) CG(active_op_array); - } else if ((name->len == sizeof(ZEND_SET_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_SET_FUNC_NAME, sizeof(ZEND_SET_FUNC_NAME)-1))) { - if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) { - zend_error(E_WARNING, "The magic method __set() must have public visibility and cannot be static"); - } - CG(active_class_entry)->__set = (zend_function *) CG(active_op_array); - } else if ((name->len == sizeof(ZEND_UNSET_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_UNSET_FUNC_NAME, sizeof(ZEND_UNSET_FUNC_NAME)-1))) { - if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) { - zend_error(E_WARNING, "The magic method __unset() must have public visibility and cannot be static"); - } - CG(active_class_entry)->__unset = (zend_function *) CG(active_op_array); - } else if ((name->len == sizeof(ZEND_ISSET_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_ISSET_FUNC_NAME, sizeof(ZEND_ISSET_FUNC_NAME)-1))) { - if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) { - zend_error(E_WARNING, "The magic method __isset() must have public visibility and cannot be static"); - } - CG(active_class_entry)->__isset = (zend_function *) CG(active_op_array); - } else if ((name->len == sizeof(ZEND_TOSTRING_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_TOSTRING_FUNC_NAME, sizeof(ZEND_TOSTRING_FUNC_NAME)-1))) { - if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) { - zend_error(E_WARNING, "The magic method __toString() must have public visibility and cannot be static"); - } - CG(active_class_entry)->__tostring = (zend_function *) CG(active_op_array); - } else if ((name->len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1))) { - if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) { - zend_error(E_WARNING, "The magic method __invoke() must have public visibility and cannot be static"); - } - } else if ((name->len == sizeof(ZEND_DEBUGINFO_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_DEBUGINFO_FUNC_NAME, sizeof(ZEND_DEBUGINFO_FUNC_NAME)-1))) { - if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) { - zend_error(E_WARNING, "The magic method __debugInfo() must have public visibility and cannot be static"); - } - CG(active_class_entry)->__debugInfo = (zend_function *) CG(active_op_array); - } else if (!(fn_flags & ZEND_ACC_STATIC)) { - CG(active_op_array)->fn_flags |= ZEND_ACC_ALLOW_STATIC; - } - free_alloca(class_lcname, use_heap); - } - - STR_RELEASE(lcname); - } else { - zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC); - zval key; - zend_string *ns_name; - - if (Z_TYPE(CG(current_namespace)) != IS_UNDEF) { - /* Prefix function name with current namespace name */ - znode tmp; - - ZVAL_DUP(&tmp.u.constant, &CG(current_namespace)); - zend_do_build_namespace_name(&tmp, &tmp, function_name TSRMLS_CC); - op_array.function_name = Z_STR(tmp.u.constant); - lcname = STR_ALLOC(Z_STRLEN(tmp.u.constant), 0); - zend_str_tolower_copy(lcname->val, Z_STRVAL(tmp.u.constant), Z_STRLEN(tmp.u.constant)); - } else { - lcname = STR_ALLOC(name->len, 0); - zend_str_tolower_copy(lcname->val, name->val, name->len); - } - - /* Function name must not conflict with import names */ - if (CG(current_import_function) && - (ns_name = zend_hash_find_ptr(CG(current_import_function), lcname)) != NULL) { - - char *tmp = zend_str_tolower_dup(ns_name->val, ns_name->len); - - if (ns_name->len != Z_STRLEN(function_name->u.constant) || - memcmp(tmp, lcname->val, Z_STRLEN(function_name->u.constant))) { - zend_error(E_COMPILE_ERROR, "Cannot declare function %s because the name is already in use", Z_STRVAL(function_name->u.constant)); - } - efree(tmp); - } - - opline->opcode = ZEND_DECLARE_FUNCTION; - opline->op1_type = IS_CONST; - build_runtime_defined_function_key(&key, lcname, LANG_SCNG(yy_text) TSRMLS_CC); - opline->op1.constant = zend_add_literal(CG(active_op_array), &key TSRMLS_CC); - opline->op2_type = IS_CONST; - LITERAL_STR(opline->op2, STR_COPY(lcname)); - opline->extended_value = ZEND_DECLARE_FUNCTION; - CG(active_op_array) = emalloc(sizeof(zend_op_array)); - memcpy(CG(active_op_array), &op_array, sizeof(zend_op_array)); - zend_hash_update_ptr(CG(function_table), Z_STR(key), CG(active_op_array)); - zend_stack_push(&CG(context_stack), (void *) &CG(context)); - zend_init_compiler_context(TSRMLS_C); - STR_RELEASE(lcname); - } - - if (CG(compiler_options) & ZEND_COMPILE_EXTENDED_INFO) { - zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC); - - opline->opcode = ZEND_EXT_NOP; - opline->lineno = function_begin_line; - SET_UNUSED(opline->op1); - SET_UNUSED(opline->op2); - } - - { - /* Push a separator to the switch stack */ - zend_switch_entry switch_entry; - - switch_entry.cond.op_type = IS_UNUSED; - switch_entry.default_case = 0; - switch_entry.control_var = 0; - - zend_stack_push(&CG(switch_cond_stack), (void *) &switch_entry); - } - - { - /* Push a separator to the foreach stack */ - zend_op dummy_opline; - - dummy_opline.result_type = IS_UNUSED; - - zend_stack_push(&CG(foreach_copy_stack), (void *) &dummy_opline); - } - - if (CG(doc_comment)) { - CG(active_op_array)->doc_comment = CG(doc_comment); - CG(doc_comment) = NULL; - } -} -/* }}} */ - void zend_do_handle_exception(TSRMLS_D) /* {{{ */ { zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC); @@ -977,39 +720,6 @@ void zend_do_handle_exception(TSRMLS_D) /* {{{ */ } /* }}} */ -void zend_do_end_function_declaration(const znode *function_token TSRMLS_DC) /* {{{ */ -{ - char lcname[16]; - int name_len; - - zend_do_extended_info(TSRMLS_C); - zend_do_return(NULL, 0 TSRMLS_CC); - - pass_two(CG(active_op_array) TSRMLS_CC); - zend_release_labels(0 TSRMLS_CC); - - if (CG(active_class_entry)) { - zend_check_magic_method_implementation(CG(active_class_entry), (zend_function*)CG(active_op_array), E_COMPILE_ERROR TSRMLS_CC); - } else { - /* we don't care if the function name is longer, in fact lowercasing only - * the beginning of the name speeds up the check process */ - name_len = CG(active_op_array)->function_name->len; - zend_str_tolower_copy(lcname, CG(active_op_array)->function_name->val, MIN(name_len, sizeof(lcname)-1)); - lcname[sizeof(lcname)-1] = '\0'; /* zend_str_tolower_copy won't necessarily set the zero byte */ - if (name_len == sizeof(ZEND_AUTOLOAD_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_AUTOLOAD_FUNC_NAME, sizeof(ZEND_AUTOLOAD_FUNC_NAME)) && CG(active_op_array)->num_args != 1) { - zend_error_noreturn(E_COMPILE_ERROR, "%s() must take exactly 1 argument", ZEND_AUTOLOAD_FUNC_NAME); - } - } - - CG(active_op_array)->line_end = zend_get_compiled_lineno(TSRMLS_C); - CG(active_op_array) = function_token->u.op_array; - - /* Pop the switch and foreach separators */ - zend_stack_del_top(&CG(switch_cond_stack)); - zend_stack_del_top(&CG(foreach_copy_stack)); -} -/* }}} */ - zend_string *zend_concat3( char *str1, size_t str1_len, char *str2, size_t str2_len, char *str3, size_t str3_len ) { diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index 4da186f..1361b52 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -481,8 +481,6 @@ ZEND_API void zend_make_immutable_array(zval *zv TSRMLS_DC); void zend_do_free(znode *op1 TSRMLS_DC); int zend_do_verify_access_types(const znode *current_access_type, const znode *new_modifier); -void zend_do_begin_function_declaration(znode *function_token, znode *function_name, int is_method, int return_reference, znode *fn_flags_znode TSRMLS_DC); -void zend_do_end_function_declaration(const znode *function_token TSRMLS_DC); void zend_do_fetch_class(znode *result, znode *class_name TSRMLS_DC); void zend_do_build_full_name(znode *result, znode *prefix, znode *name, int is_class_member TSRMLS_DC); void zend_do_return(znode *expr, int do_end_vparse TSRMLS_DC);
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index ef0f878..d54ee6e 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -710,263 +710,6 @@ int zend_do_verify_access_types(const znode *current_access_type, const znode *n } /* }}} */ -void zend_do_begin_function_declaration(znode *function_token, znode *function_name, int is_method, int return_reference, znode *fn_flags_znode TSRMLS_DC) /* {{{ */ -{ - zend_op_array op_array; - zend_string *name = Z_STR(function_name->u.constant); - int function_begin_line = function_token->EA; - zend_uint fn_flags; - zend_string *lcname; - zend_bool orig_interactive; - ALLOCA_FLAG(use_heap) - - if (is_method) { - if (CG(active_class_entry)->ce_flags & ZEND_ACC_INTERFACE) { - if ((Z_LVAL(fn_flags_znode->u.constant) & ~(ZEND_ACC_STATIC|ZEND_ACC_PUBLIC))) { - zend_error_noreturn(E_COMPILE_ERROR, "Access type for interface method %s::%s() must be omitted", CG(active_class_entry)->name->val, Z_STRVAL(function_name->u.constant)); - } - Z_LVAL(fn_flags_znode->u.constant) |= ZEND_ACC_ABSTRACT; /* propagates to the rest of the parser */ - } - fn_flags = Z_LVAL(fn_flags_znode->u.constant); /* must be done *after* the above check */ - } else { - fn_flags = 0; - } - if ((fn_flags & ZEND_ACC_STATIC) && (fn_flags & ZEND_ACC_ABSTRACT) && !(CG(active_class_entry)->ce_flags & ZEND_ACC_INTERFACE)) { - zend_error(E_STRICT, "Static function %s%s%s() should not be abstract", is_method ? CG(active_class_entry)->name->val : "", is_method ? "::" : "", Z_STRVAL(function_name->u.constant)); - } - - function_token->u.op_array = CG(active_op_array); - - orig_interactive = CG(interactive); - CG(interactive) = 0; - init_op_array(&op_array, ZEND_USER_FUNCTION, INITIAL_OP_ARRAY_SIZE TSRMLS_CC); - CG(interactive) = orig_interactive; - - op_array.function_name = name; - if (return_reference) { - op_array.fn_flags |= ZEND_ACC_RETURN_REFERENCE; - } - op_array.fn_flags |= fn_flags; - - op_array.scope = is_method?CG(active_class_entry):NULL; - op_array.prototype = NULL; - - op_array.line_start = zend_get_compiled_lineno(TSRMLS_C); - - if (is_method) { - lcname = STR_ALLOC(name->len, 0); - zend_str_tolower_copy(lcname->val, name->val, name->len); - lcname = zend_new_interned_string(lcname TSRMLS_CC); - CG(active_op_array) = emalloc(sizeof(zend_op_array)); - memcpy(CG(active_op_array), &op_array, sizeof(zend_op_array)); - if (zend_hash_add_ptr(&CG(active_class_entry)->function_table, lcname, CG(active_op_array)) == NULL) { - zend_error_noreturn(E_COMPILE_ERROR, "Cannot redeclare %s::%s()", CG(active_class_entry)->name->val, name->val); - } - - zend_stack_push(&CG(context_stack), (void *) &CG(context)); - zend_init_compiler_context(TSRMLS_C); - - if (fn_flags & ZEND_ACC_ABSTRACT) { - CG(active_class_entry)->ce_flags |= ZEND_ACC_IMPLICIT_ABSTRACT_CLASS; - } - - if (!(fn_flags & ZEND_ACC_PPP_MASK)) { - fn_flags |= ZEND_ACC_PUBLIC; - } - - if (CG(active_class_entry)->ce_flags & ZEND_ACC_INTERFACE) { - if ((name->len == sizeof(ZEND_CALL_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME)-1))) { - if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) { - zend_error(E_WARNING, "The magic method __call() must have public visibility and cannot be static"); - } - } else if ((name->len == sizeof(ZEND_CALLSTATIC_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_CALLSTATIC_FUNC_NAME, sizeof(ZEND_CALLSTATIC_FUNC_NAME)-1))) { - if ((fn_flags & (ZEND_ACC_PPP_MASK ^ ZEND_ACC_PUBLIC)) || (fn_flags & ZEND_ACC_STATIC) == 0) { - zend_error(E_WARNING, "The magic method __callStatic() must have public visibility and be static"); - } - } else if ((name->len == sizeof(ZEND_GET_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_GET_FUNC_NAME, sizeof(ZEND_GET_FUNC_NAME)-1))) { - if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) { - zend_error(E_WARNING, "The magic method __get() must have public visibility and cannot be static"); - } - } else if ((name->len == sizeof(ZEND_SET_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_SET_FUNC_NAME, sizeof(ZEND_SET_FUNC_NAME)-1))) { - if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) { - zend_error(E_WARNING, "The magic method __set() must have public visibility and cannot be static"); - } - } else if ((name->len == sizeof(ZEND_UNSET_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_UNSET_FUNC_NAME, sizeof(ZEND_UNSET_FUNC_NAME)-1))) { - if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) { - zend_error(E_WARNING, "The magic method __unset() must have public visibility and cannot be static"); - } - } else if ((name->len == sizeof(ZEND_ISSET_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_ISSET_FUNC_NAME, sizeof(ZEND_ISSET_FUNC_NAME)-1))) { - if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) { - zend_error(E_WARNING, "The magic method __isset() must have public visibility and cannot be static"); - } - } else if ((name->len == sizeof(ZEND_TOSTRING_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_TOSTRING_FUNC_NAME, sizeof(ZEND_TOSTRING_FUNC_NAME)-1))) { - if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) { - zend_error(E_WARNING, "The magic method __toString() must have public visibility and cannot be static"); - } - } else if ((name->len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1))) { - if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) { - zend_error(E_WARNING, "The magic method __invoke() must have public visibility and cannot be static"); - } - - } else if ((name->len == sizeof(ZEND_DEBUGINFO_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_DEBUGINFO_FUNC_NAME, sizeof(ZEND_DEBUGINFO_FUNC_NAME)-1))) { - if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) { - zend_error(E_WARNING, "The magic method __debugInfo() must have public visibility and cannot be static"); - } - } - } else { - char *class_lcname; - - class_lcname = do_alloca(CG(active_class_entry)->name->len + 1, use_heap); - zend_str_tolower_copy(class_lcname, CG(active_class_entry)->name->val, CG(active_class_entry)->name->len); - /* Improve after RC: cache the lowercase class name */ - - if ((CG(active_class_entry)->name->len == name->len) && ((CG(active_class_entry)->ce_flags & ZEND_ACC_TRAIT) != ZEND_ACC_TRAIT) && (!memcmp(class_lcname, lcname->val, name->len))) { - if (!CG(active_class_entry)->constructor) { - CG(active_class_entry)->constructor = (zend_function *) CG(active_op_array); - } - } else if ((name->len == sizeof(ZEND_CONSTRUCTOR_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_CONSTRUCTOR_FUNC_NAME, sizeof(ZEND_CONSTRUCTOR_FUNC_NAME)-1))) { - if (CG(active_class_entry)->constructor) { - zend_error(E_STRICT, "Redefining already defined constructor for class %s", CG(active_class_entry)->name->val); - } - CG(active_class_entry)->constructor = (zend_function *) CG(active_op_array); - } else if ((name->len == sizeof(ZEND_DESTRUCTOR_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_DESTRUCTOR_FUNC_NAME, sizeof(ZEND_DESTRUCTOR_FUNC_NAME)-1))) { - CG(active_class_entry)->destructor = (zend_function *) CG(active_op_array); - } else if ((name->len == sizeof(ZEND_CLONE_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_CLONE_FUNC_NAME, sizeof(ZEND_CLONE_FUNC_NAME)-1))) { - CG(active_class_entry)->clone = (zend_function *) CG(active_op_array); - } else if ((name->len == sizeof(ZEND_CALL_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME)-1))) { - if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) { - zend_error(E_WARNING, "The magic method __call() must have public visibility and cannot be static"); - } - CG(active_class_entry)->__call = (zend_function *) CG(active_op_array); - } else if ((name->len == sizeof(ZEND_CALLSTATIC_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_CALLSTATIC_FUNC_NAME, sizeof(ZEND_CALLSTATIC_FUNC_NAME)-1))) { - if ((fn_flags & (ZEND_ACC_PPP_MASK ^ ZEND_ACC_PUBLIC)) || (fn_flags & ZEND_ACC_STATIC) == 0) { - zend_error(E_WARNING, "The magic method __callStatic() must have public visibility and be static"); - } - CG(active_class_entry)->__callstatic = (zend_function *) CG(active_op_array); - } else if ((name->len == sizeof(ZEND_GET_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_GET_FUNC_NAME, sizeof(ZEND_GET_FUNC_NAME)-1))) { - if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) { - zend_error(E_WARNING, "The magic method __get() must have public visibility and cannot be static"); - } - CG(active_class_entry)->__get = (zend_function *) CG(active_op_array); - } else if ((name->len == sizeof(ZEND_SET_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_SET_FUNC_NAME, sizeof(ZEND_SET_FUNC_NAME)-1))) { - if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) { - zend_error(E_WARNING, "The magic method __set() must have public visibility and cannot be static"); - } - CG(active_class_entry)->__set = (zend_function *) CG(active_op_array); - } else if ((name->len == sizeof(ZEND_UNSET_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_UNSET_FUNC_NAME, sizeof(ZEND_UNSET_FUNC_NAME)-1))) { - if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) { - zend_error(E_WARNING, "The magic method __unset() must have public visibility and cannot be static"); - } - CG(active_class_entry)->__unset = (zend_function *) CG(active_op_array); - } else if ((name->len == sizeof(ZEND_ISSET_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_ISSET_FUNC_NAME, sizeof(ZEND_ISSET_FUNC_NAME)-1))) { - if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) { - zend_error(E_WARNING, "The magic method __isset() must have public visibility and cannot be static"); - } - CG(active_class_entry)->__isset = (zend_function *) CG(active_op_array); - } else if ((name->len == sizeof(ZEND_TOSTRING_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_TOSTRING_FUNC_NAME, sizeof(ZEND_TOSTRING_FUNC_NAME)-1))) { - if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) { - zend_error(E_WARNING, "The magic method __toString() must have public visibility and cannot be static"); - } - CG(active_class_entry)->__tostring = (zend_function *) CG(active_op_array); - } else if ((name->len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1))) { - if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) { - zend_error(E_WARNING, "The magic method __invoke() must have public visibility and cannot be static"); - } - } else if ((name->len == sizeof(ZEND_DEBUGINFO_FUNC_NAME)-1) && (!memcmp(lcname->val, ZEND_DEBUGINFO_FUNC_NAME, sizeof(ZEND_DEBUGINFO_FUNC_NAME)-1))) { - if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) { - zend_error(E_WARNING, "The magic method __debugInfo() must have public visibility and cannot be static"); - } - CG(active_class_entry)->__debugInfo = (zend_function *) CG(active_op_array); - } else if (!(fn_flags & ZEND_ACC_STATIC)) { - CG(active_op_array)->fn_flags |= ZEND_ACC_ALLOW_STATIC; - } - free_alloca(class_lcname, use_heap); - } - - STR_RELEASE(lcname); - } else { - zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC); - zval key; - zend_string *ns_name; - - if (Z_TYPE(CG(current_namespace)) != IS_UNDEF) { - /* Prefix function name with current namespace name */ - znode tmp; - - ZVAL_DUP(&tmp.u.constant, &CG(current_namespace)); - zend_do_build_namespace_name(&tmp, &tmp, function_name TSRMLS_CC); - op_array.function_name = Z_STR(tmp.u.constant); - lcname = STR_ALLOC(Z_STRLEN(tmp.u.constant), 0); - zend_str_tolower_copy(lcname->val, Z_STRVAL(tmp.u.constant), Z_STRLEN(tmp.u.constant)); - } else { - lcname = STR_ALLOC(name->len, 0); - zend_str_tolower_copy(lcname->val, name->val, name->len); - } - - /* Function name must not conflict with import names */ - if (CG(current_import_function) && - (ns_name = zend_hash_find_ptr(CG(current_import_function), lcname)) != NULL) { - - char *tmp = zend_str_tolower_dup(ns_name->val, ns_name->len); - - if (ns_name->len != Z_STRLEN(function_name->u.constant) || - memcmp(tmp, lcname->val, Z_STRLEN(function_name->u.constant))) { - zend_error(E_COMPILE_ERROR, "Cannot declare function %s because the name is already in use", Z_STRVAL(function_name->u.constant)); - } - efree(tmp); - } - - opline->opcode = ZEND_DECLARE_FUNCTION; - opline->op1_type = IS_CONST; - build_runtime_defined_function_key(&key, lcname, LANG_SCNG(yy_text) TSRMLS_CC); - opline->op1.constant = zend_add_literal(CG(active_op_array), &key TSRMLS_CC); - opline->op2_type = IS_CONST; - LITERAL_STR(opline->op2, STR_COPY(lcname)); - opline->extended_value = ZEND_DECLARE_FUNCTION; - CG(active_op_array) = emalloc(sizeof(zend_op_array)); - memcpy(CG(active_op_array), &op_array, sizeof(zend_op_array)); - zend_hash_update_ptr(CG(function_table), Z_STR(key), CG(active_op_array)); - zend_stack_push(&CG(context_stack), (void *) &CG(context)); - zend_init_compiler_context(TSRMLS_C); - STR_RELEASE(lcname); - } - - if (CG(compiler_options) & ZEND_COMPILE_EXTENDED_INFO) { - zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC); - - opline->opcode = ZEND_EXT_NOP; - opline->lineno = function_begin_line; - SET_UNUSED(opline->op1); - SET_UNUSED(opline->op2); - } - - { - /* Push a separator to the switch stack */ - zend_switch_entry switch_entry; - - switch_entry.cond.op_type = IS_UNUSED; - switch_entry.default_case = 0; - switch_entry.control_var = 0; - - zend_stack_push(&CG(switch_cond_stack), (void *) &switch_entry); - } - - { - /* Push a separator to the foreach stack */ - zend_op dummy_opline; - - dummy_opline.result_type = IS_UNUSED; - - zend_stack_push(&CG(foreach_copy_stack), (void *) &dummy_opline); - } - - if (CG(doc_comment)) { - CG(active_op_array)->doc_comment = CG(doc_comment); - CG(doc_comment) = NULL; - } -} -/* }}} */ - void zend_do_handle_exception(TSRMLS_D) /* {{{ */ { zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC); @@ -977,39 +720,6 @@ void zend_do_handle_exception(TSRMLS_D) /* {{{ */ } /* }}} */ -void zend_do_end_function_declaration(const znode *function_token TSRMLS_DC) /* {{{ */ -{ - char lcname[16]; - int name_len; - - zend_do_extended_info(TSRMLS_C); - zend_do_return(NULL, 0 TSRMLS_CC); - - pass_two(CG(active_op_array) TSRMLS_CC); - zend_release_labels(0 TSRMLS_CC); - - if (CG(active_class_entry)) { - zend_check_magic_method_implementation(CG(active_class_entry), (zend_function*)CG(active_op_array), E_COMPILE_ERROR TSRMLS_CC); - } else { - /* we don't care if the function name is longer, in fact lowercasing only - * the beginning of the name speeds up the check process */ - name_len = CG(active_op_array)->function_name->len; - zend_str_tolower_copy(lcname, CG(active_op_array)->function_name->val, MIN(name_len, sizeof(lcname)-1)); - lcname[sizeof(lcname)-1] = '\0'; /* zend_str_tolower_copy won't necessarily set the zero byte */ - if (name_len == sizeof(ZEND_AUTOLOAD_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_AUTOLOAD_FUNC_NAME, sizeof(ZEND_AUTOLOAD_FUNC_NAME)) && CG(active_op_array)->num_args != 1) { - zend_error_noreturn(E_COMPILE_ERROR, "%s() must take exactly 1 argument", ZEND_AUTOLOAD_FUNC_NAME); - } - } - - CG(active_op_array)->line_end = zend_get_compiled_lineno(TSRMLS_C); - CG(active_op_array) = function_token->u.op_array; - - /* Pop the switch and foreach separators */ - zend_stack_del_top(&CG(switch_cond_stack)); - zend_stack_del_top(&CG(foreach_copy_stack)); -} -/* }}} */ - zend_string *zend_concat3( char *str1, size_t str1_len, char *str2, size_t str2_len, char *str3, size_t str3_len ) { diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index 4da186f..1361b52 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -481,8 +481,6 @@ ZEND_API void zend_make_immutable_array(zval *zv TSRMLS_DC); void zend_do_free(znode *op1 TSRMLS_DC); int zend_do_verify_access_types(const znode *current_access_type, const znode *new_modifier); -void zend_do_begin_function_declaration(znode *function_token, znode *function_name, int is_method, int return_reference, znode *fn_flags_znode TSRMLS_DC); -void zend_do_end_function_declaration(const znode *function_token TSRMLS_DC); void zend_do_fetch_class(znode *result, znode *class_name TSRMLS_DC); void zend_do_build_full_name(znode *result, znode *prefix, znode *name, int is_class_member TSRMLS_DC); void zend_do_return(znode *expr, int do_end_vparse TSRMLS_DC);