Skip to content

Commit cbad23a

Browse files
committed
Convert pretty-printer to istrs. Issue #855
1 parent 675073c commit cbad23a

File tree

18 files changed

+395
-370
lines changed

18 files changed

+395
-370
lines changed

src/comp/back/link.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ fn build_link_meta(sess: &session::session, c: &ast::crate, output: &istr,
347347
}
348348

349349
fn len_and_str_lit(l: &ast::lit) -> istr {
350-
ret len_and_str(istr::from_estr(pprust::lit_to_str(@l)));
350+
ret len_and_str(pprust::lit_to_str(@l));
351351
}
352352

353353
let cmh_items = attr::sort_meta_items(metas.cmh_items);

src/comp/driver/rustc.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,11 @@ fn pretty_print_input(sess: session::session, cfg: ast::crate_cfg, input: str,
185185
alt node {
186186
pprust::node_expr(s, expr) {
187187
pp::space(s.s);
188-
pp::word(s.s, "as");
188+
pp::word(s.s, ~"as");
189189
pp::space(s.s);
190190
pp::word(
191191
s.s,
192-
istr::to_estr(ppaux::ty_to_str(tcx, ty::expr_ty(tcx, expr))));
192+
ppaux::ty_to_str(tcx, ty::expr_ty(tcx, expr)));
193193
pprust::pclose(s);
194194
}
195195
_ { }
@@ -200,17 +200,17 @@ fn pretty_print_input(sess: session::session, cfg: ast::crate_cfg, input: str,
200200
pprust::node_item(s, item) {
201201
pp::space(s.s);
202202
pprust::synth_comment(
203-
s, istr::to_estr(int::to_str(item.id, 10u)));
203+
s, int::to_str(item.id, 10u));
204204
}
205205
pprust::node_block(s, blk) {
206206
pp::space(s.s);
207207
pprust::synth_comment(
208-
s, istr::to_estr(~"block " + int::to_str(blk.node.id, 10u)));
208+
s, ~"block " + int::to_str(blk.node.id, 10u));
209209
}
210210
pprust::node_expr(s, expr) {
211211
pp::space(s.s);
212212
pprust::synth_comment(
213-
s, istr::to_estr(int::to_str(expr.id, 10u)));
213+
s, int::to_str(expr.id, 10u));
214214
pprust::pclose(s);
215215
}
216216
_ { }
@@ -246,7 +246,8 @@ fn pretty_print_input(sess: session::session, cfg: ast::crate_cfg, input: str,
246246
}
247247
ppm_normal. { ann = pprust::no_ann(); }
248248
}
249-
pprust::print_crate(sess.get_codemap(), crate, input,
249+
pprust::print_crate(sess.get_codemap(), crate,
250+
istr::from_estr(input),
250251
io::string_reader(istr::from_estr(src)),
251252
io::stdout(), ann);
252253
}

src/comp/front/attr.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,12 @@ fn eq(a: @ast::meta_item, b: @ast::meta_item) -> bool {
125125

126126
fn contains(haystack: &[@ast::meta_item], needle: @ast::meta_item) -> bool {
127127
log #fmt["looking for %s",
128-
syntax::print::pprust::meta_item_to_str(*needle)];
128+
istr::to_estr(
129+
syntax::print::pprust::meta_item_to_str(*needle))];
129130
for item: @ast::meta_item in haystack {
130131
log #fmt["looking in %s",
131-
syntax::print::pprust::meta_item_to_str(*item)];
132+
istr::to_estr(
133+
syntax::print::pprust::meta_item_to_str(*item))];
132134
if eq(item, needle) { log "found it!"; ret true; }
133135
}
134136
log "found it not :(";

src/comp/front/test.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ fn mk_test_module(cx: &test_ctxt) -> @ast::item {
167167
node: item_,
168168
span: dummy_sp()};
169169

170-
log #fmt["Synthetic test module:\n%s\n", pprust::item_to_str(@item)];
170+
log #fmt["Synthetic test module:\n%s\n",
171+
istr::to_estr(pprust::item_to_str(@item))];
171172

172173
ret @item;
173174
}

src/comp/metadata/creader.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ fn metadata_matches(crate_data: &@[u8], metas: &[@ast::meta_item]) -> bool {
105105

106106
for needed: @ast::meta_item in metas {
107107
if !attr::contains(linkage_metas, needed) {
108-
log #fmt["missing %s", pprust::meta_item_to_str(*needed)];
108+
log #fmt["missing %s",
109+
istr::to_estr(pprust::meta_item_to_str(*needed))];
109110
ret false;
110111
}
111112
}

src/comp/metadata/decoder.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,9 @@ fn get_attributes(md: &ebml::doc) -> [ast::attribute] {
349349
fn list_meta_items(meta_items: &ebml::doc, out: io::writer) {
350350
for mi: @ast::meta_item in get_meta_items(meta_items) {
351351
out.write_str(
352-
istr::from_estr(#fmt["%s\n", pprust::meta_item_to_str(*mi)]));
352+
istr::from_estr(
353+
#fmt["%s\n",
354+
istr::to_estr(pprust::meta_item_to_str(*mi))]));
353355
}
354356
}
355357

@@ -358,7 +360,9 @@ fn list_crate_attributes(md: &ebml::doc, out: io::writer) {
358360

359361
for attr: ast::attribute in get_attributes(md) {
360362
out.write_str(
361-
istr::from_estr(#fmt["%s\n", pprust::attribute_to_str(attr)]));
363+
istr::from_estr(
364+
#fmt["%s\n",
365+
istr::to_estr(pprust::attribute_to_str(attr))]));
362366
}
363367

364368
out.write_str(~"\n\n");

src/comp/metadata/tyencode.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ fn enc_ty_fn(w: &io::writer, cx: &@ctxt, args: &[ty::arg], out: ty::t,
235235
236236
// FIXME less copy-and-paste
237237
fn enc_constr(w: &io::writer, cx: &@ctxt, c: &@ty::constr) {
238-
w.write_str(istr::from_estr(path_to_str(c.node.path)));
238+
w.write_str(path_to_str(c.node.path));
239239
w.write_char('(');
240240
w.write_str(cx.ds(c.node.id));
241241
w.write_char('|');
@@ -246,15 +246,15 @@ fn enc_constr(w: &io::writer, cx: &@ctxt, c: &@ty::constr) {
246246
carg_base. { w.write_char('*'); }
247247
carg_ident(i) { w.write_uint(i); }
248248
carg_lit(l) {
249-
w.write_str(istr::from_estr(lit_to_str(l)));
249+
w.write_str(lit_to_str(l));
250250
}
251251
}
252252
}
253253
w.write_char(')');
254254
}
255255
256256
fn enc_ty_constr(w: &io::writer, cx: &@ctxt, c: &@ty::type_constr) {
257-
w.write_str(istr::from_estr(path_to_str(c.node.path)));
257+
w.write_str(path_to_str(c.node.path));
258258
w.write_char('(');
259259
w.write_str(cx.ds(c.node.id));
260260
w.write_char('|');
@@ -264,9 +264,9 @@ fn enc_ty_constr(w: &io::writer, cx: &@ctxt, c: &@ty::type_constr) {
264264
alt a.node {
265265
carg_base. { w.write_char('*'); }
266266
carg_ident(p) {
267-
w.write_str(istr::from_estr(path_to_str(p))); }
267+
w.write_str(path_to_str(p)); }
268268
carg_lit(l) {
269-
w.write_str(istr::from_estr(lit_to_str(l))); }
269+
w.write_str(lit_to_str(l)); }
270270
}
271271
}
272272
w.write_char(')');

src/comp/middle/resolve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ fn resolve_constr(e: @env, c: &@ast::constr, sc: &scopes, _v: &vt<scopes>) {
451451
_ {
452452
e.sess.span_err(c.span,
453453
"Non-predicate in constraint: " +
454-
path_to_str(c.node.path));
454+
istr::to_estr(path_to_str(c.node.path)));
455455
}
456456
}
457457
}

src/comp/middle/trans.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4602,7 +4602,7 @@ fn trans_log(lvl: int, cx: &@block_ctxt, e: &@ast::expr) -> result {
46024602

46034603
fn trans_check_expr(cx: &@block_ctxt, e: &@ast::expr, s: &istr) -> result {
46044604
let cond_res = trans_expr(cx, e);
4605-
let expr_str = s + ~" " + istr::from_estr(expr_to_str(e)) + ~" failed";
4605+
let expr_str = s + ~" " + expr_to_str(e) + ~" failed";
46064606
let fail_cx = new_sub_block_ctxt(cx, ~"fail");
46074607
trans_fail(fail_cx, some::<span>(e.span), expr_str);
46084608
let next_cx = new_sub_block_ctxt(cx, ~"next");

src/comp/middle/tstate/auxiliary.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn comma_str(args: &[@constr_arg_use]) -> istr {
6868
alt a.node {
6969
carg_base. { rslt += ~"*"; }
7070
carg_ident(i) { rslt += i.ident; }
71-
carg_lit(l) { rslt += istr::from_estr(lit_to_str(l)); }
71+
carg_lit(l) { rslt += lit_to_str(l); }
7272
}
7373
}
7474
ret rslt;
@@ -81,7 +81,7 @@ fn constraint_to_str(tcx: &ty::ctxt, c: &sp_constr) -> istr {
8181
istr::from_estr(tcx.sess.span_str(c.span)) + ~"])";
8282
}
8383
npred(p, _, args) {
84-
ret istr::from_estr(path_to_str(p)) + ~"(" +
84+
ret path_to_str(p) + ~"(" +
8585
comma_str(args) + ~")" + ~"[" +
8686
istr::from_estr(tcx.sess.span_str(c.span)) + ~"]";
8787
}
@@ -593,9 +593,9 @@ fn constraints(fcx: &fn_ctxt) -> [norm_constraint] {
593593
// should freeze it at some earlier point.
594594
fn match_args(fcx: &fn_ctxt, occs: &@mutable [pred_args],
595595
occ: &[@constr_arg_use]) -> uint {
596-
log "match_args: looking at " +
597-
constr_args_to_str(fn (i: &inst) -> str {
598-
ret istr::to_estr(i.ident);
596+
log ~"match_args: looking at " +
597+
constr_args_to_str(fn (i: &inst) -> istr {
598+
ret i.ident;
599599
}, occ);
600600
for pd: pred_args in *occs {
601601
log ~"match_args: candidate " + pred_args_to_str(pd);
@@ -687,11 +687,11 @@ fn expr_to_constr(tcx: ty::ctxt, e: &@expr) -> sp_constr {
687687
}
688688

689689
fn pred_args_to_str(p: &pred_args) -> istr {
690-
istr::from_estr("<" + istr::to_estr(uint::str(p.node.bit_num)) + ", " +
691-
constr_args_to_str(fn (i: &inst) -> str {
692-
ret istr::to_estr(i.ident);
693-
}, p.node.args)
694-
+ ">")
690+
~"<" + uint::str(p.node.bit_num) + ~", " +
691+
constr_args_to_str(fn (i: &inst) -> istr {
692+
ret i.ident;
693+
}, p.node.args)
694+
+ ~">"
695695
}
696696
697697
fn substitute_constr_args(cx: &ty::ctxt, actuals: &[@expr], c: &@ty::constr)

src/comp/middle/tstate/ck.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ fn check_states_expr(e: &@expr, fcx: &fn_ctxt, v: &visit::vt<fn_ctxt>) {
8787
s +=
8888
~"Unsatisfied precondition constraint (for example, " + diff +
8989
~") for expression:\n";
90-
s += istr::from_estr(syntax::print::pprust::expr_to_str(e));
90+
s += syntax::print::pprust::expr_to_str(e);
9191
s += ~"\nPrecondition:\n";
9292
s += tritv_to_str(fcx, prec);
9393
s += ~"\nPrestate:\n";
@@ -119,7 +119,7 @@ fn check_states_stmt(s: &@stmt, fcx: &fn_ctxt, v: &visit::vt<fn_ctxt>) {
119119
ss +=
120120
~"Unsatisfied precondition constraint (for example, " + diff +
121121
~") for statement:\n";
122-
ss += istr::from_estr(syntax::print::pprust::stmt_to_str(*s));
122+
ss += syntax::print::pprust::stmt_to_str(*s);
123123
ss += ~"\nPrecondition:\n";
124124
ss += tritv_to_str(fcx, prec);
125125
ss += ~"\nPrestate: \n";
@@ -154,9 +154,10 @@ fn check_states_against_conditions(fcx: &fn_ctxt, f: &_fn,
154154
istr::to_estr(fcx.name) +
155155
", not all control paths \
156156
return a value");
157-
fcx.ccx.tcx.sess.span_fatal(f.decl.output.span,
158-
"see declared return type of '" +
159-
ty_to_str(f.decl.output) + "'");
157+
fcx.ccx.tcx.sess.span_fatal(
158+
f.decl.output.span,
159+
"see declared return type of '" +
160+
istr::to_estr(ty_to_str(f.decl.output)) + "'");
160161
} else if f.decl.cf == noreturn {
161162

162163
// check that this really always fails

src/comp/middle/ty.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2900,7 +2900,8 @@ fn ast_constr_to_constr<T>(tcx: ty::ctxt, c: &@ast::constr_general<T>) ->
29002900
}
29012901
_ {
29022902
tcx.sess.span_fatal(c.span,
2903-
"Predicate " + path_to_str(c.node.path) +
2903+
"Predicate " +
2904+
istr::to_estr(path_to_str(c.node.path)) +
29042905
" is unbound or bound to a non-function or an \
29052906
impure function");
29062907
}

src/comp/middle/typeck.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ fn ast_ty_to_ty(tcx: &ty::ctxt, getter: &ty_getter, ast_ty: &@ast::ty) ->
315315
ret typ;
316316
}
317317
let typ;
318-
let cname = none::<str>;
318+
let cname = none::<istr>;
319319
alt ast_ty.node {
320320
ast::ty_nil. { typ = ty::mk_nil(tcx); }
321321
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) ->
415415
}
416416
alt cname {
417417
none. {/* no-op */ }
418-
some(cname_str) { typ = ty::rename(tcx, typ, cname_str); }
418+
some(cname_str) {
419+
typ = ty::rename(tcx, typ, istr::to_estr(cname_str));
420+
}
419421
}
420422
tcx.ast_ty_to_ty_cache.insert(ast_ty, some(typ));
421423
ret typ;
@@ -2402,7 +2404,8 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr, unify: &unifier,
24022404
// The user is trying to extend a non-object.
24032405
tcx.sess.span_fatal(
24042406
e.span,
2405-
syntax::print::pprust::expr_to_str(e)
2407+
istr::to_estr(
2408+
syntax::print::pprust::expr_to_str(e))
24062409
+
24072410
" does not have object type");
24082411
}

src/comp/syntax/ext/log_syntax.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr,
88

99
cx.print_backtrace();
1010
std::io::stdout().write_line(
11-
istr::from_estr(print::pprust::expr_to_str(arg)));
11+
print::pprust::expr_to_str(arg));
1212

1313
//trivial expression
1414
ret @{id: cx.next_id(), node: ast::expr_rec([], option::none), span: sp};

src/comp/syntax/print/pp.rs

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -62,33 +62,37 @@ type break_t = {offset: int, blank_space: int};
6262

6363
type begin_t = {offset: int, breaks: breaks};
6464

65-
tag token { STRING(str, int); BREAK(break_t); BEGIN(begin_t); END; EOF; }
65+
tag token { STRING(istr, int); BREAK(break_t); BEGIN(begin_t); END; EOF; }
6666

67-
fn tok_str(t: token) -> str {
67+
fn tok_str(t: token) -> istr {
6868
alt t {
69-
STRING(s, len) { ret #fmt["STR(%s,%d)", s, len]; }
70-
BREAK(_) { ret "BREAK"; }
71-
BEGIN(_) { ret "BEGIN"; }
72-
END. { ret "END"; }
73-
EOF. { ret "EOF"; }
69+
STRING(s, len) {
70+
ret istr::from_estr(
71+
#fmt["STR(%s,%d)", istr::to_estr(s), len]);
72+
}
73+
BREAK(_) { ret ~"BREAK"; }
74+
BEGIN(_) { ret ~"BEGIN"; }
75+
END. { ret ~"END"; }
76+
EOF. { ret ~"EOF"; }
7477
}
7578
}
7679

7780
fn buf_str(toks: &[mutable token], szs: &[mutable int], left: uint,
78-
right: uint, lim: uint) -> str {
81+
right: uint, lim: uint) -> istr {
7982
let n = vec::len(toks);
8083
assert (n == vec::len(szs));
8184
let i = left;
8285
let L = lim;
83-
let s = "[";
86+
let s = ~"[";
8487
while i != right && L != 0u {
8588
L -= 1u;
86-
if i != left { s += ", "; }
87-
s += #fmt["%d=%s", szs[i], tok_str(toks[i])];
89+
if i != left { s += ~", "; }
90+
s += istr::from_estr(
91+
#fmt["%d=%s", szs[i], istr::to_estr(tok_str(toks[i]))]);
8892
i += 1u;
8993
i %= n;
9094
}
91-
s += "]";
95+
s += ~"]";
9296
ret s;
9397
}
9498

@@ -405,15 +409,16 @@ obj printer(out: io::writer,
405409
if n != 0u { top = print_stack[n - 1u]; }
406410
ret top;
407411
}
408-
fn write_str(s: str) {
412+
fn write_str(s: &istr) {
409413
while pending_indentation > 0 {
410414
out.write_str(~" ");
411415
pending_indentation -= 1;
412416
}
413-
out.write_str(istr::from_estr(s));
417+
out.write_str(s);
414418
}
415419
fn print(x: token, L: int) {
416-
log #fmt["print %s %d (remaining line space=%d)", tok_str(x), L,
420+
log #fmt["print %s %d (remaining line space=%d)",
421+
istr::to_estr(tok_str(x)), L,
417422
space];
418423
log buf_str(token, size, left, right, 6u);
419424
alt x {
@@ -493,15 +498,15 @@ fn end(p: printer) { p.pretty_print(END); }
493498

494499
fn eof(p: printer) { p.pretty_print(EOF); }
495500

496-
fn word(p: printer, wrd: str) {
497-
p.pretty_print(STRING(wrd, str::char_len(wrd) as int));
501+
fn word(p: printer, wrd: &istr) {
502+
p.pretty_print(STRING(wrd, istr::char_len(wrd) as int));
498503
}
499504

500-
fn huge_word(p: printer, wrd: str) {
505+
fn huge_word(p: printer, wrd: &istr) {
501506
p.pretty_print(STRING(wrd, size_infinity));
502507
}
503508

504-
fn zero_word(p: printer, wrd: str) { p.pretty_print(STRING(wrd, 0)); }
509+
fn zero_word(p: printer, wrd: &istr) { p.pretty_print(STRING(wrd, 0)); }
505510

506511
fn spaces(p: printer, n: uint) { break_offset(p, n, 0); }
507512

0 commit comments

Comments
 (0)