diff options
| author | Patrick Walton <[email protected]> | 2011-02-25 16:45:43 -0800 |
|---|---|---|
| committer | Patrick Walton <[email protected]> | 2011-02-25 16:45:43 -0800 |
| commit | b5081a6a825f23b45920cf72896076039f30386d (patch) | |
| tree | bafefc0a703c81ad26a6c56734807b385cbd17ba /src | |
| parent | rustc: Move all of the logic in type_of() to type_of_inner() (diff) | |
| download | rust-b5081a6a825f23b45920cf72896076039f30386d.tar.xz rust-b5081a6a825f23b45920cf72896076039f30386d.zip | |
Add a tag_variant_count() function to trans that doesn't go through the soon-to-be-deprecated tag info table
Diffstat (limited to 'src')
| -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)); |