Mercurial > octave
diff libinterp/octave-value/ov-usr-fcn.h @ 24037:21915520ac7b
use more direct method for non-local symbol access (bug #38236)
* pt-id.h, pd-id.cc (tree_evaluator::get_current_scope): New function.
* symtab.h, symtab.cc (symbol_table::symbol_reference): Delete class.
(symbol_table::dummy_symbol_record): Delete static data member.
* oct-lvalue.h, oct-lvalue.cc (octave_lvalue::sym): Use symbol_record,
not symbol_reference. Change all uses.
(octave_lvalue::black_hole): New data member.
(octave_lvalue:is_black_hole): Use it.
(octave_lvalue::mark_black_hole): New function.
* pt-eval.cc (tree_identifier::sym): Use symbol_record, not
symbol_reference. Change all uses.
(tree_black_hole::lvalue): Explicitly mark retval as black_hole.
(tree_evaluator::visit_tree_identifier): Adapt to
tree_identifier::symbol returning symbol_record, not symbol_reference.
* oct-parse.in.yy (push_script_symtab, begin_file): New non-terminals.
(file): Use begin_file to start script and classdef files.
Use separate symbol table scope when parsing scripts.
* ov-usr-fcn.h, ov-usr-fcn.cc (octave_user_code::m_scope): Move here
from octave_user_fcn.
(octave_user_code::scope): Likewise.
(octave_user_script::octave_user_script): New argument scope.
(octave_user_script::call): Add
symbol_table::scope::unbind_script_symbols to unwind_protect frame.
Call scope::bind_script_symbols to access evaluation scope.
(octave_user_function::octave_user_function): Pass scope argument to
octave_user_code base class.
* symtab.h, symtab.cc (symbol_record_rep::m_fwd_rep): New data
member. Change member functions to forward to secondary rep if it is
defined.
(symbol_record::bind_fwd_rep, symbol_record_rep::bind_fwd_rep,
symbol_record::unbind_fwd_rep, symbol_record_rep::unbind_fwd_rep):
New functions.
(scope::bind_script_symbols, scope::unbind_script_symbols): New functions.
(scope::varval, scope::global_varval, scope::top_level_varval):
Now const.
(scope::update_nest): Set forwarding rep for nonlocal symbol.
(scope::look_nonlocal): Likewise.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 13 Sep 2017 17:10:51 -0400 |
parents | 4f12819a634f |
children | 51e408a7d38f |
line wrap: on
line diff
--- a/libinterp/octave-value/ov-usr-fcn.h Wed Sep 13 16:42:14 2017 -0700 +++ b/libinterp/octave-value/ov-usr-fcn.h Wed Sep 13 17:10:51 2017 -0400 @@ -61,15 +61,18 @@ protected: octave_user_code (const std::string& nm, + octave::symbol_table::scope *scope = nullptr, const std::string& ds = "") - : octave_function (nm, ds), curr_unwind_protect_frame (nullptr), - m_file_info (nullptr) + : octave_function (nm, ds), m_scope (scope), m_file_info (nullptr), + curr_unwind_protect_frame (nullptr) { } public: octave_user_code (void) - : octave_function () { } + : octave_function (), m_scope (nullptr), m_file_info (nullptr), + curr_unwind_protect_frame (nullptr) + { } // No copying! @@ -94,6 +97,8 @@ void cache_function_text (const std::string& text, const octave::sys::time& timestamp); + octave::symbol_table::scope *scope (void) { return m_scope; } + virtual std::map<std::string, octave_value> subfunctions (void) const; virtual octave::tree_statement_list * body (void) = 0; @@ -102,12 +107,15 @@ void get_file_info (void); - // pointer to the current unwind_protect frame of this function. - octave::unwind_protect *curr_unwind_protect_frame; + // Our symbol table scope. + octave::symbol_table::scope *m_scope; // Cached text of function or script code with line offsets // calculated. octave::file_info *m_file_info; + + // pointer to the current unwind_protect frame of this function. + octave::unwind_protect *curr_unwind_protect_frame; }; // Scripts. @@ -120,10 +128,12 @@ octave_user_script (void); octave_user_script (const std::string& fnm, const std::string& nm, - octave::tree_statement_list *cmds, + octave::symbol_table::scope *scope = nullptr, + octave::tree_statement_list *cmds = nullptr, const std::string& ds = ""); octave_user_script (const std::string& fnm, const std::string& nm, + octave::symbol_table::scope *scope = nullptr, const std::string& ds = ""); // No copying! @@ -273,8 +283,6 @@ octave::symbol_table::scope * parent_fcn_scope (void) const { return parent_scope; } - octave::symbol_table::scope *scope (void) { return m_scope; } - octave::sys::time time_parsed (void) const { return t_parsed; } octave::sys::time time_checked (void) const { return t_checked; } @@ -411,9 +419,6 @@ std::string ctor_type_str (void) const; - // Our symbol table scope. - octave::symbol_table::scope *m_scope; - // List of arguments for this function. These are local variables. octave::tree_parameter_list *param_list;