Mercurial > hg > octave-terminal
changeset 9445:c5f03874ea2a
simplify symbol_table::find and associated functions
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 22 Jul 2009 11:41:41 +0200 |
parents | 0c785ad961fa |
children | 419a5f9c1538 |
files | src/ChangeLog src/pt-id.cc src/pt-id.h src/pt-idx.cc src/symtab.cc src/symtab.h src/variables.cc |
diffstat | 7 files changed, 72 insertions(+), 162 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,18 @@ +2009-07-22 Jaroslav Hajek <highegg@gmail.com> + + * symtab.cc (symbol_table::find, + symbol_table::find_function, + symbol_table::symbol_record::find, + symbol_table::fcn_info::find, + symbol_table::fcn_info::fcn_info_rep::find, + symbol_table::fcn_info::fcn_info_rep::xfind): Simplify argument lists. + * symtab.h: Update declarations. + * pt-id.cc (tree_identifier::rvalue): Simplify. + * pt-id.h (tree_identifier::do_lookup): Simplify. + * pt-idx.cc (tree_index_expression::rvalue): Update. + * variables.cc (symbol_exist): Update. + + 2009-07-21 John W. Eaton <jwe@octave.org> * symtab.cc (symbol_table::builtin_find,
--- a/src/pt-id.cc +++ b/src/pt-id.cc @@ -60,11 +60,7 @@ if (error_state) return retval; - octave_value_list evaluated_args; - bool args_evaluated = false; - - octave_value val = xsym().find (0, string_vector (), evaluated_args, - args_evaluated); + octave_value val = xsym ().find (); if (val.is_defined ()) {
--- a/src/pt-id.h +++ b/src/pt-id.h @@ -84,10 +84,9 @@ // then .mex files, then .m files. octave_value - do_lookup (tree_argument_list *args, const string_vector& arg_names, - octave_value_list& evaluated_args, bool& args_evaluated) + do_lookup (const octave_value_list& args = octave_value_list ()) { - return xsym().find (args, arg_names, evaluated_args, args_evaluated); + return xsym().find (args); } void mark_global (void) { xsym().mark_global (); }
--- a/src/pt-idx.cc +++ b/src/pt-idx.cc @@ -296,8 +296,12 @@ if (n > 0) { string_vector anm = *(arg_nm.begin ()); + have_args = true; + first_args = al -> convert_to_const_vector (); + first_args.stash_name_tags (anm); - first_expr_val = id->do_lookup (al, anm, first_args, have_args); + if (! error_state) + first_expr_val = id->do_lookup (first_args); } } }
--- a/src/symtab.cc +++ b/src/symtab.cc @@ -96,10 +96,7 @@ } octave_value -symbol_table::symbol_record::find (tree_argument_list *args, - const string_vector& arg_names, - octave_value_list& evaluated_args, - bool& args_evaluated) const +symbol_table::symbol_record::find (const octave_value_list& args) const { octave_value retval; @@ -113,12 +110,10 @@ { // Use cached fcn_info pointer if possible. if (rep->finfo) - retval = rep->finfo->find (args, arg_names, - evaluated_args, args_evaluated); + retval = rep->finfo->find (args); else { - retval = symbol_table::find_function (name (), args, arg_names, - evaluated_args, args_evaluated); + retval = symbol_table::find_function (name (), args); if (retval.is_defined ()) rep->finfo = get_fcn_info (name ()); @@ -429,11 +424,11 @@ } static std::string -get_dispatch_type (const octave_value_list& evaluated_args) +get_dispatch_type (const octave_value_list& args) { std::string dispatch_type; - int n = evaluated_args.length (); + int n = args.length (); if (n > 0) { @@ -443,7 +438,7 @@ for (i = 0; i < n; i++) { - octave_value arg = evaluated_args(i); + octave_value arg = args(i); if (arg.is_object ()) { @@ -454,7 +449,7 @@ for (int j = i+1; j < n; j++) { - octave_value arg = evaluated_args(j); + octave_value arg = args(j); if (arg.is_object ()) { @@ -472,7 +467,7 @@ { // No object found, so use class of first argument. - dispatch_type = evaluated_args(0).class_name (); + dispatch_type = args(0).class_name (); } } @@ -493,30 +488,10 @@ // function on the path // built-in function -// Notes: -// -// FIXME -- we need to evaluate the argument list to determine the -// dispatch type. The method used here works (pass in the args, pass -// out the evaluated args and a flag saying whether the evaluation was -// needed), but it seems a bit inelegant. We do need to save the -// evaluated args in some way to avoid evaluating them multiple times. -// Maybe evaluated args could be attached to the tree_argument_list -// object? Then the argument list could be evaluated outside of this -// function and we could elimnate the arg_names, evaluated_args, and -// args_evaluated arguments. We would still want to avoid computing -// the dispatch type unless it is needed, so the args should be passed -// rather than the dispatch type. But the arguments will need to be -// evaluated no matter what, so evaluating them beforehand should be -// OK. If the evaluated arguments are attached to args, then we would -// need to determine the appropriate place(s) to clear them (for -// example, before returning from tree_index_expression::rvalue). - octave_value -symbol_table::fcn_info::fcn_info_rep::find - (tree_argument_list *args, const string_vector& arg_names, - octave_value_list& evaluated_args, bool& args_evaluated) +symbol_table::fcn_info::fcn_info_rep::find (const octave_value_list& args) { - octave_value retval = xfind (args, arg_names, evaluated_args, args_evaluated); + octave_value retval = xfind (args); if (! retval.is_defined ()) { @@ -526,16 +501,14 @@ load_path::update (); - retval = xfind (args, arg_names, evaluated_args, args_evaluated); + retval = xfind (args); } return retval; } octave_value -symbol_table::fcn_info::fcn_info_rep::xfind - (tree_argument_list *args, const string_vector& arg_names, - octave_value_list& evaluated_args, bool& args_evaluated) +symbol_table::fcn_info::fcn_info_rep::xfind (const octave_value_list& args) { // Subfunction. I think it only makes sense to check for // subfunctions if we are currently executing a function defined @@ -644,42 +617,21 @@ // Class methods. - if (args_evaluated || (args && args->length () > 0)) + if (! args.empty ()) { - if (! args_evaluated) - evaluated_args = args->convert_to_const_vector (); - - if (! error_state) - { - int n = evaluated_args.length (); - - if (n > 0 && ! args_evaluated) - evaluated_args.stash_name_tags (arg_names); + std::string dispatch_type = get_dispatch_type (args); - args_evaluated = true; - - if (n > 0) - { - std::string dispatch_type = get_dispatch_type (evaluated_args); + octave_value fcn = find_method (dispatch_type); - octave_value fcn = find_method (dispatch_type); - - if (fcn.is_defined ()) - return fcn; - } - } - else - return octave_value (); + if (fcn.is_defined ()) + return fcn; } - // Legacy dispatch. We just check args_evaluated here because the - // actual evaluation will have happened already when searching for - // class methods. + // Legacy dispatch. - if (args_evaluated && ! dispatch_map.empty ()) + if (! args.empty () && ! dispatch_map.empty ()) { - std::string dispatch_type = - const_cast<const octave_value_list&>(evaluated_args)(0).type_name (); + std::string dispatch_type = args(0).type_name (); std::string fname; @@ -693,7 +645,7 @@ fname = p->second; octave_value fcn - = symbol_table::find_function (fname, evaluated_args); + = symbol_table::find_function (fname, args); if (fcn.is_defined ()) return fcn; @@ -1080,25 +1032,20 @@ } octave_value -symbol_table::fcn_info::find (tree_argument_list *args, - const string_vector& arg_names, - octave_value_list& evaluated_args, - bool& args_evaluated) +symbol_table::fcn_info::find (const octave_value_list& args) { - return rep->find (args, arg_names, evaluated_args, args_evaluated); + return rep->find (args); } octave_value -symbol_table::find (const std::string& name, tree_argument_list *args, - const string_vector& arg_names, - octave_value_list& evaluated_args, bool& args_evaluated, - bool skip_variables) +symbol_table::find (const std::string& name, + const octave_value_list& args, + bool skip_variables) { symbol_table *inst = get_instance (xcurrent_scope); return inst - ? inst->do_find (name, args, arg_names, evaluated_args, - args_evaluated, skip_variables) + ? inst->do_find (name, args, skip_variables) : octave_value (); } @@ -1111,10 +1058,8 @@ } octave_value -symbol_table::find_function (const std::string& name, tree_argument_list *args, - const string_vector& arg_names, - octave_value_list& evaluated_args, - bool& args_evaluated) +symbol_table::find_function (const std::string& name, + const octave_value_list& args) { octave_value retval; @@ -1135,8 +1080,7 @@ size_t pos = name.find_first_of (Vfilemarker); if (pos == std::string::npos) - retval = find (name, args, arg_names, evaluated_args, - args_evaluated, true); + retval = find (name, args, true); else { std::string fcn_scope = name.substr (0, pos); @@ -1153,9 +1097,7 @@ xcurrent_scope = parent_fcn->scope (); if (xcurrent_scope > 1) - retval = find_function (name.substr (pos + 1), args, - arg_names, evaluated_args, - args_evaluated); + retval = find_function (name.substr (pos + 1), args); } } @@ -1264,10 +1206,9 @@ } octave_value -symbol_table::do_find (const std::string& name, tree_argument_list *args, - const string_vector& arg_names, - octave_value_list& evaluated_args, - bool& args_evaluated, bool skip_variables) +symbol_table::do_find (const std::string& name, + const octave_value_list& args, + bool skip_variables) { octave_value retval; @@ -1298,13 +1239,12 @@ fcn_table_iterator p = fcn_table.find (name); if (p != fcn_table.end ()) - return p->second.find (args, arg_names, evaluated_args, args_evaluated); + return p->second.find (args); else { fcn_info finfo (name); - octave_value fcn = finfo.find (args, arg_names, evaluated_args, - args_evaluated); + octave_value fcn = finfo.find (args); if (fcn.is_defined ()) fcn_table[name] = finfo;
--- a/src/symtab.h +++ b/src/symtab.h @@ -424,9 +424,7 @@ std::string name (void) const { return rep->name; } - octave_value - find (tree_argument_list *args, const string_vector& arg_names, - octave_value_list& evaluated_args, bool& args_evaluated) const; + octave_value find (const octave_value_list& args = octave_value_list ()) const; octave_value builtin_find (void) const; @@ -542,9 +540,7 @@ octave_value load_class_method (const std::string& dispatch_type); - octave_value - find (tree_argument_list *args, const string_vector& arg_names, - octave_value_list& evaluated_args, bool& args_evaluated); + octave_value find (const octave_value_list& args = octave_value_list ()); octave_value builtin_find (void); @@ -559,20 +555,9 @@ return function_on_path.is_defined (); } - octave_value find_function (void) + octave_value find_function (const octave_value_list& args = octave_value_list ()) { - octave_value_list args; - - return find_function (args); - } - - octave_value find_function (const octave_value_list& args) - { - string_vector arg_names; - octave_value_list evaluated_args = args; - bool args_evaluated = false; - - return find (0, arg_names, evaluated_args, args_evaluated); + return find (args); } void lock_subfunction (scope_id scope) @@ -735,9 +720,7 @@ private: - octave_value - xfind (tree_argument_list *args, const string_vector& arg_names, - octave_value_list& evaluated_args, bool& args_evaluated); + octave_value xfind (const octave_value_list& args); octave_value x_builtin_find (void); @@ -778,9 +761,7 @@ delete rep; } - octave_value - find (tree_argument_list *args, const string_vector& arg_names, - octave_value_list& evaluated_args, bool& args_evaluated); + octave_value find (const octave_value_list& args); octave_value builtin_find (void) { @@ -1052,9 +1033,8 @@ // Find a value corresponding to the given name in the table. static octave_value - find (const std::string& name, tree_argument_list *args, - const string_vector& arg_names, - octave_value_list& evaluated_args, bool& args_evaluated, + find (const std::string& name, + const octave_value_list& args = octave_value_list (), bool skip_variables = false); static octave_value builtin_find (const std::string& name); @@ -1193,9 +1173,8 @@ } static octave_value - find_function (const std::string& name, tree_argument_list *args, - const string_vector& arg_names, - octave_value_list& evaluated_args, bool& args_evaluated); + find_function (const std::string& name, + const octave_value_list& args = octave_value_list ()); static octave_value find_user_function (const std::string& name) { @@ -1205,23 +1184,6 @@ ? p->second.find_user_function () : octave_value (); } - static octave_value find_function (const std::string& name) - { - octave_value_list evaluated_args; - - return find_function (name, evaluated_args); - } - - static octave_value - find_function (const std::string& name, const octave_value_list& args) - { - string_vector arg_names; - octave_value_list evaluated_args = args; - bool args_evaluated = ! args.empty (); - - return find_function (name, 0, arg_names, evaluated_args, args_evaluated); - } - static void install_cmdline_function (const std::string& name, const octave_value& fcn) { @@ -2012,10 +1974,8 @@ } octave_value - do_find (const std::string& name, tree_argument_list *args, - const string_vector& arg_names, - octave_value_list& evaluated_args, bool& args_evaluated, - bool skip_variables); + do_find (const std::string& name, const octave_value_list& args, + bool skip_variables); octave_value do_builtin_find (const std::string& name);
--- a/src/variables.cc +++ b/src/variables.cc @@ -395,11 +395,7 @@ // name that is visible in the current scope will be in the local // symbol table. - octave_value_list evaluated_args; - bool args_evaluated = false; - - octave_value val = symbol_table::find (symbol_name, 0, string_vector (), - evaluated_args, args_evaluated); + octave_value val = symbol_table::find (symbol_name); if (val.is_defined ()) {