Convert std::int to istrs. Issue #855

This commit is contained in:
Brian Anderson
2011-08-23 21:17:20 -07:00
parent ee2a11eb4f
commit 53be480d20
20 changed files with 92 additions and 51 deletions

View File

@@ -27,6 +27,7 @@ import std::option;
import std::option::some; import std::option::some;
import std::option::none; import std::option::none;
import std::str; import std::str;
import std::istr;
import std::vec; import std::vec;
import std::int; import std::int;
import std::io; import std::io;
@@ -189,16 +190,18 @@ fn pretty_print_input(sess: session::session, cfg: ast::crate_cfg, input: str,
alt node { alt node {
pprust::node_item(s, item) { pprust::node_item(s, item) {
pp::space(s.s); pp::space(s.s);
pprust::synth_comment(s, int::to_str(item.id, 10u)); pprust::synth_comment(
s, istr::to_estr(int::to_str(item.id, 10u)));
} }
pprust::node_block(s, blk) { pprust::node_block(s, blk) {
pp::space(s.s); pp::space(s.s);
pprust::synth_comment(s, pprust::synth_comment(
"block " + int::to_str(blk.node.id, 10u)); s, istr::to_estr(~"block " + int::to_str(blk.node.id, 10u)));
} }
pprust::node_expr(s, expr) { pprust::node_expr(s, expr) {
pp::space(s.s); pp::space(s.s);
pprust::synth_comment(s, int::to_str(expr.id, 10u)); pprust::synth_comment(
s, istr::to_estr(int::to_str(expr.id, 10u)));
pprust::pclose(s); pprust::pclose(s);
} }
_ { } _ { }

View File

@@ -1,5 +1,6 @@
import std::vec; import std::vec;
import std::str; import std::str;
import std::istr;
import std::str::rustrt::sbuf; import std::str::rustrt::sbuf;
import llvm::ModuleRef; import llvm::ModuleRef;
@@ -976,7 +977,8 @@ fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) ->
7 { 7 {
ret "i" + std::int::str(llvm::LLVMGetIntTypeWidth(ty) as int); ret "i" + istr::to_estr(std::int::str(
llvm::LLVMGetIntTypeWidth(ty) as int));
} }
@@ -1020,7 +1022,7 @@ fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) ->
i += 1u; i += 1u;
if tout as int == ty as int { if tout as int == ty as int {
let n: uint = vec::len::<TypeRef>(outer0) - i; let n: uint = vec::len::<TypeRef>(outer0) - i;
ret "*\\" + std::int::str(n as int); ret "*\\" + istr::to_estr(std::int::str(n as int));
} }
} }
ret "*" + ret "*" +

View File

@@ -172,7 +172,10 @@ fn enc_sty(w: &io::writer, cx: &@ctxt, st: &ty::sty) {
for t: ty::t in tps { enc_ty(w, cx, t); } for t: ty::t in tps { enc_ty(w, cx, t); }
w.write_char(']'); w.write_char(']');
} }
ty::ty_var(id) { w.write_char('X'); w.write_str(int::str(id)); } ty::ty_var(id) {
w.write_char('X');
w.write_str(istr::to_estr(int::str(id)));
}
ty::ty_native(def) { ty::ty_native(def) {
w.write_char('E'); w.write_char('E');
w.write_str(cx.ds(def)); w.write_str(cx.ds(def));

View File

@@ -5,6 +5,7 @@ import std::map;
import std::map::*; import std::map::*;
import std::option; import std::option;
import std::int; import std::int;
import std::istr;
import std::option::*; import std::option::*;
import syntax::ast; import syntax::ast;
import syntax::ast_util; import syntax::ast_util;
@@ -146,7 +147,10 @@ fn annotate_freevars(sess: &session::session, def_map: &resolve::def_map,
fn get_freevar_info(tcx: &ty::ctxt, fid: ast::node_id) -> freevar_info { fn get_freevar_info(tcx: &ty::ctxt, fid: ast::node_id) -> freevar_info {
alt tcx.freevars.find(fid) { alt tcx.freevars.find(fid) {
none. { fail "get_freevars: " + int::str(fid) + " has no freevars"; } none. {
fail "get_freevars: " + istr::to_estr(int::str(fid))
+ " has no freevars";
}
some(d) { ret d; } some(d) { ret d; }
} }
} }

View File

@@ -63,7 +63,9 @@ import trans::type_of_fn_full;
import trans::drop_ty; import trans::drop_ty;
obj namegen(mutable i: int) { obj namegen(mutable i: int) {
fn next(prefix: str) -> str { i += 1; ret prefix + int::str(i); } fn next(prefix: str) -> str {
i += 1; ret prefix + istr::to_estr(int::str(i));
}
} }
type derived_tydesc_info = {lltydesc: ValueRef, escapes: bool}; type derived_tydesc_info = {lltydesc: ValueRef, escapes: bool};

View File

@@ -32,12 +32,12 @@ fn collect_ids_block(b: &blk, rs: @mutable [node_id]) { *rs += [b.node.id]; }
fn collect_ids_stmt(s: &@stmt, rs: @mutable [node_id]) { fn collect_ids_stmt(s: &@stmt, rs: @mutable [node_id]) {
alt s.node { alt s.node {
stmt_decl(_, id) { stmt_decl(_, id) {
log "node_id " + int::str(id); log ~"node_id " + int::str(id);
log_stmt(*s);; log_stmt(*s);;
*rs += [id]; *rs += [id];
} }
stmt_expr(_, id) { stmt_expr(_, id) {
log "node_id " + int::str(id); log ~"node_id " + int::str(id);
log_stmt(*s);; log_stmt(*s);;
*rs += [id]; *rs += [id];
} }
@@ -62,7 +62,7 @@ fn node_ids_in_fn(f: &_fn, tps: &[ty_param], sp: &span, i: &fn_ident,
fn init_vecs(ccx: &crate_ctxt, node_ids: &[node_id], len: uint) { fn init_vecs(ccx: &crate_ctxt, node_ids: &[node_id], len: uint) {
for i: node_id in node_ids { for i: node_id in node_ids {
log int::str(i) + " |-> " + istr::to_estr(uint::str(len)); log istr::to_estr(int::str(i) + ~" |-> " + uint::str(len));
add_node(ccx, i, empty_ann(len)); add_node(ccx, i, empty_ann(len));
} }
} }

View File

@@ -57,7 +57,7 @@ tag oper_type {
/* logging funs */ /* logging funs */
fn def_id_to_str(d: def_id) -> str { fn def_id_to_str(d: def_id) -> str {
ret int::str(d.crate) + "," + int::str(d.node); ret istr::to_estr(int::str(d.crate) + ~"," + int::str(d.node));
} }
fn comma_str(args: &[@constr_arg_use]) -> str { fn comma_str(args: &[@constr_arg_use]) -> str {
@@ -329,7 +329,8 @@ fn get_ts_ann(ccx: &crate_ctxt, i: node_id) -> option::t<ts_ann> {
fn node_id_to_ts_ann(ccx: &crate_ctxt, id: node_id) -> ts_ann { fn node_id_to_ts_ann(ccx: &crate_ctxt, id: node_id) -> ts_ann {
alt get_ts_ann(ccx, id) { alt get_ts_ann(ccx, id) {
none. { none. {
log_err "node_id_to_ts_ann: no ts_ann for node_id " + int::str(id); log_err "node_id_to_ts_ann: no ts_ann for node_id "
+ istr::to_estr(int::str(id));
fail; fail;
} }
some(t) { ret t; } some(t) { ret t; }
@@ -531,7 +532,8 @@ fn constraints_expr(cx: &ty::ctxt, e: @expr) -> [@ty::constr] {
fn node_id_to_def_upvar_strict(cx: &fn_ctxt, id: node_id) -> def { fn node_id_to_def_upvar_strict(cx: &fn_ctxt, id: node_id) -> def {
alt freevars::def_lookup(cx.ccx.tcx, cx.id, id) { alt freevars::def_lookup(cx.ccx.tcx, cx.id, id) {
none. { none. {
log_err "node_id_to_def: node_id " + int::str(id) + " has no def"; log_err "node_id_to_def: node_id "
+ istr::to_estr(int::str(id)) + " has no def";
fail; fail;
} }
some(d) { ret d; } some(d) { ret d; }
@@ -540,7 +542,8 @@ fn node_id_to_def_upvar_strict(cx: &fn_ctxt, id: node_id) -> def {
fn node_id_to_def_strict(cx: &ty::ctxt, id: node_id) -> def { fn node_id_to_def_strict(cx: &ty::ctxt, id: node_id) -> def {
alt cx.def_map.find(id) { alt cx.def_map.find(id) {
none. { none. {
log_err "node_id_to_def: node_id " + int::str(id) + " has no def"; log_err "node_id_to_def: node_id "
+ istr::to_estr(int::str(id)) + " has no def";
fail; fail;
} }
some(d) { ret d; } some(d) { ret d; }
@@ -601,7 +604,8 @@ fn match_args(fcx: &fn_ctxt, occs: &@mutable [pred_args],
fn def_id_for_constr(tcx: ty::ctxt, t: node_id) -> def_id { fn def_id_for_constr(tcx: ty::ctxt, t: node_id) -> def_id {
alt tcx.def_map.find(t) { alt tcx.def_map.find(t) {
none. { none. {
tcx.sess.bug("node_id_for_constr: bad node_id " + int::str(t)); tcx.sess.bug("node_id_for_constr: bad node_id "
+ istr::to_estr(int::str(t)));
} }
some(def_fn(i, _)) { ret i; } some(def_fn(i, _)) { ret i; }
_ { tcx.sess.bug("node_id_for_constr: pred is not a function"); } _ { tcx.sess.bug("node_id_for_constr: pred is not a function"); }

View File

@@ -1629,8 +1629,9 @@ fn node_id_to_ty_param_substs_opt_and_ty(cx: &ctxt, id: &ast::node_id) ->
alt smallintmap::find(*cx.node_types, id as uint) { alt smallintmap::find(*cx.node_types, id as uint) {
none. { none. {
cx.sess.bug("node_id_to_ty_param_substs_opt_and_ty() called on " + cx.sess.bug("node_id_to_ty_param_substs_opt_and_ty() called on " +
"an untyped node (" + std::int::to_str(id, 10u) + "an untyped node (" +
")"); istr::to_estr(std::int::to_str(id, 10u)) +
")");
} }
some(tpot) { ret tpot; } some(tpot) { ret tpot; }
} }

View File

@@ -37,6 +37,7 @@ import middle::ty::unify::fix_err;
import std::int; import std::int;
import std::vec; import std::vec;
import std::str; import std::str;
import std::istr;
import std::uint; import std::uint;
import std::map; import std::map;
import std::map::hashmap; import std::map::hashmap;
@@ -586,7 +587,10 @@ mod collect {
some(ast_map::node_native_item(native_item)) { some(ast_map::node_native_item(native_item)) {
tpt = ty_of_native_item(cx, native_item, ast::native_abi_cdecl); tpt = ty_of_native_item(cx, native_item, ast::native_abi_cdecl);
} }
_ { cx.tcx.sess.fatal("internal error " + std::int::str(id.node)); } _ {
cx.tcx.sess.fatal(
"internal error " + istr::to_estr(std::int::str(id.node)));
}
} }
ret tpt; ret tpt;
} }
@@ -2152,8 +2156,9 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr, unify: &unifier,
this_obj_sty = some(structure_of(fcx, expr.span, tpt.ty)); this_obj_sty = some(structure_of(fcx, expr.span, tpt.ty));
} }
none. { none. {
tcx.sess.bug("didn't find " + int::str(did.node) + tcx.sess.bug("didn't find " +
" in type cache"); istr::to_estr(int::str(did.node)) +
" in type cache");
} }
} }
} }

View File

@@ -7,6 +7,7 @@
*/ */
import std::vec; import std::vec;
import std::str; import std::str;
import std::istr;
import std::option; import std::option;
import std::option::none; import std::option::none;
import std::option::some; import std::option::some;
@@ -258,7 +259,10 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece],
} }
fn log_conv(c: conv) { fn log_conv(c: conv) {
alt c.param { alt c.param {
some(p) { log "param: " + std::int::to_str(p, 10u); } some(p) {
log "param: "
+ istr::to_estr(std::int::to_str(p, 10u));
}
_ { log "param: none"; } _ { log "param: none"; }
} }
for f: flag in c.flags { for f: flag in c.flags {
@@ -271,17 +275,21 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece],
} }
} }
alt c.width { alt c.width {
count_is(i) { log "width: count is " + std::int::to_str(i, 10u); } count_is(i) { log "width: count is "
+ istr::to_estr(std::int::to_str(i, 10u)); }
count_is_param(i) { count_is_param(i) {
log "width: count is param " + std::int::to_str(i, 10u); log "width: count is param "
+ istr::to_estr(std::int::to_str(i, 10u));
} }
count_is_next_param. { log "width: count is next param"; } count_is_next_param. { log "width: count is next param"; }
count_implied. { log "width: count is implied"; } count_implied. { log "width: count is implied"; }
} }
alt c.precision { alt c.precision {
count_is(i) { log "prec: count is " + std::int::to_str(i, 10u); } count_is(i) { log "prec: count is "
+ istr::to_estr(std::int::to_str(i, 10u)); }
count_is_param(i) { count_is_param(i) {
log "prec: count is param " + std::int::to_str(i, 10u); log "prec: count is param "
+ istr::to_estr(std::int::to_str(i, 10u));
} }
count_is_next_param. { log "prec: count is next param"; } count_is_next_param. { log "prec: count is next param"; }
count_implied. { log "prec: count is implied"; } count_implied. { log "prec: count is implied"; }

View File

@@ -145,11 +145,11 @@ fn to_str(r: lexer::reader, t: token) -> str {
/* Literals */ /* Literals */
LIT_INT(i) { LIT_INT(i) {
ret int::to_str(i, 10u); ret istr::to_estr(int::to_str(i, 10u));
} }
LIT_UINT(u) { ret istr::to_estr(uint::to_str(u, 10u)); } LIT_UINT(u) { ret istr::to_estr(uint::to_str(u, 10u)); }
LIT_MACH_INT(tm, i) { LIT_MACH_INT(tm, i) {
ret int::to_str(i, 10u) + "_" + ty_mach_to_str(tm); ret istr::to_estr(int::to_str(i, 10u)) + "_" + ty_mach_to_str(tm);
} }
LIT_MACH_FLOAT(tm, s) { LIT_MACH_FLOAT(tm, s) {
ret interner::get::<str>(*r.get_interner(), s) + "_" + ret interner::get::<str>(*r.get_interner(), s) + "_" +
@@ -173,7 +173,7 @@ fn to_str(r: lexer::reader, t: token) -> str {
IDENT(s, _) { IDENT(s, _) {
ret interner::get::<str>(*r.get_interner(), s); ret interner::get::<str>(*r.get_interner(), s);
} }
IDX(i) { ret "_" + int::to_str(i, 10u); } IDX(i) { ret istr::to_estr(~"_" + int::to_str(i, 10u)); }
UNDERSCORE. { ret "_"; } UNDERSCORE. { ret "_"; }
BRACEQUOTE(_) { ret "<bracequote>"; } BRACEQUOTE(_) { ret "<bracequote>"; }
EOF. { ret "<eof>"; } EOF. { ret "<eof>"; }

View File

@@ -1498,11 +1498,11 @@ fn print_literal(s: &ps, lit: &@ast::lit) {
"'" + escape_str(str::unsafe_from_bytes([ch as u8]), '\'') + "'" + escape_str(str::unsafe_from_bytes([ch as u8]), '\'') +
"'"); "'");
} }
ast::lit_int(val) { word(s.s, int::str(val)); } ast::lit_int(val) { word(s.s, istr::to_estr(int::str(val))); }
ast::lit_uint(val) { word(s.s, istr::to_estr(uint::str(val)) + "u"); } ast::lit_uint(val) { word(s.s, istr::to_estr(uint::str(val)) + "u"); }
ast::lit_float(fstr) { word(s.s, fstr); } ast::lit_float(fstr) { word(s.s, fstr); }
ast::lit_mach_int(mach, val) { ast::lit_mach_int(mach, val) {
word(s.s, int::str(val as int)); word(s.s, istr::to_estr(int::str(val as int)));
word(s.s, ast_util::ty_mach_to_str(mach)); word(s.s, ast_util::ty_mach_to_str(mach));
} }
ast::lit_mach_float(mach, val) { ast::lit_mach_float(mach, val) {

View File

@@ -1,5 +1,6 @@
import std::vec; import std::vec;
import std::str; import std::str;
import std::istr;
import std::int; import std::int;
import std::option; import std::option;
import std::option::none; import std::option::none;
@@ -35,7 +36,10 @@ fn mode_str_1(m: &ty::mode) -> str {
} }
fn fn_ident_to_string(id: ast::node_id, i: &ast::fn_ident) -> str { fn fn_ident_to_string(id: ast::node_id, i: &ast::fn_ident) -> str {
ret alt i { none. { "anon" + int::str(id) } some(s) { s } }; ret alt i {
none. { istr::to_estr(~"anon" + int::str(id)) }
some(s) { s }
};
} }
fn get_id_ident(cx: &ctxt, id: ast::def_id) -> str { fn get_id_ident(cx: &ctxt, id: ast::def_id) -> str {
@@ -139,7 +143,7 @@ fn ty_to_str(cx: &ctxt, typ: &t) -> str {
"obj {\n\t" + str::connect(strs, "\n\t") + "\n}" "obj {\n\t" + str::connect(strs, "\n\t") + "\n}"
} }
ty_res(id, _, _) { get_id_ident(cx, id) } ty_res(id, _, _) { get_id_ident(cx, id) }
ty_var(v) { "<T" + int::str(v) + ">" } ty_var(v) { istr::to_estr(~"<T" + int::str(v) + ~">") }
ty_param(id, _) { ty_param(id, _) {
"'" + str::unsafe_from_bytes([('a' as u8) + (id as u8)]) "'" + str::unsafe_from_bytes([('a' as u8) + (id as u8)])
} }

View File

@@ -41,13 +41,13 @@ iter range(lo: int, hi: int) -> int {
while lo_ < hi { put lo_; lo_ += 1; } while lo_ < hi { put lo_; lo_ += 1; }
} }
fn to_str(n: int, radix: uint) -> str { fn to_str(n: int, radix: uint) -> istr {
assert (0u < radix && radix <= 16u); assert (0u < radix && radix <= 16u);
ret if n < 0 { ret if n < 0 {
"-" + istr::to_estr(uint::to_str(-n as uint, radix)) ~"-" + uint::to_str(-n as uint, radix)
} else { istr::to_estr(uint::to_str(n as uint, radix)) }; } else { uint::to_str(n as uint, radix) };
} }
fn str(i: int) -> str { ret to_str(i, 10u); } fn str(i: int) -> istr { ret to_str(i, 10u); }
fn pow(base: int, exponent: uint) -> int { fn pow(base: int, exponent: uint) -> int {
ret if exponent == 0u { ret if exponent == 0u {

View File

@@ -337,7 +337,8 @@ obj new_writer(out: buf_writer) {
out.write(str::bytes(str::from_char(ch))); out.write(str::bytes(str::from_char(ch)));
} }
fn write_int(n: int) { out.write(str::bytes(int::to_str(n, 10u))); } fn write_int(n: int) { out.write(str::bytes(
istr::to_estr(int::to_str(n, 10u)))); }
fn write_uint(n: uint) { out.write(str::bytes( fn write_uint(n: uint) { out.write(str::bytes(
istr::to_estr(uint::to_str(n, 10u)))); } istr::to_estr(uint::to_str(n, 10u)))); }
fn write_bytes(bytes: &[u8]) { out.write(bytes); } fn write_bytes(bytes: &[u8]) { out.write(bytes); }

View File

@@ -7,6 +7,7 @@
use std; use std;
import std::int; import std::int;
import std::str; import std::str;
import std::istr;
fn b1() -> str { ret "# of beer on the wall, # of beer."; } fn b1() -> str { ret "# of beer on the wall, # of beer."; }
@@ -29,7 +30,7 @@ fn sub(t: str, n: int) -> str {
alt n { alt n {
0 { ns = "no more bottles"; } 0 { ns = "no more bottles"; }
1 { ns = "1 bottle"; } 1 { ns = "1 bottle"; }
_ { ns = int::to_str(n, 10u) + " bottles"; } _ { ns = istr::to_estr(int::to_str(n, 10u) + ~" bottles"); }
} }
while i < str::byte_len(t) { while i < str::byte_len(t) {
if t[i] == '#' as u8 { b += ns; } else { str::push_byte(b, t[i]); } if t[i] == '#' as u8 { b += ns; } else { str::push_byte(b, t[i]); }

View File

@@ -7,6 +7,7 @@
use std; use std;
import std::int; import std::int;
import std::str; import std::str;
import std::istr;
tag bottle { none; dual; single; multiple(int); } tag bottle { none; dual; single; multiple(int); }
@@ -29,8 +30,8 @@ fn show(b: bottle) {
"1 bottle of beer on the wall."; "1 bottle of beer on the wall.";
} }
multiple(n) { multiple(n) {
let nb: str = int::to_str(n, 10u); let nb: str = istr::to_estr(int::to_str(n, 10u));
let mb: str = int::to_str(n - 1, 10u); let mb: str = istr::to_estr(int::to_str(n - 1, 10u));
log nb + " bottles of beer on the wall, " + nb + " bottles of beer,"; log nb + " bottles of beer on the wall, " + nb + " bottles of beer,";
log "Take one down and pass it around, " + mb + log "Take one down and pass it around, " + mb +
" bottles of beer on the wall."; " bottles of beer on the wall.";

View File

@@ -7,6 +7,7 @@
use std; use std;
import std::int; import std::int;
import std::str; import std::str;
import std::istr;
fn b1() -> str { ret "# of beer on the wall, # of beer."; } fn b1() -> str { ret "# of beer on the wall, # of beer."; }
@@ -29,7 +30,7 @@ fn sub(t: str, n: int) -> str {
alt n { alt n {
0 { ns = "no more bottles"; } 0 { ns = "no more bottles"; }
1 { ns = "1 bottle"; } 1 { ns = "1 bottle"; }
_ { ns = int::to_str(n, 10u) + " bottles"; } _ { ns = istr::to_estr(int::to_str(n, 10u) + ~" bottles"); }
} }
while i < str::byte_len(t) { while i < str::byte_len(t) {
if t[i] == '#' as u8 { b += ns; } else { str::push_byte(b, t[i]); } if t[i] == '#' as u8 { b += ns; } else { str::push_byte(b, t[i]); }

View File

@@ -5,11 +5,12 @@
use std; use std;
import std::int; import std::int;
import std::str; import std::str;
import std::istr;
fn main() { fn main() {
fn multiple(n: int) { fn multiple(n: int) {
let nb: str = int::to_str(n, 10u); let nb: str = istr::to_estr(int::to_str(n, 10u));
let mb: str = int::to_str(n - 1, 10u); let mb: str = istr::to_estr(int::to_str(n - 1, 10u));
log nb + " bottles of beer on the wall, " + nb + " bottles of beer,"; log nb + " bottles of beer on the wall, " + nb + " bottles of beer,";
log "Take one down and pass it around, " + mb + log "Take one down and pass it around, " + mb +
" bottles of beer on the wall."; " bottles of beer on the wall.";

View File

@@ -1,15 +1,15 @@
use std; use std;
import std::int; import std::int;
import std::str::eq; import std::istr::eq;
#[test] #[test]
fn test_to_str() { fn test_to_str() {
assert (eq(int::to_str(0, 10u), "0")); assert (eq(int::to_str(0, 10u), ~"0"));
assert (eq(int::to_str(1, 10u), "1")); assert (eq(int::to_str(1, 10u), ~"1"));
assert (eq(int::to_str(-1, 10u), "-1")); assert (eq(int::to_str(-1, 10u), ~"-1"));
assert (eq(int::to_str(255, 16u), "ff")); assert (eq(int::to_str(255, 16u), ~"ff"));
assert (eq(int::to_str(100, 10u), "100")); assert (eq(int::to_str(100, 10u), ~"100"));
} }
#[test] #[test]