# HG changeset patch # User John W. Eaton # Date 1630596053 14400 # Node ID 3efce22b735086eb369a6adecf0978460bf407cf # Parent 4fa7200f230a27190cd367e6c61c8190a49f6dcd eliminate duplicate parent function name info in symbol scope objects * symscope.h, symscope.cc (symbol_scope_rep::m_parent_fcn_names): Delete member variable. (symbol_scope_rep::cache_parent_fcn_names): Delete function and all uses. (symbol_scope_rep::parent_fcn_names): Generate list of parent function names from parent scope info as needed. diff -r 4fa7200f230a -r 3efce22b7350 libinterp/corefcn/symscope.cc --- a/libinterp/corefcn/symscope.cc Thu Sep 02 11:17:45 2021 -0400 +++ b/libinterp/corefcn/symscope.cc Thu Sep 02 11:20:53 2021 -0400 @@ -196,10 +196,21 @@ } } - void - symbol_scope_rep::cache_parent_fcn_names (const std::list& names) + std::list + symbol_scope_rep::parent_fcn_names (void) const { - m_parent_fcn_names = names; + std::list retval; + + auto pscope = parent_scope_rep (); + + while (pscope) + { + retval.push_back (pscope->fcn_name ()); + + pscope = pscope->parent_scope_rep (); + } + + return retval; } void @@ -319,14 +330,8 @@ m_is_static = true; } - std::list plst = parent_fcn_names (); - plst.push_front (m_fcn_name); - for (auto& scope_obj : m_children) - { - scope_obj.cache_parent_fcn_names (plst); - scope_obj.update_nest (); - } + scope_obj.update_nest (); } bool symbol_scope_rep::look_nonlocal (const std::string& name, diff -r 4fa7200f230a -r 3efce22b7350 libinterp/corefcn/symscope.h --- a/libinterp/corefcn/symscope.h Thu Sep 02 11:17:45 2021 -0400 +++ b/libinterp/corefcn/symscope.h Thu Sep 02 11:20:53 2021 -0400 @@ -66,11 +66,11 @@ subfunctions_iterator; symbol_scope_rep (const std::string& name = "") - : m_name (name), m_symbols (), m_subfunctions (), m_persistent_values (), - m_code (nullptr), m_fcn_name (), m_parent_fcn_names (), - m_fcn_file_name (), m_dir_name (), m_parent (), m_primary_parent (), - m_children (), m_nesting_depth (0), m_is_static (false), - m_is_primary_fcn_scope (false) + : m_name (name), m_symbols (), m_subfunctions (), + m_persistent_values (), m_code (nullptr), m_fcn_name (), + m_fcn_file_name (), m_dir_name (), m_parent (), + m_primary_parent (), m_children (), m_nesting_depth (0), + m_is_static (false), m_is_primary_fcn_scope (false) { // All scopes have ans as the first symbol, initially undefined. @@ -128,7 +128,6 @@ new_sid->m_subfunction_names = m_subfunction_names; new_sid->m_code = m_code; new_sid->m_fcn_name = m_fcn_name; - new_sid->m_parent_fcn_names = m_parent_fcn_names; new_sid->m_fcn_file_name = m_fcn_file_name; new_sid->m_dir_name = m_dir_name; new_sid->m_parent = m_parent; @@ -257,12 +256,7 @@ void cache_fcn_name (const std::string& name) { m_fcn_name = name; } - std::list parent_fcn_names (void) const - { - return m_parent_fcn_names; - } - - void cache_parent_fcn_names (const std::list& names); + std::list parent_fcn_names (void) const; octave_user_code *user_code (void) const { return m_code; } @@ -344,10 +338,6 @@ std::string m_fcn_name; - //! List Simple names of the parent functions corresponding to this scope. - - std::list m_parent_fcn_names; - //! The file name associated with m_code. std::string m_fcn_file_name; @@ -605,12 +595,6 @@ return m_rep ? m_rep->parent_fcn_names () : std::list (); } - void cache_parent_fcn_names (const std::list& names) - { - if (m_rep) - m_rep->cache_parent_fcn_names (names); - } - octave_user_code * user_code (void) const { return m_rep ? m_rep->user_code () : nullptr; diff -r 4fa7200f230a -r 3efce22b7350 libinterp/parse-tree/oct-parse.yy --- a/libinterp/parse-tree/oct-parse.yy Thu Sep 02 11:17:45 2021 -0400 +++ b/libinterp/parse-tree/oct-parse.yy Thu Sep 02 11:20:53 2021 -0400 @@ -4216,6 +4216,7 @@ 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 (fcn_nm, ov_fcn, fcn_scope); // For nested functions, the list of parent functions is @@ -4225,18 +4226,12 @@ { fcn->mark_as_subfunction (); m_subfunction_names.push_back (fcn_nm); + fcn_scope.set_parent (m_primary_fcn_scope); 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 function to list of parent - // functions (if any) for subfunction. - - std::list plst - = fcn_scope.parent_fcn_names (); - plst.push_front (m_primary_fcn_scope.fcn_name ()); - fcn_scope.cache_parent_fcn_names (plst); } }