Skip to content

Commit 3d0f581

Browse files
committed
zend_compile: Add zend_compile_rope_finalize()
This just extracts the implementation as-is into a dedicated function to make it reusable in preparation of a future commit.
1 parent d545b1d commit 3d0f581

File tree

1 file changed

+52
-47
lines changed

1 file changed

+52
-47
lines changed

Zend/zend_compile.c

Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -10188,6 +10188,57 @@ static zend_op *zend_compile_rope_add(znode *result, uint32_t num, znode *elem_n
1018810188
}
1018910189
/* }}} */
1019010190

10191+
static void zend_compile_rope_finalize(znode *result, uint32_t j, zend_op *init_opline, zend_op *opline)
10192+
{
10193+
if (j == 1) {
10194+
if (opline->op2_type == IS_CONST) {
10195+
GET_NODE(result, opline->op2);
10196+
MAKE_NOP(opline);
10197+
} else {
10198+
opline->opcode = ZEND_CAST;
10199+
opline->extended_value = IS_STRING;
10200+
opline->op1_type = opline->op2_type;
10201+
opline->op1 = opline->op2;
10202+
SET_UNUSED(opline->op2);
10203+
zend_make_tmp_result(result, opline);
10204+
}
10205+
} else if (j == 2) {
10206+
opline->opcode = ZEND_FAST_CONCAT;
10207+
opline->extended_value = 0;
10208+
opline->op1_type = init_opline->op2_type;
10209+
opline->op1 = init_opline->op2;
10210+
zend_make_tmp_result(result, opline);
10211+
MAKE_NOP(init_opline);
10212+
} else {
10213+
uint32_t var;
10214+
10215+
init_opline->extended_value = j;
10216+
opline->opcode = ZEND_ROPE_END;
10217+
zend_make_tmp_result(result, opline);
10218+
var = opline->op1.var = get_temporary_variable();
10219+
10220+
/* Allocates the necessary number of zval slots to keep the rope */
10221+
uint32_t i = ((j * sizeof(zend_string*)) + (sizeof(zval) - 1)) / sizeof(zval);
10222+
while (i > 1) {
10223+
get_temporary_variable();
10224+
i--;
10225+
}
10226+
10227+
/* Update all the previous opcodes to use the same variable */
10228+
while (opline != init_opline) {
10229+
opline--;
10230+
if (opline->opcode == ZEND_ROPE_ADD &&
10231+
opline->result.var == (uint32_t)-1) {
10232+
opline->op1.var = var;
10233+
opline->result.var = var;
10234+
} else if (opline->opcode == ZEND_ROPE_INIT &&
10235+
opline->result.var == (uint32_t)-1) {
10236+
opline->result.var = var;
10237+
}
10238+
}
10239+
}
10240+
}
10241+
1019110242
static void zend_compile_encaps_list(znode *result, zend_ast *ast) /* {{{ */
1019210243
{
1019310244
uint32_t i, j;
@@ -10263,53 +10314,7 @@ static void zend_compile_encaps_list(znode *result, zend_ast *ast) /* {{{ */
1026310314
opline = zend_compile_rope_add_ex(opline, result, j++, &last_const_node);
1026410315
}
1026510316
init_opline = CG(active_op_array)->opcodes + rope_init_lineno;
10266-
if (j == 1) {
10267-
if (opline->op2_type == IS_CONST) {
10268-
GET_NODE(result, opline->op2);
10269-
MAKE_NOP(opline);
10270-
} else {
10271-
opline->opcode = ZEND_CAST;
10272-
opline->extended_value = IS_STRING;
10273-
opline->op1_type = opline->op2_type;
10274-
opline->op1 = opline->op2;
10275-
SET_UNUSED(opline->op2);
10276-
zend_make_tmp_result(result, opline);
10277-
}
10278-
} else if (j == 2) {
10279-
opline->opcode = ZEND_FAST_CONCAT;
10280-
opline->extended_value = 0;
10281-
opline->op1_type = init_opline->op2_type;
10282-
opline->op1 = init_opline->op2;
10283-
zend_make_tmp_result(result, opline);
10284-
MAKE_NOP(init_opline);
10285-
} else {
10286-
uint32_t var;
10287-
10288-
init_opline->extended_value = j;
10289-
opline->opcode = ZEND_ROPE_END;
10290-
zend_make_tmp_result(result, opline);
10291-
var = opline->op1.var = get_temporary_variable();
10292-
10293-
/* Allocates the necessary number of zval slots to keep the rope */
10294-
i = ((j * sizeof(zend_string*)) + (sizeof(zval) - 1)) / sizeof(zval);
10295-
while (i > 1) {
10296-
get_temporary_variable();
10297-
i--;
10298-
}
10299-
10300-
/* Update all the previous opcodes to use the same variable */
10301-
while (opline != init_opline) {
10302-
opline--;
10303-
if (opline->opcode == ZEND_ROPE_ADD &&
10304-
opline->result.var == (uint32_t)-1) {
10305-
opline->op1.var = var;
10306-
opline->result.var = var;
10307-
} else if (opline->opcode == ZEND_ROPE_INIT &&
10308-
opline->result.var == (uint32_t)-1) {
10309-
opline->result.var = var;
10310-
}
10311-
}
10312-
}
10317+
zend_compile_rope_finalize(result, j, init_opline, opline);
1031310318
}
1031410319
/* }}} */
1031510320

0 commit comments

Comments
 (0)