summaryrefslogtreecommitdiff
path: root/Zend/zend_compile.c
diff options
context:
space:
mode:
authorAndrea Faulds <ajf@ajf.me>2014-09-28 00:07:04 +0100
committerAndrea Faulds <ajf@ajf.me>2014-09-28 00:07:04 +0100
commit2d069f640e6cccfa3ba8b1e4f375ade20fb33f64 (patch)
treee6edf9822fe559eae0506c75c83286d404c822be /Zend/zend_compile.c
parentf13da5b0d72dc8dfcc5e7d4ae11556a92c36ce53 (diff)
parentec39802e4e7dac14b629f41017d04573a6a5fdc4 (diff)
downloadphp-git-2d069f640e6cccfa3ba8b1e4f375ade20fb33f64.tar.gz
Merge branch 'coalesce_operator'
* coalesce_operator: Extended coalesce operator test case for ordering/short-circuiting Ensure not evaluated twice Added test Initial coalesce operator implementation
Diffstat (limited to 'Zend/zend_compile.c')
-rw-r--r--Zend/zend_compile.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 54d1837e82..4e5ac0b80f 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -5324,6 +5324,30 @@ void zend_compile_conditional(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
}
/* }}} */
+void zend_compile_coalesce(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
+{
+ zend_ast *expr_ast = ast->child[0];
+ zend_ast *default_ast = ast->child[1];
+
+ znode expr_node, default_node;
+ zend_op *opline;
+ uint32_t opnum;
+
+ zend_compile_var(&expr_node, expr_ast, BP_VAR_IS TSRMLS_CC);
+
+ opnum = get_next_op_number(CG(active_op_array));
+ zend_emit_op(result, ZEND_COALESCE, &expr_node, NULL TSRMLS_CC);
+
+ zend_compile_expr(&default_node, default_ast TSRMLS_CC);
+
+ opline = zend_emit_op(NULL, ZEND_QM_ASSIGN, &default_node, NULL TSRMLS_CC);
+ SET_NODE(opline->result, result);
+
+ opline = &CG(active_op_array)->opcodes[opnum];
+ opline->op2.opline_num = get_next_op_number(CG(active_op_array));
+}
+/* }}} */
+
void zend_compile_print(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
{
zend_ast *expr_ast = ast->child[0];
@@ -6158,6 +6182,9 @@ void zend_compile_expr(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
case ZEND_AST_CONDITIONAL:
zend_compile_conditional(result, ast TSRMLS_CC);
return;
+ case ZEND_AST_COALESCE:
+ zend_compile_coalesce(result, ast TSRMLS_CC);
+ return;
case ZEND_AST_PRINT:
zend_compile_print(result, ast TSRMLS_CC);
return;