494
|
1 /* |
|
2 |
1827
|
3 Copyright (C) 1996 John W. Eaton |
494
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
494
|
20 |
|
21 */ |
|
22 |
1297
|
23 #if defined (__GNUG__) |
|
24 #pragma implementation |
|
25 #endif |
|
26 |
494
|
27 #ifdef HAVE_CONFIG_H |
1192
|
28 #include <config.h> |
494
|
29 #endif |
|
30 |
1350
|
31 #include <iostream.h> |
|
32 #include <strstream.h> |
|
33 |
494
|
34 #include "error.h" |
|
35 #include "pager.h" |
1742
|
36 #include "pt-const.h" |
|
37 #include "pt-exp-base.h" |
1352
|
38 #include "user-prefs.h" |
494
|
39 |
581
|
40 // Expressions. |
|
41 |
1827
|
42 bool |
1491
|
43 tree_expression::is_logically_true (const char *warn_for) |
|
44 { |
1827
|
45 bool expr_value = false; |
1491
|
46 |
2086
|
47 octave_value t1 = eval (false); |
1491
|
48 |
1492
|
49 if (! error_state) |
1491
|
50 { |
1492
|
51 if (t1.is_defined ()) |
1491
|
52 { |
1492
|
53 if (t1.rows () == 0 || t1.columns () == 0) |
|
54 { |
|
55 t1 = 0.0; |
|
56 int flag = user_pref.propagate_empty_matrices; |
|
57 if (flag < 0) |
1510
|
58 warning ("%s: empty matrix used in conditional expression", |
|
59 warn_for); |
1492
|
60 else if (flag == 0) |
|
61 { |
1510
|
62 ::error ("%s: empty matrix used in conditional expression", |
|
63 warn_for); |
1492
|
64 return expr_value; |
|
65 } |
|
66 } |
|
67 else if (! t1.is_scalar_type ()) |
|
68 { |
2086
|
69 octave_value t2 = t1.all (); |
1492
|
70 if (! error_state) |
|
71 t1 = t2.all (); |
|
72 } |
|
73 |
|
74 if (! error_state) |
|
75 { |
|
76 if (t1.is_real_scalar ()) |
1827
|
77 expr_value = t1.double_value () != 0.0; |
1492
|
78 else if (t1.is_complex_scalar ()) |
|
79 expr_value = t1.complex_value () != 0.0; |
|
80 else |
|
81 panic_impossible (); |
|
82 } |
|
83 else |
1510
|
84 ::error ("%s: invalid type in conditional expression", warn_for); |
1491
|
85 } |
1492
|
86 else |
1510
|
87 ::error ("%s: undefined value used in conditional expression", |
|
88 warn_for); |
1491
|
89 } |
|
90 else |
1510
|
91 ::error ("%s: error evaluating conditional expression", warn_for); |
1491
|
92 |
|
93 return expr_value; |
|
94 } |
|
95 |
1742
|
96 void |
|
97 tree_expression::mark_for_possible_ans_assign (void) |
|
98 { |
|
99 panic_impossible (); |
|
100 } |
|
101 |
2086
|
102 octave_value |
1827
|
103 tree_expression::eval (bool /* print */) |
581
|
104 { |
|
105 panic ("invalid evaluation of generic expression"); |
2086
|
106 return octave_value (); |
581
|
107 } |
|
108 |
494
|
109 /* |
|
110 ;;; Local Variables: *** |
|
111 ;;; mode: C++ *** |
|
112 ;;; End: *** |
|
113 */ |