Mercurial > octave-nkf
comparison src/pt-binop.h @ 11091:5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 08 Oct 2010 15:22:47 -0400 |
parents | f3b65e1ae355 |
children | fd0a3ac60b0e |
comparison
equal
deleted
inserted
replaced
11090:2adf4736dafa | 11091:5677f3f7b5fa |
---|---|
44 public: | 44 public: |
45 | 45 |
46 tree_binary_expression (int l = -1, int c = -1, | 46 tree_binary_expression (int l = -1, int c = -1, |
47 octave_value::binary_op t | 47 octave_value::binary_op t |
48 = octave_value::unknown_binary_op) | 48 = octave_value::unknown_binary_op) |
49 : tree_expression (l, c), op_lhs (0), op_rhs (0), etype (t) { } | 49 : tree_expression (l, c), op_lhs (0), op_rhs (0), etype (t), |
50 eligible_for_braindead_shortcircuit (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), |
57 eligible_for_braindead_shortcircuit (false) { } | |
56 | 58 |
57 ~tree_binary_expression (void) | 59 ~tree_binary_expression (void) |
58 { | 60 { |
59 delete op_lhs; | 61 delete op_lhs; |
60 delete op_rhs; | 62 delete op_rhs; |
63 } | |
64 | |
65 void mark_braindead_shortcircuit (const std::string& file) | |
66 { | |
67 if (etype == octave_value::op_el_and | |
68 || etype == octave_value::op_el_or) | |
69 { | |
70 if (file.empty ()) | |
71 warning_with_id ("Octave:possible-matlab-short-circuit-operator", | |
72 "possible Matlab-style short-circuit operator at line %d, column %d", | |
73 line (), column ()); | |
74 else | |
75 warning_with_id ("Octave:possible-matlab-short-circuit-operator", | |
76 "%s: possible Matlab-style short-circuit operator at line %d, column %d", | |
77 file.c_str (), line (), column ()); | |
78 | |
79 eligible_for_braindead_shortcircuit = true; | |
80 | |
81 op_lhs->mark_braindead_shortcircuit (file); | |
82 op_rhs->mark_braindead_shortcircuit (file); | |
83 } | |
61 } | 84 } |
62 | 85 |
63 bool has_magic_end (void) const | 86 bool has_magic_end (void) const |
64 { | 87 { |
65 return ((op_lhs && op_lhs->has_magic_end ()) | 88 return ((op_lhs && op_lhs->has_magic_end ()) |
94 | 117 |
95 private: | 118 private: |
96 | 119 |
97 // The type of the expression. | 120 // The type of the expression. |
98 octave_value::binary_op etype; | 121 octave_value::binary_op etype; |
122 | |
123 // TRUE if this is an | or & expression in the condition of an IF | |
124 // or WHILE statement. | |
125 bool eligible_for_braindead_shortcircuit; | |
99 | 126 |
100 // No copying! | 127 // No copying! |
101 | 128 |
102 tree_binary_expression (const tree_binary_expression&); | 129 tree_binary_expression (const tree_binary_expression&); |
103 | 130 |