diff libinterp/corefcn/help.cc @ 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 b018f553fd85
children b743a63e2dab fab862fedf85
line wrap: on
line diff
--- a/libinterp/corefcn/help.cc	Fri Apr 03 21:59:15 2020 -0400
+++ b/libinterp/corefcn/help.cc	Fri Apr 03 22:00:06 2020 -0400
@@ -814,30 +814,14 @@
 
   // Find the main function we are in.
   octave::tree_evaluator& tw = interp.get_evaluator ();
-  octave_user_code *parent_fcn = tw.debug_user_code ();
+  octave_user_code *caller = tw.debug_user_code ();
 
-  if (! parent_fcn)
+  if (! caller)
     return ovl (retval);
 
-  // Find the subfunctions of this function.
-  // 1) subfunction_names contains only valid subfunctions
-  // 2) subfunctions contains both nested functions and subfunctions
-  const std::list<std::string> names = parent_fcn->subfunction_names ();
-  const std::map<std::string, octave_value> h = parent_fcn->subfunctions ();
-
-  size_t sz = names.size ();
-  retval.resize (dim_vector (sz, 1));
+  octave::symbol_scope scope = caller->scope ();
 
-  // loop over them.
-  size_t i = 0;
-  for (const auto& nm : names)
-    {
-      std::map<std::string, octave_value>::const_iterator nm_fcn = h.find (nm);
-      if (nm_fcn != h.end ())
-        retval(i++) = octave_value (new octave_fcn_handle (nm_fcn->second, nm));
-    }
-
-  return ovl (retval);
+  return ovl (Cell (scope.localfunctions ()));
 }
 
 /*