Skip to content

Commit 38846e3

Browse files
committed
Add ast.ty_mutable.
1 parent 20b11c8 commit 38846e3

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

src/comp/front/ast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ tag ty_ {
150150
ty_tup(vec[tup(bool /* mutability */, @ty)]);
151151
ty_fn(vec[rec(mode mode, @ty ty)], @ty); // TODO: effect
152152
ty_path(path, option.t[def]);
153+
ty_mutable(@ty);
153154
}
154155

155156
tag mode {

src/comp/front/parser.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,12 @@ impure fn parse_ty(parser p) -> @ast.ty {
174174
}
175175
}
176176

177-
case (token.AT) { p.bump(); t = ast.ty_box(parse_ty(p)); }
177+
case (token.AT) {
178+
p.bump();
179+
auto t0 = parse_ty(p);
180+
hi = t0.span;
181+
t = ast.ty_box(t0);
182+
}
178183

179184
case (token.VEC) {
180185
p.bump();
@@ -193,6 +198,13 @@ impure fn parse_ty(parser p) -> @ast.ty {
193198
t = ast.ty_tup(elems.node);
194199
}
195200

201+
case (token.MUTABLE) {
202+
p.bump();
203+
auto t0 = parse_ty(p);
204+
hi = p.get_span();
205+
t = ast.ty_mutable(t0);
206+
}
207+
196208
case (token.FN) {
197209
t = parse_ty_fn(p);
198210
alt (t) {

src/comp/middle/fold.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ type ast_fold[ENV] =
5555
(fn(&ENV e, &span sp, ast.path p,
5656
&option.t[def] d) -> @ty) fold_ty_path,
5757

58+
(fn(&ENV e, &span sp, @ty t) -> @ty) fold_ty_mutable,
59+
5860
// Expr folds.
5961
(fn(&ENV e, &span sp,
6062
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 {
258260
ret fld.fold_ty_path(env_, t.span, path, ref_opt);
259261
}
260262

263+
case (ast.ty_mutable(?ty)) {
264+
auto ty_ = fold_ty(env, fld, ty);
265+
ret fld.fold_ty_mutable(env_, t.span, ty_);
266+
}
267+
261268
case (ast.ty_fn(?inputs, ?output)) {
262269
ret fld.fold_ty_fn(env_, t.span, inputs, output);
263270
}
@@ -659,6 +666,10 @@ fn identity_fold_ty_path[ENV](&ENV env, &span sp, ast.path p,
659666
ret @respan(sp, ast.ty_path(p, d));
660667
}
661668

669+
fn identity_fold_ty_mutable[ENV](&ENV env, &span sp, @ty t) -> @ty {
670+
ret @respan(sp, ast.ty_mutable(t));
671+
}
672+
662673

663674
// Expr identities.
664675

@@ -908,6 +919,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
908919
fold_ty_tup = bind identity_fold_ty_tup[ENV](_,_,_),
909920
fold_ty_fn = bind identity_fold_ty_fn[ENV](_,_,_,_),
910921
fold_ty_path = bind identity_fold_ty_path[ENV](_,_,_,_),
922+
fold_ty_mutable = bind identity_fold_ty_mutable[ENV](_,_,_),
911923

912924
fold_expr_vec = bind identity_fold_expr_vec[ENV](_,_,_,_),
913925
fold_expr_tup = bind identity_fold_expr_tup[ENV](_,_,_,_),

src/comp/middle/typeck.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ fn ast_ty_to_str(&@ast.ty ty) -> str {
122122
s = path_to_str(path);
123123
}
124124

125+
case (ast.ty_mutable(?t)) {
126+
s = "mutable " + ast_ty_to_str(t);
127+
}
128+
125129
case (_) {
126130
fail; // FIXME: typestate bug
127131
}
@@ -213,6 +217,7 @@ fn ast_ty_to_ty(ty_getter getter, &@ast.ty ast_ty) -> @ty {
213217
ret rec(mode=arg.mode, ty=ast_ty_to_ty(getter, arg.ty));
214218
}
215219

220+
auto mut = false;
216221
auto sty;
217222
auto cname = none[str];
218223
alt (ast_ty.node) {
@@ -252,12 +257,19 @@ fn ast_ty_to_ty(ty_getter getter, &@ast.ty ast_ty) -> @ty {
252257
cname = some(path_to_str(path));
253258
}
254259

260+
case (ast.ty_mutable(?t)) {
261+
mut = true;
262+
auto t0 = ast_ty_to_ty(getter, t);
263+
sty = t0.struct;
264+
cname = t0.cname;
265+
}
266+
255267
case (_) {
256268
fail;
257269
}
258270
}
259271

260-
ret @rec(struct=sty, mut=false, cname=cname);
272+
ret @rec(struct=sty, mut=mut, cname=cname);
261273
}
262274

263275
// A convenience function to use a crate_ctxt to resolve names for

0 commit comments

Comments
 (0)