Mercurial > octave-nkf
annotate src/pt-unop.cc @ 7767:71f068b22fcc
scope and context fixes for function handles
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 07 May 2008 13:45:30 -0400 |
parents | 745a8299c2b5 |
children | 3100283874d7 |
rev | line source |
---|---|
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 * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
124 tree_prefix_expression::dup (symbol_table::scope_id scope, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
125 symbol_table::context_id context) |
5861 | 126 { |
127 tree_prefix_expression *new_pe | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
128 = new tree_prefix_expression (op ? op->dup (scope, context) : 0, |
5861 | 129 line (), column (), etype); |
130 | |
131 new_pe->copy_base (*this); | |
132 | |
133 return new_pe; | |
134 } | |
135 | |
2980 | 136 void |
137 tree_prefix_expression::accept (tree_walker& tw) | |
138 { | |
139 tw.visit_prefix_expression (*this); | |
140 } | |
141 | |
142 // Postfix expressions. | |
143 | |
144 octave_value_list | |
145 tree_postfix_expression::rvalue (int nargout) | |
146 { | |
147 octave_value_list retval; | |
148 | |
149 if (nargout > 1) | |
150 error ("postfix operator `%s': invalid number of output arguments", | |
151 oper () . c_str ()); | |
152 else | |
153 retval = rvalue (); | |
154 | |
155 return retval; | |
156 } | |
157 | |
158 octave_value | |
159 tree_postfix_expression::rvalue (void) | |
160 { | |
161 octave_value retval; | |
162 | |
3770 | 163 MAYBE_DO_BREAKPOINT; |
164 | |
2980 | 165 if (error_state) |
166 return retval; | |
167 | |
168 if (op) | |
169 { | |
3539 | 170 if (etype == octave_value::op_incr || etype == octave_value::op_decr) |
3203 | 171 { |
3962 | 172 op->rvalue (); |
173 | |
174 if (! error_state) | |
175 { | |
176 octave_lvalue ref = op->lvalue (); | |
3203 | 177 |
3962 | 178 if (! error_state && ref.is_defined ()) |
179 { | |
180 retval = ref.value (); | |
3203 | 181 |
3962 | 182 ref.do_unary_op (etype); |
183 } | |
184 else | |
185 eval_error (); | |
3203 | 186 } |
187 else | |
188 eval_error (); | |
189 } | |
190 else | |
2980 | 191 { |
192 octave_value val = op->rvalue (); | |
193 | |
3962 | 194 if (! error_state && val.is_defined ()) |
2980 | 195 { |
3203 | 196 retval = ::do_unary_op (etype, val); |
2980 | 197 |
3203 | 198 if (error_state) |
2980 | 199 { |
3203 | 200 retval = octave_value (); |
201 eval_error (); | |
2980 | 202 } |
203 } | |
3203 | 204 else |
205 eval_error (); | |
2980 | 206 } |
207 } | |
3203 | 208 else |
209 eval_error (); | |
2980 | 210 |
211 return retval; | |
212 } | |
213 | |
214 void | |
215 tree_postfix_expression::eval_error (void) | |
216 { | |
3965 | 217 ::error ("evaluating postfix operator `%s' near line %d, column %d", |
218 oper () . c_str (), line (), column ()); | |
2980 | 219 } |
220 | |
5861 | 221 tree_expression * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
222 tree_postfix_expression::dup (symbol_table::scope_id scope, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
223 symbol_table::context_id context) |
5861 | 224 { |
225 tree_postfix_expression *new_pe | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
226 = new tree_postfix_expression (op ? op->dup (scope, context) : 0, |
5861 | 227 line (), column (), etype); |
228 | |
229 new_pe->copy_base (*this); | |
230 | |
231 return new_pe; | |
232 } | |
233 | |
2980 | 234 void |
235 tree_postfix_expression::accept (tree_walker& tw) | |
236 { | |
237 tw.visit_postfix_expression (*this); | |
238 } | |
239 | |
240 /* | |
241 ;;; Local Variables: *** | |
242 ;;; mode: C++ *** | |
243 ;;; End: *** | |
244 */ |