From: Nikita Popov Date: Fri, 9 Sep 2016 13:45:46 +0000 (+0200) Subject: Compile intval() etc to casts X-Git-Tag: php-7.1.0RC2~41 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=30af80610e98ef7e41f706d39a1278d69e6d085f;p=php Compile intval() etc to casts --- diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 26930f7ece..353cef9579 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -3412,6 +3412,22 @@ int zend_compile_func_typecheck(znode *result, zend_ast_list *args, uint32_t typ } /* }}} */ +int zend_compile_func_cast(znode *result, zend_ast_list *args, uint32_t type) /* {{{ */ +{ + znode arg_node; + zend_op *opline; + + if (args->children != 1 || args->child[0]->kind == ZEND_AST_UNPACK) { + return FAILURE; + } + + zend_compile_expr(&arg_node, args->child[0]); + opline = zend_emit_op_tmp(result, ZEND_CAST, &arg_node, NULL); + opline->extended_value = type; + return SUCCESS; +} +/* }}} */ + int zend_compile_func_defined(znode *result, zend_ast_list *args) /* {{{ */ { zend_string *name; @@ -3677,6 +3693,16 @@ int zend_try_compile_special_func(znode *result, zend_string *lcname, zend_ast_l return zend_compile_func_typecheck(result, args, IS_OBJECT); } else if (zend_string_equals_literal(lcname, "is_resource")) { return zend_compile_func_typecheck(result, args, IS_RESOURCE); + } else if (zend_string_equals_literal(lcname, "boolval")) { + return zend_compile_func_cast(result, args, _IS_BOOL); + } else if (zend_string_equals_literal(lcname, "intval")) { + return zend_compile_func_cast(result, args, IS_LONG); + } else if (zend_string_equals_literal(lcname, "floatval") + || zend_string_equals_literal(lcname, "doubleval") + ) { + return zend_compile_func_cast(result, args, IS_DOUBLE); + } else if (zend_string_equals_literal(lcname, "strval")) { + return zend_compile_func_cast(result, args, IS_STRING); } else if (zend_string_equals_literal(lcname, "defined")) { return zend_compile_func_defined(result, args); } else if (zend_string_equals_literal(lcname, "chr") && type == BP_VAR_R) {