diff libinterp/parse-tree/oct-parse.yy @ 28432:71c34141cc2d stable

refactor handling of parent functions and localfunctions * help.cc (Flocalfunctions): Simply call symbol_scope::localfunctions for the current user function. * symscope.h, symscope.cc (symbol_scope_rep::m_fcn_name, symbol_scope_rep::m_parent_fcn_names, symbol_scope_rep::m_is_primary_fcn_scope): New data members. (symbol_scope_rep::localfunctions, symbol_scope_rep::fcn_name, symbol_scope_rep::cache_fcn_name, symbol_scope_rep::parent_fcn_names, symbol_scope_rep::cache_parent_fcn_names, symbol_scope_rep::mark_primary_fcn_scope, symbol_scope_rep::is_primary_fcn_scope, symbol_scope::localfunctions, symbol_scope::fcn_name, symbol_scope::cache_fcn_name, symbol_scope::parent_fcn_names, symbol_scope::cache_parent_fcn_names, symbol_scope::mark_primary_fcn_scope, symbol_scope::is_primary_fcn_scope): New functions. (symbol_scope_rep): Also cache parent function names. * oct-parse.yy (base_parser::push_fcn_symtab): Mark primary_fcn_scope as primary. (base_parser::finish_function): If parsing subfunction, set primary parent scope in subfunction scope. Cache parent function names in current scope. * ov-fcn.h (octave_function::parent_fcn_names): New virtual function. * ov-usr-fcn.h (octave_user_function::parent_fcn_names): New function.
author John W. Eaton <jwe@octave.org>
date Fri, 03 Apr 2020 22:00:06 -0400
parents 808e3964987b
children b743a63e2dab 06bc2f0bf760
line wrap: on
line diff
--- a/libinterp/parse-tree/oct-parse.yy	Fri Apr 03 21:59:15 2020 -0400
+++ b/libinterp/parse-tree/oct-parse.yy	Fri Apr 03 22:00:06 2020 -0400
@@ -2489,7 +2489,10 @@
 
     if (! m_lexer.m_reading_script_file && m_curr_fcn_depth == 0
         && ! m_parsing_subfunctions)
-      m_primary_fcn_scope = m_lexer.m_symtab_context.curr_scope ();
+        {
+          m_primary_fcn_scope = m_lexer.m_symtab_context.curr_scope ();
+          m_primary_fcn_scope.mark_primary_fcn_scope ();
+        }
 
     if (m_lexer.m_reading_script_file && m_curr_fcn_depth > 0)
       {
@@ -3681,15 +3684,16 @@
 
     if (fcn)
       {
-        std::string nm = fcn->name ();
+        std::string fcn_nm = fcn->name ();
         std::string file = fcn->fcn_file_name ();
 
-        std::string tmp = nm;
+        std::string tmp = fcn_nm;
         if (! file.empty ())
           tmp += ": " + file;
 
         symbol_scope fcn_scope = fcn->scope ();
         fcn_scope.cache_name (tmp);
+        fcn_scope.cache_fcn_name (fcn_nm);
         fcn_scope.cache_fcn_file_name (file);
         fcn_scope.cache_dir_name (m_lexer.m_dir_name);
 
@@ -3713,14 +3717,27 @@
                 symbol_scope pscope = m_function_scopes.parent_scope ();
                 fcn_scope.set_parent (pscope);
                 fcn_scope.set_primary_parent (m_primary_fcn_scope);
-                pscope.install_nestfunction (nm, ov_fcn, fcn_scope);
+                pscope.install_nestfunction (fcn_nm, ov_fcn, fcn_scope);
+
+                // For nested functions, the list of parent functions is
+                // set in symbol_scope::update_nest.
               }
             else
               {
                 fcn->mark_as_subfunction ();
-                m_subfunction_names.push_back (nm);
+                m_subfunction_names.push_back (fcn_nm);
                 fcn_scope.set_parent (m_primary_fcn_scope);
-                m_primary_fcn_scope.install_subfunction (nm, ov_fcn);
+                if (m_parsing_subfunctions)
+                  fcn_scope.set_primary_parent (m_primary_fcn_scope);
+                m_primary_fcn_scope.install_subfunction (fcn_nm, ov_fcn);
+
+                // Prepend name of primary fucntion to list of parent
+                // functions (if any) for subfunction.
+
+                std::list<std::string> plst
+                  = fcn_scope.parent_fcn_names ();
+                plst.push_front (m_primary_fcn_scope.fcn_name ());
+                fcn_scope.cache_parent_fcn_names (plst);
               }
           }