From 15744210e7913c6607bf033f4ffd53d36de116e6 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Mon, 9 Jan 2012 16:24:53 +0100 Subject: Implement std::map as an iface/impl instead of an obj --- src/comp/metadata/creader.rs | 14 ++--- src/comp/middle/ast_map.rs | 80 +-------------------------- src/comp/middle/tstate/auxiliary.rs | 6 +- src/comp/middle/tstate/collect_locals.rs | 2 +- src/comp/middle/tstate/pre_post_conditions.rs | 2 +- 5 files changed, 14 insertions(+), 90 deletions(-) (limited to 'src/comp') diff --git a/src/comp/metadata/creader.rs b/src/comp/metadata/creader.rs index 167e6bbcbab..08df19b54e9 100644 --- a/src/comp/metadata/creader.rs +++ b/src/comp/metadata/creader.rs @@ -20,10 +20,9 @@ export list_file_metadata; // Traverses an AST, reading all the information about use'd crates and native // libraries necessary for later resolving, typechecking, linking, etc. fn read_crates(sess: session::session, crate: ast::crate) { - let e = - @{sess: sess, - crate_cache: @std::map::new_str_hash::(), - mutable next_crate_num: 1}; + let e = @{sess: sess, + crate_cache: std::map::new_str_hash::(), + mutable next_crate_num: 1}; let v = visit::mk_simple_visitor(@{visit_view_item: bind visit_view_item(e, _), @@ -32,10 +31,9 @@ fn read_crates(sess: session::session, crate: ast::crate) { visit::visit_crate(crate, (), v); } -type env = - @{sess: session::session, - crate_cache: @hashmap, - mutable next_crate_num: ast::crate_num}; +type env = @{sess: session::session, + crate_cache: hashmap, + mutable next_crate_num: ast::crate_num}; fn visit_view_item(e: env, i: @ast::view_item) { alt i.node { diff --git a/src/comp/middle/ast_map.rs b/src/comp/middle/ast_map.rs index b5e53ab305a..c9382589d73 100644 --- a/src/comp/middle/ast_map.rs +++ b/src/comp/middle/ast_map.rs @@ -1,5 +1,5 @@ import option; -import std::smallintmap; +import std::map; import syntax::ast::*; import syntax::ast_util; import syntax::{visit, codemap}; @@ -18,14 +18,11 @@ tag ast_node { node_res_ctor(@item); } -type map = std::map::hashmap; +type map = std::map::map; type ctx = @{map: map, mutable local_id: uint}; fn map_crate(c: crate) -> map { - // FIXME: This is using an adapter to convert the smallintmap - // interface to the hashmap interface. It would be better to just - // convert everything to use the smallintmap. - let cx = @{map: new_smallintmap_int_adapter::(), + let cx = @{map: std::map::new_int_hash(), mutable local_id: 0u}; let v_map = visit::mk_simple_visitor @@ -98,77 +95,6 @@ fn map_expr(cx: ctx, ex: @expr) { } } -fn new_smallintmap_int_adapter() -> std::map::hashmap { - let key_idx = fn (&&key: int) -> uint { key as uint }; - let idx_key = fn (idx: uint) -> int { idx as int }; - ret new_smallintmap_adapter(key_idx, idx_key); -} - -// This creates an object with the hashmap interface backed -// by the smallintmap type, because I don't want to go through -// the entire codebase adapting all the callsites to the different -// interface. -// FIXME: hashmap and smallintmap should support the same interface. -fn new_smallintmap_adapter(key_idx: fn(K) -> uint, - idx_key: fn(uint) -> K) - -> std::map::hashmap { - - obj adapter(map: smallintmap::smallintmap, - key_idx: fn(K) -> uint, - idx_key: fn(uint) -> K) { - - fn size() -> uint { fail } - - fn insert(key: K, value: V) -> bool { - let exists = smallintmap::contains_key(map, key_idx(key)); - smallintmap::insert(map, key_idx(key), value); - ret !exists; - } - - fn contains_key(key: K) -> bool { - ret smallintmap::contains_key(map, key_idx(key)); - } - - fn get(key: K) -> V { ret smallintmap::get(map, key_idx(key)); } - - fn find(key: K) -> option::t { - ret smallintmap::find(map, key_idx(key)); - } - - fn remove(_key: K) -> option::t { fail } - - fn rehash() { fail } - - fn items(it: block(K, V)) { - let idx = 0u; - for item in map.v { - alt item { - option::some(elt) { - it(idx_key(idx), elt); - } - option::none. { } - } - idx += 1u; - } - } - fn keys(it: block(K)) { - let idx = 0u; - for item in map.v { - if item != option::none { it(idx_key(idx)); } - idx += 1u; - } - } - fn values(it: block(V)) { - for item in map.v { - alt item { option::some(elt) { it(elt); } _ {} } - } - } - } - - let map = smallintmap::mk::(); - ret adapter(map, key_idx, idx_key); -} - fn node_span(node: ast_node) -> codemap::span { alt node { node_item(item) { item.span } diff --git a/src/comp/middle/tstate/auxiliary.rs b/src/comp/middle/tstate/auxiliary.rs index 0b021bbeac4..de723dc16cc 100644 --- a/src/comp/middle/tstate/auxiliary.rs +++ b/src/comp/middle/tstate/auxiliary.rs @@ -218,7 +218,7 @@ type sp_constr = spanned; type norm_constraint = {bit_num: uint, c: sp_constr}; -type constr_map = @std::map::hashmap; +type constr_map = std::map::hashmap; /* Contains stuff that has to be computed up front */ /* For easy access, the fn_info stores two special constraints for each @@ -278,7 +278,7 @@ type node_ann_table = @mutable [mutable ts_ann]; /* mapping from function name to fn_info map */ -type fn_info_map = @std::map::hashmap; +type fn_info_map = std::map::hashmap; type fn_ctxt = {enclosing: fn_info, id: node_id, name: ident, ccx: crate_ctxt}; @@ -483,7 +483,7 @@ fn num_constraints(m: fn_info) -> uint { ret m.num_constraints; } fn new_crate_ctxt(cx: ty::ctxt) -> crate_ctxt { let na: [mutable ts_ann] = [mutable]; - ret {tcx: cx, node_anns: @mutable na, fm: @new_int_hash::()}; + ret {tcx: cx, node_anns: @mutable na, fm: new_int_hash::()}; } /* Use e's type to determine whether it returns. diff --git a/src/comp/middle/tstate/collect_locals.rs b/src/comp/middle/tstate/collect_locals.rs index 60c79468589..939197716b4 100644 --- a/src/comp/middle/tstate/collect_locals.rs +++ b/src/comp/middle/tstate/collect_locals.rs @@ -102,7 +102,7 @@ fn mk_fn_info(ccx: crate_ctxt, f_sp: span, id: node_id) { let name = visit::name_of_fn(fk); - let res_map = @new_def_hash::(); + let res_map = new_def_hash::(); let next: uint = 0u; let cx: ctxt = find_locals(ccx.tcx, fk, f_decl, f_body, f_sp, id); diff --git a/src/comp/middle/tstate/pre_post_conditions.rs b/src/comp/middle/tstate/pre_post_conditions.rs index e4d00120aac..244f696549e 100644 --- a/src/comp/middle/tstate/pre_post_conditions.rs +++ b/src/comp/middle/tstate/pre_post_conditions.rs @@ -44,7 +44,7 @@ fn find_pre_post_item(ccx: crate_ctxt, i: item) { { // just bogus enclosing: - {constrs: @new_def_hash::(), + {constrs: new_def_hash::(), num_constraints: 0u, cf: return_val, i_return: ninit(0, ""), -- cgit 1.4.1-3-g733a5