aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGraydon Hoare <[email protected]>2010-11-29 12:29:57 -0800
committerGraydon Hoare <[email protected]>2010-11-29 12:29:57 -0800
commit38846e39c4be0f12241ab0df2e94cbb366ae34ba (patch)
tree78b01de1abc68687f5057619de868763b8daf07b /src
parentAdd mut field to typeck.ty. (diff)
downloadrust-38846e39c4be0f12241ab0df2e94cbb366ae34ba.tar.xz
rust-38846e39c4be0f12241ab0df2e94cbb366ae34ba.zip
Add ast.ty_mutable.
Diffstat (limited to 'src')
-rw-r--r--src/comp/front/ast.rs1
-rw-r--r--src/comp/front/parser.rs14
-rw-r--r--src/comp/middle/fold.rs12
-rw-r--r--src/comp/middle/typeck.rs14
4 files changed, 39 insertions, 2 deletions
diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs
index 3c2af3c8..a177f301 100644
--- a/src/comp/front/ast.rs
+++ b/src/comp/front/ast.rs
@@ -150,6 +150,7 @@ tag ty_ {
ty_tup(vec[tup(bool /* mutability */, @ty)]);
ty_fn(vec[rec(mode mode, @ty ty)], @ty); // TODO: effect
ty_path(path, option.t[def]);
+ ty_mutable(@ty);
}
tag mode {
diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs
index 261ea1ad..ab0f795d 100644
--- a/src/comp/front/parser.rs
+++ b/src/comp/front/parser.rs
@@ -174,7 +174,12 @@ impure fn parse_ty(parser p) -> @ast.ty {
}
}
- case (token.AT) { p.bump(); t = ast.ty_box(parse_ty(p)); }
+ case (token.AT) {
+ p.bump();
+ auto t0 = parse_ty(p);
+ hi = t0.span;
+ t = ast.ty_box(t0);
+ }
case (token.VEC) {
p.bump();
@@ -193,6 +198,13 @@ impure fn parse_ty(parser p) -> @ast.ty {
t = ast.ty_tup(elems.node);
}
+ case (token.MUTABLE) {
+ p.bump();
+ auto t0 = parse_ty(p);
+ hi = p.get_span();
+ t = ast.ty_mutable(t0);
+ }
+
case (token.FN) {
t = parse_ty_fn(p);
alt (t) {
diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs
index de2fd87a..1caaa00e 100644
--- a/src/comp/middle/fold.rs
+++ b/src/comp/middle/fold.rs
@@ -55,6 +55,8 @@ type ast_fold[ENV] =
(fn(&ENV e, &span sp, ast.path p,
&option.t[def] d) -> @ty) fold_ty_path,
+ (fn(&ENV e, &span sp, @ty t) -> @ty) fold_ty_mutable,
+
// Expr folds.
(fn(&ENV e, &span sp,
vec[@expr] es, ann a) -> @expr) fold_expr_vec,
@@ -258,6 +260,11 @@ fn fold_ty[ENV](&ENV env, ast_fold[ENV] fld, @ty t) -> @ty {
ret fld.fold_ty_path(env_, t.span, path, ref_opt);
}
+ case (ast.ty_mutable(?ty)) {
+ auto ty_ = fold_ty(env, fld, ty);
+ ret fld.fold_ty_mutable(env_, t.span, ty_);
+ }
+
case (ast.ty_fn(?inputs, ?output)) {
ret fld.fold_ty_fn(env_, t.span, inputs, output);
}
@@ -659,6 +666,10 @@ fn identity_fold_ty_path[ENV](&ENV env, &span sp, ast.path p,
ret @respan(sp, ast.ty_path(p, d));
}
+fn identity_fold_ty_mutable[ENV](&ENV env, &span sp, @ty t) -> @ty {
+ ret @respan(sp, ast.ty_mutable(t));
+}
+
// Expr identities.
@@ -908,6 +919,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
fold_ty_tup = bind identity_fold_ty_tup[ENV](_,_,_),
fold_ty_fn = bind identity_fold_ty_fn[ENV](_,_,_,_),
fold_ty_path = bind identity_fold_ty_path[ENV](_,_,_,_),
+ fold_ty_mutable = bind identity_fold_ty_mutable[ENV](_,_,_),
fold_expr_vec = bind identity_fold_expr_vec[ENV](_,_,_,_),
fold_expr_tup = bind identity_fold_expr_tup[ENV](_,_,_,_),
diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs
index a0aec16f..0fd72d9e 100644
--- a/src/comp/middle/typeck.rs
+++ b/src/comp/middle/typeck.rs
@@ -122,6 +122,10 @@ fn ast_ty_to_str(&@ast.ty ty) -> str {
s = path_to_str(path);
}
+ case (ast.ty_mutable(?t)) {
+ s = "mutable " + ast_ty_to_str(t);
+ }
+
case (_) {
fail; // FIXME: typestate bug
}
@@ -213,6 +217,7 @@ fn ast_ty_to_ty(ty_getter getter, &@ast.ty ast_ty) -> @ty {
ret rec(mode=arg.mode, ty=ast_ty_to_ty(getter, arg.ty));
}
+ auto mut = false;
auto sty;
auto cname = none[str];
alt (ast_ty.node) {
@@ -252,12 +257,19 @@ fn ast_ty_to_ty(ty_getter getter, &@ast.ty ast_ty) -> @ty {
cname = some(path_to_str(path));
}
+ case (ast.ty_mutable(?t)) {
+ mut = true;
+ auto t0 = ast_ty_to_ty(getter, t);
+ sty = t0.struct;
+ cname = t0.cname;
+ }
+
case (_) {
fail;
}
}
- ret @rec(struct=sty, mut=false, cname=cname);
+ ret @rec(struct=sty, mut=mut, cname=cname);
}
// A convenience function to use a crate_ctxt to resolve names for