Make uses of self in impls compile
Get rid of expr_self_call, introduces def_self. `self` is now, syntactically, simply a variable. A method implicitly brings a `self` binding into scope. Issue #1227
This commit is contained in:
parent
1dd2f1ec03
commit
7efef98901
17 changed files with 137 additions and 203 deletions
|
|
@ -28,13 +28,13 @@ type ty_param = {ident: ident, kind: kind};
|
|||
tag def {
|
||||
def_fn(def_id, purity);
|
||||
def_obj_field(def_id, mutability);
|
||||
def_self(def_id);
|
||||
def_mod(def_id);
|
||||
def_native_mod(def_id);
|
||||
def_const(def_id);
|
||||
def_arg(def_id, mode);
|
||||
def_local(def_id, let_style);
|
||||
def_variant(def_id /* tag */, def_id /* variant */);
|
||||
def_self(def_id);
|
||||
def_ty(def_id);
|
||||
def_ty_param(uint, kind);
|
||||
def_binding(def_id);
|
||||
|
|
@ -214,7 +214,6 @@ tag expr_ {
|
|||
expr_rec([field], option::t<@expr>);
|
||||
expr_call(@expr, [@expr], bool);
|
||||
expr_tup([@expr]);
|
||||
expr_self_method(ident);
|
||||
expr_bind(@expr, [option::t<@expr>]);
|
||||
expr_binary(binop, @expr, @expr);
|
||||
expr_unary(unop, @expr);
|
||||
|
|
|
|||
|
|
@ -353,7 +353,6 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
|
|||
expr_call(fld.fold_expr(f), fld.map_exprs(fld.fold_expr, args),
|
||||
blk)
|
||||
}
|
||||
expr_self_method(id) { expr_self_method(fld.fold_ident(id)) }
|
||||
expr_bind(f, args) {
|
||||
let opt_map_se = bind option::map(fld.fold_expr, _);
|
||||
expr_bind(fld.fold_expr(f), vec::map(opt_map_se, args))
|
||||
|
|
|
|||
|
|
@ -155,8 +155,7 @@ fn bad_expr_word_table() -> hashmap<str, ()> {
|
|||
"cont", "ret", "be", "fail", "type", "resource", "check",
|
||||
"assert", "claim", "native", "fn", "lambda", "pure",
|
||||
"unsafe", "block", "import", "export", "let", "const",
|
||||
"log", "log_err", "tag", "obj", "self", "copy", "sendfn",
|
||||
"impl"] {
|
||||
"log", "log_err", "tag", "obj", "copy", "sendfn", "impl"] {
|
||||
words.insert(word, ());
|
||||
}
|
||||
words
|
||||
|
|
@ -942,15 +941,6 @@ fn parse_bottom_expr(p: parser) -> @ast::expr {
|
|||
let e = parse_expr(p);
|
||||
ex = ast::expr_copy(e);
|
||||
hi = e.span.hi;
|
||||
} else if is_word(p, "self") && p.look_ahead(1u) == token::DOT {
|
||||
p.bump(); p.bump();
|
||||
// The rest is a call expression.
|
||||
let f: @ast::expr = parse_self_method(p);
|
||||
let es =
|
||||
parse_seq(token::LPAREN, token::RPAREN, seq_sep(token::COMMA),
|
||||
parse_expr, p);
|
||||
hi = es.span.hi;
|
||||
ex = ast::expr_call(f, es.node, false);
|
||||
} else if p.peek() == token::MOD_SEP ||
|
||||
is_ident(p.peek()) && !is_word(p, "true") &&
|
||||
!is_word(p, "false") {
|
||||
|
|
@ -998,12 +988,6 @@ fn parse_syntax_ext_naked(p: parser, lo: uint) -> @ast::expr {
|
|||
ret mk_mac_expr(p, lo, hi, ast::mac_invoc(pth, e, none));
|
||||
}
|
||||
|
||||
fn parse_self_method(p: parser) -> @ast::expr {
|
||||
let sp = p.get_span();
|
||||
let f_name: ast::ident = parse_ident(p);
|
||||
ret mk_expr(p, sp.lo, sp.hi, ast::expr_self_method(f_name));
|
||||
}
|
||||
|
||||
fn parse_dot_or_call_expr(p: parser) -> @ast::expr {
|
||||
let b = parse_bottom_expr(p);
|
||||
if expr_has_value(b) { parse_dot_or_call_expr_with(p, b) }
|
||||
|
|
|
|||
|
|
@ -736,10 +736,6 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
|
|||
print_expr(s, option::get(blk));
|
||||
}
|
||||
}
|
||||
ast::expr_self_method(ident) {
|
||||
word(s.s, "self.");
|
||||
print_ident(s, ident);
|
||||
}
|
||||
ast::expr_bind(func, args) {
|
||||
fn print_opt(s: ps, expr: option::t<@ast::expr>) {
|
||||
alt expr {
|
||||
|
|
|
|||
|
|
@ -251,7 +251,6 @@ fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) {
|
|||
visit_exprs(args, e, v);
|
||||
v.visit_expr(callee, e, v);
|
||||
}
|
||||
expr_self_method(_) { }
|
||||
expr_bind(callee, args) {
|
||||
v.visit_expr(callee, e, v);
|
||||
for eo: option::t<@expr> in args { visit_expr_opt(eo, e, v); }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue