2980
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 John W. Eaton |
|
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 |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if defined (__GNUG__) |
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
|
31 #include "error.h" |
|
32 #include "oct-obj.h" |
|
33 #include "oct-lvalue.h" |
|
34 #include "ov.h" |
3770
|
35 #include "pt-bp.h" |
2980
|
36 #include "pt-unop.h" |
|
37 #include "pt-walk.h" |
|
38 |
3203
|
39 // Unary expressions. |
|
40 |
3536
|
41 std::string |
3203
|
42 tree_unary_expression::oper (void) const |
|
43 { |
|
44 return octave_value::unary_op_as_string (etype); |
|
45 } |
|
46 |
2980
|
47 // Prefix expressions. |
|
48 |
|
49 octave_value_list |
|
50 tree_prefix_expression::rvalue (int nargout) |
|
51 { |
|
52 octave_value_list retval; |
|
53 |
|
54 if (nargout > 1) |
|
55 error ("prefix operator `%s': invalid number of output arguments", |
|
56 oper () . c_str ()); |
|
57 else |
|
58 retval = rvalue (); |
|
59 |
|
60 return retval; |
|
61 } |
|
62 |
|
63 octave_value |
|
64 tree_prefix_expression::rvalue (void) |
|
65 { |
|
66 octave_value retval; |
|
67 |
3770
|
68 MAYBE_DO_BREAKPOINT; |
|
69 |
2980
|
70 if (error_state) |
|
71 return retval; |
|
72 |
|
73 if (op) |
|
74 { |
3539
|
75 if (etype == octave_value::op_incr || etype == octave_value::op_decr) |
3203
|
76 { |
3962
|
77 op->rvalue (); |
|
78 |
|
79 if (! error_state) |
|
80 { |
|
81 octave_lvalue ref = op->lvalue (); |
3203
|
82 |
3962
|
83 if (! error_state && ref.is_defined ()) |
|
84 { |
|
85 ref.do_unary_op (etype); |
3203
|
86 |
3962
|
87 retval = ref.value (); |
|
88 } |
|
89 else |
|
90 eval_error (); |
3203
|
91 } |
|
92 else |
|
93 eval_error (); |
|
94 } |
|
95 else |
2980
|
96 { |
|
97 octave_value val = op->rvalue (); |
|
98 |
3962
|
99 if (! error_state && val.is_defined ()) |
2980
|
100 { |
3203
|
101 retval = ::do_unary_op (etype, val); |
2980
|
102 |
3203
|
103 if (error_state) |
2980
|
104 { |
3203
|
105 retval = octave_value (); |
|
106 eval_error (); |
2980
|
107 } |
|
108 } |
3203
|
109 else |
|
110 eval_error (); |
2980
|
111 } |
|
112 } |
|
113 |
|
114 return retval; |
|
115 } |
|
116 |
|
117 void |
|
118 tree_prefix_expression::eval_error (void) |
|
119 { |
|
120 if (error_state > 0) |
|
121 ::error ("evaluating prefix operator `%s' near line %d, column %d", |
|
122 oper () . c_str (), line (), column ()); |
|
123 } |
|
124 |
|
125 void |
|
126 tree_prefix_expression::accept (tree_walker& tw) |
|
127 { |
|
128 tw.visit_prefix_expression (*this); |
|
129 } |
|
130 |
|
131 // Postfix expressions. |
|
132 |
|
133 octave_value_list |
|
134 tree_postfix_expression::rvalue (int nargout) |
|
135 { |
|
136 octave_value_list retval; |
|
137 |
|
138 if (nargout > 1) |
|
139 error ("postfix operator `%s': invalid number of output arguments", |
|
140 oper () . c_str ()); |
|
141 else |
|
142 retval = rvalue (); |
|
143 |
|
144 return retval; |
|
145 } |
|
146 |
|
147 octave_value |
|
148 tree_postfix_expression::rvalue (void) |
|
149 { |
|
150 octave_value retval; |
|
151 |
3770
|
152 MAYBE_DO_BREAKPOINT; |
|
153 |
2980
|
154 if (error_state) |
|
155 return retval; |
|
156 |
|
157 if (op) |
|
158 { |
3539
|
159 if (etype == octave_value::op_incr || etype == octave_value::op_decr) |
3203
|
160 { |
3962
|
161 op->rvalue (); |
|
162 |
|
163 if (! error_state) |
|
164 { |
|
165 octave_lvalue ref = op->lvalue (); |
3203
|
166 |
3962
|
167 if (! error_state && ref.is_defined ()) |
|
168 { |
|
169 retval = ref.value (); |
3203
|
170 |
3962
|
171 ref.do_unary_op (etype); |
|
172 } |
|
173 else |
|
174 eval_error (); |
3203
|
175 } |
|
176 else |
|
177 eval_error (); |
|
178 } |
|
179 else |
2980
|
180 { |
|
181 octave_value val = op->rvalue (); |
|
182 |
3962
|
183 if (! error_state && val.is_defined ()) |
2980
|
184 { |
3203
|
185 retval = ::do_unary_op (etype, val); |
2980
|
186 |
3203
|
187 if (error_state) |
2980
|
188 { |
3203
|
189 retval = octave_value (); |
|
190 eval_error (); |
2980
|
191 } |
|
192 } |
3203
|
193 else |
|
194 eval_error (); |
2980
|
195 } |
|
196 } |
3203
|
197 else |
|
198 eval_error (); |
2980
|
199 |
|
200 return retval; |
|
201 } |
|
202 |
|
203 void |
|
204 tree_postfix_expression::eval_error (void) |
|
205 { |
|
206 if (error_state > 0) |
|
207 ::error ("evaluating postfix operator `%s' near line %d, column %d", |
|
208 oper () . c_str (), line (), column ()); |
|
209 } |
|
210 |
|
211 void |
|
212 tree_postfix_expression::accept (tree_walker& tw) |
|
213 { |
|
214 tw.visit_postfix_expression (*this); |
|
215 } |
|
216 |
|
217 /* |
|
218 ;;; Local Variables: *** |
|
219 ;;; mode: C++ *** |
|
220 ;;; End: *** |
|
221 */ |