Change the pretty printer to print vstores for strs in prefix notation.

This commit is contained in:
Michael Sullivan 2012-07-13 15:24:41 -07:00
parent 985b52be6d
commit f5e69d611e
8 changed files with 29 additions and 31 deletions

View File

@ -379,19 +379,16 @@ fn print_field(s: ps, f: ast::ty_field) {
word(s.s, constrs_str(cs, ty_constr_to_str));
}
ast::ty_vstore(t, v) {
// If it is a vector, print it in prefix notation.
// Someday it will all be like this.
let is_fixed = alt v { ast::vstore_fixed(_) { true } _ { false } };
alt t.node {
ast::ty_vec(*) if !is_fixed {
print_vstore(s, v);
print_type(s, t);
}
_ {
alt v {
ast::vstore_fixed(_) {
print_type(s, t);
word(s.s, "/");
print_vstore(s, v);
}
_ {
print_vstore(s, v);
print_type(s, t);
}
}
}
ast::ty_mac(_) {
@ -888,19 +885,16 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
s.ann.pre(ann_node);
alt expr.node {
ast::expr_vstore(e, v) {
// If it is a vector, print it in prefix notation.
// Someday it will all be like this.
let is_fixed = alt v { ast::vstore_fixed(_) { true } _ { false } };
alt e.node {
ast::expr_vec(*) if !is_fixed {
print_vstore(s, v);
print_expr(s, e);
}
_ {
alt v {
ast::vstore_fixed(_) {
print_expr(s, e);
word(s.s, "/");
print_vstore(s, v);
}
_ {
print_vstore(s, v);
print_expr(s, e);
}
}
}
ast::expr_vec(exprs, mutbl) {

View File

@ -100,6 +100,15 @@ fn vstore_to_str(cx: ctxt, vs: ty::vstore) -> str {
}
}
fn vstore_ty_to_str(cx: ctxt, ty: str, vs: ty::vstore) -> str {
alt vs {
ty::vstore_fixed(_) {
#fmt["%s/%s", ty, vstore_to_str(cx, vs)]
}
_ { #fmt["%s%s", vstore_to_str(cx, vs), ty] }
}
}
fn tys_to_str(cx: ctxt, ts: ~[t]) -> str {
let mut rs = "";
for ts.each |t| { rs += ty_to_str(cx, t); }
@ -223,14 +232,9 @@ fn field_to_str(cx: ctxt, f: field) -> str {
parameterized(cx, base, substs.self_r, substs.tps)
}
ty_evec(mt, vs) {
alt vs {
ty::vstore_fixed(_) {
#fmt["[%s]/%s", mt_to_str(cx, mt), vstore_to_str(cx, vs)]
}
_ { #fmt["%s[%s]", vstore_to_str(cx, vs), mt_to_str(cx, mt)] }
}
vstore_ty_to_str(cx, #fmt["[%s]", mt_to_str(cx, mt)], vs)
}
ty_estr(vs) { #fmt["str/%s", vstore_to_str(cx, vs)] }
ty_estr(vs) { vstore_ty_to_str(cx, "str", vs) }
ty_opaque_box { "@?" }
ty_constr(t, _) { "@?" }
ty_opaque_closure_ptr(ck_block) { "closure&" }

View File

@ -1,4 +1,4 @@
// error-pattern:expected `str/~` but found `int`
// error-pattern:expected `~str` but found `int`
const i: str = 10i;
fn main() { log(debug, i); }

View File

@ -1,3 +1,3 @@
// error-pattern:^ cannot be applied to type `str/~`
// error-pattern:^ cannot be applied to type `~str`
fn main() { let x = "a" ^ "b"; }

View File

@ -1,2 +1,2 @@
// error-pattern:expected `str/~` but found `~[int]`
// error-pattern:expected `~str` but found `~[int]`
fn main() { fail ~[0i]; }

View File

@ -8,5 +8,5 @@
fn main() {
let x: map<str,str> = map::str_hash::<str>() as map::<str,str>;
let y: map<uint,str> = x;
//~^ ERROR mismatched types: expected `std::map::map<uint,str/~>`
//~^ ERROR mismatched types: expected `std::map::map<uint,~str>`
}

View File

@ -1,3 +1,3 @@
// error-pattern:cannot apply unary operator `-` to type `str/~`
// error-pattern:cannot apply unary operator `-` to type `~str`
fn main() { -"foo"; }

View File

@ -3,7 +3,7 @@
fn foo(f: fn()) { f() }
fn main() {
"" || 42; //~ ERROR binary operation || cannot be applied to type `str/~`
"" || 42; //~ ERROR binary operation || cannot be applied to type `~str`
foo || {}; //~ ERROR binary operation || cannot be applied to type `extern fn(fn())`
//~^ NOTE did you forget the 'do' keyword for the call?
}