com php-src: Compile intval() etc to casts: Zend/zend_compile .c
| From: | Nikita Popov | Date: | Fri, 09 Sep 2016 13:45:46 +0000 |
| Subject: | com php-src: Compile intval() etc to casts: Zend/zend_compile .c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-94399@lists.php.net to get a copy of this message | ||
Commit: 30af80610e98ef7e41f706d39a1278d69e6d085f
Author: Nikita Popov <nikic@php.net> Fri, 9 Sep 2016 15:45:46 +0200
Parents: b4213f0d0bec0fbeedf61312c0fc009a67ed86c1
Branches: PHP-7.1 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=30af80610e98ef7e41f706d39a1278d69e6d085f
Log:
Compile intval() etc to casts
Changed paths:
M Zend/zend_compile.c
Diff:
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 26930f7..353cef9 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) {