1
Fork 0

Convert rustc::syntax::ast_util to istrs. Issue #855

This commit is contained in:
Brian Anderson 2011-08-27 14:42:29 -07:00
parent cbad23a747
commit 9fb085560d
8 changed files with 63 additions and 60 deletions

View file

@ -92,7 +92,8 @@ fn fold_item(cx: &test_ctxt, i: &@ast::item, fld: fold::ast_fold) ->
@ast::item { @ast::item {
cx.path += [i.ident]; cx.path += [i.ident];
log #fmt["current path: %s", ast_util::path_name_i(cx.path)]; log #fmt["current path: %s",
istr::to_estr(ast_util::path_name_i(cx.path))];
if is_test_fn(i) { if is_test_fn(i) {
log "this is a test function"; log "this is a test function";
@ -248,11 +249,11 @@ fn mk_test_desc_vec(cx: &test_ctxt) -> @ast::expr {
fn mk_test_desc_rec(cx: &test_ctxt, test: test) -> @ast::expr { fn mk_test_desc_rec(cx: &test_ctxt, test: test) -> @ast::expr {
let path = test.path; let path = test.path;
log #fmt["encoding %s", ast_util::path_name_i(path)]; log #fmt["encoding %s",
istr::to_estr(ast_util::path_name_i(path))];
let name_lit: ast::lit = let name_lit: ast::lit =
nospan(ast::lit_str( nospan(ast::lit_str(ast_util::path_name_i(path), ast::sk_rc));
istr::from_estr(ast_util::path_name_i(path)), ast::sk_rc));
let name_expr: ast::expr = let name_expr: ast::expr =
{id: cx.next_node_id(), {id: cx.next_node_id(),
node: ast::expr_lit(@name_lit), node: ast::expr_lit(@name_lit),

View file

@ -518,16 +518,18 @@ fn test_scope(cx: &ctx, sc: &scope, r: &restrict, p: &ast::path) {
let msg = let msg =
alt prob { alt prob {
overwritten(sp, wpt) { overwritten(sp, wpt) {
{span: sp, msg: "overwriting " + ast_util::path_name(wpt)} {span: sp, msg: "overwriting " +
istr::to_estr(ast_util::path_name(wpt))}
} }
val_taken(sp, vpt) { val_taken(sp, vpt) {
{span: sp, {span: sp,
msg: "taking the value of " + ast_util::path_name(vpt)} msg: "taking the value of " +
istr::to_estr(ast_util::path_name(vpt))}
} }
}; };
cx.tcx.sess.span_err(msg.span, cx.tcx.sess.span_err(msg.span,
msg.msg + " will invalidate alias " + msg.msg + " will invalidate alias " +
ast_util::path_name(p) + istr::to_estr(ast_util::path_name(p)) +
", which is still used"); ", which is still used");
} }
} }

View file

@ -324,7 +324,7 @@ fn resolve_names(e: &@env, c: &@ast::crate) {
_ { _ {
e.sess.span_err(p.span, e.sess.span_err(p.span,
"not a tag variant: " + "not a tag variant: " +
ast_util::path_name(p)); istr::to_estr(ast_util::path_name(p)));
} }
} }
} }

View file

@ -1792,10 +1792,10 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr, unify: &unifier,
let binopstr = ast_util::binop_to_str(binop); let binopstr = ast_util::binop_to_str(binop);
let t_str = ty_to_str(fcx.ccx.tcx, resolved_t); let t_str = ty_to_str(fcx.ccx.tcx, resolved_t);
let errmsg = let errmsg =
"binary operation " + binopstr + ~"binary operation " + binopstr +
" cannot be applied to type `" + ~" cannot be applied to type `" +
istr::to_estr(t_str) + "`"; t_str + ~"`";
fcx.ccx.tcx.sess.span_err(span, errmsg); fcx.ccx.tcx.sess.span_err(span, istr::to_estr(errmsg));
} }
} }

View file

@ -14,10 +14,10 @@ fn mk_sp(lo: uint, hi: uint) -> span {
// make this a const, once the compiler supports it // make this a const, once the compiler supports it
fn dummy_sp() -> span { ret mk_sp(0u, 0u); } fn dummy_sp() -> span { ret mk_sp(0u, 0u); }
fn path_name(p: &path) -> str { path_name_i(p.node.idents) } fn path_name(p: &path) -> istr { path_name_i(p.node.idents) }
fn path_name_i(idents: &[ident]) -> str { fn path_name_i(idents: &[ident]) -> istr {
istr::to_estr(istr::connect(idents, ~"::")) istr::connect(idents, ~"::")
} }
fn local_def(id: node_id) -> def_id { ret {crate: local_crate, node: id}; } fn local_def(id: node_id) -> def_id { ret {crate: local_crate, node: id}; }
@ -83,27 +83,27 @@ fn pat_binding_ids(pat: &@pat) -> [node_id] {
ret found; ret found;
} }
fn binop_to_str(op: binop) -> str { fn binop_to_str(op: binop) -> istr {
alt op { alt op {
add. { ret "+"; } add. { ret ~"+"; }
sub. { ret "-"; } sub. { ret ~"-"; }
mul. { ret "*"; } mul. { ret ~"*"; }
div. { ret "/"; } div. { ret ~"/"; }
rem. { ret "%"; } rem. { ret ~"%"; }
and. { ret "&&"; } and. { ret ~"&&"; }
or. { ret "||"; } or. { ret ~"||"; }
bitxor. { ret "^"; } bitxor. { ret ~"^"; }
bitand. { ret "&"; } bitand. { ret ~"&"; }
bitor. { ret "|"; } bitor. { ret ~"|"; }
lsl. { ret "<<"; } lsl. { ret ~"<<"; }
lsr. { ret ">>"; } lsr. { ret ~">>"; }
asr. { ret ">>>"; } asr. { ret ~">>>"; }
eq. { ret "=="; } eq. { ret ~"=="; }
lt. { ret "<"; } lt. { ret ~"<"; }
le. { ret "<="; } le. { ret ~"<="; }
ne. { ret "!="; } ne. { ret ~"!="; }
ge. { ret ">="; } ge. { ret ~">="; }
gt. { ret ">"; } gt. { ret ~">"; }
} }
} }
@ -111,12 +111,12 @@ pure fn lazy_binop(b: binop) -> bool {
alt b { and. { true } or. { true } _ { false } } alt b { and. { true } or. { true } _ { false } }
} }
fn unop_to_str(op: unop) -> str { fn unop_to_str(op: unop) -> istr {
alt op { alt op {
box(mt) { if mt == mut { ret "@mutable "; } ret "@"; } box(mt) { if mt == mut { ret ~"@mutable "; } ret ~"@"; }
deref. { ret "*"; } deref. { ret ~"*"; }
not. { ret "!"; } not. { ret ~"!"; }
neg. { ret "-"; } neg. { ret ~"-"; }
} }
} }
@ -124,18 +124,18 @@ fn is_path(e: &@expr) -> bool {
ret alt e.node { expr_path(_) { true } _ { false } }; ret alt e.node { expr_path(_) { true } _ { false } };
} }
fn ty_mach_to_str(tm: ty_mach) -> str { fn ty_mach_to_str(tm: ty_mach) -> istr {
alt tm { alt tm {
ty_u8. { ret "u8"; } ty_u8. { ret ~"u8"; }
ty_u16. { ret "u16"; } ty_u16. { ret ~"u16"; }
ty_u32. { ret "u32"; } ty_u32. { ret ~"u32"; }
ty_u64. { ret "u64"; } ty_u64. { ret ~"u64"; }
ty_i8. { ret "i8"; } ty_i8. { ret ~"i8"; }
ty_i16. { ret "i16"; } ty_i16. { ret ~"i16"; }
ty_i32. { ret "i32"; } ty_i32. { ret ~"i32"; }
ty_i64. { ret "i64"; } ty_i64. { ret ~"i64"; }
ty_f32. { ret "f32"; } ty_f32. { ret ~"f32"; }
ty_f64. { ret "f64"; } ty_f64. { ret ~"f64"; }
} }
} }

View file

@ -149,12 +149,12 @@ fn to_str(r: lexer::reader, t: token) -> istr {
} }
LIT_UINT(u) { ret uint::to_str(u, 10u); } LIT_UINT(u) { ret uint::to_str(u, 10u); }
LIT_MACH_INT(tm, i) { LIT_MACH_INT(tm, i) {
ret int::to_str(i, 10u) + ~"_" + istr::from_estr(ty_mach_to_str(tm)); ret int::to_str(i, 10u) + ~"_" + ty_mach_to_str(tm);
} }
LIT_MACH_FLOAT(tm, s) { LIT_MACH_FLOAT(tm, s) {
ret interner::get::<istr>( ret interner::get::<istr>(
*r.get_interner(), s) + ~"_" + *r.get_interner(), s) + ~"_" +
istr::from_estr(ty_mach_to_str(tm)); ty_mach_to_str(tm);
} }
LIT_FLOAT(s) { LIT_FLOAT(s) {
ret interner::get::<istr>(*r.get_interner(), s); ret interner::get::<istr>(*r.get_interner(), s);

View file

@ -276,7 +276,7 @@ fn print_type(s: &ps, ty: &@ast::ty) {
ast::ty_uint. { word(s.s, ~"uint"); } ast::ty_uint. { word(s.s, ~"uint"); }
ast::ty_float. { word(s.s, ~"float"); } ast::ty_float. { word(s.s, ~"float"); }
ast::ty_machine(tm) { ast::ty_machine(tm) {
word(s.s, istr::from_estr(ast_util::ty_mach_to_str(tm))); word(s.s, ast_util::ty_mach_to_str(tm));
} }
ast::ty_char. { word(s.s, ~"char"); } ast::ty_char. { word(s.s, ~"char"); }
ast::ty_str. { word(s.s, ~"str"); } ast::ty_str. { word(s.s, ~"str"); }
@ -846,11 +846,11 @@ fn print_expr(s: &ps, expr: &@ast::expr) {
let prec = operator_prec(op); let prec = operator_prec(op);
print_maybe_parens(s, lhs, prec); print_maybe_parens(s, lhs, prec);
space(s.s); space(s.s);
word_space(s, istr::from_estr(ast_util::binop_to_str(op))); word_space(s, ast_util::binop_to_str(op));
print_maybe_parens(s, rhs, prec + 1); print_maybe_parens(s, rhs, prec + 1);
} }
ast::expr_unary(op, expr) { ast::expr_unary(op, expr) {
word(s.s, istr::from_estr(ast_util::unop_to_str(op))); word(s.s, ast_util::unop_to_str(op));
print_maybe_parens(s, expr, parse::parser::unop_prec); print_maybe_parens(s, expr, parse::parser::unop_prec);
} }
ast::expr_lit(lit) { print_literal(s, lit); } ast::expr_lit(lit) { print_literal(s, lit); }
@ -982,7 +982,7 @@ fn print_expr(s: &ps, expr: &@ast::expr) {
ast::expr_assign_op(op, lhs, rhs) { ast::expr_assign_op(op, lhs, rhs) {
print_expr(s, lhs); print_expr(s, lhs);
space(s.s); space(s.s);
word(s.s, istr::from_estr(ast_util::binop_to_str(op))); word(s.s, ast_util::binop_to_str(op));
word_space(s, ~"="); word_space(s, ~"=");
print_expr(s, rhs); print_expr(s, rhs);
} }
@ -1526,12 +1526,12 @@ fn print_literal(s: &ps, lit: &@ast::lit) {
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, int::str(val as int));
word(s.s, istr::from_estr(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) {
// val is already a str // val is already a str
word(s.s, val); word(s.s, val);
word(s.s, istr::from_estr(ast_util::ty_mach_to_str(mach))); word(s.s, ast_util::ty_mach_to_str(mach));
} }
ast::lit_nil. { word(s.s, ~"()"); } ast::lit_nil. { word(s.s, ~"()"); }
ast::lit_bool(val) { ast::lit_bool(val) {

View file

@ -114,7 +114,7 @@ fn ty_to_str(cx: &ctxt, typ: &t) -> istr {
ty_int. { ~"int" } ty_int. { ~"int" }
ty_float. { ~"float" } ty_float. { ~"float" }
ty_uint. { ~"uint" } ty_uint. { ~"uint" }
ty_machine(tm) { istr::from_estr(ty_mach_to_str(tm)) } ty_machine(tm) { ty_mach_to_str(tm) }
ty_char. { ~"char" } ty_char. { ~"char" }
ty_str. { ~"str" } ty_str. { ~"str" }
ty_istr. { ~"istr" } ty_istr. { ~"istr" }