Skip to content

Commit 3a0fc00

Browse files
rjhdbykrakjoe
rjhdby
authored andcommitted
zend_compile.c: zend_is_variable(). Removed unnecessary checks. Naming according to internal logic.
1 parent 9be6b16 commit 3a0fc00

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

Zend/zend_compile.c

+15-12
Original file line numberDiff line numberDiff line change
@@ -2081,9 +2081,7 @@ void zend_emit_final_return(int return_one) /* {{{ */
20812081
static inline zend_bool zend_is_variable(zend_ast *ast) /* {{{ */
20822082
{
20832083
return ast->kind == ZEND_AST_VAR || ast->kind == ZEND_AST_DIM
2084-
|| ast->kind == ZEND_AST_PROP || ast->kind == ZEND_AST_STATIC_PROP
2085-
|| ast->kind == ZEND_AST_CALL || ast->kind == ZEND_AST_METHOD_CALL
2086-
|| ast->kind == ZEND_AST_STATIC_CALL;
2084+
|| ast->kind == ZEND_AST_PROP || ast->kind == ZEND_AST_STATIC_PROP;
20872085
}
20882086
/* }}} */
20892087

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

2096+
static inline zend_bool zend_is_variable_or_call(zend_ast *ast) /* {{{ */
2097+
{
2098+
return zend_is_variable(ast) || zend_is_call(ast);
2099+
}
2100+
/* }}} */
2101+
20982102
static inline zend_bool zend_is_unticked_stmt(zend_ast *ast) /* {{{ */
20992103
{
21002104
return ast->kind == ZEND_AST_STMT_LIST || ast->kind == ZEND_AST_LABEL
@@ -2109,7 +2113,7 @@ static inline zend_bool zend_can_write_to_variable(zend_ast *ast) /* {{{ */
21092113
ast = ast->child[0];
21102114
}
21112115

2112-
return zend_is_variable(ast);
2116+
return zend_is_variable_or_call(ast);
21132117
}
21142118
/* }}} */
21152119

@@ -2607,7 +2611,7 @@ zend_bool zend_is_assign_to_self(zend_ast *var_ast, zend_ast *expr_ast) /* {{{ *
26072611
return 0;
26082612
}
26092613

2610-
while (zend_is_variable(var_ast) && var_ast->kind != ZEND_AST_VAR) {
2614+
while (zend_is_variable_or_call(var_ast)) {
26112615
var_ast = var_ast->child[0];
26122616
}
26132617

@@ -2741,7 +2745,7 @@ void zend_compile_assign(znode *result, zend_ast *ast) /* {{{ */
27412745
return;
27422746
case ZEND_AST_ARRAY:
27432747
if (zend_propagate_list_refs(var_ast)) {
2744-
if (!zend_is_variable(expr_ast)) {
2748+
if (!zend_is_variable_or_call(expr_ast)) {
27452749
zend_error_noreturn(E_COMPILE_ERROR,
27462750
"Cannot assign reference to non referencable value");
27472751
}
@@ -2938,7 +2942,7 @@ uint32_t zend_compile_args(zend_ast *ast, zend_function *fbc) /* {{{ */
29382942
}
29392943

29402944
arg_count++;
2941-
if (zend_is_variable(arg)) {
2945+
if (zend_is_variable_or_call(arg)) {
29422946
if (zend_is_call(arg)) {
29432947
zend_compile_var(&arg_node, arg, BP_VAR_R, 0);
29442948
if (arg_node.op_type & (IS_CONST|IS_TMP_VAR)) {
@@ -4228,7 +4232,7 @@ void zend_compile_return(zend_ast *ast) /* {{{ */
42284232
if (!expr_ast) {
42294233
expr_node.op_type = IS_CONST;
42304234
ZVAL_NULL(&expr_node.u.constant);
4231-
} else if (by_ref && zend_is_variable(expr_ast) && !zend_is_call(expr_ast)) {
4235+
} else if (by_ref && zend_is_variable(expr_ast)) {
42324236
zend_compile_var(&expr_node, expr_ast, BP_VAR_W, 1);
42334237
} else {
42344238
zend_compile_expr(&expr_node, expr_ast);
@@ -4562,8 +4566,7 @@ void zend_compile_foreach(zend_ast *ast) /* {{{ */
45624566
zend_ast *key_ast = ast->child[2];
45634567
zend_ast *stmt_ast = ast->child[3];
45644568
zend_bool by_ref = value_ast->kind == ZEND_AST_REF;
4565-
zend_bool is_variable = zend_is_variable(expr_ast) && !zend_is_call(expr_ast)
4566-
&& zend_can_write_to_variable(expr_ast);
4569+
zend_bool is_variable = zend_is_variable(expr_ast) && zend_can_write_to_variable(expr_ast);
45674570

45684571
znode expr_node, reset_node, value_node, key_node;
45694572
zend_op *opline;
@@ -7409,7 +7412,7 @@ void zend_compile_yield(znode *result, zend_ast *ast) /* {{{ */
74097412
}
74107413

74117414
if (value_ast) {
7412-
if (returns_by_ref && zend_is_variable(value_ast) && !zend_is_call(value_ast)) {
7415+
if (returns_by_ref && zend_is_variable(value_ast)) {
74137416
zend_compile_var(&value_node, value_ast, BP_VAR_W, 1);
74147417
} else {
74157418
zend_compile_expr(&value_node, value_ast);
@@ -7499,7 +7502,7 @@ void zend_compile_isset_or_empty(znode *result, zend_ast *ast) /* {{{ */
74997502

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

7502-
if (!zend_is_variable(var_ast) || zend_is_call(var_ast)) {
7505+
if (!zend_is_variable(var_ast)) {
75037506
if (ast->kind == ZEND_AST_EMPTY) {
75047507
/* empty(expr) can be transformed to !expr */
75057508
zend_ast *not_ast = zend_ast_create_ex(ZEND_AST_UNARY_OP, ZEND_BOOL_NOT, var_ast);

0 commit comments

Comments
 (0)