comparison libinterp/parse-tree/pt-binop.h @ 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 ebb3ef964372
children 91cd85a75705
comparison
equal deleted inserted replaced
18107:834549618a52 18126:d76f790b4eec
44 44
45 tree_binary_expression (int l = -1, int c = -1, 45 tree_binary_expression (int l = -1, int c = -1,
46 octave_value::binary_op t 46 octave_value::binary_op t
47 = octave_value::unknown_binary_op) 47 = octave_value::unknown_binary_op)
48 : tree_expression (l, c), op_lhs (0), op_rhs (0), etype (t), 48 : tree_expression (l, c), op_lhs (0), op_rhs (0), etype (t),
49 eligible_for_braindead_shortcircuit (false) { } 49 eligible_for_braindead_shortcircuit (false),
50 braindead_shortcircuit_warning_issued (false) { }
50 51
51 tree_binary_expression (tree_expression *a, tree_expression *b, 52 tree_binary_expression (tree_expression *a, tree_expression *b,
52 int l = -1, int c = -1, 53 int l = -1, int c = -1,
53 octave_value::binary_op t 54 octave_value::binary_op t
54 = octave_value::unknown_binary_op) 55 = octave_value::unknown_binary_op)
55 : tree_expression (l, c), op_lhs (a), op_rhs (b), etype (t), 56 : tree_expression (l, c), op_lhs (a), op_rhs (b), etype (t),
56 eligible_for_braindead_shortcircuit (false) { } 57 eligible_for_braindead_shortcircuit (false),
58 braindead_shortcircuit_warning_issued (false) { }
57 59
58 ~tree_binary_expression (void) 60 ~tree_binary_expression (void)
59 { 61 {
60 delete op_lhs; 62 delete op_lhs;
61 delete op_rhs; 63 delete op_rhs;
62 } 64 }
63 65
64 void mark_braindead_shortcircuit (const std::string& file) 66 void mark_braindead_shortcircuit (void)
65 { 67 {
66 if (etype == octave_value::op_el_and || etype == octave_value::op_el_or) 68 if (etype == octave_value::op_el_and || etype == octave_value::op_el_or)
67 { 69 {
68 if (file.empty ())
69 warning_with_id ("Octave:possible-matlab-short-circuit-operator",
70 "possible Matlab-style short-circuit operator at line %d, column %d",
71 line (), column ());
72 else
73 warning_with_id ("Octave:possible-matlab-short-circuit-operator",
74 "%s: possible Matlab-style short-circuit operator at line %d, column %d",
75 file.c_str (), line (), column ());
76
77 eligible_for_braindead_shortcircuit = true; 70 eligible_for_braindead_shortcircuit = true;
78 71
79 op_lhs->mark_braindead_shortcircuit (file); 72 op_lhs->mark_braindead_shortcircuit ();
80 op_rhs->mark_braindead_shortcircuit (file); 73 op_rhs->mark_braindead_shortcircuit ();
81 } 74 }
82 } 75 }
83 76
84 bool has_magic_end (void) const 77 bool has_magic_end (void) const
85 { 78 {
119 octave_value::binary_op etype; 112 octave_value::binary_op etype;
120 113
121 // TRUE if this is an | or & expression in the condition of an IF 114 // TRUE if this is an | or & expression in the condition of an IF
122 // or WHILE statement. 115 // or WHILE statement.
123 bool eligible_for_braindead_shortcircuit; 116 bool eligible_for_braindead_shortcircuit;
117
118 // TRUE if we have already issued a warning about short circuiting
119 // for this operator.
120 bool braindead_shortcircuit_warning_issued;
121
122 void matlab_style_short_circuit_warning (const char *op);
124 123
125 // No copying! 124 // No copying!
126 125
127 tree_binary_expression (const tree_binary_expression&); 126 tree_binary_expression (const tree_binary_expression&);
128 127