Mercurial > hg > octave-lyh
changeset 7755:ea9cb4d68dbf
avoid installing subfunctions twice
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 04 May 2008 23:36:31 -0400 |
parents | e26d0931c044 |
children | 45de7d8dac72 |
files | src/ChangeLog src/parse.y src/pt-cmd.cc |
diffstat | 3 files changed, 35 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,7 +1,8 @@ 2008-05-04 John W. Eaton <jwe@octave.org> - * pt-cmd.cc (tree_function_def::eval): Only define command-line - function if we are executing in the top-level scope. + * parse.y (frob_function): Don't install subfunctions here. + (finish_function): Handle subfunctions here. + Conditionally define tree_function_def object here. * symtab.h (symbol_table::fcn_info::fcn_info_rep::find_function): Initialize args_evaluated.
--- a/src/parse.y +++ b/src/parse.y @@ -2529,21 +2529,7 @@ help_buf.pop (); } - if (lexer_flags.parsing_nested_function) - { - std::string nm = fcn->name (); - - fcn->mark_as_nested_function (); - - symbol_table::install_subfunction (nm, octave_value (fcn)); - - if (lexer_flags.parsing_nested_function < 0) - { - lexer_flags.parsing_nested_function = 0; - symbol_table::reset_parent_scope (); - } - } - else if (reading_fcn_file) + if (reading_fcn_file && ! lexer_flags.parsing_nested_function) curr_fcn_ptr = fcn; else curr_fcn_ptr = 0; @@ -2566,11 +2552,31 @@ fcn->stash_leading_comment (lc); fcn->define_ret_list (ret_list); + + if (lexer_flags.parsing_nested_function) + { + std::string nm = fcn->name (); + + fcn->mark_as_nested_function (); + + symbol_table::install_subfunction (nm, octave_value (fcn)); + + if (lexer_flags.parsing_nested_function < 0) + { + lexer_flags.parsing_nested_function = 0; + symbol_table::reset_parent_scope (); + } + } + else if (! curr_fcn_ptr) + { + // FIXME -- there should be a better way to indicate that we + // should create a tree_function_def object other than + // looking at curr_fcn_ptr... + + retval = new tree_function_def (fcn); + } } - if (! curr_fcn_ptr) - retval = new tree_function_def (fcn); - return retval; }
--- a/src/pt-cmd.cc +++ b/src/pt-cmd.cc @@ -47,21 +47,18 @@ void tree_function_def::eval (void) { - if (symbol_table::at_top_level ()) - { - octave_function *f = function (); + octave_function *f = function (); - if (f) - { - std::string nm = f->name (); + if (f) + { + std::string nm = f->name (); - symbol_table::install_cmdline_function (nm, fcn); + symbol_table::install_cmdline_function (nm, fcn); - // Make sure that any variable with the same name as the new - // function is cleared. + // Make sure that any variable with the same name as the new + // function is cleared. - symbol_table::varref (nm) = octave_value (); - } + symbol_table::varref (nm) = octave_value (); } }