comparison libinterp/parse-tree/pt-binop.cc @ 20764:b10432a40432

eliminate more simple uses of error_state * dasrt.cc, debug.cc, find.cc, gammainc.cc, matrix_type.cc, ov-usr-fcn.cc, pt-assign.cc, pt-binop.cc: Eliminate simple uses of error_state.
author John W. Eaton <jwe@octave.org>
date Mon, 05 Oct 2015 20:37:19 -0400
parents 075a5e2e1ba5
children
comparison
equal deleted inserted replaced
20763:4bed806ee3d4 20764:b10432a40432
67 octave_value 67 octave_value
68 tree_binary_expression::rvalue1 (int) 68 tree_binary_expression::rvalue1 (int)
69 { 69 {
70 octave_value retval; 70 octave_value retval;
71 71
72 if (error_state)
73 return retval;
74
75 if (Vdo_braindead_shortcircuit_evaluation 72 if (Vdo_braindead_shortcircuit_evaluation
76 && eligible_for_braindead_shortcircuit) 73 && eligible_for_braindead_shortcircuit)
77 { 74 {
78 if (op_lhs) 75 if (op_lhs)
79 { 76 {
80 octave_value a = op_lhs->rvalue1 (); 77 octave_value a = op_lhs->rvalue1 ();
81 78
82 if (! error_state) 79 if (a.ndims () == 2 && a.rows () == 1 && a.columns () == 1)
83 { 80 {
84 if (a.ndims () == 2 && a.rows () == 1 && a.columns () == 1) 81 bool result = false;
85 { 82
86 bool result = false; 83 bool a_true = a.is_true ();
87 84
88 bool a_true = a.is_true ();
89
90 if (! error_state)
91 {
92 if (a_true)
93 {
94 if (etype == octave_value::op_el_or)
95 {
96 matlab_style_short_circuit_warning ("|");
97 result = true;
98 goto done;
99 }
100 }
101 else
102 {
103 if (etype == octave_value::op_el_and)
104 {
105 matlab_style_short_circuit_warning ("&");
106 goto done;
107 }
108 }
109
110 if (op_rhs)
111 {
112 octave_value b = op_rhs->rvalue1 ();
113
114 if (! error_state)
115 result = b.is_true ();
116 }
117
118 done:
119
120 if (! error_state)
121 return octave_value (result);
122 }
123 }
124 }
125 }
126 }
127
128 if (op_lhs)
129 {
130 octave_value a = op_lhs->rvalue1 ();
131
132 if (! error_state && a.is_defined () && op_rhs)
133 {
134 octave_value b = op_rhs->rvalue1 ();
135
136 if (! error_state && b.is_defined ())
137 {
138 BEGIN_PROFILER_BLOCK (tree_binary_expression)
139
140 // Note: The profiler does not catch the braindead
141 // short-circuit evaluation code above, but that should be
142 // ok. The evaluation of operands and the operator itself
143 // is entangled and it's not clear where to start/stop
144 // timing the operator to make it reasonable.
145
146 retval = ::do_binary_op (etype, a, b);
147
148 if (error_state)
149 retval = octave_value ();
150
151 END_PROFILER_BLOCK
152 }
153 }
154 }
155
156 return retval;
157 }
158
159 std::string
160 tree_binary_expression::oper (void) const
161 {
162 return octave_value::binary_op_as_string (etype);
163 }
164
165 tree_expression *
166 tree_binary_expression::dup (symbol_table::scope_id scope,
167 symbol_table::context_id context) const
168 {
169 tree_binary_expression *new_be
170 = new tree_binary_expression (op_lhs ? op_lhs->dup (scope, context) : 0,
171 op_rhs ? op_rhs->dup (scope, context) : 0,
172 line (), column (), etype);
173
174 new_be->copy_base (*this);
175
176 return new_be;
177 }
178
179 void
180 tree_binary_expression::accept (tree_walker& tw)
181 {
182 tw.visit_binary_expression (*this);
183 }
184
185 // Boolean expressions.
186
187 octave_value_list
188 tree_boolean_expression::rvalue (int nargout)
189 {
190 octave_value_list retval;
191
192 if (nargout > 1)
193 error ("binary operator '%s': invalid number of output arguments",
194 oper () . c_str ());
195 else
196 retval = rvalue1 (nargout);
197
198 return retval;
199 }
200
201 octave_value
202 tree_boolean_expression::rvalue1 (int)
203 {
204 octave_value retval;
205
206 if (error_state)
207 return retval;
208
209 bool result = false;
210
211 // This evaluation is not caught by the profiler, since we can't find
212 // a reasonable place where to time. Note that we don't want to
213 // include evaluation of LHS or RHS into the timing, but this is
214 // entangled together with short-circuit evaluation here.
215
216 if (op_lhs)
217 {
218 octave_value a = op_lhs->rvalue1 ();
219
220 if (! error_state)
221 {
222 bool a_true = a.is_true ();
223
224 if (! error_state)
225 {
226 if (a_true) 85 if (a_true)
227 { 86 {
228 if (etype == bool_or) 87 if (etype == octave_value::op_el_or)
229 { 88 {
89 matlab_style_short_circuit_warning ("|");
230 result = true; 90 result = true;
231 goto done; 91 goto done;
232 } 92 }
233 } 93 }
234 else 94 else
235 { 95 {
236 if (etype == bool_and) 96 if (etype == octave_value::op_el_and)
237 goto done; 97 {
98 matlab_style_short_circuit_warning ("&");
99 goto done;
100 }
238 } 101 }
239 102
240 if (op_rhs) 103 if (op_rhs)
241 { 104 {
242 octave_value b = op_rhs->rvalue1 (); 105 octave_value b = op_rhs->rvalue1 ();
243 106
244 if (! error_state) 107 result = b.is_true ();
245 result = b.is_true ();
246 } 108 }
247 109
248 done: 110 done:
249 111
250 if (! error_state) 112 return octave_value (result);
251 retval = octave_value (result);
252 } 113 }
253 } 114 }
115 }
116
117 if (op_lhs)
118 {
119 octave_value a = op_lhs->rvalue1 ();
120
121 if (a.is_defined () && op_rhs)
122 {
123 octave_value b = op_rhs->rvalue1 ();
124
125 if (b.is_defined ())
126 {
127 BEGIN_PROFILER_BLOCK (tree_binary_expression)
128
129 // Note: The profiler does not catch the braindead
130 // short-circuit evaluation code above, but that should be
131 // ok. The evaluation of operands and the operator itself
132 // is entangled and it's not clear where to start/stop
133 // timing the operator to make it reasonable.
134
135 retval = ::do_binary_op (etype, a, b);
136
137 END_PROFILER_BLOCK
138 }
139 }
140 }
141
142 return retval;
143 }
144
145 std::string
146 tree_binary_expression::oper (void) const
147 {
148 return octave_value::binary_op_as_string (etype);
149 }
150
151 tree_expression *
152 tree_binary_expression::dup (symbol_table::scope_id scope,
153 symbol_table::context_id context) const
154 {
155 tree_binary_expression *new_be
156 = new tree_binary_expression (op_lhs ? op_lhs->dup (scope, context) : 0,
157 op_rhs ? op_rhs->dup (scope, context) : 0,
158 line (), column (), etype);
159
160 new_be->copy_base (*this);
161
162 return new_be;
163 }
164
165 void
166 tree_binary_expression::accept (tree_walker& tw)
167 {
168 tw.visit_binary_expression (*this);
169 }
170
171 // Boolean expressions.
172
173 octave_value_list
174 tree_boolean_expression::rvalue (int nargout)
175 {
176 octave_value_list retval;
177
178 if (nargout > 1)
179 error ("binary operator '%s': invalid number of output arguments",
180 oper () . c_str ());
181 else
182 retval = rvalue1 (nargout);
183
184 return retval;
185 }
186
187 octave_value
188 tree_boolean_expression::rvalue1 (int)
189 {
190 octave_value retval;
191
192 bool result = false;
193
194 // This evaluation is not caught by the profiler, since we can't find
195 // a reasonable place where to time. Note that we don't want to
196 // include evaluation of LHS or RHS into the timing, but this is
197 // entangled together with short-circuit evaluation here.
198
199 if (op_lhs)
200 {
201 octave_value a = op_lhs->rvalue1 ();
202
203 bool a_true = a.is_true ();
204
205 if (a_true)
206 {
207 if (etype == bool_or)
208 {
209 result = true;
210 goto done;
211 }
212 }
213 else
214 {
215 if (etype == bool_and)
216 goto done;
217 }
218
219 if (op_rhs)
220 {
221 octave_value b = op_rhs->rvalue1 ();
222
223 result = b.is_true ();
224 }
225
226 done:
227
228 retval = octave_value (result);
254 } 229 }
255 230
256 return retval; 231 return retval;
257 } 232 }
258 233