Mercurial > hg > octave-lyh
changeset 4432:ff7187bd3075
[project @ 2003-06-19 16:40:53 by jwe]
author | jwe |
---|---|
date | Thu, 19 Jun 2003 16:40:54 +0000 |
parents | c4bde1d5eb98 |
children | b18ace8faf31 |
files | src/ChangeLog src/pt-arg-list.cc src/pt-idx.cc |
diffstat | 3 files changed, 78 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2003-06-19 John W. Eaton <jwe@bevo.che.wisc.edu> + + * pt-idx.cc (tree_index_expression::rvalue): + Correctly handle index expressions like x(end).f(end). + (tree_index_expression::lvalue): Likewise. + + * pt-arg-list.cc (F__end__): Add nr, nc info to error messages. + 2003-06-18 John W. Eaton <jwe@bevo.che.wisc.edu> * pr-output.cc (set_format (const Matrix&, int&, double&)): Ask
--- a/src/pt-arg-list.cc +++ b/src/pt-arg-list.cc @@ -132,7 +132,7 @@ int nc = indexed_object->columns (); if (nr < 0 || nc < 0) - ::error ("invalid use of end"); + ::error ("invalid use of end: (nr=%d, nc=%d)", nr, nc); else retval = nr * nc; } @@ -143,7 +143,7 @@ int nr = indexed_object->rows (); if (nr < 0) - ::error ("invalid use of end"); + ::error ("invalid use of end: (nr=%d)", nr); else retval = nr; } @@ -154,7 +154,7 @@ int nc = indexed_object->columns (); if (nc < 0) - ::error ("invalid use of end"); + ::error ("invalid use of end: (nc=%d)", nc); else retval = nc; }
--- a/src/pt-idx.cc +++ b/src/pt-idx.cc @@ -258,7 +258,8 @@ if (error_state) return retval; - octave_value tmp = expr->rvalue (); + octave_value first_expr_val = expr->rvalue (); + octave_value tmp = first_expr_val; if (! error_state) { @@ -272,6 +273,32 @@ for (int i = 0; i < n; i++) { + if (i > 0) + { + tree_argument_list *al = *p_args; + + if (al && al->has_magic_end ()) + { + // We have an expression like + // + // x{end}.a(end) + // + // and we are looking at the argument list that + // contains the second (or third, etc.) "end" token, + // so we must evaluate everything up to the point of + // that argument list so we pass the appropiate + // value to the built-in __end__ function. + + octave_value_list tmp_list + = first_expr_val.subsref (type, idx, nargout); + + tmp = tmp_list(0); + + if (error_state) + break; + } + } + switch (type[i]) { case '(': @@ -304,7 +331,7 @@ } if (! error_state) - retval = tmp.subsref (type, idx, nargout); + retval = first_expr_val.subsref (type, idx, nargout); } return retval; @@ -340,18 +367,53 @@ if (! error_state) { - const octave_value *tmp = retval.object (); + // I think it is OK to have a copy here. + + const octave_value *tro = retval.object (); + + octave_value first_retval_object; + + if (tro) + first_retval_object = *tro; + + octave_value tmp = first_retval_object; for (int i = 0; i < n; i++) { + if (i > 0) + { + tree_argument_list *al = *p_args; + + if (al && al->has_magic_end ()) + { + // We have an expression like + // + // x{end}.a(end) + // + // and we are looking at the argument list that + // contains the second (or third, etc.) "end" token, + // so we must evaluate everything up to the point of + // that argument list so we pass the appropiate + // value to the built-in __end__ function. + + octave_value_list tmp_list + = first_retval_object.subsref (type, idx, 1); + + tmp = tmp_list(0); + + if (error_state) + break; + } + } + switch (type[i]) { case '(': - idx.push_back (make_value_list (*p_args, *p_arg_nm, tmp)); + idx.push_back (make_value_list (*p_args, *p_arg_nm, &tmp)); break; case '{': - idx.push_back (make_value_list (*p_args, *p_arg_nm, tmp)); + idx.push_back (make_value_list (*p_args, *p_arg_nm, &tmp)); break; case '.':