mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 08:44:35 +00:00
rustc: Add bind expressions to the AST
This commit is contained in:
parent
ed1dddc33f
commit
5cbf8889d0
@ -139,6 +139,7 @@ tag expr_ {
|
|||||||
expr_tup(vec[elt], ann);
|
expr_tup(vec[elt], ann);
|
||||||
expr_rec(vec[field], ann);
|
expr_rec(vec[field], ann);
|
||||||
expr_call(@expr, vec[@expr], ann);
|
expr_call(@expr, vec[@expr], ann);
|
||||||
|
expr_bind(@expr, vec[option.t[@expr]], ann);
|
||||||
expr_binary(binop, @expr, @expr, ann);
|
expr_binary(binop, @expr, @expr, ann);
|
||||||
expr_unary(unop, @expr, ann);
|
expr_unary(unop, @expr, ann);
|
||||||
expr_lit(@lit, ann);
|
expr_lit(@lit, ann);
|
||||||
|
@ -74,6 +74,10 @@ type ast_fold[ENV] =
|
|||||||
@expr f, vec[@expr] args,
|
@expr f, vec[@expr] args,
|
||||||
ann a) -> @expr) fold_expr_call,
|
ann a) -> @expr) fold_expr_call,
|
||||||
|
|
||||||
|
(fn(&ENV e, &span sp,
|
||||||
|
@expr f, vec[option.t[@expr]] args,
|
||||||
|
ann a) -> @expr) fold_expr_bind,
|
||||||
|
|
||||||
(fn(&ENV e, &span sp,
|
(fn(&ENV e, &span sp,
|
||||||
ast.binop,
|
ast.binop,
|
||||||
@expr lhs, @expr rhs,
|
@expr lhs, @expr rhs,
|
||||||
@ -417,6 +421,20 @@ fn fold_expr[ENV](&ENV env, ast_fold[ENV] fld, &@expr e) -> @expr {
|
|||||||
ret fld.fold_expr_call(env_, e.span, ff, aargs, t);
|
ret fld.fold_expr_call(env_, e.span, ff, aargs, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case (ast.expr_bind(?f, ?args_opt, ?t)) {
|
||||||
|
auto ff = fold_expr(env_, fld, f);
|
||||||
|
let vec[option.t[@ast.expr]] aargs_opt = vec();
|
||||||
|
for (option.t[@ast.expr] t_opt in args_opt) {
|
||||||
|
alt (t_opt) {
|
||||||
|
case (some[@ast.expr](?e)) {
|
||||||
|
aargs_opt += vec(some(fold_expr(env_, fld, e)));
|
||||||
|
}
|
||||||
|
case (none[@ast.expr]) { /* empty */ }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ret fld.fold_expr_bind(env_, e.span, ff, aargs_opt, t);
|
||||||
|
}
|
||||||
|
|
||||||
case (ast.expr_binary(?op, ?a, ?b, ?t)) {
|
case (ast.expr_binary(?op, ?a, ?b, ?t)) {
|
||||||
auto aa = fold_expr(env_, fld, a);
|
auto aa = fold_expr(env_, fld, a);
|
||||||
auto bb = fold_expr(env_, fld, b);
|
auto bb = fold_expr(env_, fld, b);
|
||||||
@ -807,6 +825,12 @@ fn identity_fold_expr_call[ENV](&ENV env, &span sp, @expr f,
|
|||||||
ret @respan(sp, ast.expr_call(f, args, a));
|
ret @respan(sp, ast.expr_call(f, args, a));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn identity_fold_expr_bind[ENV](&ENV env, &span sp, @expr f,
|
||||||
|
vec[option.t[@expr]] args_opt, ann a)
|
||||||
|
-> @expr {
|
||||||
|
ret @respan(sp, ast.expr_bind(f, args_opt, a));
|
||||||
|
}
|
||||||
|
|
||||||
fn identity_fold_expr_binary[ENV](&ENV env, &span sp, ast.binop b,
|
fn identity_fold_expr_binary[ENV](&ENV env, &span sp, ast.binop b,
|
||||||
@expr lhs, @expr rhs,
|
@expr lhs, @expr rhs,
|
||||||
ann a) -> @expr {
|
ann a) -> @expr {
|
||||||
@ -1075,6 +1099,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
|
|||||||
fold_expr_tup = bind identity_fold_expr_tup[ENV](_,_,_,_),
|
fold_expr_tup = bind identity_fold_expr_tup[ENV](_,_,_,_),
|
||||||
fold_expr_rec = bind identity_fold_expr_rec[ENV](_,_,_,_),
|
fold_expr_rec = bind identity_fold_expr_rec[ENV](_,_,_,_),
|
||||||
fold_expr_call = bind identity_fold_expr_call[ENV](_,_,_,_,_),
|
fold_expr_call = bind identity_fold_expr_call[ENV](_,_,_,_,_),
|
||||||
|
fold_expr_bind = bind identity_fold_expr_bind[ENV](_,_,_,_,_),
|
||||||
fold_expr_binary = bind identity_fold_expr_binary[ENV](_,_,_,_,_,_),
|
fold_expr_binary = bind identity_fold_expr_binary[ENV](_,_,_,_,_,_),
|
||||||
fold_expr_unary = bind identity_fold_expr_unary[ENV](_,_,_,_,_),
|
fold_expr_unary = bind identity_fold_expr_unary[ENV](_,_,_,_,_),
|
||||||
fold_expr_lit = bind identity_fold_expr_lit[ENV](_,_,_,_),
|
fold_expr_lit = bind identity_fold_expr_lit[ENV](_,_,_,_),
|
||||||
|
Loading…
Reference in New Issue
Block a user