mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Rename ZEND_CONST to ZEND_AST_ZVAL
This commit is contained in:
parent
64dab4b914
commit
111ad71d38
4 changed files with 39 additions and 50 deletions
|
@ -23,15 +23,6 @@
|
|||
#include "zend_API.h"
|
||||
#include "zend_operators.h"
|
||||
|
||||
ZEND_API zend_ast *zend_ast_create_constant(zval *zv)
|
||||
{
|
||||
zend_ast_zval *ast = emalloc(sizeof(zend_ast_zval));
|
||||
ast->kind = ZEND_CONST;
|
||||
ast->attr = 0;
|
||||
ZVAL_COPY_VALUE(&ast->val, zv);
|
||||
return (zend_ast *) ast;
|
||||
}
|
||||
|
||||
ZEND_API zend_ast *zend_ast_create_znode(znode *node)
|
||||
{
|
||||
zend_ast_znode *ast = emalloc(sizeof(zend_ast_znode));
|
||||
|
@ -44,7 +35,7 @@ ZEND_API zend_ast *zend_ast_create_znode(znode *node)
|
|||
ZEND_API zend_ast *zend_ast_create_zval_ex(zval *zv, zend_ast_attr attr)
|
||||
{
|
||||
zend_ast_zval *ast = emalloc(sizeof(zend_ast_zval));
|
||||
ast->kind = ZEND_CONST;
|
||||
ast->kind = ZEND_AST_ZVAL;
|
||||
ast->attr = attr;
|
||||
ZVAL_COPY_VALUE(&ast->val, zv);
|
||||
return (zend_ast *) ast;
|
||||
|
@ -117,7 +108,7 @@ ZEND_API int zend_ast_is_ct_constant(zend_ast *ast)
|
|||
{
|
||||
int i;
|
||||
|
||||
if (ast->kind == ZEND_CONST) {
|
||||
if (ast->kind == ZEND_AST_ZVAL) {
|
||||
return !Z_CONSTANT_P(zend_ast_get_zval(ast));
|
||||
} else {
|
||||
for (i = 0; i < ast->children; i++) {
|
||||
|
@ -201,7 +192,7 @@ ZEND_API void zend_ast_evaluate(zval *result, zend_ast *ast, zend_class_entry *s
|
|||
boolean_not_function(result, &op1 TSRMLS_CC);
|
||||
zval_dtor(&op1);
|
||||
break;
|
||||
case ZEND_CONST:
|
||||
case ZEND_AST_ZVAL:
|
||||
ZVAL_DUP(result, zend_ast_get_zval(ast));
|
||||
if (Z_OPT_CONSTANT_P(result)) {
|
||||
zval_update_constant_ex(result, 1, scope TSRMLS_CC);
|
||||
|
@ -280,14 +271,15 @@ ZEND_API zend_ast *zend_ast_copy(zend_ast *ast)
|
|||
{
|
||||
if (ast == NULL) {
|
||||
return NULL;
|
||||
} else if (ast->kind == ZEND_CONST) {
|
||||
zend_ast *copy = zend_ast_create_constant(zend_ast_get_zval(ast));
|
||||
} else if (ast->kind == ZEND_AST_ZVAL) {
|
||||
zend_ast *copy = zend_ast_create_zval_ex(zend_ast_get_zval(ast), ast->attr);
|
||||
zval_copy_ctor(zend_ast_get_zval(copy));
|
||||
return copy;
|
||||
} else if (ast->children) {
|
||||
zend_ast *new = emalloc(sizeof(zend_ast) + sizeof(zend_ast *) * (ast->children - 1));
|
||||
int i;
|
||||
new->kind = ast->kind;
|
||||
new->attr = ast->attr;
|
||||
new->children = ast->children;
|
||||
for (i = 0; i < ast->children; i++) {
|
||||
new->child[i] = zend_ast_copy(ast->child[i]);
|
||||
|
@ -301,7 +293,7 @@ ZEND_API void zend_ast_destroy(zend_ast *ast)
|
|||
{
|
||||
int i;
|
||||
|
||||
if (ast->kind == ZEND_CONST) {
|
||||
if (ast->kind == ZEND_AST_ZVAL) {
|
||||
zval_ptr_dtor(zend_ast_get_zval(ast));
|
||||
} else if (ast->kind != ZEND_AST_ZNODE) {
|
||||
for (i = 0; i < ast->children; i++) {
|
||||
|
|
|
@ -26,8 +26,7 @@
|
|||
|
||||
enum _zend_ast_kind {
|
||||
/* first 256 kinds are reserved for opcodes */
|
||||
ZEND_CONST = 256, /* TODO.AST: Split in constant lookup and literal zval */
|
||||
|
||||
ZEND_AST_ZVAL = 256,
|
||||
ZEND_AST_ZNODE,
|
||||
|
||||
ZEND_AST_VAR,
|
||||
|
@ -97,8 +96,6 @@ static inline zval *zend_ast_get_zval(zend_ast *ast) {
|
|||
return &((zend_ast_zval *) ast)->val;
|
||||
}
|
||||
|
||||
ZEND_API zend_ast *zend_ast_create_constant(zval *zv);
|
||||
|
||||
ZEND_API zend_ast *zend_ast_create_zval_ex(zval *zv, zend_ast_attr attr);
|
||||
|
||||
ZEND_API zend_ast *zend_ast_create_unary_ex(
|
||||
|
@ -139,7 +136,7 @@ static inline zend_ast *zend_ast_create_dynamic_and_add(zend_ast_kind kind, zend
|
|||
}
|
||||
|
||||
static inline zend_ast *zend_ast_create_var(zval *name) {
|
||||
return zend_ast_create_unary(ZEND_AST_VAR, zend_ast_create_constant(name));
|
||||
return zend_ast_create_unary(ZEND_AST_VAR, zend_ast_create_zval(name));
|
||||
}
|
||||
static inline zend_ast *zend_ast_create_binary_op(zend_uint opcode, zend_ast *op0, zend_ast *op1) {
|
||||
return zend_ast_create_binary_ex(ZEND_AST_BINARY_OP, opcode, op0, op1);
|
||||
|
@ -167,7 +164,7 @@ static inline zend_ast *zend_ast_create_assign_op(zend_uint opcode, zend_ast *op
|
|||
} while (0)
|
||||
|
||||
#define AST_ZNODE(znode) zend_ast_create_znode((znode))
|
||||
#define AST_ZVAL(znode) zend_ast_create_constant(&(znode)->u.constant)
|
||||
#define AST_ZVAL(znode) zend_ast_create_zval(&(znode)->u.constant)
|
||||
|
||||
#define AC(znode) AST_COMPILE(&znode, znode.u.ast)
|
||||
#define AZ(znode) ((znode).u.ast = AST_ZNODE(&znode))
|
||||
|
|
|
@ -5880,7 +5880,7 @@ void zend_do_constant_expression(znode *result, zend_ast *ast TSRMLS_DC) /* {{{
|
|||
{
|
||||
zend_eval_const_expr(&ast TSRMLS_CC);
|
||||
zend_compile_const_expr(&ast TSRMLS_CC);
|
||||
if (ast->kind == ZEND_CONST) {
|
||||
if (ast->kind == ZEND_AST_ZVAL) {
|
||||
ZVAL_COPY_VALUE(&result->u.constant, zend_ast_get_zval(ast));
|
||||
if (Z_TYPE(result->u.constant) == IS_ARRAY) {
|
||||
zend_make_immutable_array_r(&result->u.constant TSRMLS_CC);
|
||||
|
@ -6087,7 +6087,7 @@ static zend_bool zend_can_write_to_variable(zend_ast *ast) {
|
|||
static zend_bool zend_is_const_default_class_ref(zend_ast *name_ast) {
|
||||
zval *name;
|
||||
int fetch_type;
|
||||
if (name_ast->kind != ZEND_CONST) {
|
||||
if (name_ast->kind != ZEND_AST_ZVAL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -6159,7 +6159,7 @@ static zend_op *zend_compile_class_ref(znode *result, zend_ast *name_ast TSRMLS_
|
|||
|
||||
static int zend_try_compile_cv(znode *result, zend_ast *ast TSRMLS_DC) {
|
||||
zend_ast *name_ast = ast->child[0];
|
||||
if (name_ast->kind == ZEND_CONST) {
|
||||
if (name_ast->kind == ZEND_AST_ZVAL) {
|
||||
zend_string *name = zval_get_string(zend_ast_get_zval(name_ast));
|
||||
|
||||
if (zend_is_auto_global(name TSRMLS_CC)) {
|
||||
|
@ -6186,7 +6186,7 @@ static zend_op *zend_compile_simple_var_no_cv(znode *result, zend_ast *ast, int
|
|||
zend_op *opline;
|
||||
|
||||
/* there is a chance someone is accessing $this */
|
||||
if (ast->kind != ZEND_CONST
|
||||
if (ast->kind != ZEND_AST_ZVAL
|
||||
&& CG(active_op_array)->scope && CG(active_op_array)->this_var == -1
|
||||
) {
|
||||
zend_string *key = STR_INIT("this", sizeof("this") - 1, 0);
|
||||
|
@ -6257,7 +6257,7 @@ void zend_compile_dim(znode *result, zend_ast *ast, int type TSRMLS_DC) {
|
|||
}
|
||||
|
||||
static zend_bool is_this_fetch(zend_ast *ast) {
|
||||
if (ast->kind != ZEND_AST_VAR || ast->child[0]->kind != ZEND_CONST) {
|
||||
if (ast->kind != ZEND_AST_VAR || ast->child[0]->kind != ZEND_AST_ZVAL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -6392,7 +6392,7 @@ void zend_ensure_writable_variable(const zend_ast *ast) {
|
|||
|
||||
/* Detects $a... = $a pattern */
|
||||
zend_bool zend_is_assign_to_self(zend_ast *var_ast, zend_ast *expr_ast TSRMLS_DC) {
|
||||
if (expr_ast->kind != ZEND_AST_VAR || expr_ast->child[0]->kind != ZEND_CONST) {
|
||||
if (expr_ast->kind != ZEND_AST_VAR || expr_ast->child[0]->kind != ZEND_AST_ZVAL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -6400,7 +6400,7 @@ zend_bool zend_is_assign_to_self(zend_ast *var_ast, zend_ast *expr_ast TSRMLS_DC
|
|||
var_ast = var_ast->child[0];
|
||||
}
|
||||
|
||||
if (var_ast->kind != ZEND_AST_VAR || var_ast->child[0]->kind != ZEND_CONST) {
|
||||
if (var_ast->kind != ZEND_AST_VAR || var_ast->child[0]->kind != ZEND_AST_ZVAL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -6731,7 +6731,7 @@ void zend_compile_call(znode *result, zend_ast *ast, int type TSRMLS_DC) {
|
|||
|
||||
znode name_node;
|
||||
|
||||
if (name_ast->kind != ZEND_CONST) {
|
||||
if (name_ast->kind != ZEND_AST_ZVAL) {
|
||||
zend_compile_expr(&name_node, name_ast TSRMLS_CC);
|
||||
zend_compile_dynamic_call(result, &name_node, params_ast TSRMLS_CC);
|
||||
return;
|
||||
|
@ -7521,7 +7521,7 @@ void zend_compile_encaps_list(znode *result, zend_ast *ast TSRMLS_DC) {
|
|||
|
||||
zend_compile_expr(&elem_node, elem_ast TSRMLS_CC);
|
||||
|
||||
if (elem_ast->kind == ZEND_CONST) {
|
||||
if (elem_ast->kind == ZEND_AST_ZVAL) {
|
||||
zval *zv = &elem_node.u.constant;
|
||||
ZEND_ASSERT(Z_TYPE_P(zv) == IS_STRING);
|
||||
|
||||
|
@ -7557,7 +7557,7 @@ void zend_compile_encaps_list(znode *result, zend_ast *ast TSRMLS_DC) {
|
|||
}
|
||||
|
||||
zend_bool zend_is_allowed_in_const_expr(zend_ast_kind kind) {
|
||||
return kind == ZEND_CONST || kind == ZEND_AST_BINARY_OP
|
||||
return kind == ZEND_AST_ZVAL || kind == ZEND_AST_BINARY_OP
|
||||
|| kind == ZEND_AST_GREATER || kind == ZEND_AST_GREATER_EQUAL
|
||||
|| kind == ZEND_AST_AND || kind == ZEND_AST_OR
|
||||
|| kind == ZEND_BW_NOT || kind == ZEND_BOOL_NOT
|
||||
|
@ -7576,7 +7576,7 @@ void zend_compile_const_expr_class_const(zend_ast **ast_ptr TSRMLS_DC) {
|
|||
zval result;
|
||||
int fetch_type;
|
||||
|
||||
if (class_ast->kind != ZEND_CONST) {
|
||||
if (class_ast->kind != ZEND_AST_ZVAL) {
|
||||
zend_error_noreturn(E_COMPILE_ERROR,
|
||||
"Dynamic class names are not allowed in compile-time class constant references");
|
||||
}
|
||||
|
@ -7603,7 +7603,7 @@ void zend_compile_const_expr_class_const(zend_ast **ast_ptr TSRMLS_DC) {
|
|||
Z_CONST_FLAGS(result) = fetch_type;
|
||||
|
||||
zend_ast_destroy(ast);
|
||||
*ast_ptr = zend_ast_create_constant(&result);
|
||||
*ast_ptr = zend_ast_create_zval(&result);
|
||||
}
|
||||
|
||||
void zend_compile_const_expr_const(zend_ast **ast_ptr TSRMLS_DC) {
|
||||
|
@ -7619,7 +7619,7 @@ void zend_compile_const_expr_const(zend_ast **ast_ptr TSRMLS_DC) {
|
|||
|
||||
if (zend_constant_ct_subst(&result, &const_name.u.constant, 0 TSRMLS_CC)) {
|
||||
zend_ast_destroy(ast);
|
||||
*ast_ptr = zend_ast_create_constant(&result.u.constant);
|
||||
*ast_ptr = zend_ast_create_zval(&result.u.constant);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -7635,7 +7635,7 @@ void zend_compile_const_expr_const(zend_ast **ast_ptr TSRMLS_DC) {
|
|||
}
|
||||
|
||||
zend_ast_destroy(ast);
|
||||
*ast_ptr = zend_ast_create_constant(&result.u.constant);
|
||||
*ast_ptr = zend_ast_create_zval(&result.u.constant);
|
||||
}
|
||||
|
||||
void zend_compile_const_expr_resolve_class_name(zend_ast **ast_ptr TSRMLS_DC) {
|
||||
|
@ -7668,12 +7668,12 @@ void zend_compile_const_expr_resolve_class_name(zend_ast **ast_ptr TSRMLS_DC) {
|
|||
}
|
||||
|
||||
zend_ast_destroy(ast);
|
||||
*ast_ptr = zend_ast_create_constant(&result.u.constant);
|
||||
*ast_ptr = zend_ast_create_zval(&result.u.constant);
|
||||
}
|
||||
|
||||
void zend_compile_const_expr(zend_ast **ast_ptr TSRMLS_DC) {
|
||||
zend_ast *ast = *ast_ptr;
|
||||
if (ast == NULL || ast->kind == ZEND_CONST) {
|
||||
if (ast == NULL || ast->kind == ZEND_AST_ZVAL) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -7715,7 +7715,7 @@ void zend_compile_stmt(zend_ast *ast TSRMLS_DC) {
|
|||
|
||||
void zend_compile_expr(znode *result, zend_ast *ast TSRMLS_DC) {
|
||||
switch (ast->kind) {
|
||||
case ZEND_CONST:
|
||||
case ZEND_AST_ZVAL:
|
||||
ZVAL_COPY(&result->u.constant, zend_ast_get_zval(ast));
|
||||
result->op_type = IS_CONST;
|
||||
return;
|
||||
|
@ -7869,12 +7869,12 @@ void zend_eval_const_binary_op(zend_ast **ast_ptr TSRMLS_DC) {
|
|||
zend_ast *right_ast = ast->child[1];
|
||||
zend_uchar opcode = ast->attr;
|
||||
|
||||
if (left_ast->kind == ZEND_CONST && right_ast->kind == ZEND_CONST) {
|
||||
if (left_ast->kind == ZEND_AST_ZVAL && right_ast->kind == ZEND_AST_ZVAL) {
|
||||
binary_op_type op = get_binary_op(opcode);
|
||||
zval result;
|
||||
op(&result, zend_ast_get_zval(left_ast), zend_ast_get_zval(right_ast) TSRMLS_CC);
|
||||
zend_ast_destroy(ast);
|
||||
*ast_ptr = zend_ast_create_constant(&result);
|
||||
*ast_ptr = zend_ast_create_zval(&result);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7884,7 +7884,7 @@ void zend_eval_const_unary_pm(zend_ast **ast_ptr TSRMLS_DC) {
|
|||
|
||||
ZEND_ASSERT(ast->kind == ZEND_AST_UNARY_PLUS || ast->kind == ZEND_AST_UNARY_MINUS);
|
||||
|
||||
if (expr_ast->kind == ZEND_CONST) {
|
||||
if (expr_ast->kind == ZEND_AST_ZVAL) {
|
||||
binary_op_type op = ast->kind == ZEND_AST_UNARY_PLUS
|
||||
? add_function : sub_function;
|
||||
|
||||
|
@ -7892,7 +7892,7 @@ void zend_eval_const_unary_pm(zend_ast **ast_ptr TSRMLS_DC) {
|
|||
ZVAL_LONG(&left, 0);
|
||||
op(&result, &left, zend_ast_get_zval(expr_ast) TSRMLS_CC);
|
||||
zend_ast_destroy(ast);
|
||||
*ast_ptr = zend_ast_create_constant(&result);
|
||||
*ast_ptr = zend_ast_create_zval(&result);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7903,14 +7903,14 @@ void zend_eval_const_greater(zend_ast **ast_ptr TSRMLS_DC) {
|
|||
|
||||
ZEND_ASSERT(ast->kind == ZEND_AST_GREATER || ast->kind == ZEND_AST_GREATER_EQUAL);
|
||||
|
||||
if (left_ast->kind == ZEND_CONST && right_ast->kind == ZEND_CONST) {
|
||||
if (left_ast->kind == ZEND_AST_ZVAL && right_ast->kind == ZEND_AST_ZVAL) {
|
||||
binary_op_type op = ast->kind == ZEND_AST_GREATER
|
||||
? is_smaller_function : is_smaller_or_equal_function;
|
||||
|
||||
zval result;
|
||||
op(&result, zend_ast_get_zval(right_ast), zend_ast_get_zval(left_ast) TSRMLS_CC);
|
||||
zend_ast_destroy(ast);
|
||||
*ast_ptr = zend_ast_create_constant(&result);
|
||||
*ast_ptr = zend_ast_create_zval(&result);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7926,7 +7926,7 @@ void zend_eval_const_array(zend_ast **ast_ptr TSRMLS_DC) {
|
|||
zend_ast *key_ast = elem_ast->child[1];
|
||||
zend_bool by_ref = elem_ast->attr;
|
||||
|
||||
if (by_ref || (key_ast && key_ast->kind != ZEND_CONST) || value_ast->kind != ZEND_CONST) {
|
||||
if (by_ref || (key_ast && key_ast->kind != ZEND_AST_ZVAL) || value_ast->kind != ZEND_AST_ZVAL) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -7973,12 +7973,12 @@ void zend_eval_const_array(zend_ast **ast_ptr TSRMLS_DC) {
|
|||
|
||||
zend_ast_destroy(ast);
|
||||
zend_make_immutable_array(&array TSRMLS_CC);
|
||||
*ast_ptr = zend_ast_create_constant(&array);
|
||||
*ast_ptr = zend_ast_create_zval(&array);
|
||||
}
|
||||
|
||||
void zend_eval_const_expr(zend_ast **ast_ptr TSRMLS_DC) {
|
||||
zend_ast *ast = *ast_ptr;
|
||||
if (!ast || ast->kind == ZEND_CONST || ast->kind == ZEND_AST_ZNODE) {
|
||||
if (!ast || ast->kind == ZEND_AST_ZVAL || ast->kind == ZEND_AST_ZNODE) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -938,7 +938,7 @@ exit_expr:
|
|||
backticks_expr:
|
||||
/* empty */
|
||||
{ zval empty_str; ZVAL_EMPTY_STRING(&empty_str);
|
||||
$$.u.ast = zend_ast_create_constant(&empty_str); }
|
||||
$$.u.ast = zend_ast_create_zval(&empty_str); }
|
||||
| T_ENCAPSED_AND_WHITESPACE { $$.u.ast = AST_ZVAL(&$1); }
|
||||
| encaps_list { $$.u.ast = $1.u.ast; }
|
||||
;
|
||||
|
@ -974,14 +974,14 @@ scalar:
|
|||
{ if (Z_TYPE($1.u.constant) == IS_UNDEF) {
|
||||
zval class_const; ZVAL_STRING(&class_const, "__CLASS__");
|
||||
$$.u.ast = zend_ast_create_unary(ZEND_AST_CONST,
|
||||
zend_ast_create_constant(&class_const));
|
||||
zend_ast_create_zval(&class_const));
|
||||
} else {
|
||||
$$.u.ast = AST_ZVAL(&$1);
|
||||
} }
|
||||
| T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC { $$.u.ast = AST_ZVAL(&$2); }
|
||||
| T_START_HEREDOC T_END_HEREDOC
|
||||
{ zval empty_str; ZVAL_EMPTY_STRING(&empty_str);
|
||||
$$.u.ast = zend_ast_create_constant(&empty_str); }
|
||||
$$.u.ast = zend_ast_create_zval(&empty_str); }
|
||||
| '"' encaps_list '"' { $$.u.ast = $2.u.ast; }
|
||||
| T_START_HEREDOC encaps_list T_END_HEREDOC { $$.u.ast = $2.u.ast; }
|
||||
| dereferencable_scalar { $$.u.ast = $1.u.ast; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue