rustc: Annotate variants with their types. This may be useful for trans!
This commit is contained in:
parent
cd97b9d965
commit
fd600bad46
@ -183,7 +183,7 @@ tag mod_index_entry {
|
||||
type _mod = rec(vec[@item] items,
|
||||
hashmap[ident,mod_index_entry] index);
|
||||
|
||||
type variant = rec(str name, vec[@ty] args, def_id id);
|
||||
type variant = rec(str name, vec[@ty] args, def_id id, ann ann);
|
||||
|
||||
type item = spanned[item_];
|
||||
tag item_ {
|
||||
|
@ -1283,7 +1283,8 @@ impure fn parse_item_tag(parser p) -> @ast.item {
|
||||
expect(p, token.SEMI);
|
||||
|
||||
auto id = p.next_def_id();
|
||||
variants += vec(rec(name=name, args=args, id=id));
|
||||
variants += vec(rec(name=name, args=args, id=id,
|
||||
ann=ast.ann_none));
|
||||
}
|
||||
case (token.RBRACE) { /* empty */ }
|
||||
case (_) {
|
||||
|
@ -591,7 +591,8 @@ fn fold_item[ENV](&ENV env, ast_fold[ENV] fld, @item i) -> @item {
|
||||
for (@ast.ty t in v.args) {
|
||||
new_args += vec(fold_ty[ENV](env_, fld, t));
|
||||
}
|
||||
new_variants += rec(name=v.name, args=new_args, id=v.id);
|
||||
new_variants += rec(name=v.name, args=new_args, id=v.id,
|
||||
ann=v.ann);
|
||||
}
|
||||
ret fld.fold_item_tag(env_, i.span, ident, new_variants,
|
||||
ty_params, id);
|
||||
|
@ -402,10 +402,12 @@ fn collect_item_types(@ast.crate crate) -> tup(@ast.crate, @ty_table) {
|
||||
}
|
||||
}
|
||||
|
||||
fn add_tag_variant_types(@hashmap[ast.def_id,@ast.item] id_to_ty_item,
|
||||
fn get_tag_variant_types(@hashmap[ast.def_id,@ast.item] id_to_ty_item,
|
||||
@ty_table item_to_ty,
|
||||
&ast.def_id tag_id,
|
||||
&vec[ast.variant] variants) {
|
||||
&vec[ast.variant] variants) -> vec[ast.variant] {
|
||||
let vec[ast.variant] result = vec();
|
||||
|
||||
for (ast.variant variant in variants) {
|
||||
// Nullary tag constructors get turned into constants; n-ary tag
|
||||
// constructors get turned into functions.
|
||||
@ -427,7 +429,12 @@ fn collect_item_types(@ast.crate crate) -> tup(@ast.crate, @ty_table) {
|
||||
}
|
||||
|
||||
item_to_ty.insert(variant.id, result_ty);
|
||||
|
||||
auto variant_t = rec(ann=ast.ann_type(result_ty) with variant);
|
||||
result += vec(variant_t);
|
||||
}
|
||||
|
||||
ret result;
|
||||
}
|
||||
|
||||
// First pass: collect all type item IDs.
|
||||
@ -463,10 +470,12 @@ fn collect_item_types(@ast.crate crate) -> tup(@ast.crate, @ty_table) {
|
||||
case (ast.item_mod(_, _, _)) {
|
||||
result = it.node;
|
||||
}
|
||||
case (ast.item_tag(_, ?variants, _, ?tag_id)) {
|
||||
add_tag_variant_types(id_to_ty_item, item_to_ty, tag_id,
|
||||
variants);
|
||||
result = it.node;
|
||||
case (ast.item_tag(?ident, ?variants, ?tps, ?tag_id)) {
|
||||
auto variants_t = get_tag_variant_types(id_to_ty_item,
|
||||
item_to_ty,
|
||||
tag_id,
|
||||
variants);
|
||||
result = ast.item_tag(ident, variants_t, tps, tag_id);
|
||||
}
|
||||
}
|
||||
items_t += vec(@fold.respan[ast.item_](it.span, result));
|
||||
|
Loading…
x
Reference in New Issue
Block a user