about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorMarijn Haverbeke <marijnh@gmail.com>2011-05-11 15:10:24 +0200
committerMarijn Haverbeke <marijnh@gmail.com>2011-05-11 15:10:24 +0200
commit5405f45274dc6dce53743092dc0679a5f43482d9 (patch)
treed1417d56ca0770e3cbf7abf1273ed1f2fce3fe4c /src/comp
parent7d086df0954263c2667fb4af65ab82b7e39d51ca (diff)
downloadrust-5405f45274dc6dce53743092dc0679a5f43482d9.tar.gz
rust-5405f45274dc6dce53743092dc0679a5f43482d9.zip
Get rid of block indices
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/front/ast.rs57
-rw-r--r--src/comp/front/parser.rs11
-rw-r--r--src/comp/middle/fold.rs4
-rw-r--r--src/comp/middle/resolve.rs99
-rw-r--r--src/comp/middle/typeck.rs2
-rw-r--r--src/comp/middle/typestate_check.rs5
6 files changed, 62 insertions, 116 deletions
diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs
index e7328d7ae3f..01dea8d82fb 100644
--- a/src/comp/front/ast.rs
+++ b/src/comp/front/ast.rs
@@ -94,15 +94,8 @@ type meta_item = spanned[meta_item_];
 type meta_item_ = rec(ident name, str value);
 
 type block = spanned[block_];
-type block_index = hashmap[ident, block_index_entry];
-tag block_index_entry {
-    bie_item(@item);
-    bie_local(@local);
-    bie_tag_variant(@item /* tag item */, uint /* variant index */);
-}
 type block_ = rec(vec[@stmt] stmts,
                   Option.t[@expr] expr,
-                  hashmap[ident,block_index_entry] index,
                   ann a); /* ann is only meaningful for the ts_ann field */
 
 type variant_def = tup(def_id /* tag */, def_id /* variant */);
@@ -421,6 +414,18 @@ tag item_ {
     item_obj(ident, _obj, vec[ty_param], obj_def_ids, ann);
 }
 
+fn item_ident(@item it) -> ident {
+    ret alt (it.node) {
+        case (item_const(?ident, _, _, _, _)) { ident }
+        case (item_fn(?ident, _, _, _, _)) { ident }
+        case (item_mod(?ident, _, _)) { ident }
+        case (item_native_mod(?ident, _, _)) { ident }
+        case (item_ty(?ident, _, _, _, _)) { ident }
+        case (item_tag(?ident, _, _, _, _)) { ident }
+        case (item_obj(?ident, _, _, _, _)) { ident }
+    }
+}
+
 type native_item = spanned[native_item_];
 tag native_item_ {
     native_item_ty(ident, def_id);
@@ -500,44 +505,6 @@ fn index_native_view_item(native_mod_index index, @view_item it) {
     }
 }
 
-fn index_stmt(block_index index, @stmt s) {
-    alt (s.node) {
-        case (ast.stmt_decl(?d,_)) {
-            alt (d.node) {
-                case (ast.decl_local(?loc)) {
-                    index.insert(loc.ident, ast.bie_local(loc));
-                }
-                case (ast.decl_item(?it)) {
-                    alt (it.node) {
-                        case (ast.item_fn(?i, _, _, _, _)) {
-                            index.insert(i, ast.bie_item(it));
-                        }
-                        case (ast.item_mod(?i, _, _)) {
-                            index.insert(i, ast.bie_item(it));
-                        }
-                        case (ast.item_ty(?i, _, _, _, _)) {
-                            index.insert(i, ast.bie_item(it));
-                        }
-                        case (ast.item_tag(?i, ?variants, _, _, _)) {
-                            index.insert(i, ast.bie_item(it));
-                            let uint vid = 0u;
-                            for (ast.variant v in variants) {
-                                auto t = ast.bie_tag_variant(it, vid);
-                                index.insert(v.node.name, t);
-                                vid += 1u;
-                            }
-                        }
-                        case (ast.item_obj(?i, _, _, _, _)) {
-                            index.insert(i, ast.bie_item(it));
-                        }
-                    }
-                }
-            }
-        }
-        case (_) { /* fall through */ }
-    }
-}
-
 fn is_exported(ident i, _mod m) -> bool {
     auto count = 0;
     for (@ast.view_item vi in m.view_items) {
diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs
index 46cad2fd8dc..69f0e0546c4 100644
--- a/src/comp/front/parser.rs
+++ b/src/comp/front/parser.rs
@@ -1626,15 +1626,6 @@ fn parse_source_stmt(parser p) -> @ast.stmt {
     fail;
 }
 
-fn index_block(parser p, vec[@ast.stmt] stmts, Option.t[@ast.expr] expr)
-        -> ast.block_ {
-    auto index = new_str_hash[ast.block_index_entry]();
-    for (@ast.stmt s in stmts) {
-        ast.index_stmt(index, s);
-    }
-    ret rec(stmts=stmts, expr=expr, index=index, a=p.get_ann());
-}
-
 fn index_arm(@ast.pat pat) -> hashmap[ast.ident,ast.def_id] {
     fn do_index_arm(&hashmap[ast.ident,ast.def_id] index, @ast.pat pat) {
         alt (pat.node) {
@@ -1770,7 +1761,7 @@ fn parse_block(parser p) -> ast.block {
     auto hi = p.get_hi_pos();
     p.bump();
 
-    auto bloc = index_block(p, stmts, expr);
+    auto bloc = rec(stmts=stmts, expr=expr, a=p.get_ann());
     ret spanned[ast.block_](lo, hi, bloc);
 }
 
diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs
index 62521067c91..bf85297f4d4 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 ce2048af80b..ee3288ac377 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 7e948376b72..fca0ab2308b 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 4346db02444..d4e2e8c6335 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