comparison src/pt-exp-base.cc @ 1491:893b416bb919

[project @ 1995-09-29 04:03:01 by jwe]
author jwe
date Fri, 29 Sep 1995 04:08:17 +0000
parents 89c587478067
children af2d53865577
comparison
equal deleted inserted replaced
1490:4d6c168ff235 1491:893b416bb919
179 return 0; 179 return 0;
180 } 180 }
181 181
182 // Expressions. 182 // Expressions.
183 183
184 int
185 tree_expression::is_logically_true (const char *warn_for)
186 {
187 int expr_value = 0;
188
189 tree_constant t1 = eval (0);
190
191 if (error_state)
192 {
193 // XXX FIXME XXX
194 //
195 // eval_error ();
196 //
197 return expr_value;
198 }
199
200 if (t1.is_undefined ())
201 {
202 ::error ("%s: undefined value used in conditional expression\
203 near line %d, column %d", warn_for, line (), column ());
204 return expr_value;
205 }
206
207 if (t1.rows () == 0 || t1.columns () == 0)
208 {
209 int flag = user_pref.propagate_empty_matrices;
210 if (flag < 0)
211 warning ("%s: empty matrix used in conditional expression\
212 near line %d, column %d", warn_for, line (), column ());
213 else if (flag == 0)
214 {
215 ::error ("%s: empty matrix used in conditional expression\
216 near line %d, column %d", warn_for, line (), column ());
217 return expr_value;
218 }
219 t1 = 0.0;
220 }
221 else if (! t1.is_scalar_type ())
222 {
223 tree_constant t2 = t1.all ();
224 if (! error_state)
225 t1 = t2.all ();
226
227 if (error_state)
228 {
229 ::error ("%s: invalid type in conditional expression near\
230 line %d, column %d", warn_for, line (), column ());
231 return expr_value;
232 }
233 }
234
235 if (t1.is_real_scalar ())
236 expr_value = (int) t1.double_value ();
237 else if (t1.is_complex_scalar ())
238 expr_value = t1.complex_value () != 0.0;
239 else
240 panic_impossible ();
241
242 return expr_value;
243 }
244
184 tree_constant 245 tree_constant
185 tree_expression::eval (int /* print */) 246 tree_expression::eval (int /* print */)
186 { 247 {
187 panic ("invalid evaluation of generic expression"); 248 panic ("invalid evaluation of generic expression");
188 return tree_constant (); 249 return tree_constant ();