diff options
Diffstat (limited to 'src/comp/front')
| -rw-r--r-- | src/comp/front/ast.rs | 8 | ||||
| -rw-r--r-- | src/comp/front/parser.rs | 24 |
2 files changed, 21 insertions, 11 deletions
diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs index 05daf5ee..c17eddee 100644 --- a/src/comp/front/ast.rs +++ b/src/comp/front/ast.rs @@ -66,9 +66,15 @@ 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,uint] index); + hashmap[ident,block_index_entry] index); type variant_def = tup(def_id /* tag */, def_id /* variant */); diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index 2836b120..58cbac00 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -1478,31 +1478,36 @@ impure fn parse_source_stmt(parser p) -> @ast.stmt { } fn index_block(vec[@ast.stmt] stmts, option.t[@ast.expr] expr) -> ast.block_ { - auto index = new_str_hash[uint](); - auto u = 0u; + auto index = new_str_hash[ast.block_index_entry](); for (@ast.stmt s in stmts) { alt (s.node) { case (ast.stmt_decl(?d)) { alt (d.node) { case (ast.decl_local(?loc)) { - index.insert(loc.ident, u); + index.insert(loc.ident, ast.bie_local(loc)); } case (ast.decl_item(?it)) { alt (it.node) { case (ast.item_fn(?i, _, _, _, _)) { - index.insert(i, u); + index.insert(i, ast.bie_item(it)); } case (ast.item_mod(?i, _, _)) { - index.insert(i, u); + index.insert(i, ast.bie_item(it)); } case (ast.item_ty(?i, _, _, _, _)) { - index.insert(i, u); + index.insert(i, ast.bie_item(it)); } - case (ast.item_tag(?i, _, _, _)) { - index.insert(i, u); + 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.name, t); + vid += 1u; + } } case (ast.item_obj(?i, _, _, _, _)) { - index.insert(i, u); + index.insert(i, ast.bie_item(it)); } } } @@ -1510,7 +1515,6 @@ fn index_block(vec[@ast.stmt] stmts, option.t[@ast.expr] expr) -> ast.block_ { } case (_) { /* fall through */ } } - u += 1u; } ret rec(stmts=stmts, expr=expr, index=index); } |