Skip to content

Commit 23a86d4

Browse files
committed
---
yaml --- r: 1465 b: refs/heads/master c: 64ab5ea h: refs/heads/master i: 1463: 1192503 v: v3
1 parent a121b27 commit 23a86d4

File tree

4 files changed

+38
-16
lines changed

4 files changed

+38
-16
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 9869aebf7d21e5076e16193f2fad9c7f9446fdc6
2+
refs/heads/master: 64ab5eaaf09de6a75392554c13784c492ed19465

trunk/src/comp/front/ast.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ type method = spanned[method_];
247247

248248
type obj_field = rec(@ty ty, ident ident, def_id id, ann ann);
249249
type _obj = rec(vec[obj_field] fields,
250-
vec[@method] methods);
250+
vec[@method] methods,
251+
option.t[block] dtor);
251252

252253
tag mod_index_entry {
253254
mie_view_item(@view_item);

trunk/src/comp/front/parser.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,21 +1715,33 @@ impure fn parse_item_obj(parser p, ast.layer lyr) -> @ast.item {
17151715
some(token.COMMA),
17161716
pf, p);
17171717

1718-
auto pm = parse_method;
1719-
let util.common.spanned[vec[@ast.method]] meths =
1720-
parse_seq[@ast.method]
1721-
(token.LBRACE,
1722-
token.RBRACE,
1723-
none[token.token],
1724-
pm, p);
1718+
let vec[@ast.method] meths = vec();
1719+
let option.t[ast.block] dtor = none[ast.block];
1720+
1721+
expect(p, token.LBRACE);
1722+
while (p.peek() != token.RBRACE) {
1723+
alt (p.peek()) {
1724+
case (token.DROP) {
1725+
p.bump();
1726+
dtor = some[ast.block](parse_block(p));
1727+
}
1728+
case (_) {
1729+
append[@ast.method](meths,
1730+
parse_method(p));
1731+
}
1732+
}
1733+
}
1734+
auto hi = p.get_span();
1735+
expect(p, token.RBRACE);
17251736

17261737
let ast._obj ob = rec(fields=fields.node,
1727-
methods=meths.node);
1738+
methods=meths,
1739+
dtor=dtor);
17281740

17291741
auto item = ast.item_obj(ident, ob, ty_params,
17301742
p.next_def_id(), ast.ann_none);
17311743

1732-
ret @spanned(lo, meths.span, item);
1744+
ret @spanned(lo, hi, item);
17331745
}
17341746

17351747
impure fn parse_mod_items(parser p, token.token term) -> ast._mod {

trunk/src/comp/middle/fold.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ type ast_fold[ENV] =
269269

270270
(fn(&ENV e,
271271
vec[ast.obj_field] fields,
272-
vec[@ast.method] methods) -> ast._obj) fold_obj,
272+
vec[@ast.method] methods,
273+
option.t[block] dtor) -> ast._obj) fold_obj,
273274

274275
// Env updates.
275276
(fn(&ENV e, @ast.crate c) -> ENV) update_env_for_crate,
@@ -791,6 +792,13 @@ fn fold_obj[ENV](&ENV env, ast_fold[ENV] fld, &ast._obj ob) -> ast._obj {
791792
for (ast.obj_field f in ob.fields) {
792793
fields += fold_obj_field(env, fld, f);
793794
}
795+
let option.t[block] dtor = none[block];
796+
alt (ob.dtor) {
797+
case (none[block]) { }
798+
case (some[block](?b)) {
799+
dtor = some[block](fold_block[ENV](env, fld, b));
800+
}
801+
}
794802
let vec[ast.ty_param] tp = vec();
795803
for (@ast.method m in ob.methods) {
796804
// Fake-up an ast.item for this method.
@@ -805,7 +813,7 @@ fn fold_obj[ENV](&ENV env, ast_fold[ENV] fld, &ast._obj ob) -> ast._obj {
805813
let ENV _env = fld.update_env_for_item(env, i);
806814
append[@ast.method](meths, fold_method(_env, fld, m));
807815
}
808-
ret fld.fold_obj(env, fields, meths);
816+
ret fld.fold_obj(env, fields, meths, dtor);
809817
}
810818

811819
fn fold_view_item[ENV](&ENV env, ast_fold[ENV] fld, @view_item vi)
@@ -1334,8 +1342,9 @@ fn identity_fold_crate[ENV](&ENV e, &span sp, &ast._mod m) -> @ast.crate {
13341342

13351343
fn identity_fold_obj[ENV](&ENV e,
13361344
vec[ast.obj_field] fields,
1337-
vec[@ast.method] methods) -> ast._obj {
1338-
ret rec(fields=fields, methods=methods);
1345+
vec[@ast.method] methods,
1346+
option.t[block] dtor) -> ast._obj {
1347+
ret rec(fields=fields, methods=methods, dtor=dtor);
13391348
}
13401349

13411350

@@ -1481,7 +1490,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
14811490
fold_mod = bind identity_fold_mod[ENV](_,_),
14821491
fold_native_mod = bind identity_fold_native_mod[ENV](_,_),
14831492
fold_crate = bind identity_fold_crate[ENV](_,_,_),
1484-
fold_obj = bind identity_fold_obj[ENV](_,_,_),
1493+
fold_obj = bind identity_fold_obj[ENV](_,_,_,_),
14851494

14861495
update_env_for_crate = bind identity_update_env_for_crate[ENV](_,_),
14871496
update_env_for_item = bind identity_update_env_for_item[ENV](_,_),

0 commit comments

Comments
 (0)