changeset 11304:c9fefa096ce2

echo commands in scripts
author John W. Eaton <jwe@octave.org>
date Wed, 01 Dec 2010 15:26:01 -0500
parents 5d1877a86180
children c9df571efe95
files src/ChangeLog src/ov-usr-fcn.cc src/pt-eval.cc src/pt-eval.h src/pt-pr-code.cc
diffstat 5 files changed, 54 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Wed Dec 01 19:55:47 2010 +0100
+++ b/src/ChangeLog	Wed Dec 01 15:26:01 2010 -0500
@@ -1,3 +1,25 @@
+2010-12-01  John W. Eaton  <jwe@octave.org>
+
+	* pt-pr-code.cc	(tree_print_code::visit_octave_user_function_trailer):
+	Don't indent or print "endfunction" here.
+	* ov-usr-fcn.cc (ov_user_script::do_multi_index_op): Save and
+	set tree_evaluator::statement_context, not
+	tree_evaluator::in_fcn_or_script_body.
+	(ov_user_function::do_multi_index_op): Likewise.
+	* pt-eval.cc: Initialize tree_evaluator::statement_context, not
+	tree_evaluator::in_fcn_or_script_body.
+	(tree_evaluator::visit_break_command): Check statement_context,
+	not in_fcn_or_script_body.
+	(tree_evaluator::visit_continue_command): Likewise.
+	(tree_evaluator::visit_return_command): Likewise.
+	(visit_statement): Also echo commands in scripts if
+	Vecho_executing_commands & ECHO_SCRIPTS is true.
+	* pt-eval.h (tree_evaluator::in_fcn_body,
+	tree_evaluator::in_script_body): New static variables.
+	(tree_evaluator::): Now an enum.
+	(tree_evaluator::in_function_or_script_body): Now an enum.
+	Rename from in_fcn_or_script_body.
+
 2010-12-01  Kai Habel  <kai.habel@gmx.de>
 
 	* DLD-FUNCTIONS/fltk_backend.cc (fltk_gui_mode): Fix gui mode
--- a/src/ov-usr-fcn.cc	Wed Dec 01 19:55:47 2010 +0100
+++ b/src/ov-usr-fcn.cc	Wed Dec 01 15:26:01 2010 -0500
@@ -129,8 +129,8 @@
 
                   frame.add_fcn (octave_call_stack::pop);
 
-                  frame.protect_var (tree_evaluator::in_fcn_or_script_body);
-                  tree_evaluator::in_fcn_or_script_body = true;
+                  frame.protect_var (tree_evaluator::statement_context);
+                  tree_evaluator::statement_context = tree_evaluator::script;
 
                   cmd_list->accept (*current_evaluator);
 
@@ -426,8 +426,8 @@
 
   // Evaluate the commands that make up the function.
 
-  frame.protect_var (tree_evaluator::in_fcn_or_script_body);
-  tree_evaluator::in_fcn_or_script_body = true;
+  frame.protect_var (tree_evaluator::statement_context);
+  tree_evaluator::statement_context = tree_evaluator::function;
 
   bool special_expr = (is_inline_function ()
                        || cmd_list->is_anon_function_body ());
--- a/src/pt-eval.cc	Wed Dec 01 19:55:47 2010 +0100
+++ b/src/pt-eval.cc	Wed Dec 01 15:26:01 2010 -0500
@@ -54,7 +54,8 @@
 
 bool tree_evaluator::debug_mode = false;
 
-bool tree_evaluator::in_fcn_or_script_body = false;
+tree_evaluator::stmt_list_type tree_evaluator::statement_context
+  = tree_evaluator::other;
 
 bool tree_evaluator::in_loop_command = false;
 
@@ -94,8 +95,8 @@
       if (debug_mode)
         do_breakpoint (cmd.is_breakpoint ());
 
-      if (tree_evaluator::in_fcn_or_script_body
-          || tree_evaluator::in_loop_command)
+      if (statement_context == function || statement_context == script
+          || in_loop_command)
         tree_break_command::breaking = 1;
     }
 }
@@ -114,8 +115,8 @@
       if (debug_mode)
         do_breakpoint (cmd.is_breakpoint ());
 
-      if (tree_evaluator::in_fcn_or_script_body
-          || tree_evaluator::in_loop_command)
+      if (statement_context == function || statement_context == script
+          || in_loop_command)
         tree_continue_command::continuing = 1;
     }
 }
@@ -656,8 +657,8 @@
 
           reset_debug_state ();
         }
-      else if (tree_evaluator::in_fcn_or_script_body
-               || tree_evaluator::in_loop_command)
+      else if (statement_context == function || statement_context == script
+               || in_loop_command)
         tree_return_command::returning = 1;
     }
 }
@@ -682,7 +683,7 @@
 
   if (cmd || expr)
     {
-      if (in_fcn_or_script_body)
+      if (statement_context == function || statement_context == script)
         {
           // Skip commands issued at a debug> prompt to avoid disturbing
           // the state of the program we are debugging.
@@ -690,7 +691,13 @@
           if (! Vdebugging)
             octave_call_stack::set_statement (&stmt);
 
-          if (Vecho_executing_commands & ECHO_FUNCTIONS)
+          // FIXME -- we need to distinguish functions from scripts to
+          // get this right.
+          if ((statement_context == script
+               && ((Vecho_executing_commands & ECHO_SCRIPTS)
+                   || (Vecho_executing_commands & ECHO_FUNCTIONS)))
+              || (statement_context == function
+                  && (Vecho_executing_commands & ECHO_FUNCTIONS)))
             stmt.echo_code ();
         }
 
@@ -703,7 +710,8 @@
               if (debug_mode)
                 do_breakpoint (expr->is_breakpoint ());
 
-              if (in_fcn_or_script_body && Vsilent_functions)
+              if ((statement_context == function || statement_context == script)
+                  && Vsilent_functions)
                 expr->set_print_flag (false);
 
               // FIXME -- maybe all of this should be packaged in
--- a/src/pt-eval.h	Wed Dec 01 19:55:47 2010 +0100
+++ b/src/pt-eval.h	Wed Dec 01 15:26:01 2010 -0500
@@ -147,8 +147,16 @@
 
   static bool debug_mode;
 
-  // TRUE means we are evaluating a function or script body.
-  static bool in_fcn_or_script_body;
+  // Possible types of evaluation contexts.
+  enum stmt_list_type
+  {
+    function,  // function body
+    script,    // script file
+    other      // command-line input or eval string
+  };
+
+  // The context for the current evaluation.
+  static stmt_list_type statement_context;
 
   // TRUE means we are evaluating some kind of looping construct.
   static bool in_loop_command;
--- a/src/pt-pr-code.cc	Wed Dec 01 19:55:47 2010 +0100
+++ b/src/pt-pr-code.cc	Wed Dec 01 15:26:01 2010 -0500
@@ -419,10 +419,6 @@
 {
   print_indented_comment (fcn.trailing_comment ());
 
-  indent ();
-
-  os << "endfunction";
-
   newline ();
 }