Mercurial > hg > octave-nkf
comparison src/ov.cc @ 2880:0a076230ca87
[project @ 1997-04-24 09:47:41 by jwe]
author | jwe |
---|---|
date | Thu, 24 Apr 1997 09:47:41 +0000 |
parents | 8b262e771614 |
children | 1a30f46e1870 |
comparison
equal
deleted
inserted
replaced
2879:4309724baab6 | 2880:0a076230ca87 |
---|---|
40 #include "ov-cx-mat.h" | 40 #include "ov-cx-mat.h" |
41 #include "ov-ch-mat.h" | 41 #include "ov-ch-mat.h" |
42 #include "ov-str-mat.h" | 42 #include "ov-str-mat.h" |
43 #include "ov-range.h" | 43 #include "ov-range.h" |
44 #include "ov-struct.h" | 44 #include "ov-struct.h" |
45 #include "ov-list.h" | |
45 #include "ov-colon.h" | 46 #include "ov-colon.h" |
46 #include "ov-va-args.h" | 47 #include "ov-va-args.h" |
47 #include "ov-typeinfo.h" | 48 #include "ov-typeinfo.h" |
48 | 49 |
49 #include "defun.h" | 50 #include "defun.h" |
51 #include "error.h" | |
50 #include "gripes.h" | 52 #include "gripes.h" |
51 #include "pager.h" | 53 #include "pager.h" |
52 #include "pr-output.h" | 54 #include "pr-output.h" |
53 #include "utils.h" | 55 #include "utils.h" |
54 #include "variables.h" | 56 #include "variables.h" |
122 decrement_struct_indent (void) | 124 decrement_struct_indent (void) |
123 { | 125 { |
124 struct_indent -= 2; | 126 struct_indent -= 2; |
125 } | 127 } |
126 | 128 |
129 // Indentation level for lists. | |
130 int list_indent = 0; | |
131 | |
132 void | |
133 increment_list_indent (void) | |
134 { | |
135 list_indent += 2; | |
136 } | |
137 | |
138 void | |
139 decrement_list_indent (void) | |
140 { | |
141 list_indent -= 2; | |
142 } | |
143 | |
144 // XXX FIXME XXX | |
145 | |
127 // Octave's value type. | 146 // Octave's value type. |
128 | 147 |
129 string | 148 string |
130 octave_value::binary_op_as_string (binary_op op) | 149 octave_value::binary_op_as_string (binary_op op) |
131 { | 150 { |
205 retval = "|"; | 224 retval = "|"; |
206 break; | 225 break; |
207 | 226 |
208 case struct_ref: | 227 case struct_ref: |
209 retval = "."; | 228 retval = "."; |
229 break; | |
230 | |
231 default: | |
232 retval = "<unknown>"; | |
233 } | |
234 | |
235 return retval; | |
236 } | |
237 | |
238 string | |
239 octave_value::assign_op_as_string (assign_op op) | |
240 { | |
241 string retval; | |
242 | |
243 switch (op) | |
244 { | |
245 case asn_eq: | |
246 retval = "="; | |
247 break; | |
248 | |
249 case add_eq: | |
250 retval = "+="; | |
251 break; | |
252 | |
253 case sub_eq: | |
254 retval = "-="; | |
255 break; | |
256 | |
257 case mul_eq: | |
258 retval = "*="; | |
259 break; | |
260 | |
261 case div_eq: | |
262 retval = "/="; | |
263 break; | |
264 | |
265 case el_mul_eq: | |
266 retval = ".*="; | |
267 break; | |
268 | |
269 case el_div_eq: | |
270 retval = "./="; | |
271 break; | |
272 | |
273 case el_and_eq: | |
274 retval = "&="; | |
275 break; | |
276 | |
277 case el_or_eq: | |
278 retval = "|="; | |
210 break; | 279 break; |
211 | 280 |
212 default: | 281 default: |
213 retval = "<unknown>"; | 282 retval = "<unknown>"; |
214 } | 283 } |
353 | 422 |
354 octave_value::octave_value (const Octave_map& m) | 423 octave_value::octave_value (const Octave_map& m) |
355 : rep (new octave_struct (m)) | 424 : rep (new octave_struct (m)) |
356 { | 425 { |
357 rep->count = 1; | 426 rep->count = 1; |
358 } | 427 } |
428 | |
429 octave_value::octave_value (const octave_value_list& l) | |
430 : rep (new octave_list (l)) | |
431 { | |
432 rep->count = 1; | |
433 } | |
359 | 434 |
360 octave_value::octave_value (octave_value::magic_colon) | 435 octave_value::octave_value (octave_value::magic_colon) |
361 : rep (new octave_magic_colon ()) | 436 : rep (new octave_magic_colon ()) |
362 { | 437 { |
363 rep->count = 1; | 438 rep->count = 1; |
387 delete rep; | 462 delete rep; |
388 rep = 0; | 463 rep = 0; |
389 } | 464 } |
390 } | 465 } |
391 | 466 |
467 octave_value * | |
468 octave_value::clone (void) | |
469 { | |
470 panic_impossible (); | |
471 } | |
472 | |
392 void | 473 void |
393 octave_value::maybe_mutate (void) | 474 octave_value::maybe_mutate (void) |
394 { | 475 { |
395 octave_value *tmp = rep->try_narrowing_conversion (); | 476 octave_value *tmp = rep->try_narrowing_conversion (); |
396 | 477 |
410 error ("no suitable conversion found for assignment of %s to indexed %s", | 491 error ("no suitable conversion found for assignment of %s to indexed %s", |
411 tn2.c_str (), tn1.c_str ()); | 492 tn2.c_str (), tn1.c_str ()); |
412 } | 493 } |
413 | 494 |
414 octave_value& | 495 octave_value& |
415 octave_value::assign (const octave_value_list& idx, const octave_value& rhs) | 496 octave_value::assign (assign_op, const octave_value& rhs) |
497 { | |
498 // XXX FIXME XXX -- make this work for ops other than `='. | |
499 | |
500 return operator = (rhs); | |
501 } | |
502 | |
503 octave_value& | |
504 octave_value::assign (octave_value::assign_op op, | |
505 const octave_value_list& idx, | |
506 const octave_value& rhs) | |
416 { | 507 { |
417 make_unique (); | 508 make_unique (); |
418 | 509 |
419 bool assignment_ok = try_assignment (idx, rhs); | 510 bool assignment_ok = try_assignment (op, idx, rhs); |
420 | 511 |
421 if (! (error_state || assignment_ok)) | 512 if (! (error_state || assignment_ok)) |
422 { | 513 { |
423 assignment_ok = try_assignment_with_conversion (idx, rhs); | 514 assignment_ok = try_assignment_with_conversion (op,idx, rhs); |
424 | 515 |
425 if (! (error_state || assignment_ok)) | 516 if (! (error_state || assignment_ok)) |
426 gripe_no_conversion (type_name (), rhs.type_name ()); | 517 gripe_no_conversion (type_name (), rhs.type_name ()); |
427 } | 518 } |
428 | 519 |
434 | 525 |
435 Octave_map | 526 Octave_map |
436 octave_value::map_value (void) const | 527 octave_value::map_value (void) const |
437 { | 528 { |
438 return rep->map_value (); | 529 return rep->map_value (); |
530 } | |
531 | |
532 octave_value_list | |
533 octave_value::list_value (void) const | |
534 { | |
535 return rep->list_value (); | |
439 } | 536 } |
440 | 537 |
441 ColumnVector | 538 ColumnVector |
442 octave_value::vector_value (bool force_string_conv, | 539 octave_value::vector_value (bool force_string_conv, |
443 bool force_vector_conversion) const | 540 bool force_vector_conversion) const |
593 error ("type conversion for assignment of %s to indexed %s failed", | 690 error ("type conversion for assignment of %s to indexed %s failed", |
594 tn2.c_str (), tn1.c_str ()); | 691 tn2.c_str (), tn1.c_str ()); |
595 } | 692 } |
596 | 693 |
597 bool | 694 bool |
598 octave_value::convert_and_assign (const octave_value_list& idx, | 695 octave_value::convert_and_assign (octave_value::assign_op op, |
696 const octave_value_list& idx, | |
599 const octave_value& rhs) | 697 const octave_value& rhs) |
600 { | 698 { |
601 bool assignment_ok = false; | 699 bool assignment_ok = false; |
602 | 700 |
603 int t_lhs = type_id (); | 701 int t_lhs = type_id (); |
619 { | 717 { |
620 octave_value *old_rep = rep; | 718 octave_value *old_rep = rep; |
621 rep = tmp; | 719 rep = tmp; |
622 rep->count = 1; | 720 rep->count = 1; |
623 | 721 |
624 assignment_ok = try_assignment (idx, rhs); | 722 assignment_ok = try_assignment (op, idx, rhs); |
625 | 723 |
626 if (! assignment_ok && old_rep) | 724 if (! assignment_ok && old_rep) |
627 { | 725 { |
628 if (--rep->count == 0) | 726 if (--rep->count == 0) |
629 delete rep; | 727 delete rep; |
644 | 742 |
645 return (assignment_ok && ! error_state); | 743 return (assignment_ok && ! error_state); |
646 } | 744 } |
647 | 745 |
648 bool | 746 bool |
649 octave_value::try_assignment_with_conversion (const octave_value_list& idx, | 747 octave_value::try_assignment_with_conversion (octave_value::assign_op op, |
748 const octave_value_list& idx, | |
650 const octave_value& rhs) | 749 const octave_value& rhs) |
651 { | 750 { |
652 bool assignment_ok = convert_and_assign (idx, rhs); | 751 bool assignment_ok = convert_and_assign (op, idx, rhs); |
653 | 752 |
654 if (! (error_state || assignment_ok)) | 753 if (! (error_state || assignment_ok)) |
655 { | 754 { |
656 octave_value tmp_rhs; | 755 octave_value tmp_rhs; |
657 type_conv_fcn cf_rhs = rhs.numeric_conversion_function (); | 756 type_conv_fcn cf_rhs = rhs.numeric_conversion_function (); |
671 rep->count = 1; | 770 rep->count = 1; |
672 } | 771 } |
673 | 772 |
674 if (cf_this || cf_rhs) | 773 if (cf_this || cf_rhs) |
675 { | 774 { |
676 assignment_ok = try_assignment (idx, tmp_rhs); | 775 assignment_ok = try_assignment (op, idx, tmp_rhs); |
677 | 776 |
678 if (! (error_state || assignment_ok)) | 777 if (! (error_state || assignment_ok)) |
679 assignment_ok = convert_and_assign (idx, tmp_rhs); | 778 assignment_ok = convert_and_assign (op, idx, tmp_rhs); |
680 } | 779 } |
681 | 780 |
682 if (! assignment_ok && old_rep) | 781 if (! assignment_ok && old_rep) |
683 { | 782 { |
684 if (--rep->count == 0) | 783 if (--rep->count == 0) |
694 | 793 |
695 return (assignment_ok && ! error_state); | 794 return (assignment_ok && ! error_state); |
696 } | 795 } |
697 | 796 |
698 bool | 797 bool |
699 octave_value::try_assignment (const octave_value_list& idx, | 798 octave_value::try_assignment (octave_value::assign_op op, |
799 const octave_value_list& idx, | |
700 const octave_value& rhs) | 800 const octave_value& rhs) |
701 { | 801 { |
702 bool retval = false; | 802 bool retval = false; |
703 | 803 |
704 int t_lhs = type_id (); | 804 int t_lhs = type_id (); |
705 int t_rhs = rhs.type_id (); | 805 int t_rhs = rhs.type_id (); |
706 | 806 |
707 assign_op_fcn f = octave_value_typeinfo::lookup_assign_op (t_lhs, t_rhs); | 807 assign_op_fcn f |
808 = octave_value_typeinfo::lookup_assign_op (op, t_lhs, t_rhs); | |
708 | 809 |
709 if (f) | 810 if (f) |
710 { | 811 { |
711 f (*rep, idx, *(rhs.rep)); | 812 f (*rep, idx, *(rhs.rep)); |
712 | 813 |
791 octave_bool::register_type (); | 892 octave_bool::register_type (); |
792 octave_bool_matrix::register_type (); | 893 octave_bool_matrix::register_type (); |
793 octave_char_matrix::register_type (); | 894 octave_char_matrix::register_type (); |
794 octave_char_matrix_str::register_type (); | 895 octave_char_matrix_str::register_type (); |
795 octave_struct::register_type (); | 896 octave_struct::register_type (); |
897 octave_list::register_type (); | |
796 octave_all_va_args::register_type (); | 898 octave_all_va_args::register_type (); |
797 octave_magic_colon::register_type (); | 899 octave_magic_colon::register_type (); |
798 } | 900 } |
799 | 901 |
800 static int | 902 static int |