diff options
| author | Marijn Haverbeke <[email protected]> | 2011-05-11 15:10:24 +0200 |
|---|---|---|
| committer | Marijn Haverbeke <[email protected]> | 2011-05-11 15:10:24 +0200 |
| commit | 5405f45274dc6dce53743092dc0679a5f43482d9 (patch) | |
| tree | d1417d56ca0770e3cbf7abf1273ed1f2fce3fe4c /src/comp/middle | |
| parent | Stop depending on block indices in capture.rs (diff) | |
| download | rust-5405f45274dc6dce53743092dc0679a5f43482d9.tar.xz rust-5405f45274dc6dce53743092dc0679a5f43482d9.zip | |
Get rid of block indices
Diffstat (limited to 'src/comp/middle')
| -rw-r--r-- | src/comp/middle/fold.rs | 4 | ||||
| -rw-r--r-- | src/comp/middle/resolve.rs | 99 | ||||
| -rw-r--r-- | src/comp/middle/typeck.rs | 2 | ||||
| -rw-r--r-- | src/comp/middle/typestate_check.rs | 5 |
4 files changed, 49 insertions, 61 deletions
diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs index 62521067..bf85297f 100644 --- a/src/comp/middle/fold.rs +++ b/src/comp/middle/fold.rs @@ -862,7 +862,6 @@ fn fold_stmt[ENV](&ENV env, &ast_fold[ENV] fld, &@stmt s) -> @stmt { fn fold_block[ENV](&ENV env, &ast_fold[ENV] fld, &block blk) -> block { - auto index = new_str_hash[ast.block_index_entry](); let ENV env_ = fld.update_env_for_block(env, blk); if (!fld.keep_going(env_)) { @@ -873,7 +872,6 @@ fn fold_block[ENV](&ENV env, &ast_fold[ENV] fld, &block blk) -> block { for (@ast.stmt s in blk.node.stmts) { auto new_stmt = fold_stmt[ENV](env_, fld, s); Vec.push[@ast.stmt](stmts, new_stmt); - ast.index_stmt(index, new_stmt); } auto expr = none[@ast.expr]; @@ -887,7 +885,7 @@ fn fold_block[ENV](&ENV env, &ast_fold[ENV] fld, &block blk) -> block { } auto aa = fld.fold_ann(env, blk.node.a); - ret respan(blk.span, rec(stmts=stmts, expr=expr, index=index, a=aa)); + ret respan(blk.span, rec(stmts=stmts, expr=expr, a=aa)); } fn fold_arm[ENV](&ENV env, &ast_fold[ENV] fld, &arm a) -> arm { diff --git a/src/comp/middle/resolve.rs b/src/comp/middle/resolve.rs index ce2048af..ee3288ac 100644 --- a/src/comp/middle/resolve.rs +++ b/src/comp/middle/resolve.rs @@ -500,82 +500,77 @@ fn lookup_in_obj(ident id, &ast._obj ob, &vec[ast.ty_param] ty_params, fn lookup_in_block(ident id, &ast.block_ b, namespace ns) -> Option.t[def] { - alt (b.index.find(id)) { - case (some[ast.block_index_entry](?ix)) { - alt (ix) { - case (ast.bie_item(?it)) { - ret found_def_item(it, ns); - } - case (ast.bie_local(?l)) { - if (ns == ns_value) { - ret some(ast.def_local(l.id)); + for (@ast.stmt st in b.stmts) { + alt (st.node) { + case (ast.stmt_decl(?d,_)) { + alt (d.node) { + case (ast.decl_local(?loc)) { + if (ns == ns_value && Str.eq(id, loc.ident)) { + ret some(ast.def_local(loc.id)); + } } - } - case (ast.bie_tag_variant(?item, ?variant_idx)) { - if (ns == ns_value) { - ret some(found_def_tag(item, variant_idx)); + case (ast.decl_item(?it)) { + alt (it.node) { + case (ast.item_tag(?name, ?variants, _, + ?defid, _)) { + if (ns == ns_type) { + if (Str.eq(name, id)) { + ret some(ast.def_ty(defid)); + } + } else { + for (ast.variant v in variants) { + if (Str.eq(v.node.name, id)) { + ret some(ast.def_variant( + defid, v.node.id)); + } + } + } + } + case (_) { + if (Str.eq(ast.item_ident(it), id)) { + auto found = found_def_item(it, ns); + if (found != none[def]) { ret found; } + } + } + } } } } + case (_) {} } - case (_) { } } ret none[def]; } fn found_def_item(@ast.item i, namespace ns) -> Option.t[def] { alt (i.node) { - case (ast.item_const(_, _, _, ?id, _)) { - if (ns == ns_value) { - ret some(ast.def_const(id)); - } + case (ast.item_const(_, _, _, ?defid, _)) { + if (ns == ns_value) { ret some(ast.def_const(defid)); } } - case (ast.item_fn(_, _, _, ?id, _)) { - if (ns == ns_value) { - ret some(ast.def_fn(id)); - } + case (ast.item_fn(_, _, _, ?defid, _)) { + if (ns == ns_value) { ret some(ast.def_fn(defid)); } } - case (ast.item_mod(_, _, ?id)) { - ret some(ast.def_mod(id)); + case (ast.item_mod(_, _, ?defid)) { + ret some(ast.def_mod(defid)); } - case (ast.item_native_mod(_, _, ?id)) { - ret some(ast.def_native_mod(id)); + case (ast.item_native_mod(_, _, ?defid)) { + ret some(ast.def_native_mod(defid)); } - case (ast.item_ty(_, _, _, ?id, _)) { - if (ns == ns_type) { - ret some(ast.def_ty(id)); - } + case (ast.item_ty(_, _, _, ?defid, _)) { + if (ns == ns_type) { ret some(ast.def_ty(defid)); } } - case (ast.item_tag(_, _, _, ?id, _)) { - if (ns == ns_type) { - ret some(ast.def_ty(id)); - } + case (ast.item_tag(_, _, _, ?defid, _)) { + if (ns == ns_type) { ret some(ast.def_ty(defid)); } } case (ast.item_obj(_, _, _, ?odid, _)) { - if (ns == ns_value) { - ret some(ast.def_obj(odid.ctor)); - } else { - ret some(ast.def_obj(odid.ty)); - } + if (ns == ns_value) { ret some(ast.def_obj(odid.ctor)); } + else { ret some(ast.def_obj(odid.ty)); } } case (_) { } } ret none[def]; } -fn found_def_tag(@ast.item item, uint variant_idx) -> def { - alt (item.node) { - case (ast.item_tag(_, ?variants, _, ?tid, _)) { - auto vid = variants.(variant_idx).node.id; - ret ast.def_variant(tid, vid); - } - case (_) { - log_err "tag item not actually a tag"; - fail; - } - } -} - fn lookup_in_mod_strict(&env e, def m, &span sp, ident id, namespace ns, dir dr) -> def { alt (lookup_in_mod(e, m, id, ns, dr)) { diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index 7e948376..fca0ab23 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -1507,7 +1507,6 @@ mod Pushdown { auto e_1 = pushdown_expr(fcx, expected, e_0); auto block_ = rec(stmts=bloc.node.stmts, expr=some[@ast.expr](e_1), - index=bloc.node.index, a=plain_ann(fcx.ccx.tcx)); ret fold.respan[ast.block_](bloc.span, block_); } @@ -2806,7 +2805,6 @@ fn check_block(&@fn_ctxt fcx, &ast.block block) -> ast.block { ret fold.respan[ast.block_](block.span, rec(stmts=stmts, expr=expr, - index=block.node.index, a=plain_ann(fcx.ccx.tcx))); } diff --git a/src/comp/middle/typestate_check.rs b/src/comp/middle/typestate_check.rs index 4346db02..d4e2e8c6 100644 --- a/src/comp/middle/typestate_check.rs +++ b/src/comp/middle/typestate_check.rs @@ -6,7 +6,6 @@ import front.ast.mutability; import front.ast.item; import front.ast.block; import front.ast.block_; -import front.ast.block_index_entry; import front.ast.mod_index_entry; import front.ast.obj_field; import front.ast.decl; @@ -2337,12 +2336,10 @@ fn annotate_stmt(&fn_info_map fm, &@stmt s) -> @stmt { } fn annotate_block(&fn_info_map fm, &block b) -> block { let vec[@stmt] new_stmts = vec(); - auto new_index = new_str_hash[block_index_entry](); for (@stmt s in b.node.stmts) { auto new_s = annotate_stmt(fm, s); Vec.push[@stmt](new_stmts, new_s); - ast.index_stmt(new_index, new_s); } fn ann_e(fn_info_map fm, &@expr e) -> @expr { ret annotate_expr(fm, e); @@ -2352,7 +2349,7 @@ fn annotate_block(&fn_info_map fm, &block b) -> block { auto new_e = Option.map[@expr, @expr](f, b.node.expr); ret respan(b.span, - rec(stmts=new_stmts, expr=new_e, index=new_index with b.node)); + rec(stmts=new_stmts, expr=new_e with b.node)); } fn annotate_fn(&fn_info_map fm, &ast._fn f) -> ast._fn { // subexps have *already* been annotated based on |