rustc: Update type serialization and deserialization for the "mutable?" change

This commit is contained in:
Patrick Walton 2011-03-21 11:44:08 -07:00
parent 86d05655b4
commit 84c0d8638e
2 changed files with 30 additions and 10 deletions

View File

@ -59,6 +59,16 @@ impure fn parse_ty(@pstate st, str_def sd) -> @ty.t {
cname=option.none[str]);
}
impure fn parse_mt(@pstate st, str_def sd) -> ty.mt {
auto mut;
alt (peek(st)) {
case ('m') {next(st); mut = ast.mut;}
case ('?') {next(st); mut = ast.maybe_mut;}
case (_) {mut=ast.imm;}
}
ret rec(ty=parse_ty(st, sd), mut=mut);
}
impure fn parse_sty(@pstate st, str_def sd) -> ty.sty {
alt (next(st)) {
case ('n') {ret ty.ty_nil;}
@ -93,15 +103,15 @@ impure fn parse_sty(@pstate st, str_def sd) -> ty.sty {
st.pos = st.pos + 1u;
ret ty.ty_tag(sd(def), params);
}
case ('@') {ret ty.ty_box(parse_ty(st, sd));}
case ('V') {ret ty.ty_vec(parse_ty(st, sd));}
case ('@') {ret ty.ty_box(parse_mt(st, sd));}
case ('V') {ret ty.ty_vec(parse_mt(st, sd));}
case ('P') {ret ty.ty_port(parse_ty(st, sd));}
case ('C') {ret ty.ty_chan(parse_ty(st, sd));}
case ('T') {
check(next(st) == '[');
let vec[@ty.t] params = vec();
let vec[ty.mt] params = vec();
while (peek(st) != ']') {
params = _vec.push[@ty.t](params, parse_ty(st, sd));
params = _vec.push[ty.mt](params, parse_mt(st, sd));
}
st.pos = st.pos + 1u;
ret ty.ty_tup(params);
@ -114,7 +124,7 @@ impure fn parse_sty(@pstate st, str_def sd) -> ty.sty {
while (peek(st) != '=') {name += _str.from_char(next(st));}
st.pos = st.pos + 1u;
fields = _vec.push[ty.field]
(fields, rec(ident=name, ty=parse_ty(st, sd)));
(fields, rec(ident=name, mt=parse_mt(st, sd)));
}
st.pos = st.pos + 1u;
ret ty.ty_rec(fields);

View File

@ -26,6 +26,16 @@ fn ty_str(@ty.t t, def_str ds) -> str {
ret sty_str(t.struct, ds);
}
fn mt_str(&ty.mt mt, def_str ds) -> str {
auto mut_str;
alt (mt.mut) {
case (ast.imm) { mut_str = ""; }
case (ast.mut) { mut_str = "m"; }
case (ast.maybe_mut) { mut_str = "?"; }
}
ret mut_str + ty_str(mt.ty, ds);
}
fn sty_str(ty.sty st, def_str ds) -> str {
alt (st) {
case (ty.ty_nil) {ret "n";}
@ -53,20 +63,20 @@ fn sty_str(ty.sty st, def_str ds) -> str {
for (@ty.t t in tys) {acc += ty_str(t, ds);}
ret acc + "]";
}
case (ty.ty_box(?t)) {ret "@" + ty_str(t, ds);}
case (ty.ty_vec(?t)) {ret "V" + ty_str(t, ds);}
case (ty.ty_box(?mt)) {ret "@" + mt_str(mt, ds);}
case (ty.ty_vec(?mt)) {ret "V" + mt_str(mt, ds);}
case (ty.ty_port(?t)) {ret "P" + ty_str(t, ds);}
case (ty.ty_chan(?t)) {ret "C" + ty_str(t, ds);}
case (ty.ty_tup(?tys)) {
case (ty.ty_tup(?mts)) {
auto acc = "T[";
for (@ty.t t in tys) {acc += ty_str(t, ds);}
for (ty.mt mt in mts) {acc += mt_str(mt, ds);}
ret acc + "]";
}
case (ty.ty_rec(?fields)) {
auto acc = "R[";
for (ty.field field in fields) {
acc += field.ident + "=";
acc += ty_str(field.ty, ds);
acc += mt_str(field.mt, ds);
}
ret acc + "]";
}