Mercurial > hg > octave-shane
changeset 8669:33783e94fb16
line number fixes and other evaluator tweaks
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 04 Feb 2009 13:28:06 -0500 |
parents | 739b0aebf261 |
children | 6f5b2835325c |
files | src/ChangeLog src/ov-usr-fcn.cc src/parse.h src/parse.y src/pt-eval.cc src/pt-eval.h src/pt-loop.cc src/pt-loop.h src/pt-stmt.cc src/pt-stmt.h src/toplev.cc |
diffstat | 11 files changed, 85 insertions(+), 56 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,38 @@ +2009-02-04 John W. Eaton <jwe@octave.org> + + * 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 <highegg@gmail.com> * pt-loop.h (tree_simple_for_command::do_for_loop_once,
--- a/src/ov-usr-fcn.cc +++ b/src/ov-usr-fcn.cc @@ -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 ());
--- a/src/parse.h +++ b/src/parse.h @@ -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<symbol_table::scope_id> symtab_context;
--- a/src/parse.y +++ b/src/parse.y @@ -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);
--- a/src/pt-eval.cc +++ b/src/pt-eval.cc @@ -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 ();
--- a/src/pt-eval.h +++ b/src/pt-eval.h @@ -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);
--- a/src/pt-loop.cc +++ b/src/pt-loop.cc @@ -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)
--- a/src/pt-loop.h +++ b/src/pt-loop.h @@ -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
--- a/src/pt-stmt.cc +++ b/src/pt-stmt.cc @@ -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