summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikic@php.net>2016-09-28 21:41:56 +0200
committerNikita Popov <nikic@php.net>2016-09-28 21:43:48 +0200
commit19f1ff5ad0d098eb1a84cd2f93df580941a57a8e (patch)
treeb1aeee36403a38601d3b137e21f3b04270d34b0e
parent6f9e5684a1b1a52b0a14c531c275a8f009d5d293 (diff)
downloadphp-git-19f1ff5ad0d098eb1a84cd2f93df580941a57a8e.tar.gz
Combine code for keyed/unkeyed list()
-rw-r--r--Zend/zend_compile.c87
1 files changed, 29 insertions, 58 deletions
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 1501acec1e..87590e71e4 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -2804,75 +2804,54 @@ static void zend_verify_list_assign_target(zend_ast *var_ast, zend_bool old_styl
}
/* }}} */
-static void zend_compile_unkeyed_list_assign(zend_ast_list *list, znode *expr_node, zend_bool old_style) /* {{{ */
+static void zend_compile_list_assign(
+ znode *result, zend_ast *ast, znode *expr_node, zend_bool old_style) /* {{{ */
{
+ zend_ast_list *list = zend_ast_get_list(ast);
uint32_t i;
zend_bool has_elems = 0;
+ zend_bool is_keyed =
+ list->children > 0 && list->child[0] != NULL && list->child[0]->child[1] != NULL;
for (i = 0; i < list->children; ++i) {
zend_ast *elem_ast = list->child[i];
- zend_ast *var_ast;
+ zend_ast *var_ast, *key_ast;
znode fetch_result, dim_node;
if (elem_ast == NULL) {
- continue;
+ if (is_keyed) {
+ zend_error(E_COMPILE_ERROR,
+ "Cannot use empty array entries in keyed array assignment");
+ } else {
+ continue;
+ }
}
+
if (elem_ast->attr) {
zend_error(E_COMPILE_ERROR, "[] and list() assignments cannot be by reference");
}
var_ast = elem_ast->child[0];
+ key_ast = elem_ast->child[1];
has_elems = 1;
- dim_node.op_type = IS_CONST;
- ZVAL_LONG(&dim_node.u.constant, i);
-
- if (expr_node->op_type == IS_CONST) {
- Z_TRY_ADDREF(expr_node->u.constant);
- }
-
- if (elem_ast->child[1] != NULL) {
- zend_error(E_COMPILE_ERROR, "Cannot mix keyed and unkeyed array entries in assignments");
- }
-
- zend_verify_list_assign_target(var_ast, old_style);
-
- zend_emit_op(&fetch_result, ZEND_FETCH_LIST, expr_node, &dim_node);
- zend_emit_assign_znode(var_ast, &fetch_result);
- }
-
- if (has_elems == 0) {
- zend_error_noreturn(E_COMPILE_ERROR, "Cannot use empty list");
- }
-
-}
-/* }}} */
-
-static void zend_compile_keyed_list_assign(zend_ast_list *list, znode *expr_node, zend_bool old_style) /* {{{ */
-{
- uint32_t i;
-
- for (i = 0; i < list->children; ++i) {
- zend_ast *elem_ast = list->child[i];
- zend_ast *var_ast, *key_ast;
- znode fetch_result, dim_node;
-
- if (elem_ast == NULL) {
- zend_error(E_COMPILE_ERROR, "Cannot use empty array entries in keyed array assignment");
- }
- if (elem_ast->attr) {
- zend_error(E_COMPILE_ERROR, "[] and list() assignments cannot be by reference");
- }
+ if (is_keyed) {
+ if (key_ast == NULL) {
+ zend_error(E_COMPILE_ERROR,
+ "Cannot mix keyed and unkeyed array entries in assignments");
+ }
- var_ast = elem_ast->child[0];
- key_ast = elem_ast->child[1];
+ zend_compile_expr(&dim_node, key_ast);
+ } else {
+ if (key_ast != NULL) {
+ zend_error(E_COMPILE_ERROR,
+ "Cannot mix keyed and unkeyed array entries in assignments");
+ }
- if (key_ast == NULL) {
- zend_error(E_COMPILE_ERROR, "Cannot mix keyed and unkeyed array entries in assignments");
+ dim_node.op_type = IS_CONST;
+ ZVAL_LONG(&dim_node.u.constant, i);
}
- zend_compile_expr(&dim_node, key_ast);
-
if (expr_node->op_type == IS_CONST) {
Z_TRY_ADDREF(expr_node->u.constant);
}
@@ -2882,17 +2861,9 @@ static void zend_compile_keyed_list_assign(zend_ast_list *list, znode *expr_node
zend_emit_op(&fetch_result, ZEND_FETCH_LIST, expr_node, &dim_node);
zend_emit_assign_znode(var_ast, &fetch_result);
}
-}
-/* }}} */
-
-static void zend_compile_list_assign(znode *result, zend_ast *ast, znode *expr_node, zend_bool old_style) /* {{{ */
-{
- zend_ast_list *list = zend_ast_get_list(ast);
- if (list->children > 0 && list->child[0] != NULL && list->child[0]->child[1] != NULL /* has key */) {
- zend_compile_keyed_list_assign(list, expr_node, old_style);
- } else {
- zend_compile_unkeyed_list_assign(list, expr_node, old_style);
+ if (has_elems == 0) {
+ zend_error_noreturn(E_COMPILE_ERROR, "Cannot use empty list");
}
*result = *expr_node;