diff options
| author | Graydon Hoare <[email protected]> | 2010-12-09 15:03:19 -0800 |
|---|---|---|
| committer | Graydon Hoare <[email protected]> | 2010-12-09 15:03:19 -0800 |
| commit | b7e344622c12bd25d73bfc5a2844e96705bf8d8a (patch) | |
| tree | 8e5729aec70fbda4c9fc9f7f8d049fb93e721003 /src/comp | |
| parent | First sketch of support for const items, not including most of trans. (diff) | |
| download | rust-b7e344622c12bd25d73bfc5a2844e96705bf8d8a.tar.xz rust-b7e344622c12bd25d73bfc5a2844e96705bf8d8a.zip | |
Add a type abbreviation and redo first pass of collect_item_types to collect across the whole crate, not just top level.
Diffstat (limited to 'src/comp')
| -rw-r--r-- | src/comp/middle/typeck.rs | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index 160dce2c..3692b7a7 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -353,7 +353,10 @@ fn type_err_to_str(&type_err err) -> str { // AST, along with a table mapping item IDs to their types. fn collect_item_types(@ast.crate crate) -> tup(@ast.crate, @ty_table) { - fn trans_ty_item_id_to_ty(@hashmap[ast.def_id,@ast.item] id_to_ty_item, + + type ty_item_table = hashmap[ast.def_id,@ast.item]; + + fn trans_ty_item_id_to_ty(@ty_item_table id_to_ty_item, @ty_table item_to_ty, ast.def_id id) -> @ty { check (id_to_ty_item.contains_key(id)); @@ -361,14 +364,14 @@ fn collect_item_types(@ast.crate crate) -> tup(@ast.crate, @ty_table) { ret trans_ty_item_to_ty(id_to_ty_item, item_to_ty, item); } - fn trans_fn_arg_to_ty(@hashmap[ast.def_id,@ast.item] id_to_ty_item, + fn trans_fn_arg_to_ty(@ty_item_table id_to_ty_item, @ty_table item_to_ty, &ast.arg a) -> arg { auto f = bind trans_ty_item_id_to_ty(id_to_ty_item, item_to_ty, _); ret rec(mode=a.mode, ty=ast_ty_to_ty(f, a.ty)); } - fn trans_ty_item_to_ty(@hashmap[ast.def_id,@ast.item] id_to_ty_item, + fn trans_ty_item_to_ty(@ty_item_table id_to_ty_item, @ty_table item_to_ty, @ast.item it) -> @ty { alt (it.node) { @@ -414,7 +417,7 @@ fn collect_item_types(@ast.crate crate) -> tup(@ast.crate, @ty_table) { } } - fn get_tag_variant_types(@hashmap[ast.def_id,@ast.item] id_to_ty_item, + fn get_tag_variant_types(@ty_item_table id_to_ty_item, @ty_table item_to_ty, &ast.def_id tag_id, &vec[ast.variant] variants) -> vec[ast.variant] { @@ -452,14 +455,22 @@ fn collect_item_types(@ast.crate crate) -> tup(@ast.crate, @ty_table) { // First pass: collect all type item IDs. auto module = crate.node.module; auto id_to_ty_item = @common.new_def_hash[@ast.item](); - for (@ast.item item in module.items) { - alt (item.node) { + fn collect(&@ty_item_table id_to_ty_item, @ast.item i) + -> @ty_item_table { + alt (i.node) { case (ast.item_ty(_, _, _, ?def_id, _)) { - id_to_ty_item.insert(def_id, item); + id_to_ty_item.insert(def_id, i); } case (_) { /* empty */ } } + ret id_to_ty_item; } + auto fld_1 = fold.new_identity_fold[@ty_item_table](); + auto f = collect; + fld_1 = @rec(update_env_for_item = f with *fld_1); + fold.fold_crate[@ty_item_table](id_to_ty_item, fld_1, crate); + + // Second pass: translate the types of all items. auto item_to_ty = @common.new_def_hash[@ty](); |