Add ast.ty_mutable.
This commit is contained in:
parent
20b11c832c
commit
38846e39c4
@ -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 {
|
||||
|
@ -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) {
|
||||
|
@ -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](_,_,_,_),
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user