提交 76aabbe9 编写于 作者: M Marijn Haverbeke

Rename tag to enum throughout the compiler

This should reduce confusion of people trying to read the code.
上级 8420f8c5
......@@ -30,7 +30,7 @@
const tag_items_data_item_variant: uint = 0x0eu;
const tag_items_data_item_tag_id: uint = 0x0fu;
const tag_items_data_item_enum_id: uint = 0x0fu;
const tag_index: uint = 0x11u;
......
......@@ -9,7 +9,7 @@
export get_symbol;
export get_type_param_count;
export lookup_defs;
export get_tag_variants;
export get_enum_variants;
export get_impls_for_mod;
export get_iface_methods;
export get_type;
......@@ -56,10 +56,10 @@ fn resolve_path(cstore: cstore::cstore, cnum: ast::crate_num,
ret result;
}
fn get_tag_variants(tcx: ty::ctxt, def: ast::def_id) -> [ty::variant_info] {
fn get_enum_variants(tcx: ty::ctxt, def: ast::def_id) -> [ty::variant_info] {
let cstore = tcx.sess.cstore;
let cdata = cstore::get_crate_data(cstore, def.crate);
ret decoder::get_tag_variants(cdata, def.node, tcx)
ret decoder::get_enum_variants(cdata, def.node, tcx)
}
fn get_impls_for_mod(cstore: cstore::cstore, def: ast::def_id,
......
......@@ -11,7 +11,7 @@
import cmd=cstore::crate_metadata;
export get_symbol;
export get_tag_variants;
export get_enum_variants;
export get_type;
export get_type_param_count;
export get_impl_iface;
......@@ -86,8 +86,8 @@ fn item_symbol(item: ebml::doc) -> str {
ret str::unsafe_from_bytes(ebml::doc_data(sym));
}
fn variant_tag_id(d: ebml::doc) -> ast::def_id {
let tagdoc = ebml::get_doc(d, tag_items_data_item_tag_id);
fn variant_enum_id(d: ebml::doc) -> ast::def_id {
let tagdoc = ebml::get_doc(d, tag_items_data_item_enum_id);
ret parse_def_id(ebml::doc_data(tagdoc));
}
......@@ -147,7 +147,7 @@ fn item_ty_param_count(item: ebml::doc) -> uint {
n
}
fn tag_variant_ids(item: ebml::doc, cdata: cmd) -> [ast::def_id] {
fn enum_variant_ids(item: ebml::doc, cdata: cmd) -> [ast::def_id] {
let ids: [ast::def_id] = [];
let v = tag_items_data_item_variant;
ebml::tagged_docs(item, v) {|p|
......@@ -189,7 +189,7 @@ fn lookup_def(cnum: ast::crate_num, data: @[u8], did_: ast::def_id) ->
let item = lookup_item(did_.node, data);
let fam_ch = item_family(item);
let did = {crate: cnum, node: did_.node};
// We treat references to tags as references to types.
// We treat references to enums as references to types.
let def =
alt fam_ch as char {
'c' { ast::def_const(did) }
......@@ -205,7 +205,7 @@ fn lookup_def(cnum: ast::crate_num, data: @[u8], did_: ast::def_id) ->
'm' { ast::def_mod(did) }
'n' { ast::def_native_mod(did) }
'v' {
let tid = variant_tag_id(item);
let tid = variant_enum_id(item);
tid = {crate: cnum, node: tid.node};
ast::def_variant(tid, did)
}
......@@ -237,13 +237,13 @@ fn get_symbol(data: @[u8], id: ast::node_id) -> str {
ret item_symbol(lookup_item(id, data));
}
fn get_tag_variants(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
fn get_enum_variants(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
-> [ty::variant_info] {
let data = cdata.data;
let items = ebml::get_doc(ebml::new_doc(data), tag_items);
let item = find_item(id, items);
let infos: [ty::variant_info] = [];
let variant_ids = tag_variant_ids(item, cdata);
let variant_ids = enum_variant_ids(item, cdata);
let disr_val = 0;
for did: ast::def_id in variant_ids {
let item = find_item(did.node, items);
......
......@@ -33,7 +33,7 @@ fn encode_def_id(ebml_w: ebml::writer, id: def_id) {
type entry<T> = {val: T, pos: uint};
fn encode_tag_variant_paths(ebml_w: ebml::writer, variants: [variant],
fn encode_enum_variant_paths(ebml_w: ebml::writer, variants: [variant],
path: [str], &index: [entry<str>]) {
for variant: variant in variants {
add_to_index(ebml_w, path, index, variant.node.name);
......@@ -118,13 +118,13 @@ fn encode_module_item_paths(ebml_w: ebml::writer, module: _mod, path: [str],
encode_def_id(ebml_w, local_def(it.id));
ebml::end_tag(ebml_w);
}
item_tag(variants, tps) {
item_enum(variants, tps) {
add_to_index(ebml_w, path, index, it.ident);
ebml::start_tag(ebml_w, tag_paths_data_item);
encode_name(ebml_w, it.ident);
encode_def_id(ebml_w, local_def(it.id));
ebml::end_tag(ebml_w);
encode_tag_variant_paths(ebml_w, variants, path, index);
encode_enum_variant_paths(ebml_w, variants, path, index);
}
item_iface(_, _) {
add_to_index(ebml_w, path, index, it.ident);
......@@ -222,25 +222,25 @@ fn encode_disr_val(_ecx: @encode_ctxt, ebml_w: ebml::writer, disr_val: int) {
ebml::end_tag(ebml_w);
}
fn encode_tag_id(ebml_w: ebml::writer, id: def_id) {
ebml::start_tag(ebml_w, tag_items_data_item_tag_id);
fn encode_enum_id(ebml_w: ebml::writer, id: def_id) {
ebml::start_tag(ebml_w, tag_items_data_item_enum_id);
ebml_w.writer.write(str::bytes(def_to_str(id)));
ebml::end_tag(ebml_w);
}
fn encode_tag_variant_info(ecx: @encode_ctxt, ebml_w: ebml::writer,
fn encode_enum_variant_info(ecx: @encode_ctxt, ebml_w: ebml::writer,
id: node_id, variants: [variant],
&index: [entry<int>], ty_params: [ty_param]) {
let disr_val = 0;
let i = 0;
let vi = ty::tag_variants(ecx.ccx.tcx, {crate: local_crate, node: id});
let vi = ty::enum_variants(ecx.ccx.tcx, {crate: local_crate, node: id});
for variant: variant in variants {
index += [{val: variant.node.id, pos: ebml_w.writer.tell()}];
ebml::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, local_def(variant.node.id));
encode_family(ebml_w, 'v' as u8);
encode_name(ebml_w, variant.node.name);
encode_tag_id(ebml_w, local_def(id));
encode_enum_id(ebml_w, local_def(id));
encode_type(ecx, ebml_w,
node_id_to_monotype(ecx.ccx.tcx, variant.node.id));
if vec::len::<variant_arg>(variant.node.args) > 0u {
......@@ -324,7 +324,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
encode_name(ebml_w, item.ident);
ebml::end_tag(ebml_w);
}
item_tag(variants, tps) {
item_enum(variants, tps) {
ebml::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, local_def(item.id));
encode_family(ebml_w, 't' as u8);
......@@ -335,7 +335,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
encode_variant_id(ebml_w, local_def(v.node.id));
}
ebml::end_tag(ebml_w);
encode_tag_variant_info(ecx, ebml_w, item.id, variants, index, tps);
encode_enum_variant_info(ecx, ebml_w, item.id, variants, index, tps);
}
item_res(_, tps, _, _, ctor_id) {
let fn_ty = node_id_to_monotype(tcx, ctor_id);
......
......@@ -202,7 +202,7 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
let params: [ty::t] = [];
while peek(st) as char != ']' { params += [parse_ty(st, conv)]; }
st.pos = st.pos + 1u;
ret ty::mk_tag(st.tcx, def, params);
ret ty::mk_enum(st.tcx, def, params);
}
'x' {
assert (next(st) as char == '[');
......
......@@ -117,7 +117,7 @@ fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
}
}
ty::ty_str { w.write_char('S'); }
ty::ty_tag(def, tys) {
ty::ty_enum(def, tys) {
w.write_str("t[");
w.write_str(cx.ds(def));
w.write_char('|');
......
......@@ -502,7 +502,7 @@ fn helper(tcx: ty::ctxt, needle: unsafe_ty, haystack: ty::t, mut: bool)
mut_contains(ty) { mut && ty == haystack }
} { ret true; }
alt ty::struct(tcx, haystack) {
ty::ty_tag(_, ts) {
ty::ty_enum(_, ts) {
for t: ty::t in ts {
if helper(tcx, needle, t, mut) { ret true; }
}
......@@ -565,7 +565,7 @@ fn score_ty(tcx: ty::ctxt, ty: ty::t) -> uint {
ty::ty_fn(_) | ty::ty_native_fn(_, _) { 4u }
ty::ty_str | ty::ty_vec(_) | ty::ty_param(_, _) { 50u }
ty::ty_uniq(mt) { 1u + score_ty(tcx, mt.ty) }
ty::ty_tag(_, ts) | ty::ty_tup(ts) {
ty::ty_enum(_, ts) | ty::ty_tup(ts) {
let sum = 0u;
for t in ts { sum += score_ty(tcx, t); }
sum
......@@ -596,7 +596,7 @@ fn walk(tcx: ty::ctxt, mut: option::t<unsafe_ty>, pat: @ast::pat,
span: pat.span}];
alt sub { some(p) { walk(tcx, mut, p, set); } _ {} }
}
ast::pat_tag(_, ps) | ast::pat_tup(ps) {
ast::pat_enum(_, ps) | ast::pat_tup(ps) {
for p in ps { walk(tcx, mut, p, set); }
}
ast::pat_rec(fs, _) {
......
......@@ -80,9 +80,9 @@ fn field_patterns_supersede(tcx: ty::ctxt, fas: [field_pat],
_ { false }
}
}
pat_tag(va, suba) {
pat_enum(va, suba) {
alt b.node {
pat_tag(vb, subb) {
pat_enum(vb, subb) {
tcx.def_map.get(a.id) == tcx.def_map.get(b.id) &&
patterns_supersede(tcx, suba, subb)
}
......@@ -154,9 +154,9 @@ fn is_refutable(tcx: ty::ctxt, pat: @pat) -> bool {
for elt in elts { if is_refutable(tcx, elt) { ret true; } }
false
}
pat_tag(_, args) {
pat_enum(_, args) {
let vdef = variant_def_ids(tcx.def_map.get(pat.id));
if vec::len(*ty::tag_variants(tcx, vdef.tg)) != 1u { ret true; }
if vec::len(*ty::enum_variants(tcx, vdef.tg)) != 1u { ret true; }
for p: @pat in args { if is_refutable(tcx, p) { ret true; } }
false
}
......
......@@ -15,7 +15,7 @@ fn check_crate(sess: session, crate: @crate) {
fn check_item(it: @item, &&_is_const: bool, v: visit::vt<bool>) {
alt it.node {
item_const(_, ex) { v.visit_expr(ex, true, v); }
item_tag(vs, _) {
item_enum(vs, _) {
for var in vs {
option::may(var.node.disr_expr) {|ex|
v.visit_expr(ex, true, v);
......
......@@ -108,11 +108,6 @@ fn type_is_gc_relevant(cx: ty::ctxt, ty: ty::t) -> bool {
ty::ty_type | ty::ty_ptr(_) | ty::ty_native(_) {
ret false;
}
ty::ty_rec(fields) {
for f in fields { if type_is_gc_relevant(cx, f.mt.ty) { ret true; } }
ret false;
......@@ -121,13 +116,8 @@ fn type_is_gc_relevant(cx: ty::ctxt, ty: ty::t) -> bool {
for elt in elts { if type_is_gc_relevant(cx, elt) { ret true; } }
ret false;
}
ty::ty_tag(did, tps) {
let variants = ty::tag_variants(cx, did);
ty::ty_enum(did, tps) {
let variants = ty::enum_variants(cx, did);
for variant in *variants {
for aty in variant.args {
let arg_ty = ty::substitute_type_params(cx, tps, aty);
......@@ -136,11 +126,6 @@ fn type_is_gc_relevant(cx: ty::ctxt, ty: ty::t) -> bool {
}
ret false;
}
ty::ty_vec(tm) {
ret type_is_gc_relevant(cx, tm.ty);
}
......
......@@ -31,8 +31,8 @@ fn maybe_auto_unbox(tcx: ty::ctxt, t: ty::t) -> {t: ty::t, ds: [deref]} {
ds += [@{mut: false, kind: unbox, outer_t: t}];
t = ty::substitute_type_params(tcx, tps, inner);
}
ty::ty_tag(did, tps) {
let variants = ty::tag_variants(tcx, did);
ty::ty_enum(did, tps) {
let variants = ty::enum_variants(tcx, did);
if vec::len(*variants) != 1u ||
vec::len(variants[0].args) != 1u {
break;
......@@ -90,7 +90,7 @@ fn maybe_auto_unbox(tcx: ty::ctxt, t: ty::t) -> {t: ty::t, ds: [deref]} {
ty::ty_box(mt) { is_mut = mt.mut == mut; }
ty::ty_uniq(mt) { is_mut = mt.mut == mut; }
ty::ty_res(_, _, _) { }
ty::ty_tag(_, _) { }
ty::ty_enum(_, _) { }
ty::ty_ptr(mt) { is_mut = mt.mut == mut; }
}
ds += [@{mut: is_mut, kind: unbox, outer_t: base_t}];
......
......@@ -22,8 +22,8 @@ fn normalize_pat_def_map(dm: resolve::def_map, p: @pat) -> @pat {
@{node: pat_ident(q, some(normalize_pat_def_map(dm, r)))
with *p}
}
pat_tag(a_path, subs) {
@{node: pat_tag(a_path,
pat_enum(a_path, subs) {
@{node: pat_enum(a_path,
vec::map(subs, {|p| normalize_pat_def_map(dm, p)})) with *p}
}
pat_rec(field_pats, b) {
......@@ -52,8 +52,8 @@ fn normalize_one(dm: resolve::def_map, p: @pat) -> @pat {
alt dm.find(p.id) {
some(d) {
alt p.node {
pat_ident(tag_path, _) { @{id: p.id,
node: pat_tag(tag_path, []),
pat_ident(enum_path, _) { @{id: p.id,
node: pat_enum(enum_path, []),
span: p.span} }
_ { p }
}
......@@ -95,7 +95,7 @@ fn pat_bindings(pat: @pat, it: fn(@pat)) {
alt pat.node {
pat_ident(_, option::none) { it(pat); }
pat_ident(_, option::some(sub)) { it(pat); pat_bindings(sub, it); }
pat_tag(_, sub) { for p in sub { pat_bindings(p, it); } }
pat_enum(_, sub) { for p in sub { pat_bindings(p, it); } }
pat_rec(fields, _) { for f in fields { pat_bindings(f.pat, it); } }
pat_tup(elts) { for elt in elts { pat_bindings(elt, it); } }
pat_box(sub) { pat_bindings(sub, it); }
......
......@@ -103,7 +103,7 @@ enum mod_index_entry {
mie_import_ident(node_id, codemap::span),
mie_item(@ast::item),
mie_native_item(@ast::native_item),
mie_tag_variant(/* enum item */@ast::item, /* variant index */uint),
mie_enum_variant(/* enum item */@ast::item, /* variant index */uint),
}
type mod_index = hashmap<ident, list<mod_index_entry>>;
......@@ -119,8 +119,9 @@ enum mod_index_entry {
path: str
};
/* native modules can't contain tags, and we don't store their ASTs because we
only need to look at them to determine exports, which they can't control.*/
/* native modules can't contain enums, and we don't store their ASTs because
we only need to look at them to determine exports, which they can't
control.*/
type def_map = hashmap<node_id, def>;
type ext_map = hashmap<def_id, [ident]>;
......@@ -158,7 +159,7 @@ enum dir { inside, outside, }
// when looking up a variable name that's not yet in scope to check
// if it's already bound to a enum.
enum namespace { ns_val(ns_value_type), ns_type, ns_module, }
enum ns_value_type { ns_a_tag, ns_any_value, }
enum ns_value_type { ns_a_enum, ns_any_value, }
fn resolve_crate(sess: session, amap: ast_map::map, crate: @ast::crate) ->
{def_map: def_map, exp_map: exp_map, impl_map: impl_map} {
......@@ -406,7 +407,7 @@ fn walk_constr(e: @env, p: @ast::path, sp: span, id: node_id, sc: scopes,
fn walk_pat(e: @env, pat: @ast::pat, sc: scopes, v: vt<scopes>) {
visit::visit_pat(pat, sc, v);
alt pat.node {
ast::pat_tag(p, _) {
ast::pat_enum(p, _) {
let fnd = lookup_path_strict(*e, sc, p.span, p.node,
ns_val(ns_any_value));
alt option::get(fnd) {
......@@ -424,7 +425,7 @@ fn walk_pat(e: @env, pat: @ast::pat, sc: scopes, v: vt<scopes>) {
variable a refers to a nullary enum. */
ast::pat_ident(p, none) {
let fnd = lookup_in_scope(*e, sc, p.span, path_to_ident(p),
ns_val(ns_a_tag));
ns_val(ns_a_enum));
alt fnd {
some(ast::def_variant(did, vid)) {
e.def_map.insert(pat.id, ast::def_variant(did, vid));
......@@ -566,11 +567,11 @@ fn visit_local_with_scope(e: @env, loc: @local, sc:scopes, v:vt<scopes>) {
// to enum foo, or is it binding a new name foo?)
alt loc.node.pat.node {
pat_ident(an_ident,_) {
// Be sure to pass ns_a_tag to lookup_in_scope so that
// Be sure to pass ns_a_enum to lookup_in_scope so that
// if this is a name that's being shadowed, we don't die
alt lookup_in_scope(*e, sc, loc.span,
path_to_ident(an_ident), ns_val(ns_a_tag)) {
some(ast::def_variant(tag_id,variant_id)) {
path_to_ident(an_ident), ns_val(ns_a_enum)) {
some(ast::def_variant(enum_id,variant_id)) {
// Declaration shadows a enum that's in scope.
// That's an error.
e.sess.span_err(loc.span,
......@@ -742,7 +743,7 @@ fn ns_name(ns: namespace) -> str {
ns_val(v) {
alt (v) {
ns_any_value { "name" }
ns_a_tag { "enum" }
ns_a_enum { "enum" }
}
}
ns_module { ret "modulename" }
......@@ -893,7 +894,7 @@ fn in_scope(e: env, sp: span, name: ident, s: scope, ns: namespace) ->
ast::item_impl(tps, _, _, _) {
if ns == ns_type { ret lookup_in_ty_params(e, name, tps); }
}
ast::item_iface(tps, _) | ast::item_tag(_, tps) |
ast::item_iface(tps, _) | ast::item_enum(_, tps) |
ast::item_ty(_, tps) {
if ns == ns_type { ret lookup_in_ty_params(e, name, tps); }
}
......@@ -970,7 +971,7 @@ fn in_scope(e: env, sp: span, name: ident, s: scope, ns: namespace) ->
/* If we were looking for a enum, at this point
we know it's bound to a non-enum value, and
we can return none instead of failing */
ns_a_tag { ret none; }
ns_a_enum { ret none; }
_ { "attempted dynamic environment-capture" }
}
}
......@@ -1074,7 +1075,7 @@ fn lookup_in_block(e: env, name: ident, sp: span, b: ast::blk_, pos: uint,
}
ast::decl_item(it) {
alt it.node {
ast::item_tag(variants, _) {
ast::item_enum(variants, _) {
if ns == ns_type {
if str::eq(it.ident, name) {
ret some(ast::def_ty(local_def(it.id)));
......@@ -1150,7 +1151,7 @@ fn found_def_item(i: @ast::item, ns: namespace) -> option::t<def> {
ast::item_native_mod(_) {
if ns == ns_module { ret some(ast::def_native_mod(local_def(i.id))); }
}
ast::item_ty(_, _) | item_iface(_, _) | item_tag(_, _) {
ast::item_ty(_, _) | item_iface(_, _) | item_enum(_, _) {
if ns == ns_type { ret some(ast::def_ty(local_def(i.id))); }
}
ast::item_res(_, _, _, _, ctor_id) {
......@@ -1292,7 +1293,7 @@ fn lookup_in_mod_(e: env, def: glob_imp_def, sp: span, name: ident,
if vec::len(matches) == 0u {
ret none;
}
else if vec::len(matches) == 1u || ns == ns_val(ns_a_tag) {
else if vec::len(matches) == 1u || ns == ns_val(ns_a_enum) {
ret some(matches[0].def);
} else {
for match: glob_imp_def in matches {
......@@ -1312,8 +1313,8 @@ fn lookup_glob_in_mod(e: env, info: @indexed_mod, sp: span, id: ident,
info.glob_imported_names.insert(id, glob_resolving(sp));
let val = lookup_in_globs(e, info.glob_imports, sp, id,
// kludge
(if wanted_ns == ns_val(ns_a_tag)
{ ns_val(ns_a_tag) }
(if wanted_ns == ns_val(ns_a_enum)
{ ns_val(ns_a_enum) }
else { ns_val(ns_any_value) }), dr);
let typ = lookup_in_globs(e, info.glob_imports, sp, id, ns_type, dr);
let md = lookup_in_globs(e, info.glob_imports, sp, id, ns_module, dr);
......@@ -1341,9 +1342,9 @@ fn lookup_in_mie(e: env, mie: mod_index_entry, ns: namespace) ->
}
mie_import_ident(id, _) { ret lookup_import(e, local_def(id), ns); }
mie_item(item) { ret found_def_item(item, ns); }
mie_tag_variant(item, variant_idx) {
mie_enum_variant(item, variant_idx) {
alt item.node {
ast::item_tag(variants, _) {
ast::item_enum(variants, _) {
alt ns {
ns_val(_) {
let vid = variants[variant_idx].node.id;
......@@ -1415,12 +1416,12 @@ fn index_mod(md: ast::_mod) -> mod_index {
ast::item_impl(_, _, _, _) | ast::item_iface(_, _) {
add_to_index(index, it.ident, mie_item(it));
}
ast::item_tag(variants, _) {
ast::item_enum(variants, _) {
add_to_index(index, it.ident, mie_item(it));
let variant_idx: uint = 0u;
for v: ast::variant in variants {
add_to_index(index, v.node.name,
mie_tag_variant(it, variant_idx));
mie_enum_variant(it, variant_idx));
variant_idx += 1u;
}
}
......@@ -1458,7 +1459,7 @@ fn index_nmod(md: ast::native_mod) -> mod_index {
// External lookups
fn ns_for_def(d: def) -> namespace {
alt d {
ast::def_variant(_, _) { ns_val(ns_a_tag) }
ast::def_variant(_, _) { ns_val(ns_a_enum) }
ast::def_fn(_, _) | ast::def_self(_) |
ast::def_const(_) | ast::def_arg(_, _) | ast::def_local(_, _) |
ast::def_upvar(_, _, _) | ast::def_native_fn(_, _) | ast::def_self(_)
......@@ -1473,7 +1474,7 @@ fn ns_for_def(d: def) -> namespace {
// a enum
fn ns_ok(wanted:namespace, actual:namespace) -> bool {
alt actual {
ns_val(ns_a_tag) {
ns_val(ns_a_enum) {
alt wanted {
ns_val(_) { true }
_ { false }
......@@ -1548,7 +1549,7 @@ fn mie_span(mie: mod_index_entry) -> span {
mie_view_item(item) { item.span }
mie_import_ident(_, span) { span }
mie_item(item) { item.span }
mie_tag_variant(item, _) { item.span }
mie_enum_variant(item, _) { item.span }
mie_native_item(item) { item.span }
};
}
......@@ -1566,7 +1567,7 @@ fn typaram_names(tps: [ast::ty_param]) -> [ident] {
ensure_unique(*e, i.span, typaram_names(ty_params), ident_id,
"type parameter");
}
ast::item_tag(_, ty_params) {
ast::item_enum(_, ty_params) {
ensure_unique(*e, i.span, typaram_names(ty_params), ident_id,
"type parameter");
}
......@@ -1635,7 +1636,7 @@ fn check_block(e: @env, b: ast::blk, &&x: (), v: vt<()>) {
}
ast::decl_item(it) {
alt it.node {
ast::item_tag(variants, _) {
ast::item_enum(variants, _) {
add_name(types, it.span, it.ident);
for v: ast::variant in variants {
add_name(values, v.span, v.node.name);
......@@ -1776,7 +1777,7 @@ fn check_enum_ok(e: @env, sp:span, id: ident, val: @indexed_mod)
alt m {
mie_item(an_item) {
alt an_item.node {
item_tag(_,_) { /* OK */ some(an_item.id) }
item_enum(_,_) { /* OK */ some(an_item.id) }
_ { none }
}
}
......@@ -1802,10 +1803,10 @@ fn check_enum_ok(e: @env, sp:span, id: ident, val: @indexed_mod)
check_export(e, ident, val, vi);
}
}
ast::view_item_export_tag_none(id, _) {
ast::view_item_export_enum_none(id, _) {
let _ = check_enum_ok(e, vi.span, id, val);
}
ast::view_item_export_tag_some(id, ids, _) {
ast::view_item_export_enum_some(id, ids, _) {
// Check that it's an enum and all the given variants
// belong to it
let parent_id = check_enum_ok(e, vi.span, id, val);
......@@ -1814,7 +1815,7 @@ fn check_enum_ok(e: @env, sp:span, id: ident, val: @indexed_mod)
some(ms) {
list::iter(ms) {|m|
alt m {
mie_tag_variant(parent_item,_) {
mie_enum_variant(parent_item,_) {
if parent_item.id != parent_id {
e.sess.span_err(vi.span,
#fmt("variant %s \
......
......@@ -8,7 +8,7 @@
import driver::session::session;
import middle::{trans, trans_common};
import middle::trans_common::{crate_ctxt, val_ty, C_bytes, C_int,
C_named_struct, C_struct, T_tag_variant,
C_named_struct, C_struct, T_enum_variant,
block_ctxt, result, rslt, bcx_ccx, bcx_tcx,
type_has_static_size, umax, umin, align_to,
tydesc_info};
......@@ -51,7 +51,7 @@
const shape_f64: u8 = 9u8;
// (10 is currently unused, was evec)
const shape_vec: u8 = 11u8;
const shape_tag: u8 = 12u8;
const shape_enum: u8 = 12u8;
const shape_box: u8 = 13u8;
const shape_struct: u8 = 17u8;
const shape_box_fn: u8 = 18u8;
......@@ -119,7 +119,7 @@ fn largest_variants(ccx: @crate_ctxt, tag_id: ast::def_id) -> [uint] {
// contains (T,T) must be as least as large as any variant that contains
// just T.
let ranges = [];
let variants = ty::tag_variants(ccx.tcx, tag_id);
let variants = ty::enum_variants(ccx.tcx, tag_id);
for variant: ty::variant_info in *variants {
let bounded = true;
let {a: min_size, b: min_align} = {a: 0u, b: 0u};
......@@ -201,17 +201,17 @@ fn round_up(size: u16, align: u8) -> u16 {
type size_align = {size: u16, align: u8};
fn compute_static_tag_size(ccx: @crate_ctxt, largest_variants: [uint],
fn compute_static_enum_size(ccx: @crate_ctxt, largest_variants: [uint],
did: ast::def_id) -> size_align {
let max_size = 0u16;
let max_align = 1u8;
let variants = ty::tag_variants(ccx.tcx, did);
let variants = ty::enum_variants(ccx.tcx, did);
for vid: uint in largest_variants {
// We increment a "virtual data pointer" to compute the size.
let lltys = [];
for typ: ty::t in variants[vid].args {
// FIXME: there should really be a postcondition
// on tag_variants that would obviate the need for
// on enum_variants that would obviate the need for
// this check. (Issue #586)
check (trans_common::type_has_static_size(ccx, typ));
lltys += [trans::type_of(ccx, dummy_sp(), typ)];
......@@ -229,7 +229,7 @@ fn compute_static_tag_size(ccx: @crate_ctxt, largest_variants: [uint],
// FIXME (issue #792): This is wrong. If the enum starts with an 8 byte
// aligned quantity, we don't align it.
if vec::len(*variants) > 1u {
let variant_t = T_tag_variant(ccx);
let variant_t = T_enum_variant(ccx);
max_size += llsize_of_real(ccx, variant_t) as u16;
let align = llalign_of_real(ccx, variant_t) as u8;
if max_align < align { max_align = align; }
......@@ -238,15 +238,15 @@ fn compute_static_tag_size(ccx: @crate_ctxt, largest_variants: [uint],
ret {size: max_size, align: max_align};
}
enum tag_kind {
enum enum_kind {
tk_unit, // 1 variant, no data
tk_enum, // N variants, no data
tk_newtype, // 1 variant, data
tk_complex // N variants, no data
}
fn tag_kind(ccx: @crate_ctxt, did: ast::def_id) -> tag_kind {
let variants = ty::tag_variants(ccx.tcx, did);
fn enum_kind(ccx: @crate_ctxt, did: ast::def_id) -> enum_kind {
let variants = ty::enum_variants(ccx.tcx, did);
if vec::any(*variants) {|v| vec::len(v.args) > 0u} {
if vec::len(*variants) == 1u { tk_newtype }
else { tk_complex }
......@@ -281,7 +281,7 @@ fn s_float(tcx: ty_ctxt) -> u8 {
};
}
fn s_variant_tag_t(tcx: ty_ctxt) -> u8 {
fn s_variant_enum_t(tcx: ty_ctxt) -> u8 {
ret s_int(tcx);
}
......@@ -349,15 +349,15 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t, ty_param_map: [uint]) -> [u8] {
let unit_ty = ty::mk_mach_uint(ccx.tcx, ast::ty_u8);
add_substr(s, shape_of(ccx, unit_ty, ty_param_map));
}
ty::ty_tag(did, tps) {
alt tag_kind(ccx, did) {
ty::ty_enum(did, tps) {
alt enum_kind(ccx, did) {
tk_unit {
// FIXME: For now we do this.
s += [s_variant_tag_t(ccx.tcx)];
s += [s_variant_enum_t(ccx.tcx)];
}
tk_enum { s += [s_variant_tag_t(ccx.tcx)]; }
tk_enum { s += [s_variant_enum_t(ccx.tcx)]; }
tk_newtype | tk_complex {
s += [shape_tag];
s += [shape_enum];
let sub = [];
......@@ -481,16 +481,16 @@ fn shape_of_variant(ccx: @crate_ctxt, v: ty::variant_info,
// }
//}
fn gen_tag_shapes(ccx: @crate_ctxt) -> ValueRef {
// Loop over all the enum variants and write their shapes into a data
// buffer. As we do this, it's possible for us to discover new tags, so we
// must do this first.
fn gen_enum_shapes(ccx: @crate_ctxt) -> ValueRef {
// Loop over all the enum variants and write their shapes into a
// data buffer. As we do this, it's possible for us to discover
// new enums, so we must do this first.
let i = 0u;
let data = [];
let offsets = [];
while i < vec::len(ccx.shape_cx.tag_order) {
let did = ccx.shape_cx.tag_order[i];
let variants = ty::tag_variants(ccx.tcx, did);
let variants = ty::enum_variants(ccx.tcx, did);
let item_tyt = ty::lookup_item_type(ccx.tcx, did);
let ty_param_count = vec::len(*item_tyt.bounds);
......@@ -519,7 +519,7 @@ fn gen_tag_shapes(ccx: @crate_ctxt) -> ValueRef {
let info_sz = 0u16;
for did_: ast::def_id in ccx.shape_cx.tag_order {
let did = did_; // Satisfy alias checker.
let num_variants = vec::len(*ty::tag_variants(ccx.tcx, did)) as u16;
let num_variants = vec::len(*ty::enum_variants(ccx.tcx, did)) as u16;
add_u16(header, header_sz + info_sz);
info_sz += 2u16 * (num_variants + 2u16) + 3u16;
}
......@@ -532,7 +532,7 @@ fn gen_tag_shapes(ccx: @crate_ctxt) -> ValueRef {
i = 0u;
for did_: ast::def_id in ccx.shape_cx.tag_order {
let did = did_; // Satisfy alias checker.
let variants = ty::tag_variants(ccx.tcx, did);
let variants = ty::enum_variants(ccx.tcx, did);
add_u16(info, vec::len(*variants) as u16);
// Construct the largest-variants table.
......@@ -556,7 +556,7 @@ fn gen_tag_shapes(ccx: @crate_ctxt) -> ValueRef {
let size_align;
if dynamic {
size_align = {size: 0u16, align: 0u8};
} else { size_align = compute_static_tag_size(ccx, lv, did); }
} else { size_align = compute_static_enum_size(ccx, lv, did); }
add_u16(info, size_align.size);
info += [size_align.align];
......@@ -593,7 +593,7 @@ fn gen_resource_shapes(ccx: @crate_ctxt) -> ValueRef {
}
fn gen_shape_tables(ccx: @crate_ctxt) {
let lltagstable = gen_tag_shapes(ccx);
let lltagstable = gen_enum_shapes(ccx);
let llresourcestable = gen_resource_shapes(ccx);
trans_common::set_struct_body(ccx.shape_cx.llshapetablesty,
[val_ty(lltagstable),
......@@ -676,15 +676,15 @@ fn llalign_of(cx: @crate_ctxt, t: TypeRef) -> ValueRef {
}
// Computes the size of the data part of a non-dynamically-sized enum.
fn static_size_of_tag(cx: @crate_ctxt, sp: span, t: ty::t)
fn static_size_of_enum(cx: @crate_ctxt, sp: span, t: ty::t)
: type_has_static_size(cx, t) -> uint {
if cx.tag_sizes.contains_key(t) { ret cx.tag_sizes.get(t); }
if cx.enum_sizes.contains_key(t) { ret cx.enum_sizes.get(t); }
alt ty::struct(cx.tcx, t) {
ty::ty_tag(tid, subtys) {
ty::ty_enum(tid, subtys) {
// Compute max(variant sizes).
let max_size = 0u;
let variants = ty::tag_variants(cx.tcx, tid);
let variants = ty::enum_variants(cx.tcx, tid);
for variant: ty::variant_info in *variants {
let tup_ty = simplify_type(cx, ty::mk_tup(cx.tcx, variant.args));
// Perform any type parameter substitutions.
......@@ -700,11 +700,12 @@ fn static_size_of_tag(cx: @crate_ctxt, sp: span, t: ty::t)
llsize_of_real(cx, trans::type_of(cx, sp, tup_ty));
if max_size < this_size { max_size = this_size; }
}
cx.tag_sizes.insert(t, max_size);
cx.enum_sizes.insert(t, max_size);
ret max_size;
}
_ {
cx.tcx.sess.span_fatal(sp, "non-enum passed to static_size_of_tag()");
cx.tcx.sess.span_fatal(
sp, "non-enum passed to static_size_of_enum()");
}
}
}
......@@ -754,7 +755,7 @@ fn align_elements(cx: @block_ctxt, elts: [ty::t]) -> metrics {
for tp in elts { tys += [tp]; }
align_elements(cx, tys)
}
ty::ty_tag(tid, tps) {
ty::ty_enum(tid, tps) {
let bcx = cx;
let ccx = bcx_ccx(bcx);
......@@ -762,7 +763,7 @@ fn align_elements(cx: @block_ctxt, elts: [ty::t]) -> metrics {
// Compute max(variant sizes).
let bcx = bcx;
let max_size: ValueRef = C_int(ccx, 0);
let variants = ty::tag_variants(bcx_tcx(bcx), tid);
let variants = ty::enum_variants(bcx_tcx(bcx), tid);
for variant: ty::variant_info in *variants {
// Perform type substitution on the raw argument types.
let tys = vec::map(variant.args) {|raw_ty|
......@@ -775,12 +776,12 @@ fn align_elements(cx: @block_ctxt, elts: [ty::t]) -> metrics {
rslt(bcx, max_size)
};
let {bcx, val: sz} = alt tag_kind(ccx, tid) {
tk_unit | tk_enum { rslt(bcx, llsize_of(ccx, T_tag_variant(ccx))) }
let {bcx, val: sz} = alt enum_kind(ccx, tid) {
tk_unit | tk_enum { rslt(bcx, llsize_of(ccx, T_enum_variant(ccx))) }
tk_newtype { compute_max_variant_size(bcx) }
tk_complex {
let {bcx, val} = compute_max_variant_size(bcx);
rslt(bcx, Add(bcx, val, llsize_of(ccx, T_tag_variant(ccx))))
rslt(bcx, Add(bcx, val, llsize_of(ccx, T_enum_variant(ccx))))
}
};
......
......@@ -135,7 +135,7 @@ fn type_of_inner(cx: @crate_ctxt, sp: span, t: ty::t)
ty::ty_uint(t) { T_uint_ty(cx, t) }
ty::ty_float(t) { T_float_ty(cx, t) }
ty::ty_str { T_ptr(T_vec(cx, T_i8())) }
ty::ty_tag(did, _) { type_of_tag(cx, sp, did, t) }
ty::ty_enum(did, _) { type_of_enum(cx, sp, did, t) }
ty::ty_box(mt) {
let mt_ty = mt.ty;
check non_ty_var(cx, mt_ty);
......@@ -213,18 +213,18 @@ fn type_of_inner(cx: @crate_ctxt, sp: span, t: ty::t)
ret llty;
}
fn type_of_tag(cx: @crate_ctxt, sp: span, did: ast::def_id, t: ty::t)
fn type_of_enum(cx: @crate_ctxt, sp: span, did: ast::def_id, t: ty::t)
-> TypeRef {
let degen = vec::len(*ty::tag_variants(cx.tcx, did)) == 1u;
let degen = vec::len(*ty::enum_variants(cx.tcx, did)) == 1u;
if check type_has_static_size(cx, t) {
let size = static_size_of_tag(cx, sp, t);
if !degen { T_tag(cx, size) }
else if size == 0u { T_struct([T_tag_variant(cx)]) }
let size = static_size_of_enum(cx, sp, t);
if !degen { T_enum(cx, size) }
else if size == 0u { T_struct([T_enum_variant(cx)]) }
else { T_array(T_i8(), size) }
}
else {
if degen { T_struct([T_tag_variant(cx)]) }
else { T_opaque_tag(cx) }
if degen { T_struct([T_enum_variant(cx)]) }
else { T_opaque_enum(cx) }
}
}
......@@ -498,16 +498,16 @@ fn simplifier(ccx: @crate_ctxt, typ: ty::t) -> ty::t {
}
// Computes the size of the data part of a non-dynamically-sized tag.
fn static_size_of_tag(cx: @crate_ctxt, sp: span, t: ty::t)
// Computes the size of the data part of a non-dynamically-sized enum.
fn static_size_of_enum(cx: @crate_ctxt, sp: span, t: ty::t)
: type_has_static_size(cx, t) -> uint {
if cx.tag_sizes.contains_key(t) { ret cx.tag_sizes.get(t); }
if cx.enum_sizes.contains_key(t) { ret cx.enum_sizes.get(t); }
alt ty::struct(cx.tcx, t) {
ty::ty_tag(tid, subtys) {
ty::ty_enum(tid, subtys) {
// Compute max(variant sizes).
let max_size = 0u;
let variants = ty::tag_variants(cx.tcx, tid);
let variants = ty::enum_variants(cx.tcx, tid);
for variant: ty::variant_info in *variants {
let tup_ty = simplify_type(cx, ty::mk_tup(cx.tcx, variant.args));
// Perform any type parameter substitutions.
......@@ -522,12 +522,9 @@ fn static_size_of_tag(cx: @crate_ctxt, sp: span, t: ty::t)
let this_size = llsize_of_real(cx, type_of(cx, sp, tup_ty));
if max_size < this_size { max_size = this_size; }
}
cx.tag_sizes.insert(t, max_size);
cx.enum_sizes.insert(t, max_size);
ret max_size;
}
_ {
cx.tcx.sess.span_fatal(sp, "non-tag passed to static_size_of_tag()");
}
}
}
......@@ -581,14 +578,14 @@ fn align_elements(cx: @block_ctxt, elts: [ty::t]) -> result {
for tp in elts { tys += [tp]; }
ret align_elements(cx, tys);
}
ty::ty_tag(tid, tps) {
ty::ty_enum(tid, tps) {
let bcx = cx;
let ccx = bcx_ccx(bcx);
// Compute max(variant sizes).
let max_size: ValueRef = alloca(bcx, ccx.int_type);
Store(bcx, C_int(ccx, 0), max_size);
let variants = ty::tag_variants(bcx_tcx(bcx), tid);
let variants = ty::enum_variants(bcx_tcx(bcx), tid);
for variant: ty::variant_info in *variants {
// Perform type substitution on the raw argument types.
......@@ -632,7 +629,7 @@ fn dynamic_align_of(cx: @block_ctxt, t: ty::t) -> result {
}
ret rslt(bcx, a);
}
ty::ty_tag(_, _) {
ty::ty_enum(_, _) {
ret rslt(cx, C_int(bcx_ccx(cx), 1)); // FIXME: stub
}
ty::ty_tup(elts) {
......@@ -740,11 +737,11 @@ fn compute_off(bcx: @block_ctxt,
// This function uses GEP_tup_like() above and automatically performs casts as
// appropriate. @llblobptr is the data part of a enum value; its actual type
// is meaningless, as it will be cast away.
fn GEP_tag(cx: @block_ctxt, llblobptr: ValueRef, tag_id: ast::def_id,
fn GEP_enum(cx: @block_ctxt, llblobptr: ValueRef, enum_id: ast::def_id,
variant_id: ast::def_id, ty_substs: [ty::t],
ix: uint) : valid_variant_index(ix, cx, tag_id, variant_id) ->
ix: uint) : valid_variant_index(ix, cx, enum_id, variant_id) ->
result {
let variant = ty::tag_variant_with_id(bcx_tcx(cx), tag_id, variant_id);
let variant = ty::enum_variant_with_id(bcx_tcx(cx), enum_id, variant_id);
// Synthesize a tuple type so that GEP_tup_like() can work its magic.
// Separately, store the type of the element we're interested in.
......@@ -1592,7 +1589,7 @@ fn iter_variant(cx: @block_ctxt, a_tup: ValueRef,
let v_id = variant.id;
for a: ty::arg in args {
check (valid_variant_index(j, cx, tid, v_id));
let rslt = GEP_tag(cx, a_tup, tid, v_id, tps, j);
let rslt = GEP_enum(cx, a_tup, tid, v_id, tps, j);
let llfldp_a = rslt.val;
cx = rslt.bcx;
let ty_subst = ty::substitute_type_params(ccx.tcx, tps, a.ty);
......@@ -1639,20 +1636,20 @@ fn iter_variant(cx: @block_ctxt, a_tup: ValueRef,
let {bcx: bcx, val: llfld_a} = GEP_tup_like(cx, tup_t, av, [0, 1]);
ret f(bcx, llfld_a, inner1);
}
ty::ty_tag(tid, tps) {
let variants = ty::tag_variants(bcx_tcx(cx), tid);
ty::ty_enum(tid, tps) {
let variants = ty::enum_variants(bcx_tcx(cx), tid);
let n_variants = vec::len(*variants);
// Cast the tags to types we can GEP into.
// Cast the enums to types we can GEP into.
if n_variants == 1u {
ret iter_variant(cx, av, variants[0], tps, tid, f);
}
let ccx = bcx_ccx(cx);
let lltagty = T_opaque_tag_ptr(ccx);
let av_tag = PointerCast(cx, av, lltagty);
let lldiscrim_a_ptr = GEPi(cx, av_tag, [0, 0]);
let llunion_a_ptr = GEPi(cx, av_tag, [0, 1]);
let llenumty = T_opaque_enum_ptr(ccx);
let av_enum = PointerCast(cx, av, llenumty);
let lldiscrim_a_ptr = GEPi(cx, av_enum, [0, 0]);
let llunion_a_ptr = GEPi(cx, av_enum, [0, 1]);
let lldiscrim_a = Load(cx, lldiscrim_a_ptr);
// NB: we must hit the discriminant first so that structural
......@@ -2098,7 +2095,7 @@ fn trans_unary(bcx: @block_ctxt, op: ast::unop, e: @ast::expr,
let {bcx, box, body} = trans_malloc_boxed(bcx, e_ty);
add_clean_free(bcx, box, false);
// Cast the body type to the type of the value. This is needed to
// make tags work, since tags have a different LLVM type depending
// make enums work, since enums have a different LLVM type depending
// on whether they're boxed or not
let ccx = bcx_ccx(bcx);
if check type_has_static_size(ccx, e_ty) {
......@@ -2262,8 +2259,8 @@ fn autoderef(cx: @block_ctxt, v: ValueRef, t: ty::t) -> result_t {
t1 = ty::substitute_type_params(ccx.tcx, tps, inner);
v1 = GEPi(cx, v1, [0, 1]);
}
ty::ty_tag(did, tps) {
let variants = ty::tag_variants(ccx.tcx, did);
ty::ty_enum(did, tps) {
let variants = ty::enum_variants(ccx.tcx, did);
if vec::len(*variants) != 1u ||
vec::len(variants[0].args) != 1u {
break;
......@@ -2644,22 +2641,22 @@ fn trans_var(cx: @block_ctxt, sp: span, def: ast::def, id: ast::node_id)
ret lval_static_fn(cx, did, id);
}
ast::def_variant(tid, vid) {
if vec::len(ty::tag_variant_with_id(ccx.tcx, tid, vid).args) > 0u {
if vec::len(ty::enum_variant_with_id(ccx.tcx, tid, vid).args) > 0u {
// N-ary variant.
ret lval_static_fn(cx, vid, id);
} else {
// Nullary variant.
let tag_ty = node_id_type(ccx, id);
let alloc_result = alloc_ty(cx, tag_ty);
let lltagblob = alloc_result.val;
let lltagty = type_of_tag(ccx, sp, tid, tag_ty);
let enum_ty = node_id_type(ccx, id);
let alloc_result = alloc_ty(cx, enum_ty);
let llenumblob = alloc_result.val;
let llenumty = type_of_enum(ccx, sp, tid, enum_ty);
let bcx = alloc_result.bcx;
let lltagptr = PointerCast(bcx, lltagblob, T_ptr(lltagty));
let lldiscrimptr = GEPi(bcx, lltagptr, [0, 0]);
let llenumptr = PointerCast(bcx, llenumblob, T_ptr(llenumty));
let lldiscrimptr = GEPi(bcx, llenumptr, [0, 0]);
let lldiscrim_gv = lookup_discriminant(bcx.fcx.lcx, vid);
let lldiscrim = Load(bcx, lldiscrim_gv);
Store(bcx, lldiscrim, lldiscrimptr);
ret lval_no_env(bcx, lltagptr, temporary);
ret lval_no_env(bcx, llenumptr, temporary);
}
}
ast::def_const(did) {
......@@ -2800,7 +2797,7 @@ fn trans_lval(cx: @block_ctxt, e: @ast::expr) -> lval_result {
ty::ty_res(_, _, _) {
GEPi(sub.bcx, sub.val, [0, 1])
}
ty::ty_tag(_, _) {
ty::ty_enum(_, _) {
let ety = ty::expr_ty(ccx.tcx, e);
let sp = e.span;
let ellty =
......@@ -2896,7 +2893,7 @@ fn trans_cast(cx: @block_ctxt, e: @ast::expr, id: ast::node_id,
check (type_has_static_size(ccx, t_out));
let ll_t_out = type_of(ccx, e.span, t_out);
enum kind { pointer, integral, float, tag_, other, }
enum kind { pointer, integral, float, enum_, other, }
fn t_kind(tcx: ty::ctxt, t: ty::t) -> kind {
ret if ty::type_is_fp(tcx, t) {
float
......@@ -2905,8 +2902,8 @@ fn t_kind(tcx: ty::ctxt, t: ty::t) -> kind {
pointer
} else if ty::type_is_integral(tcx, t) {
integral
} else if ty::type_is_tag(tcx, t) {
tag_
} else if ty::type_is_enum(tcx, t) {
enum_
} else { other };
}
let k_in = t_kind(ccx.tcx, t_in);
......@@ -2940,11 +2937,11 @@ fn t_kind(tcx: ty::ctxt, t: ty::t) -> kind {
{in: pointer, out: pointer} {
PointerCast(e_res.bcx, e_res.val, ll_t_out)
}
{in: tag_, out: integral} | {in: tag_, out: float} {
{in: enum_, out: integral} | {in: enum_, out: float} {
let cx = e_res.bcx;
let lltagty = T_opaque_tag_ptr(ccx);
let av_tag = PointerCast(cx, e_res.val, lltagty);
let lldiscrim_a_ptr = GEPi(cx, av_tag, [0, 0]);
let llenumty = T_opaque_enum_ptr(ccx);
let av_enum = PointerCast(cx, e_res.val, llenumty);
let lldiscrim_a_ptr = GEPi(cx, av_enum, [0, 0]);
let lldiscrim_a = Load(cx, lldiscrim_a_ptr);
alt k_out {
integral {int_cast(e_res.bcx, ll_t_out,
......@@ -4520,7 +4517,7 @@ fn trans_res_ctor(cx: @local_ctxt, sp: span, dtor: ast::fn_decl,
}
fn trans_tag_variant(cx: @local_ctxt, tag_id: ast::node_id,
fn trans_enum_variant(cx: @local_ctxt, enum_id: ast::node_id,
variant: ast::variant, disr: int, is_degen: bool,
ty_params: [ast::ty_param]) {
let ccx = cx.ccx;
......@@ -4546,7 +4543,7 @@ fn trans_tag_variant(cx: @local_ctxt, tag_id: ast::node_id,
some(x) { llfndecl = x; }
_ {
ccx.sess.span_fatal(variant.span,
"unbound variant id in trans_tag_variant");
"unbound variant id in trans_enum_variant");
}
}
let fcx = new_fn_ctxt(cx, variant.span, llfndecl);
......@@ -4568,18 +4565,18 @@ fn trans_tag_variant(cx: @local_ctxt, tag_id: ast::node_id,
if is_degen {
fcx.llretptr
} else {
let lltagptr =
PointerCast(bcx, fcx.llretptr, T_opaque_tag_ptr(ccx));
let lldiscrimptr = GEPi(bcx, lltagptr, [0, 0]);
let llenumptr =
PointerCast(bcx, fcx.llretptr, T_opaque_enum_ptr(ccx));
let lldiscrimptr = GEPi(bcx, llenumptr, [0, 0]);
Store(bcx, C_int(ccx, disr), lldiscrimptr);
GEPi(bcx, lltagptr, [0, 1])
GEPi(bcx, llenumptr, [0, 1])
};
i = 0u;
let t_id = ast_util::local_def(tag_id);
let t_id = ast_util::local_def(enum_id);
let v_id = ast_util::local_def(variant.node.id);
for va: ast::variant_arg in variant.node.args {
check (valid_variant_index(i, bcx, t_id, v_id));
let rslt = GEP_tag(bcx, llblobptr, t_id, v_id, ty_param_substs, i);
let rslt = GEP_enum(bcx, llblobptr, t_id, v_id, ty_param_substs, i);
bcx = rslt.bcx;
let lldestptr = rslt.val;
// If this argument to this function is a enum, it'll have come in to
......@@ -4915,14 +4912,14 @@ fn trans_item(cx: @local_ctxt, item: ast::item) {
module_path: cx.module_path + [item.ident] with *cx};
trans_mod(sub_cx, m);
}
ast::item_tag(variants, tps) {
ast::item_enum(variants, tps) {
let sub_cx = extend_path(cx, item.ident);
let degen = vec::len(variants) == 1u;
let vi = ty::tag_variants(cx.ccx.tcx, {crate: ast::local_crate,
let vi = ty::enum_variants(cx.ccx.tcx, {crate: ast::local_crate,
node: item.id});
let i = 0;
for variant: ast::variant in variants {
trans_tag_variant(sub_cx, item.id, variant,
trans_enum_variant(sub_cx, item.id, variant,
vi[i].disr_val, degen, tps);
i += 1;
}
......@@ -5224,7 +5221,7 @@ fn collect_item(ccx: @crate_ctxt, abi: @mutable option::t<ast::native_abi>,
check returns_non_ty_var(ccx, t);
register_fn_full(ccx, i.span, new_pt, "res_dtor", tps, i.id, t);
}
ast::item_tag(variants, tps) {
ast::item_enum(variants, tps) {
for variant in variants {
if vec::len(variant.node.args) != 0u {
register_fn(ccx, i.span, new_pt + [variant.node.name],
......@@ -5252,8 +5249,8 @@ fn trans_constant(ccx: @crate_ctxt, it: @ast::item, &&pt: [str],
let new_pt = pt + [it.ident];
visit::visit_item(it, new_pt, v);
alt it.node {
ast::item_tag(variants, _) {
let vi = ty::tag_variants(ccx.tcx, {crate: ast::local_crate,
ast::item_enum(variants, _) {
let vi = ty::enum_variants(ccx.tcx, {crate: ast::local_crate,
node: it.id});
let i = 0;
for variant in variants {
......@@ -5517,7 +5514,7 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
item_symbols: new_int_hash::<str>(),
mutable main_fn: none::<ValueRef>,
link_meta: link_meta,
tag_sizes: ty::new_ty_hash(),
enum_sizes: ty::new_ty_hash(),
discrims: ast_util::new_def_id_hash::<ValueRef>(),
discrim_symbols: new_int_hash::<str>(),
consts: new_int_hash::<ValueRef>(),
......
......@@ -68,7 +68,7 @@ fn trans_opt(bcx: @block_ctxt, o: opt) -> opt_result {
// FIXME: invariant -- pat_id is bound in the def_map?
fn variant_opt(ccx: @crate_ctxt, pat_id: ast::node_id) -> opt {
let vdef = ast_util::variant_def_ids(ccx.tcx.def_map.get(pat_id));
let variants = ty::tag_variants(ccx.tcx, vdef.tg);
let variants = ty::enum_variants(ccx.tcx, vdef.tg);
for v: ty::variant_info in *variants {
if vdef.var == v.id { ret var(v.disr_val, vdef); }
}
......@@ -158,13 +158,13 @@ fn e(p: @ast::pat) -> option::t<[@ast::pat]> {
ret enter_match(m, col, val, e);
}
fn enter_opt(ccx: @crate_ctxt, m: match, opt: opt, col: uint, tag_size: uint,
fn enter_opt(ccx: @crate_ctxt, m: match, opt: opt, col: uint, enum_size: uint,
val: ValueRef) -> match {
let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()};
fn e(ccx: @crate_ctxt, dummy: @ast::pat, opt: opt, size: uint,
p: @ast::pat) -> option::t<[@ast::pat]> {
alt p.node {
ast::pat_tag(ctor, subpats) {
ast::pat_enum(ctor, subpats) {
ret if opt_eq(variant_opt(ccx, p.id), opt) {
some(subpats)
} else { none };
......@@ -178,7 +178,7 @@ fn e(ccx: @crate_ctxt, dummy: @ast::pat, opt: opt, size: uint,
_ { ret some(vec::init_elt(size, dummy)); }
}
}
ret enter_match(m, col, val, bind e(ccx, dummy, opt, tag_size, _));
ret enter_match(m, col, val, bind e(ccx, dummy, opt, enum_size, _));
}
fn enter_rec(m: match, col: uint, fields: [ast::ident], val: ValueRef) ->
......@@ -251,7 +251,7 @@ fn add_to_set(&set: [opt], val: opt) {
ast::pat_range(l1, l2) {
add_to_set(found, range(l1, l2));
}
ast::pat_tag(_, _) {
ast::pat_enum(_, _) {
add_to_set(found, variant_opt(ccx, br.pats[col].id));
}
_ { }
......@@ -268,14 +268,14 @@ fn extract_variant_args(bcx: @block_ctxt, pat_id: ast::node_id,
// pat_id must have the same length ty_param_substs as vdefs?
let ty_param_substs = ty::node_id_to_type_params(ccx.tcx, pat_id);
let blobptr = val;
let variants = ty::tag_variants(ccx.tcx, vdefs.tg);
let variants = ty::enum_variants(ccx.tcx, vdefs.tg);
let args = [];
let size =
vec::len(ty::tag_variant_with_id(ccx.tcx, vdefs.tg, vdefs.var).args);
vec::len(ty::enum_variant_with_id(ccx.tcx, vdefs.tg, vdefs.var).args);
if size > 0u && vec::len(*variants) != 1u {
let tagptr =
PointerCast(bcx, val, trans_common::T_opaque_tag_ptr(ccx));
blobptr = GEPi(bcx, tagptr, [0, 1]);
let enumptr =
PointerCast(bcx, val, trans_common::T_opaque_enum_ptr(ccx));
blobptr = GEPi(bcx, enumptr, [0, 1]);
}
let i = 0u;
let vdefs_tg = vdefs.tg;
......@@ -286,8 +286,8 @@ fn extract_variant_args(bcx: @block_ctxt, pat_id: ast::node_id,
// invariant needed:
// how do we know it even makes sense to pass in ty_param_substs
// here? What if it's [] and the enum type has variables in it?
trans::GEP_tag(bcx, blobptr, vdefs_tg, vdefs_var, ty_param_substs,
i);
trans::GEP_enum(bcx, blobptr, vdefs_tg, vdefs_var,
ty_param_substs, i);
bcx = r.bcx;
args += [r.val];
i += 1u;
......@@ -339,7 +339,7 @@ fn any_tup_pat(m: match, col: uint) -> bool {
fn pick_col(m: match) -> uint {
fn score(p: @ast::pat) -> uint {
alt p.node {
ast::pat_lit(_) | ast::pat_tag(_, _) | ast::pat_range(_, _) { 1u }
ast::pat_lit(_) | ast::pat_enum(_, _) | ast::pat_range(_, _) { 1u }
ast::pat_ident(_, some(p)) { score(p) }
_ { 0u }
}
......@@ -479,13 +479,13 @@ enum branch_kind { no_branch, single, switch, compare, }
if vec::len(opts) > 0u {
alt opts[0] {
var(_, vdef) {
if vec::len(*ty::tag_variants(ccx.tcx, vdef.tg)) == 1u {
if vec::len(*ty::enum_variants(ccx.tcx, vdef.tg)) == 1u {
kind = single;
} else {
let tagptr =
let enumptr =
PointerCast(bcx, val,
trans_common::T_opaque_tag_ptr(ccx));
let discrimptr = GEPi(bcx, tagptr, [0, 0]);
trans_common::T_opaque_enum_ptr(ccx));
let discrimptr = GEPi(bcx, enumptr, [0, 0]);
test_val = Load(bcx, discrimptr);
kind = switch;
}
......@@ -725,7 +725,7 @@ fn bind_irrefutable_pat(bcx: @block_ctxt, pat: @ast::pat, val: ValueRef,
_ {}
}
}
ast::pat_tag(_, sub) {
ast::pat_enum(_, sub) {
if vec::len(sub) == 0u { ret bcx; }
let vdefs = ast_util::variant_def_ids(ccx.tcx.def_map.get(pat.id));
let args = extract_variant_args(bcx, pat.id, vdefs, val);
......
......@@ -92,7 +92,7 @@ enum tydesc_kind {
item_symbols: hashmap<ast::node_id, str>,
mutable main_fn: option::t<ValueRef>,
link_meta: link::link_meta,
tag_sizes: hashmap<ty::t, uint>,
enum_sizes: hashmap<ty::t, uint>,
discrims: hashmap<ast::def_id, ValueRef>,
discrim_symbols: hashmap<ast::node_id, str>,
consts: hashmap<ast::node_id, ValueRef>,
......@@ -701,31 +701,31 @@ fn T_opaque_cbox_ptr(cx: @crate_ctxt) -> TypeRef {
ret t;
}
fn T_tag_variant(cx: @crate_ctxt) -> TypeRef {
fn T_enum_variant(cx: @crate_ctxt) -> TypeRef {
ret cx.int_type;
}
fn T_tag(cx: @crate_ctxt, size: uint) -> TypeRef {
let s = "tag_" + uint::to_str(size, 10u);
fn T_enum(cx: @crate_ctxt, size: uint) -> TypeRef {
let s = "enum_" + uint::to_str(size, 10u);
alt name_has_type(cx.tn, s) { some(t) { ret t; } _ {} }
let t =
if size == 0u {
T_struct([T_tag_variant(cx)])
} else { T_struct([T_tag_variant(cx), T_array(T_i8(), size)]) };
T_struct([T_enum_variant(cx)])
} else { T_struct([T_enum_variant(cx), T_array(T_i8(), size)]) };
associate_type(cx.tn, s, t);
ret t;
}
fn T_opaque_tag(cx: @crate_ctxt) -> TypeRef {
let s = "opaque_tag";
fn T_opaque_enum(cx: @crate_ctxt) -> TypeRef {
let s = "opaque_enum";
alt name_has_type(cx.tn, s) { some(t) { ret t; } _ {} }
let t = T_struct([T_tag_variant(cx), T_i8()]);
let t = T_struct([T_enum_variant(cx), T_i8()]);
associate_type(cx.tn, s, t);
ret t;
}
fn T_opaque_tag_ptr(cx: @crate_ctxt) -> TypeRef {
ret T_ptr(T_opaque_tag(cx));
fn T_opaque_enum_ptr(cx: @crate_ctxt) -> TypeRef {
ret T_ptr(T_opaque_enum(cx));
}
fn T_captured_tydescs(cx: @crate_ctxt, n: uint) -> TypeRef {
......@@ -850,7 +850,7 @@ fn C_shape(ccx: @crate_ctxt, bytes: [u8]) -> ValueRef {
}
pure fn valid_variant_index(ix: uint, cx: @block_ctxt, tag_id: ast::def_id,
pure fn valid_variant_index(ix: uint, cx: @block_ctxt, enum_id: ast::def_id,
variant_id: ast::def_id) -> bool {
// Handwaving: it's ok to pretend this code is referentially
......@@ -858,7 +858,7 @@ fn C_shape(ccx: @crate_ctxt, bytes: [u8]) -> ValueRef {
// change. (We're not adding new variants during trans.)
unchecked{
let variant =
ty::tag_variant_with_id(bcx_tcx(cx), tag_id, variant_id);
ty::enum_variant_with_id(bcx_tcx(cx), enum_id, variant_id);
ix < vec::len(variant.args)
}
}
......
......@@ -67,7 +67,7 @@ fn find_pre_post_item(ccx: crate_ctxt, i: item) {
}
item_mod(m) { find_pre_post_mod(m); }
item_native_mod(nm) { find_pre_post_native_mod(nm); }
item_ty(_, _) | item_tag(_, _) | item_iface(_, _) { ret; }
item_ty(_, _) | item_enum(_, _) | item_iface(_, _) { ret; }
item_res(_, _, body, dtor_id, _) {
let fcx =
{enclosing: ccx.fm.get(dtor_id),
......
......@@ -77,7 +77,7 @@
export mk_param;
export mk_ptr;
export mk_rec;
export mk_tag;
export mk_enum;
export mk_tup;
export mk_type;
export mk_send_type;
......@@ -101,9 +101,9 @@
export substitute_type_params;
export t;
export new_ty_hash;
export tag_variants;
export enum_variants;
export iface_methods, store_iface_methods, impl_iface;
export tag_variant_with_id;
export enum_variant_with_id;
export ty_param_substs_opt_and_ty;
export ty_param_bounds_and_ty;
export ty_native_fn;
......@@ -128,7 +128,7 @@
export ty_param;
export ty_ptr;
export ty_rec;
export ty_tag;
export ty_enum;
export ty_tup;
export ty_type;
export ty_send_type;
......@@ -172,7 +172,7 @@
export type_is_tup_like;
export type_is_str;
export type_is_unique;
export type_is_tag;
export type_is_enum;
export type_is_c_like_enum;
export type_structurally_contains_uniques;
export type_autoderef;
......@@ -221,7 +221,7 @@
needs_drop_cache: hashmap<t, bool>,
kind_cache: hashmap<t, kind>,
ast_ty_to_ty_cache: hashmap<@ast::ty, option::t<t>>,
tag_var_cache: hashmap<def_id, @[variant_info]>,
enum_var_cache: hashmap<def_id, @[variant_info]>,
iface_method_cache: hashmap<def_id, @[method]>,
ty_param_bounds: hashmap<ast::node_id, param_bounds>};
......@@ -258,7 +258,7 @@ enum sty {
ty_uint(ast::uint_ty),
ty_float(ast::float_ty),
ty_str,
ty_tag(def_id, [t]),
ty_enum(def_id, [t]),
ty_box(mt),
ty_uniq(mt),
ty_vec(mt),
......@@ -437,7 +437,7 @@ fn eq_raw_ty(&&a: @raw_t, &&b: @raw_t) -> bool {
kind_cache: new_ty_hash(),
ast_ty_to_ty_cache:
map::mk_hashmap(ast_util::hash_ty, ast_util::eq_ty),
tag_var_cache: new_def_hash(),
enum_var_cache: new_def_hash(),
iface_method_cache: new_def_hash(),
ty_param_bounds: map::new_int_hash()};
populate_type_store(cx);
......@@ -475,7 +475,7 @@ fn derive_flags_sig(cx: ctxt, &has_params: bool, &has_vars: bool,
}
ty_param(_, _) { has_params = true; }
ty_var(_) { has_vars = true; }
ty_tag(_, tys) | ty_iface(_, tys) {
ty_enum(_, tys) | ty_iface(_, tys) {
for tt: t in tys { derive_flags_t(cx, has_params, has_vars, tt); }
}
ty_box(m) { derive_flags_mt(cx, has_params, has_vars, m); }
......@@ -567,8 +567,8 @@ fn mk_mach_float(_cx: ctxt, tm: ast::float_ty) -> t {
fn mk_str(_cx: ctxt) -> t { ret idx_str; }
fn mk_tag(cx: ctxt, did: ast::def_id, tys: [t]) -> t {
ret gen_ty(cx, ty_tag(did, tys));
fn mk_enum(cx: ctxt, did: ast::def_id, tys: [t]) -> t {
ret gen_ty(cx, ty_enum(did, tys));
}
fn mk_box(cx: ctxt, tm: mt) -> t { ret gen_ty(cx, ty_box(tm)); }
......@@ -685,7 +685,7 @@ fn walk_ty(cx: ctxt, walker: ty_walk, ty: t) {
/* no-op */
}
ty_box(tm) | ty_vec(tm) | ty_ptr(tm) { walk_ty(cx, walker, tm.ty); }
ty_tag(_, subtys) | ty_iface(_, subtys) {
ty_enum(_, subtys) | ty_iface(_, subtys) {
for subty: t in subtys { walk_ty(cx, walker, subty); }
}
ty_rec(fields) {
......@@ -748,8 +748,8 @@ fn fold_ty(cx: ctxt, fld: fold_mode, ty_0: t) -> t {
ty_vec(tm) {
ty = mk_vec(cx, {ty: fold_ty(cx, fld, tm.ty), mut: tm.mut});
}
ty_tag(tid, subtys) {
ty = mk_tag(cx, tid, vec::map(subtys, {|t| fold_ty(cx, fld, t) }));
ty_enum(tid, subtys) {
ty = mk_enum(cx, tid, vec::map(subtys, {|t| fold_ty(cx, fld, t) }));
}
ty_iface(did, subtys) {
ty = mk_iface(cx, did, vec::map(subtys, {|t| fold_ty(cx, fld, t) }));
......@@ -826,7 +826,7 @@ fn type_is_bool(cx: ctxt, ty: t) -> bool {
fn type_is_structural(cx: ctxt, ty: t) -> bool {
alt struct(cx, ty) {
ty_rec(_) | ty_tup(_) | ty_tag(_, _) | ty_fn(_) |
ty_rec(_) | ty_tup(_) | ty_enum(_, _) | ty_fn(_) |
ty_native_fn(_, _) | ty_res(_, _, _) { true }
_ { false }
}
......@@ -954,8 +954,8 @@ fn type_needs_drop(cx: ctxt, ty: t) -> bool {
for m in elts { if type_needs_drop(cx, m) { accum = true; } }
accum
}
ty_tag(did, tps) {
let variants = tag_variants(cx, did);
ty_enum(did, tps) {
let variants = enum_variants(cx, did);
for variant in *variants {
for aty in variant.args {
// Perform any type parameter substitutions.
......@@ -1052,10 +1052,10 @@ fn type_kind(cx: ctxt, ty: t) -> kind {
for ty in tys { lowest = lower_kind(lowest, type_kind(cx, ty)); }
lowest
}
// Tags lower to the lowest of their variants.
ty_tag(did, tps) {
// Enums lower to the lowest of their variants.
ty_enum(did, tps) {
let lowest = kind_sendable;
for variant in *tag_variants(cx, did) {
for variant in *enum_variants(cx, did) {
for aty in variant.args {
// Perform any type parameter substitutions.
let arg_ty = substitute_type_params(cx, tps, aty);
......@@ -1088,8 +1088,8 @@ fn type_structurally_contains(cx: ctxt, ty: t, test: fn(sty) -> bool) ->
let sty = struct(cx, ty);
if test(sty) { ret true; }
alt sty {
ty_tag(did, tps) {
for variant in *tag_variants(cx, did) {
ty_enum(did, tps) {
for variant in *enum_variants(cx, did) {
for aty in variant.args {
let sty = substitute_type_params(cx, tps, aty);
if type_structurally_contains(cx, sty, test) { ret true; }
......@@ -1207,8 +1207,8 @@ fn type_is_pod(cx: ctxt, ty: t) -> bool {
ty_str | ty_box(_) | ty_uniq(_) | ty_vec(_) | ty_fn(_) |
ty_native_fn(_, _) | ty_iface(_, _) { result = false; }
// Structural types
ty_tag(did, tps) {
let variants = tag_variants(cx, did);
ty_enum(did, tps) {
let variants = enum_variants(cx, did);
for variant: variant_info in *variants {
let tup_ty = mk_tup(cx, variant.args);
......@@ -1238,9 +1238,9 @@ fn type_is_pod(cx: ctxt, ty: t) -> bool {
ret result;
}
fn type_is_tag(cx: ctxt, ty: t) -> bool {
fn type_is_enum(cx: ctxt, ty: t) -> bool {
alt struct(cx, ty) {
ty_tag(_, _) { ret true; }
ty_enum(_, _) { ret true; }
_ { ret false;}
}
}
......@@ -1249,8 +1249,8 @@ fn type_is_tag(cx: ctxt, ty: t) -> bool {
// constructors
fn type_is_c_like_enum(cx: ctxt, ty: t) -> bool {
alt struct(cx, ty) {
ty_tag(did, tps) {
let variants = tag_variants(cx, did);
ty_enum(did, tps) {
let variants = enum_variants(cx, did);
let some_n_ary = vec::any(*variants, {|v| vec::len(v.args) > 0u});
ret !some_n_ary;
}
......@@ -1287,8 +1287,8 @@ fn type_autoderef(cx: ctxt, t: ty::t) -> ty::t {
ty_res(_, inner, tps) {
t1 = substitute_type_params(cx, tps, inner);
}
ty_tag(did, tps) {
let variants = tag_variants(cx, did);
ty_enum(did, tps) {
let variants = enum_variants(cx, did);
if vec::len(*variants) != 1u || vec::len(variants[0].args) != 1u {
break;
}
......@@ -1372,7 +1372,7 @@ fn hash_fn(id: uint, args: [arg], rty: t) -> uint {
alt t { ast::ty_f { 13u } ast::ty_f32 { 14u } ast::ty_f64 { 15u } }
}
ty_str { ret 17u; }
ty_tag(did, tys) {
ty_enum(did, tys) {
let h = hash_def(18u, did);
for typ: t in tys { h += (h << 5u) + typ; }
ret h;
......@@ -2182,14 +2182,14 @@ fn unify_step(cx: @ctxt, expected: t, actual: t,
_ { ret ures_err(terr_mismatch); }
}
}
ty::ty_tag(expected_id, expected_tps) {
ty::ty_enum(expected_id, expected_tps) {
alt struct(cx.tcx, actual) {
ty::ty_tag(actual_id, actual_tps) {
ty::ty_enum(actual_id, actual_tps) {
if expected_id != actual_id {
ret ures_err(terr_mismatch);
}
ret unify_tps(cx, expected_tps, actual_tps, variance, {|tps|
ures_ok(mk_tag(cx.tcx, expected_id, tps))
ures_ok(mk_enum(cx.tcx, expected_id, tps))
});
}
_ {/* fall through */ }
......@@ -2628,23 +2628,23 @@ fn impl_iface(cx: ctxt, id: ast::def_id) -> option::t<t> {
}
}
// Tag information
// Enum information
type variant_info = @{args: [ty::t], ctor_ty: ty::t, name: str,
id: ast::def_id, disr_val: int};
fn tag_variants(cx: ctxt, id: ast::def_id) -> @[variant_info] {
alt cx.tag_var_cache.find(id) {
fn enum_variants(cx: ctxt, id: ast::def_id) -> @[variant_info] {
alt cx.enum_var_cache.find(id) {
some(variants) { ret variants; }
_ { /* fallthrough */ }
}
let result = if ast::local_crate != id.crate {
@csearch::get_tag_variants(cx, id)
@csearch::get_enum_variants(cx, id)
} else {
// FIXME: Now that the variants are run through the type checker (to
// check the disr_expr if it exists), this code should likely be
// moved there to avoid having to call eval_const_expr twice.
alt cx.items.get(id.node) {
ast_map::node_item(@{node: ast::item_tag(variants, _), _}) {
ast_map::node_item(@{node: ast::item_enum(variants, _), _}) {
let disr_val = -1;
@vec::map(variants, {|variant|
let ctor_ty = node_id_to_monotype(cx, variant.node.id);
......@@ -2670,22 +2670,22 @@ fn tag_variants(cx: ctxt, id: ast::def_id) -> @[variant_info] {
}
}
};
cx.tag_var_cache.insert(id, result);
cx.enum_var_cache.insert(id, result);
result
}
// Returns information about the enum variant with the given ID:
fn tag_variant_with_id(cx: ctxt, tag_id: ast::def_id, variant_id: ast::def_id)
-> variant_info {
let variants = tag_variants(cx, tag_id);
fn enum_variant_with_id(cx: ctxt, enum_id: ast::def_id,
variant_id: ast::def_id) -> variant_info {
let variants = enum_variants(cx, enum_id);
let i = 0u;
while i < vec::len::<variant_info>(*variants) {
let variant = variants[i];
if def_eq(variant.id, variant_id) { ret variant; }
i += 1u;
}
cx.sess.bug("tag_variant_with_id(): no variant exists with that ID");
cx.sess.bug("enum_variant_with_id(): no variant exists with that ID");
}
......@@ -2766,7 +2766,7 @@ fn tycat(cx: ctxt, ty: t) -> int {
ty_vec(_) { tycat_vec }
ty_rec(_) { tycat_struct }
ty_tup(_) { tycat_struct }
ty_tag(_, _) { tycat_struct }
ty_enum(_, _) { tycat_struct }
ty_bot { tycat_bot }
_ { tycat_other }
}
......
......@@ -405,10 +405,10 @@ fn ty_of_item(tcx: ty::ctxt, mode: mode, it: @ast::item)
tcx.tcache.insert(local_def(it.id), t_res);
ret t_res;
}
ast::item_tag(_, tps) {
ast::item_enum(_, tps) {
// Create a new generic polytype.
let {bounds, params} = mk_ty_params(tcx, tps);
let t = ty::mk_named(tcx, ty::mk_tag(tcx, local_def(it.id), params),
let t = ty::mk_named(tcx, ty::mk_enum(tcx, local_def(it.id), params),
@it.ident);
let tpt = {bounds: bounds, ty: t};
tcx.tcache.insert(local_def(it.id), tpt);
......@@ -644,7 +644,7 @@ fn compare_impl_method(tcx: ty::ctxt, sp: span, impl_m: ty::method,
mod collect {
type ctxt = {tcx: ty::ctxt};
fn get_tag_variant_types(cx: @ctxt, tag_ty: ty::t,
fn get_enum_variant_types(cx: @ctxt, enum_ty: ty::t,
variants: [ast::variant],
ty_params: [ast::ty_param]) {
// Create a set of parameter types shared among all the variants.
......@@ -654,7 +654,7 @@ fn get_tag_variant_types(cx: @ctxt, tag_ty: ty::t,
// constructors get turned into functions.
let result_ty = if vec::len(variant.node.args) == 0u {
tag_ty
enum_ty
} else {
// As above, tell ast_ty_to_ty() that trans_ty_item_to_ty()
// should be called to resolve named types.
......@@ -666,7 +666,7 @@ fn get_tag_variant_types(cx: @ctxt, tag_ty: ty::t,
// FIXME: this will be different for constrained types
ty::mk_fn(cx.tcx,
{proto: ast::proto_box,
inputs: args, output: tag_ty,
inputs: args, output: enum_ty,
ret_style: ast::return_val, constraints: []})
};
let tpt = {bounds: ty_param_bounds(cx.tcx, m_collect, ty_params),
......@@ -679,10 +679,10 @@ fn convert(cx: @ctxt, it: @ast::item) {
alt it.node {
// These don't define types.
ast::item_mod(_) | ast::item_native_mod(_) {}
ast::item_tag(variants, ty_params) {
ast::item_enum(variants, ty_params) {
let tpt = ty_of_item(cx.tcx, m_collect, it);
write::ty_only(cx.tcx, it.id, tpt.ty);
get_tag_variant_types(cx, tpt.ty, variants, ty_params);
get_enum_variant_types(cx, tpt.ty, variants, ty_params);
}
ast::item_impl(tps, ifce, selfty, ms) {
let i_bounds = ty_param_bounds(cx.tcx, m_collect, tps);
......@@ -826,8 +826,8 @@ fn do_autoderef(fcx: @fn_ctxt, sp: span, t: ty::t) -> ty::t {
ty::ty_res(_, inner, tps) {
t1 = ty::substitute_type_params(fcx.ccx.tcx, tps, inner);
}
ty::ty_tag(did, tps) {
let variants = ty::tag_variants(fcx.ccx.tcx, did);
ty::ty_enum(did, tps) {
let variants = ty::enum_variants(fcx.ccx.tcx, did);
if vec::len(*variants) != 1u || vec::len(variants[0].args) != 1u {
ret t1;
}
......@@ -923,7 +923,7 @@ fn are_compatible(fcx: @fn_ctxt, expected: ty::t, actual: ty::t) -> bool {
// Returns the types of the arguments to a enum variant.
fn variant_arg_types(ccx: @crate_ctxt, _sp: span, vid: ast::def_id,
tag_ty_params: [ty::t]) -> [ty::t] {
enum_ty_params: [ty::t]) -> [ty::t] {
let result: [ty::t] = [];
let tpt = ty::lookup_item_type(ccx.tcx, vid);
alt ty::struct(ccx.tcx, tpt.ty) {
......@@ -931,7 +931,7 @@ fn variant_arg_types(ccx: @crate_ctxt, _sp: span, vid: ast::def_id,
// N-ary variant.
for arg: ty::arg in f.inputs {
let arg_ty =
ty::substitute_type_params(ccx.tcx, tag_ty_params, arg.ty);
ty::substitute_type_params(ccx.tcx, enum_ty_params, arg.ty);
result += [arg_ty];
}
}
......@@ -1187,7 +1187,7 @@ fn check_pat(fcx: @fn_ctxt, map: pat_util::pat_id_map, pat: @ast::pat,
alt normalize_pat(fcx.ccx.tcx, pat).node {
ast::pat_wild {
alt structure_of(fcx, pat.span, expected) {
ty::ty_tag(_, expected_tps) {
ty::ty_enum(_, expected_tps) {
let path_tpt = {substs: some(expected_tps),
ty: expected};
write::ty_fixup(fcx, pat.id, path_tpt);
......@@ -1236,16 +1236,16 @@ fn check_pat(fcx: @fn_ctxt, map: pat_util::pat_id_map, pat: @ast::pat,
_ {}
}
}
ast::pat_tag(path, subpats) {
ast::pat_enum(path, subpats) {
// Typecheck the path.
let v_def = lookup_def(fcx, path.span, pat.id);
let v_def_ids = ast_util::variant_def_ids(v_def);
let tag_tpt = ty::lookup_item_type(fcx.ccx.tcx, v_def_ids.tg);
let path_tpot = instantiate_path(fcx, path, tag_tpt, pat.span);
let enum_tpt = ty::lookup_item_type(fcx.ccx.tcx, v_def_ids.tg);
let path_tpot = instantiate_path(fcx, path, enum_tpt, pat.span);
// Take the enum type params out of `expected`.
alt structure_of(fcx, pat.span, expected) {
ty::ty_tag(_, expected_tps) {
ty::ty_enum(_, expected_tps) {
// Unify with the expected enum type.
let ctor_ty =
ty::ty_param_substs_opt_and_ty_to_monotype(fcx.ccx.tcx,
......@@ -1837,12 +1837,12 @@ fn check_binop_type_compat(fcx: @fn_ctxt, span: span, ty: ty::t,
ty::ty_box(inner) { oper_t = inner.ty; }
ty::ty_uniq(inner) { oper_t = inner.ty; }
ty::ty_res(_, inner, _) { oper_t = inner; }
ty::ty_tag(id, tps) {
let variants = ty::tag_variants(tcx, id);
ty::ty_enum(id, tps) {
let variants = ty::enum_variants(tcx, id);
if vec::len(*variants) != 1u ||
vec::len(variants[0].args) != 1u {
tcx.sess.span_fatal(expr.span,
"can only dereference tags " +
"can only dereference enums " +
"with a single variant which has a "
+ "single argument");
}
......@@ -2463,7 +2463,7 @@ fn check_const(ccx: @crate_ctxt, _sp: span, e: @ast::expr, id: ast::node_id) {
demand::simple(fcx, e.span, declty, cty);
}
fn check_tag_variants(ccx: @crate_ctxt, _sp: span, vs: [ast::variant],
fn check_enum_variants(ccx: @crate_ctxt, _sp: span, vs: [ast::variant],
id: ast::node_id) {
// FIXME: this is kinda a kludge; we manufacture a fake function context
// and statement context for checking the initializer expression.
......@@ -2683,7 +2683,7 @@ fn check_method(ccx: @crate_ctxt, method: @ast::method) {
fn check_item(ccx: @crate_ctxt, it: @ast::item) {
alt it.node {
ast::item_const(_, e) { check_const(ccx, it.span, e, it.id); }
ast::item_tag(vs, _) { check_tag_variants(ccx, it.span, vs, it.id); }
ast::item_enum(vs, _) { check_enum_variants(ccx, it.span, vs, it.id); }
ast::item_fn(decl, tps, body) {
check_fn(ccx, ast::proto_bare, decl, body, it.id, none);
}
......
......@@ -103,12 +103,12 @@ enum pat_ {
// In the nullary enum case, the parser can't determine
// which it is. The resolver determines this, and
// records this pattern's node_id in an auxiliary
// set (of "pat_idents that refer to nullary tags")
// set (of "pat_idents that refer to nullary enums")
// After the resolution phase, code should never pattern-
// match on a pat directly! Always call pat_util::normalize_pat --
// it turns any pat_idents that refer to nullary tags into pat_tags.
// it turns any pat_idents that refer to nullary enums into pat_enums.
pat_ident(@path, option::t<@pat>),
pat_tag(@path, [@pat]),
pat_enum(@path, [@pat]),
pat_rec([field_pat], bool),
pat_tup([@pat]),
pat_box(@pat),
......@@ -440,9 +440,9 @@ enum view_item_ {
view_item_import_from(@simple_path, [import_ident], node_id),
view_item_export([ident], node_id),
// export foo::{}
view_item_export_tag_none(ident, node_id),
view_item_export_enum_none(ident, node_id),
// export foo::{bar, baz, blat}
view_item_export_tag_some(ident, [import_ident], node_id)
view_item_export_enum_some(ident, [import_ident], node_id)
}
// Meta-data associated with an item
......@@ -465,7 +465,7 @@ enum item_ {
item_mod(_mod),
item_native_mod(native_mod),
item_ty(@ty, [ty_param]),
item_tag([variant], [ty_param]),
item_enum([variant], [ty_param]),
item_res(fn_decl /* dtor */, [ty_param], blk,
node_id /* dtor id */, node_id /* ctor id */),
item_iface([ty_param], [ty_method]),
......
......@@ -20,7 +20,7 @@ fn path_name_i(idents: [ident]) -> str { str::connect(idents, "::") }
fn local_def(id: node_id) -> def_id { ret {crate: local_crate, node: id}; }
fn variant_def_ids(d: def) -> {tg: def_id, var: def_id} {
alt d { def_variant(tag_id, var_id) { ret {tg: tag_id, var: var_id}; } }
alt d { def_variant(enum_id, var_id) { ret {tg: enum_id, var: var_id}; } }
}
fn def_id_of_def(d: def) -> def_id {
......@@ -113,15 +113,15 @@ fn float_ty_to_str(t: float_ty) -> str {
fn is_exported(i: ident, m: _mod) -> bool {
let nonlocal = true;
let parent_tag : option<ident> = none;
let parent_enum : option<ident> = none;
for it: @item in m.items {
if it.ident == i { nonlocal = false; }
alt it.node {
item_tag(variants, _) {
item_enum(variants, _) {
for v: variant in variants {
if v.node.name == i {
nonlocal = false;
parent_tag = some(it.ident);
parent_enum = some(it.ident);
}
}
}
......@@ -133,24 +133,24 @@ fn is_exported(i: ident, m: _mod) -> bool {
for vi: @view_item in m.view_items {
alt vi.node {
view_item_export(ids, _) {
// If any of ids is a tag, we want to consider
// If any of ids is a enum, we want to consider
// all the variants to be exported
for id in ids {
if str::eq(i, id) { ret true; }
alt parent_tag {
some(parent_tag_id) {
if str::eq(id, parent_tag_id) { ret true; }
alt parent_enum {
some(parent_enum_id) {
if str::eq(id, parent_enum_id) { ret true; }
}
_ { }
}
}
count += 1u;
}
view_item_export_tag_none(id, _) {
view_item_export_enum_none(id, _) {
if str::eq(i, id) { ret true; }
count += 1u;
}
view_item_export_tag_some(id, ids, _) {
view_item_export_enum_some(id, ids, _) {
if str::eq(i, id) { ret true; }
for id in ids { if str::eq(i, id.node.name) { ret true; } }
count += 1u;
......@@ -278,7 +278,8 @@ fn fromb(b: bool) -> const_val { const_int(b as i64) }
mul { const_uint(a * b) } div { const_uint(a / b) }
rem { const_uint(a % b) } and | bitand { const_uint(a & b) }
or | bitor { const_uint(a | b) } bitxor { const_uint(a ^ b) }
lsl { const_int(a << b as i64) } lsr { const_int(a >> b as i64) }
lsl { const_int(a << b as i64) }
lsr { const_int(a >> b as i64) }
asr { const_int(a >>> b as i64) }
eq { fromb(a == b) } lt { fromb(a < b) }
le { fromb(a <= b) } ne { fromb(a != b) }
......
......@@ -226,8 +226,8 @@ fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
item_mod(m) { item_mod(fld.fold_mod(m)) }
item_native_mod(nm) { item_native_mod(fld.fold_native_mod(nm)) }
item_ty(t, typms) { item_ty(fld.fold_ty(t), typms) }
item_tag(variants, typms) {
item_tag(vec::map(variants, fld.fold_variant), typms)
item_enum(variants, typms) {
item_enum(vec::map(variants, fld.fold_variant), typms)
}
item_impl(tps, ifce, ty, methods) {
item_impl(tps, option::map(ifce, fld.fold_ty), fld.fold_ty(ty),
......@@ -279,8 +279,8 @@ fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ {
pat_ident(fld.fold_path(pth), option::map(sub, fld.fold_pat))
}
pat_lit(_) { p }
pat_tag(pth, pats) {
pat_tag(fld.fold_path(pth), vec::map(pats, fld.fold_pat))
pat_enum(pth, pats) {
pat_enum(fld.fold_path(pth), vec::map(pats, fld.fold_pat))
}
pat_rec(fields, etc) {
let fs = [];
......
......@@ -1501,8 +1501,8 @@ fn parse_pat(p: parser) -> @ast::pat {
let sub = eat(p, token::AT) ? some(parse_pat(p)) : none;
pat = ast::pat_ident(name, sub);
} else {
let tag_path = parse_path_and_ty_param_substs(p, true);
hi = tag_path.span.hi;
let enum_path = parse_path_and_ty_param_substs(p, true);
hi = enum_path.span.hi;
let args: [@ast::pat];
alt p.token {
token::LPAREN {
......@@ -1516,11 +1516,11 @@ fn parse_pat(p: parser) -> @ast::pat {
}
// at this point, we're not sure whether it's a enum or a bind
if vec::len(args) == 0u &&
vec::len(tag_path.node.idents) == 1u {
pat = ast::pat_ident(tag_path, none);
vec::len(enum_path.node.idents) == 1u {
pat = ast::pat_ident(enum_path, none);
}
else {
pat = ast::pat_tag(tag_path, args);
pat = ast::pat_enum(enum_path, args);
}
}
}
......@@ -2024,7 +2024,7 @@ fn parse_item_type(p: parser, attrs: [ast::attribute]) -> @ast::item {
ret mk_item(p, t.lo, hi, t.ident, ast::item_ty(ty, tps), attrs);
}
fn parse_item_tag(p: parser, attrs: [ast::attribute]) -> @ast::item {
fn parse_item_enum(p: parser, attrs: [ast::attribute]) -> @ast::item {
let lo = p.last_span.lo;
let id = parse_ident(p);
let ty_params = parse_ty_params(p);
......@@ -2044,7 +2044,7 @@ fn parse_item_tag(p: parser, attrs: [ast::attribute]) -> @ast::item {
id: p.get_id(),
disr_expr: none});
ret mk_item(p, lo, ty.span.hi, id,
ast::item_tag([variant], ty_params), attrs);
ast::item_enum([variant], ty_params), attrs);
}
expect(p, token::LBRACE);
let all_nullary = true, have_disr = false;
......@@ -2077,7 +2077,7 @@ fn parse_item_tag(p: parser, attrs: [ast::attribute]) -> @ast::item {
p.fatal("discriminator values can only be used with a c-like enum");
}
ret mk_item(p, lo, p.last_span.hi, id,
ast::item_tag(variants, ty_params), attrs);
ast::item_enum(variants, ty_params), attrs);
}
fn parse_fn_ty_proto(p: parser) -> ast::proto {
......@@ -2134,7 +2134,7 @@ fn parse_item(p: parser, attrs: [ast::attribute]) -> option::t<@ast::item> {
} if eat_word(p, "type") {
ret some(parse_item_type(p, attrs));
} else if eat_word(p, "enum") {
ret some(parse_item_tag(p, attrs));
ret some(parse_item_enum(p, attrs));
} else if eat_word(p, "iface") {
ret some(parse_item_iface(p, attrs));
} else if eat_word(p, "impl") {
......@@ -2364,16 +2364,16 @@ fn parse_import(p: parser) -> ast::view_item_ {
}
}
fn parse_tag_export(p:parser, tyname:ast::ident) -> ast::view_item_ {
let tagnames:[ast::import_ident] =
fn parse_enum_export(p:parser, tyname:ast::ident) -> ast::view_item_ {
let enumnames:[ast::import_ident] =
parse_seq(token::LBRACE, token::RBRACE,
seq_sep(token::COMMA), {|p| parse_import_ident(p) }, p).node;
let id = p.get_id();
if vec::is_empty(tagnames) {
ret ast::view_item_export_tag_none(tyname, id);
if vec::is_empty(enumnames) {
ret ast::view_item_export_enum_none(tyname, id);
}
else {
ret ast::view_item_export_tag_some(tyname, tagnames, id);
ret ast::view_item_export_enum_some(tyname, enumnames, id);
}
}
......@@ -2382,7 +2382,7 @@ fn parse_export(p: parser) -> ast::view_item_ {
alt p.token {
token::MOD_SEP {
p.bump();
ret parse_tag_export(p, first);
ret parse_enum_export(p, first);
}
t {
if t == token::COMMA { p.bump(); }
......
......@@ -412,7 +412,7 @@ fn print_item(s: ps, &&item: @ast::item) {
word(s.s, ";");
end(s); // end the outer ibox
}
ast::item_tag(variants, params) {
ast::item_enum(variants, params) {
let newtype =
vec::len(variants) == 1u &&
str::eq(item.ident, variants[0].node.name) &&
......@@ -1081,7 +1081,7 @@ fn print_pat(s: ps, &&pat: @ast::pat) {
_ {}
}
}
ast::pat_tag(path, args) {
ast::pat_enum(path, args) {
print_path(s, path, true);
if vec::len(args) > 0u {
popen(s);
......@@ -1304,12 +1304,12 @@ fn print_view_item(s: ps, item: @ast::view_item) {
commasep(s, inconsistent, ids,
fn@(s: ps, &&w: ast::ident) { word(s.s, w) });
}
ast::view_item_export_tag_none(id, _) {
ast::view_item_export_enum_none(id, _) {
head(s, "export");
word(s.s, id);
word(s.s, "::{}");
}
ast::view_item_export_tag_some(id, ids, _) {
ast::view_item_export_enum_some(id, ids, _) {
head(s, "export");
word(s.s, id);
word(s.s, "::{");
......
......@@ -120,7 +120,7 @@ fn visit_item<E>(i: @item, e: E, v: vt<E>) {
v.visit_fn(fk_res(i.ident, tps), decl, body, i.span,
dtor_id, e, v);
}
item_tag(variants, tps) {
item_enum(variants, tps) {
v.visit_ty_params(tps, e, v);
for vr: variant in variants {
for va: variant_arg in vr.node.args { v.visit_ty(va.ty, e, v); }
......@@ -187,7 +187,7 @@ fn visit_path<E>(p: @path, e: E, v: vt<E>) {
fn visit_pat<E>(p: @pat, e: E, v: vt<E>) {
alt p.node {
pat_tag(path, children) {
pat_enum(path, children) {
visit_path(path, e, v);
for child: @pat in children { v.visit_pat(child, e, v); }
}
......
......@@ -72,7 +72,7 @@ fn mt_to_str(cx: ctxt, m: mt) -> str {
alt ty_name(cx, typ) {
some(cs) {
alt struct(cx, typ) {
ty_tag(_, tps) | ty_res(_, _, tps) {
ty_enum(_, tps) | ty_res(_, _, tps) {
if vec::len(tps) > 0u {
let strs = vec::map(tps, {|t| ty_to_str(cx, t)});
ret *cs + "<" + str::connect(strs, ",") + ">";
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册