Refactor ast::item representation

Most of the fields in an AST item were present in all variants. Things
could be simplified considerably by putting them in the rec rather
than in the variant tags.
This commit is contained in:
Marijn Haverbeke 2011-06-16 11:53:06 +02:00
parent 6c2f322f82
commit 15f71b3600
15 changed files with 311 additions and 382 deletions

View File

@ -459,28 +459,21 @@ tag attr_style { attr_outer; attr_inner; }
type attribute_ = rec(attr_style style, meta_item value);
type item = spanned[item_];
type item = rec(ident ident,
vec[attribute] attrs,
def_id id, // For objs, this is the type def_id
ann ann,
item_ node,
span span);
tag item_ {
item_const(ident, @ty, @expr, vec[attribute], def_id, ann);
item_fn(ident, _fn, vec[ty_param], vec[attribute], def_id, ann);
item_mod(ident, _mod, vec[attribute], def_id);
item_native_mod(ident, native_mod, vec[attribute], def_id);
item_ty(ident, @ty, vec[ty_param], vec[attribute], def_id, ann);
item_tag(ident, vec[variant], vec[ty_param], vec[attribute], def_id, ann);
item_obj(ident, _obj, vec[ty_param], vec[attribute], obj_def_ids, ann);
}
fn item_ident(@item it) -> ident {
ret alt (it.node) {
case (item_const(?ident, _, _, _, _, _)) { ident }
case (item_fn(?ident, _, _, _, _, _)) { ident }
case (item_mod(?ident, _, _, _)) { ident }
case (item_native_mod(?ident, _, _, _)) { ident }
case (item_ty(?ident, _, _, _, _, _)) { ident }
case (item_tag(?ident, _, _, _, _, _)) { ident }
case (item_obj(?ident, _, _, _, _, _)) { ident }
}
item_const(@ty, @expr);
item_fn(_fn, vec[ty_param]);
item_mod(_mod);
item_native_mod(native_mod);
item_ty(@ty, vec[ty_param]);
item_tag(vec[variant], vec[ty_param]);
item_obj(_obj, vec[ty_param], def_id /* constructor id */);
}
type native_item = spanned[native_item_];
@ -498,15 +491,16 @@ tag native_item_ {
fn is_exported(ident i, _mod m) -> bool {
auto nonlocal = true;
for (@ast::item it in m.items) {
if (item_ident(it) == i) { nonlocal = false; }
if (it.ident == i) { nonlocal = false; }
alt (it.node) {
case (item_tag(_, ?variants, _, _, _, _)) {
case (item_tag(?variants, _)) {
for (variant v in variants) {
if (v.node.name == i) { nonlocal = false; }
}
}
case (_) { }
}
if (!nonlocal) { break; }
}
auto count = 0u;
for (@ast::view_item vi in m.view_items) {
@ -525,7 +519,7 @@ fn is_exported(ident i, _mod m) -> bool {
// If there are no declared exports then
// everything not imported is exported
if (count == 0u && !nonlocal) { ret true; } else { ret false; }
ret count == 0u && !nonlocal;
}
fn is_call_expr(@expr e) -> bool {

View File

@ -294,8 +294,8 @@ fn eval_crate_directive(ctx cx, env e, @ast::crate_directive cdir, str prefix,
cx.p.set_def(next_id._1);
cx.chpos = p0.get_chpos();
cx.next_ann = p0.next_ann_num();
auto im = ast::item_mod(id, m0, [], next_id);
auto i = @spanned(cdir.span.lo, cdir.span.hi, im);
auto i = front::parser::mk_item(cx.p, cdir.span.lo, cdir.span.hi,
id, ast::item_mod(m0), []);
vec::push[@ast::item](items, i);
}
case (ast::cdir_dir_mod(?id, ?dir_opt, ?cdirs)) {
@ -303,8 +303,8 @@ fn eval_crate_directive(ctx cx, env e, @ast::crate_directive cdir, str prefix,
alt (dir_opt) { case (some(?d)) { path = d; } case (none) { } }
auto full_path = prefix + std::fs::path_sep() + path;
auto m0 = eval_crate_directives_to_mod(cx, e, cdirs, full_path);
auto im = ast::item_mod(id, m0, [], cx.p.next_def_id());
auto i = @spanned(cdir.span.lo, cdir.span.hi, im);
auto i = front::parser::mk_item
(cx.p, cdir.span.lo, cdir.span.hi, id, ast::item_mod(m0), []);
vec::push[@ast::item](items, i);
}
case (ast::cdir_view_item(?vi)) {

View File

@ -1662,14 +1662,22 @@ fn parse_fn_header(&parser p) -> tup(ast::ident, vec[ast::ty_param]) {
ret tup(id, ty_params);
}
fn mk_item(&parser p, uint lo, uint hi, &ast::ident ident, &ast::item_ node,
&vec[ast::attribute] attrs) -> @ast::item {
ret @rec(ident=ident,
attrs=attrs,
id=p.next_def_id(),
ann=p.get_ann(),
node=node,
span=rec(lo=lo, hi=hi));
}
fn parse_item_fn_or_iter(&parser p, ast::purity purity, ast::proto proto,
vec[ast::attribute] attrs) -> @ast::item {
auto lo = p.get_last_lo_pos();
auto t = parse_fn_header(p);
auto f = parse_fn(p, proto, purity);
auto item =
ast::item_fn(t._0, f, t._1, attrs, p.next_def_id(), p.get_ann());
ret @spanned(lo, f.body.span.hi, item);
ret mk_item(p, lo, f.body.span.hi, t._0, ast::item_fn(f, t._1), attrs);
}
fn parse_obj_field(&parser p) -> ast::obj_field {
@ -1727,9 +1735,8 @@ fn parse_item_obj(&parser p, ast::layer lyr, vec[ast::attribute] attrs) ->
auto hi = p.get_hi_pos();
expect(p, token::RBRACE);
let ast::_obj ob = rec(fields=fields.node, methods=meths, dtor=dtor);
auto odid = rec(ty=p.next_def_id(), ctor=p.next_def_id());
auto item = ast::item_obj(ident, ob, ty_params, attrs, odid, p.get_ann());
ret @spanned(lo, hi, item);
ret mk_item(p, lo, hi, ident, ast::item_obj(ob, ty_params,
p.next_def_id()), attrs);
}
fn parse_mod_items(&parser p, token::token term) -> ast::_mod {
@ -1756,9 +1763,7 @@ fn parse_item_const(&parser p, vec[ast::attribute] attrs) -> @ast::item {
auto e = parse_expr(p);
auto hi = p.get_hi_pos();
expect(p, token::SEMI);
auto item =
ast::item_const(id, ty, e, attrs, p.next_def_id(), p.get_ann());
ret @spanned(lo, hi, item);
ret mk_item(p, lo, hi, id, ast::item_const(ty, e), attrs);
}
fn parse_item_mod(&parser p, vec[ast::attribute] attrs) -> @ast::item {
@ -1768,8 +1773,7 @@ fn parse_item_mod(&parser p, vec[ast::attribute] attrs) -> @ast::item {
auto m = parse_mod_items(p, token::RBRACE);
auto hi = p.get_hi_pos();
expect(p, token::RBRACE);
auto item = ast::item_mod(id, m, attrs, p.next_def_id());
ret @spanned(lo, hi, item);
ret mk_item(p, lo, hi, id, ast::item_mod(m), attrs);
}
fn parse_item_native_type(&parser p) -> @ast::native_item {
@ -1856,8 +1860,7 @@ fn parse_item_native_mod(&parser p, vec[ast::attribute] attrs) -> @ast::item {
auto m = parse_native_mod_items(p, native_name, abi);
auto hi = p.get_hi_pos();
expect(p, token::RBRACE);
auto item = ast::item_native_mod(id, m, attrs, p.next_def_id());
ret @spanned(lo, hi, item);
ret mk_item(p, lo, hi, id, ast::item_native_mod(m), attrs);
}
fn parse_type_decl(&parser p) -> tup(uint, ast::ident) {
@ -1873,9 +1876,7 @@ fn parse_item_type(&parser p, vec[ast::attribute] attrs) -> @ast::item {
auto ty = parse_ty(p);
auto hi = p.get_hi_pos();
expect(p, token::SEMI);
auto item =
ast::item_ty(t._1, ty, tps, attrs, p.next_def_id(), p.get_ann());
ret @spanned(t._0, hi, item);
ret mk_item(p, t._0, hi, t._1, ast::item_ty(ty, tps), attrs);
}
fn parse_item_tag(&parser p, vec[ast::attribute] attrs) -> @ast::item {
@ -1922,10 +1923,7 @@ fn parse_item_tag(&parser p, vec[ast::attribute] attrs) -> @ast::item {
}
auto hi = p.get_hi_pos();
p.bump();
auto item =
ast::item_tag(id, variants, ty_params, attrs, p.next_def_id(),
p.get_ann());
ret @spanned(lo, hi, item);
ret mk_item(p, lo, hi, id, ast::item_tag(variants, ty_params), attrs);
}
fn parse_layer(&parser p) -> ast::layer {

View File

@ -63,7 +63,7 @@ fn visit_fn(@ctx cx, &ast::_fn f, &vec[ast::ty_param] tp, &span sp,
fn visit_item(@ctx cx, &@ast::item i, &scope sc, &vt[scope] v) {
alt (i.node) {
case (ast::item_obj(_, ?o, _, _, _, _)) {
case (ast::item_obj(?o, _, _)) {
for (ast::obj_field f in o.fields) {
cx.local_map.insert(f.id._1, objfield(f.mut));
}

View File

@ -361,64 +361,65 @@ fn encode_module_item_paths(&ebml::writer ebml_w, &ast::_mod module,
&vec[str] path,
&mutable vec[tup(str, uint)] index) {
for (@ast::item it in module.items) {
if (!ast::is_exported(ast::item_ident(it), module)) { cont; }
if (!ast::is_exported(it.ident, module)) { cont; }
alt (it.node) {
case (ast::item_const(?id, _, ?tps, _, ?did, ?ann)) {
add_to_index(ebml_w, path, index, id);
case (ast::item_const(_, _)) {
add_to_index(ebml_w, path, index, it.ident);
ebml::start_tag(ebml_w, tag_paths_data_item);
encode_name(ebml_w, id);
encode_def_id(ebml_w, did);
encode_name(ebml_w, it.ident);
encode_def_id(ebml_w, it.id);
ebml::end_tag(ebml_w);
}
case (ast::item_fn(?id, _, ?tps, _, ?did, ?ann)) {
add_to_index(ebml_w, path, index, id);
case (ast::item_fn(_, ?tps)) {
add_to_index(ebml_w, path, index, it.ident);
ebml::start_tag(ebml_w, tag_paths_data_item);
encode_name(ebml_w, id);
encode_def_id(ebml_w, did);
encode_name(ebml_w, it.ident);
encode_def_id(ebml_w, it.id);
ebml::end_tag(ebml_w);
}
case (ast::item_mod(?id, ?_mod, _, ?did)) {
add_to_index(ebml_w, path, index, id);
case (ast::item_mod(?_mod)) {
add_to_index(ebml_w, path, index, it.ident);
ebml::start_tag(ebml_w, tag_paths_data_mod);
encode_name(ebml_w, id);
encode_def_id(ebml_w, did);
encode_module_item_paths(ebml_w, _mod, path + [id], index);
encode_name(ebml_w, it.ident);
encode_def_id(ebml_w, it.id);
encode_module_item_paths(ebml_w, _mod, path + [it.ident],
index);
ebml::end_tag(ebml_w);
}
case (ast::item_native_mod(?id, ?nmod, _, ?did)) {
add_to_index(ebml_w, path, index, id);
case (ast::item_native_mod(?nmod)) {
add_to_index(ebml_w, path, index, it.ident);
ebml::start_tag(ebml_w, tag_paths_data_mod);
encode_name(ebml_w, id);
encode_def_id(ebml_w, did);
encode_native_module_item_paths(ebml_w, nmod, path + [id],
index);
encode_name(ebml_w, it.ident);
encode_def_id(ebml_w, it.id);
encode_native_module_item_paths(ebml_w, nmod,
path + [it.ident], index);
ebml::end_tag(ebml_w);
}
case (ast::item_ty(?id, _, ?tps, _, ?did, ?ann)) {
add_to_index(ebml_w, path, index, id);
case (ast::item_ty(_, ?tps)) {
add_to_index(ebml_w, path, index, it.ident);
ebml::start_tag(ebml_w, tag_paths_data_item);
encode_name(ebml_w, id);
encode_def_id(ebml_w, did);
encode_name(ebml_w, it.ident);
encode_def_id(ebml_w, it.id);
ebml::end_tag(ebml_w);
}
case (ast::item_tag(?id, ?variants, ?tps, _, ?did, _)) {
add_to_index(ebml_w, path, index, id);
case (ast::item_tag(?variants, ?tps)) {
add_to_index(ebml_w, path, index, it.ident);
ebml::start_tag(ebml_w, tag_paths_data_item);
encode_name(ebml_w, id);
encode_def_id(ebml_w, did);
encode_name(ebml_w, it.ident);
encode_def_id(ebml_w, it.id);
ebml::end_tag(ebml_w);
encode_tag_variant_paths(ebml_w, variants, path, index);
}
case (ast::item_obj(?id, _, ?tps, _, ?odid, ?ann)) {
add_to_index(ebml_w, path, index, id);
case (ast::item_obj(_, ?tps, ?ctor_id)) {
add_to_index(ebml_w, path, index, it.ident);
ebml::start_tag(ebml_w, tag_paths_data_item);
encode_name(ebml_w, id);
encode_def_id(ebml_w, odid.ctor);
encode_name(ebml_w, it.ident);
encode_def_id(ebml_w, ctor_id);
ebml::end_tag(ebml_w);
add_to_index(ebml_w, path, index, id);
add_to_index(ebml_w, path, index, it.ident);
ebml::start_tag(ebml_w, tag_paths_data_item);
encode_name(ebml_w, id);
encode_def_id(ebml_w, odid.ty);
encode_name(ebml_w, it.ident);
encode_def_id(ebml_w, it.id);
ebml::end_tag(ebml_w);
}
}
@ -509,67 +510,68 @@ fn encode_tag_variant_info(&@trans::crate_ctxt cx, &ebml::writer ebml_w,
fn encode_info_for_item(@trans::crate_ctxt cx, &ebml::writer ebml_w,
@ast::item item, &mutable vec[tup(int, uint)] index) {
alt (item.node) {
case (ast::item_const(_, _, _, _, ?did, ?ann)) {
case (ast::item_const(_, _)) {
ebml::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, did);
encode_def_id(ebml_w, item.id);
encode_kind(ebml_w, 'c' as u8);
encode_type(cx, ebml_w, trans::node_ann_type(cx, ann));
encode_symbol(cx, ebml_w, did);
encode_type(cx, ebml_w, trans::node_ann_type(cx, item.ann));
encode_symbol(cx, ebml_w, item.id);
ebml::end_tag(ebml_w);
}
case (ast::item_fn(_, _, ?tps, _, ?did, ?ann)) {
case (ast::item_fn(_, ?tps)) {
ebml::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, did);
encode_def_id(ebml_w, item.id);
encode_kind(ebml_w, 'f' as u8);
encode_type_param_count(ebml_w, tps);
encode_type(cx, ebml_w, trans::node_ann_type(cx, ann));
encode_symbol(cx, ebml_w, did);
encode_type(cx, ebml_w, trans::node_ann_type(cx, item.ann));
encode_symbol(cx, ebml_w, item.id);
ebml::end_tag(ebml_w);
}
case (ast::item_mod(_, _, _, ?did)) {
case (ast::item_mod(_)) {
ebml::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, did);
encode_def_id(ebml_w, item.id);
encode_kind(ebml_w, 'm' as u8);
ebml::end_tag(ebml_w);
}
case (ast::item_native_mod(?id, _, _, ?did)) {
case (ast::item_native_mod(_)) {
ebml::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, did);
encode_def_id(ebml_w, item.id);
encode_kind(ebml_w, 'n' as u8);
ebml::end_tag(ebml_w);
}
case (ast::item_ty(?id, _, ?tps, _, ?did, ?ann)) {
case (ast::item_ty(_, ?tps)) {
ebml::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, did);
encode_def_id(ebml_w, item.id);
encode_kind(ebml_w, 'y' as u8);
encode_type_param_count(ebml_w, tps);
encode_type(cx, ebml_w, trans::node_ann_type(cx, ann));
encode_type(cx, ebml_w, trans::node_ann_type(cx, item.ann));
ebml::end_tag(ebml_w);
}
case (ast::item_tag(?id, ?variants, ?tps, _, ?did, ?ann)) {
case (ast::item_tag(?variants, ?tps)) {
ebml::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, did);
encode_def_id(ebml_w, item.id);
encode_kind(ebml_w, 't' as u8);
encode_type_param_count(ebml_w, tps);
encode_type(cx, ebml_w, trans::node_ann_type(cx, ann));
encode_type(cx, ebml_w, trans::node_ann_type(cx, item.ann));
for (ast::variant v in variants) {
encode_variant_id(ebml_w, v.node.id);
}
ebml::end_tag(ebml_w);
encode_tag_variant_info(cx, ebml_w, did, variants, index, tps);
encode_tag_variant_info(cx, ebml_w, item.id, variants,
index, tps);
}
case (ast::item_obj(?id, _, ?tps, _, ?odid, ?ann)) {
case (ast::item_obj(_, ?tps, ?ctor_id)) {
ebml::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, odid.ctor);
encode_def_id(ebml_w, ctor_id);
encode_kind(ebml_w, 'o' as u8);
encode_type_param_count(ebml_w, tps);
auto fn_ty = trans::node_ann_type(cx, ann);
auto fn_ty = trans::node_ann_type(cx, item.ann);
encode_type(cx, ebml_w, fn_ty);
encode_symbol(cx, ebml_w, odid.ctor);
encode_symbol(cx, ebml_w, ctor_id);
ebml::end_tag(ebml_w);
index += [tup(odid.ty._1, ebml_w.writer.tell())];
index += [tup(item.id._1, ebml_w.writer.tell())];
ebml::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, odid.ty);
encode_def_id(ebml_w, item.id);
encode_kind(ebml_w, 'y' as u8);
encode_type_param_count(ebml_w, tps);
encode_type(cx, ebml_w, ty::ty_fn_ret(cx.tcx, fn_ty));

View File

@ -176,39 +176,30 @@ fn map_crate(&@env e, &@ast::crate c) {
fn index_i(@env e, &@ast::item i, &scopes sc, &vt[scopes] v) {
visit_item_with_scope(i, sc, v);
alt (i.node) {
case (ast::item_mod(_, ?md, _, ?defid)) {
case (ast::item_mod(?md)) {
auto s = new_str_hash[import_state]();
e.mod_map.insert(defid._1,
e.mod_map.insert(i.id._1,
@rec(m=some(md),
index=index_mod(md),
mutable glob_imports=vec::empty[def](),
glob_imported_names=s));
e.ast_map.insert(defid, i);
e.ast_map.insert(i.id, i);
}
case (ast::item_native_mod(_, ?nmd, _, ?defid)) {
case (ast::item_native_mod(?nmd)) {
auto s = new_str_hash[import_state]();
e.mod_map.insert(defid._1,
e.mod_map.insert(i.id._1,
@rec(m=none[ast::_mod],
index=index_nmod(nmd),
mutable glob_imports=vec::empty[def](),
glob_imported_names=s));
e.ast_map.insert(defid, i);
e.ast_map.insert(i.id, i);
}
case (ast::item_const(_, _, _, _, ?defid, _)) {
e.ast_map.insert(defid, i);
case (ast::item_obj(_, _, ?ctor_id)) {
e.ast_map.insert(i.id, i);
e.ast_map.insert(ctor_id, i);
}
case (ast::item_fn(_, _, _, _, ?defid, _)) {
e.ast_map.insert(defid, i);
}
case (ast::item_ty(_, _, _, _, ?defid, _)) {
e.ast_map.insert(defid, i);
}
case (ast::item_tag(_, _, _, _, ?defid, _)) {
e.ast_map.insert(defid, i);
}
case (ast::item_obj(_, _, _, _, ?obj_def_ids, _)) {
e.ast_map.insert(obj_def_ids.ty, i);
e.ast_map.insert(obj_def_ids.ctor, i);
case (_) {
e.ast_map.insert(i.id, i);
}
}
}
@ -225,11 +216,11 @@ fn map_crate(&@env e, &@ast::crate c) {
alt (sc) {
case (cons(scope_item(?i), ?tl)) {
alt (i.node) {
case (ast::item_mod(_, _, _, ?defid)) {
ret e.mod_map.get(defid._1);
case (ast::item_mod(_)) {
ret e.mod_map.get(i.id._1);
}
case (ast::item_native_mod(_, _, _, ?defid)) {
ret e.mod_map.get(defid._1);
case (ast::item_native_mod(_)) {
ret e.mod_map.get(i.id._1);
}
case (_) { be find_mod(e, *tl); }
}
@ -556,21 +547,21 @@ fn lookup_in_scope(&env e, scopes sc, &span sp, &ident id, namespace ns) ->
}
case (scope_item(?it)) {
alt (it.node) {
case (ast::item_obj(_, ?ob, ?ty_params, _, _, _)) {
case (ast::item_obj(?ob, ?ty_params, _)) {
ret lookup_in_obj(id, ob, ty_params, ns);
}
case (ast::item_tag(_, _, ?ty_params, _, _, _)) {
case (ast::item_tag(_, ?ty_params)) {
if (ns == ns_type) {
ret lookup_in_ty_params(id, ty_params);
}
}
case (ast::item_mod(_, _, _, ?defid)) {
ret lookup_in_local_mod(e, defid, sp, id, ns, inside);
case (ast::item_mod(_)) {
ret lookup_in_local_mod(e, it.id, sp, id, ns, inside);
}
case (ast::item_native_mod(_, ?m, _, ?defid)) {
ret lookup_in_local_native_mod(e, defid, sp, id, ns);
case (ast::item_native_mod(?m)) {
ret lookup_in_local_native_mod(e, it.id, sp, id, ns);
}
case (ast::item_ty(_, _, ?ty_params, _, _, _)) {
case (ast::item_ty(_, ?ty_params)) {
if (ns == ns_type) {
ret lookup_in_ty_params(id, ty_params);
}
@ -702,24 +693,23 @@ fn lookup_in_block(&ident id, &ast::block_ b, namespace ns) ->
}
case (ast::decl_item(?it)) {
alt (it.node) {
case (ast::item_tag(?name, ?variants, _, _,
?defid, _)) {
case (ast::item_tag(?variants, _)) {
if (ns == ns_type) {
if (str::eq(name, id)) {
ret some(ast::def_ty(defid));
if (str::eq(it.ident, id)) {
ret some(ast::def_ty(it.id));
}
} else if (ns == ns_value) {
for (ast::variant v in variants) {
if (str::eq(v.node.name, id)) {
auto i = v.node.id;
ret some(ast::def_variant(defid,
ret some(ast::def_variant(it.id,
i));
}
}
}
}
case (_) {
if (str::eq(ast::item_ident(it), id)) {
if (str::eq(it.ident, id)) {
auto found = found_def_item(it, ns);
if (!option::is_none(found)) {
ret found;
@ -738,28 +728,28 @@ fn lookup_in_block(&ident id, &ast::block_ b, namespace ns) ->
fn found_def_item(&@ast::item i, namespace ns) -> option::t[def] {
alt (i.node) {
case (ast::item_const(_, _, _, _, ?defid, _)) {
if (ns == ns_value) { ret some(ast::def_const(defid)); }
case (ast::item_const(_, _)) {
if (ns == ns_value) { ret some(ast::def_const(i.id)); }
}
case (ast::item_fn(_, _, _, _, ?defid, _)) {
if (ns == ns_value) { ret some(ast::def_fn(defid)); }
case (ast::item_fn(_, _)) {
if (ns == ns_value) { ret some(ast::def_fn(i.id)); }
}
case (ast::item_mod(_, _, _, ?defid)) {
if (ns == ns_module) { ret some(ast::def_mod(defid)); }
case (ast::item_mod(_)) {
if (ns == ns_module) { ret some(ast::def_mod(i.id)); }
}
case (ast::item_native_mod(_, _, _, ?defid)) {
if (ns == ns_module) { ret some(ast::def_native_mod(defid)); }
case (ast::item_native_mod(_)) {
if (ns == ns_module) { ret some(ast::def_native_mod(i.id)); }
}
case (ast::item_ty(_, _, _, _, ?defid, _)) {
if (ns == ns_type) { ret some(ast::def_ty(defid)); }
case (ast::item_ty(_, _)) {
if (ns == ns_type) { ret some(ast::def_ty(i.id)); }
}
case (ast::item_tag(_, _, _, _, ?defid, _)) {
if (ns == ns_type) { ret some(ast::def_ty(defid)); }
case (ast::item_tag(_, _)) {
if (ns == ns_type) { ret some(ast::def_ty(i.id)); }
}
case (ast::item_obj(_, _, _, _, ?odid, _)) {
case (ast::item_obj(_, _, ?ctor_id)) {
alt (ns) {
case (ns_value) { ret some(ast::def_obj(odid.ctor)); }
case (ns_type) { ret some(ast::def_obj(odid.ty)); }
case (ns_value) { ret some(ast::def_obj(ctor_id)); }
case (ns_type) { ret some(ast::def_obj(i.id)); }
case (_) { }
}
}
@ -939,10 +929,10 @@ fn lookup_in_mie(&env e, &mod_index_entry mie, namespace ns) ->
case (mie_item(?item)) { ret found_def_item(item, ns); }
case (mie_tag_variant(?item, ?variant_idx)) {
alt (item.node) {
case (ast::item_tag(_, ?variants, _, _, ?tid, _)) {
case (ast::item_tag(?variants, _)) {
if (ns == ns_value) {
auto vid = variants.(variant_idx).node.id;
ret some(ast::def_variant(tid, vid));
ret some(ast::def_variant(item.id, vid));
} else { ret none[def]; }
}
}
@ -991,23 +981,23 @@ fn index_mod(&ast::_mod md) -> mod_index {
}
for (@ast::item it in md.items) {
alt (it.node) {
case (ast::item_const(?id, _, _, _, _, _)) {
add_to_index(index, id, mie_item(it));
case (ast::item_const(_, _)) {
add_to_index(index, it.ident, mie_item(it));
}
case (ast::item_fn(?id, _, _, _, _, _)) {
add_to_index(index, id, mie_item(it));
case (ast::item_fn(_, _)) {
add_to_index(index, it.ident, mie_item(it));
}
case (ast::item_mod(?id, _, _, _)) {
add_to_index(index, id, mie_item(it));
case (ast::item_mod(_)) {
add_to_index(index, it.ident, mie_item(it));
}
case (ast::item_native_mod(?id, _, _, _)) {
add_to_index(index, id, mie_item(it));
case (ast::item_native_mod(_)) {
add_to_index(index, it.ident, mie_item(it));
}
case (ast::item_ty(?id, _, _, _, _, _)) {
add_to_index(index, id, mie_item(it));
case (ast::item_ty(_, _)) {
add_to_index(index, it.ident, mie_item(it));
}
case (ast::item_tag(?id, ?variants, _, _, _, _)) {
add_to_index(index, id, mie_item(it));
case (ast::item_tag(?variants, _)) {
add_to_index(index, it.ident, mie_item(it));
let uint variant_idx = 0u;
for (ast::variant v in variants) {
add_to_index(index, v.node.name,
@ -1015,8 +1005,8 @@ fn index_mod(&ast::_mod md) -> mod_index {
variant_idx += 1u;
}
}
case (ast::item_obj(?id, _, _, _, _, _)) {
add_to_index(index, id, mie_item(it));
case (ast::item_obj(_, _, _)) {
add_to_index(index, it.ident, mie_item(it));
}
}
}
@ -1143,11 +1133,11 @@ fn mie_span(&mod_index_entry mie) -> span {
fn check_item(@env e, &@ast::item i, &() x, &vt[()] v) {
visit::visit_item(i, x, v);
alt (i.node) {
case (ast::item_fn(_, ?f, ?ty_params, _, _, _)) {
case (ast::item_fn(?f, ?ty_params)) {
check_fn(*e, i.span, f);
ensure_unique(*e, i.span, ty_params, ident_id, "type parameter");
}
case (ast::item_obj(_, ?ob, ?ty_params, _, _, _)) {
case (ast::item_obj(?ob, ?ty_params, _)) {
fn field_name(&ast::obj_field field) -> ident { ret field.ident; }
ensure_unique(*e, i.span, ob.fields, field_name, "object field");
for (@ast::method m in ob.methods) {
@ -1155,7 +1145,7 @@ fn check_item(@env e, &@ast::item i, &() x, &vt[()] v) {
}
ensure_unique(*e, i.span, ty_params, ident_id, "type parameter");
}
case (ast::item_tag(_, _, ?ty_params, _, _, _)) {
case (ast::item_tag(_, ?ty_params)) {
ensure_unique(*e, i.span, ty_params, ident_id, "type parameter");
}
case (_) { }
@ -1190,31 +1180,30 @@ fn check_block(@env e, &ast::block b, &() x, &vt[()] v) {
}
case (ast::decl_item(?it)) {
alt (it.node) {
case (ast::item_tag(?name, ?variants, _, _, _, _))
{
add_name(types, it.span, name);
case (ast::item_tag(?variants, _)) {
add_name(types, it.span, it.ident);
for (ast::variant v in variants) {
add_name(values, v.span, v.node.name);
}
}
case (ast::item_const(?name, _, _, _, _, _)) {
add_name(values, it.span, name);
case (ast::item_const(_, _)) {
add_name(values, it.span, it.ident);
}
case (ast::item_fn(?name, _, _, _, _, _)) {
add_name(values, it.span, name);
case (ast::item_fn(_, _)) {
add_name(values, it.span, it.ident);
}
case (ast::item_mod(?name, _, _, _)) {
add_name(mods, it.span, name);
case (ast::item_mod(_)) {
add_name(mods, it.span, it.ident);
}
case (ast::item_native_mod(?name, _, _, _)) {
add_name(mods, it.span, name);
case (ast::item_native_mod(_)) {
add_name(mods, it.span, it.ident);
}
case (ast::item_ty(?name, _, _, _, _, _)) {
add_name(types, it.span, name);
case (ast::item_ty(_, _)) {
add_name(types, it.span, it.ident);
}
case (ast::item_obj(?name, _, _, _, _, _)) {
add_name(types, it.span, name);
add_name(values, it.span, name);
case (ast::item_obj(_, _, _)) {
add_name(types, it.span, it.ident);
add_name(values, it.span, it.ident);
}
case (_) { }
}

View File

@ -7254,34 +7254,34 @@ fn trans_const(&@crate_ctxt cx, @ast::expr e, &ast::def_id cid,
fn trans_item(@local_ctxt cx, &ast::item item) {
alt (item.node) {
case (ast::item_fn(?name, ?f, ?tps, _, ?fid, ?ann)) {
auto sub_cx = extend_path(cx, name);
auto llfndecl = cx.ccx.item_ids.get(fid);
case (ast::item_fn(?f, ?tps)) {
auto sub_cx = extend_path(cx, item.ident);
auto llfndecl = cx.ccx.item_ids.get(item.id);
trans_fn(sub_cx, item.span, f, llfndecl, none[ty_self_pair], tps,
ann);
item.ann);
}
case (ast::item_obj(?name, ?ob, ?tps, _, ?oid, ?ann)) {
case (ast::item_obj(?ob, ?tps, ?ctor_id)) {
auto sub_cx =
@rec(obj_typarams=tps, obj_fields=ob.fields
with *extend_path(cx, name));
trans_obj(sub_cx, item.span, ob, oid.ctor, tps, ann);
with *extend_path(cx, item.ident));
trans_obj(sub_cx, item.span, ob, ctor_id, tps, item.ann);
}
case (ast::item_mod(?name, ?m, _, _)) {
case (ast::item_mod(?m)) {
auto sub_cx =
@rec(path=cx.path + [name],
module_path=cx.module_path + [name] with *cx);
@rec(path=cx.path + [item.ident],
module_path=cx.module_path + [item.ident] with *cx);
trans_mod(sub_cx, m);
}
case (ast::item_tag(?name, ?variants, ?tps, _, ?tag_id, _)) {
auto sub_cx = extend_path(cx, name);
case (ast::item_tag(?variants, ?tps)) {
auto sub_cx = extend_path(cx, item.ident);
auto i = 0;
for (ast::variant variant in variants) {
trans_tag_variant(sub_cx, tag_id, variant, i, tps);
trans_tag_variant(sub_cx, item.id, variant, i, tps);
i += 1;
}
}
case (ast::item_const(?name, _, ?expr, _, ?cid, ?ann)) {
trans_const(cx.ccx, expr, cid, ann);
case (ast::item_const(_, ?expr)) {
trans_const(cx.ccx, expr, item.id, item.ann);
}
case (_) {/* fall through */ }
}
@ -7545,12 +7545,7 @@ fn decl_native_fn_and_pair(&@crate_ctxt ccx, &span sp, vec[str] path,
}
fn item_path(&@ast::item item) -> vec[str] {
alt (item.node) {
case (ast::item_fn(?name, _, _, _, _, _)) { ret [name]; }
case (ast::item_obj(?name, _, _, _, _, _)) { ret [name]; }
case (ast::item_mod(?name, _, _, _)) { ret [name]; }
case (_) { ret []; }
}
ret [item.ident];
}
fn collect_native_item(@crate_ctxt ccx, &@ast::native_item i, &vec[str] pt,
@ -7572,25 +7567,21 @@ fn collect_item_1(@crate_ctxt ccx, &@ast::item i, &vec[str] pt,
&vt[vec[str]] v) {
visit::visit_item(i, pt + item_path(i), v);
alt (i.node) {
case (ast::item_const(?name, _, _, _, ?cid, ?ann)) {
auto typ = node_ann_type(ccx, ann);
case (ast::item_const(_, _)) {
auto typ = node_ann_type(ccx, i.ann);
auto g =
llvm::LLVMAddGlobal(ccx.llmod, type_of(ccx, i.span, typ),
str::buf(ccx.names.next(name)));
str::buf(ccx.names.next(i.ident)));
llvm::LLVMSetLinkage(g,
lib::llvm::LLVMInternalLinkage as
llvm::Linkage);
ccx.items.insert(cid, i);
ccx.consts.insert(cid, g);
}
case (ast::item_mod(?name, ?m, _, ?mid)) { ccx.items.insert(mid, i); }
case (ast::item_native_mod(_, _, _, ?mid)) {
ccx.items.insert(mid, i);
}
case (ast::item_ty(_, _, _, _, ?did, _)) { ccx.items.insert(did, i); }
case (ast::item_tag(?name, ?variants, ?tps, _, ?tag_id, _)) {
ccx.items.insert(tag_id, i);
ccx.items.insert(i.id, i);
ccx.consts.insert(i.id, g);
}
case (ast::item_mod(?m)) { ccx.items.insert(i.id, i); }
case (ast::item_native_mod(_)) { ccx.items.insert(i.id, i); }
case (ast::item_ty(_, _)) { ccx.items.insert(i.id, i); }
case (ast::item_tag(_, _)) { ccx.items.insert(i.id, i); }
case (_) { }
}
}
@ -7600,16 +7591,16 @@ fn collect_item_2(&@crate_ctxt ccx, &@ast::item i, &vec[str] pt,
auto new_pt = pt + item_path(i);
visit::visit_item(i, new_pt, v);
alt (i.node) {
case (ast::item_fn(?name, ?f, ?tps, _, ?fid, ?ann)) {
ccx.items.insert(fid, i);
if (!ccx.obj_methods.contains_key(fid)) {
decl_fn_and_pair(ccx, i.span, new_pt, "fn", tps, ann, fid);
case (ast::item_fn(?f, ?tps)) {
ccx.items.insert(i.id, i);
if (!ccx.obj_methods.contains_key(i.id)) {
decl_fn_and_pair(ccx, i.span, new_pt, "fn", tps, i.ann, i.id);
}
}
case (ast::item_obj(?name, ?ob, ?tps, _, ?oid, ?ann)) {
ccx.items.insert(oid.ctor, i);
decl_fn_and_pair(ccx, i.span, new_pt, "obj_ctor", tps, ann,
oid.ctor);
case (ast::item_obj(?ob, ?tps, ?ctor_id)) {
ccx.items.insert(ctor_id, i);
decl_fn_and_pair(ccx, i.span, new_pt, "obj_ctor", tps, i.ann,
ctor_id);
for (@ast::method m in ob.methods) {
ccx.obj_methods.insert(m.node.id, ());
}
@ -7634,7 +7625,7 @@ fn collect_tag_ctor(@crate_ctxt ccx, &@ast::item i, &vec[str] pt,
auto new_pt = pt + item_path(i);
visit::visit_item(i, new_pt, v);
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(ccx, i.span,
@ -7661,13 +7652,13 @@ fn trans_constant(@crate_ctxt ccx, &@ast::item it, &vec[str] pt,
auto new_pt = pt + item_path(it);
visit::visit_item(it, new_pt, v);
alt (it.node) {
case (ast::item_tag(?ident, ?variants, _, _, ?tag_id, _)) {
case (ast::item_tag(?variants, _)) {
auto i = 0u;
auto n_variants = vec::len[ast::variant](variants);
while (i < n_variants) {
auto variant = variants.(i);
auto discrim_val = C_int(i as int);
auto p = new_pt + [ident, variant.node.name, "discrim"];
auto p = new_pt + [it.ident, variant.node.name, "discrim"];
auto s = mangle_exported_name(ccx, p, ty::mk_int(ccx.tcx));
auto discrim_gvar =
llvm::LLVMAddGlobal(ccx.llmod, T_int(), str::buf(s));
@ -7678,16 +7669,16 @@ fn trans_constant(@crate_ctxt ccx, &@ast::item it, &vec[str] pt,
i += 1u;
}
}
case (ast::item_const(?name, _, ?expr, _, ?cid, ?ann)) {
case (ast::item_const(_, ?expr)) {
// FIXME: The whole expr-translation system needs cloning to deal
// with consts.
auto v = C_int(1);
ccx.item_ids.insert(cid, v);
ccx.item_ids.insert(it.id, v);
auto s =
mangle_exported_name(ccx, new_pt + [name],
node_ann_type(ccx, ann));
ccx.item_symbols.insert(cid, s);
mangle_exported_name(ccx, new_pt + [it.ident],
node_ann_type(ccx, it.ann));
ccx.item_symbols.insert(it.id, s);
}
case (_) { }
}

View File

@ -61,7 +61,6 @@ import bitvectors::gen;
import front::ast::*;
import middle::ty::expr_ann;
import util::common::new_def_hash;
import util::common::decl_lhs;
import util::common::uistr;
import util::common::log_expr;
import util::common::log_fn;
@ -101,9 +100,8 @@ fn find_pre_post_obj(&crate_ctxt ccx, _obj o) {
fn find_pre_post_item(&crate_ctxt ccx, &item i) {
alt (i.node) {
case (item_const(?id, ?t, ?e, _, ?di, ?a)) {
case (item_const(_, ?e)) {
// make a fake fcx
auto fake_fcx =
rec(enclosing=rec(constrs=@new_def_hash[constraint](),
num_constraints=0u,
@ -113,18 +111,19 @@ fn find_pre_post_item(&crate_ctxt ccx, &item i) {
ccx=ccx);
find_pre_post_expr(fake_fcx, e);
}
case (item_fn(?id, ?f, ?ps, _, ?di, ?a)) {
assert (ccx.fm.contains_key(di));
auto fcx = rec(enclosing=ccx.fm.get(di), id=di, name=id, ccx=ccx);
case (item_fn(?f, ?ps)) {
assert (ccx.fm.contains_key(i.id));
auto fcx = rec(enclosing=ccx.fm.get(i.id), id=i.id,
name=i.ident, ccx=ccx);
find_pre_post_fn(fcx, f);
}
case (item_mod(?id, ?m, _, ?di)) { find_pre_post_mod(m); }
case (item_native_mod(?id, ?nm, _, ?di)) {
case (item_mod(?m)) { find_pre_post_mod(m); }
case (item_native_mod(?nm)) {
find_pre_post_native_mod(nm);
}
case (item_ty(_, _, _, _, _, _)) { ret; }
case (item_tag(_, _, _, _, _, _)) { ret; }
case (item_obj(?id, ?o, ?ps, _, ?di, ?a)) {
case (item_ty(_, _)) { ret; }
case (item_tag(_, _)) { ret; }
case (item_obj(?o, _, _)) {
find_pre_post_obj(ccx, o);
}
}

View File

@ -66,7 +66,6 @@ import middle::ty::expr_ty;
import middle::ty::type_is_nil;
import middle::ty::type_is_bot;
import util::common::new_def_hash;
import util::common::decl_lhs;
import util::common::uistr;
import util::common::log_expr;
import util::common::log_block;

View File

@ -1507,26 +1507,6 @@ fn pat_ty(&ctxt cx, &@ast::pat pat) -> t {
ret ann_to_monotype(cx, pat_ann(pat));
}
fn item_ann(&@ast::item it) -> ast::ann {
alt (it.node) {
case (ast::item_const(_, _, _, _, _, ?a)) { ret a; }
case (ast::item_fn(_, _, _, _, _, ?a)) { ret a; }
case (ast::item_mod(_, _, _, _)) {
log_err "a module was passed to item_ann(), " +
"but modules haven't annotations";
fail;
}
case (ast::item_native_mod(_, _, _, _)) {
log_err "a native module was passed to item_ann(), " +
"but native modules haven't annotations";
fail;
}
case (ast::item_ty(_, _, _, _, _, ?a)) { ret a; }
case (ast::item_tag(_, _, _, _, _, ?a)) { ret a; }
case (ast::item_obj(_, _, _, _, _, ?a)) { ret a; }
}
}
fn expr_ann(&@ast::expr e) -> ast::ann {
alt (e.node) {
case (ast::expr_vec(_, _, _, ?a)) { ret a; }
@ -2441,7 +2421,7 @@ fn tag_variants(&ctxt cx, &ast::def_id id) -> vec[variant_info] {
alt (cx.items.get(id)) {
case (any_item_rust(?item)) {
alt (item.node) {
case (ast::item_tag(_, ?variants, _, _, _, _)) {
case (ast::item_tag(?variants, _)) {
let vec[variant_info] result = [];
for (ast::variant variant in variants) {
auto ctor_ty = ann_to_monotype(cx, variant.node.ann);

View File

@ -559,24 +559,24 @@ mod collect {
auto get = bind getter(cx, _);
auto convert = bind ast_ty_to_ty(cx.tcx, get, _);
alt (it.node) {
case (ast::item_const(?ident, ?t, _, _, ?def_id, _)) {
case (ast::item_const(?t, _)) {
auto typ = convert(t);
auto tpt = tup(0u, typ);
cx.tcx.tcache.insert(def_id, tpt);
cx.tcx.tcache.insert(it.id, tpt);
ret tpt;
}
case (ast::item_fn(?ident, ?fn_info, ?tps, _, ?def_id, _)) {
case (ast::item_fn(?fn_info, ?tps)) {
auto f = bind ty_of_arg(cx, _);
ret ty_of_fn_decl(cx, convert, f, fn_info.decl, fn_info.proto,
tps, some(def_id));
tps, some(it.id));
}
case (ast::item_obj(?ident, ?obj_info, ?tps, _, ?odid, _)) {
auto t_obj = ty_of_obj(cx, ident, obj_info, tps);
cx.tcx.tcache.insert(odid.ty, t_obj);
case (ast::item_obj(?obj_info, ?tps, _)) {
auto t_obj = ty_of_obj(cx, it.ident, obj_info, tps);
cx.tcx.tcache.insert(it.id, t_obj);
ret t_obj;
}
case (ast::item_ty(?ident, ?t, ?tps, _, ?def_id, _)) {
alt (cx.tcx.tcache.find(def_id)) {
case (ast::item_ty(?t, ?tps)) {
alt (cx.tcx.tcache.find(it.id)) {
case (some(?tpt)) { ret tpt; }
case (none) { }
}
@ -586,10 +586,10 @@ mod collect {
auto typ = convert(t);
auto ty_param_count = vec::len[ast::ty_param](tps);
auto tpt = tup(ty_param_count, typ);
cx.tcx.tcache.insert(def_id, tpt);
cx.tcx.tcache.insert(it.id, tpt);
ret tpt;
}
case (ast::item_tag(_, _, ?tps, _, ?def_id, _)) {
case (ast::item_tag(_, ?tps)) {
// Create a new generic polytype.
let vec[ty::t] subtys = [];
@ -598,28 +598,27 @@ mod collect {
subtys += [ty::mk_param(cx.tcx, i)];
i += 1u;
}
auto t = ty::mk_tag(cx.tcx, def_id, subtys);
auto t = ty::mk_tag(cx.tcx, it.id, subtys);
auto ty_param_count = vec::len[ast::ty_param](tps);
auto tpt = tup(ty_param_count, t);
cx.tcx.tcache.insert(def_id, tpt);
cx.tcx.tcache.insert(it.id, tpt);
ret tpt;
}
case (ast::item_mod(_, _, _, _)) { fail; }
case (ast::item_native_mod(_, _, _, _)) { fail; }
case (ast::item_mod(_)) { fail; }
case (ast::item_native_mod(_)) { fail; }
}
}
fn ty_of_native_item(&@ctxt cx, &@ast::native_item it,
ast::native_abi abi) -> ty::ty_param_count_and_ty {
alt (it.node) {
case (ast::native_item_fn(?ident, ?lname, ?fn_decl, ?params,
?def_id, _)) {
case (ast::native_item_fn(_, _, ?fn_decl, ?params, ?did, _)) {
auto get = bind getter(cx, _);
auto convert = bind ast_ty_to_ty(cx.tcx, get, _);
auto f = bind ty_of_arg(cx, _);
ret ty_of_native_fn_decl(cx, convert, f, fn_decl, abi, params,
def_id);
did);
}
case (ast::native_item_ty(_, ?def_id)) {
case (ast::native_item_ty(?tpt, ?def_id)) {
alt (cx.tcx.tcache.find(def_id)) {
case (some(?tpt)) { ret tpt; }
case (none) { }
@ -676,14 +675,14 @@ mod collect {
}
fn collect(ty::item_table id_to_ty_item, &@ast::item i) {
alt (i.node) {
case (ast::item_ty(_, _, _, _, ?def_id, _)) {
id_to_ty_item.insert(def_id, ty::any_item_rust(i));
case (ast::item_ty(_, _)) {
id_to_ty_item.insert(i.id, ty::any_item_rust(i));
}
case (ast::item_tag(_, _, _, _, ?def_id, _)) {
id_to_ty_item.insert(def_id, ty::any_item_rust(i));
case (ast::item_tag(_, _)) {
id_to_ty_item.insert(i.id, ty::any_item_rust(i));
}
case (ast::item_obj(_, _, _, _, ?odid, _)) {
id_to_ty_item.insert(odid.ty, ty::any_item_rust(i));
case (ast::item_obj(_, _, _)) {
id_to_ty_item.insert(i.id, ty::any_item_rust(i));
}
case (_) {/* empty */ }
}
@ -702,23 +701,22 @@ mod collect {
fn convert(@ctxt cx, @mutable option::t[ast::native_abi] abi,
&@ast::item it) {
alt (it.node) {
case (ast::item_mod(_, _, _, _)) {
case (ast::item_mod(_)) {
// ignore item_mod, it has no type.
}
case (ast::item_native_mod(_, ?native_mod, _, _)) {
case (ast::item_native_mod(?native_mod)) {
// Propagate the native ABI down to convert_native() below,
// but otherwise do nothing, as native modules have no types.
*abi = some[ast::native_abi](native_mod.abi);
}
case (ast::item_tag(_, ?variants, ?ty_params, _, ?tag_id, ?ann)) {
case (ast::item_tag(?variants, ?ty_params)) {
auto tpt = ty_of_item(cx, it);
write::ty_only(cx.tcx, ann.id, tpt._1);
get_tag_variant_types(cx, tag_id, variants, ty_params);
write::ty_only(cx.tcx, it.ann.id, tpt._1);
get_tag_variant_types(cx, it.id, variants, ty_params);
}
case (ast::item_obj(?ident, ?object, ?ty_params, _, ?odid, ?ann))
{
case (ast::item_obj(?object, ?ty_params, ?ctor_id)) {
// This calls ty_of_obj().
auto t_obj = ty_of_item(cx, it);
@ -726,8 +724,8 @@ mod collect {
// we write into the table for this item.
auto tpt =
ty_of_obj_ctor(cx, ident, object, odid.ctor, ty_params);
write::ty_only(cx.tcx, ann.id, tpt._1);
ty_of_obj_ctor(cx, it.ident, object, ctor_id, ty_params);
write::ty_only(cx.tcx, it.ann.id, tpt._1);
// Write the methods into the type table.
//
// FIXME: Inefficient; this ends up calling
@ -771,7 +769,7 @@ mod collect {
// it into the node type table.
auto tpt = ty_of_item(cx, it);
write::ty_only(cx.tcx, ty::item_ann(it).id, tpt._1);
write::ty_only(cx.tcx, it.ann.id, tpt._1);
}
}
}
@ -788,8 +786,8 @@ mod collect {
// FIXME: Native types have no annotation. Should they? --pcw
}
case (ast::native_item_fn(_, _, _, _, _, ?a)) {
write::ty_only(cx.tcx, a.id, tpt._1);
case (ast::native_item_fn(_, _, _, _, _, ?ann)) {
write::ty_only(cx.tcx, ann.id, tpt._1);
}
}
}
@ -2327,18 +2325,17 @@ fn check_method(&@crate_ctxt ccx, &@ast::method method) {
fn check_item(@crate_ctxt ccx, &@ast::item it) {
alt (it.node) {
case (ast::item_const(_, _, ?e, _, _, ?a)) {
check_const(ccx, it.span, e, a);
case (ast::item_const(_, ?e)) {
check_const(ccx, it.span, e, it.ann);
}
case (ast::item_fn(_, ?f, _, _, _, ?a)) {
check_fn(ccx, f.decl, f.proto, f.body, a);
case (ast::item_fn(?f, _)) {
check_fn(ccx, f.decl, f.proto, f.body, it.ann);
}
case (ast::item_obj(_, ?ob, _, _, ?obj_def_ids, _)) {
case (ast::item_obj(?ob, _, _)) {
// We're entering an object, so gather up the info we need.
let ast::def_id di = obj_def_ids.ty;
vec::push[obj_info](ccx.obj_infos,
rec(obj_fields=ob.fields, this_obj=di));
rec(obj_fields=ob.fields, this_obj=it.id));
// Typecheck the methods.
for (@ast::method method in ob.methods) {
@ -2357,8 +2354,8 @@ fn mk_fn_purity_table(&@ast::crate crate) -> @fn_purity_table {
auto res = @new_def_hash[ast::purity]();
fn do_one(@fn_purity_table t, &@ast::item i) {
alt (i.node) {
case (ast::item_fn(_, ?f, _, _, ?d_id, _)) {
t.insert(d_id, f.decl.purity);
case (ast::item_fn(?f, _)) {
t.insert(i.id, f.decl.purity);
}
case (_) { }
}

View File

@ -99,15 +99,15 @@ fn visit_local[E](&@local loc, &E e, &vt[E] v) {
fn visit_item[E](&@item i, &E e, &vt[E] v) {
alt (i.node) {
case (item_const(_, ?t, ?ex, _, _, _)) {
case (item_const(?t, ?ex)) {
vt(v).visit_ty(t, e, v);
vt(v).visit_expr(ex, e, v);
}
case (item_fn(?nm, ?f, ?tp, _, ?d, ?a)) {
vt(v).visit_fn(f, tp, i.span, nm, d, a, e, v);
case (item_fn(?f, ?tp)) {
vt(v).visit_fn(f, tp, i.span, i.ident, i.id, i.ann, e, v);
}
case (item_mod(_, ?m, _, _)) { vt(v).visit_mod(m, i.span, e, v); }
case (item_native_mod(_, ?nm, _, _)) {
case (item_mod(?m)) { vt(v).visit_mod(m, i.span, e, v); }
case (item_native_mod(?nm)) {
for (@view_item vi in nm.view_items) {
vt(v).visit_view_item(vi, e, v);
}
@ -115,15 +115,15 @@ fn visit_item[E](&@item i, &E e, &vt[E] v) {
vt(v).visit_native_item(ni, e, v);
}
}
case (item_ty(_, ?t, _, _, _, _)) { vt(v).visit_ty(t, e, v); }
case (item_tag(_, ?variants, _, _, _, _)) {
case (item_ty(?t, _)) { vt(v).visit_ty(t, e, v); }
case (item_tag(?variants, _)) {
for (variant vr in variants) {
for (variant_arg va in vr.node.args) {
vt(v).visit_ty(va.ty, e, v);
}
}
}
case (item_obj(_, ?ob, _, _, _, _)) {
case (item_obj(?ob, _, _)) {
for (obj_field f in ob.fields) { vt(v).visit_ty(f.ty, e, v); }
for (@method m in ob.methods) {
vt(v).visit_fn(m.node.meth, [], m.span, m.node.ident,

View File

@ -103,24 +103,24 @@ fn walk_item(&ast_visitor v, @ast::item i) {
if (!v.keep_going()) { ret; }
v.visit_item_pre(i);
alt (i.node) {
case (ast::item_const(_, ?t, ?e, _, _, _)) {
case (ast::item_const(?t, ?e)) {
walk_ty(v, t);
walk_expr(v, e);
}
case (ast::item_fn(?nm, ?f, _, _, ?d, ?a)) {
walk_fn(v, f, i.span, nm, d, a);
case (ast::item_fn(?f, _)) {
walk_fn(v, f, i.span, i.ident, i.id, i.ann);
}
case (ast::item_mod(_, ?m, _, _)) { walk_mod(v, m); }
case (ast::item_native_mod(_, ?nm, _, _)) { walk_native_mod(v, nm); }
case (ast::item_ty(_, ?t, _, _, _, _)) { walk_ty(v, t); }
case (ast::item_tag(_, ?variants, _, _, _, _)) {
case (ast::item_mod(?m)) { walk_mod(v, m); }
case (ast::item_native_mod(?nm)) { walk_native_mod(v, nm); }
case (ast::item_ty(?t, _)) { walk_ty(v, t); }
case (ast::item_tag(?variants, _)) {
for (ast::variant vr in variants) {
for (ast::variant_arg va in vr.node.args) {
walk_ty(v, va.ty);
}
}
}
case (ast::item_obj(_, ?ob, _, _, _, _)) {
case (ast::item_obj(?ob, _, _)) {
for (ast::obj_field f in ob.fields) { walk_ty(v, f.ty); }
for (@ast::method m in ob.methods) {
v.visit_method_pre(m);

View File

@ -259,12 +259,12 @@ fn print_item(&ps s, &@ast::item item) {
hardbreak(s.s);
maybe_print_comment(s, item.span.lo);
alt (item.node) {
case (ast::item_const(?id, ?ty, ?expr, ?attrs, _, _)) {
print_outer_attributes(s, attrs);
case (ast::item_const(?ty, ?expr)) {
print_outer_attributes(s, item.attrs);
head(s, "const");
print_type(s, *ty);
space(s.s);
word_space(s, id);
word_space(s, item.ident);
end(s); // end the head-ibox
word_space(s, "=");
@ -273,22 +273,22 @@ fn print_item(&ps s, &@ast::item item) {
end(s); // end the outer cbox
}
case (ast::item_fn(?name, ?_fn, ?typarams, ?attrs, _, _)) {
print_outer_attributes(s, attrs);
print_fn(s, _fn.decl, _fn.proto, name, typarams);
case (ast::item_fn(?_fn, ?typarams)) {
print_outer_attributes(s, item.attrs);
print_fn(s, _fn.decl, _fn.proto, item.ident, typarams);
word(s.s, " ");
print_block(s, _fn.body);
}
case (ast::item_mod(?id, ?_mod, ?attrs, _)) {
print_outer_attributes(s, attrs);
case (ast::item_mod(?_mod)) {
print_outer_attributes(s, item.attrs);
head(s, "mod");
word_nbsp(s, id);
word_nbsp(s, item.ident);
bopen(s);
for (@ast::item itm in _mod.items) { print_item(s, itm); }
bclose(s, item.span);
}
case (ast::item_native_mod(?id, ?nmod, ?attrs, _)) {
print_outer_attributes(s, attrs);
case (ast::item_native_mod(?nmod)) {
print_outer_attributes(s, item.attrs);
head(s, "native");
alt (nmod.abi) {
case (ast::native_abi_rust) { word_nbsp(s, "\"rust\""); }
@ -298,7 +298,7 @@ fn print_item(&ps s, &@ast::item item) {
}
}
word_nbsp(s, "mod");
word_nbsp(s, id);
word_nbsp(s, item.ident);
bopen(s);
for (@ast::native_item item in nmod.items) {
hardbreak(s.s);
@ -331,12 +331,12 @@ fn print_item(&ps s, &@ast::item item) {
}
bclose(s, item.span);
}
case (ast::item_ty(?id, ?ty, ?params, ?attrs, _, _)) {
print_outer_attributes(s, attrs);
case (ast::item_ty(?ty, ?params)) {
print_outer_attributes(s, item.attrs);
ibox(s, indent_unit);
ibox(s, 0u);
word_nbsp(s, "type");
word(s.s, id);
word(s.s, item.ident);
print_type_params(s, params);
end(s); // end the inner ibox
@ -348,10 +348,10 @@ fn print_item(&ps s, &@ast::item item) {
break_offset(s.s, 0u, 0);
}
case (ast::item_tag(?id, ?variants, ?params, ?attrs, _, _)) {
print_outer_attributes(s, attrs);
case (ast::item_tag(?variants, ?params)) {
print_outer_attributes(s, item.attrs);
head(s, "tag");
word(s.s, id);
word(s.s, item.ident);
print_type_params(s, params);
space(s.s);
bopen(s);
@ -372,10 +372,10 @@ fn print_item(&ps s, &@ast::item item) {
}
bclose(s, item.span);
}
case (ast::item_obj(?id, ?_obj, ?params, ?attrs, _, _)) {
print_outer_attributes(s, attrs);
case (ast::item_obj(?_obj, ?params, _)) {
print_outer_attributes(s, item.attrs);
head(s, "obj");
word(s.s, id);
word(s.s, item.ident);
print_type_params(s, params);
popen(s);
fn print_field(&ps s, &ast::obj_field field) {
@ -415,7 +415,7 @@ fn print_item(&ps s, &@ast::item item) {
alt (s.mode) {
case (mo_identified) {
space(s.s);
synth_comment(s, uint::to_str(ty::item_ann(item).id, 10u));
synth_comment(s, uint::to_str(item.ann.id, 10u));
}
case (_) {/* no-op */ }
}

View File

@ -148,26 +148,6 @@ fn log_stmt(&ast::stmt st) { log pretty::pprust::stmt_to_str(st); }
fn log_stmt_err(&ast::stmt st) { log_err pretty::pprust::stmt_to_str(st); }
fn decl_lhs(@ast::decl d) -> ast::def_id {
alt (d.node) {
case (ast::decl_local(?l)) { ret l.id; }
case (ast::decl_item(?an_item)) {
alt (an_item.node) {
case (ast::item_const(_, _, _, _, ?d, _)) { ret d; }
case (ast::item_fn(_, _, _, _, ?d, _)) { ret d; }
case (ast::item_mod(_, _, _, ?d)) { ret d; }
case (ast::item_native_mod(_, _, _, ?d)) { ret d; }
case (ast::item_ty(_, _, _, _, ?d, _)) { ret d; }
case (ast::item_tag(_, _, _, _, ?d, _)) { ret d; }
case (ast::item_obj(_, _, _, _, ?d, _)) {
ret d.ctor; /* This doesn't really make sense */
}
}
}
}
}
fn has_nonlocal_exits(&ast::block b) -> bool {
auto has_exits = @mutable false;
fn visit_expr(@mutable bool flag, &@ast::expr e) {