Convert misc compiler bits to istrs. Issue #855

This commit is contained in:
Brian Anderson 2011-08-27 18:01:52 -07:00
parent cffd9b8044
commit 5f57a508af
12 changed files with 93 additions and 91 deletions

View file

@ -112,44 +112,45 @@ fn type_and_kind(tcx: &ty::ctxt, e: &@ast::expr) ->
}
fn need_expr_kind(tcx: &ty::ctxt, e: &@ast::expr, k_need: ast::kind,
descr: &str) {
descr: &istr) {
let tk = type_and_kind(tcx, e);
log #fmt["for %s: want %s type, got %s type %s", descr,
log #fmt["for %s: want %s type, got %s type %s", istr::to_estr(descr),
kind_to_str(k_need), kind_to_str(tk.kind),
istr::to_estr(util::ppaux::ty_to_str(tcx, tk.ty))];
if !kind_lteq(k_need, tk.kind) {
let s =
#fmt["mismatched kinds for %s: needed %s type, got %s type %s",
descr, kind_to_str(k_need), kind_to_str(tk.kind),
istr::to_estr(descr), kind_to_str(k_need),
kind_to_str(tk.kind),
istr::to_estr(util::ppaux::ty_to_str(tcx, tk.ty))];
tcx.sess.span_err(e.span, istr::from_estr(s));
}
}
fn need_shared_lhs_rhs(tcx: &ty::ctxt, a: &@ast::expr, b: &@ast::expr,
op: &str) {
need_expr_kind(tcx, a, ast::kind_shared, op + " lhs");
need_expr_kind(tcx, b, ast::kind_shared, op + " rhs");
op: &istr) {
need_expr_kind(tcx, a, ast::kind_shared, op + ~" lhs");
need_expr_kind(tcx, b, ast::kind_shared, op + ~" rhs");
}
fn check_expr(tcx: &ty::ctxt, e: &@ast::expr) {
alt e.node {
ast::expr_move(a, b) { need_shared_lhs_rhs(tcx, a, b, "<-"); }
ast::expr_assign(a, b) { need_shared_lhs_rhs(tcx, a, b, "="); }
ast::expr_assign_op(_, a, b) { need_shared_lhs_rhs(tcx, a, b, "op="); }
ast::expr_swap(a, b) { need_shared_lhs_rhs(tcx, a, b, "<->"); }
ast::expr_move(a, b) { need_shared_lhs_rhs(tcx, a, b, ~"<-"); }
ast::expr_assign(a, b) { need_shared_lhs_rhs(tcx, a, b, ~"="); }
ast::expr_assign_op(_, a, b) { need_shared_lhs_rhs(tcx, a, b, ~"op="); }
ast::expr_swap(a, b) { need_shared_lhs_rhs(tcx, a, b, ~"<->"); }
ast::expr_copy(a) {
need_expr_kind(tcx, a, ast::kind_shared, "'copy' operand");
need_expr_kind(tcx, a, ast::kind_shared, ~"'copy' operand");
}
ast::expr_ret(option::some(a)) {
need_expr_kind(tcx, a, ast::kind_shared, "'ret' operand");
need_expr_kind(tcx, a, ast::kind_shared, ~"'ret' operand");
}
ast::expr_be(a) {
need_expr_kind(tcx, a, ast::kind_shared, "'be' operand");
need_expr_kind(tcx, a, ast::kind_shared, ~"'be' operand");
}
ast::expr_fail(option::some(a)) {
need_expr_kind(tcx, a, ast::kind_shared, "'fail' operand");
need_expr_kind(tcx, a, ast::kind_shared, ~"'fail' operand");
}
ast::expr_call(callee, _) {
let tpt = ty::expr_ty_params_and_ty(tcx, callee);

View file

@ -58,9 +58,9 @@ fn variant_opt(ccx: &@crate_ctxt, pat_id: ast::node_id) -> opt {
}
type bind_map = [{ident: ast::ident, val: ValueRef}];
fn assoc(key: str, list: &bind_map) -> option::t<ValueRef> {
fn assoc(key: &istr, list: &bind_map) -> option::t<ValueRef> {
for elt: {ident: ast::ident, val: ValueRef} in list {
if istr::eq(elt.ident, istr::from_estr(key)) { ret some(elt.val); }
if istr::eq(elt.ident, key) { ret some(elt.val); }
}
ret none;
}
@ -304,7 +304,7 @@ fn compile_submatch(bcx: @block_ctxt, m: &match, vals: [ValueRef],
// the actual arm block.
for each @{key, val} in data.id_map.items() {
bcx.fcx.lllocals.insert
(val, option::get(assoc(istr::to_estr(key),
(val, option::get(assoc(key,
m[0].bound)));
}
let {bcx: guard_bcx, val: guard_val} =
@ -474,7 +474,7 @@ fn make_phi_bindings(bcx: &@block_ctxt, map: &[exit_node],
let vals = [];
for ex: exit_node in map {
if ex.to as uint == our_block {
alt assoc(istr::to_estr(item.key), ex.bound) {
alt assoc(item.key, ex.bound) {
some(val) { llbbs += [ex.from]; vals += [val]; }
none. { }
}

View file

@ -243,7 +243,7 @@ fn method_ty_to_fn_ty(cx: &ctxt, m: method) -> t {
// Never construct these manually. These are interned.
type raw_t =
{struct: sty,
cname: option::t<str>,
cname: option::t<istr>,
hash: uint,
has_params: bool,
has_vars: bool};
@ -427,8 +427,8 @@ fn mk_ctxt(s: session::session, dm: resolve::def_map,
// Type constructors
fn mk_raw_ty(cx: &ctxt, st: &sty, _in_cname: &option::t<str>) -> @raw_t {
let cname = none;
fn mk_raw_ty(cx: &ctxt, st: &sty, _in_cname: &option::t<istr>) -> @raw_t {
let cname: option::t<istr> = none;
let h = hash_type_info(st, cname);
let has_params: bool = false;
let has_vars: bool = false;
@ -505,11 +505,11 @@ fn mk_raw_ty(cx: &ctxt, st: &sty, _in_cname: &option::t<str>) -> @raw_t {
has_vars: has_vars};
}
fn intern(cx: &ctxt, st: &sty, cname: &option::t<str>) {
fn intern(cx: &ctxt, st: &sty, cname: &option::t<istr>) {
interner::intern(*cx.ts, mk_raw_ty(cx, st, cname));
}
fn gen_ty_full(cx: &ctxt, st: &sty, cname: &option::t<str>) -> t {
fn gen_ty_full(cx: &ctxt, st: &sty, cname: &option::t<istr>) -> t {
let raw_type = mk_raw_ty(cx, st, cname);
ret interner::intern(*cx.ts, raw_type);
}
@ -617,7 +617,7 @@ fn struct(cx: &ctxt, typ: t) -> sty {
// Returns the canonical name of the given type.
fn cname(cx: &ctxt, typ: t) -> option::t<str> {
fn cname(cx: &ctxt, typ: t) -> option::t<istr> {
ret interner::get(*cx.ts, typ).cname;
}
@ -794,7 +794,7 @@ fn fold_ty(cx: &ctxt, fld: fold_mode, ty_0: t) -> t {
// Type utilities
fn rename(cx: &ctxt, typ: t, new_cname: str) -> t {
fn rename(cx: &ctxt, typ: t, new_cname: &istr) -> t {
ret gen_ty_full(cx, struct(cx, typ), some(new_cname));
}
@ -1538,11 +1538,11 @@ fn hash_type_structure(st: &sty) -> uint {
}
}
fn hash_type_info(st: &sty, cname_opt: &option::t<str>) -> uint {
fn hash_type_info(st: &sty, cname_opt: &option::t<istr>) -> uint {
let h = hash_type_structure(st);
alt cname_opt {
none. {/* no-op */ }
some(s) { h += h << 5u + str::hash(s); }
some(s) { h += h << 5u + istr::hash(s); }
}
ret h;
}
@ -1606,7 +1606,7 @@ fn eq_raw_ty(a: &@raw_t, b: &@raw_t) -> bool {
none. { alt b.cname { none. {/* ok */ } _ { ret false; } } }
some(s_a) {
alt b.cname {
some(s_b) { if !str::eq(s_a, s_b) { ret false; } }
some(s_b) { if !istr::eq(s_a, s_b) { ret false; } }
_ { ret false; }
}
}

View file

@ -417,7 +417,7 @@ fn ast_ty_to_ty(tcx: &ty::ctxt, getter: &ty_getter, ast_ty: &@ast::ty) ->
alt cname {
none. {/* no-op */ }
some(cname_str) {
typ = ty::rename(tcx, typ, istr::to_estr(cname_str));
typ = ty::rename(tcx, typ, cname_str);
}
}
tcx.ast_ty_to_ty_cache.insert(ast_ty, some(typ));
@ -629,7 +629,7 @@ mod collect {
ty_params: &[ast::ty_param]) -> ty::ty_param_kinds_and_ty {
let methods = get_obj_method_types(cx, ob);
let t_obj = ty::mk_obj(cx.tcx, ty::sort_methods(methods));
t_obj = ty::rename(cx.tcx, t_obj, istr::to_estr(id));
t_obj = ty::rename(cx.tcx, t_obj, id);
ret {kinds: ty_param_kinds(ty_params), ty: t_obj};
}
fn ty_of_obj_ctor(cx: @ctxt, id: &ast::ident, ob: &ast::_obj,