提交 7e43a31f 编写于 作者: P Patrick Walton

rustc: Move the interner to a new module intended to be used for general data structures

上级 02b995f4
......@@ -10,7 +10,7 @@
import driver::session::session;
import util::common;
import util::common::new_str_hash;
import util::interner;
import util::data::interner;
state type reader = state obj {
fn is_eof() -> bool;
......@@ -800,7 +800,7 @@ fn read_block_comment(&reader rdr) -> cmnt {
fn gather_comments(session sess, str path) -> vec[cmnt] {
auto srdr = io::file_reader(path);
auto itr = @interner::mk_interner[str](str::hash, str::eq);
auto itr = @interner::mk[str](str::hash, str::eq);
auto rdr = new_reader(sess, srdr, codemap::new_filemap(path, 0u), itr);
let vec[cmnt] comments = [];
while (!rdr.is_eof()) {
......
......@@ -11,7 +11,7 @@
import util::common::filename;
import util::common::span;
import util::common::new_str_hash;
import util::interner;
import util::data::interner;
tag restriction {
UNRESTRICTED;
......@@ -165,7 +165,7 @@ fn next_ann_num() -> uint {
auto srdr = io::file_reader(path);
auto filemap = codemap::new_filemap(path, pos);
vec::push[codemap::filemap](sess.get_codemap().files, filemap);
auto itr = @interner::mk_interner[str](str::hash, str::eq);
auto itr = @interner::mk[str](str::hash, str::eq);
auto rdr = lexer::new_reader(sess, srdr, filemap, itr);
// Make sure npos points at first actual token:
lexer::consume_any_whitespace(rdr);
......
import util::common::ty_mach;
import util::common::ty_mach_to_str;
import util::common::new_str_hash;
import util::interner;
import util::data::interner;
import std::int;
import std::uint;
import std::str;
......
......@@ -34,7 +34,7 @@
import util::common::span;
import middle::tstate::ann::ts_ann;
import util::interner;
import util::data::interner;
// Data types
......@@ -232,7 +232,7 @@ fn mk_ctxt(session::session s, resolve::def_map dm) -> ctxt {
common::new_def_hash[ty::ty_param_count_and_ty]();
auto items = common::new_def_hash[any_item]();
auto ts = @interner::mk_interner[raw_t](hash_raw_ty, eq_raw_ty);
auto ts = @interner::mk[raw_t](hash_raw_ty, eq_raw_ty);
auto cx =
rec(ts = ts,
......
......@@ -62,7 +62,7 @@ mod driver {
mod util {
mod common;
mod interner;
mod data;
}
auth front::creader::load_crate = unsafe;
......
......@@ -11,32 +11,34 @@
import std::option::none;
import std::option::some;
type interner[T] = rec(
hashmap[T,uint] map,
mutable vec[T] vect,
hashfn[T] hasher,
eqfn[T] eqer
);
mod interner {
type interner[T] = rec(
hashmap[T,uint] map,
mutable vec[T] vect,
hashfn[T] hasher,
eqfn[T] eqer
);
fn mk_interner[T](hashfn[T] hasher, eqfn[T] eqer) -> interner[T] {
auto m = map::mk_hashmap[T,uint](hasher, eqer);
let vec[T] vect = [];
ret rec(map=m, mutable vect=vect, hasher=hasher, eqer=eqer);
}
fn mk[T](hashfn[T] hasher, eqfn[T] eqer) -> interner[T] {
auto m = map::mk_hashmap[T,uint](hasher, eqer);
let vec[T] vect = [];
ret rec(map=m, mutable vect=vect, hasher=hasher, eqer=eqer);
}
fn intern[T](&interner[T] itr, &T val) -> uint {
alt (itr.map.find(val)) {
case (some[uint](?idx)) { ret idx; }
case (none[uint]) {
auto new_idx = vec::len[T](itr.vect);
itr.map.insert(val, new_idx);
itr.vect += [val];
ret new_idx;
fn intern[T](&interner[T] itr, &T val) -> uint {
alt (itr.map.find(val)) {
case (some[uint](?idx)) { ret idx; }
case (none[uint]) {
auto new_idx = vec::len[T](itr.vect);
itr.map.insert(val, new_idx);
itr.vect += [val];
ret new_idx;
}
}
}
}
fn get[T](&interner[T] itr, uint idx) -> T {
ret itr.vect.(idx);
fn get[T](&interner[T] itr, uint idx) -> T {
ret itr.vect.(idx);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册