Skip to content

zend_compile.c: zend_is_variable(). Removed unnecessary checks. Namin… #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 27, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -2081,9 +2081,7 @@ void zend_emit_final_return(int return_one) /* {{{ */
static inline zend_bool zend_is_variable(zend_ast *ast) /* {{{ */
{
return ast->kind == ZEND_AST_VAR || ast->kind == ZEND_AST_DIM
|| ast->kind == ZEND_AST_PROP || ast->kind == ZEND_AST_STATIC_PROP
|| ast->kind == ZEND_AST_CALL || ast->kind == ZEND_AST_METHOD_CALL
|| ast->kind == ZEND_AST_STATIC_CALL;
|| ast->kind == ZEND_AST_PROP || ast->kind == ZEND_AST_STATIC_PROP;
}
/* }}} */

Expand All @@ -2095,6 +2093,12 @@ static inline zend_bool zend_is_call(zend_ast *ast) /* {{{ */
}
/* }}} */

static inline zend_bool zend_is_variable_or_call(zend_ast *ast) /* {{{ */
{
return zend_is_variable(ast) || zend_is_call(ast);
}
/* }}} */

static inline zend_bool zend_is_unticked_stmt(zend_ast *ast) /* {{{ */
{
return ast->kind == ZEND_AST_STMT_LIST || ast->kind == ZEND_AST_LABEL
Expand All @@ -2109,7 +2113,7 @@ static inline zend_bool zend_can_write_to_variable(zend_ast *ast) /* {{{ */
ast = ast->child[0];
}

return zend_is_variable(ast);
return zend_is_variable_or_call(ast);
}
/* }}} */

Expand Down Expand Up @@ -2607,7 +2611,7 @@ zend_bool zend_is_assign_to_self(zend_ast *var_ast, zend_ast *expr_ast) /* {{{ *
return 0;
}

while (zend_is_variable(var_ast) && var_ast->kind != ZEND_AST_VAR) {
while (zend_is_variable_or_call(var_ast)) {
var_ast = var_ast->child[0];
}

Expand Down Expand Up @@ -2741,7 +2745,7 @@ void zend_compile_assign(znode *result, zend_ast *ast) /* {{{ */
return;
case ZEND_AST_ARRAY:
if (zend_propagate_list_refs(var_ast)) {
if (!zend_is_variable(expr_ast)) {
if (!zend_is_variable_or_call(expr_ast)) {
zend_error_noreturn(E_COMPILE_ERROR,
"Cannot assign reference to non referencable value");
}
Expand Down Expand Up @@ -2938,7 +2942,7 @@ uint32_t zend_compile_args(zend_ast *ast, zend_function *fbc) /* {{{ */
}

arg_count++;
if (zend_is_variable(arg)) {
if (zend_is_variable_or_call(arg)) {
if (zend_is_call(arg)) {
zend_compile_var(&arg_node, arg, BP_VAR_R, 0);
if (arg_node.op_type & (IS_CONST|IS_TMP_VAR)) {
Expand Down Expand Up @@ -4228,7 +4232,7 @@ void zend_compile_return(zend_ast *ast) /* {{{ */
if (!expr_ast) {
expr_node.op_type = IS_CONST;
ZVAL_NULL(&expr_node.u.constant);
} else if (by_ref && zend_is_variable(expr_ast) && !zend_is_call(expr_ast)) {
} else if (by_ref && zend_is_variable(expr_ast)) {
zend_compile_var(&expr_node, expr_ast, BP_VAR_W, 1);
} else {
zend_compile_expr(&expr_node, expr_ast);
Expand Down Expand Up @@ -4562,8 +4566,7 @@ void zend_compile_foreach(zend_ast *ast) /* {{{ */
zend_ast *key_ast = ast->child[2];
zend_ast *stmt_ast = ast->child[3];
zend_bool by_ref = value_ast->kind == ZEND_AST_REF;
zend_bool is_variable = zend_is_variable(expr_ast) && !zend_is_call(expr_ast)
&& zend_can_write_to_variable(expr_ast);
zend_bool is_variable = zend_is_variable(expr_ast) && zend_can_write_to_variable(expr_ast);

znode expr_node, reset_node, value_node, key_node;
zend_op *opline;
Expand Down Expand Up @@ -7409,7 +7412,7 @@ void zend_compile_yield(znode *result, zend_ast *ast) /* {{{ */
}

if (value_ast) {
if (returns_by_ref && zend_is_variable(value_ast) && !zend_is_call(value_ast)) {
if (returns_by_ref && zend_is_variable(value_ast)) {
zend_compile_var(&value_node, value_ast, BP_VAR_W, 1);
} else {
zend_compile_expr(&value_node, value_ast);
Expand Down Expand Up @@ -7499,7 +7502,7 @@ void zend_compile_isset_or_empty(znode *result, zend_ast *ast) /* {{{ */

ZEND_ASSERT(ast->kind == ZEND_AST_ISSET || ast->kind == ZEND_AST_EMPTY);

if (!zend_is_variable(var_ast) || zend_is_call(var_ast)) {
if (!zend_is_variable(var_ast)) {
if (ast->kind == ZEND_AST_EMPTY) {
/* empty(expr) can be transformed to !expr */
zend_ast *not_ast = zend_ast_create_ex(ZEND_AST_UNARY_OP, ZEND_BOOL_NOT, var_ast);
Expand Down