Convert std::int to istrs. Issue #855
This commit is contained in:
parent
ee2a11eb4f
commit
53be480d20
@ -27,6 +27,7 @@ import std::option;
|
||||
import std::option::some;
|
||||
import std::option::none;
|
||||
import std::str;
|
||||
import std::istr;
|
||||
import std::vec;
|
||||
import std::int;
|
||||
import std::io;
|
||||
@ -189,16 +190,18 @@ fn pretty_print_input(sess: session::session, cfg: ast::crate_cfg, input: str,
|
||||
alt node {
|
||||
pprust::node_item(s, item) {
|
||||
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) {
|
||||
pp::space(s.s);
|
||||
pprust::synth_comment(s,
|
||||
"block " + int::to_str(blk.node.id, 10u));
|
||||
pprust::synth_comment(
|
||||
s, istr::to_estr(~"block " + int::to_str(blk.node.id, 10u)));
|
||||
}
|
||||
pprust::node_expr(s, expr) {
|
||||
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);
|
||||
}
|
||||
_ { }
|
||||
|
@ -1,5 +1,6 @@
|
||||
import std::vec;
|
||||
import std::str;
|
||||
import std::istr;
|
||||
import std::str::rustrt::sbuf;
|
||||
|
||||
import llvm::ModuleRef;
|
||||
@ -976,7 +977,8 @@ fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) ->
|
||||
|
||||
|
||||
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;
|
||||
if tout as int == ty as int {
|
||||
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 "*" +
|
||||
|
@ -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); }
|
||||
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) {
|
||||
w.write_char('E');
|
||||
w.write_str(cx.ds(def));
|
||||
|
@ -5,6 +5,7 @@ import std::map;
|
||||
import std::map::*;
|
||||
import std::option;
|
||||
import std::int;
|
||||
import std::istr;
|
||||
import std::option::*;
|
||||
import syntax::ast;
|
||||
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 {
|
||||
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; }
|
||||
}
|
||||
}
|
||||
|
@ -63,7 +63,9 @@ import trans::type_of_fn_full;
|
||||
import trans::drop_ty;
|
||||
|
||||
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};
|
||||
|
@ -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]) {
|
||||
alt s.node {
|
||||
stmt_decl(_, id) {
|
||||
log "node_id " + int::str(id);
|
||||
log ~"node_id " + int::str(id);
|
||||
log_stmt(*s);;
|
||||
*rs += [id];
|
||||
}
|
||||
stmt_expr(_, id) {
|
||||
log "node_id " + int::str(id);
|
||||
log ~"node_id " + int::str(id);
|
||||
log_stmt(*s);;
|
||||
*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) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ tag oper_type {
|
||||
|
||||
/* logging funs */
|
||||
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 {
|
||||
@ -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 {
|
||||
alt get_ts_ann(ccx, id) {
|
||||
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;
|
||||
}
|
||||
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 {
|
||||
alt freevars::def_lookup(cx.ccx.tcx, cx.id, id) {
|
||||
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;
|
||||
}
|
||||
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 {
|
||||
alt cx.def_map.find(id) {
|
||||
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;
|
||||
}
|
||||
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 {
|
||||
alt tcx.def_map.find(t) {
|
||||
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; }
|
||||
_ { tcx.sess.bug("node_id_for_constr: pred is not a function"); }
|
||||
|
@ -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) {
|
||||
none. {
|
||||
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; }
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ import middle::ty::unify::fix_err;
|
||||
import std::int;
|
||||
import std::vec;
|
||||
import std::str;
|
||||
import std::istr;
|
||||
import std::uint;
|
||||
import std::map;
|
||||
import std::map::hashmap;
|
||||
@ -586,7 +587,10 @@ mod collect {
|
||||
some(ast_map::node_native_item(native_item)) {
|
||||
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;
|
||||
}
|
||||
@ -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));
|
||||
}
|
||||
none. {
|
||||
tcx.sess.bug("didn't find " + int::str(did.node) +
|
||||
" in type cache");
|
||||
tcx.sess.bug("didn't find " +
|
||||
istr::to_estr(int::str(did.node)) +
|
||||
" in type cache");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
*/
|
||||
import std::vec;
|
||||
import std::str;
|
||||
import std::istr;
|
||||
import std::option;
|
||||
import std::option::none;
|
||||
import std::option::some;
|
||||
@ -258,7 +259,10 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece],
|
||||
}
|
||||
fn log_conv(c: conv) {
|
||||
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"; }
|
||||
}
|
||||
for f: flag in c.flags {
|
||||
@ -271,17 +275,21 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece],
|
||||
}
|
||||
}
|
||||
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) {
|
||||
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_implied. { log "width: count is implied"; }
|
||||
}
|
||||
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) {
|
||||
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_implied. { log "prec: count is implied"; }
|
||||
|
@ -145,11 +145,11 @@ fn to_str(r: lexer::reader, t: token) -> str {
|
||||
|
||||
/* Literals */
|
||||
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_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) {
|
||||
ret interner::get::<str>(*r.get_interner(), s) + "_" +
|
||||
@ -173,7 +173,7 @@ fn to_str(r: lexer::reader, t: token) -> str {
|
||||
IDENT(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 "_"; }
|
||||
BRACEQUOTE(_) { ret "<bracequote>"; }
|
||||
EOF. { ret "<eof>"; }
|
||||
|
@ -1498,11 +1498,11 @@ fn print_literal(s: &ps, lit: &@ast::lit) {
|
||||
"'" + 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_float(fstr) { word(s.s, fstr); }
|
||||
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));
|
||||
}
|
||||
ast::lit_mach_float(mach, val) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
import std::vec;
|
||||
import std::str;
|
||||
import std::istr;
|
||||
import std::int;
|
||||
import std::option;
|
||||
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 {
|
||||
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 {
|
||||
@ -139,7 +143,7 @@ fn ty_to_str(cx: &ctxt, typ: &t) -> str {
|
||||
"obj {\n\t" + str::connect(strs, "\n\t") + "\n}"
|
||||
}
|
||||
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, _) {
|
||||
"'" + str::unsafe_from_bytes([('a' as u8) + (id as u8)])
|
||||
}
|
||||
|
@ -41,13 +41,13 @@ iter range(lo: int, hi: int) -> int {
|
||||
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);
|
||||
ret if n < 0 {
|
||||
"-" + istr::to_estr(uint::to_str(-n as uint, radix))
|
||||
} else { istr::to_estr(uint::to_str(n as uint, radix)) };
|
||||
~"-" + 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 {
|
||||
ret if exponent == 0u {
|
||||
|
@ -337,7 +337,8 @@ obj new_writer(out: buf_writer) {
|
||||
|
||||
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(
|
||||
istr::to_estr(uint::to_str(n, 10u)))); }
|
||||
fn write_bytes(bytes: &[u8]) { out.write(bytes); }
|
||||
|
@ -7,6 +7,7 @@
|
||||
use std;
|
||||
import std::int;
|
||||
import std::str;
|
||||
import std::istr;
|
||||
|
||||
fn b1() -> str { ret "# of beer on the wall, # of beer."; }
|
||||
|
||||
@ -29,7 +30,7 @@ fn sub(t: str, n: int) -> str {
|
||||
alt n {
|
||||
0 { ns = "no more bottles"; }
|
||||
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) {
|
||||
if t[i] == '#' as u8 { b += ns; } else { str::push_byte(b, t[i]); }
|
||||
|
@ -7,6 +7,7 @@
|
||||
use std;
|
||||
import std::int;
|
||||
import std::str;
|
||||
import std::istr;
|
||||
|
||||
tag bottle { none; dual; single; multiple(int); }
|
||||
|
||||
@ -29,8 +30,8 @@ fn show(b: bottle) {
|
||||
"1 bottle of beer on the wall.";
|
||||
}
|
||||
multiple(n) {
|
||||
let nb: str = int::to_str(n, 10u);
|
||||
let mb: str = int::to_str(n - 1, 10u);
|
||||
let nb: str = istr::to_estr(int::to_str(n, 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 "Take one down and pass it around, " + mb +
|
||||
" bottles of beer on the wall.";
|
||||
|
@ -7,6 +7,7 @@
|
||||
use std;
|
||||
import std::int;
|
||||
import std::str;
|
||||
import std::istr;
|
||||
|
||||
fn b1() -> str { ret "# of beer on the wall, # of beer."; }
|
||||
|
||||
@ -29,7 +30,7 @@ fn sub(t: str, n: int) -> str {
|
||||
alt n {
|
||||
0 { ns = "no more bottles"; }
|
||||
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) {
|
||||
if t[i] == '#' as u8 { b += ns; } else { str::push_byte(b, t[i]); }
|
||||
|
@ -5,11 +5,12 @@
|
||||
use std;
|
||||
import std::int;
|
||||
import std::str;
|
||||
import std::istr;
|
||||
|
||||
fn main() {
|
||||
fn multiple(n: int) {
|
||||
let nb: str = int::to_str(n, 10u);
|
||||
let mb: str = int::to_str(n - 1, 10u);
|
||||
let nb: str = istr::to_estr(int::to_str(n, 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 "Take one down and pass it around, " + mb +
|
||||
" bottles of beer on the wall.";
|
||||
|
@ -1,15 +1,15 @@
|
||||
|
||||
use std;
|
||||
import std::int;
|
||||
import std::str::eq;
|
||||
import std::istr::eq;
|
||||
|
||||
#[test]
|
||||
fn test_to_str() {
|
||||
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(255, 16u), "ff"));
|
||||
assert (eq(int::to_str(100, 10u), "100"));
|
||||
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(255, 16u), ~"ff"));
|
||||
assert (eq(int::to_str(100, 10u), ~"100"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user