mirror of
https://github.com/php/php-src.git
synced 2025-08-16 22:18:50 +02:00
fixed pretty-printer (support for "elseif")
This commit is contained in:
parent
5a976c8d85
commit
07b1f92ed6
2 changed files with 52 additions and 11 deletions
|
@ -134,6 +134,9 @@ assert(0 && ($a = function () {
|
||||||
$x = new foo();
|
$x = new foo();
|
||||||
$x = new \foo();
|
$x = new \foo();
|
||||||
$x = new namespace\foo();
|
$x = new namespace\foo();
|
||||||
|
if ($a) {
|
||||||
|
} elseif ($b) {
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -286,4 +289,7 @@ Warning: assert(): assert(0 && ($a = function () {
|
||||||
$x = new foo();
|
$x = new foo();
|
||||||
$x = new \foo();
|
$x = new \foo();
|
||||||
$x = new namespace\foo();
|
$x = new namespace\foo();
|
||||||
|
if ($a) {
|
||||||
|
} elseif ($b) {
|
||||||
|
}
|
||||||
})) failed in %sexpect_015.php on line %d
|
})) failed in %sexpect_015.php on line %d
|
||||||
|
|
|
@ -747,6 +747,43 @@ static void zend_ast_export_stmt(smart_str *str, zend_ast *ast, int indent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void zend_ast_export_if_stmt(smart_str *str, zend_ast_list *list, int indent)
|
||||||
|
{
|
||||||
|
uint32_t i;
|
||||||
|
zend_ast *ast;
|
||||||
|
|
||||||
|
tail_call:
|
||||||
|
i = 0;
|
||||||
|
while (i < list->children) {
|
||||||
|
ast = list->child[i];
|
||||||
|
ZEND_ASSERT(ast->kind == ZEND_AST_IF_ELEM);
|
||||||
|
if (ast->child[0]) {
|
||||||
|
if (i == 0) {
|
||||||
|
smart_str_appends(str, "if (");
|
||||||
|
} else {
|
||||||
|
zend_ast_export_indent(str, indent);
|
||||||
|
smart_str_appends(str, "} elseif (");
|
||||||
|
}
|
||||||
|
zend_ast_export_ex(str, ast->child[0], 0, indent);
|
||||||
|
smart_str_appends(str, ") {\n");
|
||||||
|
zend_ast_export_stmt(str, ast->child[1], indent + 1);
|
||||||
|
} else {
|
||||||
|
zend_ast_export_indent(str, indent);
|
||||||
|
smart_str_appends(str, "} else ");
|
||||||
|
if (ast->child[1]->kind == ZEND_AST_IF) {
|
||||||
|
list = (zend_ast_list*)ast->child[1];
|
||||||
|
goto tail_call;
|
||||||
|
} else {
|
||||||
|
smart_str_appends(str, "{\n");
|
||||||
|
zend_ast_export_stmt(str, ast->child[1], indent + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
zend_ast_export_indent(str, indent);
|
||||||
|
smart_str_appendc(str, '}');
|
||||||
|
}
|
||||||
|
|
||||||
static void zend_ast_export_zval(smart_str *str, zval *zv, int priority, int indent)
|
static void zend_ast_export_zval(smart_str *str, zval *zv, int priority, int indent)
|
||||||
{
|
{
|
||||||
zend_long idx;
|
zend_long idx;
|
||||||
|
@ -974,6 +1011,8 @@ simple_list:
|
||||||
zend_ast_export_stmt(str, ast, indent);
|
zend_ast_export_stmt(str, ast, indent);
|
||||||
break;
|
break;
|
||||||
case ZEND_AST_IF:
|
case ZEND_AST_IF:
|
||||||
|
zend_ast_export_if_stmt(str, (zend_ast_list*)ast, indent);
|
||||||
|
break;
|
||||||
case ZEND_AST_SWITCH_LIST:
|
case ZEND_AST_SWITCH_LIST:
|
||||||
case ZEND_AST_CATCH_LIST:
|
case ZEND_AST_CATCH_LIST:
|
||||||
zend_ast_export_list(str, (zend_ast_list*)ast, 0, 0, indent);
|
zend_ast_export_list(str, (zend_ast_list*)ast, 0, 0, indent);
|
||||||
|
@ -1268,23 +1307,19 @@ simple_list:
|
||||||
zend_ast_export_ex(str, ast->child[1], 0, indent);
|
zend_ast_export_ex(str, ast->child[1], 0, indent);
|
||||||
smart_str_appendc(str, ')');
|
smart_str_appendc(str, ')');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ZEND_AST_IF_ELEM:
|
case ZEND_AST_IF_ELEM:
|
||||||
if (ast->child[0]) {
|
if (ast->child[0]) {
|
||||||
smart_str_appends(str, "if (");
|
smart_str_appends(str, "if (");
|
||||||
zend_ast_export_ex(str, ast->child[0], 0, indent);
|
zend_ast_export_ex(str, ast->child[0], 0, indent);
|
||||||
smart_str_appends(str, ") ");
|
smart_str_appends(str, ") {\n");
|
||||||
} else {
|
zend_ast_export_stmt(str, ast->child[1], indent + 1);
|
||||||
smart_str_appends(str, " else ");
|
} else {
|
||||||
}
|
smart_str_appends(str, "else {\n");
|
||||||
if (ast->child[1]->kind == ZEND_AST_IF) {
|
|
||||||
zend_ast_export_list(str, (zend_ast_list*)ast->child[1], 0, 0, indent);
|
|
||||||
} else {
|
|
||||||
smart_str_appends(str, "{\n");
|
|
||||||
zend_ast_export_stmt(str, ast->child[1], indent + 1);
|
zend_ast_export_stmt(str, ast->child[1], indent + 1);
|
||||||
zend_ast_export_indent(str, indent);
|
|
||||||
smart_str_appendc(str, '}');
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
zend_ast_export_indent(str, indent);
|
||||||
|
smart_str_appendc(str, '}');
|
||||||
break;
|
break;
|
||||||
case ZEND_AST_SWITCH:
|
case ZEND_AST_SWITCH:
|
||||||
smart_str_appends(str, "switch (");
|
smart_str_appends(str, "switch (");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue