diff libinterp/corefcn/call-stack.cc @ 27873:020d0e8f7ac6

reafactor mlock, munlock, and mislocked functions * interpreter.h, interpreter.cc (interpreter::mlock, interpreter::munlock, interpreter::mislocked): Revamp. Provide versions that act on current function in the call stack (possibly skipping the first found) and versions of munlock and mislocked that accept function names. * call-stack.h, call-stack.cc (call_stack::current): Delete. (call_stack::current_function): New function. Change all uses of call_stack::current to use this function instead. (call_stack::caller): Delete. (call_stack::caller_function): New function, define in terms of current_function. Change all uses of call_stack::caller to use this function instead. (call_stack::mlock): Delete. * ov-fcn.h (octave_function::islocked): Now const. * pt-eval.h, pt-eval.cc (tree_evaluator::current_function, tree_evaluator::current_function_name, tree_evaluator::mlock): New argument, SKIP_FIRST. (tree_evaluator::munlock, tree_evaluator::mislocked): New functions. * variables.cc (Fmlock, Fmunlock, Fmislocked): Simplify. Decode arguments and call interpreter fucntions.
author John W. Eaton <jwe@octave.org>
date Tue, 17 Dec 2019 12:26:09 -0500
parents e06ce39f78ad
children b442ec6dda5c
line wrap: on
line diff
--- a/libinterp/corefcn/call-stack.cc	Thu Dec 26 08:11:00 2019 -0800
+++ b/libinterp/corefcn/call-stack.cc	Tue Dec 17 12:26:09 2019 -0500
@@ -64,6 +64,29 @@
     push (symbol_scope ("top scope"));
   }
 
+  octave_function * call_stack::current_function (bool skip_first) const
+  {
+    if (m_cs.empty ())
+      error ("current_function: call stack is empty");
+
+    octave_function *fcn = nullptr;
+
+    size_t idx = size ();
+
+    if (idx > 1 && skip_first)
+      --idx;
+
+    while (--idx)
+      {
+        fcn = m_cs[idx]->function ();
+
+        if (fcn)
+          break;
+      }
+
+    return fcn;
+  }
+
   int call_stack::current_line (void) const
   {
     int retval = -1;
@@ -275,7 +298,7 @@
   {
     dispatch_class = "";
 
-    octave_function *f = current ();
+    octave_function *f = current_function ();
 
     bool retval = (f && f->is_class_method ());
 
@@ -289,7 +312,7 @@
   {
     dispatch_class = "";
 
-    octave_function *f = current ();
+    octave_function *f = current_function ();
 
     bool retval = (f && f->is_class_constructor ());
 
@@ -720,41 +743,6 @@
       pop ();
   }
 
-  void call_stack::mlock (void) const
-  {
-    if (m_cs.empty ())
-      error ("mlock: call stack is empty");
-
-    octave_function *fcn = nullptr;
-
-    size_t idx = size ();
-
-    while (--idx)
-      {
-        const stack_frame *elt = m_cs[idx];
-        fcn = elt->function ();
-
-        if (fcn)
-          {
-            if (fcn->is_builtin_function ())
-              {
-                if (fcn->name () == "mlock")
-                  continue;
-
-                warning ("mlock: locking built-in function has no effect");
-                return;
-              }
-
-            break;
-          }
-      }
-
-    if (! fcn)
-      error ("mlock: invalid use outside a function");
-
-    fcn->lock ();
-  }
-
   symbol_info_list call_stack::all_variables (void)
   {
     return m_cs[m_curr_frame]->all_variables ();
@@ -1095,12 +1083,12 @@
       {
         if (verbose)
           {
-            std::string caller_function_name;
-            octave_function *caller_function = caller ();
-            if (caller_function)
-              caller_function_name = caller_function->name ();
+            std::string caller_fcn_name;
+            octave_function *caller_fcn = caller_function ();
+            if (caller_fcn)
+              caller_fcn_name = caller_fcn->name ();
 
-            return symbol_stats.map_value (caller_function_name, 1);
+            return symbol_stats.map_value (caller_fcn_name, 1);
           }
         else
           return Cell (string_vector (symbol_names));