# HG changeset patch # User jwe # Date 1056040854 0 # Node ID ff7187bd30750d6aaf2b51a978e307a81bef0209 # Parent c4bde1d5eb984d62a2d3db9c381409e4c30f3531 [project @ 2003-06-19 16:40:53 by jwe] diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2003-06-19 John W. Eaton + + * 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 * pr-output.cc (set_format (const Matrix&, int&, double&)): Ask diff --git a/src/pt-arg-list.cc b/src/pt-arg-list.cc --- 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; } diff --git a/src/pt-idx.cc b/src/pt-idx.cc --- 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 '.':