# HG changeset patch # User jwe # Date 909807618 0 # Node ID 549691faa6385d4003a328e4f47f60e3df4b3693 # Parent 81738e630f571692454aee497ee84d732cf5b4d1 [project @ 1998-10-31 04:20:15 by jwe] diff --git a/NEWS b/NEWS --- a/NEWS +++ b/NEWS @@ -1,6 +1,14 @@ Summary of changes for version 2.1.x: ------------------------------------ + * The ++ and -- operators now work for indexed matrices, and the + following operators now work: + + +=, -=, *=, /=, \=, <<=, >>=, .*=, ./=, .\=, &=, |= + + These operators are currently implemented using a relatively + inefficient brute-force method but hey, they work. + * The built-in variable argv is now a list of strings instead of a string vector. diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,10 @@ Fri Oct 30 08:39:30 1998 John W. Eaton + * oct-lvalue.cc (octave_lvalue::do_unary_op): Make it work for + indexed ops too. + * ov.cc (octave_value::unary_op_to_assign_op): New function. + (octave_value::do_non_const_unary_op): New function for indexed ops. + * parse.y (LEFTDIV_EQ, ELEFTDIV_EQ): New tokens. (assign_expr): Add rules for them. (make_assign_op): Handle them here too. diff --git a/src/oct-lvalue.cc b/src/oct-lvalue.cc --- a/src/oct-lvalue.cc +++ b/src/oct-lvalue.cc @@ -67,11 +67,7 @@ if (idx.empty ()) val->do_non_const_unary_op (op); else - { - string on = octave_value::unary_op_as_string (op); - error ("indexed operations not implemented yet for operator `%s'", - on.c_str ()); - } + val->do_non_const_unary_op (op, idx); if (chg_fcn && ! error_state && chg_fcn () < 0) *val = saved_val; diff --git a/src/ov.cc b/src/ov.cc --- a/src/ov.cc +++ b/src/ov.cc @@ -1229,6 +1229,30 @@ } } +static void +gripe_unary_op_failed_or_no_method (const string& on, const string& tn) +{ + error ("operator %s: no method, or unable to evaluate for %s operand", + on.c_str (), tn.c_str ()); +} + +void +octave_value::do_non_const_unary_op (octave_value::unary_op op, + const octave_value_list& idx) +{ + // XXX FIXME XXX -- only do the following stuff if we can't find a + // specific function to call to handle the op= operation for the + // types we have. + + assign_op assop = unary_op_to_assign_op (op); + + if (! error_state) + assign (assop, idx, 1.0); + else + gripe_unary_op_failed_or_no_method (unary_op_as_string (op), + type_name ()); +} + // Current indentation. int octave_value::curr_print_indent_level = 0; @@ -1275,6 +1299,31 @@ curr_print_indent_level = 0; } +octave_value::assign_op +octave_value::unary_op_to_assign_op (unary_op op) +{ + assign_op binop = unknown_assign_op; + + switch (op) + { + case incr: + binop = add_eq; + break; + + case decr: + binop = sub_eq; + break; + + default: + { + string on = unary_op_as_string (op); + error ("operator %s: no assign operator found", on.c_str ()); + } + } + + return binop; +} + octave_value::binary_op octave_value::op_eq_to_binary_op (assign_op op) { diff --git a/src/ov.h b/src/ov.h --- a/src/ov.h +++ b/src/ov.h @@ -471,6 +471,9 @@ void do_non_const_unary_op (octave_value::unary_op); + void do_non_const_unary_op (octave_value::unary_op, + const octave_value_list& idx); + friend octave_value do_binary_op (octave_value::binary_op, const octave_value&, const octave_value&); @@ -520,6 +523,8 @@ static int curr_print_indent_level; static bool beginning_of_line; + assign_op unary_op_to_assign_op (unary_op op); + binary_op op_eq_to_binary_op (assign_op op); void simple_assign (assign_op orig_op, const octave_value_list& idx,