diff options
| author | Marijn Haverbeke <marijnh@gmail.com> | 2012-01-26 12:26:14 +0100 |
|---|---|---|
| committer | Marijn Haverbeke <marijnh@gmail.com> | 2012-01-26 14:25:06 +0100 |
| commit | 87b064b249657c8e65079d01beb77409f69d49cd (patch) | |
| tree | cecb525f7ddf7312521d1a65e93ea8531f23426e /src/comp/syntax/parse/parser.rs | |
| parent | 1792d9ec96d680cb3ec257bfef84baffea352d80 (diff) | |
| download | rust-87b064b249657c8e65079d01beb77409f69d49cd.tar.gz rust-87b064b249657c8e65079d01beb77409f69d49cd.zip | |
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
Diffstat (limited to 'src/comp/syntax/parse/parser.rs')
| -rw-r--r-- | src/comp/syntax/parse/parser.rs | 4 |
1 files changed, 4 insertions, 0 deletions
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 { |
