diff options
| author | Lindsey Kuper <[email protected]> | 2011-03-18 12:32:54 -0700 |
|---|---|---|
| committer | Lindsey Kuper <[email protected]> | 2011-03-18 12:32:54 -0700 |
| commit | 6dee1ac161a22a4bc1e49c5dac3c7bbba1ff97f0 (patch) | |
| tree | f423d576e977e7a258f09e50e5a51702525782e2 /src/comp/middle/fold.rs | |
| parent | Ignore emacs autosave files. (diff) | |
| parent | rustc: Add a span_unimpl() for debugging (diff) | |
| download | rust-6dee1ac161a22a4bc1e49c5dac3c7bbba1ff97f0.tar.xz rust-6dee1ac161a22a4bc1e49c5dac3c7bbba1ff97f0.zip | |
Merge branch 'master' of git://github.com/graydon/rust
Diffstat (limited to 'src/comp/middle/fold.rs')
| -rw-r--r-- | src/comp/middle/fold.rs | 98 |
1 files changed, 45 insertions, 53 deletions
diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs index 73b2cab3..703c7ea4 100644 --- a/src/comp/middle/fold.rs +++ b/src/comp/middle/fold.rs @@ -7,7 +7,6 @@ import util.common.new_str_hash; import util.common.spanned; import util.common.span; import util.common.ty_mach; -import util.common.append; import front.ast; import front.ast.fn_decl; @@ -29,6 +28,7 @@ import front.ast.arm; import front.ast.def; import front.ast.def_id; import front.ast.ann; +import front.ast.mt; import std._uint; import std._vec; @@ -47,10 +47,10 @@ type ast_fold[ENV] = (fn(&ENV e, &span sp, ty_mach tm) -> @ty) fold_ty_machine, (fn(&ENV e, &span sp) -> @ty) fold_ty_char, (fn(&ENV e, &span sp) -> @ty) fold_ty_str, - (fn(&ENV e, &span sp, @ty t) -> @ty) fold_ty_box, - (fn(&ENV e, &span sp, @ty t) -> @ty) fold_ty_vec, + (fn(&ENV e, &span sp, &mt tm) -> @ty) fold_ty_box, + (fn(&ENV e, &span sp, &mt tm) -> @ty) fold_ty_vec, - (fn(&ENV e, &span sp, vec[@ty] elts) -> @ty) fold_ty_tup, + (fn(&ENV e, &span sp, vec[mt] elts) -> @ty) fold_ty_tup, (fn(&ENV e, &span sp, vec[ast.ty_field] elts) -> @ty) fold_ty_rec, @@ -66,13 +66,13 @@ 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, (fn(&ENV e, &span sp, @ty t) -> @ty) fold_ty_chan, (fn(&ENV e, &span sp, @ty t) -> @ty) fold_ty_port, // Expr folds. (fn(&ENV e, &span sp, - vec[@expr] es, ann a) -> @expr) fold_expr_vec, + vec[@expr] es, ast.mutability mut, + ann a) -> @expr) fold_expr_vec, (fn(&ENV e, &span sp, vec[ast.elt] es, ann a) -> @expr) fold_expr_tup, @@ -318,7 +318,7 @@ type ast_fold[ENV] = fn fold_path[ENV](&ENV env, ast_fold[ENV] fld, &path p) -> path { let vec[@ast.ty] tys_ = vec(); for (@ast.ty t in p.node.types) { - append[@ast.ty](tys_, fold_ty(env, fld, t)); + _vec.push[@ast.ty](tys_, fold_ty(env, fld, t)); } let ast.path_ p_ = rec(idents=p.node.idents, types=tys_); ret fld.fold_path(env, p.span, p_); @@ -344,20 +344,21 @@ fn fold_ty[ENV](&ENV env, ast_fold[ENV] fld, @ty t) -> @ty { case (ast.ty_char) { ret fld.fold_ty_char(env_, t.span); } case (ast.ty_str) { ret fld.fold_ty_str(env_, t.span); } - case (ast.ty_box(?ty)) { - auto ty_ = fold_ty(env, fld, ty); - ret fld.fold_ty_box(env_, t.span, ty_); + case (ast.ty_box(?tm)) { + auto ty_ = fold_ty(env, fld, tm.ty); + ret fld.fold_ty_box(env_, t.span, rec(ty=ty_, mut=tm.mut)); } - case (ast.ty_vec(?ty)) { - auto ty_ = fold_ty(env, fld, ty); - ret fld.fold_ty_vec(env_, t.span, ty_); + case (ast.ty_vec(?tm)) { + auto ty_ = fold_ty(env, fld, tm.ty); + ret fld.fold_ty_vec(env_, t.span, rec(ty=ty_, mut=tm.mut)); } case (ast.ty_tup(?elts)) { - let vec[@ty] elts_ = vec(); - for (@ty elt in elts) { - append[@ty](elts_,fold_ty(env, fld, elt)); + let vec[mt] elts_ = vec(); + for (mt elt in elts) { + auto ty_ = fold_ty(env, fld, elt.ty); + _vec.push[mt](elts_, rec(ty=ty_, mut=elt.mut)); } ret fld.fold_ty_tup(env_, t.span, elts_); } @@ -365,8 +366,9 @@ fn fold_ty[ENV](&ENV env, ast_fold[ENV] fld, @ty t) -> @ty { case (ast.ty_rec(?flds)) { let vec[ast.ty_field] flds_ = vec(); for (ast.ty_field f in flds) { - append[ast.ty_field] - (flds_, rec(ty=fold_ty(env, fld, f.ty) with f)); + auto ty_ = fold_ty(env, fld, f.mt.ty); + _vec.push[ast.ty_field] + (flds_, rec(mt=rec(ty=ty_, mut=f.mt.mut) with f)); } ret fld.fold_ty_rec(env_, t.span, flds_); } @@ -378,7 +380,7 @@ fn fold_ty[ENV](&ENV env, ast_fold[ENV] fld, @ty t) -> @ty { m.inputs, m.output); alt (tfn.node) { case (ast.ty_fn(?p, ?ins, ?out)) { - append[ast.ty_method] + _vec.push[ast.ty_method] (meths_, rec(proto=p, inputs=ins, output=out with m)); } @@ -392,11 +394,6 @@ fn fold_ty[ENV](&ENV env, ast_fold[ENV] fld, @ty t) -> @ty { ret fld.fold_ty_path(env_, t.span, pth_, 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(?proto, ?inputs, ?output)) { ret fold_ty_fn(env_, fld, t.span, proto, inputs, output); } @@ -494,7 +491,7 @@ fn fold_pat[ENV](&ENV env, ast_fold[ENV] fld, @ast.pat p) -> @ast.pat { fn fold_exprs[ENV](&ENV env, ast_fold[ENV] fld, vec[@expr] es) -> vec[@expr] { let vec[@expr] exprs = vec(); for (@expr e in es) { - append[@expr](exprs, fold_expr(env, fld, e)); + _vec.push[@expr](exprs, fold_expr(env, fld, e)); } ret exprs; } @@ -517,15 +514,15 @@ fn fold_expr[ENV](&ENV env, ast_fold[ENV] fld, &@expr e) -> @expr { } alt (e.node) { - case (ast.expr_vec(?es, ?t)) { + case (ast.expr_vec(?es, ?mut, ?t)) { auto ees = fold_exprs(env_, fld, es); - ret fld.fold_expr_vec(env_, e.span, ees, t); + ret fld.fold_expr_vec(env_, e.span, ees, mut, t); } case (ast.expr_tup(?es, ?t)) { let vec[ast.elt] elts = vec(); for (ast.elt e in es) { - elts += fold_tup_elt[ENV](env, fld, e); + elts += vec(fold_tup_elt[ENV](env, fld, e)); } ret fld.fold_expr_tup(env_, e.span, elts, t); } @@ -534,7 +531,7 @@ fn fold_expr[ENV](&ENV env, ast_fold[ENV] fld, &@expr e) -> @expr { let vec[ast.field] fields = vec(); let option.t[@expr] b = none[@expr]; for (ast.field f in fs) { - fields += fold_rec_field(env, fld, f); + fields += vec(fold_rec_field(env, fld, f)); } alt (base) { case (none[@ast.expr]) { } @@ -557,7 +554,7 @@ fn fold_expr[ENV](&ENV env, ast_fold[ENV] fld, &@expr e) -> @expr { for (option.t[@ast.expr] t_opt in args_opt) { alt (t_opt) { case (none[@ast.expr]) { - aargs_opt += none[@ast.expr]; + aargs_opt += vec(none[@ast.expr]); } case (some[@ast.expr](?e)) { aargs_opt += vec(some(fold_expr(env_, fld, e))); @@ -779,7 +776,7 @@ fn fold_block[ENV](&ENV env, ast_fold[ENV] fld, &block blk) -> block { let vec[@ast.stmt] stmts = vec(); for (@ast.stmt s in blk.node.stmts) { auto new_stmt = fold_stmt[ENV](env_, fld, s); - append[@ast.stmt](stmts, new_stmt); + _vec.push[@ast.stmt](stmts, new_stmt); ast.index_stmt(index, new_stmt); } @@ -812,7 +809,7 @@ fn fold_fn_decl[ENV](&ENV env, ast_fold[ENV] fld, &ast.fn_decl decl) -> ast.fn_decl { let vec[ast.arg] inputs = vec(); for (ast.arg a in decl.inputs) { - inputs += fold_arg(env, fld, a); + inputs += vec(fold_arg(env, fld, a)); } auto output = fold_ty[ENV](env, fld, decl.output); ret fld.fold_fn_decl(env, decl.effect, inputs, output); @@ -846,7 +843,7 @@ fn fold_obj[ENV](&ENV env, ast_fold[ENV] fld, &ast._obj ob) -> ast._obj { let vec[ast.obj_field] fields = vec(); let vec[@ast.method] meths = vec(); for (ast.obj_field f in ob.fields) { - fields += fold_obj_field(env, fld, f); + fields += vec(fold_obj_field(env, fld, f)); } let option.t[block] dtor = none[block]; alt (ob.dtor) { @@ -867,7 +864,7 @@ fn fold_obj[ENV](&ENV env, ast_fold[ENV] fld, &ast._obj ob) -> ast._obj { m.node.ann), span=m.span); let ENV _env = fld.update_env_for_item(env, i); - append[@ast.method](meths, fold_method(_env, fld, m)); + _vec.push[@ast.method](meths, fold_method(_env, fld, m)); } ret fld.fold_obj(env, fields, meths, dtor); } @@ -944,8 +941,8 @@ fn fold_item[ENV](&ENV env, ast_fold[ENV] fld, @item i) -> @item { auto new_ty = fold_ty[ENV](env_, fld, va.ty); new_args += vec(rec(ty=new_ty, id=va.id)); } - new_variants += rec(name=v.name, args=new_args, id=v.id, - ann=v.ann); + new_variants += vec(rec(name=v.name, args=new_args, id=v.id, + ann=v.ann)); } ret fld.fold_item_tag(env_, i.span, ident, new_variants, ty_params, id); @@ -969,13 +966,13 @@ fn fold_mod[ENV](&ENV e, ast_fold[ENV] fld, &ast._mod m) -> ast._mod { for (@view_item vi in m.view_items) { auto new_vi = fold_view_item[ENV](e, fld, vi); - append[@view_item](view_items, new_vi); + _vec.push[@view_item](view_items, new_vi); ast.index_view_item(index, new_vi); } for (@item i in m.items) { auto new_item = fold_item[ENV](e, fld, i); - append[@item](items, new_item); + _vec.push[@item](items, new_item); ast.index_item(index, new_item); } @@ -1009,12 +1006,12 @@ fn fold_native_mod[ENV](&ENV e, ast_fold[ENV] fld, for (@view_item vi in m.view_items) { auto new_vi = fold_view_item[ENV](e, fld, vi); - append[@view_item](view_items, new_vi); + _vec.push[@view_item](view_items, new_vi); } for (@native_item i in m.items) { auto new_item = fold_native_item[ENV](e, fld, i); - append[@native_item](items, new_item); + _vec.push[@native_item](items, new_item); ast.index_native_item(index, new_item); } @@ -1078,16 +1075,16 @@ fn identity_fold_ty_str[ENV](&ENV env, &span sp) -> @ty { ret @respan(sp, ast.ty_str); } -fn identity_fold_ty_box[ENV](&ENV env, &span sp, @ty t) -> @ty { - ret @respan(sp, ast.ty_box(t)); +fn identity_fold_ty_box[ENV](&ENV env, &span sp, &mt tm) -> @ty { + ret @respan(sp, ast.ty_box(tm)); } -fn identity_fold_ty_vec[ENV](&ENV env, &span sp, @ty t) -> @ty { - ret @respan(sp, ast.ty_vec(t)); +fn identity_fold_ty_vec[ENV](&ENV env, &span sp, &mt tm) -> @ty { + ret @respan(sp, ast.ty_vec(tm)); } fn identity_fold_ty_tup[ENV](&ENV env, &span sp, - vec[@ty] elts) -> @ty { + vec[mt] elts) -> @ty { ret @respan(sp, ast.ty_tup(elts)); } @@ -1113,10 +1110,6 @@ 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)); -} - fn identity_fold_ty_chan[ENV](&ENV env, &span sp, @ty t) -> @ty { ret @respan(sp, ast.ty_chan(t)); } @@ -1128,8 +1121,8 @@ fn identity_fold_ty_port[ENV](&ENV env, &span sp, @ty t) -> @ty { // Expr identities. fn identity_fold_expr_vec[ENV](&ENV env, &span sp, vec[@expr] es, - ann a) -> @expr { - ret @respan(sp, ast.expr_vec(es, a)); + ast.mutability mut, ann a) -> @expr { + ret @respan(sp, ast.expr_vec(es, mut, a)); } fn identity_fold_expr_tup[ENV](&ENV env, &span sp, @@ -1529,11 +1522,10 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] { fold_ty_obj = bind identity_fold_ty_obj[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_ty_chan = bind identity_fold_ty_chan[ENV](_,_,_), fold_ty_port = bind identity_fold_ty_port[ENV](_,_,_), - fold_expr_vec = bind identity_fold_expr_vec[ENV](_,_,_,_), + fold_expr_vec = bind identity_fold_expr_vec[ENV](_,_,_,_,_), fold_expr_tup = bind identity_fold_expr_tup[ENV](_,_,_,_), fold_expr_rec = bind identity_fold_expr_rec[ENV](_,_,_,_,_), fold_expr_call = bind identity_fold_expr_call[ENV](_,_,_,_,_), |