changeset 24705:8b346a19108e

mark objects as nested or subfunctions when parsing * oct-parse.in.yy (base_parser::finish_function): Mark functions as nested functions and subfunctions here. * symscope.h, symscope.cc (symbols_scope::install_subfunction, symbol_scope_rep::install_subfunction): Not here. (symbol_scope_rep::install_nestfunction): New function. (symbols_scope::install_subfunction, symbol_scope_rep::install_subfunction): Eliminate is_nested argument. (symbol_scope::install_nestfunction): New argument, fcn_scope. Call symbol_scope::install_subfunction with is_nested = true instead of symbol_scope_rep::install_nestfunction.
author John W. Eaton <jwe@octave.org>
date Thu, 08 Feb 2018 01:08:36 -0500
parents 368a02326172
children 30e1d0bf7ade
files libinterp/corefcn/symscope.cc libinterp/corefcn/symscope.h libinterp/parse-tree/oct-parse.in.yy
diffstat 3 files changed, 21 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/symscope.cc	Wed Feb 07 17:22:45 2018 -0500
+++ b/libinterp/corefcn/symscope.cc	Thu Feb 08 01:08:36 2018 -0500
@@ -133,31 +133,6 @@
     return octave_value (info_map);
   }
 
-  void
-  symbol_scope_rep::install_subfunction (const std::string& name,
-                                         const octave_value& fval,
-                                         bool is_nested)
-  {
-    m_subfunctions[name] = fval;
-
-    // This can be simpler once the scope object is stored in the function
-    // object...
-    octave_user_function *fcn = fval.user_function_value ();
-
-    symbol_scope fcn_scope = fcn->scope ();
-
-    fcn_scope.set_parent (this);
-
-    if (is_nested)
-      {
-        m_children.push_back (fcn_scope);
-
-        fcn->mark_as_nested_function ();
-
-        fcn_scope.mark_nested ();
-      }
-  }
-
   octave_value
   symbol_scope_rep::find_subfunction (const std::string& name) const
   {
--- a/libinterp/corefcn/symscope.h	Wed Feb 07 17:22:45 2018 -0500
+++ b/libinterp/corefcn/symscope.h	Thu Feb 08 01:08:36 2018 -0500
@@ -448,13 +448,18 @@
     }
 
     void install_subfunction (const std::string& name,
-                              const octave_value& fval,
-                              bool is_nested = false);
+                              const octave_value& fval)
+    {
+      m_subfunctions[name] = fval;
+    }
 
     void install_nestfunction (const std::string& name,
-                               const octave_value& fval)
+                               const octave_value& fval,
+                               const symbol_scope& fcn_scope)
     {
-      install_subfunction (name, fval, true);
+      m_subfunctions[name] = fval;
+
+      m_children.push_back (fcn_scope);
     }
 
     octave_value find_subfunction (const std::string& name) const;
@@ -802,18 +807,18 @@
     }
 
     void install_subfunction (const std::string& name,
-                              const octave_value& fval,
-                              bool is_nested = false)
+                              const octave_value& fval)
     {
       if (m_rep)
-        m_rep->install_subfunction (name, fval, is_nested);
+        m_rep->install_subfunction (name, fval);
     }
 
     void install_nestfunction (const std::string& name,
-                               const octave_value& fval)
+                               const octave_value& fval,
+                               const symbol_scope& fcn_scope)
     {
       if (m_rep)
-        m_rep->install_nestfunction (name, fval);
+        m_rep->install_nestfunction (name, fval, fcn_scope);
     }
 
     octave_value find_subfunction (const std::string& name) const
--- a/libinterp/parse-tree/oct-parse.in.yy	Wed Feb 07 17:22:45 2018 -0500
+++ b/libinterp/parse-tree/oct-parse.in.yy	Thu Feb 08 01:08:36 2018 -0500
@@ -3499,17 +3499,20 @@
 
             if (m_endfunction_found && m_function_scopes.size () > 1)
               {
+                fcn->mark_as_nested_function ();
+                fcn_scope.mark_nested ();
+
                 symbol_scope pscope = m_function_scopes.parent_scope ();
-
-                pscope.install_nestfunction (nm, ov_fcn);
+                fcn_scope.set_parent (pscope);
+                pscope.install_nestfunction (nm, ov_fcn, fcn_scope);
               }
             else
               {
                 fcn->mark_as_subfunction ();
                 m_subfunction_names.push_back (nm);
-
+                fcn_scope.set_parent (m_primary_fcn_scope);
                 m_primary_fcn_scope.install_subfunction (nm, ov_fcn);
-               }
+              }
           }
 
         if (m_curr_fcn_depth == 1)