Mercurial > hg > octave-nkf
comparison src/pt-assign.cc @ 10230:0a5a769b8fc0
disallow computed multiple assignment
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Sat, 30 Jan 2010 19:28:25 +0100 |
parents | d3fc22c3071c |
children | 57a59eae83cc |
comparison
equal
deleted
inserted
replaced
10229:02ae72071221 | 10230:0a5a769b8fc0 |
---|---|
298 | 298 |
299 // Multi-valued assignment expressions. | 299 // Multi-valued assignment expressions. |
300 | 300 |
301 tree_multi_assignment::tree_multi_assignment | 301 tree_multi_assignment::tree_multi_assignment |
302 (tree_argument_list *lst, tree_expression *r, | 302 (tree_argument_list *lst, tree_expression *r, |
303 bool plhs, int l, int c, octave_value::assign_op t) | 303 bool plhs, int l, int c) |
304 : tree_expression (l, c), lhs (lst), rhs (r), preserve (plhs), etype (t), | 304 : tree_expression (l, c), lhs (lst), rhs (r), preserve (plhs), |
305 first_execution (true) { } | 305 first_execution (true) { } |
306 | 306 |
307 tree_multi_assignment::~tree_multi_assignment (void) | 307 tree_multi_assignment::~tree_multi_assignment (void) |
308 { | 308 { |
309 if (! preserve) | 309 if (! preserve) |
391 | 391 |
392 if (nel != 1) | 392 if (nel != 1) |
393 { | 393 { |
394 if (k + nel <= n) | 394 if (k + nel <= n) |
395 { | 395 { |
396 if (etype == octave_value::op_asn_eq) | 396 // This won't do a copy. |
397 octave_value_list ovl = rhs_val.slice (k, nel); | |
398 | |
399 ult.assign (octave_value::op_asn_eq, octave_value (ovl, true)); | |
400 | |
401 if (! error_state) | |
397 { | 402 { |
398 // This won't do a copy. | 403 retval_list.push_back (ovl); |
399 octave_value_list ovl = rhs_val.slice (k, nel); | 404 |
400 | 405 k += nel; |
401 ult.assign (etype, octave_value (ovl, true)); | |
402 | |
403 if (! error_state) | |
404 { | |
405 retval_list.push_back (ovl); | |
406 | |
407 k += nel; | |
408 } | |
409 } | |
410 else | |
411 { | |
412 std::string op = octave_value::assign_op_as_string (etype); | |
413 error ("operator %s unsupported for comma-separated list assignment", | |
414 op.c_str ()); | |
415 } | 406 } |
416 } | 407 } |
417 else | 408 else |
418 error ("some elements undefined in return list"); | 409 error ("some elements undefined in return list"); |
419 } | 410 } |
420 else | 411 else |
421 { | 412 { |
422 if (k < n) | 413 if (k < n) |
423 { | 414 { |
424 ult.assign (etype, rhs_val(k)); | 415 ult.assign (octave_value::op_asn_eq, rhs_val(k)); |
425 | 416 |
426 if (ult.is_black_hole ()) | 417 if (ult.is_black_hole ()) |
427 { | 418 { |
428 k++; | 419 k++; |
429 continue; | 420 continue; |
430 } | 421 } |
431 else if (! error_state) | 422 else if (! error_state) |
432 { | 423 { |
433 if (etype == octave_value::op_asn_eq) | 424 retval_list.push_back (rhs_val(k)); |
434 retval_list.push_back (rhs_val(k)); | |
435 else | |
436 retval_list.push_back (ult.value ()); | |
437 | 425 |
438 k++; | 426 k++; |
439 } | 427 } |
440 } | 428 } |
441 else | 429 else |
476 } | 464 } |
477 | 465 |
478 std::string | 466 std::string |
479 tree_multi_assignment::oper (void) const | 467 tree_multi_assignment::oper (void) const |
480 { | 468 { |
481 return octave_value::assign_op_as_string (etype); | 469 return octave_value::assign_op_as_string (op_type ()); |
482 } | 470 } |
483 | 471 |
484 tree_expression * | 472 tree_expression * |
485 tree_multi_assignment::dup (symbol_table::scope_id scope, | 473 tree_multi_assignment::dup (symbol_table::scope_id scope, |
486 symbol_table::context_id context) const | 474 symbol_table::context_id context) const |
487 { | 475 { |
488 tree_multi_assignment *new_ma | 476 tree_multi_assignment *new_ma |
489 = new tree_multi_assignment (lhs ? lhs->dup (scope, context) : 0, | 477 = new tree_multi_assignment (lhs ? lhs->dup (scope, context) : 0, |
490 rhs ? rhs->dup (scope, context) : 0, | 478 rhs ? rhs->dup (scope, context) : 0, |
491 preserve, etype); | 479 preserve); |
492 | 480 |
493 new_ma->copy_base (*this); | 481 new_ma->copy_base (*this); |
494 | 482 |
495 return new_ma; | 483 return new_ma; |
496 } | 484 } |