diff libinterp/corefcn/stack-frame.h @ 28793:c5953e65c6aa stable

track direct caller in stack frames * stack-frame.h, stack-frame.cc (stack_frame::m_parent_link): New data member to track direct parent, not just user-defined function, script, or scope frames as m_static_link does. (stack_frame::parent_link): New function. (stack_frame::stack_frame): Accept parent_link argument. Change all uses. (stack_frame::create): Accept parent_link argument. Change all uses. * call-stack.cc (call_stack::pop): Set m_curr_frame to parent_link, not static_link.
author John W. Eaton <jwe@octave.org>
date Fri, 25 Sep 2020 09:43:53 -0400
parents e760fef2829c
children 3bd58f479489 0a5b15007766
line wrap: on
line diff
--- a/libinterp/corefcn/stack-frame.h	Wed Sep 23 21:23:01 2020 +0200
+++ b/libinterp/corefcn/stack-frame.h	Fri Sep 25 09:43:53 2020 -0400
@@ -140,38 +140,44 @@
     stack_frame (void) = delete;
 
     stack_frame (tree_evaluator& tw, size_t index,
+                 const std::shared_ptr<stack_frame>& parent_link,
                  const std::shared_ptr<stack_frame>& static_link,
                  const std::shared_ptr<stack_frame>& access_link)
       : m_evaluator (tw), m_line (-1), m_column (-1), m_index (index),
-        m_static_link (static_link), m_access_link (access_link),
-        m_dispatch_class ()
+        m_parent_link (parent_link), m_static_link (static_link),
+        m_access_link (access_link), m_dispatch_class ()
     { }
 
     // Compiled function.
     static stack_frame *
     create (tree_evaluator& tw, octave_function *fcn, size_t index,
+            const std::shared_ptr<stack_frame>& parent_link,
             const std::shared_ptr<stack_frame>& static_link);
 
     // Script.
     static stack_frame *
     create (tree_evaluator& tw, octave_user_script *script, size_t index,
+            const std::shared_ptr<stack_frame>& parent_link,
             const std::shared_ptr<stack_frame>& static_link);
 
     // User-defined function.
     static stack_frame *
     create (tree_evaluator& tw, octave_user_function *fcn, size_t index,
+            const std::shared_ptr<stack_frame>& parent_link,
             const std::shared_ptr<stack_frame>& static_link,
             const std::shared_ptr<stack_frame>& access_link = std::shared_ptr<stack_frame> ());
 
     // Anonymous user-defined function with init vars.
     static stack_frame *
     create (tree_evaluator& tw, octave_user_function *fcn, size_t index,
+            const std::shared_ptr<stack_frame>& parent_link,
             const std::shared_ptr<stack_frame>& static_link,
             const local_vars_map& local_vars);
 
     // Scope.
     static stack_frame *
     create (tree_evaluator& tw, const symbol_scope& scope, size_t index,
+            const std::shared_ptr<stack_frame>& parent_link,
             const std::shared_ptr<stack_frame>& static_link);
 
     stack_frame (const stack_frame& elt) = default;
@@ -300,6 +306,9 @@
     }
 
     std::shared_ptr<stack_frame>
+    parent_link (void) const {return m_parent_link; }
+
+    std::shared_ptr<stack_frame>
     static_link (void) const {return m_static_link; }
 
     std::shared_ptr<stack_frame>
@@ -556,8 +565,13 @@
     // Index in call stack.
     size_t m_index;
 
+    // Pointer to the nearest parent frame.  May include compiled
+    // functions.
+    std::shared_ptr<stack_frame> m_parent_link;
+
     // Pointer to the nearest parent frame that contains variable
-    // information (script, function, or scope).
+    // information (script, function, or scope).  This link skips over
+    // compiled function parent frames.
     std::shared_ptr<stack_frame> m_static_link;
 
     // Pointer to the nearest lexical parent frame.  Used to access