diff options
| author | Marvin Löbel <loebel.marvin@gmail.com> | 2013-09-02 03:45:37 +0200 |
|---|---|---|
| committer | Marvin Löbel <loebel.marvin@gmail.com> | 2013-09-03 14:45:06 +0200 |
| commit | 74190853373c7963d933e2fb5c2ac2f761fdbc02 (patch) | |
| tree | 12ffa50679235aab28c7bf26799504d7ac8b8ac6 /src/libsyntax/print/pprust.rs | |
| parent | 58decdd7a115f2892d63fa3760fa2125eb784ac8 (diff) | |
| download | rust-74190853373c7963d933e2fb5c2ac2f761fdbc02.tar.gz rust-74190853373c7963d933e2fb5c2ac2f761fdbc02.zip | |
Modernized a few more types in syntax::ast
Diffstat (limited to 'src/libsyntax/print/pprust.rs')
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 202 |
1 files changed, 101 insertions, 101 deletions
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index c03bcca7bf9..e1a0e1bf08d 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -33,8 +33,8 @@ use std::io; pub enum ann_node<'self> { node_block(@ps, &'self ast::Block), node_item(@ps, &'self ast::item), - node_expr(@ps, &'self ast::expr), - node_pat(@ps, &'self ast::pat), + node_expr(@ps, &'self ast::Expr), + node_pat(@ps, &'self ast::Pat), } pub struct pp_ann { pre: @fn(ann_node), @@ -148,11 +148,11 @@ pub fn ty_to_str(ty: &ast::Ty, intr: @ident_interner) -> ~str { to_str(ty, print_type, intr) } -pub fn pat_to_str(pat: &ast::pat, intr: @ident_interner) -> ~str { +pub fn pat_to_str(pat: &ast::Pat, intr: @ident_interner) -> ~str { to_str(pat, print_pat, intr) } -pub fn expr_to_str(e: &ast::expr, intr: @ident_interner) -> ~str { +pub fn expr_to_str(e: &ast::Expr, intr: @ident_interner) -> ~str { to_str(e, print_expr, intr) } @@ -168,7 +168,7 @@ pub fn tts_to_str(tts: &[ast::token_tree], intr: @ident_interner) -> ~str { to_str(&tts, print_tts, intr) } -pub fn stmt_to_str(s: &ast::stmt, intr: @ident_interner) -> ~str { +pub fn stmt_to_str(s: &ast::Stmt, intr: @ident_interner) -> ~str { to_str(s, print_stmt, intr) } @@ -346,7 +346,7 @@ pub fn commasep_cmnt<T>(s: @ps, b: breaks, elts: &[T], op: &fn(@ps, &T), end(s); } -pub fn commasep_exprs(s: @ps, b: breaks, exprs: &[@ast::expr]) { +pub fn commasep_exprs(s: @ps, b: breaks, exprs: &[@ast::Expr]) { commasep_cmnt(s, b, exprs, |p, &e| print_expr(p, e), |e| e.span); } @@ -385,8 +385,8 @@ pub fn print_type(s: @ps, ty: &ast::Ty) { ast::ty_vec(ref mt) => { word(s.s, "["); match mt.mutbl { - ast::m_mutbl => word_space(s, "mut"), - ast::m_imm => () + ast::MutMutable => word_space(s, "mut"), + ast::MutImmutable => () } print_type(s, mt.ty); word(s.s, "]"); @@ -427,8 +427,8 @@ pub fn print_type(s: @ps, ty: &ast::Ty) { ast::ty_fixed_length_vec(ref mt, v) => { word(s.s, "["); match mt.mutbl { - ast::m_mutbl => word_space(s, "mut"), - ast::m_imm => () + ast::MutMutable => word_space(s, "mut"), + ast::MutImmutable => () } print_type(s, mt.ty); word(s.s, ", .."); @@ -487,7 +487,7 @@ pub fn print_item(s: @ps, item: &ast::item) { match item.node { ast::item_static(ref ty, m, expr) => { head(s, visibility_qualified(item.vis, "static")); - if m == ast::m_mutbl { + if m == ast::MutMutable { word_space(s, "mut"); } print_ident(s, item.ident); @@ -886,22 +886,22 @@ pub fn print_attribute(s: @ps, attr: &ast::Attribute) { } -pub fn print_stmt(s: @ps, st: &ast::stmt) { +pub fn print_stmt(s: @ps, st: &ast::Stmt) { maybe_print_comment(s, st.span.lo); match st.node { - ast::stmt_decl(decl, _) => { + ast::StmtDecl(decl, _) => { print_decl(s, decl); } - ast::stmt_expr(expr, _) => { + ast::StmtExpr(expr, _) => { space_if_not_bol(s); print_expr(s, expr); } - ast::stmt_semi(expr, _) => { + ast::StmtSemi(expr, _) => { space_if_not_bol(s); print_expr(s, expr); word(s.s, ";"); } - ast::stmt_mac(ref mac, semi) => { + ast::StmtMac(ref mac, semi) => { space_if_not_bol(s); print_mac(s, mac); if semi { word(s.s, ";"); } @@ -978,19 +978,19 @@ pub fn print_possibly_embedded_block_(s: @ps, (s.ann.post)(ann_node); } -pub fn print_if(s: @ps, test: &ast::expr, blk: &ast::Block, - elseopt: Option<@ast::expr>, chk: bool) { +pub fn print_if(s: @ps, test: &ast::Expr, blk: &ast::Block, + elseopt: Option<@ast::Expr>, chk: bool) { head(s, "if"); if chk { word_nbsp(s, "check"); } print_expr(s, test); space(s.s); print_block(s, blk); - fn do_else(s: @ps, els: Option<@ast::expr>) { + fn do_else(s: @ps, els: Option<@ast::Expr>) { match els { Some(_else) => { match _else.node { // "another else-if" - ast::expr_if(i, ref t, e) => { + ast::ExprIf(i, ref t, e) => { cbox(s, indent_unit - 1u); ibox(s, 0u); word(s.s, " else if "); @@ -1000,7 +1000,7 @@ pub fn print_if(s: @ps, test: &ast::expr, blk: &ast::Block, do_else(s, e); } // "final else" - ast::expr_block(ref b) => { + ast::ExprBlock(ref b) => { cbox(s, indent_unit - 1u); ibox(s, 0u); word(s.s, " else "); @@ -1030,29 +1030,29 @@ pub fn print_mac(s: @ps, m: &ast::mac) { } } -pub fn print_vstore(s: @ps, t: ast::vstore) { +pub fn print_vstore(s: @ps, t: ast::Vstore) { match t { - ast::vstore_fixed(Some(i)) => word(s.s, fmt!("%u", i)), - ast::vstore_fixed(None) => word(s.s, "_"), - ast::vstore_uniq => word(s.s, "~"), - ast::vstore_box => word(s.s, "@"), - ast::vstore_slice(ref r) => { + ast::VstoreFixed(Some(i)) => word(s.s, fmt!("%u", i)), + ast::VstoreFixed(None) => word(s.s, "_"), + ast::VstoreUniq => word(s.s, "~"), + ast::VstoreBox => word(s.s, "@"), + ast::VstoreSlice(ref r) => { word(s.s, "&"); print_opt_lifetime(s, r); } } } -pub fn print_expr_vstore(s: @ps, t: ast::expr_vstore) { +pub fn print_expr_vstore(s: @ps, t: ast::ExprVstore) { match t { - ast::expr_vstore_uniq => word(s.s, "~"), - ast::expr_vstore_box => word(s.s, "@"), - ast::expr_vstore_mut_box => { + ast::ExprVstoreUniq => word(s.s, "~"), + ast::ExprVstoreBox => word(s.s, "@"), + ast::ExprVstoreMutBox => { word(s.s, "@"); word(s.s, "mut"); } - ast::expr_vstore_slice => word(s.s, "&"), - ast::expr_vstore_mut_slice => { + ast::ExprVstoreSlice => word(s.s, "&"), + ast::ExprVstoreMutSlice => { word(s.s, "&"); word(s.s, "mut"); } @@ -1061,8 +1061,8 @@ pub fn print_expr_vstore(s: @ps, t: ast::expr_vstore) { pub fn print_call_pre(s: @ps, sugar: ast::CallSugar, - base_args: &mut ~[@ast::expr]) - -> Option<@ast::expr> { + base_args: &mut ~[@ast::Expr]) + -> Option<@ast::Expr> { match sugar { ast::DoSugar => { head(s, "do"); @@ -1078,8 +1078,8 @@ pub fn print_call_pre(s: @ps, pub fn print_call_post(s: @ps, sugar: ast::CallSugar, - blk: &Option<@ast::expr>, - base_args: &mut ~[@ast::expr]) { + blk: &Option<@ast::Expr>, + base_args: &mut ~[@ast::Expr]) { if sugar == ast::NoSugar || !base_args.is_empty() { popen(s); commasep_exprs(s, inconsistent, *base_args); @@ -1089,7 +1089,7 @@ pub fn print_call_post(s: @ps, nbsp(s); match blk.unwrap().node { // need to handle closures specifically - ast::expr_do_body(e) => { + ast::ExprDoBody(e) => { end(s); // we close our head box; closure // will create it's own. print_expr(s, e); @@ -1103,7 +1103,7 @@ pub fn print_call_post(s: @ps, } } -pub fn print_expr(s: @ps, expr: &ast::expr) { +pub fn print_expr(s: @ps, expr: &ast::Expr) { fn print_field(s: @ps, field: &ast::Field) { ibox(s, indent_unit); print_ident(s, field.ident); @@ -1118,14 +1118,14 @@ pub fn print_expr(s: @ps, expr: &ast::expr) { let ann_node = node_expr(s, expr); (s.ann.pre)(ann_node); match expr.node { - ast::expr_vstore(e, v) => { + ast::ExprVstore(e, v) => { print_expr_vstore(s, v); print_expr(s, e); }, - ast::expr_vec(ref exprs, mutbl) => { + ast::ExprVec(ref exprs, mutbl) => { ibox(s, indent_unit); word(s.s, "["); - if mutbl == ast::m_mutbl { + if mutbl == ast::MutMutable { word(s.s, "mut"); if exprs.len() > 0u { nbsp(s); } } @@ -1134,10 +1134,10 @@ pub fn print_expr(s: @ps, expr: &ast::expr) { end(s); } - ast::expr_repeat(element, count, mutbl) => { + ast::ExprRepeat(element, count, mutbl) => { ibox(s, indent_unit); word(s.s, "["); - if mutbl == ast::m_mutbl { + if mutbl == ast::MutMutable { word(s.s, "mut"); nbsp(s); } @@ -1149,7 +1149,7 @@ pub fn print_expr(s: @ps, expr: &ast::expr) { end(s); } - ast::expr_struct(ref path, ref fields, wth) => { + ast::ExprStruct(ref path, ref fields, wth) => { print_path(s, path, true); word(s.s, "{"); commasep_cmnt(s, consistent, (*fields), print_field, get_span); @@ -1166,7 +1166,7 @@ pub fn print_expr(s: @ps, expr: &ast::expr) { } word(s.s, "}"); } - ast::expr_tup(ref exprs) => { + ast::ExprTup(ref exprs) => { popen(s); commasep_exprs(s, inconsistent, *exprs); if exprs.len() == 1 { @@ -1174,13 +1174,13 @@ pub fn print_expr(s: @ps, expr: &ast::expr) { } pclose(s); } - ast::expr_call(func, ref args, sugar) => { + ast::ExprCall(func, ref args, sugar) => { let mut base_args = (*args).clone(); let blk = print_call_pre(s, sugar, &mut base_args); print_expr(s, func); print_call_post(s, sugar, &blk, &mut base_args); } - ast::expr_method_call(_, func, ident, ref tys, ref args, sugar) => { + ast::ExprMethodCall(_, func, ident, ref tys, ref args, sugar) => { let mut base_args = (*args).clone(); let blk = print_call_pre(s, sugar, &mut base_args); print_expr(s, func); @@ -1193,43 +1193,43 @@ pub fn print_expr(s: @ps, expr: &ast::expr) { } print_call_post(s, sugar, &blk, &mut base_args); } - ast::expr_binary(_, op, lhs, rhs) => { + ast::ExprBinary(_, op, lhs, rhs) => { print_expr(s, lhs); space(s.s); word_space(s, ast_util::binop_to_str(op)); print_expr(s, rhs); } - ast::expr_unary(_, op, expr) => { + ast::ExprUnary(_, op, expr) => { word(s.s, ast_util::unop_to_str(op)); print_expr(s, expr); } - ast::expr_addr_of(m, expr) => { + ast::ExprAddrOf(m, expr) => { word(s.s, "&"); print_mutability(s, m); // Avoid `& &e` => `&&e`. match (m, &expr.node) { - (ast::m_imm, &ast::expr_addr_of(*)) => space(s.s), + (ast::MutImmutable, &ast::ExprAddrOf(*)) => space(s.s), _ => { } } print_expr(s, expr); } - ast::expr_lit(lit) => print_literal(s, lit), - ast::expr_cast(expr, ref ty) => { + ast::ExprLit(lit) => print_literal(s, lit), + ast::ExprCast(expr, ref ty) => { print_expr(s, expr); space(s.s); word_space(s, "as"); print_type(s, ty); } - ast::expr_if(test, ref blk, elseopt) => { + ast::ExprIf(test, ref blk, elseopt) => { print_if(s, test, blk, elseopt, false); } - ast::expr_while(test, ref blk) => { + ast::ExprWhile(test, ref blk) => { head(s, "while"); print_expr(s, test); space(s.s); print_block(s, blk); } - ast::expr_for_loop(pat, iter, ref blk) => { + ast::ExprForLoop(pat, iter, ref blk) => { head(s, "for"); print_pat(s, pat); space(s.s); @@ -1238,7 +1238,7 @@ pub fn print_expr(s: @ps, expr: &ast::expr) { space(s.s); print_block(s, blk); } - ast::expr_loop(ref blk, opt_ident) => { + ast::ExprLoop(ref blk, opt_ident) => { for ident in opt_ident.iter() { word(s.s, "'"); print_ident(s, *ident); @@ -1248,7 +1248,7 @@ pub fn print_expr(s: @ps, expr: &ast::expr) { space(s.s); print_block(s, blk); } - ast::expr_match(expr, ref arms) => { + ast::ExprMatch(expr, ref arms) => { cbox(s, indent_unit); ibox(s, 4); word_nbsp(s, "match"); @@ -1288,7 +1288,7 @@ pub fn print_expr(s: @ps, expr: &ast::expr) { match arm.body.expr { Some(expr) => { match expr.node { - ast::expr_block(ref blk) => { + ast::ExprBlock(ref blk) => { // the block will close the pattern's ibox print_block_unclosed_indent( s, blk, indent_unit); @@ -1313,7 +1313,7 @@ pub fn print_expr(s: @ps, expr: &ast::expr) { } bclose_(s, expr.span, indent_unit); } - ast::expr_fn_block(ref decl, ref body) => { + ast::ExprFnBlock(ref decl, ref body) => { // in do/for blocks we don't want to show an empty // argument list, but at this point we don't know which // we are inside. @@ -1326,7 +1326,7 @@ pub fn print_expr(s: @ps, expr: &ast::expr) { assert!(body.expr.is_some()); // we extract the block, so as not to create another set of boxes match body.expr.unwrap().node { - ast::expr_block(ref blk) => { + ast::ExprBlock(ref blk) => { print_block_unclosed(s, blk); } _ => { @@ -1340,30 +1340,30 @@ pub fn print_expr(s: @ps, expr: &ast::expr) { // empty box to satisfy the close. ibox(s, 0); } - ast::expr_do_body(body) => { + ast::ExprDoBody(body) => { print_expr(s, body); } - ast::expr_block(ref blk) => { + ast::ExprBlock(ref blk) => { // containing cbox, will be closed by print-block at } cbox(s, indent_unit); // head-box, will be closed by print-block after { ibox(s, 0u); print_block(s, blk); } - ast::expr_assign(lhs, rhs) => { + ast::ExprAssign(lhs, rhs) => { print_expr(s, lhs); space(s.s); word_space(s, "="); print_expr(s, rhs); } - ast::expr_assign_op(_, op, lhs, rhs) => { + ast::ExprAssignOp(_, op, lhs, rhs) => { print_expr(s, lhs); space(s.s); word(s.s, ast_util::binop_to_str(op)); word_space(s, "="); print_expr(s, rhs); } - ast::expr_field(expr, id, ref tys) => { + ast::ExprField(expr, id, ref tys) => { print_expr(s, expr); word(s.s, "."); print_ident(s, id); @@ -1373,15 +1373,15 @@ pub fn print_expr(s: @ps, expr: &ast::expr) { word(s.s, ">"); } } - ast::expr_index(_, expr, index) => { + ast::ExprIndex(_, expr, index) => { print_expr(s, expr); word(s.s, "["); print_expr(s, index); word(s.s, "]"); } - ast::expr_path(ref path) => print_path(s, path, true), - ast::expr_self => word(s.s, "self"), - ast::expr_break(opt_ident) => { + ast::ExprPath(ref path) => print_path(s, path, true), + ast::ExprSelf => word(s.s, "self"), + ast::ExprBreak(opt_ident) => { word(s.s, "break"); space(s.s); for ident in opt_ident.iter() { @@ -1390,7 +1390,7 @@ pub fn print_expr(s: @ps, expr: &ast::expr) { space(s.s); } } - ast::expr_again(opt_ident) => { + ast::ExprAgain(opt_ident) => { word(s.s, "loop"); space(s.s); for ident in opt_ident.iter() { @@ -1399,14 +1399,14 @@ pub fn print_expr(s: @ps, expr: &ast::expr) { space(s.s) } } - ast::expr_ret(result) => { + ast::ExprRet(result) => { word(s.s, "return"); match result { Some(expr) => { word(s.s, " "); print_expr(s, expr); } _ => () } } - ast::expr_log(lexp, expr) => { + ast::ExprLog(lexp, expr) => { word(s.s, "__log"); popen(s); print_expr(s, lexp); @@ -1415,7 +1415,7 @@ pub fn print_expr(s: @ps, expr: &ast::expr) { print_expr(s, expr); pclose(s); } - ast::expr_inline_asm(ref a) => { + ast::ExprInlineAsm(ref a) => { if a.volatile { word(s.s, "__volatile__ asm!"); } else { @@ -1443,8 +1443,8 @@ pub fn print_expr(s: @ps, expr: &ast::expr) { print_string(s, a.clobbers); pclose(s); } - ast::expr_mac(ref m) => print_mac(s, m), - ast::expr_paren(e) => { + ast::ExprMac(ref m) => print_mac(s, m), + ast::ExprParen(e) => { popen(s); print_expr(s, e); pclose(s); @@ -1462,10 +1462,10 @@ pub fn print_local_decl(s: @ps, loc: &ast::Local) { } } -pub fn print_decl(s: @ps, decl: &ast::decl) { +pub fn print_decl(s: @ps, decl: &ast::Decl) { maybe_print_comment(s, decl.span.lo); match decl.node { - ast::decl_local(ref loc) => { + ast::DeclLocal(ref loc) => { space_if_not_bol(s); ibox(s, indent_unit); word_nbsp(s, "let"); @@ -1491,7 +1491,7 @@ pub fn print_decl(s: @ps, decl: &ast::decl) { print_local(s, *loc); end(s); } - ast::decl_item(item) => print_item(s, item) + ast::DeclItem(item) => print_item(s, item) } } @@ -1499,7 +1499,7 @@ pub fn print_ident(s: @ps, ident: ast::Ident) { word(s.s, ident_to_str(&ident)); } -pub fn print_for_decl(s: @ps, loc: &ast::Local, coll: &ast::expr) { +pub fn print_for_decl(s: @ps, loc: &ast::Local, coll: &ast::Expr) { print_local_decl(s, loc); space(s.s); word_space(s, "in"); @@ -1565,21 +1565,21 @@ pub fn print_bounded_path(s: @ps, path: &ast::Path, print_path_(s, path, false, bounds) } -pub fn print_pat(s: @ps, pat: &ast::pat) { +pub fn print_pat(s: @ps, pat: &ast::Pat) { maybe_print_comment(s, pat.span.lo); let ann_node = node_pat(s, pat); (s.ann.pre)(ann_node); /* Pat isn't normalized, but the beauty of it is that it doesn't matter */ match pat.node { - ast::pat_wild => word(s.s, "_"), - ast::pat_ident(binding_mode, ref path, sub) => { + ast::PatWild => word(s.s, "_"), + ast::PatIdent(binding_mode, ref path, sub) => { match binding_mode { - ast::bind_by_ref(mutbl) => { + ast::BindByRef(mutbl) => { word_nbsp(s, "ref"); print_mutability(s, mutbl); } - ast::bind_infer => {} + ast::BindInfer => {} } print_path(s, path, true); match sub { @@ -1590,7 +1590,7 @@ pub fn print_pat(s: @ps, pat: &ast::pat) { None => () } } - ast::pat_enum(ref path, ref args_) => { + ast::PatEnum(ref path, ref args_) => { print_path(s, path, true); match *args_ { None => word(s.s, "(*)"), @@ -1604,17 +1604,17 @@ pub fn print_pat(s: @ps, pat: &ast::pat) { } } } - ast::pat_struct(ref path, ref fields, etc) => { + ast::PatStruct(ref path, ref fields, etc) => { print_path(s, path, true); word(s.s, "{"); - fn print_field(s: @ps, f: &ast::field_pat) { + fn print_field(s: @ps, f: &ast::FieldPat) { cbox(s, indent_unit); print_ident(s, f.ident); word_space(s, ":"); print_pat(s, f.pat); end(s); } - fn get_span(f: &ast::field_pat) -> codemap::Span { return f.pat.span; } + fn get_span(f: &ast::FieldPat) -> codemap::Span { return f.pat.span; } commasep_cmnt(s, consistent, *fields, |s, f| print_field(s,f), get_span); @@ -1624,7 +1624,7 @@ pub fn print_pat(s: @ps, pat: &ast::pat) { } word(s.s, "}"); } - ast::pat_tup(ref elts) => { + ast::PatTup(ref elts) => { popen(s); commasep(s, inconsistent, *elts, |s, &p| print_pat(s, p)); if elts.len() == 1 { @@ -1632,26 +1632,26 @@ pub fn print_pat(s: @ps, pat: &ast::pat) { } pclose(s); } - ast::pat_box(inner) => { + ast::PatBox(inner) => { word(s.s, "@"); print_pat(s, inner); } - ast::pat_uniq(inner) => { + ast::PatUniq(inner) => { word(s.s, "~"); print_pat(s, inner); } - ast::pat_region(inner) => { + ast::PatRegion(inner) => { word(s.s, "&"); print_pat(s, inner); } - ast::pat_lit(e) => print_expr(s, e), - ast::pat_range(begin, end) => { + ast::PatLit(e) => print_expr(s, e), + ast::PatRange(begin, end) => { print_expr(s, begin); space(s.s); word(s.s, ".."); print_expr(s, end); } - ast::pat_vec(ref before, slice, ref after) => { + ast::PatVec(ref before, slice, ref after) => { word(s.s, "["); do commasep(s, inconsistent, *before) |s, &p| { print_pat(s, p); @@ -1900,10 +1900,10 @@ pub fn print_view_item(s: @ps, item: &ast::view_item) { end(s); // end outer head-block } -pub fn print_mutability(s: @ps, mutbl: ast::mutability) { +pub fn print_mutability(s: @ps, mutbl: ast::Mutability) { match mutbl { - ast::m_mutbl => word_nbsp(s, "mut"), - ast::m_imm => {/* nothing */ } + ast::MutMutable => word_nbsp(s, "mut"), + ast::MutImmutable => {/* nothing */ } } } @@ -1921,7 +1921,7 @@ pub fn print_arg(s: @ps, input: &ast::arg) { ast::ty_infer => print_pat(s, input.pat), _ => { match input.pat.node { - ast::pat_ident(_, ref path, _) if + ast::PatIdent(_, ref path, _) if path.segments.len() == 1 && path.segments[0].identifier == parse::token::special_idents::invalid => { |
