2980
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1996, 1997, 1998, 2000, 2001, 2002, 2004, 2005, 2006, |
|
4 2007 John W. Eaton |
2980
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
7016
|
10 Free Software Foundation; either version 3 of the License, or (at your |
|
11 option) any later version. |
2980
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
7016
|
19 along with Octave; see the file COPYING. If not, see |
|
20 <http://www.gnu.org/licenses/>. |
2980
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
|
28 #include "error.h" |
|
29 #include "oct-obj.h" |
|
30 #include "oct-lvalue.h" |
|
31 #include "ov.h" |
3770
|
32 #include "pt-bp.h" |
2980
|
33 #include "pt-unop.h" |
|
34 #include "pt-walk.h" |
|
35 |
3203
|
36 // Unary expressions. |
|
37 |
3536
|
38 std::string |
3203
|
39 tree_unary_expression::oper (void) const |
|
40 { |
|
41 return octave_value::unary_op_as_string (etype); |
|
42 } |
|
43 |
2980
|
44 // Prefix expressions. |
|
45 |
|
46 octave_value_list |
|
47 tree_prefix_expression::rvalue (int nargout) |
|
48 { |
|
49 octave_value_list retval; |
|
50 |
|
51 if (nargout > 1) |
|
52 error ("prefix operator `%s': invalid number of output arguments", |
|
53 oper () . c_str ()); |
|
54 else |
|
55 retval = rvalue (); |
|
56 |
|
57 return retval; |
|
58 } |
|
59 |
|
60 octave_value |
|
61 tree_prefix_expression::rvalue (void) |
|
62 { |
|
63 octave_value retval; |
|
64 |
3770
|
65 MAYBE_DO_BREAKPOINT; |
|
66 |
2980
|
67 if (error_state) |
|
68 return retval; |
|
69 |
|
70 if (op) |
|
71 { |
3539
|
72 if (etype == octave_value::op_incr || etype == octave_value::op_decr) |
3203
|
73 { |
3962
|
74 op->rvalue (); |
|
75 |
|
76 if (! error_state) |
|
77 { |
|
78 octave_lvalue ref = op->lvalue (); |
3203
|
79 |
3962
|
80 if (! error_state && ref.is_defined ()) |
|
81 { |
|
82 ref.do_unary_op (etype); |
3203
|
83 |
3962
|
84 retval = ref.value (); |
|
85 } |
|
86 else |
|
87 eval_error (); |
3203
|
88 } |
|
89 else |
|
90 eval_error (); |
|
91 } |
|
92 else |
2980
|
93 { |
|
94 octave_value val = op->rvalue (); |
|
95 |
3962
|
96 if (! error_state && val.is_defined ()) |
2980
|
97 { |
3203
|
98 retval = ::do_unary_op (etype, val); |
2980
|
99 |
3203
|
100 if (error_state) |
2980
|
101 { |
3203
|
102 retval = octave_value (); |
|
103 eval_error (); |
2980
|
104 } |
|
105 } |
3203
|
106 else |
|
107 eval_error (); |
2980
|
108 } |
|
109 } |
3965
|
110 else |
|
111 eval_error (); |
2980
|
112 |
|
113 return retval; |
|
114 } |
|
115 |
|
116 void |
|
117 tree_prefix_expression::eval_error (void) |
|
118 { |
3965
|
119 ::error ("evaluating prefix operator `%s' near line %d, column %d", |
|
120 oper () . c_str (), line (), column ()); |
2980
|
121 } |
|
122 |
5861
|
123 tree_expression * |
7336
|
124 tree_prefix_expression::dup (symbol_table::scope_id scope) |
5861
|
125 { |
|
126 tree_prefix_expression *new_pe |
7336
|
127 = new tree_prefix_expression (op ? op->dup (scope) : 0, |
5861
|
128 line (), column (), etype); |
|
129 |
|
130 new_pe->copy_base (*this); |
|
131 |
|
132 return new_pe; |
|
133 } |
|
134 |
2980
|
135 void |
|
136 tree_prefix_expression::accept (tree_walker& tw) |
|
137 { |
|
138 tw.visit_prefix_expression (*this); |
|
139 } |
|
140 |
|
141 // Postfix expressions. |
|
142 |
|
143 octave_value_list |
|
144 tree_postfix_expression::rvalue (int nargout) |
|
145 { |
|
146 octave_value_list retval; |
|
147 |
|
148 if (nargout > 1) |
|
149 error ("postfix operator `%s': invalid number of output arguments", |
|
150 oper () . c_str ()); |
|
151 else |
|
152 retval = rvalue (); |
|
153 |
|
154 return retval; |
|
155 } |
|
156 |
|
157 octave_value |
|
158 tree_postfix_expression::rvalue (void) |
|
159 { |
|
160 octave_value retval; |
|
161 |
3770
|
162 MAYBE_DO_BREAKPOINT; |
|
163 |
2980
|
164 if (error_state) |
|
165 return retval; |
|
166 |
|
167 if (op) |
|
168 { |
3539
|
169 if (etype == octave_value::op_incr || etype == octave_value::op_decr) |
3203
|
170 { |
3962
|
171 op->rvalue (); |
|
172 |
|
173 if (! error_state) |
|
174 { |
|
175 octave_lvalue ref = op->lvalue (); |
3203
|
176 |
3962
|
177 if (! error_state && ref.is_defined ()) |
|
178 { |
|
179 retval = ref.value (); |
3203
|
180 |
3962
|
181 ref.do_unary_op (etype); |
|
182 } |
|
183 else |
|
184 eval_error (); |
3203
|
185 } |
|
186 else |
|
187 eval_error (); |
|
188 } |
|
189 else |
2980
|
190 { |
|
191 octave_value val = op->rvalue (); |
|
192 |
3962
|
193 if (! error_state && val.is_defined ()) |
2980
|
194 { |
3203
|
195 retval = ::do_unary_op (etype, val); |
2980
|
196 |
3203
|
197 if (error_state) |
2980
|
198 { |
3203
|
199 retval = octave_value (); |
|
200 eval_error (); |
2980
|
201 } |
|
202 } |
3203
|
203 else |
|
204 eval_error (); |
2980
|
205 } |
|
206 } |
3203
|
207 else |
|
208 eval_error (); |
2980
|
209 |
|
210 return retval; |
|
211 } |
|
212 |
|
213 void |
|
214 tree_postfix_expression::eval_error (void) |
|
215 { |
3965
|
216 ::error ("evaluating postfix operator `%s' near line %d, column %d", |
|
217 oper () . c_str (), line (), column ()); |
2980
|
218 } |
|
219 |
5861
|
220 tree_expression * |
7336
|
221 tree_postfix_expression::dup (symbol_table::scope_id scope) |
5861
|
222 { |
|
223 tree_postfix_expression *new_pe |
7336
|
224 = new tree_postfix_expression (op ? op->dup (scope) : 0, |
5861
|
225 line (), column (), etype); |
|
226 |
|
227 new_pe->copy_base (*this); |
|
228 |
|
229 return new_pe; |
|
230 } |
|
231 |
2980
|
232 void |
|
233 tree_postfix_expression::accept (tree_walker& tw) |
|
234 { |
|
235 tw.visit_postfix_expression (*this); |
|
236 } |
|
237 |
|
238 /* |
|
239 ;;; Local Variables: *** |
|
240 ;;; mode: C++ *** |
|
241 ;;; End: *** |
|
242 */ |