Skip to content

Commit 3b6d94d

Browse files
committed
Move names and ids of native items into their recs, rather than their tags
1 parent 26d8eae commit 3b6d94d

File tree

10 files changed

+56
-74
lines changed

10 files changed

+56
-74
lines changed

src/comp/front/ast.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -484,15 +484,14 @@ tag item_ {
484484
item_obj(_obj, vec[ty_param], node_id /* constructor id */);
485485
}
486486

487-
type native_item = spanned[native_item_];
487+
type native_item = rec(ident ident,
488+
native_item_ node,
489+
node_id id,
490+
span span);
488491

489492
tag native_item_ {
490-
native_item_ty(ident, node_id);
491-
native_item_fn(ident,
492-
option::t[str],
493-
fn_decl,
494-
vec[ty_param],
495-
node_id);
493+
native_item_ty;
494+
native_item_fn(option::t[str], fn_decl, vec[ty_param]);
496495
}
497496

498497
fn is_exported(ident i, _mod m) -> bool {

src/comp/front/parser.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,8 +1841,10 @@ fn parse_item_native_type(&parser p) -> @ast::native_item {
18411841
auto t = parse_type_decl(p);
18421842
auto hi = p.get_hi_pos();
18431843
expect(p, token::SEMI);
1844-
auto item = ast::native_item_ty(t._1, p.get_id());
1845-
ret @spanned(t._0, hi, item);
1844+
ret @rec(ident=t._1,
1845+
node=ast::native_item_ty,
1846+
id=p.get_id(),
1847+
span=rec(lo=t._0, hi=hi));
18461848
}
18471849

18481850
fn parse_item_native_fn(&parser p) -> @ast::native_item {
@@ -1856,9 +1858,10 @@ fn parse_item_native_fn(&parser p) -> @ast::native_item {
18561858
}
18571859
auto hi = p.get_hi_pos();
18581860
expect(p, token::SEMI);
1859-
auto item =
1860-
ast::native_item_fn(t._0, link_name, decl, t._1, p.get_id());
1861-
ret @spanned(lo, hi, item);
1861+
ret @rec(ident=t._0,
1862+
node=ast::native_item_fn(link_name, decl, t._1),
1863+
id=p.get_id(),
1864+
span=rec(lo=lo, hi=hi));
18621865
}
18631866

18641867
fn parse_native_item(&parser p) -> @ast::native_item {

src/comp/middle/ast_map.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,7 @@ fn map_item(&map map, &@item i, &() e, &vt[()] v) {
3333
}
3434

3535
fn map_native_item(&map map, &@native_item i, &() e, &vt[()] v) {
36-
auto id = alt (i.node) {
37-
case (native_item_ty(_, ?id)) { id }
38-
case (native_item_fn(_, _, _, _, ?id)) { id }
39-
};
40-
map.insert(id, node_native_item(i));
36+
map.insert(i.id, node_native_item(i));
4137
visit::visit_native_item(i, e, v);
4238
}
4339

src/comp/middle/metadata.rs

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -337,22 +337,11 @@ fn encode_native_module_item_paths(&ebml::writer ebml_w,
337337
&native_mod nmod, &vec[str] path,
338338
&mutable vec[tup(str, uint)] index) {
339339
for (@native_item nitem in nmod.items) {
340-
alt (nitem.node) {
341-
case (native_item_ty(?ident, ?id)) {
342-
add_to_index(ebml_w, path, index, ident);
343-
ebml::start_tag(ebml_w, tag_paths_data_item);
344-
encode_name(ebml_w, ident);
345-
encode_def_id(ebml_w, local_def(id));
346-
ebml::end_tag(ebml_w);
347-
}
348-
case (native_item_fn(?ident, _, _, _, ?id)) {
349-
add_to_index(ebml_w, path, index, ident);
350-
ebml::start_tag(ebml_w, tag_paths_data_item);
351-
encode_name(ebml_w, ident);
352-
encode_def_id(ebml_w, local_def(id));
353-
ebml::end_tag(ebml_w);
354-
}
355-
}
340+
add_to_index(ebml_w, path, index, nitem.ident);
341+
ebml::start_tag(ebml_w, tag_paths_data_item);
342+
encode_name(ebml_w, nitem.ident);
343+
encode_def_id(ebml_w, local_def(nitem.id));
344+
ebml::end_tag(ebml_w);
356345
}
357346
}
358347

@@ -583,17 +572,17 @@ fn encode_info_for_native_item(&@trans::crate_ctxt cx, &ebml::writer ebml_w,
583572
&@native_item nitem) {
584573
ebml::start_tag(ebml_w, tag_items_data_item);
585574
alt (nitem.node) {
586-
case (native_item_ty(_, ?id)) {
587-
encode_def_id(ebml_w, local_def(id));
575+
case (native_item_ty) {
576+
encode_def_id(ebml_w, local_def(nitem.id));
588577
encode_kind(ebml_w, 'T' as u8);
589578
encode_type(cx, ebml_w, ty::mk_native(cx.tcx));
590579
}
591-
case (native_item_fn(_, _, _, ?tps, ?id)) {
592-
encode_def_id(ebml_w, local_def(id));
580+
case (native_item_fn(_, _, ?tps)) {
581+
encode_def_id(ebml_w, local_def(nitem.id));
593582
encode_kind(ebml_w, 'F' as u8);
594583
encode_type_param_count(ebml_w, tps);
595-
encode_type(cx, ebml_w, trans::node_id_type(cx, id));
596-
encode_symbol(cx, ebml_w, id);
584+
encode_type(cx, ebml_w, trans::node_id_type(cx, nitem.id));
585+
encode_symbol(cx, ebml_w, nitem.id);
597586
}
598587
}
599588
ebml::end_tag(ebml_w);

src/comp/middle/resolve.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ fn lookup_in_scope(&env e, scopes sc, &span sp, &ident name, namespace ns) ->
630630
}
631631
case (scope_native_item(?it)) {
632632
alt (it.node) {
633-
case (ast::native_item_fn(_, _, ?decl, ?ty_params, _))
633+
case (ast::native_item_fn(_, ?decl, ?ty_params))
634634
{
635635
ret lookup_in_fn(name, decl, ty_params, ns);
636636
}
@@ -1021,14 +1021,16 @@ fn lookup_in_mie(&env e, &mod_index_entry mie, namespace ns) ->
10211021
}
10221022
case (mie_native_item(?native_item)) {
10231023
alt (native_item.node) {
1024-
case (ast::native_item_ty(_, ?id)) {
1024+
case (ast::native_item_ty) {
10251025
if (ns == ns_type) {
1026-
ret some(ast::def_native_ty(local_def(id)));
1026+
ret some(ast::def_native_ty
1027+
(local_def(native_item.id)));
10271028
}
10281029
}
1029-
case (ast::native_item_fn(_, _, _, _, ?id)) {
1030+
case (ast::native_item_fn(_, _, _)) {
10301031
if (ns == ns_value) {
1031-
ret some(ast::def_native_fn(local_def(id)));
1032+
ret some(ast::def_native_fn
1033+
(local_def(native_item.id)));
10321034
}
10331035
}
10341036
}
@@ -1111,14 +1113,7 @@ fn index_nmod(&ast::native_mod md) -> mod_index {
11111113
}
11121114
}
11131115
for (@ast::native_item it in md.items) {
1114-
alt (it.node) {
1115-
case (ast::native_item_ty(?ident, _)) {
1116-
add_to_index(index, ident, mie_native_item(it));
1117-
}
1118-
case (ast::native_item_fn(?ident, _, _, _, _)) {
1119-
add_to_index(index, ident, mie_native_item(it));
1120-
}
1121-
}
1116+
add_to_index(index, it.ident, mie_native_item(it));
11221117
}
11231118
ret index;
11241119
}

src/comp/middle/trans.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7780,11 +7780,11 @@ fn native_fn_ty_param_count(&@crate_ctxt cx, ast::node_id id) -> uint {
77807780
case (ast_map::node_native_item(?i)) { i }
77817781
};
77827782
alt (native_item.node) {
7783-
case (ast::native_item_ty(_, _)) {
7783+
case (ast::native_item_ty) {
77847784
cx.sess.bug("decl_native_fn_and_pair(): native fn isn't " +
77857785
"actually a fn");
77867786
}
7787-
case (ast::native_item_fn(_, _, _, ?tps, _)) {
7787+
case (ast::native_item_fn(_, _, ?tps)) {
77887788
count = vec::len[ast::ty_param](tps);
77897789
}
77907790
}
@@ -7961,9 +7961,9 @@ fn item_path(&@ast::item item) -> vec[str] { ret [item.ident]; }
79617961
fn collect_native_item(@crate_ctxt ccx, &@ast::native_item i, &vec[str] pt,
79627962
&vt[vec[str]] v) {
79637963
alt (i.node) {
7964-
case (ast::native_item_fn(?name, _, _, _, ?id)) {
7965-
if (!ccx.obj_methods.contains_key(id)) {
7966-
decl_native_fn_and_pair(ccx, i.span, pt, name, id);
7964+
case (ast::native_item_fn(_, _, _)) {
7965+
if (!ccx.obj_methods.contains_key(i.id)) {
7966+
decl_native_fn_and_pair(ccx, i.span, pt, i.ident, i.id);
79677967
}
79687968
}
79697969
case (_) {}

src/comp/middle/typeck.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -610,21 +610,21 @@ mod collect {
610610
fn ty_of_native_item(&@ctxt cx, &@ast::native_item it,
611611
ast::native_abi abi) -> ty::ty_param_count_and_ty {
612612
alt (it.node) {
613-
case (ast::native_item_fn(_, _, ?fn_decl, ?params, ?id)) {
613+
case (ast::native_item_fn(_, ?fn_decl, ?params)) {
614614
auto get = bind getter(cx, _);
615615
auto convert = bind ast_ty_to_ty(cx.tcx, get, _);
616616
auto f = bind ty_of_arg(cx, _);
617617
ret ty_of_native_fn_decl(cx, convert, f, fn_decl, abi, params,
618-
ast::local_def(id));
618+
ast::local_def(it.id));
619619
}
620-
case (ast::native_item_ty(?tpt, ?id)) {
621-
alt (cx.tcx.tcache.find(local_def(id))) {
620+
case (ast::native_item_ty) {
621+
alt (cx.tcx.tcache.find(local_def(it.id))) {
622622
case (some(?tpt)) { ret tpt; }
623623
case (none) { }
624624
}
625625
auto t = ty::mk_native(cx.tcx);
626626
auto tpt = tup(0u, t);
627-
cx.tcx.tcache.insert(local_def(id), tpt);
627+
cx.tcx.tcache.insert(local_def(it.id), tpt);
628628
ret tpt;
629629
}
630630
}
@@ -757,12 +757,12 @@ mod collect {
757757
auto tpt =
758758
ty_of_native_item(cx, i, option::get[ast::native_abi]({ *abi }));
759759
alt (i.node) {
760-
case (ast::native_item_ty(_, _)) {
760+
case (ast::native_item_ty) {
761761
// FIXME: Native types have no annotation. Should they? --pcw
762762

763763
}
764-
case (ast::native_item_fn(_, _, _, _, ?id)) {
765-
write::ty_only(cx.tcx, id, tpt._1);
764+
case (ast::native_item_fn(_, _, _)) {
765+
write::ty_only(cx.tcx, i.id, tpt._1);
766766
}
767767
}
768768
}

src/comp/middle/visit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ fn visit_pat[E](&@pat p, &E e, &vt[E] v) {
202202

203203
fn visit_native_item[E](&@native_item ni, &E e, &vt[E] v) {
204204
alt (ni.node) {
205-
case (native_item_fn(_, _, ?fd, _, _)) { visit_fn_decl(fd, e, v); }
206-
case (native_item_ty(_, _)) { }
205+
case (native_item_fn(_, ?fd, _)) { visit_fn_decl(fd, e, v); }
206+
case (native_item_ty) { }
207207
}
208208
}
209209

src/comp/middle/walk.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,10 @@ fn walk_native_item(&ast_visitor v, @ast::native_item ni) {
203203
if (!v.keep_going()) { ret; }
204204
v.visit_native_item_pre(ni);
205205
alt (ni.node) {
206-
case (ast::native_item_fn(_, _, ?fd, _, _)) {
206+
case (ast::native_item_fn(_, ?fd, _)) {
207207
walk_fn_decl(v, fd);
208208
}
209-
case (ast::native_item_ty(_, _)) { }
209+
case (ast::native_item_ty) { }
210210
}
211211
v.visit_native_item_post(ni);
212212
}

src/comp/pretty/pprust.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,13 +320,13 @@ fn print_item(&ps s, &@ast::item item) {
320320
ibox(s, indent_unit);
321321
maybe_print_comment(s, item.span.lo);
322322
alt (item.node) {
323-
case (ast::native_item_ty(?id, _)) {
323+
case (ast::native_item_ty) {
324324
word_nbsp(s, "type");
325-
word(s.s, id);
325+
word(s.s, item.ident);
326326
}
327-
case (ast::native_item_fn(?id, ?lname, ?decl,
328-
?typarams, _)) {
329-
print_fn(s, decl, ast::proto_fn, id, typarams);
327+
case (ast::native_item_fn(?lname, ?decl, ?typarams)) {
328+
print_fn(s, decl, ast::proto_fn, item.ident,
329+
typarams);
330330
alt (lname) {
331331
case (none) { }
332332
case (some(?ss)) {

0 commit comments

Comments
 (0)