rustc: Move new_def_hash to ast_util
This commit is contained in:
parent
8ec467d521
commit
4756556748
@ -225,6 +225,23 @@ fn hash_ty(&&t: @ty) -> uint {
|
||||
ret res;
|
||||
}
|
||||
|
||||
fn def_eq(a: ast::def_id, b: ast::def_id) -> bool {
|
||||
ret a.crate == b.crate && a.node == b.node;
|
||||
}
|
||||
|
||||
fn hash_def(d: ast::def_id) -> uint {
|
||||
let mut h = 5381u;
|
||||
h = (h << 5u) + h ^ (d.crate as uint);
|
||||
h = (h << 5u) + h ^ (d.node as uint);
|
||||
ret h;
|
||||
}
|
||||
|
||||
fn new_def_hash<V: copy>() -> std::map::hashmap<ast::def_id, V> {
|
||||
let hasher: std::map::hashfn<ast::def_id> = hash_def;
|
||||
let eqer: std::map::eqfn<ast::def_id> = def_eq;
|
||||
ret std::map::hashmap::<ast::def_id, V>(hasher, eqer);
|
||||
}
|
||||
|
||||
fn hash_def_id(&&id: def_id) -> uint {
|
||||
(id.crate as uint << 16u) + (id.node as uint)
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
import std::map;
|
||||
import std::map::hashmap;
|
||||
import syntax::{ast, attr};
|
||||
import syntax::ast_util::new_def_hash;
|
||||
import util::common::*;
|
||||
|
||||
export cstore::{};
|
||||
|
@ -137,7 +137,7 @@ import middle::ty;
|
||||
import syntax::{ast, visit};
|
||||
import syntax::codemap::span;
|
||||
import syntax::print::pprust;
|
||||
import util::common::new_def_hash;
|
||||
import syntax::ast_util::new_def_hash;
|
||||
|
||||
import std::list;
|
||||
import std::list::list;
|
||||
|
@ -1,7 +1,7 @@
|
||||
import syntax::{ast, ast_util, codemap, ast_map};
|
||||
import syntax::ast::*;
|
||||
import ast::{ident, fn_ident, def, def_id, node_id};
|
||||
import syntax::ast_util::{local_def, def_id_of_def,
|
||||
import syntax::ast_util::{local_def, def_id_of_def, new_def_hash,
|
||||
class_item_ident, path_to_ident};
|
||||
import pat_util::*;
|
||||
|
||||
@ -73,10 +73,10 @@ type ext_hash = hashmap<{did: def_id, ident: str, ns: namespace}, def>;
|
||||
fn new_ext_hash() -> ext_hash {
|
||||
type key = {did: def_id, ident: str, ns: namespace};
|
||||
fn hash(v: key) -> uint {
|
||||
str::hash(v.ident) + util::common::hash_def(v.did) + v.ns as uint
|
||||
str::hash(v.ident) + ast_util::hash_def(v.did) + v.ns as uint
|
||||
}
|
||||
fn eq(v1: key, v2: key) -> bool {
|
||||
ret util::common::def_eq(v1.did, v2.did) &&
|
||||
ret ast_util::def_eq(v1.did, v2.did) &&
|
||||
str::eq(v1.ident, v2.ident) && v1.ns == v2.ns;
|
||||
}
|
||||
std::map::hashmap(hash, {|a, b| a == b})
|
||||
|
@ -5492,10 +5492,10 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
|
||||
discrims: ast_util::new_def_id_hash::<ValueRef>(),
|
||||
discrim_symbols: int_hash::<str>(),
|
||||
tydescs: ty::new_ty_hash(),
|
||||
external: util::common::new_def_hash(),
|
||||
external: ast_util::new_def_hash(),
|
||||
monomorphized: map::hashmap(hash_mono_id, {|a, b| a == b}),
|
||||
monomorphizing: ast_util::new_def_id_hash(),
|
||||
type_use_cache: util::common::new_def_hash(),
|
||||
type_use_cache: ast_util::new_def_hash(),
|
||||
vtables: map::hashmap(hash_mono_id, {|a, b| a == b}),
|
||||
const_cstr_cache: map::str_hash(),
|
||||
module_data: str_hash::<ValueRef>(),
|
||||
|
@ -11,7 +11,7 @@ import back::abi;
|
||||
import middle::ty;
|
||||
import middle::ty::field;
|
||||
import syntax::ast;
|
||||
import syntax::ast_util::dummy_sp;
|
||||
import syntax::ast_util::{dummy_sp, new_def_hash};
|
||||
import syntax::util::interner;
|
||||
import util::common;
|
||||
import syntax::codemap::span;
|
||||
@ -273,7 +273,7 @@ fn mk_ctxt(llmod: ModuleRef) -> ctxt {
|
||||
|
||||
ret {mut next_tag_id: 0u16,
|
||||
pad: 0u16,
|
||||
tag_id_to_index: common::new_def_hash(),
|
||||
tag_id_to_index: new_def_hash(),
|
||||
tag_order: dvec(),
|
||||
resources: interner::mk(hash_res_info, {|a, b| a == b}),
|
||||
llshapetablesty: llshapetablesty,
|
||||
|
@ -3,7 +3,6 @@ import pat_util::*;
|
||||
import syntax::ast::*;
|
||||
import syntax::ast_util::*;
|
||||
import syntax::visit;
|
||||
import util::common::new_def_hash;
|
||||
import syntax::codemap::span;
|
||||
import syntax::ast_util::respan;
|
||||
import driver::session::session;
|
||||
|
@ -9,7 +9,7 @@ import pat_util::*;
|
||||
import syntax::ast::*;
|
||||
import syntax::ast_util::*;
|
||||
import syntax::visit;
|
||||
import util::common::{new_def_hash, log_expr, field_exprs,
|
||||
import util::common::{log_expr, field_exprs,
|
||||
has_nonlocal_exits, log_stmt};
|
||||
import syntax::codemap::span;
|
||||
import driver::session::session;
|
||||
|
@ -6,7 +6,8 @@ import session::session;
|
||||
import syntax::{ast, ast_map};
|
||||
import syntax::ast::*;
|
||||
import syntax::ast_util;
|
||||
import syntax::ast_util::{is_local, local_def, split_class_items};
|
||||
import syntax::ast_util::{is_local, local_def, split_class_items,
|
||||
new_def_hash};
|
||||
import syntax::codemap::span;
|
||||
import metadata::csearch;
|
||||
import util::common::*;
|
||||
@ -478,7 +479,7 @@ fn mk_ctxt(s: session::session, dm: resolve::def_map, amap: ast_map::map,
|
||||
items: amap,
|
||||
intrinsic_ifaces: map::str_hash(),
|
||||
freevars: freevars,
|
||||
tcache: new_def_hash(),
|
||||
tcache: ast_util::new_def_hash(),
|
||||
rcache: mk_rcache(),
|
||||
short_names_cache: new_ty_hash(),
|
||||
needs_drop_cache: new_ty_hash(),
|
||||
@ -2524,7 +2525,7 @@ fn enum_variant_with_id(cx: ctxt, enum_id: ast::def_id,
|
||||
let mut i = 0u;
|
||||
while i < vec::len::<variant_info>(*variants) {
|
||||
let variant = variants[i];
|
||||
if def_eq(variant.id, variant_id) { ret variant; }
|
||||
if ast_util::def_eq(variant.id, variant_id) { ret variant; }
|
||||
i += 1u;
|
||||
}
|
||||
cx.sess.bug("enum_variant_with_id(): no variant exists with that ID");
|
||||
|
@ -25,23 +25,6 @@ fn indenter() -> _indenter {
|
||||
|
||||
type flag = hashmap<str, ()>;
|
||||
|
||||
fn def_eq(a: ast::def_id, b: ast::def_id) -> bool {
|
||||
ret a.crate == b.crate && a.node == b.node;
|
||||
}
|
||||
|
||||
fn hash_def(d: ast::def_id) -> uint {
|
||||
let mut h = 5381u;
|
||||
h = (h << 5u) + h ^ (d.crate as uint);
|
||||
h = (h << 5u) + h ^ (d.node as uint);
|
||||
ret h;
|
||||
}
|
||||
|
||||
fn new_def_hash<V: copy>() -> std::map::hashmap<ast::def_id, V> {
|
||||
let hasher: std::map::hashfn<ast::def_id> = hash_def;
|
||||
let eqer: std::map::eqfn<ast::def_id> = def_eq;
|
||||
ret std::map::hashmap::<ast::def_id, V>(hasher, eqer);
|
||||
}
|
||||
|
||||
fn field_expr(f: ast::field) -> @ast::expr { ret f.node.expr; }
|
||||
|
||||
fn field_exprs(fields: [ast::field]) -> [@ast::expr] {
|
||||
|
@ -5,7 +5,6 @@ import std::map::hashmap;
|
||||
import std::list;
|
||||
import syntax::ast;
|
||||
import syntax::ast_util;
|
||||
import rustc::util::common;
|
||||
import syntax::ast_map;
|
||||
import syntax::visit;
|
||||
import syntax::codemap;
|
||||
@ -69,7 +68,7 @@ fn from_assoc_list<K:copy, V:copy>(
|
||||
fn from_def_assoc_list<V:copy>(
|
||||
list: [(ast::def_id, V)]
|
||||
) -> map::hashmap<ast::def_id, V> {
|
||||
from_assoc_list(list, bind common::new_def_hash())
|
||||
from_assoc_list(list, bind ast_util::new_def_hash())
|
||||
}
|
||||
|
||||
fn from_str_assoc_list<V:copy>(
|
||||
@ -80,7 +79,7 @@ fn from_str_assoc_list<V:copy>(
|
||||
|
||||
fn build_reexport_def_set(srv: astsrv::srv) -> def_set {
|
||||
let assoc_list = astsrv::exec(srv) {|ctxt|
|
||||
let def_set = common::new_def_hash();
|
||||
let def_set = ast_util::new_def_hash();
|
||||
for ctxt.exp_map.each {|_id, defs|
|
||||
for defs.each {|def|
|
||||
if def.reexp {
|
||||
@ -120,7 +119,7 @@ fn build_reexport_def_map(
|
||||
let ctxt = {
|
||||
srv: srv,
|
||||
def_set: def_set,
|
||||
def_map: common::new_def_hash()
|
||||
def_map: ast_util::new_def_hash()
|
||||
};
|
||||
|
||||
// FIXME: Do a parallel fold
|
||||
@ -289,7 +288,7 @@ fn for_each_reexported_impl(
|
||||
}
|
||||
|
||||
fn all_impls(m: ast::_mod) -> map::set<ast::def_id> {
|
||||
let all_impls = common::new_def_hash();
|
||||
let all_impls = ast_util::new_def_hash();
|
||||
for m.items.each {|item|
|
||||
alt item.node {
|
||||
ast::item_impl(_, _, _, _, _) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user