Mercurial > octave-nkf
diff src/symtab.cc @ 9463:d34baf412786
support non-local function lookups in str2func
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 27 Jul 2009 10:39:09 +0200 |
parents | cf714e75c656 |
children | 25ed2d6aacf6 |
line wrap: on
line diff
--- a/src/symtab.cc Mon Jul 27 08:34:54 2009 +0200 +++ b/src/symtab.cc Mon Jul 27 10:39:09 2009 +0200 @@ -484,9 +484,10 @@ // built-in function octave_value -symbol_table::fcn_info::fcn_info_rep::find (const octave_value_list& args) +symbol_table::fcn_info::fcn_info_rep::find (const octave_value_list& args, + bool local_funcs) { - octave_value retval = xfind (args); + octave_value retval = xfind (args, local_funcs); if (! retval.is_defined ()) { @@ -496,89 +497,93 @@ load_path::update (); - retval = xfind (args); + retval = xfind (args, local_funcs); } return retval; } octave_value -symbol_table::fcn_info::fcn_info_rep::xfind (const octave_value_list& args) +symbol_table::fcn_info::fcn_info_rep::xfind (const octave_value_list& args, + bool 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. + 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. + + scope_val_iterator r = subfunctions.find (xcurrent_scope); + + octave_function *curr_fcn = 0; - scope_val_iterator r = subfunctions.find (xcurrent_scope); + if (r != subfunctions.end ()) + { + // FIXME -- out-of-date check here. - octave_function *curr_fcn = 0; + return r->second; + } + else + { + curr_fcn = octave_call_stack::current (); - if (r != subfunctions.end ()) - { - // FIXME -- out-of-date check here. + if (curr_fcn) + { + scope_id pscope = curr_fcn->parent_fcn_scope (); + + if (pscope > 0) + { + r = subfunctions.find (pscope); - return r->second; - } - else - { - curr_fcn = octave_call_stack::current (); + if (r != subfunctions.end ()) + { + // FIXME -- out-of-date check here. + + return r->second; + } + } + } + } + + // Private function. + + if (! curr_fcn) + curr_fcn = octave_call_stack::current (); if (curr_fcn) - { - scope_id pscope = curr_fcn->parent_fcn_scope (); - - if (pscope > 0) - { - r = subfunctions.find (pscope); - - if (r != subfunctions.end ()) - { - // FIXME -- out-of-date check here. + { + std::string dir_name = curr_fcn->dir_name (); - return r->second; - } - } - } - } + if (! dir_name.empty ()) + { + str_val_iterator q = private_functions.find (dir_name); - // Private function. - - if (! curr_fcn) - curr_fcn = octave_call_stack::current (); - - if (curr_fcn) - { - std::string dir_name = curr_fcn->dir_name (); + if (q == private_functions.end ()) + { + octave_value val = load_private_function (dir_name); - if (! dir_name.empty ()) - { - str_val_iterator q = private_functions.find (dir_name); + if (val.is_defined ()) + return val; + } + else + { + octave_value& fval = q->second; - if (q == private_functions.end ()) - { - 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_internal (fval); - if (fval.is_defined ()) - out_of_date_check_internal (fval); + if (fval.is_defined ()) + return fval; + else + { + octave_value val = load_private_function (dir_name); - if (fval.is_defined ()) - return fval; - else - { - octave_value val = load_private_function (dir_name); - - if (val.is_defined ()) - return val; - } - } - } + if (val.is_defined ()) + return val; + } + } + } + } } // Class constructors. The class name and function name are the same. @@ -1030,20 +1035,15 @@ } octave_value -symbol_table::fcn_info::find (const octave_value_list& args) -{ - return rep->find (args); -} - -octave_value symbol_table::find (const std::string& name, const octave_value_list& args, - bool skip_variables) + bool skip_variables, + bool local_funcs) { symbol_table *inst = get_instance (xcurrent_scope); return inst - ? inst->do_find (name, args, skip_variables) + ? inst->do_find (name, args, skip_variables, local_funcs) : octave_value (); } @@ -1057,7 +1057,8 @@ octave_value symbol_table::find_function (const std::string& name, - const octave_value_list& args) + const octave_value_list& args, + bool local_funcs) { octave_value retval; @@ -1078,13 +1079,14 @@ size_t pos = name.find_first_of (Vfilemarker); if (pos == std::string::npos) - retval = find (name, args, true); + retval = find (name, args, true, local_funcs); else { std::string fcn_scope = name.substr (0, pos); scope_id stored_scope = xcurrent_scope; xcurrent_scope = xtop_scope; - octave_value parent = find_function (name.substr(0, pos)); + octave_value parent = find_function (name.substr(0, pos), + octave_value_list (), false); if (parent.is_defined ()) { @@ -1206,7 +1208,8 @@ octave_value symbol_table::do_find (const std::string& name, const octave_value_list& args, - bool skip_variables) + bool skip_variables, + bool local_funcs) { octave_value retval; @@ -1237,12 +1240,12 @@ fcn_table_iterator p = fcn_table.find (name); if (p != fcn_table.end ()) - return p->second.find (args); + return p->second.find (args, local_funcs); else { fcn_info finfo (name); - octave_value fcn = finfo.find (args); + octave_value fcn = finfo.find (args, local_funcs); if (fcn.is_defined ()) fcn_table[name] = finfo;