Mercurial > octave
changeset 26119:1dd0e16b82e3
eliminate some unnecessary function arguments
* symscope.h, symscope.cc (symbol_scope::find,
symbol_scope_rep::find): Eliminate ARGS, SKIP_VARIABLES, and
LOCAL_FUNCS args. These functions were always called with ARGS set to
an empty octave_value_list object, SKIP_VARIABLES set to false, and
LOCAL_FUNCS set to true. Change all uses.
* symtab.h, symtab.cc (symbol_table::fcn_table_find): Eliminate
optional LOCAL_FUNCS argument. This function was always called with
LOCAL_FUNCS set to true. Change all uses.
* ov-fcn-handle.h, ov-fcn-handle.cc (make_fcn_handle): Eliminate
optional LOCAL_FUNCS argument. This function was always called with
LOCAL_FUNCS set to true. Change all uses.
* fcn-info.h, fcn-info.cc (fcn_info::fcn_info_rep::find,
fcn_info::fcn_info_rep::xfind, fcn_info::fcn_info_rep::find_function,
fcn_info::find, fcn_inof::find_function): Eliminate optional
LOCAL_FUNCS argument. These functions were was always called with
LOCAL_FUNCS set to true. Change all uses.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 21 Nov 2018 15:24:17 -0500 |
parents | 7502fce4cd3a |
children | 80d284ab86b6 |
files | libgui/src/m-editor/file-editor-tab.cc libinterp/corefcn/fcn-info.cc libinterp/corefcn/fcn-info.h libinterp/corefcn/symscope.cc libinterp/corefcn/symscope.h libinterp/corefcn/symtab.cc libinterp/corefcn/symtab.h libinterp/octave-value/ov-classdef.cc libinterp/octave-value/ov-fcn-handle.cc libinterp/octave-value/ov-fcn-handle.h libinterp/parse-tree/oct-parse.yy |
diffstat | 11 files changed, 110 insertions(+), 136 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc Wed Nov 21 14:54:22 2018 -0500 +++ b/libgui/src/m-editor/file-editor-tab.cc Wed Nov 21 15:24:17 2018 -0500 @@ -2003,10 +2003,13 @@ octave_value sym; try { + // FIXME: maybe we should be looking up functions directly + // instead of using a function that can also find variables? + symbol_scope curr_scope = __get_current_scope__ ("file_editor_tab::exit_debug_and_clear"); - sym = curr_scope.find (base_name, octave_value_list (), false, true); + sym = curr_scope.find (base_name); } catch (const execution_exception& e) {
--- a/libinterp/corefcn/fcn-info.cc Wed Nov 21 14:54:22 2018 -0500 +++ b/libinterp/corefcn/fcn-info.cc Wed Nov 21 15:24:17 2018 -0500 @@ -345,9 +345,9 @@ // than methods, but that does not seem to be the case. octave_value - fcn_info::fcn_info_rep::find (const octave_value_list& args, bool local_funcs) + fcn_info::fcn_info_rep::find (const octave_value_list& args) { - octave_value retval = xfind (args, local_funcs); + octave_value retval = xfind (args); if (retval.is_undefined ()) { @@ -359,93 +359,89 @@ lp.update (); - retval = xfind (args, local_funcs); + retval = xfind (args); } return retval; } octave_value - fcn_info::fcn_info_rep::xfind (const octave_value_list& args, - bool local_funcs) + fcn_info::fcn_info_rep::xfind (const octave_value_list& args) { - if (local_funcs) - { - symbol_scope curr_scope - = __get_current_scope__ ("fcn_info::fcn_info_rep::xfind"); + symbol_scope curr_scope + = __get_current_scope__ ("fcn_info::fcn_info_rep::xfind"); + + octave_user_function *current_fcn + = curr_scope ? curr_scope.function () : nullptr; - octave_user_function *current_fcn - = curr_scope ? curr_scope.function () : nullptr; - - // Local function. + // Local function. - if (current_fcn) - { - std::string fcn_file = current_fcn->fcn_file_name (); + if (current_fcn) + { + std::string fcn_file = current_fcn->fcn_file_name (); - // For anonymous functions we look at the parent scope so that if - // they were defined within class methods and use local functions - // (helper functions) we can still use those anonymous functions + // For anonymous functions we look at the parent scope so that if + // they were defined within class methods and use local functions + // (helper functions) we can still use those anonymous functions - if (current_fcn->is_anonymous_function ()) - { - if (fcn_file.empty () - && curr_scope.parent_scope () - && curr_scope.parent_scope ()->function () != nullptr) - fcn_file - = curr_scope.parent_scope ()->function ()->fcn_file_name(); - } + if (current_fcn->is_anonymous_function ()) + { + if (fcn_file.empty () + && curr_scope.parent_scope () + && curr_scope.parent_scope ()->function () != nullptr) + fcn_file + = curr_scope.parent_scope ()->function ()->fcn_file_name(); + } - if (! fcn_file.empty ()) + if (! fcn_file.empty ()) + { + auto r = local_functions.find (fcn_file); + + if (r != local_functions.end ()) { - auto r = local_functions.find (fcn_file); + // We shouldn't need an out-of-date check here since + // local functions may ultimately be called only from + // a primary function or method defined in the same + // file. - if (r != local_functions.end ()) - { - // We shouldn't need an out-of-date check here since - // local functions may ultimately be called only from - // a primary function or method defined in the same - // file. - - return r->second; - } + return r->second; } } + } - // Private function. + // Private function. - if (current_fcn) + if (current_fcn) + { + std::string dir_name = current_fcn->dir_name (); + + if (! dir_name.empty ()) { - std::string dir_name = current_fcn->dir_name (); + auto q = private_functions.find (dir_name); - if (! dir_name.empty ()) + 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 Wed Nov 21 14:54:22 2018 -0500 +++ b/libinterp/corefcn/fcn-info.h Wed Nov 21 15:24:17 2018 -0500 @@ -81,7 +81,7 @@ octave_value load_class_method (const std::string& dispatch_type); - octave_value find (const octave_value_list& args, bool local_funcs); + octave_value find (const octave_value_list& args); octave_value builtin_find (void); @@ -98,10 +98,9 @@ return function_on_path.is_defined (); } - octave_value find_function (const octave_value_list& args, - bool local_funcs) + octave_value find_function (const octave_value_list& args) { - return find (args, local_funcs); + return find (args); } void install_cmdline_function (const octave_value& f) @@ -222,7 +221,7 @@ private: - octave_value xfind (const octave_value_list& args, bool local_funcs); + octave_value xfind (const octave_value_list& args); octave_value x_builtin_find (void); }; @@ -238,10 +237,9 @@ ~fcn_info (void) = default; - octave_value find (const octave_value_list& args = octave_value_list (), - bool local_funcs = true) + octave_value find (const octave_value_list& args = octave_value_list ()) { - return m_rep->find (args, local_funcs); + return m_rep->find (args); } octave_value builtin_find (void) @@ -280,10 +278,9 @@ } octave_value find_function (const octave_value_list& args - = octave_value_list (), - bool local_funcs = true) + = octave_value_list ()) { - return m_rep->find_function (args, local_funcs); + return m_rep->find_function (args); } void install_cmdline_function (const octave_value& f)
--- a/libinterp/corefcn/symscope.cc Wed Nov 21 14:54:22 2018 -0500 +++ b/libinterp/corefcn/symscope.cc Wed Nov 21 15:24:17 2018 -0500 @@ -56,48 +56,40 @@ } octave_value - symbol_scope_rep::find (const std::string& name, - const octave_value_list& args, - bool skip_variables, bool local_funcs) + symbol_scope_rep::find (const std::string& name) { - // Variable. - symbol_table& symtab = __get_symbol_table__ ("symbol_scope_rep::find"); - if (! skip_variables) - { - table_iterator p = m_symbols.find (name); + // Variable. + + table_iterator p = m_symbols.find (name); - if (p != m_symbols.end ()) - { - symbol_record sr = p->second; + if (p != m_symbols.end ()) + { + symbol_record sr = p->second; - if (sr.is_global ()) - return symtab.global_varval (name); - else - { - octave_value val = sr.varval (m_context); + if (sr.is_global ()) + return symtab.global_varval (name); + else + { + octave_value val = sr.varval (m_context); - if (val.is_defined ()) - return val; - } + if (val.is_defined ()) + return val; } } - if (local_funcs) - { - // Subfunction. I think it only makes sense to check for - // subfunctions if we are currently executing a function defined - // from a .m file. + // Subfunction. I think it only makes sense to check for + // subfunctions if we are currently executing a function defined + // from a .m file. - octave_value fcn = find_subfunction (name); + octave_value fcn = find_subfunction (name); - if (fcn.is_defined ()) - return fcn; - } + if (fcn.is_defined ()) + return fcn; - return symtab.fcn_table_find (name, args, local_funcs); + return symtab.fcn_table_find (name, ovl ()); } symbol_record&
--- a/libinterp/corefcn/symscope.h Wed Nov 21 14:54:22 2018 -0500 +++ b/libinterp/corefcn/symscope.h Wed Nov 21 15:24:17 2018 -0500 @@ -181,9 +181,7 @@ } } - octave_value - find (const std::string& name, const octave_value_list& args, - bool skip_variables, bool local_funcs); + octave_value find (const std::string& name); symbol_record& insert (const std::string& name, bool force_add = false); @@ -718,13 +716,9 @@ m_rep->inherit (donor_scope.get_rep ()); } - octave_value - find (const std::string& name, const octave_value_list& args, - bool skip_variables, bool local_funcs) + octave_value find (const std::string& name) { - return (m_rep - ? m_rep->find (name, args, skip_variables, local_funcs) - : octave_value ()); + return m_rep ? m_rep->find (name) : octave_value (); } symbol_record&
--- a/libinterp/corefcn/symtab.cc Wed Nov 21 14:54:22 2018 -0500 +++ b/libinterp/corefcn/symtab.cc Wed Nov 21 15:24:17 2018 -0500 @@ -380,18 +380,17 @@ octave_value symbol_table::fcn_table_find (const std::string& name, - const octave_value_list& args, - bool local_funcs) + const octave_value_list& args) { fcn_table_iterator p = m_fcn_table.find (name); if (p != m_fcn_table.end ()) - return p->second.find (args, local_funcs); + return p->second.find (args); else { fcn_info finfo (name); - octave_value fcn = finfo.find (args, local_funcs); + octave_value fcn = finfo.find (args); if (fcn.is_defined ()) m_fcn_table[name] = finfo; @@ -404,8 +403,7 @@ octave_value symbol_table::find_function (const std::string& name, - const octave_value_list& args, - bool local_funcs) + const octave_value_list& args) { octave_value fcn; @@ -417,7 +415,7 @@ return fcn; } - return fcn_table_find (name, args, local_funcs); + return fcn_table_find (name, args); } // FIXME: this function only finds legacy class methods, not
--- a/libinterp/corefcn/symtab.h Wed Nov 21 14:54:22 2018 -0500 +++ b/libinterp/corefcn/symtab.h Wed Nov 21 15:24:17 2018 -0500 @@ -210,13 +210,11 @@ octave_value fcn_table_find (const std::string& name, - const octave_value_list& args = octave_value_list (), - bool local_funcs = true); + const octave_value_list& args = octave_value_list ()); octave_value find_function (const std::string& name, - const octave_value_list& args = octave_value_list (), - bool local_funcs = true); + const octave_value_list& args = octave_value_list ()); octave_value find_user_function (const std::string& name) {
--- a/libinterp/octave-value/ov-classdef.cc Wed Nov 21 14:54:22 2018 -0500 +++ b/libinterp/octave-value/ov-classdef.cc Wed Nov 21 15:24:17 2018 -0500 @@ -3381,7 +3381,7 @@ octave::symbol_scope curr_scope = octave::__get_current_scope__ ("cdef_package::cdef_package_rep::find"); - return curr_scope.find (symbol_name, octave_value_list (), false, true); + return curr_scope.find (symbol_name); } octave_value_list @@ -3793,8 +3793,7 @@ octave::symbol_scope curr_scope = m_interpreter.get_current_scope (); - ov_cls = curr_scope.find (name, octave_value_list (), - false, true); + ov_cls = curr_scope.find (name); } else {
--- a/libinterp/octave-value/ov-fcn-handle.cc Wed Nov 21 14:54:22 2018 -0500 +++ b/libinterp/octave-value/ov-fcn-handle.cc Wed Nov 21 15:24:17 2018 -0500 @@ -1459,7 +1459,7 @@ } octave_value -make_fcn_handle (const std::string& nm, bool local_funcs) +make_fcn_handle (const std::string& nm) { octave_value retval; @@ -1593,17 +1593,15 @@ octave::symbol_table& symtab = octave::__get_symbol_table__ ("make_fcn_handle"); - octave_value f = symtab.find_function (tnm, octave_value_list (), - local_funcs); + octave_value f = symtab.find_function (tnm, octave_value_list ()); octave_function *fptr = f.function_value (true); // Here we are just looking to see if FCN is a method or constructor // for any class. - if (local_funcs && fptr - && (fptr->is_subfunction () || fptr->is_private_function () - || fptr->is_class_constructor () - || fptr->is_classdef_constructor ())) + if (fptr && (fptr->is_subfunction () || fptr->is_private_function () + || fptr->is_class_constructor () + || fptr->is_classdef_constructor ())) { // Locally visible function. retval = octave_value (new octave_fcn_handle (f, tnm)); @@ -1885,7 +1883,7 @@ warning_with_id ("Octave:str2func-global-argument", "str2func: second argument ignored"); - retval = make_fcn_handle (nm, true); + retval = make_fcn_handle (nm); } return retval;
--- a/libinterp/octave-value/ov-fcn-handle.h Wed Nov 21 14:54:22 2018 -0500 +++ b/libinterp/octave-value/ov-fcn-handle.h Wed Nov 21 15:24:17 2018 -0500 @@ -183,8 +183,7 @@ friend octave_value make_fcn_handle (const std::string &, bool); }; -extern octave_value make_fcn_handle (const std::string& nm, - bool local_funcs = true); +extern octave_value make_fcn_handle (const std::string& nm); class OCTINTERP_API
--- a/libinterp/parse-tree/oct-parse.yy Wed Nov 21 14:54:22 2018 -0500 +++ b/libinterp/parse-tree/oct-parse.yy Wed Nov 21 15:24:17 2018 -0500 @@ -5007,7 +5007,7 @@ // Check if this file is already loaded (or in the path) symbol_scope curr_scope = __get_current_scope__ ("source_file"); - octave_value ov_code = curr_scope.find (symbol, ovl (), false, true); + octave_value ov_code = curr_scope.find (symbol); // For compatibility with Matlab, accept both scripts and // functions.