rustc: Add a type annotation to tag items

This commit is contained in:
Patrick Walton 2011-03-31 19:12:40 -07:00
parent 1eeedbd008
commit c66edca83d
9 changed files with 35 additions and 36 deletions

View File

@ -404,7 +404,7 @@ tag item_ {
item_mod(ident, _mod, def_id);
item_native_mod(ident, native_mod, def_id);
item_ty(ident, @ty, vec[ty_param], def_id, ann);
item_tag(ident, vec[variant], vec[ty_param], def_id);
item_tag(ident, vec[variant], vec[ty_param], def_id, ann);
item_obj(ident, _obj, vec[ty_param], obj_def_ids, ann);
}
@ -448,7 +448,7 @@ fn index_item(mod_index index, @item it) {
case (ast.item_ty(?id, _, _, _, _)) {
index.insert(id, ast.mie_item(it));
}
case (ast.item_tag(?id, ?variants, _, _)) {
case (ast.item_tag(?id, ?variants, _, _, _)) {
index.insert(id, ast.mie_item(it));
let uint variant_idx = 0u;
for (ast.variant v in variants) {
@ -505,7 +505,7 @@ fn index_stmt(block_index index, @stmt s) {
case (ast.item_ty(?i, _, _, _, _)) {
index.insert(i, ast.bie_item(it));
}
case (ast.item_tag(?i, ?variants, _, _)) {
case (ast.item_tag(?i, ?variants, _, _, _)) {
index.insert(i, ast.bie_item(it));
let uint vid = 0u;
for (ast.variant v in variants) {

View File

@ -2071,7 +2071,8 @@ impure fn parse_item_tag(parser p) -> @ast.item {
p.bump();
auto hi = p.get_span();
auto item = ast.item_tag(id, variants, ty_params, p.next_def_id());
auto item = ast.item_tag(id, variants, ty_params, p.next_def_id(),
ast.ann_none);
ret @spanned(lo, hi, item);
}

View File

@ -269,7 +269,7 @@ type ast_fold[ENV] =
(fn(&ENV e, &span sp, ident ident,
vec[ast.variant] variants,
vec[ast.ty_param] ty_params,
def_id id) -> @item) fold_item_tag,
def_id id, ann a) -> @item) fold_item_tag,
(fn(&ENV e, &span sp, ident ident,
&ast._obj ob,
@ -971,7 +971,7 @@ fn fold_item[ENV](&ENV env, ast_fold[ENV] fld, @item i) -> @item {
ret fld.fold_item_ty(env_, i.span, ident, ty_, params, id, ann);
}
case (ast.item_tag(?ident, ?variants, ?ty_params, ?id)) {
case (ast.item_tag(?ident, ?variants, ?ty_params, ?id, ?ann)) {
let vec[ast.variant] new_variants = vec();
for (ast.variant v in variants) {
let vec[ast.variant_arg] new_args = vec();
@ -984,7 +984,7 @@ fn fold_item[ENV](&ENV env, ast_fold[ENV] fld, @item i) -> @item {
new_variants += vec(respan[ast.variant_](v.span, new_v));
}
ret fld.fold_item_tag(env_, i.span, ident, new_variants,
ty_params, id);
ty_params, id, ann);
}
case (ast.item_obj(?ident, ?ob, ?tps, ?odid, ?ann)) {
@ -1440,8 +1440,8 @@ fn identity_fold_native_item_ty[ENV](&ENV e, &span sp, ident i,
fn identity_fold_item_tag[ENV](&ENV e, &span sp, ident i,
vec[ast.variant] variants,
vec[ast.ty_param] ty_params,
def_id id) -> @item {
ret @respan(sp, ast.item_tag(i, variants, ty_params, id));
def_id id, ann a) -> @item {
ret @respan(sp, ast.item_tag(i, variants, ty_params, id, a));
}
fn identity_fold_item_obj[ENV](&ENV e, &span sp, ident i,
@ -1654,7 +1654,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
fold_item_ty = bind identity_fold_item_ty[ENV](_,_,_,_,_,_,_),
fold_native_item_ty =
bind identity_fold_native_item_ty[ENV](_,_,_,_),
fold_item_tag = bind identity_fold_item_tag[ENV](_,_,_,_,_,_),
fold_item_tag = bind identity_fold_item_tag[ENV](_,_,_,_,_,_,_),
fold_item_obj = bind identity_fold_item_obj[ENV](_,_,_,_,_,_,_),
fold_view_item_use =

View File

@ -262,7 +262,7 @@ fn encode_module_item_paths(&ebml.writer ebml_w,
encode_def_id(ebml_w, did);
ebml.end_tag(ebml_w);
}
case (ast.item_tag(?id, ?variants, ?tps, ?did)) {
case (ast.item_tag(?id, ?variants, ?tps, ?did, _)) {
add_to_index(ebml_w, path, index, id);
ebml.start_tag(ebml_w, tag_paths_data_item);
encode_name(ebml_w, id);
@ -403,11 +403,12 @@ fn encode_info_for_item(@trans.crate_ctxt cx, &ebml.writer ebml_w,
encode_type(ebml_w, trans.node_ann_type(cx, ann));
ebml.end_tag(ebml_w);
}
case (ast.item_tag(?id, ?variants, ?tps, ?did)) {
case (ast.item_tag(?id, ?variants, ?tps, ?did, ?ann)) {
ebml.start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, did);
encode_kind(ebml_w, 't' as u8);
encode_type_params(ebml_w, tps);
encode_type(ebml_w, trans.node_ann_type(cx, ann));
ebml.end_tag(ebml_w);
encode_tag_variant_info(cx, ebml_w, did, variants);

View File

@ -319,7 +319,7 @@ fn lookup_name_wrapped(&env e, ast.ident i, namespace ns)
case (ast.item_ty(_, _, _, ?id, _)) {
ret def_wrap_other(ast.def_ty(id));
}
case (ast.item_tag(_, _, _, ?id)) {
case (ast.item_tag(_, _, _, ?id, _)) {
ret def_wrap_other(ast.def_ty(id));
}
case (ast.item_obj(_, _, _, ?odid, _)) {
@ -388,7 +388,7 @@ fn lookup_name_wrapped(&env e, ast.ident i, namespace ns)
}
case (ast.mie_tag_variant(?item, ?variant_idx)) {
alt (item.node) {
case (ast.item_tag(_, ?variants, _, ?tid)) {
case (ast.item_tag(_, ?variants, _, ?tid, _)) {
auto vid = variants.(variant_idx).node.id;
auto t = ast.def_variant(tid, vid);
ret some[def_wrap](def_wrap_other(t));
@ -445,7 +445,7 @@ fn lookup_name_wrapped(&env e, ast.ident i, namespace ns)
fn found_tag(@ast.item item, uint variant_idx) -> def_wrap {
alt (item.node) {
case (ast.item_tag(_, ?variants, _, ?tid)) {
case (ast.item_tag(_, ?variants, _, ?tid, _)) {
auto vid = variants.(variant_idx).node.id;
auto t = ast.def_variant(tid, vid);
ret def_wrap_other(t);
@ -505,7 +505,7 @@ fn lookup_name_wrapped(&env e, ast.ident i, namespace ns)
}
}
}
case (ast.item_tag(_, ?variants, ?ty_params, ?tag_id)) {
case (ast.item_tag(_,?variants,?ty_params,?tag_id,_)) {
for (ast.ty_param tp in ty_params) {
if (_str.eq(tp.ident, i)) {
auto t = ast.def_ty_arg(tp.id);

View File

@ -1913,7 +1913,7 @@ fn tag_ty_params(@crate_ctxt cx, ast.def_id id) -> vec[ast.def_id] {
fn tag_variants(@crate_ctxt cx, ast.def_id id) -> vec[ast.variant] {
check (cx.items.contains_key(id));
alt (cx.items.get(id).node) {
case (ast.item_tag(_, ?variants, _, _)) { ret variants; }
case (ast.item_tag(_, ?variants, _, _, _)) { ret variants; }
}
fail; // not reached
}
@ -3703,7 +3703,7 @@ fn trans_path(@block_ctxt cx, &ast.path p, &option.t[ast.def] dopt,
auto params = ty.item_ty(tag_item)._0;
auto fty = plain_ty(ty.ty_nil);
alt (tag_item.node) {
case (ast.item_tag(_, ?variants, _, _)) {
case (ast.item_tag(_, ?variants, _, _, _)) {
for (ast.variant v in variants) {
if (v.node.id == vid) {
fty = node_ann_type(cx.fcx.ccx,
@ -5943,7 +5943,7 @@ fn trans_item(@crate_ctxt cx, &ast.item item) {
auto sub_cx = extend_path(cx, name);
trans_mod(sub_cx, m);
}
case (ast.item_tag(?name, ?variants, ?tps, ?tag_id)) {
case (ast.item_tag(?name, ?variants, ?tps, ?tag_id, _)) {
auto sub_cx = extend_path(cx, name);
auto i = 0;
for (ast.variant variant in variants) {
@ -6162,7 +6162,7 @@ fn item_name(@ast.item i) -> str {
case (ast.item_mod(?name, _, _)) {
ret name;
}
case (ast.item_tag(?name, _, _, _)) {
case (ast.item_tag(?name, _, _, _, _)) {
ret name;
}
case (ast.item_const(?name, _, _, _, _)) {
@ -6211,7 +6211,7 @@ fn collect_item(&@crate_ctxt cx, @ast.item i) -> @crate_ctxt {
cx.items.insert(did, i);
}
case (ast.item_tag(?name, ?variants, ?tps, ?tag_id)) {
case (ast.item_tag(?name, ?variants, ?tps, ?tag_id, _)) {
cx.items.insert(tag_id, i);
}
@ -6272,7 +6272,7 @@ fn collect_tag_ctor(&@crate_ctxt cx, @ast.item i) -> @crate_ctxt {
alt (i.node) {
case (ast.item_tag(_, ?variants, ?tps, _)) {
case (ast.item_tag(_, ?variants, ?tps, _, _)) {
for (ast.variant variant in variants) {
if (_vec.len[ast.variant_arg](variant.node.args) != 0u) {
decl_fn_and_pair(extend_path(cx, variant.node.name),
@ -6302,7 +6302,7 @@ fn collect_tag_ctors(@crate_ctxt cx, @ast.crate crate) {
fn trans_constant(&@crate_ctxt cx, @ast.item it) -> @crate_ctxt {
alt (it.node) {
case (ast.item_tag(_, ?variants, _, ?tag_id)) {
case (ast.item_tag(_, ?variants, _, ?tag_id, _)) {
auto i = 0u;
auto n_variants = _vec.len[ast.variant](variants);
while (i < n_variants) {

View File

@ -706,14 +706,9 @@ fn item_ty(@ast.item it) -> ty_params_and_ty {
ty_params = tps;
result_ty = ann_to_type(ann);
}
case (ast.item_tag(_, _, ?tps, ?did)) {
// Create a new generic polytype.
case (ast.item_tag(_, _, ?tps, ?did, ?ann)) {
ty_params = tps;
let vec[@t] subtys = vec();
for (ast.ty_param tp in tps) {
subtys += vec(plain_ty(ty_param(tp.id)));
}
result_ty = plain_ty(ty_tag(did, subtys));
result_ty = ann_to_type(ann);
}
case (ast.item_obj(_, _, ?tps, _, ?ann)) {
ty_params = tps;

View File

@ -586,7 +586,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
ret tpt;
}
case (ast.item_tag(_, _, ?tps, ?def_id)) {
case (ast.item_tag(_, _, ?tps, ?def_id, _)) {
// Create a new generic polytype.
let vec[@ty.t] subtys = vec();
for (ast.ty_param tp in tps) {
@ -694,7 +694,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
case (ast.item_ty(_, _, _, ?def_id, _)) {
id_to_ty_item.insert(def_id, any_item_rust(i));
}
case (ast.item_tag(_, _, _, ?def_id)) {
case (ast.item_tag(_, _, _, ?def_id, _)) {
id_to_ty_item.insert(def_id, any_item_rust(i));
}
case (ast.item_obj(_, _, _, ?odid, _)) {
@ -870,14 +870,16 @@ fn collect_item_types(session.session sess, @ast.crate crate)
fn fold_item_tag(&@env e, &span sp, ast.ident i,
vec[ast.variant] variants,
vec[ast.ty_param] ty_params,
ast.def_id id) -> @ast.item {
ast.def_id id, ast.ann a) -> @ast.item {
auto variants_t = get_tag_variant_types(e.sess,
e.id_to_ty_item,
e.type_cache,
id,
variants,
ty_params);
auto item = ast.item_tag(i, variants_t, ty_params, id);
auto typ = e.type_cache.get(id)._1;
auto item = ast.item_tag(i, variants_t, ty_params, id,
ast.ann_type(typ, none[vec[@ty.t]]));
ret @fold.respan[ast.item_](sp, item);
}
@ -890,7 +892,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
fold_native_item_fn = bind fold_native_item_fn(_,_,_,_,_,_,_,_),
fold_item_obj = bind fold_item_obj(_,_,_,_,_,_,_),
fold_item_ty = bind fold_item_ty(_,_,_,_,_,_,_),
fold_item_tag = bind fold_item_tag(_,_,_,_,_,_)
fold_item_tag = bind fold_item_tag(_,_,_,_,_,_,_)
with *fld_2);
auto crate_ = fold.fold_crate[@env](e, fld_2, crate);
ret tup(crate_, type_cache, id_to_ty_item);

View File

@ -240,7 +240,7 @@ impure fn print_item(ps s, @ast.item item) {
print_type(s, ty);
wrd(s.s, ";");
}
case (ast.item_tag(?id,?variants,?params,_)) {
case (ast.item_tag(?id,?variants,?params,_,_)) {
wrd1(s, "tag");
wrd(s.s, id);
print_type_params(s, params);