From cbad23a747c282d190e3c264f515765a938b0c98 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sat, 27 Aug 2011 01:16:40 -0700 Subject: [PATCH] Convert pretty-printer to istrs. Issue #855 --- src/comp/back/link.rs | 2 +- src/comp/driver/rustc.rs | 13 +- src/comp/front/attr.rs | 6 +- src/comp/front/test.rs | 3 +- src/comp/metadata/creader.rs | 3 +- src/comp/metadata/decoder.rs | 8 +- src/comp/metadata/tyencode.rs | 10 +- src/comp/middle/resolve.rs | 2 +- src/comp/middle/trans.rs | 2 +- src/comp/middle/tstate/auxiliary.rs | 20 +- src/comp/middle/tstate/ck.rs | 11 +- src/comp/middle/ty.rs | 3 +- src/comp/middle/typeck.rs | 9 +- src/comp/syntax/ext/log_syntax.rs | 2 +- src/comp/syntax/print/pp.rs | 43 +- src/comp/syntax/print/pprust.rs | 603 ++++++++++++++-------------- src/comp/util/ppaux.rs | 12 +- src/fuzzer/fuzzer.rs | 13 +- 18 files changed, 395 insertions(+), 370 deletions(-) diff --git a/src/comp/back/link.rs b/src/comp/back/link.rs index 77f3cf671cc..09b4bbe69c3 100644 --- a/src/comp/back/link.rs +++ b/src/comp/back/link.rs @@ -347,7 +347,7 @@ fn build_link_meta(sess: &session::session, c: &ast::crate, output: &istr, } fn len_and_str_lit(l: &ast::lit) -> istr { - ret len_and_str(istr::from_estr(pprust::lit_to_str(@l))); + ret len_and_str(pprust::lit_to_str(@l)); } let cmh_items = attr::sort_meta_items(metas.cmh_items); diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs index c607f216dca..eb6c63fd295 100644 --- a/src/comp/driver/rustc.rs +++ b/src/comp/driver/rustc.rs @@ -185,11 +185,11 @@ fn pretty_print_input(sess: session::session, cfg: ast::crate_cfg, input: str, alt node { pprust::node_expr(s, expr) { pp::space(s.s); - pp::word(s.s, "as"); + pp::word(s.s, ~"as"); pp::space(s.s); pp::word( s.s, - istr::to_estr(ppaux::ty_to_str(tcx, ty::expr_ty(tcx, expr)))); + ppaux::ty_to_str(tcx, ty::expr_ty(tcx, expr))); pprust::pclose(s); } _ { } @@ -200,17 +200,17 @@ fn pretty_print_input(sess: session::session, cfg: ast::crate_cfg, input: str, pprust::node_item(s, item) { pp::space(s.s); pprust::synth_comment( - s, istr::to_estr(int::to_str(item.id, 10u))); + s, int::to_str(item.id, 10u)); } pprust::node_block(s, blk) { pp::space(s.s); pprust::synth_comment( - s, istr::to_estr(~"block " + int::to_str(blk.node.id, 10u))); + s, ~"block " + int::to_str(blk.node.id, 10u)); } pprust::node_expr(s, expr) { pp::space(s.s); pprust::synth_comment( - s, istr::to_estr(int::to_str(expr.id, 10u))); + s, int::to_str(expr.id, 10u)); pprust::pclose(s); } _ { } @@ -246,7 +246,8 @@ fn pretty_print_input(sess: session::session, cfg: ast::crate_cfg, input: str, } ppm_normal. { ann = pprust::no_ann(); } } - pprust::print_crate(sess.get_codemap(), crate, input, + pprust::print_crate(sess.get_codemap(), crate, + istr::from_estr(input), io::string_reader(istr::from_estr(src)), io::stdout(), ann); } diff --git a/src/comp/front/attr.rs b/src/comp/front/attr.rs index 8bc0ce941fb..cb7a196f75b 100644 --- a/src/comp/front/attr.rs +++ b/src/comp/front/attr.rs @@ -125,10 +125,12 @@ fn eq(a: @ast::meta_item, b: @ast::meta_item) -> bool { fn contains(haystack: &[@ast::meta_item], needle: @ast::meta_item) -> bool { log #fmt["looking for %s", - syntax::print::pprust::meta_item_to_str(*needle)]; + istr::to_estr( + syntax::print::pprust::meta_item_to_str(*needle))]; for item: @ast::meta_item in haystack { log #fmt["looking in %s", - syntax::print::pprust::meta_item_to_str(*item)]; + istr::to_estr( + syntax::print::pprust::meta_item_to_str(*item))]; if eq(item, needle) { log "found it!"; ret true; } } log "found it not :("; diff --git a/src/comp/front/test.rs b/src/comp/front/test.rs index 4d027c867bb..b2c7b200bab 100644 --- a/src/comp/front/test.rs +++ b/src/comp/front/test.rs @@ -167,7 +167,8 @@ fn mk_test_module(cx: &test_ctxt) -> @ast::item { node: item_, span: dummy_sp()}; - log #fmt["Synthetic test module:\n%s\n", pprust::item_to_str(@item)]; + log #fmt["Synthetic test module:\n%s\n", + istr::to_estr(pprust::item_to_str(@item))]; ret @item; } diff --git a/src/comp/metadata/creader.rs b/src/comp/metadata/creader.rs index 078f3e1850d..5f8923692f5 100644 --- a/src/comp/metadata/creader.rs +++ b/src/comp/metadata/creader.rs @@ -105,7 +105,8 @@ fn metadata_matches(crate_data: &@[u8], metas: &[@ast::meta_item]) -> bool { for needed: @ast::meta_item in metas { if !attr::contains(linkage_metas, needed) { - log #fmt["missing %s", pprust::meta_item_to_str(*needed)]; + log #fmt["missing %s", + istr::to_estr(pprust::meta_item_to_str(*needed))]; ret false; } } diff --git a/src/comp/metadata/decoder.rs b/src/comp/metadata/decoder.rs index 5a856723f0e..a1ab2a521c4 100644 --- a/src/comp/metadata/decoder.rs +++ b/src/comp/metadata/decoder.rs @@ -349,7 +349,9 @@ fn get_attributes(md: &ebml::doc) -> [ast::attribute] { fn list_meta_items(meta_items: &ebml::doc, out: io::writer) { for mi: @ast::meta_item in get_meta_items(meta_items) { out.write_str( - istr::from_estr(#fmt["%s\n", pprust::meta_item_to_str(*mi)])); + istr::from_estr( + #fmt["%s\n", + istr::to_estr(pprust::meta_item_to_str(*mi))])); } } @@ -358,7 +360,9 @@ fn list_crate_attributes(md: &ebml::doc, out: io::writer) { for attr: ast::attribute in get_attributes(md) { out.write_str( - istr::from_estr(#fmt["%s\n", pprust::attribute_to_str(attr)])); + istr::from_estr( + #fmt["%s\n", + istr::to_estr(pprust::attribute_to_str(attr))])); } out.write_str(~"\n\n"); diff --git a/src/comp/metadata/tyencode.rs b/src/comp/metadata/tyencode.rs index af6fe4ab7ae..fe010f589bf 100644 --- a/src/comp/metadata/tyencode.rs +++ b/src/comp/metadata/tyencode.rs @@ -235,7 +235,7 @@ fn enc_ty_fn(w: &io::writer, cx: &@ctxt, args: &[ty::arg], out: ty::t, // FIXME less copy-and-paste fn enc_constr(w: &io::writer, cx: &@ctxt, c: &@ty::constr) { - w.write_str(istr::from_estr(path_to_str(c.node.path))); + w.write_str(path_to_str(c.node.path)); w.write_char('('); w.write_str(cx.ds(c.node.id)); w.write_char('|'); @@ -246,7 +246,7 @@ fn enc_constr(w: &io::writer, cx: &@ctxt, c: &@ty::constr) { carg_base. { w.write_char('*'); } carg_ident(i) { w.write_uint(i); } carg_lit(l) { - w.write_str(istr::from_estr(lit_to_str(l))); + w.write_str(lit_to_str(l)); } } } @@ -254,7 +254,7 @@ fn enc_constr(w: &io::writer, cx: &@ctxt, c: &@ty::constr) { } fn enc_ty_constr(w: &io::writer, cx: &@ctxt, c: &@ty::type_constr) { - w.write_str(istr::from_estr(path_to_str(c.node.path))); + w.write_str(path_to_str(c.node.path)); w.write_char('('); w.write_str(cx.ds(c.node.id)); w.write_char('|'); @@ -264,9 +264,9 @@ fn enc_ty_constr(w: &io::writer, cx: &@ctxt, c: &@ty::type_constr) { alt a.node { carg_base. { w.write_char('*'); } carg_ident(p) { - w.write_str(istr::from_estr(path_to_str(p))); } + w.write_str(path_to_str(p)); } carg_lit(l) { - w.write_str(istr::from_estr(lit_to_str(l))); } + w.write_str(lit_to_str(l)); } } } w.write_char(')'); diff --git a/src/comp/middle/resolve.rs b/src/comp/middle/resolve.rs index b292c116cb5..879a1f15dcc 100644 --- a/src/comp/middle/resolve.rs +++ b/src/comp/middle/resolve.rs @@ -451,7 +451,7 @@ fn resolve_constr(e: @env, c: &@ast::constr, sc: &scopes, _v: &vt) { _ { e.sess.span_err(c.span, "Non-predicate in constraint: " + - path_to_str(c.node.path)); + istr::to_estr(path_to_str(c.node.path))); } } } diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 28d8e18c009..fa5b25e3755 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -4602,7 +4602,7 @@ fn trans_log(lvl: int, cx: &@block_ctxt, e: &@ast::expr) -> result { fn trans_check_expr(cx: &@block_ctxt, e: &@ast::expr, s: &istr) -> result { let cond_res = trans_expr(cx, e); - let expr_str = s + ~" " + istr::from_estr(expr_to_str(e)) + ~" failed"; + let expr_str = s + ~" " + expr_to_str(e) + ~" failed"; let fail_cx = new_sub_block_ctxt(cx, ~"fail"); trans_fail(fail_cx, some::(e.span), expr_str); let next_cx = new_sub_block_ctxt(cx, ~"next"); diff --git a/src/comp/middle/tstate/auxiliary.rs b/src/comp/middle/tstate/auxiliary.rs index a8e0bab3617..ecf775524e3 100644 --- a/src/comp/middle/tstate/auxiliary.rs +++ b/src/comp/middle/tstate/auxiliary.rs @@ -68,7 +68,7 @@ fn comma_str(args: &[@constr_arg_use]) -> istr { alt a.node { carg_base. { rslt += ~"*"; } carg_ident(i) { rslt += i.ident; } - carg_lit(l) { rslt += istr::from_estr(lit_to_str(l)); } + carg_lit(l) { rslt += lit_to_str(l); } } } ret rslt; @@ -81,7 +81,7 @@ fn constraint_to_str(tcx: &ty::ctxt, c: &sp_constr) -> istr { istr::from_estr(tcx.sess.span_str(c.span)) + ~"])"; } npred(p, _, args) { - ret istr::from_estr(path_to_str(p)) + ~"(" + + ret path_to_str(p) + ~"(" + comma_str(args) + ~")" + ~"[" + istr::from_estr(tcx.sess.span_str(c.span)) + ~"]"; } @@ -593,9 +593,9 @@ fn constraints(fcx: &fn_ctxt) -> [norm_constraint] { // should freeze it at some earlier point. fn match_args(fcx: &fn_ctxt, occs: &@mutable [pred_args], occ: &[@constr_arg_use]) -> uint { - log "match_args: looking at " + - constr_args_to_str(fn (i: &inst) -> str { - ret istr::to_estr(i.ident); + log ~"match_args: looking at " + + constr_args_to_str(fn (i: &inst) -> istr { + ret i.ident; }, occ); for pd: pred_args in *occs { log ~"match_args: candidate " + pred_args_to_str(pd); @@ -687,11 +687,11 @@ fn expr_to_constr(tcx: ty::ctxt, e: &@expr) -> sp_constr { } fn pred_args_to_str(p: &pred_args) -> istr { - istr::from_estr("<" + istr::to_estr(uint::str(p.node.bit_num)) + ", " + - constr_args_to_str(fn (i: &inst) -> str { - ret istr::to_estr(i.ident); - }, p.node.args) - + ">") + ~"<" + uint::str(p.node.bit_num) + ~", " + + constr_args_to_str(fn (i: &inst) -> istr { + ret i.ident; + }, p.node.args) + + ~">" } fn substitute_constr_args(cx: &ty::ctxt, actuals: &[@expr], c: &@ty::constr) diff --git a/src/comp/middle/tstate/ck.rs b/src/comp/middle/tstate/ck.rs index 75d8ec1aa6b..17fd27c3014 100644 --- a/src/comp/middle/tstate/ck.rs +++ b/src/comp/middle/tstate/ck.rs @@ -87,7 +87,7 @@ fn check_states_expr(e: &@expr, fcx: &fn_ctxt, v: &visit::vt) { s += ~"Unsatisfied precondition constraint (for example, " + diff + ~") for expression:\n"; - s += istr::from_estr(syntax::print::pprust::expr_to_str(e)); + s += syntax::print::pprust::expr_to_str(e); s += ~"\nPrecondition:\n"; s += tritv_to_str(fcx, prec); s += ~"\nPrestate:\n"; @@ -119,7 +119,7 @@ fn check_states_stmt(s: &@stmt, fcx: &fn_ctxt, v: &visit::vt) { ss += ~"Unsatisfied precondition constraint (for example, " + diff + ~") for statement:\n"; - ss += istr::from_estr(syntax::print::pprust::stmt_to_str(*s)); + ss += syntax::print::pprust::stmt_to_str(*s); ss += ~"\nPrecondition:\n"; ss += tritv_to_str(fcx, prec); ss += ~"\nPrestate: \n"; @@ -154,9 +154,10 @@ fn check_states_against_conditions(fcx: &fn_ctxt, f: &_fn, istr::to_estr(fcx.name) + ", not all control paths \ return a value"); - fcx.ccx.tcx.sess.span_fatal(f.decl.output.span, - "see declared return type of '" + - ty_to_str(f.decl.output) + "'"); + fcx.ccx.tcx.sess.span_fatal( + f.decl.output.span, + "see declared return type of '" + + istr::to_estr(ty_to_str(f.decl.output)) + "'"); } else if f.decl.cf == noreturn { // check that this really always fails diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs index 3a7ac5bd6b4..1caa48033c3 100644 --- a/src/comp/middle/ty.rs +++ b/src/comp/middle/ty.rs @@ -2900,7 +2900,8 @@ fn ast_constr_to_constr(tcx: ty::ctxt, c: &@ast::constr_general) -> } _ { tcx.sess.span_fatal(c.span, - "Predicate " + path_to_str(c.node.path) + + "Predicate " + + istr::to_estr(path_to_str(c.node.path)) + " is unbound or bound to a non-function or an \ impure function"); } diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index de71ae08a27..a7662635665 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -315,7 +315,7 @@ fn ast_ty_to_ty(tcx: &ty::ctxt, getter: &ty_getter, ast_ty: &@ast::ty) -> ret typ; } let typ; - let cname = none::; + let cname = none::; alt ast_ty.node { ast::ty_nil. { typ = ty::mk_nil(tcx); } ast::ty_bot. { typ = ty::mk_bot(tcx); } @@ -415,7 +415,9 @@ 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, cname_str); } + some(cname_str) { + typ = ty::rename(tcx, typ, istr::to_estr(cname_str)); + } } tcx.ast_ty_to_ty_cache.insert(ast_ty, some(typ)); ret typ; @@ -2402,7 +2404,8 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr, unify: &unifier, // The user is trying to extend a non-object. tcx.sess.span_fatal( e.span, - syntax::print::pprust::expr_to_str(e) + istr::to_estr( + syntax::print::pprust::expr_to_str(e)) + " does not have object type"); } diff --git a/src/comp/syntax/ext/log_syntax.rs b/src/comp/syntax/ext/log_syntax.rs index 3cab1dbd915..5acad14fbb2 100644 --- a/src/comp/syntax/ext/log_syntax.rs +++ b/src/comp/syntax/ext/log_syntax.rs @@ -8,7 +8,7 @@ fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr, cx.print_backtrace(); std::io::stdout().write_line( - istr::from_estr(print::pprust::expr_to_str(arg))); + print::pprust::expr_to_str(arg)); //trivial expression ret @{id: cx.next_id(), node: ast::expr_rec([], option::none), span: sp}; diff --git a/src/comp/syntax/print/pp.rs b/src/comp/syntax/print/pp.rs index 3ad514fdb2e..d5d7a7125ff 100644 --- a/src/comp/syntax/print/pp.rs +++ b/src/comp/syntax/print/pp.rs @@ -62,33 +62,37 @@ type break_t = {offset: int, blank_space: int}; type begin_t = {offset: int, breaks: breaks}; -tag token { STRING(str, int); BREAK(break_t); BEGIN(begin_t); END; EOF; } +tag token { STRING(istr, int); BREAK(break_t); BEGIN(begin_t); END; EOF; } -fn tok_str(t: token) -> str { +fn tok_str(t: token) -> istr { alt t { - STRING(s, len) { ret #fmt["STR(%s,%d)", s, len]; } - BREAK(_) { ret "BREAK"; } - BEGIN(_) { ret "BEGIN"; } - END. { ret "END"; } - EOF. { ret "EOF"; } + STRING(s, len) { + ret istr::from_estr( + #fmt["STR(%s,%d)", istr::to_estr(s), len]); + } + BREAK(_) { ret ~"BREAK"; } + BEGIN(_) { ret ~"BEGIN"; } + END. { ret ~"END"; } + EOF. { ret ~"EOF"; } } } fn buf_str(toks: &[mutable token], szs: &[mutable int], left: uint, - right: uint, lim: uint) -> str { + right: uint, lim: uint) -> istr { let n = vec::len(toks); assert (n == vec::len(szs)); let i = left; let L = lim; - let s = "["; + let s = ~"["; while i != right && L != 0u { L -= 1u; - if i != left { s += ", "; } - s += #fmt["%d=%s", szs[i], tok_str(toks[i])]; + if i != left { s += ~", "; } + s += istr::from_estr( + #fmt["%d=%s", szs[i], istr::to_estr(tok_str(toks[i]))]); i += 1u; i %= n; } - s += "]"; + s += ~"]"; ret s; } @@ -405,15 +409,16 @@ obj printer(out: io::writer, if n != 0u { top = print_stack[n - 1u]; } ret top; } - fn write_str(s: str) { + fn write_str(s: &istr) { while pending_indentation > 0 { out.write_str(~" "); pending_indentation -= 1; } - out.write_str(istr::from_estr(s)); + out.write_str(s); } fn print(x: token, L: int) { - log #fmt["print %s %d (remaining line space=%d)", tok_str(x), L, + log #fmt["print %s %d (remaining line space=%d)", + istr::to_estr(tok_str(x)), L, space]; log buf_str(token, size, left, right, 6u); alt x { @@ -493,15 +498,15 @@ fn end(p: printer) { p.pretty_print(END); } fn eof(p: printer) { p.pretty_print(EOF); } -fn word(p: printer, wrd: str) { - p.pretty_print(STRING(wrd, str::char_len(wrd) as int)); +fn word(p: printer, wrd: &istr) { + p.pretty_print(STRING(wrd, istr::char_len(wrd) as int)); } -fn huge_word(p: printer, wrd: str) { +fn huge_word(p: printer, wrd: &istr) { p.pretty_print(STRING(wrd, size_infinity)); } -fn zero_word(p: printer, wrd: str) { p.pretty_print(STRING(wrd, 0)); } +fn zero_word(p: printer, wrd: &istr) { p.pretty_print(STRING(wrd, 0)); } fn spaces(p: printer, n: uint) { break_offset(p, n, 0); } diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs index 7def22f8bd3..d98f1476b6b 100644 --- a/src/comp/syntax/print/pprust.rs +++ b/src/comp/syntax/print/pprust.rs @@ -75,11 +75,11 @@ const default_columns: uint = 78u; // Requires you to pass an input filename and reader so that // it can scan the input text for comments and literals to // copy forward. -fn print_crate(cm: &codemap, crate: @ast::crate, filename: str, +fn print_crate(cm: &codemap, crate: @ast::crate, filename: &istr, in: io::reader, out: io::writer, ann: &pp_ann) { let boxes: [pp::breaks] = []; let r = lexer::gather_comments_and_literals( - cm, istr::from_estr(filename), in); + cm, filename, in); let s = @{s: pp::mk_printer(out, default_columns), cm: some(cm), @@ -94,30 +94,30 @@ fn print_crate(cm: &codemap, crate: @ast::crate, filename: str, eof(s.s); } -fn ty_to_str(ty: &@ast::ty) -> str { be to_str(ty, print_type); } +fn ty_to_str(ty: &@ast::ty) -> istr { be to_str(ty, print_type); } -fn pat_to_str(pat: &@ast::pat) -> str { be to_str(pat, print_pat); } +fn pat_to_str(pat: &@ast::pat) -> istr { be to_str(pat, print_pat); } -fn expr_to_str(e: &@ast::expr) -> str { be to_str(e, print_expr); } +fn expr_to_str(e: &@ast::expr) -> istr { be to_str(e, print_expr); } -fn stmt_to_str(s: &ast::stmt) -> str { be to_str(s, print_stmt); } +fn stmt_to_str(s: &ast::stmt) -> istr { be to_str(s, print_stmt); } -fn item_to_str(i: &@ast::item) -> str { be to_str(i, print_item); } +fn item_to_str(i: &@ast::item) -> istr { be to_str(i, print_item); } -fn path_to_str(p: &ast::path) -> str { +fn path_to_str(p: &ast::path) -> istr { be to_str(p, bind print_path(_, _, false)); } fn fun_to_str(f: &ast::_fn, name: &ast::ident, - params: &[ast::ty_param]) -> str { + params: &[ast::ty_param]) -> istr { let writer = io::string_writer(); let s = rust_printer(writer.get_writer()); print_fn(s, f.decl, f.proto, name, params, f.decl.constraints); eof(s.s); - ret istr::to_estr(writer.get_str()); + ret writer.get_str(); } -fn block_to_str(blk: &ast::blk) -> str { +fn block_to_str(blk: &ast::blk) -> istr { let writer = io::string_writer(); let s = rust_printer(writer.get_writer()); // containing cbox, will be closed by print-block at } @@ -128,14 +128,14 @@ fn block_to_str(blk: &ast::blk) -> str { ibox(s, 0u); print_block(s, blk); eof(s.s); - ret istr::to_estr(writer.get_str()); + ret writer.get_str(); } -fn meta_item_to_str(mi: &ast::meta_item) -> str { +fn meta_item_to_str(mi: &ast::meta_item) -> istr { ret to_str(@mi, print_meta_item); } -fn attribute_to_str(attr: &ast::attribute) -> str { +fn attribute_to_str(attr: &ast::attribute) -> istr { be to_str(attr, print_attribute); } @@ -143,34 +143,34 @@ fn cbox(s: &ps, u: uint) { s.boxes += [pp::consistent]; pp::cbox(s.s, u); } fn box(s: &ps, u: uint, b: pp::breaks) { s.boxes += [b]; pp::box(s.s, u, b); } -fn nbsp(s: &ps) { word(s.s, " "); } +fn nbsp(s: &ps) { word(s.s, ~" "); } -fn word_nbsp(s: &ps, w: str) { word(s.s, w); nbsp(s); } +fn word_nbsp(s: &ps, w: &istr) { word(s.s, w); nbsp(s); } -fn word_space(s: &ps, w: str) { word(s.s, w); space(s.s); } +fn word_space(s: &ps, w: &istr) { word(s.s, w); space(s.s); } -fn popen(s: &ps) { word(s.s, "("); } +fn popen(s: &ps) { word(s.s, ~"("); } -fn pclose(s: &ps) { word(s.s, ")"); } +fn pclose(s: &ps) { word(s.s, ~")"); } -fn head(s: &ps, w: str) { +fn head(s: &ps, w: &istr) { // outer-box is consistent cbox(s, indent_unit); // head-box is inconsistent - ibox(s, str::char_len(w) + 1u); + ibox(s, istr::char_len(w) + 1u); // keyword that starts the head word_nbsp(s, w); } fn bopen(s: &ps) { - word(s.s, "{"); + word(s.s, ~"{"); end(s); // close the head-box } fn bclose_(s: &ps, span: codemap::span, indented: uint) { maybe_print_comment(s, span.hi); break_offset_if_not_bol(s, 1u, -(indented as int)); - word(s.s, "}"); + word(s.s, ~"}"); end(s); // close the outer-box } fn bclose(s: &ps, span: codemap::span) { bclose_(s, span, indent_unit); } @@ -205,19 +205,19 @@ fn break_offset_if_not_bol(s: &ps, n: uint, off: int) { // Synthesizes a comment that was not textually present in the original source // file. -fn synth_comment(s: &ps, text: str) { - word(s.s, "/*"); +fn synth_comment(s: &ps, text: &istr) { + word(s.s, ~"/*"); space(s.s); word(s.s, text); space(s.s); - word(s.s, "*/"); + word(s.s, ~"*/"); } fn commasep(s: &ps, b: breaks, elts: &[IN], op: fn(&ps, &IN)) { box(s, 0u, b); let first = true; for elt: IN in elts { - if first { first = false; } else { word_space(s, ","); } + if first { first = false; } else { word_space(s, ~","); } op(s, elt); } end(s); @@ -234,7 +234,7 @@ fn commasep_cmnt(s: &ps, b: breaks, elts: &[IN], op: fn(&ps, &IN), op(s, elt); i += 1u; if i < len { - word(s.s, ","); + word(s.s, ~","); maybe_print_trailing_comment(s, get_span(elt), some(get_span(elts[i]).hi)); space_if_not_bol(s); @@ -269,52 +269,54 @@ fn print_type(s: &ps, ty: &@ast::ty) { maybe_print_comment(s, ty.span.lo); ibox(s, 0u); alt ty.node { - ast::ty_nil. { word(s.s, "()"); } - ast::ty_bool. { word(s.s, "bool"); } - ast::ty_bot. { word(s.s, "!"); } - ast::ty_int. { word(s.s, "int"); } - ast::ty_uint. { word(s.s, "uint"); } - ast::ty_float. { word(s.s, "float"); } - ast::ty_machine(tm) { word(s.s, ast_util::ty_mach_to_str(tm)); } - ast::ty_char. { word(s.s, "char"); } - ast::ty_str. { word(s.s, "str"); } - ast::ty_istr. { word(s.s, "istr"); } - ast::ty_box(mt) { word(s.s, "@"); print_mt(s, mt); } + ast::ty_nil. { word(s.s, ~"()"); } + ast::ty_bool. { word(s.s, ~"bool"); } + ast::ty_bot. { word(s.s, ~"!"); } + ast::ty_int. { word(s.s, ~"int"); } + ast::ty_uint. { word(s.s, ~"uint"); } + ast::ty_float. { word(s.s, ~"float"); } + ast::ty_machine(tm) { + word(s.s, istr::from_estr(ast_util::ty_mach_to_str(tm))); + } + ast::ty_char. { word(s.s, ~"char"); } + ast::ty_str. { word(s.s, ~"str"); } + ast::ty_istr. { word(s.s, ~"istr"); } + ast::ty_box(mt) { word(s.s, ~"@"); print_mt(s, mt); } ast::ty_vec(mt) { - word(s.s, "["); + word(s.s, ~"["); alt mt.mut { - ast::mut. { word_space(s, "mutable"); } - ast::maybe_mut. { word_space(s, "mutable?"); } + ast::mut. { word_space(s, ~"mutable"); } + ast::maybe_mut. { word_space(s, ~"mutable?"); } ast::imm. { } } print_type(s, mt.ty); - word(s.s, "]"); + word(s.s, ~"]"); } - ast::ty_ptr(mt) { word(s.s, "*"); print_mt(s, mt); } - ast::ty_task. { word(s.s, "task"); } + ast::ty_ptr(mt) { word(s.s, ~"*"); print_mt(s, mt); } + ast::ty_task. { word(s.s, ~"task"); } ast::ty_port(t) { - word(s.s, "port<"); + word(s.s, ~"port<"); print_type(s, t); - word(s.s, ">"); + word(s.s, ~">"); } ast::ty_chan(t) { - word(s.s, "chan<"); + word(s.s, ~"chan<"); print_type(s, t); - word(s.s, ">"); + word(s.s, ~">"); } ast::ty_rec(fields) { - word(s.s, "{"); + word(s.s, ~"{"); fn print_field(s: &ps, f: &ast::ty_field) { cbox(s, indent_unit); print_mutability(s, f.node.mt.mut); - word(s.s, istr::to_estr(f.node.ident)); - word_space(s, ":"); + word(s.s, f.node.ident); + word_space(s, ~":"); print_type(s, f.node.mt.ty); end(s); } fn get_span(f: &ast::ty_field) -> codemap::span { ret f.span; } commasep_cmnt(s, consistent, fields, print_field, get_span); - word(s.s, "}"); + word(s.s, ~"}"); } ast::ty_tup(elts) { popen(s); @@ -325,7 +327,7 @@ fn print_type(s: &ps, ty: &@ast::ty) { print_ty_fn(s, proto, none::, inputs, output, cf, constrs); } ast::ty_obj(methods) { - head(s, "obj"); + head(s, ~"obj"); bopen(s); for m: ast::ty_method in methods { hardbreak_if_not_bol(s); @@ -333,13 +335,13 @@ fn print_type(s: &ps, ty: &@ast::ty) { maybe_print_comment(s, m.span.lo); print_ty_fn(s, m.node.proto, some(m.node.ident), m.node.inputs, m.node.output, m.node.cf, m.node.constrs); - word(s.s, ";"); + word(s.s, ~";"); end(s); } bclose(s, ty.span); } ast::ty_path(path, _) { print_path(s, path, false); } - ast::ty_type. { word(s.s, "type"); } + ast::ty_type. { word(s.s, ~"type"); } ast::ty_constr(t, cs) { print_type(s, t); space(s.s); @@ -357,10 +359,10 @@ fn print_native_item(s: &ps, item: &@ast::native_item) { ast::native_item_ty. { ibox(s, indent_unit); ibox(s, 0u); - word_nbsp(s, "type"); - word(s.s, istr::to_estr(item.ident)); + word_nbsp(s, ~"type"); + word(s.s, item.ident); end(s); // end the inner ibox - word(s.s, ";"); + word(s.s, ~";"); end(s); // end the outer ibox } @@ -374,12 +376,12 @@ fn print_native_item(s: &ps, item: &@ast::native_item) { none. { } some(ss) { space(s.s); - word_space(s, "="); - print_string(s, istr::to_estr(ss)); + word_space(s, ~"="); + print_string(s, ss); } } end(s); // end head-ibox - word(s.s, ";"); + word(s.s, ~";"); end(s); // end the outer fn box } } @@ -393,47 +395,47 @@ fn print_item(s: &ps, item: &@ast::item) { s.ann.pre(ann_node); alt item.node { ast::item_const(ty, expr) { - head(s, "const"); - word_space(s, istr::to_estr(item.ident) + ":"); + head(s, ~"const"); + word_space(s, item.ident + ~":"); print_type(s, ty); space(s.s); end(s); // end the head-ibox - word_space(s, "="); + word_space(s, ~"="); print_expr(s, expr); - word(s.s, ";"); + word(s.s, ~";"); end(s); // end the outer cbox } ast::item_fn(_fn, typarams) { print_fn(s, _fn.decl, _fn.proto, item.ident, typarams, _fn.decl.constraints); - word(s.s, " "); + word(s.s, ~" "); print_block(s, _fn.body); } ast::item_mod(_mod) { - head(s, "mod"); - word_nbsp(s, istr::to_estr(item.ident)); + head(s, ~"mod"); + word_nbsp(s, item.ident); bopen(s); print_mod(s, _mod, item.attrs); bclose(s, item.span); } ast::item_native_mod(nmod) { - head(s, "native"); + head(s, ~"native"); alt nmod.abi { - ast::native_abi_llvm. { word_nbsp(s, "\"llvm\""); } - ast::native_abi_rust. { word_nbsp(s, "\"rust\""); } - ast::native_abi_cdecl. { word_nbsp(s, "\"cdecl\""); } + ast::native_abi_llvm. { word_nbsp(s, ~"\"llvm\""); } + ast::native_abi_rust. { word_nbsp(s, ~"\"rust\""); } + ast::native_abi_cdecl. { word_nbsp(s, ~"\"cdecl\""); } ast::native_abi_rust_intrinsic. { - word_nbsp(s, "\"rust-intrinsic\""); + word_nbsp(s, ~"\"rust-intrinsic\""); } - ast::native_abi_x86stdcall. { word_nbsp(s, "\"x86stdcall\""); } + ast::native_abi_x86stdcall. { word_nbsp(s, ~"\"x86stdcall\""); } } - word_nbsp(s, "mod"); - word_nbsp(s, istr::to_estr(item.ident)); + word_nbsp(s, ~"mod"); + word_nbsp(s, item.ident); if !istr::eq(nmod.native_name, item.ident) { - word_space(s, "="); - print_string(s, istr::to_estr(nmod.native_name)); + word_space(s, ~"="); + print_string(s, nmod.native_name); nbsp(s); } bopen(s); @@ -443,15 +445,15 @@ fn print_item(s: &ps, item: &@ast::item) { ast::item_ty(ty, params) { ibox(s, indent_unit); ibox(s, 0u); - word_nbsp(s, "type"); - word(s.s, istr::to_estr(item.ident)); + word_nbsp(s, ~"type"); + word(s.s, item.ident); print_type_params(s, params); end(s); // end the inner ibox space(s.s); - word_space(s, "="); + word_space(s, ~"="); print_type(s, ty); - word(s.s, ";"); + word(s.s, ~";"); end(s); // end the outer ibox } ast::item_tag(variants, params) { @@ -461,22 +463,22 @@ fn print_item(s: &ps, item: &@ast::item) { vec::len(variants[0].node.args) == 1u; if newtype { ibox(s, indent_unit); - word_space(s, "tag"); - } else { head(s, "tag"); } - word(s.s, istr::to_estr(item.ident)); + word_space(s, ~"tag"); + } else { head(s, ~"tag"); } + word(s.s, item.ident); print_type_params(s, params); space(s.s); if newtype { - word_space(s, "="); + word_space(s, ~"="); print_type(s, variants[0].node.args[0].ty); - word(s.s, ";"); + word(s.s, ~";"); end(s); } else { bopen(s); for v: ast::variant in variants { space_if_not_bol(s); maybe_print_comment(s, v.span.lo); - word(s.s, istr::to_estr(v.node.name)); + word(s.s, v.node.name); if vec::len(v.node.args) > 0u { popen(s); fn print_variant_arg(s: &ps, arg: &ast::variant_arg) { @@ -485,21 +487,21 @@ fn print_item(s: &ps, item: &@ast::item) { commasep(s, consistent, v.node.args, print_variant_arg); pclose(s); } - word(s.s, ";"); + word(s.s, ~";"); maybe_print_trailing_comment(s, v.span, none::); } bclose(s, item.span); } } ast::item_obj(_obj, params, _) { - head(s, "obj"); - word(s.s, istr::to_estr(item.ident)); + head(s, ~"obj"); + word(s.s, item.ident); print_type_params(s, params); popen(s); fn print_field(s: &ps, field: &ast::obj_field) { ibox(s, indent_unit); print_mutability(s, field.mut); - word_space(s, istr::to_estr(field.ident) + ":"); + word_space(s, field.ident + ~":"); print_type(s, field.ty); end(s); } @@ -514,17 +516,17 @@ fn print_item(s: &ps, item: &@ast::item) { maybe_print_comment(s, meth.span.lo); print_fn(s, meth.node.meth.decl, meth.node.meth.proto, meth.node.ident, typarams, []); - word(s.s, " "); + word(s.s, ~" "); print_block(s, meth.node.meth.body); } bclose(s, item.span); } ast::item_res(dt, dt_id, tps, ct_id) { - head(s, "resource"); - word(s.s, istr::to_estr(item.ident)); + head(s, ~"resource"); + word(s.s, item.ident); print_type_params(s, tps); popen(s); - word_space(s, istr::to_estr(dt.decl.inputs[0].ident) + ":"); + word_space(s, dt.decl.inputs[0].ident + ~":"); print_type(s, dt.decl.inputs[0].ty); pclose(s); space(s.s); @@ -551,7 +553,7 @@ fn print_inner_attributes(s: &ps, attrs: &[ast::attribute]) { alt attr.node.style { ast::attr_inner. { print_attribute(s, attr); - word(s.s, ";"); + word(s.s, ~";"); count += 1; } _ {/* fallthrough */ } @@ -563,9 +565,9 @@ fn print_inner_attributes(s: &ps, attrs: &[ast::attribute]) { fn print_attribute(s: &ps, attr: &ast::attribute) { hardbreak_if_not_bol(s); maybe_print_comment(s, attr.span.lo); - word(s.s, "#["); + word(s.s, ~"#["); print_meta_item(s, @attr.node.value); - word(s.s, "]"); + word(s.s, ~"]"); } fn print_stmt(s: &ps, st: &ast::stmt) { @@ -574,7 +576,7 @@ fn print_stmt(s: &ps, st: &ast::stmt) { ast::stmt_decl(decl, _) { print_decl(s, decl); } ast::stmt_expr(expr, _) { space_if_not_bol(s); print_expr(s, expr); } } - if parse::parser::stmt_ends_with_semi(st) { word(s.s, ";"); } + if parse::parser::stmt_ends_with_semi(st) { word(s.s, ~";"); } maybe_print_trailing_comment(s, st.span, none::); } @@ -587,7 +589,7 @@ tag embed_type { block_macro; block_block_fn; block_normal; } fn print_possibly_embedded_block(s: &ps, blk: &ast::blk, embedded: embed_type, indented: uint) { alt blk.node.rules { - ast::unchecked. { word(s.s, "unchecked"); } + ast::unchecked. { word(s.s, ~"unchecked"); } _ {} } @@ -595,7 +597,7 @@ fn print_possibly_embedded_block(s: &ps, blk: &ast::blk, embedded: embed_type, let ann_node = node_block(s, blk); s.ann.pre(ann_node); alt embedded { - block_macro. { word(s.s, "#{"); end(s); } + block_macro. { word(s.s, ~"#{"); end(s); } block_block_fn. { end(s); } block_normal. { bopen(s); } } @@ -649,7 +651,7 @@ fn print_possibly_embedded_block(s: &ps, blk: &ast::blk, embedded: embed_type, _ { false } }; - if last_expr_is_block && next_expr_is_ambig { word(s.s, ";"); } + if last_expr_is_block && next_expr_is_ambig { word(s.s, ~";"); } fn expr_is_ambig(ex: @ast::expr) -> bool { // We're going to walk the expression to the 'left' looking for @@ -712,8 +714,8 @@ fn print_maybe_parens_discrim(s: &ps, e: &@ast::expr) { fn print_if(s: &ps, test: &@ast::expr, blk: &ast::blk, elseopt: &option::t<@ast::expr>, chk: bool) { - head(s, "if"); - if chk { word_nbsp(s, "check"); } + head(s, ~"if"); + if chk { word_nbsp(s, ~"check"); } print_maybe_parens_discrim(s, test); space(s.s); print_block(s, blk); @@ -727,7 +729,7 @@ fn print_if(s: &ps, test: &@ast::expr, blk: &ast::blk, ast::expr_if(i, t, e) { cbox(s, indent_unit - 1u); ibox(s, 0u); - word(s.s, " else if "); + word(s.s, ~" else if "); print_expr(s, i); space(s.s); print_block(s, t); @@ -739,7 +741,7 @@ fn print_if(s: &ps, test: &@ast::expr, blk: &ast::blk, ast::expr_block(b) { cbox(s, indent_unit - 1u); ibox(s, 0u); - word(s.s, " else "); + word(s.s, ~" else "); print_block(s, b); } } @@ -753,21 +755,21 @@ fn print_if(s: &ps, test: &@ast::expr, blk: &ast::blk, fn print_mac(s: &ps, m: &ast::mac) { alt m.node { ast::mac_invoc(path, arg, body) { - word(s.s, "#"); + word(s.s, ~"#"); print_path(s, path, false); - alt arg.node { ast::expr_vec(_, _) { } _ { word(s.s, " "); } } + alt arg.node { ast::expr_vec(_, _) { } _ { word(s.s, ~" "); } } print_expr(s, arg); // FIXME: extension 'body' } ast::mac_embed_type(ty) { - word(s.s, "#<"); + word(s.s, ~"#<"); print_type(s, ty); - word(s.s, ">"); + word(s.s, ~">"); } ast::mac_embed_block(blk) { print_possibly_embedded_block(s, blk, block_normal, indent_unit); } - ast::mac_ellipsis. { word(s.s, "..."); } + ast::mac_ellipsis. { word(s.s, ~"..."); } } } @@ -779,38 +781,38 @@ fn print_expr(s: &ps, expr: &@ast::expr) { alt expr.node { ast::expr_vec(exprs, mut) { ibox(s, indent_unit); - word(s.s, "["); + word(s.s, ~"["); if mut == ast::mut { - word(s.s, "mutable"); + word(s.s, ~"mutable"); if vec::len(exprs) > 0u { nbsp(s); } } commasep_exprs(s, inconsistent, exprs); - word(s.s, "]"); + word(s.s, ~"]"); end(s); } ast::expr_rec(fields, wth) { fn print_field(s: &ps, field: &ast::field) { ibox(s, indent_unit); - if field.node.mut == ast::mut { word_nbsp(s, "mutable"); } - word(s.s, istr::to_estr(field.node.ident)); - word_space(s, ":"); + if field.node.mut == ast::mut { word_nbsp(s, ~"mutable"); } + word(s.s, field.node.ident); + word_space(s, ~":"); print_expr(s, field.node.expr); end(s); } fn get_span(field: &ast::field) -> codemap::span { ret field.span; } - word(s.s, "{"); + word(s.s, ~"{"); commasep_cmnt(s, consistent, fields, print_field, get_span); alt wth { some(expr) { if vec::len(fields) > 0u { space(s.s); } ibox(s, indent_unit); - word_space(s, "with"); + word_space(s, ~"with"); print_expr(s, expr); end(s); } _ { } } - word(s.s, "}"); + word(s.s, ~"}"); } ast::expr_tup(exprs) { popen(s); @@ -824,17 +826,17 @@ fn print_expr(s: &ps, expr: &@ast::expr) { pclose(s); } ast::expr_self_method(ident) { - word(s.s, "self."); + word(s.s, ~"self."); print_ident(s, ident); } ast::expr_bind(func, args) { fn print_opt(s: &ps, expr: &option::t<@ast::expr>) { alt expr { some(expr) { print_expr(s, expr); } - _ { word(s.s, "_"); } + _ { word(s.s, ~"_"); } } } - word_nbsp(s, "bind"); + word_nbsp(s, ~"bind"); print_expr(s, func); popen(s); commasep(s, inconsistent, args, print_opt); @@ -844,18 +846,18 @@ fn print_expr(s: &ps, expr: &@ast::expr) { let prec = operator_prec(op); print_maybe_parens(s, lhs, prec); space(s.s); - word_space(s, ast_util::binop_to_str(op)); + word_space(s, istr::from_estr(ast_util::binop_to_str(op))); print_maybe_parens(s, rhs, prec + 1); } ast::expr_unary(op, expr) { - word(s.s, ast_util::unop_to_str(op)); + word(s.s, istr::from_estr(ast_util::unop_to_str(op))); print_maybe_parens(s, expr, parse::parser::unop_prec); } ast::expr_lit(lit) { print_literal(s, lit); } ast::expr_cast(expr, ty) { print_maybe_parens(s, expr, parse::parser::as_prec); space(s.s); - word_space(s, "as"); + word_space(s, ~"as"); print_type(s, ty); } ast::expr_if(test, blk, elseopt) { @@ -867,42 +869,42 @@ fn print_expr(s: &ps, expr: &@ast::expr) { ast::expr_ternary(test, then, els) { print_expr(s, test); space(s.s); - word_space(s, "?"); + word_space(s, ~"?"); print_expr(s, then); space(s.s); - word_space(s, ":"); + word_space(s, ~":"); print_expr(s, els); } ast::expr_while(test, blk) { - head(s, "while"); + head(s, ~"while"); print_maybe_parens_discrim(s, test); space(s.s); print_block(s, blk); } ast::expr_for(decl, expr, blk) { - head(s, "for"); + head(s, ~"for"); print_for_decl(s, decl, expr); space(s.s); print_block(s, blk); } ast::expr_for_each(decl, expr, blk) { - head(s, "for each"); + head(s, ~"for each"); print_for_decl(s, decl, expr); space(s.s); print_block(s, blk); } ast::expr_do_while(blk, expr) { - head(s, "do"); + head(s, ~"do"); space(s.s); print_block(s, blk); space(s.s); - word_space(s, "while"); + word_space(s, ~"while"); print_expr(s, expr); } ast::expr_alt(expr, arms) { cbox(s, alt_indent_unit); ibox(s, 4u); - word_nbsp(s, "alt"); + word_nbsp(s, ~"alt"); print_maybe_parens_discrim(s, expr); space(s.s); bopen(s); @@ -914,13 +916,13 @@ fn print_expr(s: &ps, expr: &@ast::expr) { for p: @ast::pat in arm.pats { if first { first = false; - } else { space(s.s); word_space(s, "|"); } + } else { space(s.s); word_space(s, ~"|"); } print_pat(s, p); } space(s.s); alt arm.guard { some(e) { - word_space(s, "when"); + word_space(s, ~"when"); print_expr(s, e); space(s.s); } @@ -940,7 +942,7 @@ fn print_expr(s: &ps, expr: &@ast::expr) { cbox(s, indent_unit); // head-box, will be closed by print-block at start ibox(s, 0u); - word(s.s, "{"); + word(s.s, ~"{"); print_fn_block_args(s, f.decl); print_possibly_embedded_block(s, f.body, block_block_fn, indent_unit); @@ -958,100 +960,102 @@ fn print_expr(s: &ps, expr: &@ast::expr) { ibox(s, 0u); print_block(s, blk); } - ast::expr_copy(e) { word_space(s, "copy"); print_expr(s, e); } + ast::expr_copy(e) { word_space(s, ~"copy"); print_expr(s, e); } ast::expr_move(lhs, rhs) { print_expr(s, lhs); space(s.s); - word_space(s, "<-"); + word_space(s, ~"<-"); print_expr(s, rhs); } ast::expr_assign(lhs, rhs) { print_expr(s, lhs); space(s.s); - word_space(s, "="); + word_space(s, ~"="); print_expr(s, rhs); } ast::expr_swap(lhs, rhs) { print_expr(s, lhs); space(s.s); - word_space(s, "<->"); + word_space(s, ~"<->"); print_expr(s, rhs); } ast::expr_assign_op(op, lhs, rhs) { print_expr(s, lhs); space(s.s); - word(s.s, ast_util::binop_to_str(op)); - word_space(s, "="); + word(s.s, istr::from_estr(ast_util::binop_to_str(op))); + word_space(s, ~"="); print_expr(s, rhs); } ast::expr_field(expr, id) { print_expr_parens_if_unary(s, expr); - word(s.s, "."); - word(s.s, istr::to_estr(id)); + word(s.s, ~"."); + word(s.s, id); } ast::expr_index(expr, index) { print_expr_parens_if_unary(s, expr); - word(s.s, "["); + word(s.s, ~"["); print_expr(s, index); - word(s.s, "]"); + word(s.s, ~"]"); } ast::expr_path(path) { print_path(s, path, true); } ast::expr_fail(maybe_fail_val) { - word(s.s, "fail"); + word(s.s, ~"fail"); alt maybe_fail_val { - some(expr) { word(s.s, " "); print_expr(s, expr); } + some(expr) { word(s.s, ~" "); print_expr(s, expr); } _ { } } } - ast::expr_break. { word(s.s, "break"); } - ast::expr_cont. { word(s.s, "cont"); } + ast::expr_break. { word(s.s, ~"break"); } + ast::expr_cont. { word(s.s, ~"cont"); } ast::expr_ret(result) { - word(s.s, "ret"); + word(s.s, ~"ret"); alt result { - some(expr) { word(s.s, " "); print_expr(s, expr); } + some(expr) { word(s.s, ~" "); print_expr(s, expr); } _ { } } } ast::expr_put(result) { - word(s.s, "put"); + word(s.s, ~"put"); alt result { - some(expr) { word(s.s, " "); print_expr(s, expr); } + some(expr) { word(s.s, ~" "); print_expr(s, expr); } _ { } } } - ast::expr_be(result) { word_nbsp(s, "be"); print_expr(s, result); } + ast::expr_be(result) { word_nbsp(s, ~"be"); print_expr(s, result); } ast::expr_log(lvl, expr) { - alt lvl { 1 { word_nbsp(s, "log"); } 0 { word_nbsp(s, "log_err"); } } + alt lvl { + 1 { word_nbsp(s, ~"log"); } 0 { word_nbsp(s, ~"log_err"); } + } print_expr(s, expr); } ast::expr_check(m, expr) { alt m { - ast::unchecked. { word_nbsp(s, "claim"); } - ast::checked. { word_nbsp(s, "check"); } + ast::unchecked. { word_nbsp(s, ~"claim"); } + ast::checked. { word_nbsp(s, ~"check"); } } popen(s); print_expr(s, expr); pclose(s); } ast::expr_assert(expr) { - word_nbsp(s, "assert"); + word_nbsp(s, ~"assert"); popen(s); print_expr(s, expr); pclose(s); } ast::expr_mac(m) { print_mac(s, m); } ast::expr_anon_obj(anon_obj) { - head(s, "obj"); + head(s, ~"obj"); // Fields popen(s); fn print_field(s: &ps, field: &ast::anon_obj_field) { ibox(s, indent_unit); print_mutability(s, field.mut); - word_space(s, istr::to_estr(field.ident) + ":"); + word_space(s, field.ident + ~":"); print_type(s, field.ty); space(s.s); - word_space(s, "="); + word_space(s, ~"="); print_expr(s, field.expr); end(s); } @@ -1075,18 +1079,18 @@ fn print_expr(s: &ps, expr: &@ast::expr) { maybe_print_comment(s, meth.span.lo); print_fn(s, meth.node.meth.decl, meth.node.meth.proto, meth.node.ident, typarams, []); - word(s.s, " "); + word(s.s, ~" "); print_block(s, meth.node.meth.body); } // With object alt anon_obj.inner_obj { none. { } - some(e) { space(s.s); word_space(s, "with"); print_expr(s, e); } + some(e) { space(s.s); word_space(s, ~"with"); print_expr(s, e); } } bclose(s, expr.span); } - ast::expr_uniq(expr) { word(s.s, "~"); print_expr(s, expr); } + ast::expr_uniq(expr) { word(s.s, ~"~"); print_expr(s, expr); } } s.ann.post(ann_node); end(s); @@ -1103,7 +1107,7 @@ fn print_local_decl(s: &ps, loc: &@ast::local) { print_pat(s, loc.node.pat); alt loc.node.ty.node { ast::ty_infer. { } - _ { word_space(s, ":"); print_type(s, loc.node.ty); } + _ { word_space(s, ~":"); print_type(s, loc.node.ty); } } } @@ -1113,7 +1117,7 @@ fn print_decl(s: &ps, decl: &@ast::decl) { ast::decl_local(locs) { space_if_not_bol(s); ibox(s, indent_unit); - word_nbsp(s, "let"); + word_nbsp(s, ~"let"); fn print_local(s: &ps, loc: &@ast::local) { ibox(s, indent_unit); print_local_decl(s, loc); @@ -1122,8 +1126,8 @@ fn print_decl(s: &ps, decl: &@ast::decl) { some(init) { nbsp(s); alt init.op { - ast::init_assign. { word_space(s, "="); } - ast::init_move. { word_space(s, "<-"); } + ast::init_assign. { word_space(s, ~"="); } + ast::init_move. { word_space(s, ~"<-"); } } print_expr(s, init.expr); } @@ -1138,29 +1142,29 @@ fn print_decl(s: &ps, decl: &@ast::decl) { } fn print_ident(s: &ps, ident: &ast::ident) { - word(s.s, istr::to_estr(ident)); + word(s.s, ident); } fn print_for_decl(s: &ps, loc: &@ast::local, coll: &@ast::expr) { print_local_decl(s, loc); space(s.s); - word_space(s, "in"); + word_space(s, ~"in"); print_expr(s, coll); } fn print_path(s: &ps, path: &ast::path, colons_before_params: bool) { maybe_print_comment(s, path.span.lo); - if path.node.global { word(s.s, "::"); } + if path.node.global { word(s.s, ~"::"); } let first = true; for id: ast::ident in path.node.idents { - if first { first = false; } else { word(s.s, "::"); } - word(s.s, istr::to_estr(id)); + if first { first = false; } else { word(s.s, ~"::"); } + word(s.s, id); } if vec::len(path.node.types) > 0u { - if colons_before_params { word(s.s, "::"); } - word(s.s, "<"); + if colons_before_params { word(s.s, ~"::"); } + word(s.s, ~"<"); commasep(s, inconsistent, path.node.types, print_type); - word(s.s, ">"); + word(s.s, ~">"); } } @@ -1169,8 +1173,8 @@ fn print_pat(s: &ps, pat: &@ast::pat) { let ann_node = node_pat(s, pat); s.ann.pre(ann_node); alt pat.node { - ast::pat_wild. { word(s.s, "_"); } - ast::pat_bind(id) { word(s.s, istr::to_estr(id)); } + ast::pat_wild. { word(s.s, ~"_"); } + ast::pat_bind(id) { word(s.s, id); } ast::pat_lit(lit) { print_literal(s, lit); } ast::pat_tag(path, args) { print_path(s, path, true); @@ -1178,31 +1182,31 @@ fn print_pat(s: &ps, pat: &@ast::pat) { popen(s); commasep(s, inconsistent, args, print_pat); pclose(s); - } else { word(s.s, "."); } + } else { word(s.s, ~"."); } } ast::pat_rec(fields, etc) { - word(s.s, "{"); + word(s.s, ~"{"); fn print_field(s: &ps, f: &ast::field_pat) { cbox(s, indent_unit); - word(s.s, istr::to_estr(f.ident)); - word_space(s, ":"); + word(s.s, f.ident); + word_space(s, ~":"); print_pat(s, f.pat); end(s); } fn get_span(f: &ast::field_pat) -> codemap::span { ret f.pat.span; } commasep_cmnt(s, consistent, fields, print_field, get_span); if etc { - if vec::len(fields) != 0u { word_space(s, ","); } - word(s.s, "_"); + if vec::len(fields) != 0u { word_space(s, ~","); } + word(s.s, ~"_"); } - word(s.s, "}"); + word(s.s, ~"}"); } ast::pat_tup(elts) { popen(s); commasep(s, inconsistent, elts, print_pat); pclose(s); } - ast::pat_box(inner) { word(s.s, "@"); print_pat(s, inner); } + ast::pat_box(inner) { word(s.s, ~"@"); print_pat(s, inner); } } s.ann.post(ann_node); } @@ -1211,9 +1215,9 @@ fn print_fn(s: &ps, decl: ast::fn_decl, proto: ast::proto, name: &ast::ident, typarams: &[ast::ty_param], constrs: [@ast::constr]) { alt decl.purity { ast::impure_fn. { head(s, proto_to_str(proto)); } - _ { head(s, "pure fn"); } + _ { head(s, ~"pure fn"); } } - word(s.s, istr::to_estr(name)); + word(s.s, name); print_type_params(s, typarams); print_fn_args_and_ret(s, decl, constrs); } @@ -1223,7 +1227,7 @@ fn print_fn_args_and_ret(s: &ps, decl: &ast::fn_decl, popen(s); fn print_arg(s: &ps, x: &ast::arg) { ibox(s, indent_unit); - word_space(s, istr::to_estr(x.ident) + ":"); + word_space(s, x.ident + ~":"); print_alias(s, x.mode); print_type(s, x.ty); end(s); @@ -1234,64 +1238,64 @@ fn print_fn_args_and_ret(s: &ps, decl: &ast::fn_decl, maybe_print_comment(s, decl.output.span.lo); if decl.output.node != ast::ty_nil { space_if_not_bol(s); - word_space(s, "->"); + word_space(s, ~"->"); print_type(s, decl.output); } } fn print_fn_block_args(s: &ps, decl: &ast::fn_decl) { - word(s.s, "|"); + word(s.s, ~"|"); fn print_arg(s: &ps, x: &ast::arg) { ibox(s, indent_unit); print_alias(s, x.mode); - word(s.s, istr::to_estr(x.ident)); + word(s.s, x.ident); end(s); } commasep(s, inconsistent, decl.inputs, print_arg); - word(s.s, "|"); + word(s.s, ~"|"); maybe_print_comment(s, decl.output.span.lo); } fn print_alias(s: &ps, m: ast::mode) { alt m { - ast::alias(true) { word_space(s, "&mutable"); } - ast::alias(false) { word(s.s, "&"); } - ast::move. { word(s.s, "-"); } + ast::alias(true) { word_space(s, ~"&mutable"); } + ast::alias(false) { word(s.s, ~"&"); } + ast::move. { word(s.s, ~"-"); } ast::val. { } } } fn print_kind(s: &ps, kind: ast::kind) { alt kind { - ast::kind_unique. { word(s.s, "~"); } - ast::kind_shared. { word(s.s, "@"); } + ast::kind_unique. { word(s.s, ~"~"); } + ast::kind_shared. { word(s.s, ~"@"); } _ {/* fallthrough */ } } } fn print_type_params(s: &ps, params: &[ast::ty_param]) { if vec::len(params) > 0u { - word(s.s, "<"); + word(s.s, ~"<"); fn printParam(s: &ps, param: &ast::ty_param) { print_kind(s, param.kind); - word(s.s, istr::to_estr(param.ident)); + word(s.s, param.ident); } commasep(s, inconsistent, params, printParam); - word(s.s, ">"); + word(s.s, ~">"); } } fn print_meta_item(s: &ps, item: &@ast::meta_item) { ibox(s, indent_unit); alt item.node { - ast::meta_word(name) { word(s.s, istr::to_estr(name)); } + ast::meta_word(name) { word(s.s, name); } ast::meta_name_value(name, value) { - word_space(s, istr::to_estr(name)); - word_space(s, "="); + word_space(s, name); + word_space(s, ~"="); print_literal(s, @value); } ast::meta_list(name, items) { - word(s.s, istr::to_estr(name)); + word(s.s, name); popen(s); commasep(s, consistent, items, print_meta_item); pclose(s); @@ -1305,8 +1309,8 @@ fn print_view_item(s: &ps, item: &@ast::view_item) { maybe_print_comment(s, item.span.lo); alt item.node { ast::view_item_use(id, mta, _) { - head(s, "use"); - word(s.s, istr::to_estr(id)); + head(s, ~"use"); + word(s.s, id); if vec::len(mta) > 0u { popen(s); commasep(s, consistent, mta, print_meta_item); @@ -1314,47 +1318,47 @@ fn print_view_item(s: &ps, item: &@ast::view_item) { } } ast::view_item_import(id, ids, _) { - head(s, "import"); + head(s, ~"import"); if !istr::eq(id, ids[vec::len(ids) - 1u]) { - word_space(s, istr::to_estr(id)); - word_space(s, "="); + word_space(s, id); + word_space(s, ~"="); } let first = true; for elt: ast::ident in ids { - if first { first = false; } else { word(s.s, "::"); } - word(s.s, istr::to_estr(elt)); + if first { first = false; } else { word(s.s, ~"::"); } + word(s.s, elt); } } ast::view_item_import_from(mod_path, idents, _) { - head(s, "import"); + head(s, ~"import"); for elt: ast::ident in mod_path { - word(s.s, istr::to_estr(elt)); word(s.s, "::"); + word(s.s, elt); word(s.s, ~"::"); } - word(s.s, "{"); + word(s.s, ~"{"); commasep(s, inconsistent, idents, fn (s: &ps, w: &ast::import_ident) { - word(s.s, istr::to_estr(w.node.name)) + word(s.s, w.node.name) }); - word(s.s, "}"); + word(s.s, ~"}"); } ast::view_item_import_glob(ids, _) { - head(s, "import"); + head(s, ~"import"); let first = true; for elt: ast::ident in ids { - if first { first = false; } else { word(s.s, "::"); } - word(s.s, istr::to_estr(elt)); + if first { first = false; } else { word(s.s, ~"::"); } + word(s.s, elt); } - word(s.s, "::*"); + word(s.s, ~"::*"); } ast::view_item_export(ids, _) { - head(s, "export"); + head(s, ~"export"); commasep(s, inconsistent, ids, fn (s: &ps, w: &ast::ident) { - word(s.s, istr::to_estr(w)) + word(s.s, w) }); } } - word(s.s, ";"); + word(s.s, ~";"); end(s); // end inner head-block end(s); // end outer head-block @@ -1404,8 +1408,8 @@ fn print_maybe_parens(s: &ps, expr: &@ast::expr, outer_prec: int) { fn print_mutability(s: &ps, mut: &ast::mutability) { alt mut { - ast::mut. { word_nbsp(s, "mutable"); } - ast::maybe_mut. { word_nbsp(s, "mutable?"); } + ast::mut. { word_nbsp(s, ~"mutable"); } + ast::maybe_mut. { word_nbsp(s, ~"mutable?"); } ast::imm. {/* nothing */ } } } @@ -1422,8 +1426,8 @@ fn print_ty_fn(s: &ps, proto: &ast::proto, id: &option::t, word(s.s, proto_to_str(proto)); alt id { some(id) { - word(s.s, " "); - word(s.s, istr::to_estr(id)); + word(s.s, ~" "); + word(s.s, id); } _ { } } @@ -1439,10 +1443,10 @@ fn print_ty_fn(s: &ps, proto: &ast::proto, id: &option::t, if output.node != ast::ty_nil { space_if_not_bol(s); ibox(s, indent_unit); - word_space(s, "->"); + word_space(s, ~"->"); alt cf { ast::return. { print_type(s, output); } - ast::noreturn. { word_nbsp(s, "!"); } + ast::noreturn. { word_nbsp(s, ~"!"); } } end(s); } @@ -1497,10 +1501,10 @@ fn print_literal(s: &ps, lit: &@ast::lit) { // FIXME: This is a hack until istrs replace strings, since // istrs are prefixed with a token that is not part of the literal alt lit.node { - ast::lit_str(_, ast::sk_unique.) { word(s.s, "~"); } + ast::lit_str(_, ast::sk_unique.) { word(s.s, ~"~"); } _ { } } - word(s.s, istr::to_estr(lt.lit)); + word(s.s, lt.lit); s.cur_lit += 1u; ret; } @@ -1509,34 +1513,34 @@ fn print_literal(s: &ps, lit: &@ast::lit) { } alt lit.node { ast::lit_str(st, kind) { - if kind == ast::sk_unique { word(s.s, "~"); } - print_string(s, istr::to_estr(st)); + if kind == ast::sk_unique { word(s.s, ~"~"); } + print_string(s, st); } ast::lit_char(ch) { word(s.s, - "'" + escape_str(str::unsafe_from_bytes([ch as u8]), '\'') + - "'"); + ~"'" + escape_str(istr::unsafe_from_bytes([ch as u8]), '\'') + + ~"'"); } - 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, istr::to_estr(fstr)); } + ast::lit_int(val) { word(s.s, int::str(val)); } + ast::lit_uint(val) { word(s.s, uint::str(val) + ~"u"); } + ast::lit_float(fstr) { word(s.s, fstr); } ast::lit_mach_int(mach, val) { - word(s.s, istr::to_estr(int::str(val as int))); - word(s.s, ast_util::ty_mach_to_str(mach)); + word(s.s, int::str(val as int)); + word(s.s, istr::from_estr(ast_util::ty_mach_to_str(mach))); } ast::lit_mach_float(mach, val) { // val is already a str - word(s.s, istr::to_estr(val)); - word(s.s, ast_util::ty_mach_to_str(mach)); + word(s.s, val); + word(s.s, istr::from_estr(ast_util::ty_mach_to_str(mach))); } - ast::lit_nil. { word(s.s, "()"); } + ast::lit_nil. { word(s.s, ~"()"); } ast::lit_bool(val) { - if val { word(s.s, "true"); } else { word(s.s, "false"); } + if val { word(s.s, ~"true"); } else { word(s.s, ~"false"); } } } } -fn lit_to_str(l: &@ast::lit) -> str { be to_str(l, print_literal); } +fn lit_to_str(l: &@ast::lit) -> istr { be to_str(l, print_literal); } fn next_lit(s: &ps) -> option::t { alt s.literals { @@ -1568,7 +1572,7 @@ fn print_comment(s: &ps, cmnt: lexer::cmnt) { lexer::mixed. { assert (vec::len(cmnt.lines) == 1u); zerobreak(s.s); - word(s.s, istr::to_estr(cmnt.lines[0])); + word(s.s, cmnt.lines[0]); zerobreak(s.s); } lexer::isolated. { @@ -1577,21 +1581,21 @@ fn print_comment(s: &ps, cmnt: lexer::cmnt) { // Don't print empty lines because they will end up as trailing // whitespace if istr::is_not_empty(line) { - word(s.s, istr::to_estr(line)); + word(s.s, line); } hardbreak(s.s); } } lexer::trailing. { - word(s.s, " "); + word(s.s, ~" "); if vec::len(cmnt.lines) == 1u { - word(s.s, istr::to_estr(cmnt.lines[0])); + word(s.s, cmnt.lines[0]); hardbreak(s.s); } else { ibox(s, 0u); for line: istr in cmnt.lines { if istr::is_not_empty(line) { - word(s.s, istr::to_estr(line)); + word(s.s, line); } hardbreak(s.s); } @@ -1602,7 +1606,7 @@ fn print_comment(s: &ps, cmnt: lexer::cmnt) { // We need to do at least one, possibly two hardbreaks. let is_semi = alt s.s.last_token() { - pp::STRING(s, _) { s == ";" } + pp::STRING(s, _) { s == ~";" } _ { false } }; if is_semi || is_begin(s) || is_end(s) { hardbreak(s.s) } @@ -1611,27 +1615,27 @@ fn print_comment(s: &ps, cmnt: lexer::cmnt) { } } -fn print_string(s: &ps, st: &str) { - word(s.s, "\""); +fn print_string(s: &ps, st: &istr) { + word(s.s, ~"\""); word(s.s, escape_str(st, '"')); - word(s.s, "\""); + word(s.s, ~"\""); } -fn escape_str(st: str, to_escape: char) -> str { - let out: str = ""; - let len = str::byte_len(st); +fn escape_str(st: &istr, to_escape: char) -> istr { + let out: istr = ~""; + let len = istr::byte_len(st); let i = 0u; while i < len { alt st[i] as char { - '\n' { out += "\\n"; } - '\t' { out += "\\t"; } - '\r' { out += "\\r"; } - '\\' { out += "\\\\"; } + '\n' { out += ~"\\n"; } + '\t' { out += ~"\\t"; } + '\r' { out += ~"\\r"; } + '\\' { out += ~"\\\\"; } cur { - if cur == to_escape { out += "\\"; } + if cur == to_escape { out += ~"\\"; } // FIXME some (or all?) non-ascii things should be escaped - str::push_char(out, cur); + istr::push_char(out, cur); } } i += 1u; @@ -1639,12 +1643,12 @@ fn escape_str(st: str, to_escape: char) -> str { ret out; } -fn to_str(t: &T, f: fn(&ps, &T)) -> str { +fn to_str(t: &T, f: fn(&ps, &T)) -> istr { let writer = io::string_writer(); let s = rust_printer(writer.get_writer()); f(s, t); eof(s.s); - ret istr::to_estr(writer.get_str()); + ret writer.get_str(); } fn next_comment(s: &ps) -> option::t { @@ -1660,22 +1664,23 @@ fn next_comment(s: &ps) -> option::t { // Removing the aliases from the type of f in the next two functions // triggers memory corruption, but I haven't isolated the bug yet. FIXME -fn constr_args_to_str(f: &fn(&T) -> str, args: &[@ast::sp_constr_arg]) - -> str { +fn constr_args_to_str(f: &fn(&T) -> istr, args: &[@ast::sp_constr_arg]) + -> istr { let comma = false; - let s = "("; + let s = ~"("; for a: @ast::sp_constr_arg in args { - if comma { s += ", "; } else { comma = true; } + if comma { s += ~", "; } else { comma = true; } s += constr_arg_to_str::(f, a.node); } - s += ")"; + s += ~")"; ret s; } -fn constr_arg_to_str(f: &fn(&T) -> str, c: &ast::constr_arg_general_) -> - str { +fn constr_arg_to_str(f: &fn(&T) -> istr, + c: &ast::constr_arg_general_) -> + istr { alt c { - ast::carg_base. { ret "*"; } + ast::carg_base. { ret ~"*"; } ast::carg_ident(i) { ret f(i); } ast::carg_lit(l) { ret lit_to_str(l); } } @@ -1684,56 +1689,56 @@ fn constr_arg_to_str(f: &fn(&T) -> str, c: &ast::constr_arg_general_) -> // needed b/c constr_args_to_str needs // something that takes an alias // (argh) -fn uint_to_str(i: &uint) -> str { ret istr::to_estr(uint::str(i)); } +fn uint_to_str(i: &uint) -> istr { ret uint::str(i); } -fn ast_ty_fn_constr_to_str(c: &@ast::constr) -> str { +fn ast_ty_fn_constr_to_str(c: &@ast::constr) -> istr { ret path_to_str(c.node.path) + constr_args_to_str(uint_to_str, c.node.args); } // FIXME: fix repeated code -fn ast_ty_fn_constrs_str(constrs: &[@ast::constr]) -> str { - let s = ""; +fn ast_ty_fn_constrs_str(constrs: &[@ast::constr]) -> istr { + let s = ~""; let colon = true; for c: @ast::constr in constrs { - if colon { s += " : "; colon = false; } else { s += ", "; } + if colon { s += ~" : "; colon = false; } else { s += ~", "; } s += ast_ty_fn_constr_to_str(c); } ret s; } -fn fn_arg_idx_to_str(decl: &ast::fn_decl, idx: &uint) -> str { - istr::to_estr(decl.inputs[idx].ident) +fn fn_arg_idx_to_str(decl: &ast::fn_decl, idx: &uint) -> istr { + decl.inputs[idx].ident } -fn ast_fn_constr_to_str(decl: &ast::fn_decl, c: &@ast::constr) -> str { +fn ast_fn_constr_to_str(decl: &ast::fn_decl, c: &@ast::constr) -> istr { let arg_to_str = bind fn_arg_idx_to_str(decl, _); ret path_to_str(c.node.path) + constr_args_to_str(arg_to_str, c.node.args); } // FIXME: fix repeated code -fn ast_fn_constrs_str(decl: &ast::fn_decl, constrs: &[@ast::constr]) -> str { - let s = ""; +fn ast_fn_constrs_str(decl: &ast::fn_decl, constrs: &[@ast::constr]) -> istr { + let s = ~""; let colon = true; for c: @ast::constr in constrs { - if colon { s += " : "; colon = false; } else { s += ", "; } + if colon { s += ~" : "; colon = false; } else { s += ~", "; } s += ast_fn_constr_to_str(decl, c); } ret s; } -fn proto_to_str(p: &ast::proto) -> str { +fn proto_to_str(p: &ast::proto) -> istr { ret alt p { - ast::proto_fn. { "fn" } - ast::proto_iter. { "iter" } - ast::proto_block. { "block" } - ast::proto_closure. { "lambda" } + ast::proto_fn. { ~"fn" } + ast::proto_iter. { ~"iter" } + ast::proto_block. { ~"block" } + ast::proto_closure. { ~"lambda" } }; } -fn ty_constr_to_str(c: &@ast::ty_constr) -> str { - fn ty_constr_path_to_str(p: &ast::path) -> str { "*." + path_to_str(p) } +fn ty_constr_to_str(c: &@ast::ty_constr) -> istr { + fn ty_constr_path_to_str(p: &ast::path) -> istr { ~"*." + path_to_str(p) } ret path_to_str(c.node.path) + constr_args_to_str::(ty_constr_path_to_str, @@ -1741,11 +1746,11 @@ fn ty_constr_to_str(c: &@ast::ty_constr) -> str { } -fn ast_ty_constrs_str(constrs: &[@ast::ty_constr]) -> str { - let s = ""; +fn ast_ty_constrs_str(constrs: &[@ast::ty_constr]) -> istr { + let s = ~""; let colon = true; for c: @ast::ty_constr in constrs { - if colon { s += " : "; colon = false; } else { s += ", "; } + if colon { s += ~" : "; colon = false; } else { s += ~", "; } s += ty_constr_to_str(c); } ret s; diff --git a/src/comp/util/ppaux.rs b/src/comp/util/ppaux.rs index 3a672f453b3..55dacf073a1 100644 --- a/src/comp/util/ppaux.rs +++ b/src/comp/util/ppaux.rs @@ -62,7 +62,7 @@ fn ty_to_str(cx: &ctxt, typ: &t) -> istr { fn fn_to_str(cx: &ctxt, proto: ast::proto, ident: option::t, inputs: &[arg], output: t, cf: ast::controlflow, constrs: &[@constr]) -> istr { - let s = istr::from_estr(proto_to_str(proto)); + let s = proto_to_str(proto); alt ident { some(i) { s += ~" "; @@ -169,9 +169,8 @@ fn ty_to_short_str(cx: &ctxt, typ: t) -> istr { } fn constr_to_str(c: &@constr) -> istr { - ret istr::from_estr(path_to_str(c.node.path)) + - istr::from_estr( - pprust::constr_args_to_str(pprust::uint_to_str, c.node.args)); + ret path_to_str(c.node.path) + + pprust::constr_args_to_str(pprust::uint_to_str, c.node.args); } fn constrs_str(constrs: &[@constr]) -> istr { @@ -186,9 +185,8 @@ fn constrs_str(constrs: &[@constr]) -> istr { fn ty_constr_to_str(c: &@ast::spanned>) -> istr { - ret istr::from_estr(path_to_str(c.node.path)) + - istr::from_estr( - constr_args_to_str::(path_to_str, c.node.args)); + ret path_to_str(c.node.path) + + constr_args_to_str::(path_to_str, c.node.args); } // Local Variables: diff --git a/src/fuzzer/fuzzer.rs b/src/fuzzer/fuzzer.rs index 54a551f33c4..cc422556012 100644 --- a/src/fuzzer/fuzzer.rs +++ b/src/fuzzer/fuzzer.rs @@ -163,14 +163,15 @@ fn check_variants_of_ast(crate: &ast::crate, codemap: &codemap::codemap, let exprsL = vec::len(exprs); if exprsL < 100u { for each i: uint in under(uint::min(exprsL, 20u)) { - log_err "Replacing... " + pprust::expr_to_str(@exprs[i]); + log_err ~"Replacing... " + pprust::expr_to_str(@exprs[i]); for each j: uint in under(uint::min(exprsL, 5u)) { - log_err "With... " + pprust::expr_to_str(@exprs[j]); + log_err ~"With... " + pprust::expr_to_str(@exprs[j]); let crate2 = @replace_expr_in_crate(crate, i, exprs[j].node); // It would be best to test the *crate* for stability, but testing the // string for stability is easier and ok for now. let str3 = - as_str(bind pprust::print_crate(codemap, crate2, filename, + as_str(bind pprust::print_crate(codemap, crate2, + istr::from_estr(filename), io::string_reader(~""), _, pprust::no_ann())); // 1u would be sane here, but the pretty-printer currently has lots of whitespace and paren issues, @@ -254,7 +255,8 @@ fn parse_and_print(code: &str) -> str { //write_file(filename, code); let crate = parser::parse_crate_from_source_str( istr::from_estr(filename), istr::from_estr(code), [], sess); - ret as_str(bind pprust::print_crate(sess.cm, crate, filename, + ret as_str(bind pprust::print_crate(sess.cm, crate, + istr::from_estr(filename), io::string_reader(istr::from_estr(code)), _, pprust::no_ann())); } @@ -364,7 +366,8 @@ fn check_variants(files: &[str]) { parser::parse_crate_from_source_str( istr::from_estr(file), istr::from_estr(s), [], sess); - log_err as_str(bind pprust::print_crate(sess.cm, crate, file, + log_err as_str(bind pprust::print_crate(sess.cm, crate, + istr::from_estr(file), io::string_reader(istr::from_estr(s)), _, pprust::no_ann())); check_variants_of_ast(*crate, sess.cm, file);