Preserve parenthesization in the AST
Maintain explicit "paren" nodes in the AST so we can pretty-print without having to guess where parens should go. We may revisit this in the future. r=graydon
This commit is contained in:
parent
17a5d0f3a0
commit
62f98c8ff8
20 changed files with 148 additions and 217 deletions
|
@ -36,39 +36,3 @@ fn stmt_ends_with_semi(stmt: ast::stmt) -> bool {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn need_parens(expr: @ast::expr, outer_prec: uint) -> bool {
|
||||
match expr.node {
|
||||
ast::expr_binary(op, _, _) => operator_prec(op) < outer_prec,
|
||||
ast::expr_cast(_, _) => parse::prec::as_prec < outer_prec,
|
||||
// This may be too conservative in some cases
|
||||
ast::expr_assign(_, _) => true,
|
||||
ast::expr_swap(_, _) => true,
|
||||
ast::expr_assign_op(_, _, _) => true,
|
||||
ast::expr_ret(_) => true,
|
||||
ast::expr_assert(_) => true,
|
||||
ast::expr_log(_, _, _) => true,
|
||||
_ => !parse::classify::expr_requires_semi_to_be_stmt(expr)
|
||||
}
|
||||
}
|
||||
|
||||
fn ends_in_lit_int(ex: @ast::expr) -> bool {
|
||||
match ex.node {
|
||||
ast::expr_lit(node) => match node {
|
||||
@{node: ast::lit_int(_, ast::ty_i), _}
|
||||
| @{node: ast::lit_int_unsuffixed(_), _} => true,
|
||||
_ => false
|
||||
},
|
||||
ast::expr_binary(_, _, sub) | ast::expr_unary(_, sub) |
|
||||
ast::expr_copy(sub) | ast::expr_assign(_, sub) |
|
||||
ast::expr_assign_op(_, _, sub) | ast::expr_swap(_, sub) |
|
||||
ast::expr_log(_, _, sub) | ast::expr_assert(sub) => {
|
||||
ends_in_lit_int(sub)
|
||||
}
|
||||
ast::expr_fail(osub) | ast::expr_ret(osub) => match osub {
|
||||
Some(ex) => ends_in_lit_int(ex),
|
||||
_ => false
|
||||
},
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue