# HG changeset patch # User John W. Eaton # Date 1542385882 18000 # Node ID 8fb0df0c877280bf351bddfba9c12dd6277b44e1 # Parent 6a03af2c4c9ebe2f344732db9fb2a463dc0b59c5 eliminate duplicate final_index_error function * pt-idx.cc (final_index_error): Delete static function. (tree_index_expression::lvalue): Use identical tree_evaluator::final_index_expression here instead. diff -r 6a03af2c4c9e -r 8fb0df0c8772 libinterp/parse-tree/pt-eval.cc --- a/libinterp/parse-tree/pt-eval.cc Fri Nov 16 02:42:26 2018 -0500 +++ b/libinterp/parse-tree/pt-eval.cc Fri Nov 16 11:31:22 2018 -0500 @@ -3355,6 +3355,45 @@ "string_fill_char"); } + // Final step of processing an indexing error. Add the name of the + // variable being indexed, if any, then issue an error. (Will this also + // be needed by pt-lvalue, which calls subsref?) + + void tree_evaluator::final_index_error (index_exception& e, + const tree_expression *expr) + { + std::string extra_message; + + symbol_scope scope = get_current_scope (); + + symbol_record::context_id ctxt = scope.current_context (); + + if (expr->is_identifier () + && dynamic_cast (expr)->is_variable (ctxt)) + { + std::string var = expr->name (); + + e.set_var (var); + + symbol_table& symtab = m_interpreter.get_symbol_table (); + + octave_value fcn = symtab.find_function (var); + + if (fcn.is_function ()) + { + octave_function *fp = fcn.function_value (); + + if (fp && fp->name () == var) + extra_message + = " (note: variable '" + var + "' shadows function)"; + } + } + + std::string msg = e.message () + extra_message; + + error_with_id (e.err_id (), msg.c_str ()); + } + void tree_evaluator::push_echo_state (unwind_protect& frame, int type, const std::string& file_name, @@ -3615,45 +3654,6 @@ } } - // Final step of processing an indexing error. Add the name of the - // variable being indexed, if any, then issue an error. (Will this also - // be needed by pt-lvalue, which calls subsref?) - - void tree_evaluator::final_index_error (index_exception& e, - const tree_expression *expr) - { - std::string extra_message; - - symbol_scope scope = get_current_scope (); - - symbol_record::context_id ctxt = scope.current_context (); - - if (expr->is_identifier () - && dynamic_cast (expr)->is_variable (ctxt)) - { - std::string var = expr->name (); - - e.set_var (var); - - symbol_table& symtab = m_interpreter.get_symbol_table (); - - octave_value fcn = symtab.find_function (var); - - if (fcn.is_function ()) - { - octave_function *fp = fcn.function_value (); - - if (fp && fp->name () == var) - extra_message - = " (note: variable '" + var + "' shadows function)"; - } - } - - std::string msg = e.message () + extra_message; - - error_with_id (e.err_id (), msg.c_str ()); - } - // Decide if it's time to quit a for or while loop. bool tree_evaluator::quit_loop_now (void) { diff -r 6a03af2c4c9e -r 8fb0df0c8772 libinterp/parse-tree/pt-eval.h --- a/libinterp/parse-tree/pt-eval.h Fri Nov 16 02:42:26 2018 -0500 +++ b/libinterp/parse-tree/pt-eval.h Fri Nov 16 11:31:22 2018 -0500 @@ -519,6 +519,8 @@ octave_value string_fill_char (const octave_value_list& args, int nargout); + void final_index_error (index_exception& e, const tree_expression *expr); + void push_echo_state (unwind_protect& frame, int type, const std::string& file_name, size_t pos = 1); @@ -557,8 +559,6 @@ void echo_code (size_t line); - void final_index_error (index_exception& e, const tree_expression *expr); - bool quit_loop_now (void); void bind_auto_fcn_vars (symbol_scope& scope, diff -r 6a03af2c4c9e -r 8fb0df0c8772 libinterp/parse-tree/pt-idx.cc --- a/libinterp/parse-tree/pt-idx.cc Fri Nov 16 02:42:26 2018 -0500 +++ b/libinterp/parse-tree/pt-idx.cc Fri Nov 16 11:31:22 2018 -0500 @@ -194,42 +194,6 @@ return fn; } - // Final step of processing an indexing error. Add the name of the - // variable being indexed, if any, then issue an error. (Will this also - // be needed by pt-lvalue, which calls subsref?) - - static void - final_index_error (index_exception& e, const tree_expression *expr) - { - std::string extra_message; - - symbol_table& symtab = __get_symbol_table__ ("final_index_error"); - - symbol_record::context_id context = symtab.current_context (); - - if (expr->is_identifier () - && dynamic_cast (expr)->is_variable (context)) - { - std::string var = expr->name (); - - e.set_var (var); - - octave_value fcn = symtab.find_function (var); - - if (fcn.is_function ()) - { - octave_function *fp = fcn.function_value (); - - if (fp && fp->name () == var) - extra_message = " (note: variable '" + var + "' shadows function)"; - } - } - - std::string msg = e.message () + extra_message; - - error_with_id (e.err_id (), msg.c_str ()); - } - octave_lvalue tree_index_expression::lvalue (tree_evaluator& tw) { @@ -264,7 +228,7 @@ } catch (index_exception& e) // problems with range, invalid type etc. { - final_index_error (e, m_expr); + tw.final_index_error (e, m_expr); } tmpidx.clear ();