Improved the implementation of new-expressions.

This commit is contained in:
Roberto Raggi
2009-02-10 14:43:19 +01:00
committed by Roberto Raggi
parent 885d908ea3
commit 2d80acbe76
10 changed files with 294 additions and 125 deletions

View File

@@ -764,15 +764,11 @@ bool PrettyPrinter::visit(NestedNameSpecifierAST *ast)
return false;
}
bool PrettyPrinter::visit(NewDeclaratorAST *ast)
bool PrettyPrinter::visit(NewArrayDeclaratorAST *ast)
{
for (PtrOperatorAST *it = ast->ptr_operators; it; it = it->next) {
accept(it);
if (it->next)
out << ' ';
}
if (ast->declarator)
accept(ast->declarator);
out << '[';
accept(ast->expression);
out << ']';
return false;
}
@@ -782,25 +778,32 @@ bool PrettyPrinter::visit(NewExpressionAST *ast)
out << "::";
out << "new";
out << ' ';
if (ast->expression) {
accept(ast->expression);
if (ast->type_id)
out << ' ';
}
if (ast->type_id) {
accept(ast->new_placement);
if (ast->new_placement)
out << ' ';
if (ast->lparen_token) {
out << '(';
accept(ast->type_id);
if (ast->new_type_id)
out << ' ';
}
if (ast->new_type_id) {
out << ')';
} else {
accept(ast->new_type_id);
if (ast->new_initializer)
out << ' ';
}
accept(ast->new_initializer);
return false;
}
bool PrettyPrinter::visit(NewPlacementAST *ast)
{
out << '(';
for (ExpressionListAST *it = ast->expression_list; it; it = it->next) {
accept(it->expression);
if (it->next)
out << ", ";
}
out << ')';
return false;
}
bool PrettyPrinter::visit(NewInitializerAST *ast)
{
out << '(';
@@ -812,18 +815,16 @@ bool PrettyPrinter::visit(NewInitializerAST *ast)
bool PrettyPrinter::visit(NewTypeIdAST *ast)
{
for (SpecifierAST *it = ast->type_specifier; it; it = it->next) {
if (it != ast->type_specifier)
out << ' ';
accept(it);
if (it->next)
out << ' ';
}
if (ast->type_specifier)
out << ' ';
if (ast->new_initializer) {
accept(ast->new_initializer);
if (ast->new_declarator)
out << ' ';
for (PtrOperatorAST *it = ast->ptr_operators; it; it = it->next) {
accept(it);
}
for (NewArrayDeclaratorAST *it = ast->new_array_declarators; it; it = it->next) {
accept(it);
}
accept(ast->new_declarator);
return false;
}