From 87b064b249657c8e65079d01beb77409f69d49cd Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Thu, 26 Jan 2012 12:26:14 +0100 Subject: First stab at operator overloading When no built-in interpretation is found for one of the operators mentioned below, the typechecker will try to turn it into a method call with the name written next to it. For binary operators, the method will be called on the LHS with the RHS as only parameter. Binary: + op_add - op_sub * op_mul / op_div % op_rem & op_and | op_or ^ op_xor << op_shift_left >> op_shift_right >>> op_ashift_right Unary: - op_neg ! op_not Overloading of the indexing ([]) operator isn't finished yet. Issue #1520 --- src/comp/syntax/parse/parser.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/comp/syntax/parse') diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index a66b223175c..1e892eb43b1 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -1048,6 +1048,7 @@ fn parse_prefix_expr(p: parser) -> pexpr { p.bump(); let e = to_expr(parse_prefix_expr(p)); hi = e.span.hi; + p.get_id(); // see ast_util::op_expr_callee_id ex = ast::expr_unary(ast::not, e); } token::BINOP(b) { @@ -1056,6 +1057,7 @@ fn parse_prefix_expr(p: parser) -> pexpr { p.bump(); let e = to_expr(parse_prefix_expr(p)); hi = e.span.hi; + p.get_id(); // see ast_util::op_expr_callee_id ex = ast::expr_unary(ast::neg, e); } token::STAR { @@ -1146,6 +1148,7 @@ fn parse_more_binops(p: parser, plhs: pexpr, min_prec: int) -> p.bump(); let expr = parse_prefix_expr(p); let rhs = parse_more_binops(p, expr, cur.prec); + p.get_id(); // see ast_util::op_expr_callee_id let bin = mk_pexpr(p, lhs.span.lo, rhs.span.hi, ast::expr_binary(cur.op, lhs, rhs)); ret parse_more_binops(p, bin, min_prec); @@ -1186,6 +1189,7 @@ fn parse_assign_expr(p: parser) -> @ast::expr { token::LSR { aop = ast::lsr; } token::ASR { aop = ast::asr; } } + p.get_id(); // see ast_util::op_expr_callee_id ret mk_expr(p, lo, rhs.span.hi, ast::expr_assign_op(aop, lhs, rhs)); } token::LARROW { -- cgit 1.4.1-3-g733a5