diff options
author | Nikita Popov <nikic@php.net> | 2014-09-16 19:14:46 +0100 |
---|---|---|
committer | Andrea Faulds <ajf@ajf.me> | 2014-09-16 19:14:46 +0100 |
commit | 69e7c9d89ca4674b73a851154d1f06dcbb6cb352 (patch) | |
tree | e9f01ffdb2721980166d342dda725692bd1a7ea7 /Zend/zend_compile.c | |
parent | f469dc7429f2257aac6f46228302408608fbd62f (diff) | |
download | php-git-69e7c9d89ca4674b73a851154d1f06dcbb6cb352.tar.gz |
Initial coalesce operator implementation
Diffstat (limited to 'Zend/zend_compile.c')
-rw-r--r-- | Zend/zend_compile.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 5beacab0b6..5d3d7727e1 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -6917,6 +6917,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]; @@ -7754,6 +7778,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; |