# HG changeset patch # User Jaroslav Hajek # Date 1252920234 -7200 # Node ID 8d79f36ebdde886f148ec9f789019bf8b0e2390b # Parent 5d49ff601e9bb9d340a582a67e79dc3caeb5f871 store scope->function pointer diff -r 5d49ff601e9b -r 8d79f36ebdde src/ChangeLog --- a/src/ChangeLog Sat Sep 12 10:15:38 2009 -0400 +++ b/src/ChangeLog Mon Sep 14 11:23:54 2009 +0200 @@ -1,3 +1,14 @@ +2009-09-14 Jaroslav Hajek + + * symtab.h (symbol_table::curr_fcn): New member field. + (symbol_table::get_curr_fcn, symbol_table::set_curr_fcn): New member + funcs. + * symtab.cc (symbol_table::fcn_info::fcn_info_rep::xfind): Use + symbol_table::get_curr_fcn. + (symbol_table::fcn_info::fcn_info_rep::x_builtin_find): Ditto. + * ov-usr-fcn.cc (octave_user_function::octave_user_function): Call + symbol_table::set_curr_fcn. + 2009-09-12 John W. Eaton * version.h (OCTAVE_VERSION): Now 3.3.50+. diff -r 5d49ff601e9b -r 8d79f36ebdde src/ov-usr-fcn.cc --- a/src/ov-usr-fcn.cc Sat Sep 12 10:15:38 2009 -0400 +++ b/src/ov-usr-fcn.cc Mon Sep 14 11:23:54 2009 +0200 @@ -191,6 +191,9 @@ { if (cmd_list) cmd_list->mark_as_function_body (); + + if (local_scope >= 0) + symbol_table::set_curr_fcn (this, local_scope); } octave_user_function::~octave_user_function (void) diff -r 5d49ff601e9b -r 8d79f36ebdde src/symtab.cc --- a/src/symtab.cc Sat Sep 12 10:15:38 2009 -0400 +++ b/src/symtab.cc Mon Sep 14 11:23:54 2009 +0200 @@ -41,7 +41,6 @@ #include "pager.h" #include "parse.h" #include "pt-arg-list.h" -#include "toplev.h" #include "unwind-prot.h" #include "utils.h" #include "debug.h" @@ -535,7 +534,7 @@ scope_val_iterator r = subfunctions.find (xcurrent_scope); - octave_function *curr_fcn = 0; + octave_user_function *curr_fcn = symbol_table::get_curr_fcn (); if (r != subfunctions.end ()) { @@ -545,8 +544,6 @@ } else { - curr_fcn = octave_call_stack::current (); - if (curr_fcn) { scope_id pscope = curr_fcn->parent_fcn_scope (); @@ -567,9 +564,6 @@ // Private function. - if (! curr_fcn) - curr_fcn = octave_call_stack::current (); - if (curr_fcn) { std::string dir_name = curr_fcn->dir_name (); @@ -765,7 +759,7 @@ // Private function. - octave_function *curr_fcn = octave_call_stack::current (); + octave_user_function *curr_fcn = symbol_table::get_curr_fcn (); if (curr_fcn) { diff -r 5d49ff601e9b -r 8d79f36ebdde src/symtab.h --- a/src/symtab.h Sat Sep 12 10:15:38 2009 -0400 +++ b/src/symtab.h Mon Sep 14 11:23:54 2009 +0200 @@ -34,6 +34,7 @@ #include "regex-match.h" class tree_argument_list; +class octave_user_function; #include "oct-obj.h" #include "ov.h" @@ -1793,6 +1794,24 @@ parent_map[classname] = parent_list; } + static octave_user_function *get_curr_fcn (scope_id scope = xcurrent_scope) + { + symbol_table *inst = get_instance (scope); + return inst->curr_fcn; + } + + static void set_curr_fcn (octave_user_function *curr_fcn, + scope_id scope = xcurrent_scope) + { + assert (scope != xtop_scope && scope != xglobal_scope); + symbol_table *inst = get_instance (scope); + // FIXME: normally, functions should not usurp each other's scope. + // If for any incredible reason this is needed, call + // set_user_function (0, scope) first. + assert (inst->curr_fcn == 0 || curr_fcn == 0); + inst->curr_fcn = curr_fcn; + } + private: typedef std::map::const_iterator table_const_iterator; @@ -1817,6 +1836,9 @@ // Map from symbol names to symbol info. std::map table; + // The associated user code (may be null). + octave_user_function *curr_fcn; + // Map from names of global variables to values. static std::map global_table; @@ -1854,7 +1876,7 @@ static context_id xcurrent_context; symbol_table (void) - : table_name (), table () { } + : table_name (), table (), curr_fcn (0) { } ~symbol_table (void) { }