Mercurial > octave-antonio
diff libinterp/parse-tree/pt-binop.cc @ 18127:d76f790b4eec gui-release
enable do_braindead_shortcircuit_evaluation by default and deprecate
* octave.cc (maximum_braindamage): Don't call
Fdo_brainded_shortcircuit_evaluation.
* pt-exp.h (tree_expression::mark_braindead_shortcircuit): Eliminate
file name argument.
* pt-binop.h, pt-binop.cc
(tree_binary_expression::mark_braindead_shortcircuit): Likewise.
* oct-parse.in.yy (if_cmd_list1, elseif_clause, loop_command):
Eliminate argument from call to mark_braindead_shortcircuit.
* pt-binop.h, pt-binop.cc (Vdo_braindead_shortcircuit_evaluation):
Initialize to true.
(tree_binary_expression::matlab_style_short_circuit_warning): New function.
(tree_binary_expression::rvalue1): Call
matlab_style_short_circuit_warning if short circuit evaluation occurs.
(Fdo_braindead_shortcircuit_evaluation): Display deprecated warning.
Delete tests for do_braindead_shortcircuit_evaluation.
(tree_binary_expression::braindead_shortcircuit_warning_issued): New
member variable.
* NEWS: Mention change in default value and deprecated function.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 11 Dec 2013 20:51:22 -0500 |
parents | 175b392e91fe |
children | 701e91ea0fe6 |
line wrap: on
line diff
--- a/libinterp/parse-tree/pt-binop.cc Thu Dec 05 11:48:58 2013 -0800 +++ b/libinterp/parse-tree/pt-binop.cc Wed Dec 11 20:51:22 2013 -0500 @@ -36,7 +36,7 @@ // TRUE means we mark | and & expressions for braindead short-circuit // behavior. -static bool Vdo_braindead_shortcircuit_evaluation; +static bool Vdo_braindead_shortcircuit_evaluation = true; // Binary expressions. @@ -54,6 +54,16 @@ return retval; } +void +tree_binary_expression::matlab_style_short_circuit_warning (const char *op) +{ + warning_with_id ("Octave:possible-matlab-short-circuit-operator", + "Matlab-style short-circuit operation performed for operator %s", + op); + + braindead_shortcircuit_warning_issued = true; +} + octave_value tree_binary_expression::rvalue1 (int) { @@ -83,6 +93,7 @@ { if (etype == octave_value::op_el_or) { + matlab_style_short_circuit_warning ("|"); result = true; goto done; } @@ -90,7 +101,10 @@ else { if (etype == octave_value::op_el_and) - goto done; + { + matlab_style_short_circuit_warning ("&"); + goto done; + } } if (op_rhs) @@ -298,18 +312,13 @@ The original variable value is restored when exiting the function.\n\ @end deftypefn") { + static bool warned = false; + if (! warned) + { + warned = true; + warning_with_id ("Octave:deprecated-function", + "do_braindead_shortcircuit_evaluation is obsolete and will be removed from a future version of Octave"); + } + return SET_INTERNAL_VARIABLE (do_braindead_shortcircuit_evaluation); } - -/* -%!test -%! x = 0; -%! do_braindead_shortcircuit_evaluation (0); -%! if (1 | (x = 1)) -%! endif -%! assert (x, 1); -%! do_braindead_shortcircuit_evaluation (1); -%! if (1 | (x = 0)) -%! endif -%! assert (x, 1); -*/