# HG changeset patch # User John W. Eaton # Date 1209958591 14400 # Node ID ea9cb4d68dbf333ea3ba23297567c0eff51a682b # Parent e26d0931c044b51894318f2554c48028edaa8304 avoid installing subfunctions twice diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,7 +1,8 @@ 2008-05-04 John W. Eaton - * 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. diff --git a/src/parse.y b/src/parse.y --- 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; } diff --git a/src/pt-cmd.cc b/src/pt-cmd.cc --- 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 (); } }