changeset 26846:4ff25d9b1eec

set default scope in symbol_table find functions instead of fcn_info * fcn-info.h, fcn-info.cc (fcn_info::find, fcn_info::builtin_find, fcn_info::find_function): Don't allow search_scope arg to be omitted. Don't set default value here. * symtab.cc (symbol_table::builtin_find, symbol_table::find_function, symbol_table::fcn_table_find): Set default search scope here if argument is omitted or otherwise undefined.
author John W. Eaton <jwe@octave.org>
date Tue, 05 Mar 2019 07:32:38 +0000
parents 6322d51c655c
children 8bd9fd99c12a
files libinterp/corefcn/fcn-info.cc libinterp/corefcn/fcn-info.h libinterp/corefcn/symtab.cc
diffstat 3 files changed, 49 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/fcn-info.cc	Tue Mar 05 05:01:18 2019 +0000
+++ b/libinterp/corefcn/fcn-info.cc	Tue Mar 05 07:32:38 2019 +0000
@@ -345,14 +345,14 @@
   //   built-in function
 
   octave_value
-  fcn_info::fcn_info_rep::find (const octave_value_list& args,
-                                const symbol_scope& scope)
+  fcn_info::fcn_info_rep::find (const symbol_scope& scope,
+                                const octave_value_list& args)
   {
     symbol_scope search_scope
       = (scope
          ? scope : __get_current_scope__("fcn_info::fcn_info_rep::find"));
 
-    octave_value retval = xfind (args, search_scope);
+    octave_value retval = xfind (search_scope, args);
 
     if (retval.is_undefined ())
       {
@@ -364,15 +364,15 @@
 
         lp.update ();
 
-        retval = xfind (args, search_scope);
+        retval = xfind (search_scope, args);
       }
 
     return retval;
   }
 
   octave_value
-  fcn_info::fcn_info_rep::xfind (const octave_value_list& args,
-                                 const symbol_scope& search_scope)
+  fcn_info::fcn_info_rep::xfind (const symbol_scope& search_scope,
+                                 const octave_value_list& args)
   {
     octave_user_function *current_fcn
       = search_scope ? search_scope.function () : nullptr;
--- a/libinterp/corefcn/fcn-info.h	Tue Mar 05 05:01:18 2019 +0000
+++ b/libinterp/corefcn/fcn-info.h	Tue Mar 05 07:32:38 2019 +0000
@@ -80,8 +80,8 @@
 
       octave_value load_class_method (const std::string& dispatch_type);
 
-      octave_value find (const octave_value_list& args,
-                         const symbol_scope& search_scope);
+      octave_value find (const symbol_scope& search_scope,
+                         const octave_value_list& args);
 
       octave_value builtin_find (const symbol_scope& search_scope);
 
@@ -103,10 +103,10 @@
         return package.is_defined ();
       }
 
-      octave_value find_function (const octave_value_list& args,
-                                  const symbol_scope& search_scope)
+      octave_value find_function (const symbol_scope& search_scope,
+                                  const octave_value_list& args)
       {
-        return find (args, search_scope);
+        return find (search_scope, args);
       }
 
       void install_cmdline_function (const octave_value& f)
@@ -232,8 +232,8 @@
 
     private:
 
-      octave_value xfind (const octave_value_list& args,
-                          const symbol_scope& search_scope);
+      octave_value xfind (const symbol_scope& search_scope,
+                          const octave_value_list& args);
 
       octave_value x_builtin_find (const symbol_scope& search_scope);
     };
@@ -249,14 +249,14 @@
 
     ~fcn_info (void) = default;
 
-    octave_value find (const octave_value_list& args = octave_value_list (),
-                       const symbol_scope& search_scope = symbol_scope ())
+    octave_value find (const symbol_scope& search_scope,
+                       const octave_value_list& args = octave_value_list ())
     {
-      return m_rep->find (args, search_scope);
+      return m_rep->find (search_scope, args);
     }
 
     octave_value
-    builtin_find (const symbol_scope& search_scope = symbol_scope ())
+    builtin_find (const symbol_scope& search_scope)
     {
       return m_rep->builtin_find (search_scope);
     }
@@ -298,10 +298,10 @@
     }
 
     octave_value
-    find_function (const octave_value_list& args = octave_value_list (),
-                   const symbol_scope& search_scope = symbol_scope ())
+    find_function (const symbol_scope& search_scope,
+                   const octave_value_list& args = octave_value_list ())
     {
-      return m_rep->find_function (args, search_scope);
+      return m_rep->find_function (search_scope, args);
     }
 
     void install_cmdline_function (const octave_value& f)
--- a/libinterp/corefcn/symtab.cc	Tue Mar 05 05:01:18 2019 +0000
+++ b/libinterp/corefcn/symtab.cc	Tue Mar 05 07:32:38 2019 +0000
@@ -129,14 +129,18 @@
             ? p->second.find_autoload () : octave_value ());
   }
 
-  octave_value symbol_table::builtin_find (const std::string& name,
-                                           const symbol_scope& search_scope)
+  octave_value
+  symbol_table::builtin_find (const std::string& name,
+                              const symbol_scope& search_scope_arg)
   {
     if (name.empty ())
       return octave_value ();
 
     fcn_table_iterator p = m_fcn_table.find (name);
 
+    symbol_scope search_scope
+      = (search_scope_arg ? search_scope_arg : current_scope ());
+
     if (p != m_fcn_table.end ())
       return p->second.builtin_find (search_scope);
     else
@@ -154,22 +158,26 @@
     return octave_value ();
   }
 
-  octave_value symbol_table::fcn_table_find (const std::string& name,
-                                             const octave_value_list& args,
-                                             const symbol_scope& search_scope)
+  octave_value
+  symbol_table::fcn_table_find (const std::string& name,
+                                const octave_value_list& args,
+                                const symbol_scope& search_scope_arg)
   {
     if (name.empty ())
       return octave_value ();
 
     fcn_table_iterator p = m_fcn_table.find (name);
 
+    symbol_scope search_scope
+      = (search_scope_arg ? search_scope_arg : current_scope ());
+
     if (p != m_fcn_table.end ())
-      return p->second.find (args, search_scope);
+      return p->second.find (search_scope, args);
     else
       {
         fcn_info finfo (name);
 
-        octave_value fcn = finfo.find (args, search_scope);
+        octave_value fcn = finfo.find (search_scope, args);
 
         if (fcn.is_defined ())
           m_fcn_table[name] = finfo;
@@ -180,8 +188,9 @@
     return octave_value ();
   }
 
-  octave_value symbol_table::find_function (const std::string& name,
-                                            const symbol_scope& search_scope)
+  octave_value
+  symbol_table::find_function (const std::string& name,
+                               const symbol_scope& search_scope_arg)
   {
     if (name.empty ())
       return octave_value ();
@@ -199,17 +208,23 @@
         return find_method (method, dispatch_type);
       }
     else
-      return find_function (name, ovl (), search_scope);
+      {
+        symbol_scope search_scope
+          = (search_scope_arg ? search_scope_arg : current_scope ());
+
+        return find_function (name, ovl (), search_scope);
+      }
   }
 
-  octave_value symbol_table::find_function (const std::string& name,
-                                            const octave_value_list& args,
-                                            const symbol_scope& scope_arg)
+  octave_value
+  symbol_table::find_function (const std::string& name,
+                               const octave_value_list& args,
+                               const symbol_scope& search_scope)
   {
     if (name.empty ())
       return octave_value ();
 
-    return fcn_table_find (name, args, scope_arg);
+    return fcn_table_find (name, args, search_scope);
   }
 
   octave_value