aboutsummaryrefslogtreecommitdiff
path: root/src/comp
diff options
context:
space:
mode:
authorPatrick Walton <[email protected]>2011-03-21 11:44:08 -0700
committerPatrick Walton <[email protected]>2011-03-21 11:44:08 -0700
commit84c0d8638ebf766cc4f6e442bbd4f01c5810795a (patch)
tree916d6c4b84efd58682e323e773f782117fcff628 /src/comp
parentrustc: Merge in type serialization and deserialization (diff)
downloadrust-84c0d8638ebf766cc4f6e442bbd4f01c5810795a.tar.xz
rust-84c0d8638ebf766cc4f6e442bbd4f01c5810795a.zip
rustc: Update type serialization and deserialization for the "mutable?" change
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/front/creader.rs20
-rw-r--r--src/comp/middle/metadata.rs20
2 files changed, 30 insertions, 10 deletions
diff --git a/src/comp/front/creader.rs b/src/comp/front/creader.rs
index 89a19fc2..8ef75e54 100644
--- a/src/comp/front/creader.rs
+++ b/src/comp/front/creader.rs
@@ -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);
diff --git a/src/comp/middle/metadata.rs b/src/comp/middle/metadata.rs
index bff0ac94..06b527de 100644
--- a/src/comp/middle/metadata.rs
+++ b/src/comp/middle/metadata.rs
@@ -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 + "]";
}