diff options
| author | Graydon Hoare <[email protected]> | 2011-03-01 17:32:16 -0800 |
|---|---|---|
| committer | Graydon Hoare <[email protected]> | 2011-03-01 17:33:17 -0800 |
| commit | 64ab5eaaf09de6a75392554c13784c492ed19465 (patch) | |
| tree | 2c166a5924fcae5971dad486f42cc25d913c6d95 /src | |
| parent | rustc: Remove the static "size" field from the tag info (diff) | |
| download | rust-64ab5eaaf09de6a75392554c13784c492ed19465.tar.xz rust-64ab5eaaf09de6a75392554c13784c492ed19465.zip | |
Parse (and ignore) dtors on objs.
Diffstat (limited to 'src')
| -rw-r--r-- | src/comp/front/ast.rs | 3 | ||||
| -rw-r--r-- | src/comp/front/parser.rs | 30 | ||||
| -rw-r--r-- | src/comp/middle/fold.rs | 19 |
3 files changed, 37 insertions, 15 deletions
diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs index 9b995f9a..4ed513a3 100644 --- a/src/comp/front/ast.rs +++ b/src/comp/front/ast.rs @@ -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); diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index 696140b1..f747c084 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -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 { diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs index 65bbe602..09783070 100644 --- a/src/comp/middle/fold.rs +++ b/src/comp/middle/fold.rs @@ -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](_,_), |