diff options
Diffstat (limited to 'src/comp')
| -rw-r--r-- | src/comp/middle/trans.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 29ff9d6e..cfe07caa 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -1442,6 +1442,8 @@ fn decr_refcnt_and_if_zero(@block_ctxt cx, ret res(next_cx, phi); } +// Tag information + fn type_of_variant(@crate_ctxt cx, &ast.variant v) -> TypeRef { let vec[TypeRef] lltys = vec(); alt (ty.ann_to_type(v.ann).struct) { @@ -1455,6 +1457,17 @@ fn type_of_variant(@crate_ctxt cx, &ast.variant v) -> TypeRef { ret T_struct(lltys); } +// Returns the number of variants in a tag. +fn tag_variant_count(@crate_ctxt cx, ast.def_id id) -> uint { + check (cx.items.contains_key(id)); + alt (cx.items.get(id).node) { + case (ast.item_tag(_, ?variants, _, _)) { + ret _vec.len[ast.variant](variants); + } + } + fail; // not reached +} + type val_and_ty_fn = fn(@block_ctxt cx, ValueRef v, @ty.t t) -> result; // Iterates through the elements of a structural type. @@ -1506,7 +1519,7 @@ fn iter_structural_ty(@block_ctxt cx, case (ty.ty_tag(?tid, ?tps)) { check (cx.fcx.ccx.tags.contains_key(tid)); auto info = cx.fcx.ccx.tags.get(tid); - auto n_variants = _vec.len[tup(ast.def_id,arity)](info.variants); + auto n_variants = tag_variant_count(cx.fcx.ccx, tid); // Look up the tag in the typechecked AST. check (cx.fcx.ccx.items.contains_key(tid)); |