# HG changeset patch # User Jaroslav Hajek # Date 1273324522 -7200 # Node ID d1194069e58cdeafe34f152004164b33ac13a2dd # Parent e103fb2182cebbfe29b0da6a3c96566d571e76d9 optimize code handling ++,-- diff -r e103fb2182ce -r d1194069e58c src/ChangeLog --- a/src/ChangeLog Fri May 07 15:58:51 2010 -0400 +++ b/src/ChangeLog Sat May 08 15:15:22 2010 +0200 @@ -1,3 +1,11 @@ +2010-05-08 Jaroslav Hajek + + * ov.cc (octave_value::do_non_const_unary_op): Always return *this as + octave_value&. Remove unused overload. + * oct-lvalue.cc (octave_lvalue::do_unary_op): Simplify. + * pt-unop.cc (tree_prefix_expression::rvalue1, + tree_postfix_expression::rvalue1): Remove dummy rvalue1 calls. + 2010-05-07 Michael Goffioul * ov-base.h (Vsparse_auto_mutate): Add OCTINTERP_API tag. diff -r e103fb2182ce -r d1194069e58c src/oct-lvalue.cc --- a/src/oct-lvalue.cc Fri May 07 15:58:51 2010 -0400 +++ b/src/oct-lvalue.cc Sat May 08 15:15:22 2010 +0200 @@ -60,12 +60,10 @@ { if (val) { - octave_value tmp (idx.empty () - ? val->do_non_const_unary_op (op) - : val->do_non_const_unary_op (op, type, idx)); - - if (! error_state) - *val = tmp; + if (idx.empty ()) + val->do_non_const_unary_op (op); + else + val->do_non_const_unary_op (op, type, idx); } else error ("internal: invalid operation on ~"); diff -r e103fb2182ce -r d1194069e58c src/ov.cc --- a/src/ov.cc Fri May 07 15:58:51 2010 -0400 +++ b/src/ov.cc Sat May 08 15:15:22 2010 +0200 @@ -2328,11 +2328,22 @@ op.c_str (), tn.c_str ()); } -const octave_value& +octave_value& octave_value::do_non_const_unary_op (unary_op op) { if (op == op_incr || op == op_decr) { + // We want the gripe just here, because in the other branch this should + // not happen, and if it did anyway (internal error), the message would + // be confusing. + if (is_undefined ()) + { + std::string op_str = unary_op_as_string (op); + error ("in x%s or %sx, x must be defined first", + op_str.c_str (), op_str.c_str ()); + return *this; + } + // Genuine. int t = type_id (); @@ -2434,34 +2445,12 @@ return *this; } -#if 0 -static void -gripe_unary_op_failed_or_no_method (const std::string& on, - const std::string& tn) -{ - error ("operator %s: no method, or unable to evaluate for %s operand", - on.c_str (), tn.c_str ()); -} -#endif - -void -octave_value::do_non_const_unary_op (unary_op, const octave_value_list&) -{ - abort (); -} - -octave_value +octave_value& octave_value::do_non_const_unary_op (unary_op op, const std::string& type, const std::list& idx) { - octave_value retval; - if (idx.empty ()) - { - do_non_const_unary_op (op); - - retval = *this; - } + do_non_const_unary_op (op); else { // FIXME -- only do the following stuff if we can't find a @@ -2470,10 +2459,10 @@ assign_op assop = unary_op_to_assign_op (op); - retval = assign (assop, type, idx, 1.0); + assign (assop, type, idx, 1.0); } - return retval; + return *this; } octave_value::assign_op diff -r e103fb2182ce -r d1194069e58c src/ov.h --- a/src/ov.h Fri May 07 15:58:51 2010 -0400 +++ b/src/ov.h Sat May 08 15:15:22 2010 +0200 @@ -984,11 +984,9 @@ friend OCTINTERP_API octave_value do_unary_op (unary_op op, const octave_value& a); - const octave_value& do_non_const_unary_op (unary_op op); + octave_value& do_non_const_unary_op (unary_op op); - void do_non_const_unary_op (unary_op op, const octave_value_list& idx); - - octave_value do_non_const_unary_op (unary_op op, const std::string& type, + octave_value& do_non_const_unary_op (unary_op op, const std::string& type, const std::list& idx); friend OCTINTERP_API octave_value do_binary_op (binary_op op, diff -r e103fb2182ce -r d1194069e58c src/pt-unop.cc --- a/src/pt-unop.cc Fri May 07 15:58:51 2010 -0400 +++ b/src/pt-unop.cc Sat May 08 15:15:22 2010 +0200 @@ -69,18 +69,14 @@ { if (etype == octave_value::op_incr || etype == octave_value::op_decr) { - op->rvalue1 (); + octave_lvalue ref = op->lvalue (); if (! error_state) { - octave_lvalue ref = op->lvalue (); + ref.do_unary_op (etype); - if (! error_state && ref.is_defined ()) - { - ref.do_unary_op (etype); - - retval = ref.value (); - } + if (! error_state) + retval = ref.value (); } } else @@ -152,18 +148,13 @@ { if (etype == octave_value::op_incr || etype == octave_value::op_decr) { - op->rvalue1 (); + octave_lvalue ref = op->lvalue (); if (! error_state) { - octave_lvalue ref = op->lvalue (); + retval = ref.value (); - if (! error_state && ref.is_defined ()) - { - retval = ref.value (); - - ref.do_unary_op (etype); - } + ref.do_unary_op (etype); } } else