Skip to content

Commit 1c9277e

Browse files
committed
rustc: Make room in remaining AST item nodes for attributes
Issue #487
1 parent 697fdaa commit 1c9277e

File tree

13 files changed

+157
-150
lines changed

13 files changed

+157
-150
lines changed

src/comp/front/ast.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -465,24 +465,24 @@ type attribute_ = rec(attr_style style,
465465

466466
type item = spanned[item_];
467467
tag item_ {
468-
item_const(ident, @ty, @expr, def_id, ann);
469-
item_fn(ident, _fn, vec[ty_param], def_id, ann);
468+
item_const(ident, @ty, @expr, vec[attribute], def_id, ann);
469+
item_fn(ident, _fn, vec[ty_param], vec[attribute], def_id, ann);
470470
item_mod(ident, _mod, vec[attribute], def_id);
471-
item_native_mod(ident, native_mod, def_id);
472-
item_ty(ident, @ty, vec[ty_param], def_id, ann);
473-
item_tag(ident, vec[variant], vec[ty_param], def_id, ann);
474-
item_obj(ident, _obj, vec[ty_param], obj_def_ids, ann);
471+
item_native_mod(ident, native_mod, vec[attribute], def_id);
472+
item_ty(ident, @ty, vec[ty_param], vec[attribute], def_id, ann);
473+
item_tag(ident, vec[variant], vec[ty_param], vec[attribute], def_id, ann);
474+
item_obj(ident, _obj, vec[ty_param], vec[attribute], obj_def_ids, ann);
475475
}
476476

477477
fn item_ident(@item it) -> ident {
478478
ret alt (it.node) {
479-
case (item_const(?ident, _, _, _, _)) { ident }
480-
case (item_fn(?ident, _, _, _, _)) { ident }
479+
case (item_const(?ident, _, _, _, _, _)) { ident }
480+
case (item_fn(?ident, _, _, _, _, _)) { ident }
481481
case (item_mod(?ident, _, _, _)) { ident }
482-
case (item_native_mod(?ident, _, _)) { ident }
483-
case (item_ty(?ident, _, _, _, _)) { ident }
484-
case (item_tag(?ident, _, _, _, _)) { ident }
485-
case (item_obj(?ident, _, _, _, _)) { ident }
482+
case (item_native_mod(?ident, _, _, _)) { ident }
483+
case (item_ty(?ident, _, _, _, _, _)) { ident }
484+
case (item_tag(?ident, _, _, _, _, _)) { ident }
485+
case (item_obj(?ident, _, _, _, _, _)) { ident }
486486
}
487487
}
488488

@@ -500,7 +500,7 @@ fn is_exported(ident i, _mod m) -> bool {
500500
nonlocal = false;
501501
}
502502
alt (it.node) {
503-
case (item_tag(_, ?variants, _, _, _)) {
503+
case (item_tag(_, ?variants, _, _, _, _)) {
504504
for (variant v in variants) {
505505
if (v.node.name == i) {
506506
nonlocal = false;

src/comp/front/parser.rs

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,12 +1797,12 @@ fn parse_fn_header(&parser p)
17971797
ret tup(id, ty_params);
17981798
}
17991799

1800-
fn parse_item_fn_or_iter(&parser p, ast::purity purity, ast::proto proto)
1801-
-> @ast::item {
1800+
fn parse_item_fn_or_iter(&parser p, ast::purity purity, ast::proto proto,
1801+
vec[ast::attribute] attrs ) -> @ast::item {
18021802
auto lo = p.get_last_lo_pos();
18031803
auto t = parse_fn_header(p);
18041804
auto f = parse_fn(p, proto, purity);
1805-
auto item = ast::item_fn(t._0, f, t._1,
1805+
auto item = ast::item_fn(t._0, f, t._1, attrs,
18061806
p.next_def_id(), p.get_ann());
18071807
ret @spanned(lo, f.body.span.hi, item);
18081808
}
@@ -1846,7 +1846,8 @@ fn parse_dtor(&parser p) -> @ast::method {
18461846
ret @spanned(lo, f.body.span.hi, m);
18471847
}
18481848

1849-
fn parse_item_obj(&parser p, ast::layer lyr) -> @ast::item {
1849+
fn parse_item_obj(&parser p, ast::layer lyr,
1850+
vec[ast::attribute] attrs) -> @ast::item {
18501851
auto lo = p.get_last_lo_pos();
18511852
auto ident = parse_value_ident(p);
18521853
auto ty_params = parse_ty_params(p);
@@ -1877,7 +1878,7 @@ fn parse_item_obj(&parser p, ast::layer lyr) -> @ast::item {
18771878
dtor=dtor);
18781879

18791880
auto odid = rec(ty=p.next_def_id(), ctor=p.next_def_id());
1880-
auto item = ast::item_obj(ident, ob, ty_params, odid, p.get_ann());
1881+
auto item = ast::item_obj(ident, ob, ty_params, attrs, odid, p.get_ann());
18811882

18821883
ret @spanned(lo, hi, item);
18831884
}
@@ -1900,15 +1901,16 @@ fn parse_mod_items(&parser p, token::token term) -> ast::_mod {
19001901
ret rec(view_items=view_items, items=items);
19011902
}
19021903

1903-
fn parse_item_const(&parser p) -> @ast::item {
1904+
fn parse_item_const(&parser p, vec[ast::attribute] attrs) -> @ast::item {
19041905
auto lo = p.get_last_lo_pos();
19051906
auto ty = parse_ty(p);
19061907
auto id = parse_value_ident(p);
19071908
expect(p, token::EQ);
19081909
auto e = parse_expr(p);
19091910
auto hi = p.get_hi_pos();
19101911
expect(p, token::SEMI);
1911-
auto item = ast::item_const(id, ty, e, p.next_def_id(), p.get_ann());
1912+
auto item = ast::item_const(id, ty, e, attrs,
1913+
p.next_def_id(), p.get_ann());
19121914
ret @spanned(lo, hi, item);
19131915
}
19141916

@@ -1994,7 +1996,7 @@ fn default_native_name(session::session sess, str id) -> str {
19941996
ret n.prefix + id + n.suffix;
19951997
}
19961998

1997-
fn parse_item_native_mod(&parser p) -> @ast::item {
1999+
fn parse_item_native_mod(&parser p, vec[ast::attribute] attrs) -> @ast::item {
19982000
auto lo = p.get_last_lo_pos();
19992001
auto abi = ast::native_abi_cdecl;
20002002
if (!is_word(p, "mod")) {
@@ -2024,7 +2026,7 @@ fn parse_item_native_mod(&parser p) -> @ast::item {
20242026
auto m = parse_native_mod_items(p, native_name, abi);
20252027
auto hi = p.get_hi_pos();
20262028
expect(p, token::RBRACE);
2027-
auto item = ast::item_native_mod(id, m, p.next_def_id());
2029+
auto item = ast::item_native_mod(id, m, attrs, p.next_def_id());
20282030
ret @spanned(lo, hi, item);
20292031
}
20302032

@@ -2034,19 +2036,20 @@ fn parse_type_decl(&parser p) -> tup(uint, ast::ident) {
20342036
ret tup(lo, id);
20352037
}
20362038

2037-
fn parse_item_type(&parser p) -> @ast::item {
2039+
fn parse_item_type(&parser p, vec[ast::attribute] attrs) -> @ast::item {
20382040
auto t = parse_type_decl(p);
20392041
auto tps = parse_ty_params(p);
20402042

20412043
expect(p, token::EQ);
20422044
auto ty = parse_ty(p);
20432045
auto hi = p.get_hi_pos();
20442046
expect(p, token::SEMI);
2045-
auto item = ast::item_ty(t._1, ty, tps, p.next_def_id(), p.get_ann());
2047+
auto item = ast::item_ty(t._1, ty, tps, attrs,
2048+
p.next_def_id(), p.get_ann());
20462049
ret @spanned(t._0, hi, item);
20472050
}
20482051

2049-
fn parse_item_tag(&parser p) -> @ast::item {
2052+
fn parse_item_tag(&parser p, vec[ast::attribute] attrs) -> @ast::item {
20502053
auto lo = p.get_last_lo_pos();
20512054
auto id = parse_ident(p);
20522055
auto ty_params = parse_ty_params(p);
@@ -2092,8 +2095,8 @@ fn parse_item_tag(&parser p) -> @ast::item {
20922095
auto hi = p.get_hi_pos();
20932096
p.bump();
20942097

2095-
auto item = ast::item_tag(id, variants, ty_params, p.next_def_id(),
2096-
p.get_ann());
2098+
auto item = ast::item_tag(id, variants, ty_params, attrs,
2099+
p.next_def_id(), p.get_ann());
20972100
ret @spanned(lo, hi, item);
20982101
}
20992102

@@ -2128,29 +2131,31 @@ tag parsed_item {
21282131
fn parse_item(&parser p, vec[ast::attribute] attrs) -> parsed_item {
21292132

21302133
if (eat_word(p, "const")) {
2131-
ret got_item(parse_item_const(p));
2134+
ret got_item(parse_item_const(p, attrs));
21322135
} else if (eat_word(p, "fn")) {
21332136
// This is an anonymous function
21342137
if (p.peek() == token::LPAREN) { ret fn_no_item; }
2135-
ret got_item(parse_item_fn_or_iter(p, ast::impure_fn, ast::proto_fn));
2138+
ret got_item(parse_item_fn_or_iter(p, ast::impure_fn,
2139+
ast::proto_fn, attrs));
21362140
} else if (eat_word(p, "pred")) {
2137-
ret got_item(parse_item_fn_or_iter(p, ast::pure_fn, ast::proto_fn));
2141+
ret got_item(parse_item_fn_or_iter(p, ast::pure_fn,
2142+
ast::proto_fn, attrs));
21382143
} else if (eat_word(p, "iter")) {
21392144
ret got_item(parse_item_fn_or_iter(p, ast::impure_fn,
2140-
ast::proto_iter));
2145+
ast::proto_iter, attrs));
21412146
} else if (eat_word(p, "mod")) {
21422147
ret got_item(parse_item_mod(p, attrs));
21432148
} else if (eat_word(p, "native")) {
2144-
ret got_item(parse_item_native_mod(p));
2149+
ret got_item(parse_item_native_mod(p, attrs));
21452150
}
21462151

21472152
auto lyr = parse_layer(p);
21482153
if (eat_word(p, "type")) {
2149-
ret got_item(parse_item_type(p));
2154+
ret got_item(parse_item_type(p, attrs));
21502155
} else if (eat_word(p, "tag")) {
2151-
ret got_item(parse_item_tag(p));
2156+
ret got_item(parse_item_tag(p, attrs));
21522157
} else if (eat_word(p, "obj")) {
2153-
ret got_item(parse_item_obj(p, lyr));
2158+
ret got_item(parse_item_obj(p, lyr, attrs));
21542159
} else {
21552160
ret no_item;
21562161
}

src/comp/middle/alias.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fn visit_fn(@ctx cx, &ast::_fn f, &vec[ast::ty_param] tp, &span sp,
6666

6767
fn visit_item(@ctx cx, &@ast::item i, &scope sc, &vt[scope] v) {
6868
alt (i.node) {
69-
case (ast::item_obj(_, ?o, _, _, _)) {
69+
case (ast::item_obj(_, ?o, _, _, _, _)) {
7070
for (ast::obj_field f in o.fields) {
7171
cx.local_map.insert(f.id._1, objfield(f.mut));
7272
}

src/comp/middle/metadata.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -388,14 +388,14 @@ fn encode_module_item_paths(&ebml::writer ebml_w,
388388
}
389389

390390
alt (it.node) {
391-
case (ast::item_const(?id, _, ?tps, ?did, ?ann)) {
391+
case (ast::item_const(?id, _, ?tps, _, ?did, ?ann)) {
392392
add_to_index(ebml_w, path, index, id);
393393
ebml::start_tag(ebml_w, tag_paths_data_item);
394394
encode_name(ebml_w, id);
395395
encode_def_id(ebml_w, did);
396396
ebml::end_tag(ebml_w);
397397
}
398-
case (ast::item_fn(?id, _, ?tps, ?did, ?ann)) {
398+
case (ast::item_fn(?id, _, ?tps, _, ?did, ?ann)) {
399399
add_to_index(ebml_w, path, index, id);
400400
ebml::start_tag(ebml_w, tag_paths_data_item);
401401
encode_name(ebml_w, id);
@@ -410,7 +410,7 @@ fn encode_module_item_paths(&ebml::writer ebml_w,
410410
encode_module_item_paths(ebml_w, _mod, path + [id], index);
411411
ebml::end_tag(ebml_w);
412412
}
413-
case (ast::item_native_mod(?id, ?nmod, ?did)) {
413+
case (ast::item_native_mod(?id, ?nmod, _, ?did)) {
414414
add_to_index(ebml_w, path, index, id);
415415
ebml::start_tag(ebml_w, tag_paths_data_mod);
416416
encode_name(ebml_w, id);
@@ -419,14 +419,14 @@ fn encode_module_item_paths(&ebml::writer ebml_w,
419419
index);
420420
ebml::end_tag(ebml_w);
421421
}
422-
case (ast::item_ty(?id, _, ?tps, ?did, ?ann)) {
422+
case (ast::item_ty(?id, _, ?tps, _, ?did, ?ann)) {
423423
add_to_index(ebml_w, path, index, id);
424424
ebml::start_tag(ebml_w, tag_paths_data_item);
425425
encode_name(ebml_w, id);
426426
encode_def_id(ebml_w, did);
427427
ebml::end_tag(ebml_w);
428428
}
429-
case (ast::item_tag(?id, ?variants, ?tps, ?did, _)) {
429+
case (ast::item_tag(?id, ?variants, ?tps, _, ?did, _)) {
430430
add_to_index(ebml_w, path, index, id);
431431
ebml::start_tag(ebml_w, tag_paths_data_item);
432432
encode_name(ebml_w, id);
@@ -435,7 +435,7 @@ fn encode_module_item_paths(&ebml::writer ebml_w,
435435

436436
encode_tag_variant_paths(ebml_w, variants, path, index);
437437
}
438-
case (ast::item_obj(?id, _, ?tps, ?odid, ?ann)) {
438+
case (ast::item_obj(?id, _, ?tps, _, ?odid, ?ann)) {
439439
add_to_index(ebml_w, path, index, id);
440440
ebml::start_tag(ebml_w, tag_paths_data_item);
441441
encode_name(ebml_w, id);
@@ -543,15 +543,15 @@ fn encode_tag_variant_info(&@trans::crate_ctxt cx, &ebml::writer ebml_w,
543543
fn encode_info_for_item(@trans::crate_ctxt cx, &ebml::writer ebml_w,
544544
@ast::item item, &mutable vec[tup(int, uint)] index) {
545545
alt (item.node) {
546-
case (ast::item_const(_, _, _, ?did, ?ann)) {
546+
case (ast::item_const(_, _, _, _, ?did, ?ann)) {
547547
ebml::start_tag(ebml_w, tag_items_data_item);
548548
encode_def_id(ebml_w, did);
549549
encode_kind(ebml_w, 'c' as u8);
550550
encode_type(cx, ebml_w, trans::node_ann_type(cx, ann));
551551
encode_symbol(cx, ebml_w, did);
552552
ebml::end_tag(ebml_w);
553553
}
554-
case (ast::item_fn(_, _, ?tps, ?did, ?ann)) {
554+
case (ast::item_fn(_, _, ?tps, _, ?did, ?ann)) {
555555
ebml::start_tag(ebml_w, tag_items_data_item);
556556
encode_def_id(ebml_w, did);
557557
encode_kind(ebml_w, 'f' as u8);
@@ -566,21 +566,21 @@ fn encode_info_for_item(@trans::crate_ctxt cx, &ebml::writer ebml_w,
566566
encode_kind(ebml_w, 'm' as u8);
567567
ebml::end_tag(ebml_w);
568568
}
569-
case (ast::item_native_mod(?id, _, ?did)) {
569+
case (ast::item_native_mod(?id, _, _, ?did)) {
570570
ebml::start_tag(ebml_w, tag_items_data_item);
571571
encode_def_id(ebml_w, did);
572572
encode_kind(ebml_w, 'n' as u8);
573573
ebml::end_tag(ebml_w);
574574
}
575-
case (ast::item_ty(?id, _, ?tps, ?did, ?ann)) {
575+
case (ast::item_ty(?id, _, ?tps, _, ?did, ?ann)) {
576576
ebml::start_tag(ebml_w, tag_items_data_item);
577577
encode_def_id(ebml_w, did);
578578
encode_kind(ebml_w, 'y' as u8);
579579
encode_type_param_count(ebml_w, tps);
580580
encode_type(cx, ebml_w, trans::node_ann_type(cx, ann));
581581
ebml::end_tag(ebml_w);
582582
}
583-
case (ast::item_tag(?id, ?variants, ?tps, ?did, ?ann)) {
583+
case (ast::item_tag(?id, ?variants, ?tps, _, ?did, ?ann)) {
584584
ebml::start_tag(ebml_w, tag_items_data_item);
585585
encode_def_id(ebml_w, did);
586586
encode_kind(ebml_w, 't' as u8);
@@ -593,7 +593,7 @@ fn encode_info_for_item(@trans::crate_ctxt cx, &ebml::writer ebml_w,
593593

594594
encode_tag_variant_info(cx, ebml_w, did, variants, index, tps);
595595
}
596-
case (ast::item_obj(?id, _, ?tps, ?odid, ?ann)) {
596+
case (ast::item_obj(?id, _, ?tps, _, ?odid, ?ann)) {
597597
ebml::start_tag(ebml_w, tag_items_data_item);
598598
encode_def_id(ebml_w, odid.ctor);
599599
encode_kind(ebml_w, 'o' as u8);

0 commit comments

Comments
 (0)