diff options
| author | Marijn Haverbeke <[email protected]> | 2011-05-11 16:30:48 +0200 |
|---|---|---|
| committer | Marijn Haverbeke <[email protected]> | 2011-05-11 17:11:44 +0200 |
| commit | 14f1fe0e29d5f4d832ef622b7a1a49e5c591e1c0 (patch) | |
| tree | 838f21d4c374f114571e0c895eabcf8676566252 /src/comp/front | |
| parent | Add a missed xfail-stage0 (diff) | |
| download | rust-14f1fe0e29d5f4d832ef622b7a1a49e5c591e1c0.tar.xz rust-14f1fe0e29d5f4d832ef622b7a1a49e5c591e1c0.zip | |
Remove mod indices from the AST
They are now created by the resolve pass, which is the only pass that
needs them, and kept internal to that pass.
Diffstat (limited to 'src/comp/front')
| -rw-r--r-- | src/comp/front/ast.rs | 91 | ||||
| -rw-r--r-- | src/comp/front/eval.rs | 46 | ||||
| -rw-r--r-- | src/comp/front/parser.rs | 38 |
3 files changed, 27 insertions, 148 deletions
diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs index 3d8090b0..8cfffc39 100644 --- a/src/comp/front/ast.rs +++ b/src/comp/front/ast.rs @@ -360,21 +360,8 @@ type _obj = rec(vec[obj_field] fields, vec[@method] methods, Option.t[@method] dtor); -tag mod_index_entry { - mie_view_item(@view_item); - mie_item(@item); - mie_tag_variant(@item /* tag item */, uint /* variant index */); -} - -tag native_mod_index_entry { - nmie_view_item(@view_item); - nmie_item(@native_item); -} - -type mod_index = hashmap[ident,mod_index_entry]; type _mod = rec(vec[@view_item] view_items, - vec[@item] items, - mod_index index); + vec[@item] items); tag native_abi { native_abi_rust; @@ -386,9 +373,7 @@ tag native_abi { type native_mod = rec(str native_name, native_abi abi, vec[@view_item] view_items, - vec[@native_item] items, - native_mod_index index); -type native_mod_index = hashmap[ident,native_mod_index_entry]; + vec[@native_item] items); type variant_arg = rec(@ty ty, def_id id); type variant_ = rec(str name, vec[variant_arg] args, def_id id, ann ann); @@ -433,78 +418,6 @@ tag native_item_ { fn_decl, vec[ty_param], def_id, ann); } -fn index_view_item(mod_index index, @view_item it) { - alt (it.node) { - case(ast.view_item_use(?id, _, _, _)) { - index.insert(id, ast.mie_view_item(it)); - } - case(ast.view_item_import(?def_ident,_,_)) { - index.insert(def_ident, ast.mie_view_item(it)); - } - case(ast.view_item_export(_)) { - // NB: don't index these, they might collide with - // the import or use that they're exporting. Have - // to do linear search for exports. - } - } -} - -fn index_item(mod_index index, @item it) { - alt (it.node) { - case (ast.item_const(?id, _, _, _, _)) { - index.insert(id, ast.mie_item(it)); - } - case (ast.item_fn(?id, _, _, _, _)) { - index.insert(id, ast.mie_item(it)); - } - case (ast.item_mod(?id, _, _)) { - index.insert(id, ast.mie_item(it)); - } - case (ast.item_native_mod(?id, _, _)) { - index.insert(id, ast.mie_item(it)); - } - case (ast.item_ty(?id, _, _, _, _)) { - index.insert(id, ast.mie_item(it)); - } - case (ast.item_tag(?id, ?variants, _, _, _)) { - index.insert(id, ast.mie_item(it)); - let uint variant_idx = 0u; - for (ast.variant v in variants) { - index.insert(v.node.name, - ast.mie_tag_variant(it, variant_idx)); - variant_idx += 1u; - } - } - case (ast.item_obj(?id, _, _, _, _)) { - index.insert(id, ast.mie_item(it)); - } - } -} - -fn index_native_item(native_mod_index index, @native_item it) { - alt (it.node) { - case (ast.native_item_ty(?id, _)) { - index.insert(id, ast.nmie_item(it)); - } - case (ast.native_item_fn(?id, _, _, _, _, _)) { - index.insert(id, ast.nmie_item(it)); - } - } -} - -fn index_native_view_item(native_mod_index index, @view_item it) { - alt (it.node) { - case(ast.view_item_import(?def_ident,_,_)) { - index.insert(def_ident, ast.nmie_view_item(it)); - } - case(ast.view_item_export(_)) { - // NB: don't index these, they might collide with - // the import or use that they're exporting. Have - // to do linear search for exports. - } - } -} - 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/eval.rs b/src/comp/front/eval.rs index e1ad59bc..1d708f17 100644 --- a/src/comp/front/eval.rs +++ b/src/comp/front/eval.rs @@ -236,13 +236,11 @@ fn eval_crate_directives(ctx cx, vec[@ast.crate_directive] cdirs, str prefix, &mutable vec[@ast.view_item] view_items, - &mutable vec[@ast.item] items, - hashmap[ast.ident, - ast.mod_index_entry] index) { + &mutable vec[@ast.item] items) { for (@ast.crate_directive sub_cdir in cdirs) { eval_crate_directive(cx, e, sub_cdir, prefix, - view_items, items, index); + view_items, items); } } @@ -252,12 +250,11 @@ fn eval_crate_directives_to_mod(ctx cx, env e, str prefix) -> ast._mod { let vec[@ast.view_item] view_items = vec(); let vec[@ast.item] items = vec(); - auto index = new_str_hash[ast.mod_index_entry](); eval_crate_directives(cx, e, cdirs, prefix, - view_items, items, index); + view_items, items); - ret rec(view_items=view_items, items=items, index=index); + ret rec(view_items=view_items, items=items); } @@ -266,15 +263,13 @@ fn eval_crate_directive_block(ctx cx, &ast.block blk, str prefix, &mutable vec[@ast.view_item] view_items, - &mutable vec[@ast.item] items, - hashmap[ast.ident, - ast.mod_index_entry] index) { + &mutable vec[@ast.item] items) { for (@ast.stmt s in blk.node.stmts) { alt (s.node) { case (ast.stmt_crate_directive(?cdir)) { eval_crate_directive(cx, e, cdir, prefix, - view_items, items, index); + view_items, items); } case (_) { cx.sess.span_err(s.span, @@ -289,9 +284,7 @@ fn eval_crate_directive_expr(ctx cx, @ast.expr x, str prefix, &mutable vec[@ast.view_item] view_items, - &mutable vec[@ast.item] items, - hashmap[ast.ident, - ast.mod_index_entry] index) { + &mutable vec[@ast.item] items) { alt (x.node) { case (ast.expr_if(?cond, ?thn, ?elopt, _)) { @@ -302,15 +295,13 @@ fn eval_crate_directive_expr(ctx cx, if (val_as_bool(cv)) { ret eval_crate_directive_block(cx, e, thn, prefix, - view_items, items, - index); + view_items, items); } alt (elopt) { case (some[@ast.expr](?els)) { ret eval_crate_directive_expr(cx, e, els, prefix, - view_items, items, - index); + view_items, items); } case (_) { // Absent-else is ok. @@ -326,14 +317,13 @@ fn eval_crate_directive_expr(ctx cx, auto pv = eval_lit(cx, arm.pat.span, lit); if (val_eq(cx.sess, arm.pat.span, vv, pv)) { ret eval_crate_directive_block - (cx, e, arm.block, prefix, - view_items, items, index); + (cx, e, arm.block, prefix, view_items, items); } } case (ast.pat_wild(_)) { ret eval_crate_directive_block (cx, e, arm.block, prefix, - view_items, items, index); + view_items, items); } case (_) { cx.sess.span_err(arm.pat.span, @@ -346,8 +336,7 @@ fn eval_crate_directive_expr(ctx cx, case (ast.expr_block(?block, _)) { ret eval_crate_directive_block(cx, e, block, prefix, - view_items, items, - index); + view_items, items); } case (_) { @@ -361,21 +350,19 @@ fn eval_crate_directive(ctx cx, @ast.crate_directive cdir, str prefix, &mutable vec[@ast.view_item] view_items, - &mutable vec[@ast.item] items, - hashmap[ast.ident, - ast.mod_index_entry] index) { + &mutable vec[@ast.item] items) { alt (cdir.node) { case (ast.cdir_let(?id, ?x, ?cdirs)) { auto v = eval_expr(cx, e, x); auto e0 = vec(tup(id, v)) + e; eval_crate_directives(cx, e0, cdirs, prefix, - view_items, items, index); + view_items, items); } case (ast.cdir_expr(?x)) { eval_crate_directive_expr(cx, e, x, prefix, - view_items, items, index); + view_items, items); } case (ast.cdir_src_mod(?id, ?file_opt)) { @@ -404,7 +391,6 @@ fn eval_crate_directive(ctx cx, cx.chpos = p0.get_chpos(); auto im = ast.item_mod(id, m0, next_id); auto i = @spanned(cdir.span.lo, cdir.span.hi, im); - ast.index_item(index, i); Vec.push[@ast.item](items, i); } @@ -422,13 +408,11 @@ fn eval_crate_directive(ctx cx, auto m0 = eval_crate_directives_to_mod(cx, e, cdirs, full_path); auto im = ast.item_mod(id, m0, cx.p.next_def_id()); auto i = @spanned(cdir.span.lo, cdir.span.hi, im); - ast.index_item(index, i); Vec.push[@ast.item](items, i); } case (ast.cdir_view_item(?vi)) { Vec.push[@ast.view_item](view_items, vi); - ast.index_view_item(index, vi); } case (ast.cdir_meta(?mi)) { diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index 10432389..33b74d8d 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -1889,17 +1889,12 @@ fn parse_item_obj(parser p, ast.layer lyr) -> @ast.item { } fn parse_mod_items(parser p, token.token term) -> ast._mod { - auto index = new_str_hash[ast.mod_index_entry](); - auto view_items = parse_view(p, index); + auto view_items = parse_view(p); let vec[@ast.item] items = vec(); while (p.peek() != term) { - auto item = parse_item(p); - items += vec(item); - - // Index the item. - ast.index_item(index, item); + items += vec(parse_item(p)); } - ret rec(view_items=view_items, items=items, index=index); + ret rec(view_items=view_items, items=items); } fn parse_item_const(parser p) -> @ast.item { @@ -1972,22 +1967,16 @@ fn parse_native_item(parser p) -> @ast.native_item { fn parse_native_mod_items(parser p, str native_name, ast.native_abi abi) -> ast.native_mod { - auto index = new_str_hash[ast.native_mod_index_entry](); let vec[@ast.native_item] items = vec(); - auto view_items = parse_native_view(p, index); + auto view_items = parse_native_view(p); while (p.peek() != token.RBRACE) { - auto item = parse_native_item(p); - items += vec(item); - - // Index the item. - ast.index_native_item(index, item); + items += vec(parse_native_item(p)); } ret rec(native_name=native_name, abi=abi, view_items=view_items, - items=items, - index=index); + items=items); } fn default_native_name(session.session sess, str id) -> str { @@ -2353,25 +2342,18 @@ fn is_view_item(token.token t) -> bool { ret false; } -fn parse_view(parser p, ast.mod_index index) -> vec[@ast.view_item] { +fn parse_view(parser p) -> vec[@ast.view_item] { let vec[@ast.view_item] items = vec(); while (is_view_item(p.peek())) { - auto item = parse_view_item(p); - items += vec(item); - - ast.index_view_item(index, item); + items += vec(parse_view_item(p)); } ret items; } -fn parse_native_view(parser p, ast.native_mod_index index) - -> vec[@ast.view_item] { +fn parse_native_view(parser p) -> vec[@ast.view_item] { let vec[@ast.view_item] items = vec(); while (is_view_item(p.peek())) { - auto item = parse_view_item(p); - items += vec(item); - - ast.index_native_view_item(index, item); + items += vec(parse_view_item(p)); } ret items; } |