diff options
| author | Marijn Haverbeke <marijnh@gmail.com> | 2012-01-09 16:24:53 +0100 |
|---|---|---|
| committer | Marijn Haverbeke <marijnh@gmail.com> | 2012-01-11 20:33:44 +0100 |
| commit | 15744210e7913c6607bf033f4ffd53d36de116e6 (patch) | |
| tree | 9fdfa3473a37d7badf904dc58c220f15b90cf990 /src/comp | |
| parent | c68345e57e82e7233e0f875bd416f46e1f8859e1 (diff) | |
| download | rust-15744210e7913c6607bf033f4ffd53d36de116e6.tar.gz rust-15744210e7913c6607bf033f4ffd53d36de116e6.zip | |
Implement std::map as an iface/impl instead of an obj
Diffstat (limited to 'src/comp')
| -rw-r--r-- | src/comp/metadata/creader.rs | 14 | ||||
| -rw-r--r-- | src/comp/middle/ast_map.rs | 80 | ||||
| -rw-r--r-- | src/comp/middle/tstate/auxiliary.rs | 6 | ||||
| -rw-r--r-- | src/comp/middle/tstate/collect_locals.rs | 2 | ||||
| -rw-r--r-- | src/comp/middle/tstate/pre_post_conditions.rs | 2 |
5 files changed, 14 insertions, 90 deletions
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::<int>(), - mutable next_crate_num: 1}; + let e = @{sess: sess, + crate_cache: std::map::new_str_hash::<int>(), + 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<str, int>, - mutable next_crate_num: ast::crate_num}; +type env = @{sess: session::session, + crate_cache: hashmap<str, int>, + 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<node_id, ast_node>; +type map = std::map::map<node_id, ast_node>; 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::<ast_node>(), + 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<V: copy>() -> std::map::hashmap<int, V> { - 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<K: copy, V: copy>(key_idx: fn(K) -> uint, - idx_key: fn(uint) -> K) - -> std::map::hashmap<K, V> { - - obj adapter<K: copy, V: copy>(map: smallintmap::smallintmap<V>, - 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<V> { - ret smallintmap::find(map, key_idx(key)); - } - - fn remove(_key: K) -> option::t<V> { 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::<V>(); - 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<tsconstr>; type norm_constraint = {bit_num: uint, c: sp_constr}; -type constr_map = @std::map::hashmap<def_id, constraint>; +type constr_map = std::map::hashmap<def_id, constraint>; /* 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<node_id, fn_info>; +type fn_info_map = std::map::hashmap<node_id, fn_info>; 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::<fn_info>()}; + ret {tcx: cx, node_anns: @mutable na, fm: new_int_hash::<fn_info>()}; } /* 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::<constraint>(); + let res_map = new_def_hash::<constraint>(); 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::<constraint>(), + {constrs: new_def_hash::<constraint>(), num_constraints: 0u, cf: return_val, i_return: ninit(0, ""), |
