changeset 28437:8f3aedc5ab4f stable

split search for private functions into separate function * fcn-info.h, fcn-info.cc (fcn_info::fcn_info_rep::find_private_function): New function extracted from find_scoped_function. (fcn_info::fcn_info_rep::find_scoped_function): Use it. (fcn_info::find_private_function): New function. * symtab.h, symtab.cc (symbol_table::find_private_function): New function.
author John W. Eaton <jwe@octave.org>
date Tue, 09 Jun 2020 16:48:17 -0400
parents 22e90bdcf47f
children 55f82d23fe5e
files libinterp/corefcn/fcn-info.cc libinterp/corefcn/fcn-info.h libinterp/corefcn/symtab.cc libinterp/corefcn/symtab.h
diffstat 4 files changed, 61 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/fcn-info.cc	Tue Jun 09 16:52:57 2020 -0400
+++ b/libinterp/corefcn/fcn-info.cc	Tue Jun 09 16:48:17 2020 -0400
@@ -661,36 +661,42 @@
 
         // Private function.
 
-        std::string dir_name = search_scope.dir_name ();
+        return find_private_function (search_scope.dir_name ());
+      }
+
+    return octave_value ();
+  }
 
-        if (! dir_name.empty ())
+  octave_value
+  fcn_info::fcn_info_rep::find_private_function (const std::string& dir_name)
+  {
+    if (! dir_name.empty ())
+      {
+        auto q = private_functions.find (dir_name);
+
+        if (q == private_functions.end ())
           {
-            auto q = private_functions.find (dir_name);
+            octave_value val = load_private_function (dir_name);
 
-            if (q == private_functions.end ())
+            if (val.is_defined ())
+              return val;
+          }
+        else
+          {
+            octave_value& fval = q->second;
+
+            if (fval.is_defined ())
+              out_of_date_check (fval, "", false);
+
+            if (fval.is_defined ())
+              return fval;
+            else
               {
                 octave_value val = load_private_function (dir_name);
 
                 if (val.is_defined ())
                   return val;
               }
-            else
-              {
-                octave_value& fval = q->second;
-
-                if (fval.is_defined ())
-                  out_of_date_check (fval, "", false);
-
-                if (fval.is_defined ())
-                  return fval;
-                else
-                  {
-                    octave_value val = load_private_function (dir_name);
-
-                    if (val.is_defined ())
-                      return val;
-                  }
-              }
           }
       }
 
--- a/libinterp/corefcn/fcn-info.h	Tue Jun 09 16:52:57 2020 -0400
+++ b/libinterp/corefcn/fcn-info.h	Tue Jun 09 16:48:17 2020 -0400
@@ -91,6 +91,8 @@
 
       octave_value find_scoped_function (const symbol_scope& search_scope);
 
+      octave_value find_private_function (const std::string& dir_name);
+
       octave_value find_method (const std::string& dispatch_type);
 
       octave_value find_method (const octave_value_list& args);
@@ -264,6 +266,11 @@
       return m_rep->find_scoped_function (search_scope);
     }
 
+    octave_value find_private_function (const std::string& dir_name) const
+    {
+      return m_rep->find_private_function (dir_name);
+    }
+
     octave_value find_method (const std::string& dispatch_type) const
     {
       return m_rep->find_method (dispatch_type);
--- a/libinterp/corefcn/symtab.cc	Tue Jun 09 16:52:57 2020 -0400
+++ b/libinterp/corefcn/symtab.cc	Tue Jun 09 16:48:17 2020 -0400
@@ -95,6 +95,30 @@
       }
   }
 
+  octave_value
+  symbol_table::find_private_function (const std::string& dir_name,
+                                       const std::string& name)
+  {
+    if (name.empty ())
+      return octave_value ();
+
+    fcn_table_const_iterator p = m_fcn_table.find (name);
+
+    if (p != m_fcn_table.end ())
+      return p->second.find_private_function (dir_name);
+    else
+      {
+        fcn_info finfo (name);
+
+        octave_value fcn = finfo.find_private_function (dir_name);
+
+        if (fcn.is_defined ())
+          m_fcn_table[name] = finfo;
+
+        return fcn;
+      }
+  }
+
   // FIXME: this function only finds legacy class methods, not
   // classdef methods.
 
--- a/libinterp/corefcn/symtab.h	Tue Jun 09 16:52:57 2020 -0400
+++ b/libinterp/corefcn/symtab.h	Tue Jun 09 16:48:17 2020 -0400
@@ -75,6 +75,9 @@
     octave_value find_scoped_function (const std::string& name,
                                        const symbol_scope& search_scope);
 
+    octave_value find_private_function (const std::string& dir_name,
+                                        const std::string& name);
+
     // FIXME: this function only finds legacy class methods, not
     // classdef methods.
     octave_value find_method (const std::string& name,