rustc: Add mutability to tuple literals

This commit is contained in:
Patrick Walton 2010-10-12 16:30:44 -07:00
parent b1ca4da3b3
commit 81a43ef698
3 changed files with 30 additions and 10 deletions

View File

@ -83,7 +83,7 @@ tag decl_ {
type expr = spanned[expr_];
tag expr_ {
expr_vec(vec[@expr]);
expr_tup(vec[@expr]);
expr_tup(vec[tup(bool /* mutability */, @expr)]);
expr_rec(vec[tup(ident,@expr)]);
expr_call(@expr, vec[@expr]);
expr_binary(binop, @expr, @expr);

View File

@ -219,6 +219,18 @@ io fn parse_name(parser p, ast.ident id) -> ast.name {
ret spanned(lo, tys.span, rec(ident=id, types=tys.node));
}
io fn parse_possibly_mutable_expr(parser p) -> tup(bool, @ast.expr) {
auto mut;
if (p.peek() == token.MUTABLE) {
p.bump();
mut = true;
} else {
mut = false;
}
ret tup(mut, parse_expr(p));
}
io fn parse_bottom_expr(parser p) -> @ast.expr {
auto lo = p.get_span();
@ -239,11 +251,11 @@ io fn parse_bottom_expr(parser p) -> @ast.expr {
case (token.TUP) {
p.bump();
auto pf = parse_expr;
auto es = parse_seq[@ast.expr](token.LPAREN,
token.RPAREN,
some(token.COMMA),
pf, p);
auto pf = parse_possibly_mutable_expr;
auto es = parse_seq[tup(bool, @ast.expr)](token.LPAREN,
token.RPAREN,
some(token.COMMA),
pf, p);
hi = es.span;
ex = ast.expr_tup(es.node);
}

View File

@ -47,7 +47,7 @@ type ast_fold[ENV] =
vec[@expr] es) -> @expr) fold_expr_vec,
(fn(&ENV e, &span sp,
vec[@expr] es) -> @expr) fold_expr_tup,
vec[tup(bool,@expr)] es) -> @expr) fold_expr_tup,
(fn(&ENV e, &span sp,
vec[tup(ident,@expr)] fields) -> @expr) fold_expr_rec,
@ -161,6 +161,11 @@ fn fold_exprs[ENV](&ENV env, ast_fold[ENV] fld, vec[@expr] e) -> vec[@expr] {
ret _vec.map[@expr, @expr](fe, e);
}
fn fold_tup_entry[ENV](&ENV env, ast_fold[ENV] fld, &tup(bool,@expr) e)
-> tup(bool,@expr) {
ret tup(e._0, fold_expr(env, fld, e._1));
}
fn fold_rec_entry[ENV](&ENV env, ast_fold[ENV] fld, &tup(ident,@expr) e)
-> tup(ident,@expr) {
ret tup(e._0, fold_expr(env, fld, e._1));
@ -181,8 +186,10 @@ fn fold_expr[ENV](&ENV env, ast_fold[ENV] fld, &@expr e) -> @expr {
}
case (ast.expr_tup(?es)) {
auto ees = fold_exprs(env_, fld, es);
ret fld.fold_expr_vec(env_, e.span, ees);
let operator[tup(bool,@expr), tup(bool,@expr)] fe =
bind fold_tup_entry[ENV](env, fld, _);
auto ees = _vec.map[tup(bool,@expr), tup(bool,@expr)](fe, es);
ret fld.fold_expr_tup(env_, e.span, ees);
}
case (ast.expr_rec(?es)) {
@ -425,7 +432,8 @@ fn identity_fold_expr_vec[ENV](&ENV env, &span sp, vec[@expr] es) -> @expr {
ret @respan(sp, ast.expr_vec(es));
}
fn identity_fold_expr_tup[ENV](&ENV env, &span sp, vec[@expr] es) -> @expr {
fn identity_fold_expr_tup[ENV](&ENV env, &span sp, vec[tup(bool, @expr)] es)
-> @expr {
ret @respan(sp, ast.expr_tup(es));
}