Port __FUNCTION__ to AST

This commit is contained in:
Nikita Popov 2014-07-16 23:10:16 +02:00
parent f589713cc4
commit a75921dcb1
5 changed files with 176 additions and 167 deletions

View File

@ -68,6 +68,7 @@ enum _zend_ast_kind {
ZEND_AST_ARRAY,
ZEND_AST_ARRAY_ELEM,
ZEND_AST_ENCAPS_LIST,
ZEND_AST_MAGIC_CONST,
ZEND_AST_EXPR_LIST,
ZEND_AST_STMT_LIST,

View File

@ -7678,6 +7678,23 @@ void zend_compile_encaps_list(znode *result, zend_ast *ast TSRMLS_DC) {
}
}
void zend_compile_magic_const(znode *result, zend_ast *ast TSRMLS_DC) {
zend_op_array *op_array = CG(active_op_array);
zval *zv = &result->u.constant;
result->op_type = IS_CONST;
switch (ast->attr) {
case T_FUNC_C:
if (op_array && op_array->function_name) {
ZVAL_STR(zv, STR_COPY(op_array->function_name));
} else {
ZVAL_EMPTY_STRING(zv);
}
break;
EMPTY_SWITCH_DEFAULT_CASE()
}
}
zend_bool zend_is_allowed_in_const_expr(zend_ast_kind kind) {
return kind == ZEND_AST_ZVAL || kind == ZEND_AST_BINARY_OP
|| kind == ZEND_AST_GREATER || kind == ZEND_AST_GREATER_EQUAL
@ -7687,7 +7704,7 @@ zend_bool zend_is_allowed_in_const_expr(zend_ast_kind kind) {
|| kind == ZEND_AST_CONDITIONAL
|| kind == ZEND_AST_ARRAY || kind == ZEND_AST_ARRAY_ELEM
|| kind == ZEND_AST_CONST || kind == ZEND_AST_CLASS_CONST
|| kind == ZEND_AST_RESOLVE_CLASS_NAME;
|| kind == ZEND_AST_RESOLVE_CLASS_NAME || kind == ZEND_AST_MAGIC_CONST;
}
void zend_compile_const_expr_class_const(zend_ast **ast_ptr TSRMLS_DC) {
@ -8004,6 +8021,9 @@ void zend_compile_expr(znode *result, zend_ast *ast TSRMLS_DC) {
case ZEND_AST_ENCAPS_LIST:
zend_compile_encaps_list(result, ast TSRMLS_CC);
return;
case ZEND_AST_MAGIC_CONST:
zend_compile_magic_const(result, ast TSRMLS_CC);
return;
default:
ZEND_ASSERT(0 /* not supported */);
}

View File

@ -958,15 +958,15 @@ static_scalar: /* compile-time evaluated scalars */
;
scalar:
T_LNUMBER { $$.u.ast = AST_ZVAL(&$1); }
| T_DNUMBER { $$.u.ast = AST_ZVAL(&$1); }
| T_LINE { $$.u.ast = AST_ZVAL(&$1); }
| T_FILE { $$.u.ast = AST_ZVAL(&$1); }
| T_DIR { $$.u.ast = AST_ZVAL(&$1); }
| T_TRAIT_C { $$.u.ast = AST_ZVAL(&$1); }
| T_METHOD_C { $$.u.ast = AST_ZVAL(&$1); }
| T_FUNC_C { $$.u.ast = AST_ZVAL(&$1); }
| T_NS_C { $$.u.ast = AST_ZVAL(&$1); }
T_LNUMBER { $$.u.ast = AST_ZVAL(&$1); }
| T_DNUMBER { $$.u.ast = AST_ZVAL(&$1); }
| T_LINE { $$.u.ast = AST_ZVAL(&$1); }
| T_FILE { $$.u.ast = AST_ZVAL(&$1); }
| T_DIR { $$.u.ast = AST_ZVAL(&$1); }
| T_TRAIT_C { $$.u.ast = AST_ZVAL(&$1); }
| T_METHOD_C { $$.u.ast = AST_ZVAL(&$1); }
| T_FUNC_C { $$.u.ast = zend_ast_create_ex(0, ZEND_AST_MAGIC_CONST, T_FUNC_C); }
| T_NS_C { $$.u.ast = AST_ZVAL(&$1); }
| T_CLASS_C
{ if (Z_TYPE($1.u.constant) == IS_UNDEF) {
zval class_const; ZVAL_STRING(&class_const, "__CLASS__");

File diff suppressed because it is too large Load Diff

View File

@ -1620,12 +1620,6 @@ NEWLINE ("\r"|"\n"|"\r\n")
}
<ST_IN_SCRIPTING>"__FUNCTION__" {
zend_op_array *op_array = CG(active_op_array);
if (op_array && op_array->function_name) {
ZVAL_STR(zendlval, STR_COPY(op_array->function_name));
} else {
ZVAL_EMPTY_STRING(zendlval);
}
return T_FUNC_C;
}