changeset 26094:8fb0df0c8772

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.
author John W. Eaton <jwe@octave.org>
date Fri, 16 Nov 2018 11:31:22 -0500
parents 6a03af2c4c9e
children fda3bc89c528
files libinterp/parse-tree/pt-eval.cc libinterp/parse-tree/pt-eval.h libinterp/parse-tree/pt-idx.cc
diffstat 3 files changed, 42 insertions(+), 78 deletions(-) [+]
line wrap: on
line diff
--- 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<const tree_identifier *> (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<const tree_identifier *> (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)
   {
--- 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,
--- 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<const tree_identifier *> (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 ();