Mercurial > hg > octave-terminal
changeset 10227:d3fc22c3071c
omit ~ values from multi-assignment return lists
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Sat, 30 Jan 2010 06:03:19 +0100 |
parents | 2884758e265b |
children | fa0c28aff439 |
files | src/ChangeLog src/oct-lvalue.cc src/oct-lvalue.h src/pt-assign.cc |
diffstat | 4 files changed, 54 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2010-01-30 Jaroslav Hajek <highegg@gmail.com> + + * oct-lvalue.h (octave_lvalue::black_hole): Remove field. + (octave_lvalue::(all methods)): Update. + * oct-lvalue.cc: Ditto. + 2010-01-29 David Grundberg <davidg@cs.umu.se> * mex.cc (mex::realloc): Allocate new memory if the argument is
--- a/src/oct-lvalue.cc +++ b/src/oct-lvalue.cc @@ -33,12 +33,15 @@ void octave_lvalue::assign (octave_value::assign_op op, const octave_value& rhs) { - octave_value tmp (idx.empty () - ? val->assign (op, rhs) - : val->assign (op, type, idx, rhs)); + if (val) + { + octave_value tmp (idx.empty () + ? val->assign (op, rhs) + : val->assign (op, type, idx, rhs)); - if (! error_state) - *val = tmp; + if (! error_state) + *val = tmp; + } } void @@ -57,12 +60,17 @@ void octave_lvalue::do_unary_op (octave_value::unary_op op) { - octave_value tmp (idx.empty () - ? val->do_non_const_unary_op (op) - : val->do_non_const_unary_op (op, type, idx)); + 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 (! error_state) + *val = tmp; + } + else + error ("internal: invalid operation on ~"); } octave_value @@ -70,18 +78,21 @@ { octave_value retval; - if (idx.empty ()) - retval = *val; - else + if (val) { - if (val->is_constant ()) - retval = val->subsref (type, idx); + if (idx.empty ()) + retval = *val; else - { - octave_value_list t = val->subsref (type, idx, 1); - if (t.length () > 0) - retval = t(0); - } + { + if (val->is_constant ()) + retval = val->subsref (type, idx); + else + { + octave_value_list t = val->subsref (type, idx, 1); + if (t.length () > 0) + retval = t(0); + } + } } return retval;
--- a/src/oct-lvalue.h +++ b/src/oct-lvalue.h @@ -39,16 +39,11 @@ octave_lvalue (octave_value *v = 0) : val (v), type (), idx (), nel (1) - { - if (! v) - val = &black_hole; - } + { } octave_lvalue (const octave_lvalue& vr) : val (vr.val), type (vr.type), idx (vr.idx), nel (vr.nel) { - if (vr.is_black_hole ()) - val = &black_hole; } octave_lvalue& operator = (const octave_lvalue& vr) @@ -56,8 +51,6 @@ if (this != &vr) { val = vr.val; - if (vr.is_black_hole ()) - val = &black_hole; type = vr.type; idx = vr.idx; nel = vr.nel; @@ -68,15 +61,19 @@ ~octave_lvalue (void) { } - bool is_black_hole (void) const { return val == &black_hole; } + bool is_black_hole (void) const { return val == 0; } - bool is_defined (void) const { return val->is_defined (); } + bool is_defined (void) const { return val && val->is_defined (); } + + bool is_undefined (void) const { return ! val || val->is_undefined (); } - bool is_undefined (void) const { return val->is_undefined (); } + bool is_map (void) const { return val && val->is_map (); } - bool is_map (void) const { return val->is_map (); } - - void define (const octave_value& v) { *val = v; } + void define (const octave_value& v) + { + if (val) + *val = v; + } void assign (octave_value::assign_op, const octave_value&); @@ -103,8 +100,6 @@ std::list<octave_value_list> idx; octave_idx_type nel; - - octave_value black_hole; }; #endif