comparison src/pt-assign.cc @ 3208:e8a7163701be

[project @ 1998-11-03 05:12:47 by jwe]
author jwe
date Tue, 03 Nov 1998 05:12:48 +0000
parents fc751d2a99fd
children bc3fdfe311a3
comparison
equal deleted inserted replaced
3207:dddfaa93a99c 3208:e8a7163701be
74 // it were broken up into a couple of separate functions. 74 // it were broken up into a couple of separate functions.
75 75
76 octave_value 76 octave_value
77 tree_simple_assignment::rvalue (void) 77 tree_simple_assignment::rvalue (void)
78 { 78 {
79 octave_value rhs_val; 79 octave_value retval;
80 80
81 if (error_state) 81 if (error_state)
82 return rhs_val; 82 return retval;
83 83
84 if (rhs) 84 if (rhs)
85 { 85 {
86 octave_value_list tmp = rhs->rvalue (); 86 octave_value_list tmp = rhs->rvalue ();
87 87
88 if (! (error_state || tmp.empty ())) 88 if (! (error_state || tmp.empty ()))
89 { 89 {
90 rhs_val = tmp(0); 90 octave_value rhs_val = tmp(0);
91 91
92 if (rhs_val.is_undefined ()) 92 if (rhs_val.is_undefined ())
93 { 93 {
94 error ("value on right hand side of assignment is undefined"); 94 error ("value on right hand side of assignment is undefined");
95 eval_error (); 95 eval_error ();
102 eval_error (); 102 eval_error ();
103 else 103 else
104 { 104 {
105 ult.assign (etype, rhs_val); 105 ult.assign (etype, rhs_val);
106 106
107 // We clear any index here so that we can get the 107 retval = ult.value ();
108 // new value of the referenced object below, instead
109 // of the indexed value (which should be the same as
110 // the right hand side value).
111
112 ult.clear_index ();
113 108
114 if (error_state) 109 if (error_state)
115 eval_error (); 110 eval_error ();
116 else 111 else if (print_result ())
117 { 112 {
118 octave_value lhs_val = ult.value (); 113 if (Vprint_rhs_assign_val)
119 114 retval.print_with_name (octave_stdout,
120 if (! error_state && print_result ()) 115 lhs->str_print_code ());
116 else
121 { 117 {
122 if (Vprint_rhs_assign_val) 118 // We clear any index here so that we can
123 rhs_val.print_with_name (octave_stdout, 119 // get the new value of the referenced
124 lhs->str_print_code ()); 120 // object below, instead of the indexed
125 else 121 // value (which should be the same as the
122 // right hand side value).
123
124 ult.clear_index ();
125
126 octave_value lhs_val = ult.value ();
127
128 if (! error_state)
126 lhs_val.print_with_name (octave_stdout, 129 lhs_val.print_with_name (octave_stdout,
127 lhs->name ()); 130 lhs->name ());
128 } 131 }
129 } 132 }
130 } 133 }
132 } 135 }
133 else 136 else
134 eval_error (); 137 eval_error ();
135 } 138 }
136 139
137 return rhs_val; 140 return retval;
138 } 141 }
139 142
140 void 143 void
141 tree_simple_assignment::eval_error (void) 144 tree_simple_assignment::eval_error (void)
142 { 145 {
190 // it were broken up into a couple of separate functions. 193 // it were broken up into a couple of separate functions.
191 194
192 octave_value_list 195 octave_value_list
193 tree_multi_assignment::rvalue (int) 196 tree_multi_assignment::rvalue (int)
194 { 197 {
195 octave_value_list rhs_val; 198 octave_value_list retval;
196 199
197 if (error_state) 200 if (error_state)
198 return rhs_val; 201 return retval;
199 202
200 if (rhs) 203 if (rhs)
201 { 204 {
202 int n_out = lhs->length (); 205 int n_out = lhs->length ();
203 206
204 rhs_val = rhs->rvalue (n_out); 207 octave_value_list rhs_val = rhs->rvalue (n_out);
205 208
206 if (! (error_state || rhs_val.empty ())) 209 if (! error_state)
207 { 210 {
208 if (rhs_val.empty ()) 211 if (rhs_val.empty ())
209 { 212 {
210 error ("value on right hand side of assignment is undefined"); 213 error ("value on right hand side of assignment is undefined");
211 eval_error (); 214 eval_error ();
214 { 217 {
215 int k = 0; 218 int k = 0;
216 219
217 int n = rhs_val.length (); 220 int n = rhs_val.length ();
218 221
222 retval.resize (n, octave_value ());
223
219 for (Pix p = lhs->first (); p != 0; lhs->next (p)) 224 for (Pix p = lhs->first (); p != 0; lhs->next (p))
220 { 225 {
221 tree_expression *lhs_elt = lhs->operator () (p); 226 tree_expression *lhs_elt = lhs->operator () (p);
222 227
223 if (lhs_elt) 228 if (lhs_elt)
224 { 229 {
225 octave_lvalue ult = lhs_elt->lvalue (); 230 octave_lvalue ult = lhs_elt->lvalue ();
226 231
227 if (error_state) 232 if (error_state)
228 eval_error (); 233 eval_error ();
234 else if (k < n)
235 {
236 ult.assign (etype, rhs_val(k));
237
238 retval(k) = ult.value ();
239 }
229 else 240 else
241 error ("element number %d undefined in return list",
242 k+1);
243
244 if (error_state)
245 eval_error ();
246 else if (print_result ())
230 { 247 {
231 octave_value tmp = k < n 248 if (Vprint_rhs_assign_val)
232 ? rhs_val(k++) : octave_value (); 249 retval(k).print_with_name
233 250 (octave_stdout, lhs_elt->str_print_code ());
234 if (tmp.is_defined ()) 251 else
235 { 252 {
236 // XXX FIXME XXX -- handle other assignment ops. 253 // We clear any index here so that we can
237 ult.assign (octave_value::asn_eq, tmp); 254 // get the new value of the referenced
238 255 // object below, instead of the indexed
239 // We clear any index here so that we 256 // value (which should be the same as the
240 // can get the new value of the 257 // right hand side value).
241 // referenced object below, instead of
242 // the indexed value (which should be
243 // the same as the right hand side
244 // value).
245 258
246 ult.clear_index (); 259 ult.clear_index ();
247 } 260
248 else
249 error ("element number %d undefined in return list", k);
250
251 if (error_state)
252 eval_error ();
253 else if (! Vprint_rhs_assign_val)
254 {
255 octave_value lhs_val = ult.value (); 261 octave_value lhs_val = ult.value ();
256 262
257 if (! error_state && print_result ()) 263 if (! error_state)
258 { 264 lhs_val.print_with_name (octave_stdout,
259 if (Vprint_rhs_assign_val) 265 lhs_elt->name ());
260 tmp.print_with_name (octave_stdout,
261 lhs_elt->str_print_code ());
262 else
263 lhs_val.print_with_name (octave_stdout,
264 lhs_elt->name ());
265 }
266 } 266 }
267 } 267 }
268 } 268 }
269 else
270 eval_error ();
269 271
270 if (error_state) 272 if (error_state)
271 break; 273 break;
274
275 k++;
272 } 276 }
273 } 277 }
274 } 278 }
275 else
276 eval_error ();
277 } 279 }
278 280 else
279 return rhs_val; 281 eval_error ();
282
283 return retval;
280 } 284 }
281 285
282 void 286 void
283 tree_multi_assignment::eval_error (void) 287 tree_multi_assignment::eval_error (void)
284 { 288 {
289 293
290 if (l != -1 && c != -1) 294 if (l != -1 && c != -1)
291 ::error ("evaluating assignment expression near line %d, column %d", 295 ::error ("evaluating assignment expression near line %d, column %d",
292 l, c); 296 l, c);
293 } 297 }
298 }
299
300 string
301 tree_multi_assignment::oper (void) const
302 {
303 return octave_value::assign_op_as_string (etype);
294 } 304 }
295 305
296 void 306 void
297 tree_multi_assignment::accept (tree_walker& tw) 307 tree_multi_assignment::accept (tree_walker& tw)
298 { 308 {