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" |
|
35 #include "pt-unop.h" |
|
36 #include "pt-walk.h" |
|
37 |
3203
|
38 // Unary expressions. |
|
39 |
3534
|
40 std:string |
3203
|
41 tree_unary_expression::oper (void) const |
|
42 { |
|
43 return octave_value::unary_op_as_string (etype); |
|
44 } |
|
45 |
2980
|
46 // Prefix expressions. |
|
47 |
|
48 octave_value_list |
|
49 tree_prefix_expression::rvalue (int nargout) |
|
50 { |
|
51 octave_value_list retval; |
|
52 |
|
53 if (nargout > 1) |
|
54 error ("prefix operator `%s': invalid number of output arguments", |
|
55 oper () . c_str ()); |
|
56 else |
|
57 retval = rvalue (); |
|
58 |
|
59 return retval; |
|
60 } |
|
61 |
|
62 octave_value |
|
63 tree_prefix_expression::rvalue (void) |
|
64 { |
|
65 octave_value retval; |
|
66 |
|
67 if (error_state) |
|
68 return retval; |
|
69 |
|
70 if (op) |
|
71 { |
3203
|
72 if (etype == octave_value::incr || etype == octave_value::decr) |
|
73 { |
|
74 octave_lvalue ref = op->lvalue (); |
|
75 |
|
76 if (error_state) |
|
77 eval_error (); |
|
78 else if (ref.is_defined ()) |
|
79 { |
|
80 ref.do_unary_op (etype); |
|
81 |
|
82 retval = ref.value (); |
|
83 } |
|
84 else |
|
85 eval_error (); |
|
86 } |
|
87 else |
2980
|
88 { |
|
89 octave_value val = op->rvalue (); |
|
90 |
3203
|
91 if (error_state) |
|
92 eval_error (); |
|
93 else if (val.is_defined ()) |
2980
|
94 { |
3203
|
95 retval = ::do_unary_op (etype, val); |
2980
|
96 |
3203
|
97 if (error_state) |
2980
|
98 { |
3203
|
99 retval = octave_value (); |
|
100 eval_error (); |
2980
|
101 } |
|
102 } |
3203
|
103 else |
|
104 eval_error (); |
2980
|
105 } |
|
106 } |
|
107 |
|
108 return retval; |
|
109 } |
|
110 |
|
111 void |
|
112 tree_prefix_expression::eval_error (void) |
|
113 { |
|
114 if (error_state > 0) |
|
115 ::error ("evaluating prefix operator `%s' near line %d, column %d", |
|
116 oper () . c_str (), line (), column ()); |
|
117 } |
|
118 |
|
119 void |
|
120 tree_prefix_expression::accept (tree_walker& tw) |
|
121 { |
|
122 tw.visit_prefix_expression (*this); |
|
123 } |
|
124 |
|
125 // Postfix expressions. |
|
126 |
|
127 octave_value_list |
|
128 tree_postfix_expression::rvalue (int nargout) |
|
129 { |
|
130 octave_value_list retval; |
|
131 |
|
132 if (nargout > 1) |
|
133 error ("postfix operator `%s': invalid number of output arguments", |
|
134 oper () . c_str ()); |
|
135 else |
|
136 retval = rvalue (); |
|
137 |
|
138 return retval; |
|
139 } |
|
140 |
|
141 octave_value |
|
142 tree_postfix_expression::rvalue (void) |
|
143 { |
|
144 octave_value retval; |
|
145 |
|
146 if (error_state) |
|
147 return retval; |
|
148 |
|
149 if (op) |
|
150 { |
3203
|
151 if (etype == octave_value::incr || etype == octave_value::decr) |
|
152 { |
|
153 octave_lvalue ref = op->lvalue (); |
|
154 |
|
155 if (error_state) |
|
156 eval_error (); |
|
157 else if (ref.is_defined ()) |
|
158 { |
|
159 retval = ref.value (); |
|
160 |
|
161 ref.do_unary_op (etype); |
|
162 } |
|
163 else |
|
164 eval_error (); |
|
165 } |
|
166 else |
2980
|
167 { |
|
168 octave_value val = op->rvalue (); |
|
169 |
3203
|
170 if (error_state) |
|
171 eval_error (); |
|
172 else if (val.is_defined ()) |
2980
|
173 { |
3203
|
174 retval = ::do_unary_op (etype, val); |
2980
|
175 |
3203
|
176 if (error_state) |
2980
|
177 { |
3203
|
178 retval = octave_value (); |
|
179 eval_error (); |
2980
|
180 } |
|
181 } |
3203
|
182 else |
|
183 eval_error (); |
2980
|
184 } |
|
185 } |
3203
|
186 else |
|
187 eval_error (); |
2980
|
188 |
|
189 return retval; |
|
190 } |
|
191 |
|
192 void |
|
193 tree_postfix_expression::eval_error (void) |
|
194 { |
|
195 if (error_state > 0) |
|
196 ::error ("evaluating postfix operator `%s' near line %d, column %d", |
|
197 oper () . c_str (), line (), column ()); |
|
198 } |
|
199 |
|
200 void |
|
201 tree_postfix_expression::accept (tree_walker& tw) |
|
202 { |
|
203 tw.visit_postfix_expression (*this); |
|
204 } |
|
205 |
|
206 /* |
|
207 ;;; Local Variables: *** |
|
208 ;;; mode: C++ *** |
|
209 ;;; End: *** |
|
210 */ |