Skip to content

Commit 7465d26

Browse files
committed
remove inner class AST
1 parent 80b1d73 commit 7465d26

File tree

2 files changed

+0
-138
lines changed

2 files changed

+0
-138
lines changed

Zend/zend_compile.c

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2921,42 +2921,10 @@ static inline void zend_set_class_name_op1(zend_op *opline, znode *class_node) /
29212921
}
29222922
/* }}} */
29232923

2924-
static void zend_compile_class_ref(znode *result, zend_ast *name_ast, uint32_t fetch_flags);
2925-
2926-
static void zend_compile_inner_class_ref(znode *result, zend_ast *ast, uint32_t fetch_flags) /* {{{ */
2927-
{
2928-
zend_ast *outer_class = ast->child[0];
2929-
zend_ast *inner_class = ast->child[1];
2930-
2931-
znode outer_node, inner_node;
2932-
2933-
// handle nesting
2934-
if (outer_class->kind == ZEND_AST_INNER_CLASS) {
2935-
zend_compile_inner_class_ref(&outer_node, outer_class, fetch_flags);
2936-
} else {
2937-
zend_compile_class_ref(&outer_node, outer_class, fetch_flags | ZEND_FETCH_CLASS_OUTER);
2938-
}
2939-
2940-
if (inner_class->kind == ZEND_AST_ZVAL && Z_TYPE_P(zend_ast_get_zval(inner_class)) == IS_STRING) {
2941-
ZVAL_STR(&inner_node.u.constant, zend_string_dup(Z_STR_P(zend_ast_get_zval(inner_class)), 0));
2942-
inner_node.op_type = IS_CONST;
2943-
} else {
2944-
zend_compile_expr(&inner_node, inner_class);
2945-
}
2946-
2947-
zend_emit_op(result, ZEND_FETCH_INNER_CLASS, &outer_node, &inner_node);
2948-
}
2949-
/* }}} */
2950-
29512924
static void zend_compile_class_ref(znode *result, zend_ast *name_ast, uint32_t fetch_flags) /* {{{ */
29522925
{
29532926
uint32_t fetch_type;
29542927

2955-
if (name_ast->kind == ZEND_AST_INNER_CLASS) {
2956-
zend_compile_inner_class_ref(result, name_ast, fetch_flags);
2957-
return;
2958-
}
2959-
29602928
if (name_ast->kind != ZEND_AST_ZVAL) {
29612929
znode name_node;
29622930

@@ -11889,9 +11857,6 @@ static void zend_compile_expr_inner(znode *result, zend_ast *ast) /* {{{ */
1188911857
case ZEND_AST_MATCH:
1189011858
zend_compile_match(result, ast);
1189111859
return;
11892-
case ZEND_AST_INNER_CLASS:
11893-
zend_compile_inner_class_ref(result, ast, ZEND_FETCH_CLASS_EXCEPTION);
11894-
return;
1189511860
default:
1189611861
ZEND_ASSERT(0 /* not supported */);
1189711862
}

Zend/zend_vm_def.h

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,108 +1798,6 @@ ZEND_VM_C_LABEL(fetch_this):
17981798
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
17991799
}
18001800

1801-
ZEND_VM_HANDLER(210, ZEND_FETCH_INNER_CLASS, CONST|TMPVAR|UNUSED, CONST, CACHE_SLOT)
1802-
{
1803-
USE_OPLINE
1804-
SAVE_OPLINE();
1805-
1806-
zend_string *inner_class_name, *full_class_name;
1807-
zend_class_entry *outer_ce = NULL, *inner_ce = NULL, *scope = NULL;
1808-
1809-
scope = EX(func)->op_array.scope;
1810-
1811-
if (OP1_TYPE == IS_CONST) {
1812-
zval *outer_class_zv = RT_CONSTANT(opline, opline->op1);
1813-
outer_ce = zend_lookup_class(Z_STR_P(outer_class_zv));
1814-
if (!outer_ce) {
1815-
zend_error(E_ERROR, "Outer class '%s' not found for inner class %s:>%s", Z_STRVAL_P(outer_class_zv), Z_STRVAL_P(outer_class_zv), Z_STRVAL_P(RT_CONSTANT(opline, opline->op2)));
1816-
HANDLE_EXCEPTION();
1817-
}
1818-
} else if (OP1_TYPE == IS_UNUSED) {
1819-
uint32_t fetch_type;
1820-
zend_class_entry *called_scope;
1821-
1822-
fetch_type = opline->op1.num & ZEND_FETCH_CLASS_MASK;
1823-
if (UNEXPECTED(scope == NULL)) {
1824-
SAVE_OPLINE();
1825-
zend_throw_error(NULL, "Cannot use \"%s\" in the global scope",
1826-
fetch_type == ZEND_FETCH_CLASS_SELF ? "self" :
1827-
fetch_type == ZEND_FETCH_CLASS_PARENT ? "parent" : "static");
1828-
ZVAL_UNDEF(EX_VAR(opline->result.var));
1829-
HANDLE_EXCEPTION();
1830-
}
1831-
if (fetch_type == ZEND_FETCH_CLASS_SELF) {
1832-
outer_ce = scope;
1833-
} else if (fetch_type == ZEND_FETCH_CLASS_PARENT) {
1834-
if (UNEXPECTED(scope->parent == NULL)) {
1835-
SAVE_OPLINE();
1836-
zend_throw_error(NULL,
1837-
"Cannot use \"parent\" when current class scope has no parent");
1838-
ZVAL_UNDEF(EX_VAR(opline->result.var));
1839-
HANDLE_EXCEPTION();
1840-
}
1841-
outer_ce = scope->parent;
1842-
} else if (fetch_type == ZEND_FETCH_CLASS_STATIC) {
1843-
if (Z_TYPE(EX(This)) == IS_OBJECT) {
1844-
called_scope = Z_OBJCE(EX(This));
1845-
} else {
1846-
called_scope = Z_CE(EX(This));
1847-
}
1848-
outer_ce = called_scope;
1849-
} else {
1850-
zend_throw_error(NULL, "Unknown scope resolution");
1851-
HANDLE_EXCEPTION();
1852-
}
1853-
} else {
1854-
outer_ce = Z_CE_P(EX_VAR(opline->op1.var));
1855-
}
1856-
1857-
inner_class_name = Z_STR_P(RT_CONSTANT(opline, opline->op2));
1858-
1859-
if (UNEXPECTED(ZSTR_LEN(outer_ce->name) + ZSTR_LEN(inner_class_name) + 2 > ZSTR_MAX_LEN)) {
1860-
zend_error(E_ERROR, "Class name is too long");
1861-
HANDLE_EXCEPTION();
1862-
}
1863-
1864-
full_class_name = zend_string_concat3(
1865-
ZSTR_VAL(outer_ce->name), ZSTR_LEN(outer_ce->name),
1866-
":>", 2,
1867-
ZSTR_VAL(inner_class_name), ZSTR_LEN(inner_class_name)
1868-
);
1869-
1870-
inner_ce = zend_lookup_class(full_class_name);
1871-
if (!inner_ce) {
1872-
zend_error(E_ERROR, "Inner class '%s' not found in outer class %s", ZSTR_VAL(full_class_name), ZSTR_VAL(outer_ce->name));
1873-
HANDLE_EXCEPTION();
1874-
}
1875-
1876-
if (inner_ce->required_scope) {
1877-
if (inner_ce->required_scope_absolute) {
1878-
// for private classes, we check if the scope we are currently in has access
1879-
if (scope != NULL && (inner_ce->required_scope == scope || scope->lexical_scope == inner_ce->required_scope)) {
1880-
// we are in the correct scope
1881-
} else {
1882-
zend_error(E_ERROR, "Cannot access private inner class '%s'", ZSTR_VAL(full_class_name));
1883-
HANDLE_EXCEPTION();
1884-
}
1885-
} else {
1886-
// for protected classes, we check if the scope is an instance of the required scope
1887-
if (scope != NULL && (instanceof_function(scope, inner_ce->required_scope) || instanceof_function(scope->lexical_scope, inner_ce->required_scope))) {
1888-
// we are in the correct scope
1889-
} else {
1890-
zend_error(E_ERROR, "Cannot access protected inner class '%s'", ZSTR_VAL(full_class_name));
1891-
HANDLE_EXCEPTION();
1892-
}
1893-
}
1894-
}
1895-
1896-
Z_CE_P(EX_VAR(opline->result.var)) = inner_ce;
1897-
1898-
zend_string_release(full_class_name);
1899-
1900-
ZEND_VM_NEXT_OPCODE();
1901-
}
1902-
19031801
ZEND_VM_HANDLER(80, ZEND_FETCH_R, CONST|TMPVAR|CV, UNUSED, VAR_FETCH)
19041802
{
19051803
ZEND_VM_DISPATCH_TO_HELPER(zend_fetch_var_address_helper, type, BP_VAR_R);
@@ -8293,7 +8191,6 @@ ZEND_VM_HANDLER(149, ZEND_HANDLE_EXCEPTION, ANY, ANY)
82938191

82948192
case ZEND_FETCH_CLASS:
82958193
case ZEND_DECLARE_ANON_CLASS:
8296-
case ZEND_FETCH_INNER_CLASS:
82978194
break; /* return value is zend_class_entry pointer */
82988195

82998196
default:

0 commit comments

Comments
 (0)