diff libinterp/corefcn/symtab.cc @ 26845:6322d51c655c

allow function search in arbitrary scope * fcn-info.h, fcn-info.cc (fcn_info::builtin_find, fcn_info::find, fcn_info::find_function, fcn_info::fcn_info_rep::builtin_find, fcn_info::fcn_info_rep::find, fcn_info::fcn_info_rep::find_function, fcn_info::fcn_info_rep::xfind, fcn_info::fcn_info_rep::x_builtin_find): Pass scope as argument. (fcn_info::find, fcn_info::builtin_find): If given scope is valid, use it, otherwise default to current scope). (fcn_info::fcn_info_rep::xfind): Also search for subfunctions. * symtab.h, symtab.cc (symbol_table::builtin_find, symbol_table::fcn_table_find, symbol_table::find_function): Pass scope as argument. (symbol_table::find_function): Don't search for subfunctions. * symscope.h (symbol_scope::function, symbol_scope:symbol_scope_rep::function): Now const.
author John W. Eaton <jwe@octave.org>
date Tue, 05 Mar 2019 05:01:18 +0000
parents 98f1a964ff33
children 4ff25d9b1eec
line wrap: on
line diff
--- a/libinterp/corefcn/symtab.cc	Tue Mar 05 23:26:05 2019 +0100
+++ b/libinterp/corefcn/symtab.cc	Tue Mar 05 05:01:18 2019 +0000
@@ -129,7 +129,8 @@
             ? p->second.find_autoload () : octave_value ());
   }
 
-  octave_value symbol_table::builtin_find (const std::string& name)
+  octave_value symbol_table::builtin_find (const std::string& name,
+                                           const symbol_scope& search_scope)
   {
     if (name.empty ())
       return octave_value ();
@@ -137,12 +138,12 @@
     fcn_table_iterator p = m_fcn_table.find (name);
 
     if (p != m_fcn_table.end ())
-      return p->second.builtin_find ();
+      return p->second.builtin_find (search_scope);
     else
       {
         fcn_info finfo (name);
 
-        octave_value fcn = finfo.builtin_find ();
+        octave_value fcn = finfo.builtin_find (search_scope);
 
         if (fcn.is_defined ())
           m_fcn_table[name] = finfo;
@@ -154,7 +155,8 @@
   }
 
   octave_value symbol_table::fcn_table_find (const std::string& name,
-                                             const octave_value_list& args)
+                                             const octave_value_list& args,
+                                             const symbol_scope& search_scope)
   {
     if (name.empty ())
       return octave_value ();
@@ -162,12 +164,12 @@
     fcn_table_iterator p = m_fcn_table.find (name);
 
     if (p != m_fcn_table.end ())
-      return p->second.find (args);
+      return p->second.find (args, search_scope);
     else
       {
         fcn_info finfo (name);
 
-        octave_value fcn = finfo.find (args);
+        octave_value fcn = finfo.find (args, search_scope);
 
         if (fcn.is_defined ())
           m_fcn_table[name] = finfo;
@@ -178,7 +180,8 @@
     return octave_value ();
   }
 
-  octave_value symbol_table::find_function (const std::string& name)
+  octave_value symbol_table::find_function (const std::string& name,
+                                            const symbol_scope& search_scope)
   {
     if (name.empty ())
       return octave_value ();
@@ -196,31 +199,21 @@
         return find_method (method, dispatch_type);
       }
     else
-      return find_function (name, ovl ());
+      return find_function (name, ovl (), search_scope);
   }
 
   octave_value symbol_table::find_function (const std::string& name,
-                                            const octave_value_list& args)
+                                            const octave_value_list& args,
+                                            const symbol_scope& scope_arg)
   {
     if (name.empty ())
       return octave_value ();
 
-    octave_value fcn;
-
-    symbol_scope curr_scope = current_scope ();
-
-    if (curr_scope)
-      {
-        fcn = curr_scope.find_subfunction (name);
-
-        if (fcn.is_defined ())
-          return fcn;
-      }
-
-    return fcn_table_find (name, args);
+    return fcn_table_find (name, args, scope_arg);
   }
 
-  octave_value symbol_table::find_user_function (const std::string& name)
+  octave_value
+  symbol_table::find_user_function (const std::string& name)
   {
     if (name.empty ())
       return octave_value ();