# HG changeset patch # User John W. Eaton # Date 1291235161 18000 # Node ID c9fefa096ce25f9f05cffcc821de9169b4ab6010 # Parent 5d1877a86180736afd74247b76f7449f3bd53a23 echo commands in scripts diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,25 @@ +2010-12-01 John W. Eaton + + * 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 * DLD-FUNCTIONS/fltk_backend.cc (fltk_gui_mode): Fix gui mode diff --git a/src/ov-usr-fcn.cc b/src/ov-usr-fcn.cc --- a/src/ov-usr-fcn.cc +++ b/src/ov-usr-fcn.cc @@ -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 ()); diff --git a/src/pt-eval.cc b/src/pt-eval.cc --- a/src/pt-eval.cc +++ b/src/pt-eval.cc @@ -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 diff --git a/src/pt-eval.h b/src/pt-eval.h --- a/src/pt-eval.h +++ b/src/pt-eval.h @@ -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; diff --git a/src/pt-pr-code.cc b/src/pt-pr-code.cc --- a/src/pt-pr-code.cc +++ b/src/pt-pr-code.cc @@ -419,10 +419,6 @@ { print_indented_comment (fcn.trailing_comment ()); - indent (); - - os << "endfunction"; - newline (); }