Move names and ids of native items into their recs, rather than their tags
This commit is contained in:
parent
26d8eaefa7
commit
3b6d94d489
@ -484,15 +484,14 @@ tag item_ {
|
||||
item_obj(_obj, vec[ty_param], node_id /* constructor id */);
|
||||
}
|
||||
|
||||
type native_item = spanned[native_item_];
|
||||
type native_item = rec(ident ident,
|
||||
native_item_ node,
|
||||
node_id id,
|
||||
span span);
|
||||
|
||||
tag native_item_ {
|
||||
native_item_ty(ident, node_id);
|
||||
native_item_fn(ident,
|
||||
option::t[str],
|
||||
fn_decl,
|
||||
vec[ty_param],
|
||||
node_id);
|
||||
native_item_ty;
|
||||
native_item_fn(option::t[str], fn_decl, vec[ty_param]);
|
||||
}
|
||||
|
||||
fn is_exported(ident i, _mod m) -> bool {
|
||||
|
@ -1841,8 +1841,10 @@ fn parse_item_native_type(&parser p) -> @ast::native_item {
|
||||
auto t = parse_type_decl(p);
|
||||
auto hi = p.get_hi_pos();
|
||||
expect(p, token::SEMI);
|
||||
auto item = ast::native_item_ty(t._1, p.get_id());
|
||||
ret @spanned(t._0, hi, item);
|
||||
ret @rec(ident=t._1,
|
||||
node=ast::native_item_ty,
|
||||
id=p.get_id(),
|
||||
span=rec(lo=t._0, hi=hi));
|
||||
}
|
||||
|
||||
fn parse_item_native_fn(&parser p) -> @ast::native_item {
|
||||
@ -1856,9 +1858,10 @@ fn parse_item_native_fn(&parser p) -> @ast::native_item {
|
||||
}
|
||||
auto hi = p.get_hi_pos();
|
||||
expect(p, token::SEMI);
|
||||
auto item =
|
||||
ast::native_item_fn(t._0, link_name, decl, t._1, p.get_id());
|
||||
ret @spanned(lo, hi, item);
|
||||
ret @rec(ident=t._0,
|
||||
node=ast::native_item_fn(link_name, decl, t._1),
|
||||
id=p.get_id(),
|
||||
span=rec(lo=lo, hi=hi));
|
||||
}
|
||||
|
||||
fn parse_native_item(&parser p) -> @ast::native_item {
|
||||
|
@ -33,11 +33,7 @@ fn map_item(&map map, &@item i, &() e, &vt[()] v) {
|
||||
}
|
||||
|
||||
fn map_native_item(&map map, &@native_item i, &() e, &vt[()] v) {
|
||||
auto id = alt (i.node) {
|
||||
case (native_item_ty(_, ?id)) { id }
|
||||
case (native_item_fn(_, _, _, _, ?id)) { id }
|
||||
};
|
||||
map.insert(id, node_native_item(i));
|
||||
map.insert(i.id, node_native_item(i));
|
||||
visit::visit_native_item(i, e, v);
|
||||
}
|
||||
|
||||
|
@ -337,22 +337,11 @@ fn encode_native_module_item_paths(&ebml::writer ebml_w,
|
||||
&native_mod nmod, &vec[str] path,
|
||||
&mutable vec[tup(str, uint)] index) {
|
||||
for (@native_item nitem in nmod.items) {
|
||||
alt (nitem.node) {
|
||||
case (native_item_ty(?ident, ?id)) {
|
||||
add_to_index(ebml_w, path, index, ident);
|
||||
ebml::start_tag(ebml_w, tag_paths_data_item);
|
||||
encode_name(ebml_w, ident);
|
||||
encode_def_id(ebml_w, local_def(id));
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
case (native_item_fn(?ident, _, _, _, ?id)) {
|
||||
add_to_index(ebml_w, path, index, ident);
|
||||
ebml::start_tag(ebml_w, tag_paths_data_item);
|
||||
encode_name(ebml_w, ident);
|
||||
encode_def_id(ebml_w, local_def(id));
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
}
|
||||
add_to_index(ebml_w, path, index, nitem.ident);
|
||||
ebml::start_tag(ebml_w, tag_paths_data_item);
|
||||
encode_name(ebml_w, nitem.ident);
|
||||
encode_def_id(ebml_w, local_def(nitem.id));
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
}
|
||||
|
||||
@ -583,17 +572,17 @@ fn encode_info_for_native_item(&@trans::crate_ctxt cx, &ebml::writer ebml_w,
|
||||
&@native_item nitem) {
|
||||
ebml::start_tag(ebml_w, tag_items_data_item);
|
||||
alt (nitem.node) {
|
||||
case (native_item_ty(_, ?id)) {
|
||||
encode_def_id(ebml_w, local_def(id));
|
||||
case (native_item_ty) {
|
||||
encode_def_id(ebml_w, local_def(nitem.id));
|
||||
encode_kind(ebml_w, 'T' as u8);
|
||||
encode_type(cx, ebml_w, ty::mk_native(cx.tcx));
|
||||
}
|
||||
case (native_item_fn(_, _, _, ?tps, ?id)) {
|
||||
encode_def_id(ebml_w, local_def(id));
|
||||
case (native_item_fn(_, _, ?tps)) {
|
||||
encode_def_id(ebml_w, local_def(nitem.id));
|
||||
encode_kind(ebml_w, 'F' as u8);
|
||||
encode_type_param_count(ebml_w, tps);
|
||||
encode_type(cx, ebml_w, trans::node_id_type(cx, id));
|
||||
encode_symbol(cx, ebml_w, id);
|
||||
encode_type(cx, ebml_w, trans::node_id_type(cx, nitem.id));
|
||||
encode_symbol(cx, ebml_w, nitem.id);
|
||||
}
|
||||
}
|
||||
ebml::end_tag(ebml_w);
|
||||
|
@ -630,7 +630,7 @@ fn lookup_in_scope(&env e, scopes sc, &span sp, &ident name, namespace ns) ->
|
||||
}
|
||||
case (scope_native_item(?it)) {
|
||||
alt (it.node) {
|
||||
case (ast::native_item_fn(_, _, ?decl, ?ty_params, _))
|
||||
case (ast::native_item_fn(_, ?decl, ?ty_params))
|
||||
{
|
||||
ret lookup_in_fn(name, decl, ty_params, ns);
|
||||
}
|
||||
@ -1021,14 +1021,16 @@ fn lookup_in_mie(&env e, &mod_index_entry mie, namespace ns) ->
|
||||
}
|
||||
case (mie_native_item(?native_item)) {
|
||||
alt (native_item.node) {
|
||||
case (ast::native_item_ty(_, ?id)) {
|
||||
case (ast::native_item_ty) {
|
||||
if (ns == ns_type) {
|
||||
ret some(ast::def_native_ty(local_def(id)));
|
||||
ret some(ast::def_native_ty
|
||||
(local_def(native_item.id)));
|
||||
}
|
||||
}
|
||||
case (ast::native_item_fn(_, _, _, _, ?id)) {
|
||||
case (ast::native_item_fn(_, _, _)) {
|
||||
if (ns == ns_value) {
|
||||
ret some(ast::def_native_fn(local_def(id)));
|
||||
ret some(ast::def_native_fn
|
||||
(local_def(native_item.id)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1111,14 +1113,7 @@ fn index_nmod(&ast::native_mod md) -> mod_index {
|
||||
}
|
||||
}
|
||||
for (@ast::native_item it in md.items) {
|
||||
alt (it.node) {
|
||||
case (ast::native_item_ty(?ident, _)) {
|
||||
add_to_index(index, ident, mie_native_item(it));
|
||||
}
|
||||
case (ast::native_item_fn(?ident, _, _, _, _)) {
|
||||
add_to_index(index, ident, mie_native_item(it));
|
||||
}
|
||||
}
|
||||
add_to_index(index, it.ident, mie_native_item(it));
|
||||
}
|
||||
ret index;
|
||||
}
|
||||
|
@ -7780,11 +7780,11 @@ fn native_fn_ty_param_count(&@crate_ctxt cx, ast::node_id id) -> uint {
|
||||
case (ast_map::node_native_item(?i)) { i }
|
||||
};
|
||||
alt (native_item.node) {
|
||||
case (ast::native_item_ty(_, _)) {
|
||||
case (ast::native_item_ty) {
|
||||
cx.sess.bug("decl_native_fn_and_pair(): native fn isn't " +
|
||||
"actually a fn");
|
||||
}
|
||||
case (ast::native_item_fn(_, _, _, ?tps, _)) {
|
||||
case (ast::native_item_fn(_, _, ?tps)) {
|
||||
count = vec::len[ast::ty_param](tps);
|
||||
}
|
||||
}
|
||||
@ -7961,9 +7961,9 @@ fn item_path(&@ast::item item) -> vec[str] { ret [item.ident]; }
|
||||
fn collect_native_item(@crate_ctxt ccx, &@ast::native_item i, &vec[str] pt,
|
||||
&vt[vec[str]] v) {
|
||||
alt (i.node) {
|
||||
case (ast::native_item_fn(?name, _, _, _, ?id)) {
|
||||
if (!ccx.obj_methods.contains_key(id)) {
|
||||
decl_native_fn_and_pair(ccx, i.span, pt, name, id);
|
||||
case (ast::native_item_fn(_, _, _)) {
|
||||
if (!ccx.obj_methods.contains_key(i.id)) {
|
||||
decl_native_fn_and_pair(ccx, i.span, pt, i.ident, i.id);
|
||||
}
|
||||
}
|
||||
case (_) {}
|
||||
|
@ -610,21 +610,21 @@ mod collect {
|
||||
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(_, _, ?fn_decl, ?params, ?id)) {
|
||||
case (ast::native_item_fn(_, ?fn_decl, ?params)) {
|
||||
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,
|
||||
ast::local_def(id));
|
||||
ast::local_def(it.id));
|
||||
}
|
||||
case (ast::native_item_ty(?tpt, ?id)) {
|
||||
alt (cx.tcx.tcache.find(local_def(id))) {
|
||||
case (ast::native_item_ty) {
|
||||
alt (cx.tcx.tcache.find(local_def(it.id))) {
|
||||
case (some(?tpt)) { ret tpt; }
|
||||
case (none) { }
|
||||
}
|
||||
auto t = ty::mk_native(cx.tcx);
|
||||
auto tpt = tup(0u, t);
|
||||
cx.tcx.tcache.insert(local_def(id), tpt);
|
||||
cx.tcx.tcache.insert(local_def(it.id), tpt);
|
||||
ret tpt;
|
||||
}
|
||||
}
|
||||
@ -757,12 +757,12 @@ mod collect {
|
||||
auto tpt =
|
||||
ty_of_native_item(cx, i, option::get[ast::native_abi]({ *abi }));
|
||||
alt (i.node) {
|
||||
case (ast::native_item_ty(_, _)) {
|
||||
case (ast::native_item_ty) {
|
||||
// FIXME: Native types have no annotation. Should they? --pcw
|
||||
|
||||
}
|
||||
case (ast::native_item_fn(_, _, _, _, ?id)) {
|
||||
write::ty_only(cx.tcx, id, tpt._1);
|
||||
case (ast::native_item_fn(_, _, _)) {
|
||||
write::ty_only(cx.tcx, i.id, tpt._1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -202,8 +202,8 @@ fn visit_pat[E](&@pat p, &E e, &vt[E] v) {
|
||||
|
||||
fn visit_native_item[E](&@native_item ni, &E e, &vt[E] v) {
|
||||
alt (ni.node) {
|
||||
case (native_item_fn(_, _, ?fd, _, _)) { visit_fn_decl(fd, e, v); }
|
||||
case (native_item_ty(_, _)) { }
|
||||
case (native_item_fn(_, ?fd, _)) { visit_fn_decl(fd, e, v); }
|
||||
case (native_item_ty) { }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -203,10 +203,10 @@ fn walk_native_item(&ast_visitor v, @ast::native_item ni) {
|
||||
if (!v.keep_going()) { ret; }
|
||||
v.visit_native_item_pre(ni);
|
||||
alt (ni.node) {
|
||||
case (ast::native_item_fn(_, _, ?fd, _, _)) {
|
||||
case (ast::native_item_fn(_, ?fd, _)) {
|
||||
walk_fn_decl(v, fd);
|
||||
}
|
||||
case (ast::native_item_ty(_, _)) { }
|
||||
case (ast::native_item_ty) { }
|
||||
}
|
||||
v.visit_native_item_post(ni);
|
||||
}
|
||||
|
@ -320,13 +320,13 @@ fn print_item(&ps s, &@ast::item item) {
|
||||
ibox(s, indent_unit);
|
||||
maybe_print_comment(s, item.span.lo);
|
||||
alt (item.node) {
|
||||
case (ast::native_item_ty(?id, _)) {
|
||||
case (ast::native_item_ty) {
|
||||
word_nbsp(s, "type");
|
||||
word(s.s, id);
|
||||
word(s.s, item.ident);
|
||||
}
|
||||
case (ast::native_item_fn(?id, ?lname, ?decl,
|
||||
?typarams, _)) {
|
||||
print_fn(s, decl, ast::proto_fn, id, typarams);
|
||||
case (ast::native_item_fn(?lname, ?decl, ?typarams)) {
|
||||
print_fn(s, decl, ast::proto_fn, item.ident,
|
||||
typarams);
|
||||
alt (lname) {
|
||||
case (none) { }
|
||||
case (some(?ss)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user