Skip to content

Commit 322b7c9

Browse files
committed
---
yaml --- r: 15441 b: refs/heads/try c: 5c12cd7 h: refs/heads/master i: 15439: e5931f0 v: v3
1 parent f66b4f0 commit 322b7c9

File tree

20 files changed

+243
-84
lines changed

20 files changed

+243
-84
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: 9fda1578a219a8762fadddfd37c45abdd6a271a1
5+
refs/heads/try: 5c12cd72f4774af8ca1c3c9c0115b4b1a72404bb
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/librustsyntax/ast.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,9 @@ enum attr_style { attr_outer, attr_inner, }
641641
#[auto_serialize]
642642
type attribute_ = {style: attr_style, value: meta_item};
643643

644+
#[auto_serialize]
645+
type iface_ref = {path: @path, id: node_id};
646+
644647
#[auto_serialize]
645648
type item = {ident: ident, attrs: [attribute],
646649
id: node_id, node: item_, span: span};
@@ -656,6 +659,7 @@ enum item_ {
656659
item_res(fn_decl /* dtor */, [ty_param], blk /* dtor body */,
657660
node_id /* dtor id */, node_id /* ctor id */),
658661
item_class([ty_param], /* ty params for class */
662+
[iface_ref], /* ifaces this class implements */
659663
[@class_member], /* methods, etc. */
660664
/* (not including ctor) */
661665
class_ctor

branches/try/src/librustsyntax/fold.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,13 @@ fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
269269
item_enum(vec::map(variants, fld.fold_variant),
270270
fold_ty_params(typms, fld))
271271
}
272-
item_class(typms, items, ctor) {
272+
item_class(typms, ifaces, items, ctor) {
273273
let ctor_body = fld.fold_block(ctor.node.body);
274274
let ctor_decl = fold_fn_decl(ctor.node.dec, fld);
275275
let ctor_id = fld.new_id(ctor.node.id);
276-
item_class(typms,
276+
item_class(typms, vec::map(ifaces, {|p|
277+
{path: fld.fold_path(p.path),
278+
id: fld.new_id(p.id)}}),
277279
vec::map(items, fld.fold_class_item),
278280
{node: {body: ctor_body,
279281
dec: ctor_decl,

branches/try/src/librustsyntax/parse/parser.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,11 +2143,19 @@ fn ident_to_path_tys(p: parser, i: ast::ident,
21432143
@spanned(s.lo, s.hi, p_)
21442144
}
21452145

2146+
fn parse_iface_ref_list(p:parser) -> [ast::iface_ref] {
2147+
parse_seq_to_before_end(token::LBRACE, seq_sep(token::COMMA),
2148+
{|p| {path: parse_path(p), id: p.get_id()}}, p)
2149+
}
2150+
21462151
fn parse_item_class(p: parser, attrs: [ast::attribute]) -> @ast::item {
21472152
let lo = p.last_span.lo;
21482153
let class_name = parse_value_ident(p);
21492154
let ty_params = parse_ty_params(p);
21502155
let class_path = ident_to_path_tys(p, class_name, ty_params);
2156+
let ifaces : [ast::iface_ref] = if eat_word(p, "implements")
2157+
{ parse_iface_ref_list(p) }
2158+
else { [] };
21512159
expect(p, token::LBRACE);
21522160
let mut ms: [@ast::class_member] = [];
21532161
let ctor_id = p.get_id();
@@ -2163,9 +2171,8 @@ fn parse_item_class(p: parser, attrs: [ast::attribute]) -> @ast::item {
21632171
p.bump();
21642172
alt the_ctor {
21652173
some((ct_d, ct_b, ct_s)) {
2166-
ret mk_item(p, lo, p.last_span.hi,
2167-
class_name,
2168-
ast::item_class(ty_params, ms,
2174+
ret mk_item(p, lo, p.last_span.hi, class_name,
2175+
ast::item_class(ty_params, ifaces, ms,
21692176
{node: {id: ctor_id,
21702177
self_id: p.get_id(),
21712178
dec: ct_d,

branches/try/src/librustsyntax/print/pprust.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,10 +493,13 @@ fn print_item(s: ps, &&item: @ast::item) {
493493
bclose(s, item.span);
494494
}
495495
}
496-
ast::item_class(tps,items,ctor) {
496+
ast::item_class(tps,ifaces,items,ctor) {
497497
head(s, "class");
498498
word_nbsp(s, item.ident);
499499
print_type_params(s, tps);
500+
word_space(s, "implements");
501+
commasep(s, inconsistent, ifaces, {|s, p|
502+
print_path(s, p.path, false)});
500503
bopen(s);
501504
hardbreak_if_not_bol(s);
502505
maybe_print_comment(s, ctor.span.lo);

branches/try/src/librustsyntax/visit.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,12 @@ fn visit_item<E>(i: @item, e: E, v: vt<E>) {
137137
visit_method_helper(m, e, v)
138138
}
139139
}
140-
item_class(tps, members, ctor) {
140+
item_class(tps, ifaces, members, ctor) {
141141
v.visit_ty_params(tps, e, v);
142142
for members.each {|m|
143143
v.visit_class_item(m, e, v);
144144
}
145+
for ifaces.each {|p| visit_path(p.path, e, v); }
145146
visit_class_ctor_helper(ctor, i.ident, tps,
146147
ast_util::local_def(i.id), e, v);
147148
}

branches/try/src/rustc/metadata/encoder.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ fn encode_module_item_paths(ebml_w: ebml::writer, ecx: @encode_ctxt,
151151
encode_def_id(ebml_w, local_def(it.id));
152152
ebml_w.end_tag();
153153
}
154-
item_class(tps,items,ctor) {
154+
item_class(_, _, items, ctor) {
155155
add_to_index(ebml_w, path, index, it.ident);
156156
ebml_w.start_tag(tag_paths_data_item);
157157
encode_name(ebml_w, it.ident);
@@ -556,7 +556,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
556556
encode_enum_variant_info(ecx, ebml_w, item.id, variants,
557557
path, index, tps);
558558
}
559-
item_class(tps,items,ctor) {
559+
item_class(tps, _ifaces, items,ctor) {
560560
/* First, encode the fields and methods
561561
These come first because we need to write them to make
562562
the index, and the index needs to be in the item for the
@@ -573,7 +573,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
573573
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
574574
encode_name(ebml_w, item.ident);
575575
encode_path(ebml_w, path, ast_map::path_name(item.ident));
576-
576+
/* FIXME: encode ifaces */
577577
/* Encode def_ids for each field and method
578578
for methods, write all the stuff get_iface_method
579579
needs to know*/
@@ -729,7 +729,7 @@ fn encode_info_for_items(ecx: @encode_ctxt, ebml_w: ebml::writer,
729729
encode_info_for_item(ecx, ebml_w, i, index, *pt);
730730
/* encode ctor, then encode items */
731731
alt i.node {
732-
item_class(tps,_,ctor) {
732+
item_class(tps,_,_,ctor) {
733733
/* this is assuming that ctors aren't inlined...
734734
probably shouldn't assume that */
735735
#debug("encoding info for ctor %s %d", i.ident,

branches/try/src/rustc/middle/ast_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ fn map_item(i: @item, cx: ctx, v: vt) {
203203
cx.map.insert(nitem.id, node_native_item(nitem, abi, @cx.path));
204204
}
205205
}
206-
item_class(_, items, ctor) {
206+
item_class(_, _, items, ctor) {
207207
let d_id = ast_util::local_def(i.id);
208208
let p = extend(cx, i.ident);
209209
for items.each {|ci|

branches/try/src/rustc/middle/mutbl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ fn visit_expr(ex: @expr, &&cx: @ctx, v: visit::vt<@ctx>) {
216216

217217
fn visit_item(item: @item, &&cx: @ctx, v: visit::vt<@ctx>) {
218218
alt item.node {
219-
item_class(tps, items, ctor) {
219+
item_class(tps, _, items, ctor) {
220220
v.visit_ty_params(tps, cx, v);
221221
vec::map::<@class_member, ()>(items,
222222
{|i| v.visit_class_item(i, cx, v); });

branches/try/src/rustc/middle/region.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ fn resolve_item(item: @ast::item, cx: ctxt, visitor: visit::vt<ctxt>) {
530530
{parent: pa_fn_item(item.id),
531531
scope: cx.scope.binding_subscope(item.id)}
532532
}
533-
ast::item_impl(_, _, _, _) | ast::item_class(_, _, _) {
533+
ast::item_impl(_, _, _, _) | ast::item_class(_, _, _, _) {
534534
{parent: pa_item(item.id),
535535
scope: cx.scope.self_subscope(item.id)}
536536
}

branches/try/src/rustc/middle/resolve.rs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ fn resolve_names(e: @env, c: @ast::crate) {
391391
e.used_imports.track = true;
392392
let v =
393393
@{visit_native_item: visit_native_item_with_scope,
394-
visit_item: bind visit_item_with_scope(e, _, _, _),
394+
visit_item: bind walk_item(e, _, _, _),
395395
visit_block: visit_block_with_scope,
396396
visit_decl: visit_decl_with_scope,
397397
visit_arm: visit_arm_with_scope,
@@ -407,6 +407,24 @@ fn resolve_names(e: @env, c: @ast::crate) {
407407
e.used_imports.track = false;
408408
e.sess.abort_if_errors();
409409

410+
fn walk_item(e: @env, i: @ast::item, sc: scopes, v: vt<scopes>) {
411+
visit_item_with_scope(e, i, sc, v);
412+
/*
413+
Resolve the ifaces that a class implements; do nothing for
414+
non-class items
415+
*/
416+
alt i.node {
417+
ast::item_class(_, ifaces, _, _) {
418+
/* visit the iface paths... */
419+
for ifaces.each {|p|
420+
maybe_insert(e, p.id,
421+
lookup_path_strict(*e, sc, p.path.span, p.path.node,
422+
ns_type))};
423+
}
424+
_ {}
425+
}
426+
}
427+
410428
fn walk_expr(e: @env, exp: @ast::expr, sc: scopes, v: vt<scopes>) {
411429
visit::visit_expr(exp, sc, v);
412430
alt exp.node {
@@ -517,7 +535,7 @@ fn visit_item_with_scope(e: @env, i: @ast::item, sc: scopes, v: vt<scopes>) {
517535
v.visit_ty(m.decl.output, msc, v);
518536
}
519537
}
520-
ast::item_class(tps, members, ctor) {
538+
ast::item_class(tps, ifaces, members, ctor) {
521539
visit::visit_ty_params(tps, sc, v);
522540
// Can maybe skip this now that we require self on class fields
523541
let class_scope = cons(scope_item(i), @sc);
@@ -993,7 +1011,7 @@ fn lookup_in_scope(e: env, sc: scopes, sp: span, name: ident, ns: namespace,
9931011
ast::item_native_mod(m) {
9941012
ret lookup_in_local_native_mod(e, it.id, sp, name, ns);
9951013
}
996-
ast::item_class(tps, members, ctor) {
1014+
ast::item_class(tps, _, members, ctor) {
9971015
if ns == ns_type {
9981016
ret lookup_in_ty_params(e, name, tps);
9991017
}
@@ -1278,7 +1296,7 @@ fn found_def_item(i: @ast::item, ns: namespace) -> option<def> {
12781296
_ { }
12791297
}
12801298
}
1281-
ast::item_class(_, _, _) {
1299+
ast::item_class(_, _, _, _) {
12821300
if ns == ns_type {
12831301
ret some(ast::def_class(local_def(i.id)));
12841302
}
@@ -1407,7 +1425,11 @@ fn list_search<T: copy, U: copy>(ls: list<T>, f: fn(T) -> option<U>)
14071425

14081426
fn lookup_in_local_mod(e: env, node_id: node_id, sp: span, id: ident,
14091427
ns: namespace, dr: dir) -> option<def> {
1410-
let info = e.mod_map.get(node_id);
1428+
let info = alt e.mod_map.find(node_id) {
1429+
some(x) { x }
1430+
none { e.sess.span_bug(sp, #fmt("lookup_in_local_mod: \
1431+
module %d not in mod_map", node_id)); }
1432+
};
14111433
if dr == outside && !is_exported(e, id, info) {
14121434
// if we're in a native mod, then dr==inside, so info.m is some _mod
14131435
ret none; // name is not visible
@@ -1582,7 +1604,7 @@ fn index_mod(md: ast::_mod) -> mod_index {
15821604
variant_idx += 1u;
15831605
}
15841606
}
1585-
ast::item_class(tps, items, ctor) {
1607+
ast::item_class(tps, _, items, ctor) {
15861608
// add the class name itself
15871609
add_to_index(index, it.ident, mie_item(it));
15881610
// add the constructor decl

branches/try/src/rustc/middle/trans/base.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4432,9 +4432,11 @@ fn trans_item(ccx: @crate_ctxt, item: ast::item) {
44324432
};
44334433
native::trans_native_mod(ccx, native_mod, abi);
44344434
}
4435-
ast::item_class(tps, items, ctor) {
4435+
ast::item_class(tps, _ifaces, items, ctor) {
44364436
if tps.len() == 0u {
44374437
let psubsts = {tys: ty::ty_params_to_tys(ccx.tcx, tps),
4438+
// FIXME: vtables have to get filled in depending
4439+
// on ifaces
44384440
vtables: none,
44394441
bounds: @[]};
44404442
trans_class_ctor(ccx, *path, ctor.node.dec, ctor.node.body,

branches/try/src/rustc/middle/trans/reachable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ fn traverse_public_item(cx: ctx, item: @item) {
102102
}
103103
}
104104
}
105-
item_class(tps, items, ctor) {
105+
item_class(tps, _ifaces, items, ctor) {
106106
cx.rmap.insert(ctor.node.id, ());
107107
for vec::each(items) {|item|
108108
alt item.node {

branches/try/src/rustc/middle/tstate/pre_post_conditions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ fn find_pre_post_item(ccx: crate_ctxt, i: item) {
5757
ccx: ccx};
5858
find_pre_post_fn(fcx, body);
5959
}
60-
item_class(_,_,_) {
61-
fail "find_pre_post_item: implement item_class";
60+
item_class(_,_,_,_) {
61+
fail "find_pre_post_item: shouldn't be called on item_class";
6262
}
6363
item_impl(_, _, _, ms) {
6464
for ms.each {|m| find_pre_post_method(ccx, m); }

branches/try/src/rustc/middle/ty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2261,7 +2261,7 @@ fn lookup_class_fields(cx: ctxt, did: ast::def_id) -> [field_ty] {
22612261
alt cx.items.find(did.node) {
22622262
some(ast_map::node_item(i,_)) {
22632263
alt i.node {
2264-
ast::item_class(_, items, _) {
2264+
ast::item_class(_, _, items, _) {
22652265
class_field_tys(items)
22662266
}
22672267
_ { cx.sess.bug("class ID bound to non-class"); }
@@ -2303,7 +2303,7 @@ pure fn is_public(f: field_ty) -> bool {
23032303
fn lookup_class_method_ids(cx: ctxt, did: ast::def_id)
23042304
: is_local(did) -> [{name: ident, id: node_id, privacy: privacy}] {
23052305
alt cx.items.find(did.node) {
2306-
some(ast_map::node_item(@{node: item_class(_,items,_), _}, _)) {
2306+
some(ast_map::node_item(@{node: item_class(_,_,items,_), _}, _)) {
23072307
let (_,ms) = split_class_items(items);
23082308
vec::map(ms, {|m| {name: m.ident, id: m.id,
23092309
privacy: m.privacy}})

0 commit comments

Comments
 (0)