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 { |
|
77 octave_lvalue ref = op->lvalue (); |
|
78 |
|
79 if (error_state) |
|
80 eval_error (); |
|
81 else if (ref.is_defined ()) |
|
82 { |
|
83 ref.do_unary_op (etype); |
|
84 |
|
85 retval = ref.value (); |
|
86 } |
|
87 else |
|
88 eval_error (); |
|
89 } |
|
90 else |
2980
|
91 { |
|
92 octave_value val = op->rvalue (); |
|
93 |
3203
|
94 if (error_state) |
|
95 eval_error (); |
|
96 else if (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 } |
|
110 |
|
111 return retval; |
|
112 } |
|
113 |
|
114 void |
|
115 tree_prefix_expression::eval_error (void) |
|
116 { |
|
117 if (error_state > 0) |
|
118 ::error ("evaluating prefix operator `%s' near line %d, column %d", |
|
119 oper () . c_str (), line (), column ()); |
|
120 } |
|
121 |
|
122 void |
|
123 tree_prefix_expression::accept (tree_walker& tw) |
|
124 { |
|
125 tw.visit_prefix_expression (*this); |
|
126 } |
|
127 |
|
128 // Postfix expressions. |
|
129 |
|
130 octave_value_list |
|
131 tree_postfix_expression::rvalue (int nargout) |
|
132 { |
|
133 octave_value_list retval; |
|
134 |
|
135 if (nargout > 1) |
|
136 error ("postfix operator `%s': invalid number of output arguments", |
|
137 oper () . c_str ()); |
|
138 else |
|
139 retval = rvalue (); |
|
140 |
|
141 return retval; |
|
142 } |
|
143 |
|
144 octave_value |
|
145 tree_postfix_expression::rvalue (void) |
|
146 { |
|
147 octave_value retval; |
|
148 |
3770
|
149 MAYBE_DO_BREAKPOINT; |
|
150 |
2980
|
151 if (error_state) |
|
152 return retval; |
|
153 |
|
154 if (op) |
|
155 { |
3539
|
156 if (etype == octave_value::op_incr || etype == octave_value::op_decr) |
3203
|
157 { |
|
158 octave_lvalue ref = op->lvalue (); |
|
159 |
|
160 if (error_state) |
|
161 eval_error (); |
|
162 else if (ref.is_defined ()) |
|
163 { |
|
164 retval = ref.value (); |
|
165 |
|
166 ref.do_unary_op (etype); |
|
167 } |
|
168 else |
|
169 eval_error (); |
|
170 } |
|
171 else |
2980
|
172 { |
|
173 octave_value val = op->rvalue (); |
|
174 |
3203
|
175 if (error_state) |
|
176 eval_error (); |
|
177 else if (val.is_defined ()) |
2980
|
178 { |
3203
|
179 retval = ::do_unary_op (etype, val); |
2980
|
180 |
3203
|
181 if (error_state) |
2980
|
182 { |
3203
|
183 retval = octave_value (); |
|
184 eval_error (); |
2980
|
185 } |
|
186 } |
3203
|
187 else |
|
188 eval_error (); |
2980
|
189 } |
|
190 } |
3203
|
191 else |
|
192 eval_error (); |
2980
|
193 |
|
194 return retval; |
|
195 } |
|
196 |
|
197 void |
|
198 tree_postfix_expression::eval_error (void) |
|
199 { |
|
200 if (error_state > 0) |
|
201 ::error ("evaluating postfix operator `%s' near line %d, column %d", |
|
202 oper () . c_str (), line (), column ()); |
|
203 } |
|
204 |
|
205 void |
|
206 tree_postfix_expression::accept (tree_walker& tw) |
|
207 { |
|
208 tw.visit_postfix_expression (*this); |
|
209 } |
|
210 |
|
211 /* |
|
212 ;;; Local Variables: *** |
|
213 ;;; mode: C++ *** |
|
214 ;;; End: *** |
|
215 */ |