Skip to content

Commit afef476

Browse files
committed
---
yaml --- r: 12548 b: refs/heads/master c: 3c995fb h: refs/heads/master v: v3
1 parent 920bb89 commit afef476

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1327
-935
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: f3f34bf09b2512cac0e77281d8f2249d64cf2743
2+
refs/heads/master: 3c995fb8f3676a313f5ac883e175cc5fe354e640
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/librustsyntax/ast.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -645,21 +645,29 @@ type iface_ref = {path: @path, id: node_id};
645645
type item = {ident: ident, attrs: [attribute],
646646
id: node_id, node: item_, span: span};
647647

648+
#[auto_serialize]
649+
enum region_param {
650+
rp_none,
651+
rp_self
652+
}
653+
648654
#[auto_serialize]
649655
enum item_ {
650656
item_const(@ty, @expr),
651657
item_fn(fn_decl, [ty_param], blk),
652658
item_mod(_mod),
653659
item_native_mod(native_mod),
654-
item_ty(@ty, [ty_param]),
655-
item_enum([variant], [ty_param]),
660+
item_ty(@ty, [ty_param], region_param),
661+
item_enum([variant], [ty_param], region_param),
656662
item_res(fn_decl /* dtor */, [ty_param], blk /* dtor body */,
657-
node_id /* dtor id */, node_id /* ctor id */),
663+
node_id /* dtor id */, node_id /* ctor id */,
664+
region_param),
658665
item_class([ty_param], /* ty params for class */
659666
[iface_ref], /* ifaces this class implements */
660667
[@class_member], /* methods, etc. */
661668
/* (not including ctor) */
662-
class_ctor
669+
class_ctor,
670+
region_param
663671
),
664672
item_iface([ty_param], [ty_method]),
665673
item_impl([ty_param], option<@ty> /* iface */,

trunk/src/librustsyntax/ast_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ fn is_exported(i: ident, m: _mod) -> bool {
149149
for m.items.each {|it|
150150
if it.ident == i { local = true; }
151151
alt it.node {
152-
item_enum(variants, _) {
152+
item_enum(variants, _, _) {
153153
for variants.each {|v|
154154
if v.node.name == i {
155155
local = true;

trunk/src/librustsyntax/ext/auto_serialize.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ fn expand(cx: ext_ctxt,
102102

103103
vec::flat_map(in_items) {|in_item|
104104
alt in_item.node {
105-
ast::item_ty(ty, tps) {
105+
ast::item_ty(ty, tps, _) {
106106
[filter_attrs(in_item)] + ty_fns(cx, in_item.ident, ty, tps)
107107
}
108108

109-
ast::item_enum(variants, tps) {
109+
ast::item_enum(variants, tps, _) {
110110
[filter_attrs(in_item)] + enum_fns(cx, in_item.ident,
111111
in_item.span, variants, tps)
112112
}

trunk/src/librustsyntax/fold.rs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -265,36 +265,42 @@ fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
265265
}
266266
item_mod(m) { item_mod(fld.fold_mod(m)) }
267267
item_native_mod(nm) { item_native_mod(fld.fold_native_mod(nm)) }
268-
item_ty(t, typms) { item_ty(fld.fold_ty(t),
269-
fold_ty_params(typms, fld)) }
270-
item_enum(variants, typms) {
268+
item_ty(t, typms, rp) { item_ty(fld.fold_ty(t),
269+
fold_ty_params(typms, fld),
270+
rp) }
271+
item_enum(variants, typms, r) {
271272
item_enum(vec::map(variants, fld.fold_variant),
272-
fold_ty_params(typms, fld))
273+
fold_ty_params(typms, fld),
274+
r)
273275
}
274-
item_class(typms, ifaces, items, ctor) {
276+
item_class(typms, ifaces, items, ctor, rp) {
275277
let ctor_body = fld.fold_block(ctor.node.body);
276278
let ctor_decl = fold_fn_decl(ctor.node.dec, fld);
277279
let ctor_id = fld.new_id(ctor.node.id);
278-
item_class(typms, vec::map(ifaces, {|p|
279-
{path: fld.fold_path(p.path),
280-
id: fld.new_id(p.id)}}),
281-
vec::map(items, fld.fold_class_item),
282-
{node: {body: ctor_body,
283-
dec: ctor_decl,
284-
id: ctor_id with ctor.node}
285-
with ctor})
280+
item_class(
281+
typms,
282+
vec::map(ifaces, {|p|
283+
{path: fld.fold_path(p.path),
284+
id: fld.new_id(p.id)}}),
285+
vec::map(items, fld.fold_class_item),
286+
{node: {body: ctor_body,
287+
dec: ctor_decl,
288+
id: ctor_id with ctor.node}
289+
with ctor},
290+
rp)
286291
}
287292
item_impl(tps, ifce, ty, methods) {
288293
item_impl(tps, option::map(ifce, fld.fold_ty), fld.fold_ty(ty),
289294
vec::map(methods, fld.fold_method))
290295
}
291296
item_iface(tps, methods) { item_iface(tps, methods) }
292-
item_res(decl, typms, body, did, cid) {
297+
item_res(decl, typms, body, did, cid, rp) {
293298
item_res(fold_fn_decl(decl, fld),
294299
fold_ty_params(typms, fld),
295300
fld.fold_block(body),
296301
fld.new_id(did),
297-
fld.new_id(cid))
302+
fld.new_id(cid),
303+
rp)
298304
}
299305
};
300306
}

trunk/src/librustsyntax/parse/parser.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,6 +1992,7 @@ fn parse_item_impl(p: parser, attrs: [ast::attribute]) -> @ast::item {
19921992
fn parse_item_res(p: parser, attrs: [ast::attribute]) -> @ast::item {
19931993
let lo = p.last_span.lo;
19941994
let ident = parse_value_ident(p);
1995+
let rp = parse_region_param(p);
19951996
let ty_params = parse_ty_params(p);
19961997
expect(p, token::LPAREN);
19971998
let arg_ident = parse_value_ident(p);
@@ -2010,7 +2011,8 @@ fn parse_item_res(p: parser, attrs: [ast::attribute]) -> @ast::item {
20102011
cf: ast::return_val,
20112012
constraints: []};
20122013
ret mk_item(p, lo, dtor.span.hi, ident,
2013-
ast::item_res(decl, ty_params, dtor, p.get_id(), p.get_id()),
2014+
ast::item_res(decl, ty_params, dtor,
2015+
p.get_id(), p.get_id(), rp),
20142016
attrs);
20152017
}
20162018

@@ -2035,6 +2037,7 @@ fn parse_iface_ref_list(p:parser) -> [ast::iface_ref] {
20352037
fn parse_item_class(p: parser, attrs: [ast::attribute]) -> @ast::item {
20362038
let lo = p.last_span.lo;
20372039
let class_name = parse_value_ident(p);
2040+
let rp = parse_region_param(p);
20382041
let ty_params = parse_ty_params(p);
20392042
let class_path = ident_to_path_tys(p, class_name, ty_params);
20402043
let ifaces : [ast::iface_ref] = if eat_word(p, "implements")
@@ -2057,11 +2060,11 @@ fn parse_item_class(p: parser, attrs: [ast::attribute]) -> @ast::item {
20572060
some((ct_d, ct_b, ct_s)) {
20582061
ret mk_item(p, lo, p.last_span.hi, class_name,
20592062
ast::item_class(ty_params, ifaces, ms,
2060-
{node: {id: ctor_id,
2061-
self_id: p.get_id(),
2062-
dec: ct_d,
2063-
body: ct_b},
2064-
span: ct_s}), attrs); }
2063+
{node: {id: ctor_id,
2064+
self_id: p.get_id(),
2065+
dec: ct_d,
2066+
body: ct_b},
2067+
span: ct_s}, rp), attrs); }
20652068
/*
20662069
Is it strange for the parser to check this?
20672070
*/
@@ -2236,17 +2239,23 @@ fn parse_type_decl(p: parser) -> {lo: uint, ident: ast::ident} {
22362239

22372240
fn parse_item_type(p: parser, attrs: [ast::attribute]) -> @ast::item {
22382241
let t = parse_type_decl(p);
2242+
let rp = parse_region_param(p);
22392243
let tps = parse_ty_params(p);
22402244
expect(p, token::EQ);
22412245
let ty = parse_ty(p, false);
22422246
let mut hi = p.span.hi;
22432247
expect(p, token::SEMI);
2244-
ret mk_item(p, t.lo, hi, t.ident, ast::item_ty(ty, tps), attrs);
2248+
ret mk_item(p, t.lo, hi, t.ident, ast::item_ty(ty, tps, rp), attrs);
2249+
}
2250+
2251+
fn parse_region_param(p: parser) -> ast::region_param {
2252+
if eat(p, token::BINOP(token::AND)) {ast::rp_self} else {ast::rp_none}
22452253
}
22462254

22472255
fn parse_item_enum(p: parser, attrs: [ast::attribute]) -> @ast::item {
22482256
let lo = p.last_span.lo;
22492257
let id = parse_ident(p);
2258+
let rp = parse_region_param(p);
22502259
let ty_params = parse_ty_params(p);
22512260
let mut variants: [ast::variant] = [];
22522261
// Newtype syntax
@@ -2265,7 +2274,7 @@ fn parse_item_enum(p: parser, attrs: [ast::attribute]) -> @ast::item {
22652274
id: p.get_id(),
22662275
disr_expr: none});
22672276
ret mk_item(p, lo, ty.span.hi, id,
2268-
ast::item_enum([variant], ty_params), attrs);
2277+
ast::item_enum([variant], ty_params, rp), attrs);
22692278
}
22702279
expect(p, token::LBRACE);
22712280

@@ -2301,7 +2310,7 @@ fn parse_item_enum(p: parser, attrs: [ast::attribute]) -> @ast::item {
23012310
p.fatal("discriminator values can only be used with a c-like enum");
23022311
}
23032312
ret mk_item(p, lo, p.last_span.hi, id,
2304-
ast::item_enum(variants, ty_params), attrs);
2313+
ast::item_enum(variants, ty_params, rp), attrs);
23052314
}
23062315

23072316
fn parse_fn_ty_proto(p: parser) -> ast::proto {

trunk/src/librustsyntax/print/pprust.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ fn test_fun_to_str() {
125125
}
126126

127127
fn res_to_str(decl: ast::fn_decl, name: ast::ident,
128-
params: [ast::ty_param]) -> str {
128+
params: [ast::ty_param], rp: ast::region_param) -> str {
129129
let buffer = io::mem_buffer();
130130
let s = rust_printer(io::mem_buffer_writer(buffer));
131-
print_res(s, decl, name, params);
131+
print_res(s, decl, name, params, rp);
132132
end(s); // Close the head box
133133
end(s); // Close the outer box
134134
eof(s.s);
@@ -454,11 +454,12 @@ fn print_item(s: ps, &&item: @ast::item) {
454454
print_native_mod(s, nmod, item.attrs);
455455
bclose(s, item.span);
456456
}
457-
ast::item_ty(ty, params) {
457+
ast::item_ty(ty, params, rp) {
458458
ibox(s, indent_unit);
459459
ibox(s, 0u);
460460
word_nbsp(s, "type");
461461
word(s.s, item.ident);
462+
print_region_param(s, rp);
462463
print_type_params(s, params);
463464
end(s); // end the inner ibox
464465

@@ -468,7 +469,7 @@ fn print_item(s: ps, &&item: @ast::item) {
468469
word(s.s, ";");
469470
end(s); // end the outer ibox
470471
}
471-
ast::item_enum(variants, params) {
472+
ast::item_enum(variants, params, rp) {
472473
let newtype =
473474
vec::len(variants) == 1u &&
474475
str::eq(item.ident, variants[0].node.name) &&
@@ -478,6 +479,7 @@ fn print_item(s: ps, &&item: @ast::item) {
478479
word_space(s, "enum");
479480
} else { head(s, "enum"); }
480481
word(s.s, item.ident);
482+
print_region_param(s, rp);
481483
print_type_params(s, params);
482484
space(s.s);
483485
if newtype {
@@ -500,9 +502,10 @@ fn print_item(s: ps, &&item: @ast::item) {
500502
bclose(s, item.span);
501503
}
502504
}
503-
ast::item_class(tps,ifaces,items,ctor) {
505+
ast::item_class(tps,ifaces,items,ctor, rp) {
504506
head(s, "class");
505507
word_nbsp(s, item.ident);
508+
print_region_param(s, rp);
506509
print_type_params(s, tps);
507510
word_space(s, "implements");
508511
commasep(s, inconsistent, ifaces, {|s, p|
@@ -584,18 +587,19 @@ fn print_item(s: ps, &&item: @ast::item) {
584587
for methods.each {|meth| print_ty_method(s, meth); }
585588
bclose(s, item.span);
586589
}
587-
ast::item_res(decl, tps, body, dt_id, ct_id) {
588-
print_res(s, decl, item.ident, tps);
590+
ast::item_res(decl, tps, body, dt_id, ct_id, rp) {
591+
print_res(s, decl, item.ident, tps, rp);
589592
print_block(s, body);
590593
}
591594
}
592595
s.ann.post(ann_node);
593596
}
594597

595598
fn print_res(s: ps, decl: ast::fn_decl, name: ast::ident,
596-
typarams: [ast::ty_param]) {
599+
typarams: [ast::ty_param], rp: ast::region_param) {
597600
head(s, "resource");
598601
word(s.s, name);
602+
print_region_param(s, rp);
599603
print_type_params(s, typarams);
600604
popen(s);
601605
word_space(s, decl.inputs[0].ident + ":");
@@ -1401,6 +1405,13 @@ fn print_bounds(s: ps, bounds: @[ast::ty_param_bound]) {
14011405
}
14021406
}
14031407

1408+
fn print_region_param(s: ps, rp: ast::region_param) {
1409+
alt rp {
1410+
ast::rp_self { word(s.s, "&") }
1411+
ast::rp_none { }
1412+
}
1413+
}
1414+
14041415
fn print_type_params(s: ps, &&params: [ast::ty_param]) {
14051416
if vec::len(params) > 0u {
14061417
word(s.s, "<");

trunk/src/librustsyntax/visit.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ enum vt<E> { mk_vt(visitor<E>), }
1515
enum fn_kind {
1616
fk_item_fn(ident, [ty_param]), //< an item declared with fn()
1717
fk_method(ident, [ty_param], @method),
18-
fk_res(ident, [ty_param]),
18+
fk_res(ident, [ty_param], region_param),
1919
fk_anon(proto), //< an anonymous function like fn@(...)
2020
fk_fn_block, //< a block {||...}
2121
fk_ctor(ident, [ty_param], node_id /* self id */,
@@ -24,15 +24,15 @@ enum fn_kind {
2424

2525
fn name_of_fn(fk: fn_kind) -> ident {
2626
alt fk {
27-
fk_item_fn(name, _) | fk_method(name, _, _) | fk_res(name, _)
27+
fk_item_fn(name, _) | fk_method(name, _, _) | fk_res(name, _, _)
2828
| fk_ctor(name, _, _, _) { name }
2929
fk_anon(_) | fk_fn_block { "anon" }
3030
}
3131
}
3232

3333
fn tps_of_fn(fk: fn_kind) -> [ty_param] {
3434
alt fk {
35-
fk_item_fn(_, tps) | fk_method(_, tps, _) | fk_res(_, tps)
35+
fk_item_fn(_, tps) | fk_method(_, tps, _) | fk_res(_, tps, _)
3636
| fk_ctor(_, tps, _, _) { tps }
3737
fk_anon(_) | fk_fn_block { [] }
3838
}
@@ -118,12 +118,15 @@ fn visit_item<E>(i: @item, e: E, v: vt<E>) {
118118
for nm.view_items.each {|vi| v.visit_view_item(vi, e, v); }
119119
for nm.items.each {|ni| v.visit_native_item(ni, e, v); }
120120
}
121-
item_ty(t, tps) { v.visit_ty(t, e, v); v.visit_ty_params(tps, e, v); }
122-
item_res(decl, tps, body, dtor_id, _) {
123-
v.visit_fn(fk_res(i.ident, tps), decl, body, i.span,
121+
item_ty(t, tps, rp) {
122+
v.visit_ty(t, e, v);
123+
v.visit_ty_params(tps, e, v);
124+
}
125+
item_res(decl, tps, body, dtor_id, _, rp) {
126+
v.visit_fn(fk_res(i.ident, tps, rp), decl, body, i.span,
124127
dtor_id, e, v);
125128
}
126-
item_enum(variants, tps) {
129+
item_enum(variants, tps, _) {
127130
v.visit_ty_params(tps, e, v);
128131
for variants.each {|vr|
129132
for vr.node.args.each {|va| v.visit_ty(va.ty, e, v); }
@@ -137,7 +140,7 @@ fn visit_item<E>(i: @item, e: E, v: vt<E>) {
137140
visit_method_helper(m, e, v)
138141
}
139142
}
140-
item_class(tps, ifaces, members, ctor) {
143+
item_class(tps, ifaces, members, ctor, _) {
141144
v.visit_ty_params(tps, e, v);
142145
for members.each {|m|
143146
v.visit_class_item(m, e, v);

0 commit comments

Comments
 (0)