2376
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
2376
|
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 "Array-flags.h" |
2942
|
32 #include "str-vec.h" |
2376
|
33 |
2974
|
34 #include "oct-obj.h" |
2376
|
35 #include "ov.h" |
|
36 #include "ov-base.h" |
2825
|
37 #include "ov-bool.h" |
|
38 #include "ov-bool-mat.h" |
3351
|
39 #include "ov-cell.h" |
2376
|
40 #include "ov-scalar.h" |
|
41 #include "ov-re-mat.h" |
|
42 #include "ov-complex.h" |
|
43 #include "ov-cx-mat.h" |
|
44 #include "ov-ch-mat.h" |
|
45 #include "ov-str-mat.h" |
|
46 #include "ov-range.h" |
|
47 #include "ov-struct.h" |
2903
|
48 #include "ov-file.h" |
2880
|
49 #include "ov-list.h" |
3977
|
50 #include "ov-cs-list.h" |
2376
|
51 #include "ov-colon.h" |
|
52 #include "ov-va-args.h" |
2974
|
53 #include "ov-builtin.h" |
|
54 #include "ov-mapper.h" |
|
55 #include "ov-usr-fcn.h" |
2376
|
56 #include "ov-typeinfo.h" |
|
57 |
|
58 #include "defun.h" |
2880
|
59 #include "error.h" |
2376
|
60 #include "gripes.h" |
|
61 #include "pager.h" |
|
62 #include "pr-output.h" |
|
63 #include "utils.h" |
|
64 #include "variables.h" |
|
65 |
2477
|
66 // We are likely to have a lot of octave_value objects to allocate, so |
|
67 // make the grow_size large. |
3219
|
68 DEFINE_OCTAVE_ALLOCATOR2(octave_value, 1024); |
2477
|
69 |
2376
|
70 // If TRUE, allow assignments like |
|
71 // |
|
72 // octave> A(1) = 3; A(2) = 5 |
|
73 // |
|
74 // for A already defined and a matrix type. |
|
75 bool Vdo_fortran_indexing; |
|
76 |
|
77 // Should we allow things like: |
|
78 // |
|
79 // octave> 'abc' + 0 |
|
80 // 97 98 99 |
|
81 // |
|
82 // to happen? A positive value means yes. A negative value means |
|
83 // yes, but print a warning message. Zero means it should be |
|
84 // considered an error. |
|
85 int Vimplicit_str_to_num_ok; |
|
86 |
|
87 // Should we allow silent conversion of complex to real when a real |
|
88 // type is what we're really looking for? A positive value means yes. |
|
89 // A negative value means yes, but print a warning message. Zero |
|
90 // means it should be considered an error. |
|
91 int Vok_to_lose_imaginary_part; |
|
92 |
|
93 // If TRUE, create column vectors when doing assignments like: |
|
94 // |
|
95 // octave> A(1) = 3; A(2) = 5 |
|
96 // |
|
97 // (for A undefined). Only matters when resize_on_range_error is also |
|
98 // TRUE. |
3418
|
99 static bool Vprefer_column_vectors; |
2376
|
100 |
|
101 // If TRUE, print the name along with the value. |
|
102 bool Vprint_answer_id_name; |
|
103 |
|
104 // Should operations on empty matrices return empty matrices or an |
|
105 // error? A positive value means yes. A negative value means yes, |
|
106 // but print a warning message. Zero means it should be considered an |
|
107 // error. |
|
108 int Vpropagate_empty_matrices; |
|
109 |
|
110 // How many levels of structure elements should we print? |
|
111 int Vstruct_levels_to_print; |
|
112 |
|
113 // Allow divide by zero errors to be suppressed. |
|
114 bool Vwarn_divide_by_zero; |
|
115 |
2948
|
116 // If TRUE, resize matrices when performing and indexed assignment and |
|
117 // the indices are outside the current bounds. |
3196
|
118 bool Vresize_on_range_error; |
2948
|
119 |
2880
|
120 // XXX FIXME XXX |
|
121 |
2376
|
122 // Octave's value type. |
|
123 |
3536
|
124 std::string |
3203
|
125 octave_value::unary_op_as_string (unary_op op) |
|
126 { |
3523
|
127 std::string retval; |
3203
|
128 |
|
129 switch (op) |
|
130 { |
3533
|
131 case op_not: |
3203
|
132 retval = "!"; |
|
133 break; |
|
134 |
3533
|
135 case op_uminus: |
3203
|
136 retval = "-"; |
|
137 break; |
|
138 |
3533
|
139 case op_transpose: |
3203
|
140 retval = ".'"; |
|
141 break; |
|
142 |
3533
|
143 case op_hermitian: |
3203
|
144 retval = "'"; |
|
145 break; |
|
146 |
3533
|
147 case op_incr: |
3203
|
148 retval = "++"; |
|
149 break; |
|
150 |
3533
|
151 case op_decr: |
3203
|
152 retval = "--"; |
|
153 break; |
|
154 |
|
155 default: |
|
156 retval = "<unknown>"; |
|
157 } |
|
158 |
|
159 return retval; |
|
160 } |
|
161 |
3536
|
162 std::string |
2376
|
163 octave_value::binary_op_as_string (binary_op op) |
|
164 { |
3523
|
165 std::string retval; |
2376
|
166 |
|
167 switch (op) |
|
168 { |
3533
|
169 case op_add: |
2376
|
170 retval = "+"; |
|
171 break; |
|
172 |
3533
|
173 case op_sub: |
2376
|
174 retval = "-"; |
|
175 break; |
|
176 |
3533
|
177 case op_mul: |
2376
|
178 retval = "*"; |
|
179 break; |
|
180 |
3533
|
181 case op_div: |
2376
|
182 retval = "/"; |
|
183 break; |
|
184 |
3533
|
185 case op_pow: |
2376
|
186 retval = "^"; |
|
187 break; |
|
188 |
3533
|
189 case op_ldiv: |
2376
|
190 retval = "\\"; |
|
191 break; |
|
192 |
3533
|
193 case op_lshift: |
2903
|
194 retval = "<<"; |
|
195 break; |
|
196 |
3533
|
197 case op_rshift: |
2903
|
198 retval = ">>"; |
|
199 break; |
|
200 |
3533
|
201 case op_lt: |
2376
|
202 retval = "<"; |
|
203 break; |
|
204 |
3533
|
205 case op_le: |
2376
|
206 retval = "<="; |
|
207 break; |
|
208 |
3533
|
209 case op_eq: |
2376
|
210 retval = "=="; |
|
211 break; |
|
212 |
3533
|
213 case op_ge: |
2376
|
214 retval = ">="; |
|
215 break; |
|
216 |
3533
|
217 case op_gt: |
2376
|
218 retval = ">"; |
|
219 break; |
|
220 |
3533
|
221 case op_ne: |
2376
|
222 retval = "!="; |
|
223 break; |
|
224 |
3533
|
225 case op_el_mul: |
2376
|
226 retval = ".*"; |
|
227 break; |
|
228 |
3533
|
229 case op_el_div: |
2376
|
230 retval = "./"; |
|
231 break; |
|
232 |
3533
|
233 case op_el_pow: |
2376
|
234 retval = ".^"; |
|
235 break; |
|
236 |
3533
|
237 case op_el_ldiv: |
2376
|
238 retval = ".\\"; |
|
239 break; |
|
240 |
3533
|
241 case op_el_and: |
2376
|
242 retval = "&"; |
|
243 break; |
|
244 |
3533
|
245 case op_el_or: |
2376
|
246 retval = "|"; |
|
247 break; |
|
248 |
3533
|
249 case op_struct_ref: |
2376
|
250 retval = "."; |
|
251 break; |
|
252 |
|
253 default: |
|
254 retval = "<unknown>"; |
|
255 } |
|
256 |
|
257 return retval; |
|
258 } |
|
259 |
3536
|
260 std::string |
2880
|
261 octave_value::assign_op_as_string (assign_op op) |
|
262 { |
3523
|
263 std::string retval; |
2880
|
264 |
|
265 switch (op) |
|
266 { |
3533
|
267 case op_asn_eq: |
2880
|
268 retval = "="; |
|
269 break; |
|
270 |
3533
|
271 case op_add_eq: |
2880
|
272 retval = "+="; |
|
273 break; |
|
274 |
3533
|
275 case op_sub_eq: |
2880
|
276 retval = "-="; |
|
277 break; |
|
278 |
3533
|
279 case op_mul_eq: |
2880
|
280 retval = "*="; |
|
281 break; |
|
282 |
3533
|
283 case op_div_eq: |
2880
|
284 retval = "/="; |
|
285 break; |
|
286 |
3533
|
287 case op_ldiv_eq: |
3204
|
288 retval = "\\="; |
|
289 break; |
|
290 |
3533
|
291 case op_lshift_eq: |
2903
|
292 retval = "<<="; |
|
293 break; |
|
294 |
3533
|
295 case op_rshift_eq: |
2903
|
296 retval = ">>="; |
|
297 break; |
|
298 |
3533
|
299 case op_el_mul_eq: |
2880
|
300 retval = ".*="; |
|
301 break; |
|
302 |
3533
|
303 case op_el_div_eq: |
2880
|
304 retval = "./="; |
|
305 break; |
|
306 |
3533
|
307 case op_el_ldiv_eq: |
3204
|
308 retval = ".\\="; |
|
309 break; |
|
310 |
3533
|
311 case op_el_and_eq: |
2880
|
312 retval = "&="; |
|
313 break; |
|
314 |
3533
|
315 case op_el_or_eq: |
2880
|
316 retval = "|="; |
|
317 break; |
|
318 |
|
319 default: |
|
320 retval = "<unknown>"; |
|
321 } |
|
322 |
|
323 return retval; |
|
324 } |
|
325 |
2376
|
326 octave_value::octave_value (void) |
2825
|
327 : rep (new octave_base_value ()) |
|
328 { |
|
329 rep->count = 1; |
|
330 } |
2376
|
331 |
|
332 octave_value::octave_value (double d) |
2825
|
333 : rep (new octave_scalar (d)) |
|
334 { |
|
335 rep->count = 1; |
|
336 } |
2376
|
337 |
3351
|
338 octave_value::octave_value (const Cell& c) |
|
339 : rep (new octave_cell (c)) |
|
340 { |
|
341 rep->count = 1; |
|
342 maybe_mutate (); |
|
343 } |
|
344 |
2376
|
345 octave_value::octave_value (const Matrix& m) |
2423
|
346 : rep (new octave_matrix (m)) |
|
347 { |
|
348 rep->count = 1; |
|
349 maybe_mutate (); |
|
350 } |
2376
|
351 |
|
352 octave_value::octave_value (const DiagMatrix& d) |
2423
|
353 : rep (new octave_matrix (d)) |
|
354 { |
|
355 rep->count = 1; |
|
356 maybe_mutate (); |
|
357 } |
2376
|
358 |
3418
|
359 octave_value::octave_value (const RowVector& v) |
|
360 : rep (new octave_matrix (v)) |
2423
|
361 { |
|
362 rep->count = 1; |
|
363 maybe_mutate (); |
|
364 } |
2376
|
365 |
3418
|
366 octave_value::octave_value (const ColumnVector& v) |
|
367 : rep (new octave_matrix (v)) |
2423
|
368 { |
|
369 rep->count = 1; |
|
370 maybe_mutate (); |
|
371 } |
2376
|
372 |
|
373 octave_value::octave_value (const Complex& C) |
2423
|
374 : rep (new octave_complex (C)) |
|
375 { |
|
376 rep->count = 1; |
|
377 maybe_mutate (); |
|
378 } |
2376
|
379 |
|
380 octave_value::octave_value (const ComplexMatrix& m) |
2423
|
381 : rep (new octave_complex_matrix (m)) |
|
382 { |
|
383 rep->count = 1; |
|
384 maybe_mutate (); |
|
385 } |
2376
|
386 |
|
387 octave_value::octave_value (const ComplexDiagMatrix& d) |
2423
|
388 : rep (new octave_complex_matrix (d)) |
|
389 { |
|
390 rep->count = 1; |
|
391 maybe_mutate (); |
|
392 } |
2376
|
393 |
3418
|
394 octave_value::octave_value (const ComplexRowVector& v) |
|
395 : rep (new octave_complex_matrix (v)) |
2423
|
396 { |
|
397 rep->count = 1; |
|
398 maybe_mutate (); |
|
399 } |
2376
|
400 |
3418
|
401 octave_value::octave_value (const ComplexColumnVector& v) |
|
402 : rep (new octave_complex_matrix (v)) |
2423
|
403 { |
|
404 rep->count = 1; |
|
405 maybe_mutate (); |
|
406 } |
2376
|
407 |
2825
|
408 octave_value::octave_value (bool b) |
|
409 : rep (new octave_bool (b)) |
|
410 { |
|
411 rep->count = 1; |
|
412 } |
|
413 |
|
414 octave_value::octave_value (const boolMatrix& bm) |
|
415 : rep (new octave_bool_matrix (bm)) |
|
416 { |
|
417 rep->count = 1; |
|
418 maybe_mutate (); |
|
419 } |
|
420 |
3189
|
421 octave_value::octave_value (char c) |
|
422 : rep (new octave_char_matrix_str (c)) |
|
423 { |
|
424 rep->count = 1; |
|
425 maybe_mutate (); |
|
426 } |
|
427 |
2376
|
428 octave_value::octave_value (const char *s) |
2423
|
429 : rep (new octave_char_matrix_str (s)) |
|
430 { |
|
431 rep->count = 1; |
|
432 maybe_mutate (); |
|
433 } |
2376
|
434 |
3523
|
435 octave_value::octave_value (const std::string& s) |
2423
|
436 : rep (new octave_char_matrix_str (s)) |
|
437 { |
|
438 rep->count = 1; |
|
439 maybe_mutate (); |
|
440 } |
2376
|
441 |
|
442 octave_value::octave_value (const string_vector& s) |
2423
|
443 : rep (new octave_char_matrix_str (s)) |
|
444 { |
|
445 rep->count = 1; |
|
446 maybe_mutate (); |
|
447 } |
2376
|
448 |
|
449 octave_value::octave_value (const charMatrix& chm, bool is_string) |
2409
|
450 : rep (0) |
|
451 { |
|
452 if (is_string) |
|
453 rep = new octave_char_matrix_str (chm); |
|
454 else |
|
455 rep = new octave_char_matrix (chm); |
2376
|
456 |
2409
|
457 rep->count = 1; |
2423
|
458 maybe_mutate (); |
2409
|
459 } |
2376
|
460 |
|
461 octave_value::octave_value (double base, double limit, double inc) |
2423
|
462 : rep (new octave_range (base, limit, inc)) |
|
463 { |
|
464 rep->count = 1; |
|
465 maybe_mutate (); |
|
466 } |
2376
|
467 |
|
468 octave_value::octave_value (const Range& r) |
2423
|
469 : rep (new octave_range (r)) |
|
470 { |
|
471 rep->count = 1; |
|
472 maybe_mutate (); |
|
473 } |
2376
|
474 |
|
475 octave_value::octave_value (const Octave_map& m) |
2825
|
476 : rep (new octave_struct (m)) |
|
477 { |
|
478 rep->count = 1; |
2880
|
479 } |
|
480 |
3340
|
481 octave_value::octave_value (const octave_stream& s, int n) |
2903
|
482 : rep (new octave_file (s, n)) |
|
483 { |
|
484 rep->count = 1; |
|
485 } |
|
486 |
2974
|
487 octave_value::octave_value (octave_function *f) |
|
488 : rep (f) |
|
489 { |
|
490 rep->count = 1; |
|
491 } |
|
492 |
3977
|
493 octave_value::octave_value (const octave_value_list& l, bool is_cs_list) |
|
494 : rep (0) |
2880
|
495 { |
3977
|
496 if (is_cs_list) |
|
497 rep = new octave_cs_list (l); |
|
498 else |
|
499 new octave_list (l); |
|
500 |
2880
|
501 rep->count = 1; |
|
502 } |
2376
|
503 |
|
504 octave_value::octave_value (octave_value::magic_colon) |
2825
|
505 : rep (new octave_magic_colon ()) |
|
506 { |
|
507 rep->count = 1; |
|
508 } |
2376
|
509 |
|
510 octave_value::octave_value (octave_value::all_va_args) |
2825
|
511 : rep (new octave_all_va_args ()) |
|
512 { |
|
513 rep->count = 1; |
|
514 } |
2376
|
515 |
3933
|
516 octave_value::octave_value (octave_value *new_rep, int count) |
2825
|
517 : rep (new_rep) |
|
518 { |
3933
|
519 rep->count = count; |
2825
|
520 } |
2376
|
521 |
|
522 octave_value::~octave_value (void) |
|
523 { |
|
524 #if defined (MDEBUG) |
3531
|
525 std::cerr << "~octave_value: rep: " << rep |
|
526 << " rep->count: " << rep->count << "\n"; |
2376
|
527 #endif |
|
528 |
|
529 if (rep && --rep->count == 0) |
|
530 { |
|
531 delete rep; |
|
532 rep = 0; |
|
533 } |
|
534 } |
|
535 |
2880
|
536 octave_value * |
3933
|
537 octave_value::clone (void) const |
2880
|
538 { |
|
539 panic_impossible (); |
3546
|
540 return 0; |
2880
|
541 } |
|
542 |
2409
|
543 void |
|
544 octave_value::maybe_mutate (void) |
|
545 { |
2410
|
546 octave_value *tmp = rep->try_narrowing_conversion (); |
2409
|
547 |
|
548 if (tmp && tmp != rep) |
|
549 { |
|
550 if (--rep->count == 0) |
|
551 delete rep; |
|
552 |
|
553 rep = tmp; |
|
554 rep->count = 1; |
|
555 } |
|
556 } |
|
557 |
2974
|
558 octave_value_list |
3933
|
559 octave_value::subsref (const std::string type, |
|
560 const SLList<octave_value_list>& idx, int nargout) |
|
561 { |
|
562 if (is_constant ()) |
|
563 return rep->subsref (type, idx); |
|
564 else |
|
565 return rep->subsref (type, idx, nargout); |
|
566 } |
|
567 |
|
568 octave_value |
|
569 octave_value::next_subsref (const std::string type, |
|
570 const SLList<octave_value_list>& idx, |
|
571 int skip) |
|
572 { |
|
573 assert (skip > 0); |
|
574 |
|
575 if (idx.length () > skip) |
|
576 { |
|
577 SLList<octave_value_list> new_idx (idx); |
|
578 for (int i = 0; i < skip; i++) |
|
579 new_idx.remove_front (); |
|
580 return subsref (type.substr (skip), new_idx); |
|
581 } |
|
582 else |
|
583 return *this; |
|
584 } |
|
585 |
|
586 octave_value_list |
3544
|
587 octave_value::do_multi_index_op (int nargout, const octave_value_list& idx) |
2974
|
588 { |
3544
|
589 return rep->do_multi_index_op (nargout, idx); |
2974
|
590 } |
|
591 |
2376
|
592 static void |
3933
|
593 gripe_no_conversion (const std::string& on, const std::string& tn1, |
|
594 const std::string& tn2) |
2376
|
595 { |
3203
|
596 error ("operator %s: no conversion for assignment of `%s' to indexed `%s'", |
|
597 on.c_str (), tn2.c_str (), tn1.c_str ()); |
2376
|
598 } |
|
599 |
3933
|
600 #if 0 |
3204
|
601 static void |
3933
|
602 gripe_assign_failed (const std::string& on, const std::string& tn1, |
|
603 const std::string& tn2) |
3204
|
604 { |
|
605 error ("assignment failed for `%s %s %s'", |
|
606 tn1.c_str (), on.c_str (), tn2.c_str ()); |
|
607 } |
3933
|
608 #endif |
3204
|
609 |
|
610 static void |
3933
|
611 gripe_assign_failed_or_no_method (const std::string& on, |
|
612 const std::string& tn1, |
3523
|
613 const std::string& tn2) |
3204
|
614 { |
|
615 error ("assignment failed, or no method for `%s %s %s'", |
|
616 tn1.c_str (), on.c_str (), tn2.c_str ()); |
|
617 } |
|
618 |
3933
|
619 octave_value |
|
620 octave_value::subsasgn (const std::string type, |
|
621 const SLList<octave_value_list>& idx, |
|
622 const octave_value& rhs) |
|
623 { |
|
624 return rep->subsasgn (type, idx, rhs); |
|
625 } |
|
626 |
|
627 octave_value |
|
628 octave_value::assign (assign_op op, const std::string type, |
|
629 const SLList<octave_value_list>& idx, |
|
630 const octave_value& rhs) |
|
631 { |
|
632 octave_value retval; |
|
633 |
|
634 make_unique (); |
|
635 |
|
636 octave_value t_rhs = rhs; |
|
637 |
|
638 if (op != op_asn_eq) |
|
639 { |
|
640 // XXX FIXME XXX -- only do the following stuff if we can't find |
|
641 // a specific function to call to handle the op= operation for |
|
642 // the types we have. |
|
643 |
|
644 octave_value t = subsref (type, idx); |
|
645 |
|
646 if (! error_state) |
|
647 { |
|
648 binary_op binop = op_eq_to_binary_op (op); |
|
649 |
|
650 if (! error_state) |
|
651 t_rhs = do_binary_op (binop, t, rhs); |
|
652 } |
|
653 } |
|
654 |
|
655 if (! error_state) |
|
656 { |
|
657 if (type[0] == '.' && ! is_map ()) |
|
658 { |
|
659 octave_value tmp = Octave_map (); |
|
660 retval = tmp.subsasgn (type, idx, t_rhs); |
|
661 } |
|
662 else |
|
663 retval = subsasgn (type, idx, t_rhs); |
|
664 } |
|
665 |
|
666 if (error_state) |
|
667 gripe_assign_failed_or_no_method (assign_op_as_string (op), |
|
668 type_name (), rhs.type_name ()); |
|
669 |
|
670 return retval; |
|
671 } |
|
672 |
|
673 const octave_value& |
3203
|
674 octave_value::assign (assign_op op, const octave_value& rhs) |
2880
|
675 { |
3533
|
676 if (op == op_asn_eq) |
3203
|
677 operator = (rhs); |
|
678 else |
|
679 { |
3204
|
680 // XXX FIXME XXX -- only do the following stuff if we can't find |
|
681 // a specific function to call to handle the op= operation for |
|
682 // the types we have. |
|
683 |
|
684 binary_op binop = op_eq_to_binary_op (op); |
|
685 |
|
686 if (! error_state) |
|
687 { |
|
688 octave_value t = do_binary_op (binop, *this, rhs); |
|
689 |
|
690 if (! error_state) |
|
691 operator = (t); |
|
692 } |
|
693 |
|
694 if (error_state) |
|
695 gripe_assign_failed_or_no_method (assign_op_as_string (op), |
|
696 type_name (), rhs.type_name ()); |
|
697 } |
|
698 |
3933
|
699 return *this; |
2376
|
700 } |
|
701 |
3351
|
702 Cell |
|
703 octave_value::cell_value (void) const |
|
704 { |
|
705 return rep->cell_value (); |
|
706 } |
|
707 |
2376
|
708 Octave_map |
|
709 octave_value::map_value (void) const |
|
710 { |
|
711 return rep->map_value (); |
|
712 } |
|
713 |
3340
|
714 octave_stream |
2903
|
715 octave_value::stream_value (void) const |
|
716 { |
|
717 return rep->stream_value (); |
|
718 } |
|
719 |
|
720 int |
|
721 octave_value::stream_number (void) const |
|
722 { |
|
723 return rep->stream_number (); |
|
724 } |
|
725 |
2974
|
726 octave_function * |
|
727 octave_value::function_value (bool silent) |
|
728 { |
|
729 return rep->function_value (silent); |
|
730 } |
|
731 |
2880
|
732 octave_value_list |
|
733 octave_value::list_value (void) const |
|
734 { |
|
735 return rep->list_value (); |
|
736 } |
|
737 |
2376
|
738 ColumnVector |
3419
|
739 octave_value::column_vector_value (bool force_string_conv, |
|
740 bool force_vector_conversion) const |
|
741 { |
|
742 ColumnVector retval; |
|
743 |
|
744 Matrix m = matrix_value (force_string_conv); |
|
745 |
|
746 if (error_state) |
|
747 return retval; |
|
748 |
|
749 int nr = m.rows (); |
|
750 int nc = m.columns (); |
|
751 |
|
752 if (nc == 1) |
|
753 { |
|
754 retval.resize (nr); |
|
755 for (int i = 0; i < nr; i++) |
|
756 retval (i) = m (i, 0); |
|
757 } |
|
758 else |
|
759 { |
3523
|
760 std::string tn = type_name (); |
3419
|
761 gripe_invalid_conversion (tn.c_str (), "real column vector"); |
|
762 } |
|
763 |
|
764 return retval; |
|
765 } |
|
766 |
|
767 ComplexColumnVector |
|
768 octave_value::complex_column_vector_value (bool force_string_conv, |
|
769 bool force_vector_conversion) const |
|
770 { |
|
771 ComplexColumnVector retval; |
|
772 |
|
773 ComplexMatrix m = complex_matrix_value (force_string_conv); |
|
774 |
|
775 if (error_state) |
|
776 return retval; |
|
777 |
|
778 int nr = m.rows (); |
|
779 int nc = m.columns (); |
|
780 |
|
781 if (nc == 1) |
|
782 { |
3465
|
783 retval.resize (nr); |
|
784 for (int i = 0; i < nr; i++) |
3419
|
785 retval (i) = m (i, 0); |
|
786 } |
|
787 else |
|
788 { |
3523
|
789 std::string tn = type_name (); |
3419
|
790 gripe_invalid_conversion (tn.c_str (), "complex column vector"); |
|
791 } |
|
792 |
|
793 return retval; |
|
794 } |
|
795 |
|
796 RowVector |
|
797 octave_value::row_vector_value (bool force_string_conv, |
|
798 bool force_vector_conversion) const |
|
799 { |
|
800 RowVector retval; |
|
801 |
|
802 Matrix m = matrix_value (force_string_conv); |
|
803 |
|
804 if (error_state) |
|
805 return retval; |
|
806 |
|
807 int nr = m.rows (); |
|
808 int nc = m.columns (); |
|
809 |
|
810 if (nr == 1) |
|
811 { |
|
812 retval.resize (nc); |
|
813 for (int i = 0; i < nc; i++) |
|
814 retval (i) = m (0, i); |
|
815 } |
|
816 else |
|
817 { |
3523
|
818 std::string tn = type_name (); |
3419
|
819 gripe_invalid_conversion (tn.c_str (), "real row vector"); |
|
820 } |
|
821 |
|
822 return retval; |
|
823 } |
|
824 |
|
825 ComplexRowVector |
|
826 octave_value::complex_row_vector_value (bool force_string_conv, |
|
827 bool force_vector_conversion) const |
|
828 { |
|
829 ComplexRowVector retval; |
|
830 |
|
831 ComplexMatrix m = complex_matrix_value (force_string_conv); |
|
832 |
|
833 if (error_state) |
|
834 return retval; |
|
835 |
|
836 int nr = m.rows (); |
|
837 int nc = m.columns (); |
|
838 |
|
839 if (nr == 1) |
|
840 { |
|
841 retval.resize (nc); |
|
842 for (int i = 0; i < nc; i++) |
|
843 retval (i) = m (0, i); |
|
844 } |
|
845 else |
|
846 { |
3523
|
847 std::string tn = type_name (); |
3419
|
848 gripe_invalid_conversion (tn.c_str (), "complex row vector"); |
|
849 } |
|
850 |
|
851 return retval; |
|
852 } |
|
853 |
|
854 // Sloppy... |
|
855 |
|
856 Array<double> |
2376
|
857 octave_value::vector_value (bool force_string_conv, |
|
858 bool force_vector_conversion) const |
|
859 { |
3419
|
860 Array<double> retval; |
2376
|
861 |
|
862 Matrix m = matrix_value (force_string_conv); |
|
863 |
|
864 if (error_state) |
|
865 return retval; |
|
866 |
|
867 int nr = m.rows (); |
|
868 int nc = m.columns (); |
|
869 |
|
870 if (nr == 1) |
|
871 { |
|
872 retval.resize (nc); |
|
873 for (int i = 0; i < nc; i++) |
|
874 retval (i) = m (0, i); |
|
875 } |
|
876 else if (nc == 1) |
|
877 { |
|
878 retval.resize (nr); |
|
879 for (int i = 0; i < nr; i++) |
|
880 retval (i) = m (i, 0); |
|
881 } |
|
882 else if (nr > 0 && nc > 0 |
|
883 && (Vdo_fortran_indexing || force_vector_conversion)) |
|
884 { |
|
885 retval.resize (nr * nc); |
|
886 int k = 0; |
|
887 for (int j = 0; j < nc; j++) |
|
888 for (int i = 0; i < nr; i++) |
|
889 retval (k++) = m (i, j); |
|
890 } |
|
891 else |
|
892 { |
3523
|
893 std::string tn = type_name (); |
2376
|
894 gripe_invalid_conversion (tn.c_str (), "real vector"); |
|
895 } |
|
896 |
|
897 return retval; |
|
898 } |
|
899 |
3419
|
900 Array<Complex> |
2376
|
901 octave_value::complex_vector_value (bool force_string_conv, |
|
902 bool force_vector_conversion) const |
|
903 { |
3419
|
904 Array<Complex> retval; |
2376
|
905 |
|
906 ComplexMatrix m = complex_matrix_value (force_string_conv); |
|
907 |
|
908 if (error_state) |
|
909 return retval; |
|
910 |
|
911 int nr = m.rows (); |
|
912 int nc = m.columns (); |
|
913 |
|
914 if (nr == 1) |
|
915 { |
|
916 retval.resize (nc); |
|
917 for (int i = 0; i < nc; i++) |
|
918 retval (i) = m (0, i); |
|
919 } |
|
920 else if (nc == 1) |
|
921 { |
|
922 retval.resize (nr); |
|
923 for (int i = 0; i < nr; i++) |
|
924 retval (i) = m (i, 0); |
|
925 } |
|
926 else if (nr > 0 && nc > 0 |
|
927 && (Vdo_fortran_indexing || force_vector_conversion)) |
|
928 { |
|
929 retval.resize (nr * nc); |
|
930 int k = 0; |
|
931 for (int j = 0; j < nc; j++) |
|
932 for (int i = 0; i < nr; i++) |
|
933 retval (k++) = m (i, j); |
|
934 } |
|
935 else |
|
936 { |
3523
|
937 std::string tn = type_name (); |
2376
|
938 gripe_invalid_conversion (tn.c_str (), "complex vector"); |
|
939 } |
|
940 |
|
941 return retval; |
|
942 } |
|
943 |
|
944 void |
3523
|
945 octave_value::print_with_name (std::ostream& output_buf, const std::string& name, |
2903
|
946 bool print_padding) const |
2376
|
947 { |
2903
|
948 bool pad_after = print_name_tag (output_buf, name); |
2376
|
949 |
|
950 print (output_buf); |
|
951 |
|
952 if (print_padding && pad_after) |
2903
|
953 newline (output_buf); |
2376
|
954 } |
|
955 |
|
956 static void |
3523
|
957 gripe_indexed_assignment (const std::string& tn1, const std::string& tn2) |
2413
|
958 { |
2903
|
959 error ("assignment of `%s' to indexed `%s' not implemented", |
2413
|
960 tn2.c_str (), tn1.c_str ()); |
|
961 } |
|
962 |
|
963 static void |
3933
|
964 gripe_assign_conversion_failed (const std::string& tn1, |
|
965 const std::string& tn2) |
2413
|
966 { |
2903
|
967 error ("type conversion for assignment of `%s' to indexed `%s' failed", |
2413
|
968 tn2.c_str (), tn1.c_str ()); |
|
969 } |
|
970 |
3933
|
971 octave_value |
|
972 octave_value::numeric_assign (const std::string type, |
|
973 const SLList<octave_value_list>& idx, |
2413
|
974 const octave_value& rhs) |
|
975 { |
3933
|
976 octave_value retval; |
2413
|
977 |
|
978 int t_lhs = type_id (); |
|
979 int t_rhs = rhs.type_id (); |
|
980 |
2880
|
981 assign_op_fcn f |
3933
|
982 = octave_value_typeinfo::lookup_assign_op (op_asn_eq, t_lhs, t_rhs); |
|
983 |
|
984 bool done = false; |
2413
|
985 |
|
986 if (f) |
|
987 { |
3933
|
988 f (*this, idx.front (), rhs.get_rep ()); |
2413
|
989 |
3933
|
990 done = (! error_state); |
2413
|
991 } |
3933
|
992 |
|
993 if (done) |
|
994 retval = octave_value (this, count + 1); |
3196
|
995 else |
|
996 { |
3933
|
997 int t_result |
|
998 = octave_value_typeinfo::lookup_pref_assign_conv (t_lhs, t_rhs); |
|
999 |
|
1000 if (t_result >= 0) |
|
1001 { |
|
1002 type_conv_fcn cf |
|
1003 = octave_value_typeinfo::lookup_widening_op (t_lhs, t_result); |
|
1004 |
|
1005 if (cf) |
|
1006 { |
|
1007 octave_value *tmp (cf (*this)); |
3196
|
1008 |
3933
|
1009 if (tmp) |
|
1010 { |
|
1011 retval = tmp->subsasgn (type, idx, rhs); |
|
1012 |
|
1013 done = (! error_state); |
|
1014 } |
|
1015 else |
|
1016 gripe_assign_conversion_failed (type_name (), |
|
1017 rhs.type_name ()); |
|
1018 } |
|
1019 else |
|
1020 gripe_indexed_assignment (type_name (), rhs.type_name ()); |
|
1021 } |
|
1022 |
|
1023 if (! (done || error_state)) |
3196
|
1024 { |
3933
|
1025 octave_value tmp_rhs; |
|
1026 type_conv_fcn cf_rhs = rhs.numeric_conversion_function (); |
|
1027 |
|
1028 if (cf_rhs) |
|
1029 { |
|
1030 octave_value *tmp = cf_rhs (rhs.get_rep ()); |
|
1031 |
|
1032 if (tmp) |
|
1033 tmp_rhs = octave_value (tmp); |
|
1034 else |
|
1035 { |
|
1036 gripe_assign_conversion_failed (type_name (), |
|
1037 rhs.type_name ()); |
|
1038 return octave_value (); |
|
1039 } |
|
1040 } |
|
1041 else |
|
1042 tmp_rhs = rhs; |
|
1043 |
|
1044 type_conv_fcn cf_this = numeric_conversion_function (); |
|
1045 |
|
1046 octave_value *tmp_lhs = this; |
3196
|
1047 |
3933
|
1048 if (cf_this) |
|
1049 { |
|
1050 octave_value *tmp = cf_this (*this); |
|
1051 |
|
1052 if (tmp) |
|
1053 tmp_lhs = tmp; |
|
1054 else |
|
1055 { |
|
1056 gripe_assign_conversion_failed (type_name (), |
|
1057 rhs.type_name ()); |
|
1058 return octave_value (); |
|
1059 } |
|
1060 } |
|
1061 |
|
1062 if (cf_this || cf_rhs) |
|
1063 { |
|
1064 retval = tmp_lhs->subsasgn (type, idx, tmp_rhs); |
|
1065 |
|
1066 done = (! error_state); |
|
1067 } |
|
1068 else |
|
1069 gripe_no_conversion (assign_op_as_string (op_asn_eq), |
|
1070 type_name (), rhs.type_name ()); |
3196
|
1071 } |
|
1072 } |
2413
|
1073 |
|
1074 return retval; |
|
1075 } |
|
1076 |
|
1077 static void |
3933
|
1078 gripe_binary_op (const std::string& on, const std::string& tn1, |
|
1079 const std::string& tn2) |
2376
|
1080 { |
2903
|
1081 error ("binary operator `%s' not implemented for `%s' by `%s' operations", |
2376
|
1082 on.c_str (), tn1.c_str (), tn2.c_str ()); |
|
1083 } |
|
1084 |
3203
|
1085 static void |
3523
|
1086 gripe_binary_op_conv (const std::string& on) |
3203
|
1087 { |
|
1088 error ("type conversion failed for binary operator `%s'", on.c_str ()); |
|
1089 } |
|
1090 |
2376
|
1091 octave_value |
3933
|
1092 do_binary_op (octave_value::binary_op op, |
|
1093 const octave_value& v1, const octave_value& v2) |
2376
|
1094 { |
|
1095 octave_value retval; |
|
1096 |
|
1097 int t1 = v1.type_id (); |
|
1098 int t2 = v2.type_id (); |
|
1099 |
2427
|
1100 binary_op_fcn f = octave_value_typeinfo::lookup_binary_op (op, t1, t2); |
2376
|
1101 |
|
1102 if (f) |
|
1103 retval = f (*v1.rep, *v2.rep); |
|
1104 else |
|
1105 { |
|
1106 octave_value tv1; |
2427
|
1107 type_conv_fcn cf1 = v1.numeric_conversion_function (); |
2376
|
1108 |
|
1109 if (cf1) |
|
1110 { |
3203
|
1111 octave_value *tmp = cf1 (*v1.rep); |
|
1112 |
|
1113 if (tmp) |
|
1114 { |
|
1115 tv1 = octave_value (tmp); |
|
1116 t1 = tv1.type_id (); |
|
1117 } |
|
1118 else |
|
1119 { |
|
1120 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); |
|
1121 return retval; |
|
1122 } |
2376
|
1123 } |
|
1124 else |
|
1125 tv1 = v1; |
|
1126 |
|
1127 octave_value tv2; |
2427
|
1128 type_conv_fcn cf2 = v2.numeric_conversion_function (); |
2376
|
1129 |
|
1130 if (cf2) |
|
1131 { |
3203
|
1132 octave_value *tmp = cf2 (*v2.rep); |
|
1133 |
|
1134 if (tmp) |
|
1135 { |
|
1136 tv2 = octave_value (tmp); |
|
1137 t2 = tv2.type_id (); |
|
1138 } |
|
1139 else |
|
1140 { |
|
1141 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); |
|
1142 return retval; |
|
1143 } |
2376
|
1144 } |
|
1145 else |
|
1146 tv2 = v2; |
|
1147 |
|
1148 if (cf1 || cf2) |
|
1149 { |
2427
|
1150 binary_op_fcn f |
2376
|
1151 = octave_value_typeinfo::lookup_binary_op (op, t1, t2); |
|
1152 |
|
1153 if (f) |
|
1154 retval = f (*tv1.rep, *tv2.rep); |
|
1155 else |
|
1156 gripe_binary_op (octave_value::binary_op_as_string (op), |
|
1157 v1.type_name (), v2.type_name ()); |
|
1158 } |
|
1159 else |
|
1160 gripe_binary_op (octave_value::binary_op_as_string (op), |
|
1161 v1.type_name (), v2.type_name ()); |
|
1162 } |
|
1163 |
|
1164 return retval; |
|
1165 } |
|
1166 |
3933
|
1167 void |
|
1168 octave_value::print_info (std::ostream& os, const std::string& prefix) const |
|
1169 { |
|
1170 os << prefix << "type_name: " << type_name () << "\n" |
|
1171 << prefix << "count: " << get_count () << "\n" |
|
1172 << prefix << "rep info: "; |
|
1173 |
|
1174 rep->print_info (os, prefix + " "); |
|
1175 } |
|
1176 |
3203
|
1177 static void |
3523
|
1178 gripe_unary_op (const std::string& on, const std::string& tn) |
3203
|
1179 { |
|
1180 error ("unary operator `%s' not implemented for `%s' operands", |
|
1181 on.c_str (), tn.c_str ()); |
|
1182 } |
|
1183 |
|
1184 static void |
3523
|
1185 gripe_unary_op_conv (const std::string& on) |
3203
|
1186 { |
|
1187 error ("type conversion failed for unary operator `%s'", on.c_str ()); |
|
1188 } |
|
1189 |
|
1190 octave_value |
|
1191 do_unary_op (octave_value::unary_op op, const octave_value& v) |
|
1192 { |
|
1193 octave_value retval; |
|
1194 |
|
1195 int t = v.type_id (); |
|
1196 |
|
1197 unary_op_fcn f = octave_value_typeinfo::lookup_unary_op (op, t); |
|
1198 |
|
1199 if (f) |
|
1200 retval = f (*v.rep); |
|
1201 else |
|
1202 { |
|
1203 octave_value tv; |
|
1204 type_conv_fcn cf = v.numeric_conversion_function (); |
|
1205 |
|
1206 if (cf) |
|
1207 { |
|
1208 octave_value *tmp = cf (*v.rep); |
|
1209 |
|
1210 if (tmp) |
|
1211 { |
|
1212 tv = octave_value (tmp); |
|
1213 t = tv.type_id (); |
|
1214 |
|
1215 unary_op_fcn f = octave_value_typeinfo::lookup_unary_op (op, t); |
|
1216 |
|
1217 if (f) |
|
1218 retval = f (*tv.rep); |
|
1219 else |
|
1220 gripe_unary_op (octave_value::unary_op_as_string (op), |
|
1221 v.type_name ()); |
|
1222 } |
|
1223 else |
|
1224 gripe_unary_op_conv (octave_value::unary_op_as_string (op)); |
|
1225 } |
|
1226 else |
|
1227 gripe_unary_op (octave_value::unary_op_as_string (op), |
|
1228 v.type_name ()); |
|
1229 } |
|
1230 |
|
1231 return retval; |
|
1232 } |
|
1233 |
|
1234 static void |
3933
|
1235 gripe_unary_op_conversion_failed (const std::string& op, |
|
1236 const std::string& tn) |
3203
|
1237 { |
|
1238 error ("operator %s: type conversion for `%s' failed", |
|
1239 op.c_str (), tn.c_str ()); |
|
1240 } |
|
1241 |
3933
|
1242 const octave_value& |
|
1243 octave_value::do_non_const_unary_op (unary_op op) |
3203
|
1244 { |
|
1245 octave_value retval; |
|
1246 |
|
1247 int t = type_id (); |
|
1248 |
|
1249 non_const_unary_op_fcn f |
|
1250 = octave_value_typeinfo::lookup_non_const_unary_op (op, t); |
|
1251 |
|
1252 if (f) |
|
1253 { |
|
1254 make_unique (); |
|
1255 |
|
1256 f (*rep); |
|
1257 } |
|
1258 else |
|
1259 { |
|
1260 type_conv_fcn cf = numeric_conversion_function (); |
|
1261 |
|
1262 if (cf) |
|
1263 { |
|
1264 octave_value *tmp = cf (*rep); |
|
1265 |
|
1266 if (tmp) |
|
1267 { |
|
1268 octave_value *old_rep = rep; |
|
1269 rep = tmp; |
|
1270 rep->count = 1; |
|
1271 |
|
1272 t = type_id (); |
|
1273 |
|
1274 f = octave_value_typeinfo::lookup_non_const_unary_op (op, t); |
|
1275 |
|
1276 if (f) |
|
1277 { |
|
1278 f (*rep); |
|
1279 |
|
1280 if (old_rep && --old_rep->count == 0) |
|
1281 delete old_rep; |
|
1282 } |
|
1283 else |
|
1284 { |
|
1285 if (old_rep) |
|
1286 { |
|
1287 if (--rep->count == 0) |
|
1288 delete rep; |
|
1289 |
|
1290 rep = old_rep; |
|
1291 } |
|
1292 |
|
1293 gripe_unary_op (octave_value::unary_op_as_string (op), |
|
1294 type_name ()); |
|
1295 } |
|
1296 } |
|
1297 else |
|
1298 gripe_unary_op_conversion_failed |
|
1299 (octave_value::unary_op_as_string (op), type_name ()); |
|
1300 } |
|
1301 else |
|
1302 gripe_unary_op (octave_value::unary_op_as_string (op), type_name ()); |
|
1303 } |
3933
|
1304 |
|
1305 return *this; |
3203
|
1306 } |
|
1307 |
3933
|
1308 #if 0 |
3205
|
1309 static void |
3933
|
1310 gripe_unary_op_failed_or_no_method (const std::string& on, |
|
1311 const std::string& tn) |
3205
|
1312 { |
|
1313 error ("operator %s: no method, or unable to evaluate for %s operand", |
|
1314 on.c_str (), tn.c_str ()); |
|
1315 } |
3933
|
1316 #endif |
3205
|
1317 |
|
1318 void |
3933
|
1319 octave_value::do_non_const_unary_op (unary_op op, const octave_value_list& idx) |
3205
|
1320 { |
3933
|
1321 abort (); |
|
1322 } |
|
1323 |
|
1324 octave_value |
|
1325 octave_value::do_non_const_unary_op (unary_op op, const std::string type, |
|
1326 const SLList<octave_value_list>& idx) |
|
1327 { |
|
1328 octave_value retval; |
|
1329 |
|
1330 if (idx.empty ()) |
|
1331 { |
|
1332 do_non_const_unary_op (op); |
3205
|
1333 |
3933
|
1334 retval = *this; |
|
1335 } |
|
1336 else |
|
1337 { |
|
1338 // XXX FIXME XXX -- only do the following stuff if we can't find a |
|
1339 // specific function to call to handle the op= operation for the |
|
1340 // types we have. |
3205
|
1341 |
3933
|
1342 assign_op assop = unary_op_to_assign_op (op); |
|
1343 |
|
1344 retval = assign (assop, type, idx, 1.0); |
|
1345 } |
|
1346 |
|
1347 return retval; |
3205
|
1348 } |
|
1349 |
2903
|
1350 // Current indentation. |
|
1351 int octave_value::curr_print_indent_level = 0; |
|
1352 |
3018
|
1353 // TRUE means we are at the beginning of a line. |
2903
|
1354 bool octave_value::beginning_of_line = true; |
|
1355 |
|
1356 // Each print() function should call this before printing anything. |
|
1357 // |
|
1358 // This doesn't need to be fast, but isn't there a better way? |
|
1359 |
|
1360 void |
3523
|
1361 octave_value::indent (std::ostream& os) const |
2903
|
1362 { |
|
1363 assert (curr_print_indent_level >= 0); |
|
1364 |
|
1365 if (beginning_of_line) |
|
1366 { |
|
1367 // XXX FIXME XXX -- do we need this? |
|
1368 // os << prefix; |
|
1369 |
|
1370 for (int i = 0; i < curr_print_indent_level; i++) |
|
1371 os << " "; |
|
1372 |
|
1373 beginning_of_line = false; |
|
1374 } |
|
1375 } |
|
1376 |
|
1377 // All print() functions should use this to print new lines. |
|
1378 |
|
1379 void |
3523
|
1380 octave_value::newline (std::ostream& os) const |
2903
|
1381 { |
|
1382 os << "\n"; |
|
1383 |
|
1384 beginning_of_line = true; |
|
1385 } |
|
1386 |
|
1387 // For ressetting print state. |
|
1388 |
|
1389 void |
|
1390 octave_value::reset (void) const |
|
1391 { |
|
1392 beginning_of_line = true; |
|
1393 curr_print_indent_level = 0; |
|
1394 } |
|
1395 |
3205
|
1396 octave_value::assign_op |
|
1397 octave_value::unary_op_to_assign_op (unary_op op) |
|
1398 { |
|
1399 assign_op binop = unknown_assign_op; |
|
1400 |
|
1401 switch (op) |
|
1402 { |
3533
|
1403 case op_incr: |
|
1404 binop = op_add_eq; |
3205
|
1405 break; |
|
1406 |
3533
|
1407 case op_decr: |
|
1408 binop = op_sub_eq; |
3205
|
1409 break; |
|
1410 |
|
1411 default: |
|
1412 { |
3523
|
1413 std::string on = unary_op_as_string (op); |
3205
|
1414 error ("operator %s: no assign operator found", on.c_str ()); |
|
1415 } |
|
1416 } |
|
1417 |
|
1418 return binop; |
|
1419 } |
|
1420 |
3204
|
1421 octave_value::binary_op |
|
1422 octave_value::op_eq_to_binary_op (assign_op op) |
|
1423 { |
|
1424 binary_op binop = unknown_binary_op; |
|
1425 |
|
1426 switch (op) |
|
1427 { |
3533
|
1428 case op_add_eq: |
|
1429 binop = op_add; |
3204
|
1430 break; |
|
1431 |
3533
|
1432 case op_sub_eq: |
|
1433 binop = op_sub; |
3204
|
1434 break; |
|
1435 |
3533
|
1436 case op_mul_eq: |
|
1437 binop = op_mul; |
3204
|
1438 break; |
|
1439 |
3533
|
1440 case op_div_eq: |
|
1441 binop = op_div; |
3204
|
1442 break; |
|
1443 |
3533
|
1444 case op_ldiv_eq: |
|
1445 binop = op_ldiv; |
3204
|
1446 break; |
|
1447 |
3533
|
1448 case op_lshift_eq: |
|
1449 binop = op_lshift; |
3204
|
1450 break; |
|
1451 |
3533
|
1452 case op_rshift_eq: |
|
1453 binop = op_rshift; |
3204
|
1454 break; |
|
1455 |
3533
|
1456 case op_el_mul_eq: |
|
1457 binop = op_el_mul; |
3204
|
1458 break; |
|
1459 |
3533
|
1460 case op_el_div_eq: |
|
1461 binop = op_el_div; |
3204
|
1462 break; |
|
1463 |
3533
|
1464 case op_el_ldiv_eq: |
|
1465 binop = op_el_ldiv; |
3204
|
1466 break; |
|
1467 |
3533
|
1468 case op_el_and_eq: |
|
1469 binop = op_el_and; |
3204
|
1470 break; |
|
1471 |
3533
|
1472 case op_el_or_eq: |
|
1473 binop = op_el_or; |
3204
|
1474 break; |
|
1475 |
|
1476 default: |
|
1477 { |
3523
|
1478 std::string on = assign_op_as_string (op); |
3204
|
1479 error ("operator %s: no binary operator found", on.c_str ()); |
|
1480 } |
|
1481 } |
|
1482 |
|
1483 return binop; |
|
1484 } |
|
1485 |
3933
|
1486 octave_value |
|
1487 octave_value::empty_conv (const std::string& type, const octave_value& rhs) |
|
1488 { |
|
1489 octave_value retval; |
|
1490 |
|
1491 if (type.length () > 0) |
|
1492 { |
|
1493 switch (type[0]) |
|
1494 { |
|
1495 case '(': |
|
1496 { |
|
1497 if (type.length () > 1 && type[1] == '.') |
|
1498 retval = Octave_map (); |
|
1499 else |
|
1500 retval = octave_value (rhs.empty_clone ()); |
|
1501 } |
|
1502 break; |
|
1503 |
|
1504 case '{': |
|
1505 retval = Cell (); |
|
1506 break; |
|
1507 |
|
1508 case '.': |
|
1509 retval = Octave_map (); |
|
1510 break; |
|
1511 |
|
1512 default: |
|
1513 panic_impossible (); |
|
1514 } |
|
1515 } |
|
1516 else |
|
1517 retval = octave_value (rhs.empty_clone ()); |
|
1518 |
|
1519 return retval; |
|
1520 } |
|
1521 |
2376
|
1522 void |
|
1523 install_types (void) |
|
1524 { |
|
1525 octave_base_value::register_type (); |
3928
|
1526 octave_cell::register_type (); |
2376
|
1527 octave_scalar::register_type (); |
|
1528 octave_complex::register_type (); |
|
1529 octave_matrix::register_type (); |
|
1530 octave_complex_matrix::register_type (); |
|
1531 octave_range::register_type (); |
2825
|
1532 octave_bool::register_type (); |
|
1533 octave_bool_matrix::register_type (); |
2376
|
1534 octave_char_matrix::register_type (); |
|
1535 octave_char_matrix_str::register_type (); |
|
1536 octave_struct::register_type (); |
2903
|
1537 octave_file::register_type (); |
2880
|
1538 octave_list::register_type (); |
3977
|
1539 octave_cs_list::register_type (); |
2376
|
1540 octave_all_va_args::register_type (); |
|
1541 octave_magic_colon::register_type (); |
2974
|
1542 octave_builtin::register_type (); |
|
1543 octave_mapper::register_type (); |
|
1544 octave_user_function::register_type (); |
2376
|
1545 } |
|
1546 |
|
1547 static int |
|
1548 do_fortran_indexing (void) |
|
1549 { |
|
1550 Vdo_fortran_indexing = check_preference ("do_fortran_indexing"); |
|
1551 |
|
1552 liboctave_dfi_flag = Vdo_fortran_indexing; |
|
1553 |
|
1554 return 0; |
|
1555 } |
|
1556 |
|
1557 static int |
|
1558 implicit_str_to_num_ok (void) |
|
1559 { |
|
1560 Vimplicit_str_to_num_ok = check_preference ("implicit_str_to_num_ok"); |
|
1561 |
|
1562 return 0; |
|
1563 } |
|
1564 |
|
1565 static int |
|
1566 ok_to_lose_imaginary_part (void) |
|
1567 { |
|
1568 Vok_to_lose_imaginary_part = check_preference ("ok_to_lose_imaginary_part"); |
|
1569 |
|
1570 return 0; |
|
1571 } |
|
1572 |
|
1573 static int |
|
1574 prefer_column_vectors (void) |
|
1575 { |
|
1576 Vprefer_column_vectors |
|
1577 = check_preference ("prefer_column_vectors"); |
|
1578 |
|
1579 liboctave_pcv_flag = Vprefer_column_vectors; |
|
1580 |
|
1581 return 0; |
|
1582 } |
|
1583 |
|
1584 static int |
|
1585 print_answer_id_name (void) |
|
1586 { |
|
1587 Vprint_answer_id_name = check_preference ("print_answer_id_name"); |
|
1588 |
|
1589 return 0; |
|
1590 } |
|
1591 |
|
1592 static int |
|
1593 propagate_empty_matrices (void) |
|
1594 { |
|
1595 Vpropagate_empty_matrices = check_preference ("propagate_empty_matrices"); |
|
1596 |
|
1597 return 0; |
|
1598 } |
|
1599 |
|
1600 static int |
|
1601 resize_on_range_error (void) |
|
1602 { |
|
1603 Vresize_on_range_error = check_preference ("resize_on_range_error"); |
|
1604 |
|
1605 liboctave_rre_flag = Vresize_on_range_error; |
|
1606 |
|
1607 return 0; |
|
1608 } |
|
1609 |
|
1610 static int |
|
1611 struct_levels_to_print (void) |
|
1612 { |
|
1613 double val; |
|
1614 if (builtin_real_scalar_variable ("struct_levels_to_print", val) |
|
1615 && ! xisnan (val)) |
|
1616 { |
|
1617 int ival = NINT (val); |
3961
|
1618 if (ival == val) |
2376
|
1619 { |
|
1620 Vstruct_levels_to_print = ival; |
|
1621 return 0; |
|
1622 } |
|
1623 } |
|
1624 gripe_invalid_value_specified ("struct_levels_to_print"); |
|
1625 return -1; |
|
1626 } |
|
1627 |
|
1628 static int |
|
1629 warn_divide_by_zero (void) |
|
1630 { |
|
1631 Vwarn_divide_by_zero = check_preference ("warn_divide_by_zero"); |
|
1632 |
|
1633 return 0; |
|
1634 } |
|
1635 |
|
1636 void |
2909
|
1637 symbols_of_ov (void) |
2376
|
1638 { |
3258
|
1639 DEFVAR (do_fortran_indexing, 0.0, do_fortran_indexing, |
3371
|
1640 "-*- texinfo -*-\n\ |
|
1641 @defvr {Built-in Variable} do_fortran_indexing\n\ |
|
1642 If the value of @code{do_fortran_indexing} is nonzero, Octave allows \n\ |
|
1643 you to select elements of a two-dimensional matrix using a single index\n\ |
|
1644 by treating the matrix as a single vector created from the columns of\n\ |
|
1645 the matrix. The default value is 0. \n\ |
|
1646 @end defvr"); |
2376
|
1647 |
3258
|
1648 DEFVAR (implicit_str_to_num_ok, 0.0, implicit_str_to_num_ok, |
3361
|
1649 "-*- texinfo -*-\n\ |
|
1650 @defvr {Built-in Variable} implicit_str_to_num_ok\n\ |
|
1651 If the value of @code{implicit_str_to_num_ok} is nonzero, implicit\n\ |
|
1652 conversions of strings to their numeric ASCII equivalents are allowed.\n\ |
|
1653 Otherwise, an error message is printed and control is returned to the\n\ |
|
1654 top level. The default value is 0.\n\ |
3363
|
1655 @end defvr"); |
2376
|
1656 |
3258
|
1657 DEFVAR (ok_to_lose_imaginary_part, "warn", ok_to_lose_imaginary_part, |
3370
|
1658 "-*- texinfo -*-\n\ |
|
1659 @defvr {Built-in Variable} ok_to_lose_imaginary_part\n\ |
|
1660 If the value of @code{ok_to_lose_imaginary_part} is nonzero, implicit\n\ |
|
1661 conversions of complex numbers to real numbers are allowed (for example,\n\ |
|
1662 by fsolve). If the value is @code{\"warn\"}, the conversion is allowed,\n\ |
|
1663 but a warning is printed. Otherwise, an error message is printed and\n\ |
|
1664 control is returned to the top level. The default value is\n\ |
|
1665 @code{\"warn\"}.\n\ |
|
1666 @end defvr"); |
2376
|
1667 |
3258
|
1668 DEFVAR (prefer_column_vectors, 1.0, prefer_column_vectors, |
3371
|
1669 "-*- texinfo -*-\n\ |
|
1670 @defvr {Built-in Variable} prefer_column_vectors\n\ |
|
1671 If @code{prefer_column_vectors} is nonzero, operations like\n\ |
|
1672 \n\ |
|
1673 @example\n\ |
|
1674 for i = 1:10\n\ |
|
1675 a (i) = i;\n\ |
|
1676 endfor\n\ |
|
1677 @end example\n\ |
|
1678 \n\ |
|
1679 @noindent\n\ |
|
1680 (for @code{a} previously undefined) produce column vectors. Otherwise, row\n\ |
|
1681 vectors are preferred. The default value is 1.\n\ |
|
1682 \n\ |
|
1683 If a variable is already defined to be a vector (a matrix with a single\n\ |
|
1684 row or column), the original orientation is respected, regardless of the\n\ |
|
1685 value of @code{prefer_column_vectors}.\n\ |
|
1686 @end defvr"); |
2376
|
1687 |
3258
|
1688 DEFVAR (print_answer_id_name, 1.0, print_answer_id_name, |
3372
|
1689 "-*- texinfo -*-\n\ |
|
1690 @defvr {Built-in Variable} print_answer_id_name\n\ |
|
1691 If the value of @code{print_answer_id_name} is nonzero, variable\n\ |
|
1692 names are printed along with the result. Otherwise, only the result\n\ |
|
1693 values are printed. The default value is 1.\n\ |
|
1694 @end defvr"); |
2376
|
1695 |
3258
|
1696 DEFVAR (propagate_empty_matrices, 1.0, propagate_empty_matrices, |
3321
|
1697 "-*- texinfo -*-\n\ |
|
1698 @defvr {Built-in Variable} propagate_empty_matrices\n\ |
|
1699 If the value of @code{propagate_empty_matrices} is nonzero,\n\ |
|
1700 functions like @code{inverse} and @code{svd} will return an empty matrix\n\ |
|
1701 if they are given one as an argument. The default value is 1.\n\ |
3333
|
1702 @end defvr"); |
2376
|
1703 |
3258
|
1704 DEFVAR (resize_on_range_error, 1.0, resize_on_range_error, |
3371
|
1705 "-*- texinfo -*-\n\ |
|
1706 @defvr {Built-in Variable} resize_on_range_error\n\ |
|
1707 If the value of @code{resize_on_range_error} is nonzero, expressions\n\ |
|
1708 like\n\ |
|
1709 \n\ |
|
1710 @example\n\ |
|
1711 for i = 1:10\n\ |
|
1712 a (i) = sqrt (i);\n\ |
|
1713 endfor\n\ |
|
1714 @end example\n\ |
|
1715 \n\ |
|
1716 @noindent\n\ |
|
1717 (for @code{a} previously undefined) result in the variable @code{a}\n\ |
|
1718 being resized to be just large enough to hold the new value. New\n\ |
|
1719 elements that have not been given a value are set to zero. If the value\n\ |
|
1720 of @code{resize_on_range_error} is 0, an error message is printed and\n\ |
|
1721 control is returned to the top level. The default value is 1.\n\ |
|
1722 @end defvr"); |
2376
|
1723 |
3258
|
1724 DEFVAR (struct_levels_to_print, 2.0, struct_levels_to_print, |
3361
|
1725 "-*- texinfo -*-\n\ |
|
1726 @defvr {Built-in Variable} struct_levels_to_print\n\ |
|
1727 You can tell Octave how many structure levels to display by setting the\n\ |
|
1728 built-in variable @code{struct_levels_to_print}. The default value is 2.\n\ |
3363
|
1729 @end defvr"); |
2376
|
1730 |
3258
|
1731 DEFVAR (warn_divide_by_zero, 1.0, warn_divide_by_zero, |
3371
|
1732 "-*- texinfo -*-\n\ |
|
1733 @defvr {Built-in Variable} warn_divide_by_zero\n\ |
|
1734 If the value of @code{warn_divide_by_zero} is nonzero, a warning\n\ |
|
1735 is issued when Octave encounters a division by zero. If the value is\n\ |
|
1736 0, the warning is omitted. The default value is 1.\n\ |
|
1737 @end defvr"); |
2376
|
1738 } |
|
1739 |
|
1740 /* |
|
1741 ;;; Local Variables: *** |
|
1742 ;;; mode: C++ *** |
|
1743 ;;; End: *** |
|
1744 */ |