# HG changeset patch # User John W. Eaton # Date 1554154402 0 # Node ID bd684aad1821acdc68b5cbcb947db26b252e8067 # Parent ac92aa74fa1a12529092a0079738765438168d15 eliminate some direct access to call stack in legacy class and function objects * pt-eval.h, pt-eval.cc (tree_evaluator::push_stack_frame, tree_evaluator::pop_stack_frame, tree_evaluator::is_class_method_executing, tree_evaluator::is_class_constructor_executing): New functions. * ov-class.cc (octave_class::get_current_method_class, octave_class::in_class_method, Fclass, Fsuperiorto, Finferiorto): Eliminate direct access to call stack. * ov-builtin.cc (octave_builtin::call): Likewise. * ov-fcn-handle.cc (octave_fcn_handle::call, octave_fcn_handle::push_closure_context, make_fcn_handle): Likewise. * ov-mex-fcn.cc (octave_mex_function::call): Likewise. diff -r ac92aa74fa1a -r bd684aad1821 libinterp/octave-value/ov-builtin.cc --- a/libinterp/octave-value/ov-builtin.cc Mon Apr 01 20:53:00 2019 +0000 +++ b/libinterp/octave-value/ov-builtin.cc Mon Apr 01 21:33:22 2019 +0000 @@ -24,7 +24,6 @@ # include "config.h" #endif -#include "call-stack.h" #include "error.h" #include "errwarn.h" #include "interpreter-private.h" @@ -51,11 +50,9 @@ octave::unwind_protect frame; - octave::call_stack& cs = octave::__get_call_stack__ ("octave_builtin::call"); + tw.push_stack_frame (this); - cs.push (this); - - frame.add_method (cs, &octave::call_stack::pop); + frame.add_method (tw, &octave::tree_evaluator::pop_stack_frame); octave::profiler& profiler = tw.get_profiler (); diff -r ac92aa74fa1a -r bd684aad1821 libinterp/octave-value/ov-class.cc --- a/libinterp/octave-value/ov-class.cc Mon Apr 01 20:53:00 2019 +0000 +++ b/libinterp/octave-value/ov-class.cc Mon Apr 01 21:33:22 2019 +0000 @@ -34,7 +34,6 @@ #include "lo-mappers.h" #include "Cell.h" -#include "call-stack.h" #include "defun.h" #include "error.h" #include "file-ops.h" @@ -229,10 +228,10 @@ if (nparents () > 0) { - octave::call_stack& cs - = octave::__get_call_stack__ ("octave_class::get_current_method_class"); + octave::tree_evaluator& tw + = octave::__get_evaluator__ ("octave_class::get_current_method_class"); - octave_function *fcn = cs.current (); + octave_function *fcn = tw.current_function (); // Here we are just looking to see if FCN is a method or constructor // for any class, not specifically this one. @@ -1642,10 +1641,10 @@ bool octave_class::in_class_method (void) { - octave::call_stack& cs - = octave::__get_call_stack__ ("octave_class::in_class_method"); + octave::tree_evaluator& tw + = octave::__get_evaluator__ ("octave_class::in_class_method"); - octave_function *fcn = cs.current (); + octave_function *fcn = tw.current_function (); return (fcn && (fcn->is_class_method () @@ -1737,9 +1736,9 @@ // Called as class constructor std::string id = args(1).xstring_value ("class: ID (class name) must be a string"); - octave::call_stack& cs = interp.get_call_stack (); + octave::tree_evaluator& tw = interp.get_evaluator (); - octave_function *fcn = cs.caller (); + octave_function *fcn = tw.caller_function (); if (! fcn) error ("class: invalid call from outside class constructor or method"); @@ -1962,9 +1961,9 @@ @seealso{inferiorto} @end deftypefn */) { - octave::call_stack& cs = interp.get_call_stack (); + octave::tree_evaluator& tw = interp.get_evaluator (); - octave_function *fcn = cs.caller (); + octave_function *fcn = tw.caller_function (); if (! fcn || ! fcn->is_class_constructor ()) error ("superiorto: invalid call from outside class constructor"); @@ -2000,9 +1999,9 @@ @seealso{superiorto} @end deftypefn */) { - octave::call_stack& cs = interp.get_call_stack (); + octave::tree_evaluator& tw = interp.get_evaluator (); - octave_function *fcn = cs.caller (); + octave_function *fcn = tw.caller_function (); if (! fcn || ! fcn->is_class_constructor ()) error ("inferiorto: invalid call from outside class constructor"); diff -r ac92aa74fa1a -r bd684aad1821 libinterp/octave-value/ov-fcn-handle.cc --- a/libinterp/octave-value/ov-fcn-handle.cc Mon Apr 01 20:53:00 2019 +0000 +++ b/libinterp/octave-value/ov-fcn-handle.cc Mon Apr 01 21:33:22 2019 +0000 @@ -36,7 +36,6 @@ #include "file-ops.h" #include "oct-locbuf.h" -#include "call-stack.h" #include "defaults.h" #include "defun.h" #include "error.h" @@ -386,12 +385,10 @@ octave::unwind_protect frame; - octave::call_stack& cs = interp.get_call_stack (); - - frame.add_method (cs, &octave::call_stack::set_dispatch_class, + frame.add_method (tw, &octave::tree_evaluator::set_dispatch_class, std::string ()); - cs.set_dispatch_class (m_dispatch_class); + tw.set_dispatch_class (m_dispatch_class); return of->call (tw, nargout, args, closure_context); } @@ -445,9 +442,7 @@ if (! m_closure_frames) m_closure_frames = new std::list (); - octave::call_stack& main_cs = tw.get_call_stack (); - - octave::stack_frame& curr_frame = main_cs.get_current_stack_frame (); + octave::stack_frame& curr_frame = tw.get_current_stack_frame (); octave::stack_frame *dup_frame = curr_frame.dup (); @@ -1838,12 +1833,10 @@ octave_fcn_handle *fh = new octave_fcn_handle (curr_scope, tnm); - call_stack& cs = interp.get_call_stack (); - std::string dispatch_class; - if (cs.is_class_method_executing (dispatch_class) - || cs.is_class_constructor_executing (dispatch_class)) + if (tw.is_class_method_executing (dispatch_class) + || tw.is_class_constructor_executing (dispatch_class)) fh->set_dispatch_class (dispatch_class); return octave_value (fh); diff -r ac92aa74fa1a -r bd684aad1821 libinterp/octave-value/ov-mex-fcn.cc --- a/libinterp/octave-value/ov-mex-fcn.cc Mon Apr 01 20:53:00 2019 +0000 +++ b/libinterp/octave-value/ov-mex-fcn.cc Mon Apr 01 21:33:22 2019 +0000 @@ -26,7 +26,6 @@ #include "oct-shlib.h" -#include "call-stack.h" #include "defaults.h" #include "dynamic-ld.h" #include "error.h" @@ -98,12 +97,9 @@ octave::unwind_protect frame; - octave::call_stack& cs - = octave::__get_call_stack__ ("octave_mex_function::call"); + tw.push_stack_frame (this); - cs.push (this); - - frame.add_method (cs, &octave::call_stack::pop); + frame.add_method (tw, &octave::tree_evaluator::pop_stack_frame); octave::profiler& profiler = tw.get_profiler (); diff -r ac92aa74fa1a -r bd684aad1821 libinterp/parse-tree/pt-eval.cc --- a/libinterp/parse-tree/pt-eval.cc Mon Apr 01 20:53:00 2019 +0000 +++ b/libinterp/parse-tree/pt-eval.cc Mon Apr 01 21:33:22 2019 +0000 @@ -1864,6 +1864,34 @@ return false; } + void tree_evaluator::push_stack_frame (const symbol_scope& scope) + { + m_call_stack.push (scope); + } + + void tree_evaluator::push_stack_frame (octave_user_function *fcn, + unwind_protect *up_frame, + stack_frame *closure_frames) + { + m_call_stack.push (fcn, up_frame, closure_frames); + } + + void tree_evaluator::push_stack_frame (octave_user_script *script, + unwind_protect *up_frame) + { + m_call_stack.push (script, up_frame); + } + + void tree_evaluator::push_stack_frame (octave_function *fcn) + { + m_call_stack.push (fcn); + } + + void tree_evaluator::pop_stack_frame (void) + { + m_call_stack.pop (); + } + int tree_evaluator::current_line (void) const { return m_call_stack.current_line (); @@ -1946,6 +1974,18 @@ m_call_stack.set_dispatch_class (class_name); } + bool + tree_evaluator::is_class_method_executing (std::string& dclass) const + { + return m_call_stack.is_class_method_executing (dclass); + } + + bool + tree_evaluator::is_class_constructor_executing (std::string& dclass) const + { + return m_call_stack.is_class_constructor_executing (dclass); + } + std::list tree_evaluator::backtrace_frames (octave_idx_type& curr_user_frame) const { diff -r ac92aa74fa1a -r bd684aad1821 libinterp/parse-tree/pt-eval.h --- a/libinterp/parse-tree/pt-eval.h Mon Apr 01 20:53:00 2019 +0000 +++ b/libinterp/parse-tree/pt-eval.h Mon Apr 01 21:33:22 2019 +0000 @@ -466,6 +466,19 @@ call_stack& get_call_stack (void) { return m_call_stack; } + void push_stack_frame (const symbol_scope& scope); + + void push_stack_frame (octave_user_function *fcn, + unwind_protect *up_frame, + stack_frame *closure_frames = nullptr); + + void push_stack_frame (octave_user_script *script, + unwind_protect *up_frame); + + void push_stack_frame (octave_function *fcn); + + void pop_stack_frame (void); + const stack_frame& get_current_stack_frame (void) const { return m_call_stack.get_current_stack_frame (); @@ -514,17 +527,19 @@ void restore_frame (size_t n); - bool goto_frame_relative (int n, bool verbose = false); + std::string get_dispatch_class (void) const; + + void set_dispatch_class (const std::string& class_name); + + bool is_class_method_executing (std::string& dispatch_class) const; + + bool is_class_constructor_executing (std::string& dispatch_class) const; std::list backtrace_frames (octave_idx_type& curr_user_frame) const; std::list backtrace_frames () const; - std::string get_dispatch_class (void) const; - - void set_dispatch_class (const std::string& class_name); - octave_map backtrace (octave_idx_type& curr_user_frame, bool print_subfn = true) const;