# HG changeset patch # User jwe # Date 1095280291 0 # Node ID 48d0defe944554ec53d43208267948a11426e9cf # Parent 761b8d7607858c8edc9b48f81939b9a290e28d37 [project @ 2004-09-15 20:31:31 by jwe] diff -r 761b8d760785 -r 48d0defe9445 src/ChangeLog --- a/src/ChangeLog Wed Sep 15 18:28:56 2004 +0000 +++ b/src/ChangeLog Wed Sep 15 20:31:31 2004 +0000 @@ -1,3 +1,29 @@ +2004-09-15 John W. Eaton + + * ov-cell.cc (octave_cell::subsref): Pass nargout to next_subsref. + * ov-builtin.cc (octave_builtin::subsref): Likewise. + * ov-fcn-handle.cc (octave_fcn_handle::subsref): Likewise. + * ov-list.cc (octave_list::subsref): Likewise. + * ov-mapper.cc (octave_mapper::subsref): Likewise. + * ov-struct.cc (octave_struct::subsref): Likewise. + * ov-usr-fcn.cc (octave_user_function::subsref): Likewise. + + * ov-struct.cc, ov-struct.h (octave_struct::subsref (const + std::string&, const std::list&, int)): + Define this version. + (octave_struct::subsref (const std::string&, const + std::list&)): Panic in this version. + * ov-list.cc, ov-list.h: Likewise. + * ov-cell.cc, ov-cell.h: Likewise. + + * ov.cc (octave_value::subsref (int, const std::string&, const + std::list&, size_t)): New function. + * ov.h: Provide decl. + + * ov-cell.h (octave_cell::is_constant): Return false. + * ov-struct.h (octave_struct::is_constant): Delete. + * ov-list.h (octave_list::is_constant): Delete. + 2004-09-14 David Bateman * DLD-FUNCTIONS/sort.cc (mx_sort (charNDArray&, bool, int)): diff -r 761b8d760785 -r 48d0defe9445 src/ov-builtin.cc --- a/src/ov-builtin.cc Wed Sep 15 18:28:56 2004 +0000 +++ b/src/ov-builtin.cc Wed Sep 15 20:31:31 2004 +0000 @@ -91,7 +91,7 @@ // for exmaple? if (idx.size () > 1) - retval = retval(0).next_subsref (type, idx); + retval = retval(0).next_subsref (nargout, type, idx); return retval; } diff -r 761b8d760785 -r 48d0defe9445 src/ov-cell.cc --- a/src/ov-cell.cc Wed Sep 15 18:28:56 2004 +0000 +++ b/src/ov-cell.cc Wed Sep 15 20:31:31 2004 +0000 @@ -58,16 +58,16 @@ DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_cell, "cell", "cell"); -octave_value +octave_value_list octave_cell::subsref (const std::string& type, - const std::list& idx) + const std::list& idx, int nargout) { - octave_value retval; + octave_value_list retval; switch (type[0]) { case '(': - retval = do_index_op (idx.front ()); + retval(0) = do_index_op (idx.front ()); break; case '{': @@ -79,7 +79,7 @@ Cell tcell = tmp.cell_value (); if (tcell.length () == 1) - retval = tcell(0,0); + retval(0) = tcell(0,0); else { int n = tcell.numel (); @@ -92,7 +92,7 @@ lst(i) = tcell(i); } - retval = octave_value (lst, true); + retval(0) = octave_value (lst, true); } } } @@ -109,7 +109,14 @@ panic_impossible (); } - return retval.next_subsref (type, idx); + // XXX FIXME XXX -- perhaps there should be an + // octave_value_list::next_subsref member function? See also + // octave_user_function::subsref. + + if (idx.size () > 1) + retval = retval(0).next_subsref (nargout, type, idx); + + return retval; } octave_value diff -r 761b8d760785 -r 48d0defe9445 src/ov-cell.h --- a/src/ov-cell.h Wed Sep 15 18:28:56 2004 +0000 +++ b/src/ov-cell.h Wed Sep 15 20:31:31 2004 +0000 @@ -73,16 +73,17 @@ octave_value *try_narrowing_conversion (void); #endif - octave_value subsref (const std::string& type, - const std::list& idx); - - octave_value_list subsref (const std::string&, - const std::list&, int) + octave_value subsref (const std::string&, + const std::list&) { panic_impossible (); return octave_value_list (); } + octave_value_list subsref (const std::string& type, + const std::list& idx, + int nargout); + octave_value subsasgn (const std::string& type, const std::list& idx, const octave_value& rhs); @@ -95,6 +96,8 @@ bool is_defined (void) const { return true; } + bool is_constant (void) const { return false; } + bool is_cell (void) const { return true; } Cell cell_value (void) const { return matrix; } diff -r 761b8d760785 -r 48d0defe9445 src/ov-fcn-handle.cc --- a/src/ov-fcn-handle.cc Wed Sep 15 18:28:56 2004 +0000 +++ b/src/ov-fcn-handle.cc Wed Sep 15 20:31:31 2004 +0000 @@ -92,7 +92,7 @@ // octave_builtin::subsref. if (idx.size () > 1) - retval = retval(0).next_subsref (type, idx); + retval = retval(0).next_subsref (nargout, type, idx); return retval; } diff -r 761b8d760785 -r 48d0defe9445 src/ov-list.cc --- a/src/ov-list.cc Wed Sep 15 18:28:56 2004 +0000 +++ b/src/ov-list.cc Wed Sep 15 20:31:31 2004 +0000 @@ -36,6 +36,7 @@ #include "Cell.h" #include "defun.h" #include "error.h" +#include "ov.h" #include "ov-list.h" #include "unwind-prot.h" @@ -60,11 +61,11 @@ data(i) = c(i); } -octave_value +octave_value_list octave_list::subsref (const std::string& type, - const std::list& idx) + const std::list& idx, int nargout) { - octave_value retval; + octave_value_list retval; switch (type[0]) { @@ -78,7 +79,7 @@ Cell tmp = data.index (i); - retval = octave_value (new octave_list (tmp)); + retval(0) = octave_value (new octave_list (tmp)); } else error ("only one index allowed for lists"); @@ -96,9 +97,9 @@ Cell tmp = data.index (i); if (tmp.length () == 1) - retval = tmp(0); + retval(0) = tmp(0); else - retval = octave_value (tmp, true); + retval(0) = octave_value (tmp, true); } else error ("only one index allowed for lists"); @@ -116,7 +117,14 @@ panic_impossible (); } - return retval.next_subsref (type, idx); + // XXX FIXME XXX -- perhaps there should be an + // octave_value_list::next_subsref member function? See also + // octave_user_function::subsref. + + if (idx.size () > 1) + retval = retval(0).next_subsref (nargout, type, idx); + + return retval; } octave_value diff -r 761b8d760785 -r 48d0defe9445 src/ov-list.h --- a/src/ov-list.h Wed Sep 15 18:28:56 2004 +0000 +++ b/src/ov-list.h Wed Sep 15 20:31:31 2004 +0000 @@ -66,16 +66,17 @@ octave_value *clone (void) const { return new octave_list (*this); } octave_value *empty_clone (void) const { return new octave_list (); } - octave_value subsref (const std::string& type, - const std::list& idx); - - octave_value_list subsref (const std::string&, - const std::list&, int) + octave_value subsref (const std::string&, + const std::list&) { panic_impossible (); return octave_value_list (); } + octave_value_list subsref (const std::string& type, + const std::list& idx, + int nargout); + octave_value do_index_op (const octave_value_list& idx, int resize_ok); octave_value subsasgn (const std::string& type, @@ -90,8 +91,6 @@ bool is_defined (void) const { return true; } - bool is_constant (void) const { return true; } - bool is_list (void) const { return true; } octave_value_list list_value (void) const; diff -r 761b8d760785 -r 48d0defe9445 src/ov-mapper.cc --- a/src/ov-mapper.cc Wed Sep 15 18:28:56 2004 +0000 +++ b/src/ov-mapper.cc Wed Sep 15 20:31:31 2004 +0000 @@ -265,8 +265,12 @@ return retval; - // XXX FIXME XXX - // return retval.next_subsref (type, idx); + // XXX FIXME XXX -- perhaps there should be an + // octave_value_list::next_subsref member function? See also + // and octave_builtin::subsref. + + if (idx.size () > 1) + retval = retval(0).next_subsref (nargout, type, idx); } octave_value_list diff -r 761b8d760785 -r 48d0defe9445 src/ov-struct.cc --- a/src/ov-struct.cc Wed Sep 15 18:28:56 2004 +0000 +++ b/src/ov-struct.cc Wed Sep 15 20:31:31 2004 +0000 @@ -97,11 +97,12 @@ error ("assignment to structure element failed"); } -octave_value +octave_value_list octave_struct::subsref (const std::string& type, - const std::list& idx) + const std::list& idx, + int nargout) { - octave_value retval; + octave_value_list retval; int skip = 1; @@ -120,7 +121,7 @@ { Cell t = tmp.index (idx.front ()); - retval = (t.length () == 1) ? t(0) : octave_value (t, true); + retval(0) = (t.length () == 1) ? t(0) : octave_value (t, true); // We handled two index elements, so tell // next_subsref to skip both of them. @@ -129,7 +130,7 @@ } } else - retval = map.index (idx.front ()); + retval(0) = map.index (idx.front ()); } break; @@ -137,7 +138,7 @@ { Cell t = dotref (idx.front ()); - retval = (t.length () == 1) ? t(0) : octave_value (t, true); + retval(0) = (t.length () == 1) ? t(0) : octave_value (t, true); } break; @@ -149,8 +150,12 @@ panic_impossible (); } - if (! error_state) - retval = retval.next_subsref (type, idx, skip); + // XXX FIXME XXX -- perhaps there should be an + // octave_value_list::next_subsref member function? See also + // octave_user_function::subsref. + + if (idx.size () > 1) + retval = retval(0).next_subsref (nargout, type, idx); return retval; } diff -r 761b8d760785 -r 48d0defe9445 src/ov-struct.h --- a/src/ov-struct.h Wed Sep 15 18:28:56 2004 +0000 +++ b/src/ov-struct.h Wed Sep 15 20:31:31 2004 +0000 @@ -69,16 +69,17 @@ Cell dotref (const octave_value_list& idx); - octave_value subsref (const std::string& type, - const std::list& idx); - - octave_value_list subsref (const std::string&, - const std::list&, int) + octave_value subsref (const std::string&, + const std::list&) { panic_impossible (); return octave_value_list (); } + octave_value_list subsref (const std::string& type, + const std::list& idx, + int nargout); + static octave_value numeric_conv (const Cell& val, const std::string& type); @@ -98,8 +99,6 @@ bool is_defined (void) const { return true; } - bool is_constant (void) const { return true; } - bool is_map (void) const { return true; } Octave_map map_value (void) const { return map; } diff -r 761b8d760785 -r 48d0defe9445 src/ov-usr-fcn.cc --- a/src/ov-usr-fcn.cc Wed Sep 15 18:28:56 2004 +0000 +++ b/src/ov-usr-fcn.cc Wed Sep 15 20:31:31 2004 +0000 @@ -318,7 +318,7 @@ // octave_builtin::subsref. if (idx.size () > 1) - retval = retval(0).next_subsref (type, idx); + retval = retval(0).next_subsref (nargout, type, idx); return retval; } diff -r 761b8d760785 -r 48d0defe9445 src/ov.cc --- a/src/ov.cc Wed Sep 15 18:28:56 2004 +0000 +++ b/src/ov.cc Wed Sep 15 20:31:31 2004 +0000 @@ -844,6 +844,22 @@ } octave_value_list +octave_value::next_subsref (int nargout, const std::string& type, + const std::list& idx, + size_t skip) +{ + if (! error_state && idx.size () > skip) + { + std::list new_idx (idx); + for (size_t i = 0; i < skip; i++) + new_idx.erase (new_idx.begin ()); + return subsref (type.substr (skip), new_idx, nargout); + } + else + return *this; +} + +octave_value_list octave_value::do_multi_index_op (int nargout, const octave_value_list& idx) { return rep->do_multi_index_op (nargout, idx); diff -r 761b8d760785 -r 48d0defe9445 src/ov.h --- a/src/ov.h Wed Sep 15 18:28:56 2004 +0000 +++ b/src/ov.h Wed Sep 15 20:31:31 2004 +0000 @@ -318,6 +318,11 @@ std::list& idx, size_t skip = 1); + octave_value_list next_subsref (int nargout, + const std::string& type, const + std::list& idx, + size_t skip = 1); + virtual octave_value do_index_op (const octave_value_list& idx, int resize_ok) { return rep->do_index_op (idx, resize_ok); }