mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Parse (and ignore) dtors on objs.
This commit is contained in:
parent
9869aebf7d
commit
64ab5eaaf0
@ -247,7 +247,8 @@ type method = spanned[method_];
|
||||
|
||||
type obj_field = rec(@ty ty, ident ident, def_id id, ann ann);
|
||||
type _obj = rec(vec[obj_field] fields,
|
||||
vec[@method] methods);
|
||||
vec[@method] methods,
|
||||
option.t[block] dtor);
|
||||
|
||||
tag mod_index_entry {
|
||||
mie_view_item(@view_item);
|
||||
|
@ -1715,21 +1715,33 @@ impure fn parse_item_obj(parser p, ast.layer lyr) -> @ast.item {
|
||||
some(token.COMMA),
|
||||
pf, p);
|
||||
|
||||
auto pm = parse_method;
|
||||
let util.common.spanned[vec[@ast.method]] meths =
|
||||
parse_seq[@ast.method]
|
||||
(token.LBRACE,
|
||||
token.RBRACE,
|
||||
none[token.token],
|
||||
pm, p);
|
||||
let vec[@ast.method] meths = vec();
|
||||
let option.t[ast.block] dtor = none[ast.block];
|
||||
|
||||
expect(p, token.LBRACE);
|
||||
while (p.peek() != token.RBRACE) {
|
||||
alt (p.peek()) {
|
||||
case (token.DROP) {
|
||||
p.bump();
|
||||
dtor = some[ast.block](parse_block(p));
|
||||
}
|
||||
case (_) {
|
||||
append[@ast.method](meths,
|
||||
parse_method(p));
|
||||
}
|
||||
}
|
||||
}
|
||||
auto hi = p.get_span();
|
||||
expect(p, token.RBRACE);
|
||||
|
||||
let ast._obj ob = rec(fields=fields.node,
|
||||
methods=meths.node);
|
||||
methods=meths,
|
||||
dtor=dtor);
|
||||
|
||||
auto item = ast.item_obj(ident, ob, ty_params,
|
||||
p.next_def_id(), ast.ann_none);
|
||||
|
||||
ret @spanned(lo, meths.span, item);
|
||||
ret @spanned(lo, hi, item);
|
||||
}
|
||||
|
||||
impure fn parse_mod_items(parser p, token.token term) -> ast._mod {
|
||||
|
@ -269,7 +269,8 @@ type ast_fold[ENV] =
|
||||
|
||||
(fn(&ENV e,
|
||||
vec[ast.obj_field] fields,
|
||||
vec[@ast.method] methods) -> ast._obj) fold_obj,
|
||||
vec[@ast.method] methods,
|
||||
option.t[block] dtor) -> ast._obj) fold_obj,
|
||||
|
||||
// Env updates.
|
||||
(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 {
|
||||
for (ast.obj_field f in ob.fields) {
|
||||
fields += fold_obj_field(env, fld, f);
|
||||
}
|
||||
let option.t[block] dtor = none[block];
|
||||
alt (ob.dtor) {
|
||||
case (none[block]) { }
|
||||
case (some[block](?b)) {
|
||||
dtor = some[block](fold_block[ENV](env, fld, b));
|
||||
}
|
||||
}
|
||||
let vec[ast.ty_param] tp = vec();
|
||||
for (@ast.method m in ob.methods) {
|
||||
// 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 {
|
||||
let ENV _env = fld.update_env_for_item(env, i);
|
||||
append[@ast.method](meths, fold_method(_env, fld, m));
|
||||
}
|
||||
ret fld.fold_obj(env, fields, meths);
|
||||
ret fld.fold_obj(env, fields, meths, dtor);
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
fn identity_fold_obj[ENV](&ENV e,
|
||||
vec[ast.obj_field] fields,
|
||||
vec[@ast.method] methods) -> ast._obj {
|
||||
ret rec(fields=fields, methods=methods);
|
||||
vec[@ast.method] methods,
|
||||
option.t[block] dtor) -> ast._obj {
|
||||
ret rec(fields=fields, methods=methods, dtor=dtor);
|
||||
}
|
||||
|
||||
|
||||
@ -1481,7 +1490,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
|
||||
fold_mod = bind identity_fold_mod[ENV](_,_),
|
||||
fold_native_mod = bind identity_fold_native_mod[ENV](_,_),
|
||||
fold_crate = bind identity_fold_crate[ENV](_,_,_),
|
||||
fold_obj = bind identity_fold_obj[ENV](_,_,_),
|
||||
fold_obj = bind identity_fold_obj[ENV](_,_,_,_),
|
||||
|
||||
update_env_for_crate = bind identity_update_env_for_crate[ENV](_,_),
|
||||
update_env_for_item = bind identity_update_env_for_item[ENV](_,_),
|
||||
|
Loading…
Reference in New Issue
Block a user