Skip to content

Commit 54cbfa8

Browse files
committed
---
yaml --- r: 984 b: refs/heads/master c: 42282a2 h: refs/heads/master v: v3
1 parent ef58fa1 commit 54cbfa8

File tree

4 files changed

+66
-19
lines changed

4 files changed

+66
-19
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 4dc98e54d1191b5414e6e04367fd4e3d80311cfa
2+
refs/heads/master: 42282a25c03182a19e80fb1a3294d3869859d6fa

trunk/src/comp/front/ast.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ tag def {
3030
def_const(def_id);
3131
def_arg(def_id);
3232
def_local(def_id);
33-
def_variant(def_id);
33+
def_variant(def_id /* tag */, def_id /* variant */);
3434
def_ty(def_id);
3535
def_ty_arg(def_id);
3636
}
@@ -175,8 +175,13 @@ type _fn = rec(vec[arg] inputs,
175175
@ty output,
176176
block body);
177177

178+
tag mod_index_entry {
179+
mie_item(uint);
180+
mie_tag_variant(uint /* tag item index */, uint /* variant index */);
181+
}
182+
178183
type _mod = rec(vec[@item] items,
179-
hashmap[ident,uint] index);
184+
hashmap[ident,mod_index_entry] index);
180185

181186
type variant = rec(str name, vec[@ty] args, def_id id);
182187

trunk/src/comp/front/parser.rs

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,7 @@ impure fn parse_ty_params(parser p) -> vec[ast.ty_param] {
11551155
ret ty_params;
11561156
}
11571157

1158-
impure fn parse_item_fn(parser p) -> tup(ast.ident, @ast.item) {
1158+
impure fn parse_item_fn(parser p) -> @ast.item {
11591159
auto lo = p.get_span();
11601160
expect(p, token.FN);
11611161
auto id = parse_ident(p);
@@ -1186,23 +1186,46 @@ impure fn parse_item_fn(parser p) -> tup(ast.ident, @ast.item) {
11861186
body = body);
11871187

11881188
auto item = ast.item_fn(id, f, ty_params, p.next_def_id(), ast.ann_none);
1189-
ret tup(id, @spanned(lo, body.span, item));
1189+
ret @spanned(lo, body.span, item);
11901190
}
11911191

11921192
impure fn parse_mod_items(parser p, token.token term) -> ast._mod {
1193-
let vec[@ast.item] items = vec();
1194-
let hashmap[ast.ident,uint] index = new_str_hash[uint]();
1193+
let vec[@ast.item] items = vec();
1194+
auto index = new_str_hash[ast.mod_index_entry]();
11951195
let uint u = 0u;
11961196
while (p.peek() != term) {
1197-
auto pair = parse_item(p);
1198-
append[@ast.item](items, pair._1);
1199-
index.insert(pair._0, u);
1197+
auto item = parse_item(p);
1198+
items += vec(item);
1199+
1200+
// Index the item.
1201+
alt (item.node) {
1202+
case (ast.item_fn(?id, _, _, _, _)) {
1203+
index.insert(id, ast.mie_item(u));
1204+
}
1205+
case (ast.item_mod(?id, _, _)) {
1206+
index.insert(id, ast.mie_item(u));
1207+
}
1208+
case (ast.item_ty(?id, _, _, _, _)) {
1209+
index.insert(id, ast.mie_item(u));
1210+
}
1211+
1212+
case (ast.item_tag(?id, ?variants, _, _)) {
1213+
index.insert(id, ast.mie_item(u));
1214+
1215+
let uint variant_idx = 0u;
1216+
for (ast.variant v in variants) {
1217+
index.insert(v.name, ast.mie_tag_variant(u, variant_idx));
1218+
variant_idx += 1u;
1219+
}
1220+
}
1221+
}
1222+
12001223
u += 1u;
12011224
}
12021225
ret rec(items=items, index=index);
12031226
}
12041227

1205-
impure fn parse_item_mod(parser p) -> tup(ast.ident, @ast.item) {
1228+
impure fn parse_item_mod(parser p) -> @ast.item {
12061229
auto lo = p.get_span();
12071230
expect(p, token.MOD);
12081231
auto id = parse_ident(p);
@@ -1211,10 +1234,10 @@ impure fn parse_item_mod(parser p) -> tup(ast.ident, @ast.item) {
12111234
auto hi = p.get_span();
12121235
expect(p, token.RBRACE);
12131236
auto item = ast.item_mod(id, m, p.next_def_id());
1214-
ret tup(id, @spanned(lo, hi, item));
1237+
ret @spanned(lo, hi, item);
12151238
}
12161239

1217-
impure fn parse_item_type(parser p) -> tup(ast.ident, @ast.item) {
1240+
impure fn parse_item_type(parser p) -> @ast.item {
12181241
auto lo = p.get_span();
12191242
expect(p, token.TYPE);
12201243
auto id = parse_ident(p);
@@ -1225,10 +1248,10 @@ impure fn parse_item_type(parser p) -> tup(ast.ident, @ast.item) {
12251248
auto hi = p.get_span();
12261249
expect(p, token.SEMI);
12271250
auto item = ast.item_ty(id, ty, tps, p.next_def_id(), ast.ann_none);
1228-
ret tup(id, @spanned(lo, hi, item));
1251+
ret @spanned(lo, hi, item);
12291252
}
12301253

1231-
impure fn parse_item_tag(parser p) -> tup(ast.ident, @ast.item) {
1254+
impure fn parse_item_tag(parser p) -> @ast.item {
12321255
auto lo = p.get_span();
12331256
expect(p, token.TAG);
12341257
auto id = parse_ident(p);
@@ -1273,10 +1296,10 @@ impure fn parse_item_tag(parser p) -> tup(ast.ident, @ast.item) {
12731296

12741297
auto hi = p.get_span();
12751298
auto item = ast.item_tag(id, variants, ty_params, p.next_def_id());
1276-
ret tup(id, @spanned(lo, hi, item));
1299+
ret @spanned(lo, hi, item);
12771300
}
12781301

1279-
impure fn parse_item(parser p) -> tup(ast.ident, @ast.item) {
1302+
impure fn parse_item(parser p) -> @ast.item {
12801303
alt (p.peek()) {
12811304
case (token.FN) {
12821305
ret parse_item_fn(p);

trunk/src/comp/middle/resolve.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ fn lookup_name(&env e, ast.ident i) -> option.t[def] {
3838
case (ast.item_ty(_, _, _, ?id, _)) {
3939
ret some[def](ast.def_ty(id));
4040
}
41+
case (ast.item_tag(_, _, _, ?id)) {
42+
ret some[def](ast.def_ty(id));
43+
}
4144
}
4245
}
4346

@@ -59,8 +62,24 @@ fn lookup_name(&env e, ast.ident i) -> option.t[def] {
5962

6063
fn check_mod(ast.ident i, ast._mod m) -> option.t[def] {
6164
alt (m.index.find(i)) {
62-
case (some[uint](?ix)) {
63-
ret found_def_item(m.items.(ix));
65+
case (some[ast.mod_index_entry](?ent)) {
66+
alt (ent) {
67+
case (ast.mie_item(?ix)) {
68+
ret found_def_item(m.items.(ix));
69+
}
70+
case (ast.mie_tag_variant(?item_idx, ?variant_idx)) {
71+
alt (m.items.(item_idx).node) {
72+
case (ast.item_tag(_, ?variants, _, ?tid)) {
73+
auto vid = variants.(variant_idx).id;
74+
ret some[def](ast.def_variant(tid, vid));
75+
}
76+
case (_) {
77+
log "tag item not actually a tag";
78+
fail;
79+
}
80+
}
81+
}
82+
}
6483
}
6584
}
6685
ret none[def];

0 commit comments

Comments
 (0)