Skip to content

No index #191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 45 additions & 3 deletions src/comp/front/ast.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

import std.map.hashmap;
import std.option;
import std._vec;
import util.common.span;
import util.common.spanned;
import util.common.ty_mach;
Expand Down Expand Up @@ -213,9 +214,9 @@ type _obj = rec(vec[obj_field] fields,


tag mod_index_entry {
mie_view_item(uint);
mie_item(uint);
mie_tag_variant(uint /* tag item index */, uint /* variant index */);
mie_view_item(@view_item);
mie_item(@item);
mie_tag_variant(@item /* tag item */, uint /* variant index */);
}

type mod_index = hashmap[ident,mod_index_entry];
Expand All @@ -242,6 +243,47 @@ tag item_ {
item_obj(ident, _obj, 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(?ids,_)) {
auto len = _vec.len[ast.ident](ids);
auto last_id = ids.(len - 1u);
index.insert(last_id, ast.mie_view_item(it));
}
}
}

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_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.name,
ast.mie_tag_variant(it, variant_idx));
variant_idx += 1u;
}
}
case (ast.item_obj(?id, _, _, _, _)) {
index.insert(id, ast.mie_item(it));
}
}
}

//
// Local Variables:
Expand Down
54 changes: 8 additions & 46 deletions src/comp/front/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1418,44 +1418,16 @@ impure fn parse_item_obj(parser p, ast.layer lyr) -> @ast.item {
ret @spanned(lo, meths.span, item);
}

fn index_mod_item(@ast.item item, ast.mod_index index, uint u) {
alt (item.node) {
case (ast.item_const(?id, _, _, _, _)) {
index.insert(id, ast.mie_item(u));
}
case (ast.item_fn(?id, _, _, _, _)) {
index.insert(id, ast.mie_item(u));
}
case (ast.item_mod(?id, _, _)) {
index.insert(id, ast.mie_item(u));
}
case (ast.item_ty(?id, _, _, _, _)) {
index.insert(id, ast.mie_item(u));
}
case (ast.item_tag(?id, ?variants, _, _)) {
index.insert(id, ast.mie_item(u));
let uint variant_idx = 0u;
for (ast.variant v in variants) {
index.insert(v.name, ast.mie_tag_variant(u, variant_idx));
variant_idx += 1u;
}
}
case (ast.item_obj(?id, _, _, _, _)) {
index.insert(id, ast.mie_item(u));
}
}
}

impure 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);
let uint u = 0u;
let vec[@ast.item] items = vec();
while (p.peek() != term) {
auto item = parse_item(p);
items += vec(item);
index_mod_item(item, index, u);
u += 1u;

// Index the item.
ast.index_item(index, item);
}
ret rec(view_items=view_items, items=items, index=index);
}
Expand Down Expand Up @@ -1760,21 +1732,11 @@ fn is_use_or_import(token.token t) -> bool {

impure fn parse_view(parser p, ast.mod_index index) -> vec[@ast.view_item] {
let vec[@ast.view_item] items = vec();
let uint u = 0u;
while (is_use_or_import(p.peek())) {
auto item = parse_use_or_import(p);
items += vec(item);
alt (item.node) {
case(ast.view_item_use(?id, _, _)) {
index.insert(id, ast.mie_view_item(u));
}
case(ast.view_item_import(?ids,_)) {
auto len = _vec.len[ast.ident](ids);
auto last_id = ids.(len - 1u);
index.insert(last_id, ast.mie_view_item(u));
}
}
u = u + 1u;

ast.index_view_item(index, item);
}
ret items;
}
Expand All @@ -1801,7 +1763,7 @@ impure fn parse_crate_directive(str prefix, parser p,
alt (p.peek()) {
case (token.CONST) {
auto c = parse_item_const(p);
index_mod_item(c, index, _vec.len[@ast.item](items));
ast.index_item(index, c);
append[@ast.item](items, c);
}
case (token.MOD) {
Expand Down Expand Up @@ -1834,7 +1796,7 @@ impure fn parse_crate_directive(str prefix, parser p,
auto m0 = parse_mod_items(p0, token.EOF);
auto im = ast.item_mod(id, m0, p.next_def_id());
auto i = @spanned(lo, hi, im);
index_mod_item(i, index, _vec.len[@ast.item](items));
ast.index_item(index, i);
append[@ast.item](items, i);
}

Expand All @@ -1848,7 +1810,7 @@ impure fn parse_crate_directive(str prefix, parser p,
expect(p, token.RBRACE);
auto im = ast.item_mod(id, m0, p.next_def_id());
auto i = @spanned(lo, hi, im);
index_mod_item(i, index, _vec.len[@ast.item](items));
ast.index_item(index, i);
append[@ast.item](items, i);
}

Expand Down
10 changes: 7 additions & 3 deletions src/comp/middle/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,14 +779,18 @@ fn fold_mod[ENV](&ENV e, ast_fold[ENV] fld, &ast._mod m) -> ast._mod {

let vec[@view_item] view_items = vec();
let vec[@item] items = vec();
auto index = m.index;
auto index = new_str_hash[ast.mod_index_entry]();

for (@view_item vi in m.view_items) {
append[@view_item](view_items, fold_view_item[ENV](e, fld, vi));
auto new_vi = fold_view_item[ENV](e, fld, vi);
append[@view_item](view_items, new_vi);
ast.index_view_item(index, new_vi);
}

for (@item i in m.items) {
append[@item](items, fold_item[ENV](e, fld, i));
auto new_item = fold_item[ENV](e, fld, i);
append[@item](items, new_item);
ast.index_item(index, new_item);
}

ret fld.fold_mod(e, rec(view_items=view_items, items=items, index=index));
Expand Down
12 changes: 6 additions & 6 deletions src/comp/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,14 @@ fn lookup_name(&env e, option.t[import_map] index,
alt (m.index.find(i)) {
case (some[ast.mod_index_entry](?ent)) {
alt (ent) {
case (ast.mie_view_item(?ix)) {
ret found_def_view(e, index, m.view_items.(ix));
case (ast.mie_view_item(?view_item)) {
ret found_def_view(e, index, view_item);
}
case (ast.mie_item(?ix)) {
ret found_def_item(m.items.(ix));
case (ast.mie_item(?item)) {
ret found_def_item(item);
}
case (ast.mie_tag_variant(?item_idx, ?variant_idx)) {
alt (m.items.(item_idx).node) {
case (ast.mie_tag_variant(?item, ?variant_idx)) {
alt (item.node) {
case (ast.item_tag(_, ?variants, _, ?tid)) {
auto vid = variants.(variant_idx).id;
auto t = ast.def_variant(tid, vid);
Expand Down