changeset 10188:97ae300aa73a

improve implementation of break, continue, and return commands
author John W. Eaton <jwe@octave.org>
date Fri, 22 Jan 2010 14:37:33 -0500
parents a44d15813a39
children 8fa6ce1b21f2
files src/ChangeLog src/oct-parse.yy src/pt-eval.cc
diffstat 3 files changed, 40 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Fri Jan 22 12:12:21 2010 -0500
+++ b/src/ChangeLog	Fri Jan 22 14:37:33 2010 -0500
@@ -1,3 +1,16 @@
+2010-01-22  John W. Eaton  <jwe@octave.org>
+
+	* oct-parse.yy (make_break_command, make_continue_command,
+	make_return_command): Don't examine evaluator state here.
+	* pt-eval.cc (tree_evaluator::visit_break_command): Don't set
+	tree_break_command::breaking unless inside function or script
+	body, or inside a looping command.
+	(tree_evaluator::visit_continue_command): Likewise, for
+	tree_continue_command::continuing.
+	(tree_evaluator::visit_return_command): Likewise, for
+	tree_return_command::returning.  Act like dbcont if debugging
+	and in the top-level debugging stack frame.
+
 2010-01-22  John W. Eaton  <jwe@octave.org>
 
 	* oct-stream.cc (octave_base_stream::do_scanf): Don't skip
--- a/src/oct-parse.yy	Fri Jan 22 12:12:21 2010 -0500
+++ b/src/oct-parse.yy	Fri Jan 22 14:37:33 2010 -0500
@@ -2488,16 +2488,7 @@
   int l = break_tok->line ();
   int c = break_tok->column ();
 
-  // We check to see if we are evaluating a function, script, or loop
-  // so that we don't turn eval ("break;") inside a function, script,
-  // or loop into a no-op command.
-
-  if (lexer_flags.looping || current_function_depth > 0
-      || reading_script_file || tree_evaluator::in_fcn_or_script_body
-      || tree_evaluator::in_loop_command)
-    retval = new tree_break_command (l, c);
-  else
-    retval = new tree_no_op_command ("break", l, c);
+  retval = new tree_break_command (l, c);
 
   return retval;
 }
@@ -2512,13 +2503,7 @@
   int l = continue_tok->line ();
   int c = continue_tok->column ();
 
-  // We check to see if we are evaluating a loop so that we don't turn
-  // eval ("continue;") into a no-op command inside a loop.
-
-  if (lexer_flags.looping || tree_evaluator::in_loop_command)
-    retval = new tree_continue_command (l, c);
-  else
-    retval = new tree_no_op_command ("continue", l, c);
+  retval = new tree_continue_command (l, c);
 
   return retval;
 }
@@ -2533,24 +2518,7 @@
   int l = return_tok->line ();
   int c = return_tok->column ();
 
-  if (Vdebugging)
-    {
-      Vdebugging = false;
-
-      retval = new tree_no_op_command ("return", l, c);
-    }
-  else
-    {
-      // We check to see if we are evaluating a function or script so
-      // that we don't turn eval ("return;") inside a function, script,
-      // or loop into a no-op command.
-
-      if (current_function_depth > 0 || reading_script_file
-          || tree_evaluator::in_fcn_or_script_body)
-        retval = new tree_return_command (l, c);
-      else
-        retval = new tree_no_op_command ("return", l, c);
-    }
+  retval = new tree_return_command (l, c);
 
   return retval;
 }
--- a/src/pt-eval.cc	Fri Jan 22 12:12:21 2010 -0500
+++ b/src/pt-eval.cc	Fri Jan 22 14:37:33 2010 -0500
@@ -90,7 +90,9 @@
       if (debug_mode)
 	do_breakpoint (cmd.is_breakpoint ());
 
-      tree_break_command::breaking = 1;
+      if (tree_evaluator::in_fcn_or_script_body
+          || tree_evaluator::in_loop_command)
+        tree_break_command::breaking = 1;
     }
 }
 
@@ -101,10 +103,17 @@
 }
 
 void
-tree_evaluator::visit_continue_command (tree_continue_command&)
+tree_evaluator::visit_continue_command (tree_continue_command& cmd)
 {
   if (! error_state)
-    tree_continue_command::continuing = 1;
+    {
+      if (debug_mode)
+	do_breakpoint (cmd.is_breakpoint ());
+
+      if (tree_evaluator::in_fcn_or_script_body
+          || tree_evaluator::in_loop_command)
+        tree_continue_command::continuing = 1;
+    }
 }
 
 void
@@ -631,7 +640,18 @@
       if (debug_mode)
 	do_breakpoint (cmd.is_breakpoint ());
 
-      tree_return_command::returning = 1;
+      // Act like dbcont.
+
+      if (Vdebugging
+          && octave_call_stack::current_frame () == current_frame)
+        {
+          Vdebugging = false;
+
+          reset_debug_state;
+        }
+      else if (tree_evaluator::in_fcn_or_script_body
+               || tree_evaluator::in_loop_command)
+        tree_return_command::returning = 1;
     }
 }