Mercurial > octave
changeset 23916:85488effc0ff
refactor function value return code
* pt-eval.h, pt-eval.cc
(tree_evaluator::initialize_undefind_parameter_list_elements): Delete.
* ov-usr-fcn.cc (octave_user_function::call): Don't call it.
* pt-eval.h, pt-eval.cc
(tree_evaluator::convert_return_list_to_const_vector): Rename from
convert_parameter_list_to_const_vector. Don't exit early if undefined
elements are found.
(tree_evaluator::visit_multi_assignment): If LHS is ignored, don't
call octave_lvalue::assign for that returned value. Error for
undefined values that are not ignored.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 15 Aug 2017 08:47:39 -0400 |
parents | adf580507691 |
children | 47c44b822d11 |
files | libinterp/octave-value/ov-usr-fcn.cc libinterp/parse-tree/pt-eval.cc libinterp/parse-tree/pt-eval.h |
diffstat | 3 files changed, 20 insertions(+), 80 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/octave-value/ov-usr-fcn.cc Mon Aug 14 16:55:52 2017 -0700 +++ b/libinterp/octave-value/ov-usr-fcn.cc Tue Aug 15 08:47:39 2017 -0400 @@ -654,9 +654,6 @@ if (ret_list && ! is_special_expr ()) { - tw.initialize_undefined_parameter_list_elements (ret_list, my_name, - nargout, Matrix ()); - Cell varargout; if (ret_list->takes_varargs ()) @@ -667,7 +664,7 @@ varargout = varargout_varval.xcell_value ("varargout must be a cell array object"); } - retval = tw.convert_parameter_list_to_const_vector (ret_list, nargout, varargout); + retval = tw.convert_return_list_to_const_vector (ret_list, nargout, varargout); } return retval;
--- a/libinterp/parse-tree/pt-eval.cc Mon Aug 14 16:55:52 2017 -0700 +++ b/libinterp/parse-tree/pt-eval.cc Tue Aug 15 08:47:39 2017 -0400 @@ -482,64 +482,6 @@ } void - tree_evaluator::initialize_undefined_parameter_list_elements - (tree_parameter_list *param_list, const std::string& warnfor, - int nargout, const octave_value& val) - { - bool warned = false; - - int count = 0; - - symbol_table::scope *scope - = m_interpreter.require_current_scope ("tree_evaluator::initialize_undefined_parameter_list_elements"); - - octave_value tmp = scope->varval (".ignored."); - const Matrix ignored = (tmp.is_defined () ? tmp.matrix_value () : Matrix ()); - - octave_idx_type k = 0; - - for (tree_decl_elt *elt : *param_list) - { - if (++count > nargout) - break; - - if (! elt->is_variable ()) - { - if (! warned) - { - warned = true; - - while (k < ignored.numel ()) - { - octave_idx_type l = ignored (k); - if (l == count) - { - warned = false; - break; - } - else if (l > count) - break; - else - k++; - } - - if (warned) - { - warning_with_id - ("Octave:undefined-return-values", - "%s: some elements in list of return values are undefined", - warnfor.c_str ()); - } - } - - octave_lvalue lval = elt->lvalue (this); - - lval.assign (octave_value::op_asn_eq, val); - } - } - } - - void tree_evaluator::define_parameter_list_from_arg_vector (tree_parameter_list *param_list, const octave_value_list& args) { @@ -578,11 +520,11 @@ } octave_value_list - tree_evaluator::convert_parameter_list_to_const_vector - (tree_parameter_list *param_list, int nargout, const Cell& varargout) + tree_evaluator::convert_return_list_to_const_vector + (tree_parameter_list *ret_list, int nargout, const Cell& varargout) { octave_idx_type vlen = varargout.numel (); - int len = param_list->length (); + int len = ret_list->length (); // Special case. Will do a shallow copy. if (len == 0) @@ -593,15 +535,15 @@ int i = 0; - for (tree_decl_elt *elt : *param_list) + for (tree_decl_elt *elt : *ret_list) { if (elt->is_defined ()) { octave_value tmp = evaluate (elt); - retval(i++) = tmp; + retval(i) = tmp; } - else - break; + + i++; } return retval; @@ -612,7 +554,7 @@ int i = 0; - for (tree_decl_elt *elt : *param_list) + for (tree_decl_elt *elt : *ret_list) retval(i++) = evaluate (elt); for (octave_idx_type j = 0; j < vlen; j++) @@ -1868,8 +1810,6 @@ { if (k < n) { - ult.assign (octave_value::op_asn_eq, rhs_val(k)); - if (ult.is_black_hole ()) { k++; @@ -1877,7 +1817,15 @@ } else { - retval_list.push_back (rhs_val(k)); + octave_value tmp = rhs_val(k); + + if (tmp.is_undefined ()) + error ("element number %d undefined in return list", + k+1); + + ult.assign (octave_value::op_asn_eq, tmp); + + retval_list.push_back (tmp); k++; }
--- a/libinterp/parse-tree/pt-eval.h Mon Aug 14 16:55:52 2017 -0700 +++ b/libinterp/parse-tree/pt-eval.h Tue Aug 15 08:47:39 2017 -0400 @@ -289,19 +289,14 @@ octave_value evaluate (tree_decl_elt *); - void - initialize_undefined_parameter_list_elements - (tree_parameter_list *param_list, const std::string& warnfor, - int nargout, const octave_value& val); - void define_parameter_list_from_arg_vector (tree_parameter_list *param_list, const octave_value_list& args); void undefine_parameter_list (tree_parameter_list *param_list); octave_value_list - convert_parameter_list_to_const_vector - (tree_parameter_list *param_list, int nargout, const Cell& varargout); + convert_return_list_to_const_vector + (tree_parameter_list *ret_list, int nargout, const Cell& varargout); bool eval_decl_elt (tree_decl_elt *elt);