From 814b17352c5b5267e29f73a6ddf93f97030ac62c Mon Sep 17 00:00:00 2001 From: Lindsey Kuper Date: Fri, 13 May 2011 11:00:26 -0700 Subject: [PATCH] Use new module namespace syntax. --- src/comp/front/ast.rs | 4 +- src/comp/front/parser.rs | 122 ++++++++++++++++++--------------------- src/comp/middle/fold.rs | 60 +++++++++---------- src/comp/middle/trans.rs | 2 +- 4 files changed, 90 insertions(+), 98 deletions(-) diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs index eda09276184..d795d6c2363 100644 --- a/src/comp/front/ast.rs +++ b/src/comp/front/ast.rs @@ -374,10 +374,10 @@ type _obj = rec(vec[obj_field] fields, type anon_obj = rec( // New fields and methods, if they exist. - Option.t[vec[obj_field]] fields, + option::t[vec[obj_field]] fields, vec[@method] methods, // with_obj: the original object being extended, if it exists. - Option.t[ident] with_obj); + option::t[ident] with_obj); type _mod = rec(vec[@view_item] view_items, vec[@item] items); diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index a02a2fa4b0b..8eb6c398f9c 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -773,6 +773,63 @@ fn parse_bottom_expr(parser p) -> @ast::expr { some(token::COMMA), pf, hi, p); ex = ast::expr_vec(es, mut, p.get_ann()); + } else if (eat_word(p, "obj")) { + // Anonymous object + + // FIXME: Can anonymous objects have ty params? + auto ty_params = parse_ty_params(p); + + // Only make people type () if they're actually adding new fields + let option::t[vec[ast::obj_field]] fields = + none[vec[ast::obj_field]]; + if (p.peek() == token::LPAREN) { + auto pf = parse_obj_field; + hi = p.get_hi_pos(); + expect(p, token::LPAREN); + + + fields = some[vec[ast::obj_field]] + (parse_seq_to_end[ast::obj_field] + (token::RPAREN, + some(token::COMMA), + pf, hi, p)); + } + + let vec[@ast::method] meths = vec(); + let option::t[ast::ident] with_obj = none[ast::ident]; + + expect(p, token::LBRACE); + + while (p.peek() != token::RBRACE) { + alt (p.peek()) { + case (token::WITH) { + p.bump(); + with_obj = some[ast::ident](parse_ident(p)); + } + case (_) { + _vec::push[@ast::method](meths, + parse_method(p)); + } + } + } + + hi = p.get_hi_pos(); + expect(p, token::RBRACE); + + // fields and methods may be *additional* or *overriding* fields + // and methods if there's a with_obj, or they may be the *only* + // fields and methods if there's no with_obj. + + // We don't need to pull ".node" out of fields because it's not a + // "spanned". + let ast::anon_obj ob = rec(fields=fields, + methods=meths, + with_obj=with_obj); + + auto odid = rec(ty=p.next_def_id(), ctor=p.next_def_id()); + + ex = ast::expr_anon_obj(ob, ty_params, odid, p.get_ann()); + } else if (eat_word(p, "rec")) { expect(p, token::LPAREN); auto fields = vec(parse_field(p)); @@ -798,71 +855,6 @@ fn parse_bottom_expr(parser p) -> @ast::expr { } ex = ast::expr_rec(fields, base, p.get_ann()); - } - // Anonymous object - else if (eat_word(p, "obj")) { - - // FIXME: Can anonymous objects have ty params? - auto ty_params = parse_ty_params(p); - - // Only make people type () if they're actually adding new fields - let option.t[vec[ast::obj_field]] fields = none[vec[ast::obj_field]]; - if (p.peek() == token::LPAREN) { - auto pf = parse_obj_field; - expect(p, token::LBRACE); - while (p.peek() != token::RBRACE) { - alt (p.peek()) { - case (token.WITH) { - p.bump(); - with_obj = some[ast::ident](parse_ident(p)); - } - case (_) { - Vec.push[@ast::method](meths, - parse_method(p)); - } - } - } - - hi = p.get_hi_pos(); - expect(p, token::LPAREN); - fields = some[vec[ast::obj_field]] - (parse_seq_to_end[ast::obj_field] - (token::RPAREN, - some(token::COMMA), - pf, hi, p)); - } - - let vec[@ast::method] meths = vec(); - let option.t[ast::ident] with_obj = none[ast::ident]; - - expect(p, token::LBRACE); - while (p.peek() != token::RBRACE) { - alt (p.peek()) { - case (token::WITH) { - with_obj = some[ast::ident](parse_ident(p)); - } - case (_) { - // fall through - } - } - } - hi = p.get_hi_pos(); - expect(p, token::RBRACE); - - // fields and methods may be *additional* or *overriding* fields and - // methods if there's a with_obj, or they may be the *only* fields and - // methods if there's no with_obj. - - // We don't need to pull ".node" out of fields because it's not a - // "spanned". - let ast::anon_obj ob = rec(fields=fields, - methods=meths, - with_obj=with_obj); - - auto odid = rec(ty=p.next_def_id(), ctor=p.next_def_id()); - - ex = ast::expr_anon_obj(ob, ty_params, odid, ast::ann_none); - } else if (eat_word(p, "bind")) { auto e = parse_expr_res(p, RESTRICT_NO_CALL_EXPRS); fn parse_expr_opt(parser p) -> option::t[@ast::expr] { diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs index 7d0fa9946a0..bd5f93f94d6 100644 --- a/src/comp/middle/fold.rs +++ b/src/comp/middle/fold.rs @@ -210,9 +210,9 @@ type ast_fold[ENV] = &@expr e, &ann a) -> @expr) fold_expr_chan, (fn(&ENV e, &span sp, - &ast.anon_obj ob, // TODO: Is the ob arg supposed to be & or not? - vec[ast.ty_param] tps, - ast.obj_def_ids odid, ann a) -> @expr) fold_expr_anon_obj, + &ast::anon_obj ob, // TODO: Is the ob arg supposed to be & or not? + vec[ast::ty_param] tps, + ast::obj_def_ids odid, ann a) -> @expr) fold_expr_anon_obj, // Decl folds. (fn(&ENV e, &span sp, @@ -327,9 +327,9 @@ type ast_fold[ENV] = -> ast::_obj) fold_obj, (fn(&ENV e, - Option.t[vec[ast.obj_field]] fields, - vec[@ast.method] methods, - Option.t[ident] with_obj) -> ast.anon_obj) fold_anon_obj, + option::t[vec[ast::obj_field]] fields, + vec[@ast::method] methods, + option::t[ident] with_obj) -> ast::anon_obj) fold_anon_obj, // Env updates. (fn(&ENV e, &@ast::crate c) -> ENV) update_env_for_crate, @@ -838,7 +838,7 @@ fn fold_expr[ENV](&ENV env, &ast_fold[ENV] fld, &@expr e) -> @expr { ret fld.fold_expr_chan(env_, e.span, ee, t2); } - case (ast.expr_anon_obj(?ob, ?tps, ?odid, ?t)) { + case (ast::expr_anon_obj(?ob, ?tps, ?odid, ?t)) { auto ee = fold_anon_obj(env_, fld, ob); auto t2 = fld.fold_ann(env_, t); ret fld.fold_expr_anon_obj(env_, e.span, ee, tps, odid, t2); @@ -976,45 +976,45 @@ fn fold_obj[ENV](&ENV env, &ast_fold[ENV] fld, &ast::_obj ob) -> ast::_obj { ret fld.fold_obj(env, fields, meths, dtor); } -fn fold_anon_obj[ENV](&ENV env, ast_fold[ENV] fld, &ast.anon_obj ob) - -> ast.anon_obj { +fn fold_anon_obj[ENV](&ENV env, ast_fold[ENV] fld, &ast::anon_obj ob) + -> ast::anon_obj { // Fields - let Option.t[vec[ast.obj_field]] fields = none[vec[ast.obj_field]]; + let option::t[vec[ast::obj_field]] fields = none[vec[ast::obj_field]]; alt (ob.fields) { - case (none[vec[ast.obj_field]]) { } - case (some[vec[ast.obj_field]](?v)) { - let vec[ast.obj_field] fields = vec(); - for (ast.obj_field f in v) { + case (none[vec[ast::obj_field]]) { } + case (some[vec[ast::obj_field]](?v)) { + let vec[ast::obj_field] fields = vec(); + for (ast::obj_field f in v) { fields += vec(fold_obj_field(env, fld, f)); } } } // with_obj - let Option.t[ast.ident] with_obj = none[ast.ident]; + let option::t[ast::ident] with_obj = none[ast::ident]; alt (ob.with_obj) { - case (none[ast.ident]) { } - case (some[ast.ident](?i)) { - with_obj = some[ast.ident](i); + case (none[ast::ident]) { } + case (some[ast::ident](?i)) { + with_obj = some[ast::ident](i); } } // Methods - let vec[@ast.method] meths = vec(); - let vec[ast.ty_param] tp = vec(); - for (@ast.method m in ob.methods) { - // Fake-up an ast.item for this method. + let vec[@ast::method] meths = vec(); + let vec[ast::ty_param] tp = vec(); + for (@ast::method m in ob.methods) { + // Fake-up an ast::item for this method. // FIXME: this is kinda awful. Maybe we should reformulate // the way we store methods in the AST? - let @ast.item i = @rec(node=ast.item_fn(m.node.ident, + let @ast::item i = @rec(node=ast::item_fn(m.node.ident, m.node.meth, tp, m.node.id, m.node.ann), span=m.span); let ENV _env = fld.update_env_for_item(env, i); - Vec.push[@ast.method](meths, fold_method(_env, fld, m)); + _vec::push[@ast::method](meths, fold_method(_env, fld, m)); } ret fld.fold_anon_obj(env, fields, meths, with_obj); } @@ -1468,9 +1468,9 @@ fn identity_fold_expr_chan[ENV](&ENV e, &span sp, &@expr x, } fn identity_fold_expr_anon_obj[ENV](&ENV e, &span sp, - &ast.anon_obj ob, vec[ast.ty_param] tps, - ast.obj_def_ids odid, ann a) -> @expr { - ret @respan(sp, ast.expr_anon_obj(ob, tps, odid, a)); + &ast::anon_obj ob, vec[ast::ty_param] tps, + ast::obj_def_ids odid, ann a) -> @expr { + ret @respan(sp, ast::expr_anon_obj(ob, tps, odid, a)); } // Decl identities. @@ -1648,9 +1648,9 @@ fn identity_fold_obj[ENV](&ENV e, } fn identity_fold_anon_obj[ENV](&ENV e, - Option.t[vec[ast.obj_field]] fields, - vec[@ast.method] methods, - Option.t[ident] with_obj) -> ast.anon_obj { + option::t[vec[ast::obj_field]] fields, + vec[@ast::method] methods, + option::t[ident] with_obj) -> ast::anon_obj { ret rec(fields=fields, methods=methods, with_obj=with_obj); } diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index fa50d857ae9..fdc32f1108e 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -2889,7 +2889,7 @@ fn iter_sequence(@block_ctxt cx, cx.fcx.lcx.ccx.sess.bug("unexpected type in " + "trans::iter_sequence: " + - ty.ty_to_str(cx.fcx.lcx.ccx.tcx, t)); + ty::ty_to_str(cx.fcx.lcx.ccx.tcx, t)); fail; } }