diff options
| author | Graydon Hoare <[email protected]> | 2011-04-14 16:50:48 -0700 |
|---|---|---|
| committer | Graydon Hoare <[email protected]> | 2011-04-14 16:50:59 -0700 |
| commit | 232c4509574bd27605dfa93890670e1ae1366e31 (patch) | |
| tree | fddaed0c44cb9b15355c20c37e00cec21d1d3df1 /src/comp/front/parser.rs | |
| parent | rustc: Use the unified result for the type of assignment expressions (diff) | |
| download | rust-232c4509574bd27605dfa93890670e1ae1366e31.tar.xz rust-232c4509574bd27605dfa93890670e1ae1366e31.zip | |
Work on destructors, not entirely functional yet (no tydesc integration).
Diffstat (limited to 'src/comp/front/parser.rs')
| -rw-r--r-- | src/comp/front/parser.rs | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index ab44f638..2e6e7c29 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -1823,6 +1823,25 @@ impure fn parse_method(parser p) -> @ast.method { ret @spanned(lo, f.body.span.hi, meth); } +impure fn parse_dtor(parser p) -> @ast.method { + auto lo = p.get_lo_pos(); + expect(p, token.DROP); + let ast.block b = parse_block(p); + let vec[ast.arg] inputs = vec(); + let @ast.ty output = @spanned(lo, lo, ast.ty_nil); + let ast.fn_decl d = rec(effect=ast.eff_pure, + inputs=inputs, + output=output); + let ast._fn f = rec(decl = d, + proto = ast.proto_fn, + body = b); + let ast.method_ m = rec(ident="drop", + meth=f, + id=p.next_def_id(), + ann=ast.ann_none); + ret @spanned(lo, f.body.span.hi, m); +} + impure fn parse_item_obj(parser p, ast.layer lyr) -> @ast.item { auto lo = p.get_lo_pos(); expect(p, token.OBJ); @@ -1837,14 +1856,13 @@ impure fn parse_item_obj(parser p, ast.layer lyr) -> @ast.item { pf, p); let vec[@ast.method] meths = vec(); - let option.t[ast.block] dtor = none[ast.block]; + let option.t[@ast.method] dtor = none[@ast.method]; expect(p, token.LBRACE); while (p.peek() != token.RBRACE) { alt (p.peek()) { case (token.DROP) { - p.bump(); - dtor = some[ast.block](parse_block(p)); + dtor = some[@ast.method](parse_dtor(p)); } case (_) { _vec.push[@ast.method](meths, |