diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2013-03-15 15:24:24 -0400 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2013-04-30 06:59:32 -0400 |
| commit | a896440ca1b93cc5dc6edd827ea2ae89602bfa9e (patch) | |
| tree | c6945d51bf84faeb9be6ac32247c8ffa2cd39226 /src/libsyntax/ast_map.rs | |
| parent | b5a7e8b35322869b1cf51bd1b35a86e9e721da54 (diff) | |
| download | rust-a896440ca1b93cc5dc6edd827ea2ae89602bfa9e.tar.gz rust-a896440ca1b93cc5dc6edd827ea2ae89602bfa9e.zip | |
new borrow checker (mass squash)
Diffstat (limited to 'src/libsyntax/ast_map.rs')
| -rw-r--r-- | src/libsyntax/ast_map.rs | 69 |
1 files changed, 34 insertions, 35 deletions
diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index f9828ad2b9e..eb131b17c2f 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -19,6 +19,7 @@ use diagnostic::span_handler; use parse::token::ident_interner; use print::pprust; use visit; +use syntax::parse::token::special_idents; use core::hashmap::HashMap; @@ -89,14 +90,13 @@ pub enum ast_node { node_variant(variant, @item, @path), node_expr(@expr), node_stmt(@stmt), - // Locals are numbered, because the alias analysis needs to know in which - // order they are introduced. - node_arg(arg, uint), - node_local(uint), + node_arg, + node_local(ident), // Destructor for a struct node_dtor(Generics, @struct_dtor, def_id, @path), node_block(blk), node_struct_ctor(@struct_def, @item, @path), + node_callee_scope(@expr) } pub type map = @mut HashMap<node_id, ast_node>; @@ -104,7 +104,6 @@ pub type map = @mut HashMap<node_id, ast_node>; pub struct Ctx { map: map, path: path, - local_id: uint, diag: @span_handler, } @@ -120,9 +119,8 @@ pub fn mk_ast_map_visitor() -> vt { visit_expr: map_expr, visit_stmt: map_stmt, visit_fn: map_fn, - visit_local: map_local, - visit_arm: map_arm, visit_block: map_block, + visit_pat: map_pat, .. *visit::default_visitor() }); } @@ -131,7 +129,6 @@ pub fn map_crate(diag: @span_handler, c: @crate) -> map { let cx = @mut Ctx { map: @mut HashMap::new(), path: ~[], - local_id: 0u, diag: diag, }; visit::visit_crate(c, cx, mk_ast_map_visitor()); @@ -154,7 +151,6 @@ pub fn map_decoded_item(diag: @span_handler, let cx = @mut Ctx { map: map, path: copy path, - local_id: 0, diag: diag, }; let v = mk_ast_map_visitor(); @@ -189,9 +185,7 @@ pub fn map_fn( v: visit::vt<@mut Ctx> ) { for decl.inputs.each |a| { - cx.map.insert(a.id, - node_arg(/* FIXME (#2543) */ copy *a, cx.local_id)); - cx.local_id += 1u; + cx.map.insert(a.id, node_arg); } match *fk { visit::fk_dtor(generics, ref attrs, self_id, parent_id) => { @@ -222,33 +216,22 @@ pub fn map_block(b: &blk, cx: @mut Ctx, v: visit::vt<@mut Ctx>) { visit::visit_block(b, cx, v); } -pub fn number_pat(cx: @mut Ctx, pat: @pat) { - do ast_util::walk_pat(pat) |p| { - match p.node { - pat_ident(*) => { - cx.map.insert(p.id, node_local(cx.local_id)); - cx.local_id += 1u; - } - _ => () +pub fn map_pat(pat: @pat, cx: @mut Ctx, v: visit::vt<@mut Ctx>) { + match pat.node { + pat_ident(_, path, _) => { + // Note: this is at least *potentially* a pattern... + cx.map.insert(pat.id, node_local(ast_util::path_to_ident(path))); } - }; -} - -pub fn map_local(loc: @local, cx: @mut Ctx, v: visit::vt<@mut Ctx>) { - number_pat(cx, loc.node.pat); - visit::visit_local(loc, cx, v); -} + _ => () + } -pub fn map_arm(arm: &arm, cx: @mut Ctx, v: visit::vt<@mut Ctx>) { - number_pat(cx, arm.pats[0]); - visit::visit_arm(arm, cx, v); + visit::visit_pat(pat, cx, v); } pub fn map_method(impl_did: def_id, impl_path: @path, m: @method, cx: @mut Ctx) { cx.map.insert(m.id, node_method(m, impl_did, impl_path)); - cx.map.insert(m.self_id, node_local(cx.local_id)); - cx.local_id += 1u; + cx.map.insert(m.self_id, node_local(special_idents::self_)); } pub fn map_item(i: @item, cx: @mut Ctx, v: visit::vt<@mut Ctx>) { @@ -317,6 +300,7 @@ pub fn map_item(i: @item, cx: @mut Ctx, v: visit::vt<@mut Ctx>) { } _ => () } + match i.node { item_mod(_) | item_foreign_mod(_) => { cx.path.push(path_mod(i.ident)); @@ -352,6 +336,18 @@ pub fn map_struct_def( pub fn map_expr(ex: @expr, cx: @mut Ctx, v: visit::vt<@mut Ctx>) { cx.map.insert(ex.id, node_expr(ex)); + match ex.node { + // Expressions which are or might be calls: + ast::expr_call(*) | + ast::expr_method_call(*) | + ast::expr_index(*) | + ast::expr_binary(*) | + ast::expr_assign_op(*) | + ast::expr_unary(*) => { + cx.map.insert(ex.callee_id, node_callee_scope(ex)); + } + _ => {} + } visit::visit_expr(ex, cx, v); } @@ -401,15 +397,18 @@ pub fn node_id_to_str(map: map, id: node_id, itr: @ident_interner) -> ~str { Some(&node_expr(expr)) => { fmt!("expr %s (id=%?)", pprust::expr_to_str(expr, itr), id) } + Some(&node_callee_scope(expr)) => { + fmt!("callee_scope %s (id=%?)", pprust::expr_to_str(expr, itr), id) + } Some(&node_stmt(stmt)) => { fmt!("stmt %s (id=%?)", pprust::stmt_to_str(stmt, itr), id) } - Some(&node_arg(_, _)) => { // add more info here + Some(&node_arg) => { fmt!("arg (id=%?)", id) } - Some(&node_local(_)) => { // add more info here - fmt!("local (id=%?)", id) + Some(&node_local(ident)) => { + fmt!("local (id=%?, name=%s)", id, *itr.get(ident)) } Some(&node_dtor(*)) => { // add more info here fmt!("node_dtor (id=%?)", id) |
