Mercurial > octave
diff libinterp/parse-tree/pt-fcn-handle.cc @ 23599:5cb3a2bb5e1e
don't use singleton for symbol_table
This is the first of a series of changes to make the symbol table a
part of the interpreter instead of a global object. These changes
also aim to simplify the implementation of symbol table so that it is
easier to understand and modify.
* Functions now own their scope (workspace) data.
* The list of subfunctions is contained in the scope rather than a
global list.
* symtab.h, symtab.cc (class symbol_table): Don't use singleton
pattern.
* interpreter.h, interpreter.cc (interpreter::m_symbol_table): New
data member.
(interpreter::~interpreter): Don't set instance to 0.
* interpreter-private.h, interpreter-private.cc
(__get_symbol_table__): New function.
Change all uses of call_stack to access call_stack object from the
interpreter.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 09 Jun 2017 02:21:28 -0400 |
parents | c452180ab672 |
children | db947ba52118 |
line wrap: on
line diff
--- a/libinterp/parse-tree/pt-fcn-handle.cc Fri Jun 09 11:36:34 2017 -0400 +++ b/libinterp/parse-tree/pt-fcn-handle.cc Fri Jun 09 02:21:28 2017 -0400 @@ -28,6 +28,7 @@ #include "call-stack.h" #include "error.h" +#include "interpreter-private.h" #include "ovl.h" #include "ov-fcn-handle.h" #include "pt-fcn-handle.h" @@ -63,26 +64,37 @@ return new_fh; } + tree_anon_fcn_handle::~tree_anon_fcn_handle (void) + { + delete m_parameter_list; + delete m_return_list; + delete m_statement_list; + } + tree_expression * tree_anon_fcn_handle::dup (symbol_table::scope_id, symbol_table::context_id) const { tree_parameter_list *param_list = parameter_list (); tree_parameter_list *ret_list = return_list (); - tree_statement_list *cmd_list = body (); - symbol_table::scope_id this_scope = scope (); + tree_statement_list *stmt_list = body (); + + symbol_table::scope_id af_sid = scope (); + symbol_table::scope_id af_parent_sid = parent_scope (); - symbol_table::scope_id new_scope = symbol_table::dup_scope (this_scope); + symbol_table& symtab + = octave::__get_symbol_table__ ("tree_anon_fcn_handle::dup"); + + symbol_table::scope_id new_scope = symtab.dup_scope (af_sid); if (new_scope > 0) - symbol_table::inherit (new_scope, symbol_table::current_scope (), - symbol_table::current_context ()); + symtab.inherit (new_scope); tree_anon_fcn_handle *new_afh = new tree_anon_fcn_handle (param_list ? param_list->dup (new_scope, 0) : 0, ret_list ? ret_list->dup (new_scope, 0) : 0, - cmd_list ? cmd_list->dup (new_scope, 0) : 0, - new_scope, line (), column ()); + stmt_list ? stmt_list->dup (new_scope, 0) : 0, + new_scope, af_parent_sid, line (), column ()); new_afh->copy_base (*this);