comparison libinterp/parse-tree/pt-binop.cc @ 18126: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
comparison
equal deleted inserted replaced
18107:834549618a52 18126:d76f790b4eec
34 #include "pt-walk.h" 34 #include "pt-walk.h"
35 #include "variables.h" 35 #include "variables.h"
36 36
37 // TRUE means we mark | and & expressions for braindead short-circuit 37 // TRUE means we mark | and & expressions for braindead short-circuit
38 // behavior. 38 // behavior.
39 static bool Vdo_braindead_shortcircuit_evaluation; 39 static bool Vdo_braindead_shortcircuit_evaluation = true;
40 40
41 // Binary expressions. 41 // Binary expressions.
42 42
43 octave_value_list 43 octave_value_list
44 tree_binary_expression::rvalue (int nargout) 44 tree_binary_expression::rvalue (int nargout)
50 oper () . c_str ()); 50 oper () . c_str ());
51 else 51 else
52 retval = rvalue1 (nargout); 52 retval = rvalue1 (nargout);
53 53
54 return retval; 54 return retval;
55 }
56
57 void
58 tree_binary_expression::matlab_style_short_circuit_warning (const char *op)
59 {
60 warning_with_id ("Octave:possible-matlab-short-circuit-operator",
61 "Matlab-style short-circuit operation performed for operator %s",
62 op);
63
64 braindead_shortcircuit_warning_issued = true;
55 } 65 }
56 66
57 octave_value 67 octave_value
58 tree_binary_expression::rvalue1 (int) 68 tree_binary_expression::rvalue1 (int)
59 { 69 {
81 { 91 {
82 if (a_true) 92 if (a_true)
83 { 93 {
84 if (etype == octave_value::op_el_or) 94 if (etype == octave_value::op_el_or)
85 { 95 {
96 matlab_style_short_circuit_warning ("|");
86 result = true; 97 result = true;
87 goto done; 98 goto done;
88 } 99 }
89 } 100 }
90 else 101 else
91 { 102 {
92 if (etype == octave_value::op_el_and) 103 if (etype == octave_value::op_el_and)
93 goto done; 104 {
105 matlab_style_short_circuit_warning ("&");
106 goto done;
107 }
94 } 108 }
95 109
96 if (op_rhs) 110 if (op_rhs)
97 { 111 {
98 octave_value b = op_rhs->rvalue1 (); 112 octave_value b = op_rhs->rvalue1 ();
296 When called from inside a function with the @qcode{\"local\"} option, the\n\ 310 When called from inside a function with the @qcode{\"local\"} option, the\n\
297 variable is changed locally for the function and any subroutines it calls. \n\ 311 variable is changed locally for the function and any subroutines it calls. \n\
298 The original variable value is restored when exiting the function.\n\ 312 The original variable value is restored when exiting the function.\n\
299 @end deftypefn") 313 @end deftypefn")
300 { 314 {
315 static bool warned = false;
316 if (! warned)
317 {
318 warned = true;
319 warning_with_id ("Octave:deprecated-function",
320 "do_braindead_shortcircuit_evaluation is obsolete and will be removed from a future version of Octave");
321 }
322
301 return SET_INTERNAL_VARIABLE (do_braindead_shortcircuit_evaluation); 323 return SET_INTERNAL_VARIABLE (do_braindead_shortcircuit_evaluation);
302 } 324 }
303
304 /*
305 %!test
306 %! x = 0;
307 %! do_braindead_shortcircuit_evaluation (0);
308 %! if (1 | (x = 1))
309 %! endif
310 %! assert (x, 1);
311 %! do_braindead_shortcircuit_evaluation (1);
312 %! if (1 | (x = 0))
313 %! endif
314 %! assert (x, 1);
315 */