Mercurial > hg > octave-lojdl
changeset 7968:0d607e8dbbfa
eliminate curr_parent_function; fix subfunction lookup
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 23 Jul 2008 17:16:50 -0400 |
parents | 6add0f974aee |
children | 4f9e8eeb2059 |
files | src/ChangeLog src/ov-fcn.h src/ov-usr-fcn.cc src/ov-usr-fcn.h src/parse.y src/symtab.cc src/toplev.cc src/toplev.h |
diffstat | 8 files changed, 52 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,22 @@ +2008-07-23 John W. Eaton <jwe@octave.org> + + * ov-usr_fcn.cc (octave_user_function::do_multi_index_op): + Don't unwind_protect and set curr_parent_function here. + * toplev.cc (curr_parent_function): Delete definition. + * toplev.h: (curr_parent_function): Delete declaration. + + * ov-usr-fcn.h (octave_user_function::parent_scope): New data member. + (octave_user_function::parent_fcn_scope, + octave_user_function::stash_parent_fcn_scope): New functions. + * ov-usr_fcn.cc (octave_user_function::octave_user_function): + Initialize parent_scope. + * symtab.cc (symbol_table::fcn_info::fcn_info_rep::find): + Check parent of current function by looking at call stack, not + global curr_parent_function variable. + * parse.y (frob_function): If parsing nested function, stash + current parent function scope. + * ov-fcn.h (octave_function::parent_fcn_scope): New virtual function. + 2008-07-22 Michael Goffioul <michael.goffioul@gmail.com> * graphics.cc (F__go_execute_callback__): New function.
--- a/src/ov-fcn.h +++ b/src/ov-fcn.h @@ -62,6 +62,8 @@ virtual std::string parent_fcn_name (void) const { return std::string (); } + virtual symbol_table::scope_id parent_fcn_scope (void) const { return -1; } + virtual void mark_fcn_file_up_to_date (const octave_time&) { } virtual symbol_table::scope_id scope (void) { return -1; }
--- a/src/ov-usr-fcn.cc +++ b/src/ov-usr-fcn.cc @@ -206,7 +206,7 @@ num_named_args (param_list ? param_list->length () : 0), nested_function (false), inline_function (false), class_constructor (false), class_method (false), xdispatch_class (), - args_passed (), num_args_passed (0), local_scope (sid) + args_passed (), num_args_passed (0), parent_scope (-1), local_scope (sid) { if (cmd_list) cmd_list->mark_as_function_body (); @@ -407,12 +407,6 @@ unwind_protect::add (symbol_table::clear_variables); } - if (! (is_nested_function () || is_inline_function ())) - { - unwind_protect_ptr (curr_parent_function); - curr_parent_function = this; - } - // Save and restore args passed for recursive calls. save_args_passed (args);
--- a/src/ov-usr-fcn.h +++ b/src/ov-usr-fcn.h @@ -197,6 +197,8 @@ void stash_parent_fcn_name (const std::string& p) { parent_name = p; } + void stash_parent_fcn_scope (symbol_table::scope_id ps) { parent_scope = ps; } + void stash_leading_comment (octave_comment_list *lc) { lead_comm = lc; } void stash_trailing_comment (octave_comment_list *tc) { trail_comm = tc; } @@ -213,6 +215,8 @@ std::string parent_fcn_name (void) const { return parent_name; } + symbol_table::scope_id parent_fcn_scope (void) const { return parent_scope; } + symbol_table::scope_id scope (void) { return local_scope; } octave_time time_parsed (void) const { return t_parsed; } @@ -380,6 +384,9 @@ // The number of arguments passed in. int num_args_passed; + // The scope of the parent function, if any. + symbol_table::scope_id parent_scope; + symbol_table::scope_id local_scope; #if 0
--- a/src/parse.y +++ b/src/parse.y @@ -2439,7 +2439,6 @@ octave_user_function *fcn = new octave_user_function (symbol_table::current_scope (), param_list, 0, body); - if (fcn) { @@ -2501,7 +2500,10 @@ fcn->mark_relative (); if (lexer_flags.parsing_nested_function) - fcn->stash_parent_fcn_name (parent_function_name); + { + fcn->stash_parent_fcn_name (parent_function_name); + fcn->stash_parent_fcn_scope (symbol_table::parent_scope ()); + } if (lexer_flags.parsing_class_method) {
--- a/src/symtab.cc +++ b/src/symtab.cc @@ -404,29 +404,40 @@ scope_val_iterator r = subfunctions.find (xcurrent_scope); + octave_function *curr_fcn = 0; + if (r != subfunctions.end ()) { // FIXME -- out-of-date check here. return r->second; } - else if (curr_parent_function) + else { - scope_id pscope = curr_parent_function->scope (); + curr_fcn = octave_call_stack::current (); - r = subfunctions.find (pscope); + if (curr_fcn) + { + scope_id pscope = curr_fcn->parent_fcn_scope (); - if (r != subfunctions.end ()) - { - // FIXME -- out-of-date check here. + if (pscope > 0) + { + r = subfunctions.find (pscope); - return r->second; + if (r != subfunctions.end ()) + { + // FIXME -- out-of-date check here. + + return r->second; + } + } } } // Private function. - octave_function *curr_fcn = octave_call_stack::current (); + if (! curr_fcn) + curr_fcn = octave_call_stack::current (); if (curr_fcn) {
--- a/src/toplev.cc +++ b/src/toplev.cc @@ -90,9 +90,6 @@ // Current command to execute. tree_statement_list *global_command = 0; -// Pointer to parent function that is currently being evaluated. -octave_function *curr_parent_function = 0; - octave_call_stack *octave_call_stack::instance = 0; int
--- a/src/toplev.h +++ b/src/toplev.h @@ -59,9 +59,6 @@ // Current command to execute. extern OCTINTERP_API tree_statement_list *global_command; -// Pointer to parent function that is currently being evaluated. -extern OCTINTERP_API octave_function *curr_parent_function; - // TRUE means we are ready to interpret commands, but not everything // is ready for interactive use. extern OCTINTERP_API bool octave_interpreter_ready;