# HG changeset patch # User John W. Eaton # Date 1233772086 18000 # Node ID 33783e94fb16957d69fa52b1c02c56fc3c294392 # Parent 739b0aebf2614d9dca884bd5c32ce60de0bf13a0 line number fixes and other evaluator tweaks diff -r 739b0aebf261 -r 33783e94fb16 src/ChangeLog --- a/src/ChangeLog Wed Feb 04 11:39:45 2009 -0500 +++ b/src/ChangeLog Wed Feb 04 13:28:06 2009 -0500 @@ -1,3 +1,38 @@ +2009-02-04 John W. Eaton + + * pt-loop.h, pt-loop.cc (evaluating_looping_command): + Delete global variable and all uses. + * parse.y, parse.h (evaluating_function_body): Delete global + variable and all uses. + (make_break_command, make_continue_command, make_return_command): + Use tree_evaluator::in_fcn_or_script_body and + tree_evaluator::in_loop_command instead of + evaluating_function_body and evaluating_looping_command. + + * pt-eval.h (tree_evaluator::in_function_or_script_body): + Delete member variable and all uses. + (tree_evaluator::reset): Delete function and all uses. + + * pt-eval.cc, pt-eval.h (tree_evaluator::in_fcn_or_script_body, + tree_evaluator::in_loop_command): New static variables. + (tree_evaluator::visit_simple_for_command, + tree_evaluator::visit_complex_for_command, + tree_evaluator::visit_while_command, + tree_evaluator::visit_do_until_command): Unwind-protect and set + tree_evaluator::in_loop_command instead of + evaluating_looping_command. + (tree_evaluator::visit_statement): Only call echo_code if + evaluating function or script and (Vecho_executing_commands & + ECHO_FUNCTIONS). Use tree_evaluator::in_fcn_or_script_body + instead of evaluating_function_body. + + * ov-usr-fcn.cc (octave_user_script::do_multi_index_op): + octave_user_function::do_multi_index_op): Unwind-protect and set + tree_evaluator::in_fcn_or_script_body. + + * pt-stmt.cc, pt-stmt.h (tree_statement::echo_code): + Rename from maybe_echo_code. Simplify. + 2009-02-04 Jaroslav Hajek * pt-loop.h (tree_simple_for_command::do_for_loop_once, diff -r 739b0aebf261 -r 33783e94fb16 src/ov-usr-fcn.cc --- a/src/ov-usr-fcn.cc Wed Feb 04 11:39:45 2009 -0500 +++ b/src/ov-usr-fcn.cc Wed Feb 04 13:28:06 2009 -0500 @@ -128,6 +128,9 @@ unwind_protect::add (octave_call_stack::unwind_pop, 0); + unwind_protect_bool (tree_evaluator::in_fcn_or_script_body); + tree_evaluator::in_fcn_or_script_body = true; + cmd_list->accept (*current_evaluator); if (tree_return_command::returning) @@ -430,8 +433,8 @@ // Evaluate the commands that make up the function. - unwind_protect_bool (evaluating_function_body); - evaluating_function_body = true; + unwind_protect_bool (tree_evaluator::in_fcn_or_script_body); + tree_evaluator::in_fcn_or_script_body = true; bool special_expr = (is_inline_function () || cmd_list->is_anon_function_body ()); diff -r 739b0aebf261 -r 33783e94fb16 src/parse.h --- a/src/parse.h Wed Feb 04 11:39:45 2009 -0500 +++ b/src/parse.h Wed Feb 04 13:28:06 2009 -0500 @@ -62,11 +62,6 @@ // TRUE means input is coming from startup file. extern bool input_from_startup_file; -// TRUE means that we are in the process of evaluating a function -// body. The parser might be called in that case if we are looking at -// an eval() statement. -extern bool evaluating_function_body; - // Keep track of symbol table information when parsing functions. extern std::stack symtab_context; diff -r 739b0aebf261 -r 33783e94fb16 src/parse.y --- a/src/parse.y Wed Feb 04 11:39:45 2009 -0500 +++ b/src/parse.y Wed Feb 04 13:28:06 2009 -0500 @@ -99,11 +99,6 @@ // TRUE means input is coming from startup file. bool input_from_startup_file = false; -// TRUE means that we are in the process of evaluating a function -// body. The parser might be called in that case if we are looking at -// an eval() statement. -bool evaluating_function_body = false; - // Keep a count of how many END tokens we expect. int end_tokens_expected = 0; @@ -2216,9 +2211,13 @@ 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 || lexer_flags.defining_func - || reading_script_file || evaluating_function_body - || evaluating_looping_command) + || 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); @@ -2236,7 +2235,10 @@ int l = continue_tok->line (); int c = continue_tok->column (); - if (lexer_flags.looping || evaluating_looping_command) + // 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); @@ -2262,8 +2264,12 @@ } 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 (lexer_flags.defining_func || reading_script_file - || evaluating_function_body) + || tree_evaluator::in_fcn_or_script_body) retval = new tree_return_command (l, c); else retval = new tree_no_op_command ("return", l, c); diff -r 739b0aebf261 -r 33783e94fb16 src/pt-eval.cc --- a/src/pt-eval.cc Wed Feb 04 11:39:45 2009 -0500 +++ b/src/pt-eval.cc Wed Feb 04 13:28:06 2009 -0500 @@ -53,6 +53,10 @@ bool tree_evaluator::debug_mode = false; +bool tree_evaluator::in_fcn_or_script_body = false; + +bool tree_evaluator::in_loop_command = false; + int tree_evaluator::db_line = -1; int tree_evaluator::db_column = -1; @@ -266,9 +270,9 @@ unwind_protect::begin_frame ("tree_evaluator::visit_simple_for_command"); - unwind_protect_bool (evaluating_looping_command); + unwind_protect_bool (in_loop_command); - evaluating_looping_command = true; + in_loop_command = true; tree_expression *expr = cmd.control_expr (); @@ -395,9 +399,9 @@ unwind_protect::begin_frame ("tree_evaluator::visit_complex_for_command"); - unwind_protect_bool (evaluating_looping_command); + unwind_protect_bool (in_loop_command); - evaluating_looping_command = true; + in_loop_command = true; tree_expression *expr = cmd.control_expr (); @@ -638,10 +642,13 @@ if (cmd || expr) { - if (in_function_or_script_body) - octave_call_stack::set_statement (&stmt); + if (in_fcn_or_script_body) + { + octave_call_stack::set_statement (&stmt); - stmt.maybe_echo_code (in_function_or_script_body); + if (Vecho_executing_commands & ECHO_FUNCTIONS) + stmt.echo_code (); + } try { @@ -649,7 +656,7 @@ cmd->accept (*this); else { - if (in_function_or_script_body && Vsilent_functions) + if (in_fcn_or_script_body && Vsilent_functions) expr->set_print_flag (false); // FIXME -- maybe all of this should be packaged in @@ -708,9 +715,6 @@ { OCTAVE_QUIT; - in_function_or_script_body - = lst.is_function_body () || lst.is_script_body (); - elt->accept (*this); if (error_state) @@ -986,9 +990,9 @@ unwind_protect::begin_frame ("tree_evaluator::visit_while_command"); - unwind_protect_bool (evaluating_looping_command); + unwind_protect_bool (in_loop_command); - evaluating_looping_command = true; + in_loop_command = true; tree_expression *expr = cmd.condition (); @@ -1034,9 +1038,9 @@ unwind_protect::begin_frame ("tree_evaluator::visit_do_until_command"); - unwind_protect_bool (evaluating_looping_command); + unwind_protect_bool (in_loop_command); - evaluating_looping_command = true; + in_loop_command = true; tree_expression *expr = cmd.condition (); diff -r 739b0aebf261 -r 33783e94fb16 src/pt-eval.h --- a/src/pt-eval.h Wed Feb 04 11:39:45 2009 -0500 +++ b/src/pt-eval.h Wed Feb 04 13:28:06 2009 -0500 @@ -41,16 +41,10 @@ typedef void (*decl_elt_init_fcn) (tree_decl_elt&); - tree_evaluator (bool in_function_or_script_body_arg = false) - : in_function_or_script_body (in_function_or_script_body_arg) { } + tree_evaluator (void) { } ~tree_evaluator (void) { } - void reset (void) - { - in_function_or_script_body = false; - } - void visit_anon_fcn_handle (tree_anon_fcn_handle&); void visit_argument_list (tree_argument_list&); @@ -152,9 +146,13 @@ static bool debug_mode; -private: + // TRUE means we are evaluating a function or script body. + static bool in_fcn_or_script_body; - bool in_function_or_script_body; + // TRUE means we are evaluating some kind of looping construct. + static bool in_loop_command; + +private: void do_decl_init_list (decl_elt_init_fcn fcn, tree_decl_init_list *init_list); diff -r 739b0aebf261 -r 33783e94fb16 src/pt-loop.cc --- a/src/pt-loop.cc Wed Feb 04 11:39:45 2009 -0500 +++ b/src/pt-loop.cc Wed Feb 04 13:28:06 2009 -0500 @@ -42,9 +42,6 @@ #include "pt-walk.h" #include "unwind-prot.h" -// TRUE means we are evaluating some kind of looping construct. -bool evaluating_looping_command = false; - // While. tree_while_command::~tree_while_command (void) diff -r 739b0aebf261 -r 33783e94fb16 src/pt-loop.h --- a/src/pt-loop.h Wed Feb 04 11:39:45 2009 -0500 +++ b/src/pt-loop.h Wed Feb 04 13:28:06 2009 -0500 @@ -37,9 +37,6 @@ #include "pt-cmd.h" #include "symtab.h" -// TRUE means we are evaluating some kind of looping construct. -extern bool evaluating_looping_command; - // While. class diff -r 739b0aebf261 -r 33783e94fb16 src/pt-stmt.cc --- a/src/pt-stmt.cc Wed Feb 04 11:39:45 2009 -0500 +++ b/src/pt-stmt.cc Wed Feb 04 13:28:06 2009 -0500 @@ -83,15 +83,11 @@ } void -tree_statement::maybe_echo_code (bool in_function_or_script_body) +tree_statement::echo_code (void) { - if (in_function_or_script_body - && (Vecho_executing_commands & ECHO_FUNCTIONS)) - { - tree_print_code tpc (octave_stdout, VPS4); + tree_print_code tpc (octave_stdout, VPS4); - accept (tpc); - } + accept (tpc); } bool diff -r 739b0aebf261 -r 33783e94fb16 src/pt-stmt.h --- a/src/pt-stmt.h Wed Feb 04 11:39:45 2009 -0500 +++ b/src/pt-stmt.h Wed Feb 04 13:28:06 2009 -0500 @@ -73,7 +73,7 @@ int line (void) const; int column (void) const; - void maybe_echo_code (bool in_function_body); + void echo_code (void); tree_command *command (void) { return cmd; } diff -r 739b0aebf261 -r 33783e94fb16 src/toplev.cc --- a/src/toplev.cc Wed Feb 04 11:39:45 2009 -0500 +++ b/src/toplev.cc Wed Feb 04 13:28:06 2009 -0500 @@ -556,8 +556,6 @@ { if (global_command) { - current_evaluator->reset (); - global_command->accept (*current_evaluator); delete global_command;