Skip to content

Commit 8165e72

Browse files
committed
Introduce zend_ast_call_get_args()
1 parent 5472cac commit 8165e72

2 files changed

Lines changed: 27 additions & 22 deletions

File tree

Zend/zend_ast.c

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,19 +1139,22 @@ static zend_result ZEND_FASTCALL zend_ast_evaluate_inner(
11391139
{
11401140
zend_function *fptr;
11411141
zend_class_entry *called_scope = NULL;
1142+
1143+
zend_ast *args_ast = zend_ast_call_get_args(ast);
1144+
ZEND_ASSERT(args_ast && args_ast->kind == ZEND_AST_CALLABLE_CONVERT);
1145+
1146+
zend_ast_fcc *fcc_ast = (zend_ast_fcc*)args_ast;
1147+
1148+
zend_ast_list *args = zend_ast_get_list(fcc_ast->args);
1149+
ZEND_ASSERT(args->children > 0);
1150+
if (args->children != 1 || args->child[0]->attr != ZEND_PLACEHOLDER_VARIADIC) {
1151+
/* TODO: PFAs */
1152+
zend_error_noreturn(E_COMPILE_ERROR, "Constant expression contains invalid operations");
1153+
return FAILURE;
1154+
}
1155+
11421156
switch (ast->kind) {
11431157
case ZEND_AST_CALL: {
1144-
ZEND_ASSERT(ast->child[1]->kind == ZEND_AST_CALLABLE_CONVERT);
1145-
zend_ast_fcc *fcc_ast = (zend_ast_fcc*)ast->child[1];
1146-
1147-
zend_ast_list *args = zend_ast_get_list(fcc_ast->args);
1148-
ZEND_ASSERT(args->children > 0);
1149-
if (args->children != 1 || args->child[0]->attr != ZEND_PLACEHOLDER_VARIADIC) {
1150-
/* TODO: PFAs */
1151-
zend_error_noreturn(E_COMPILE_ERROR, "Constant expression contains invalid operations");
1152-
return FAILURE;
1153-
}
1154-
11551158
fptr = ZEND_MAP_PTR_GET(fcc_ast->fptr);
11561159

11571160
if (!fptr) {
@@ -1176,17 +1179,6 @@ static zend_result ZEND_FASTCALL zend_ast_evaluate_inner(
11761179
break;
11771180
}
11781181
case ZEND_AST_STATIC_CALL: {
1179-
ZEND_ASSERT(ast->child[2]->kind == ZEND_AST_CALLABLE_CONVERT);
1180-
zend_ast_fcc *fcc_ast = (zend_ast_fcc*)ast->child[2];
1181-
1182-
zend_ast_list *args = zend_ast_get_list(fcc_ast->args);
1183-
ZEND_ASSERT(args->children > 0);
1184-
if (args->children != 1 || args->child[0]->attr != ZEND_PLACEHOLDER_VARIADIC) {
1185-
/* TODO: PFAs */
1186-
zend_error_noreturn(E_COMPILE_ERROR, "Constant expression contains invalid operations");
1187-
return FAILURE;
1188-
}
1189-
11901182
zend_class_entry *ce = zend_ast_fetch_class(ast->child[0], scope);
11911183
if (!ce) {
11921184
return FAILURE;
@@ -3083,3 +3075,14 @@ zend_ast * ZEND_FASTCALL zend_ast_with_attributes(zend_ast *ast, zend_ast *attr)
30833075

30843076
return ast;
30853077
}
3078+
3079+
zend_ast * ZEND_FASTCALL zend_ast_call_get_args(zend_ast *ast)
3080+
{
3081+
if (ast->kind == ZEND_AST_CALL) {
3082+
return ast->child[1];
3083+
} else if (ast->kind == ZEND_AST_STATIC_CALL || ast->kind == ZEND_AST_METHOD_CALL) {
3084+
return ast->child[2];
3085+
}
3086+
3087+
return NULL;
3088+
}

Zend/zend_ast.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,4 +440,6 @@ static zend_always_inline zend_ast *zend_ast_list_rtrim(zend_ast *ast) {
440440

441441
zend_ast * ZEND_FASTCALL zend_ast_with_attributes(zend_ast *ast, zend_ast *attr);
442442

443+
zend_ast * ZEND_FASTCALL zend_ast_call_get_args(zend_ast *ast);
444+
443445
#endif

0 commit comments

Comments
 (0)