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 |
4192
|
23 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
2376
|
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" |
4153
|
33 #include "quit.h" |
2376
|
34 |
2974
|
35 #include "oct-obj.h" |
2376
|
36 #include "ov.h" |
|
37 #include "ov-base.h" |
2825
|
38 #include "ov-bool.h" |
|
39 #include "ov-bool-mat.h" |
3351
|
40 #include "ov-cell.h" |
2376
|
41 #include "ov-scalar.h" |
|
42 #include "ov-re-mat.h" |
|
43 #include "ov-complex.h" |
|
44 #include "ov-cx-mat.h" |
|
45 #include "ov-ch-mat.h" |
|
46 #include "ov-str-mat.h" |
|
47 #include "ov-range.h" |
|
48 #include "ov-struct.h" |
2903
|
49 #include "ov-file.h" |
4643
|
50 #include "ov-streamoff.h" |
2880
|
51 #include "ov-list.h" |
3977
|
52 #include "ov-cs-list.h" |
2376
|
53 #include "ov-colon.h" |
|
54 #include "ov-va-args.h" |
2974
|
55 #include "ov-builtin.h" |
|
56 #include "ov-mapper.h" |
4649
|
57 #include "ov-dld-fcn.h" |
2974
|
58 #include "ov-usr-fcn.h" |
4342
|
59 #include "ov-fcn-handle.h" |
2376
|
60 #include "ov-typeinfo.h" |
|
61 |
|
62 #include "defun.h" |
2880
|
63 #include "error.h" |
2376
|
64 #include "gripes.h" |
|
65 #include "pager.h" |
4005
|
66 #include "parse.h" |
2376
|
67 #include "pr-output.h" |
|
68 #include "utils.h" |
|
69 #include "variables.h" |
|
70 |
2477
|
71 // We are likely to have a lot of octave_value objects to allocate, so |
|
72 // make the grow_size large. |
3219
|
73 DEFINE_OCTAVE_ALLOCATOR2(octave_value, 1024); |
2477
|
74 |
4005
|
75 // If TRUE, turn off printing of results in functions (as if a |
|
76 // semicolon has been appended to each statement). |
|
77 static bool Vsilent_functions; |
|
78 |
4455
|
79 // If TRUE, print a warning for assignments like |
2376
|
80 // |
|
81 // octave> A(1) = 3; A(2) = 5 |
|
82 // |
|
83 // for A already defined and a matrix type. |
4455
|
84 bool Vwarn_fortran_indexing; |
2376
|
85 |
4452
|
86 // Should we warn about conversions from complex to real? |
|
87 int Vwarn_imag_to_real; |
4257
|
88 |
4452
|
89 // Should we print a warning when converting `[97, 98, 99, "123"]' |
|
90 // to a character string? |
|
91 bool Vwarn_num_to_str; |
|
92 |
|
93 // If TRUE, warn for operations like |
2376
|
94 // |
|
95 // octave> 'abc' + 0 |
|
96 // 97 98 99 |
|
97 // |
4452
|
98 int Vwarn_str_to_num; |
2376
|
99 |
|
100 // If TRUE, print the name along with the value. |
|
101 bool Vprint_answer_id_name; |
|
102 |
|
103 // How many levels of structure elements should we print? |
|
104 int Vstruct_levels_to_print; |
|
105 |
|
106 // Allow divide by zero errors to be suppressed. |
|
107 bool Vwarn_divide_by_zero; |
|
108 |
4461
|
109 // If TRUE, print a warning when a matrix is resized by an indexed |
|
110 // assignment with indices outside the current bounds. |
|
111 bool Vwarn_resize_on_range_error; |
2948
|
112 |
2880
|
113 // XXX FIXME XXX |
|
114 |
2376
|
115 // Octave's value type. |
|
116 |
3536
|
117 std::string |
3203
|
118 octave_value::unary_op_as_string (unary_op op) |
|
119 { |
3523
|
120 std::string retval; |
3203
|
121 |
|
122 switch (op) |
|
123 { |
3533
|
124 case op_not: |
3203
|
125 retval = "!"; |
|
126 break; |
|
127 |
3533
|
128 case op_uminus: |
3203
|
129 retval = "-"; |
|
130 break; |
|
131 |
3533
|
132 case op_transpose: |
3203
|
133 retval = ".'"; |
|
134 break; |
|
135 |
3533
|
136 case op_hermitian: |
3203
|
137 retval = "'"; |
|
138 break; |
|
139 |
3533
|
140 case op_incr: |
3203
|
141 retval = "++"; |
|
142 break; |
|
143 |
3533
|
144 case op_decr: |
3203
|
145 retval = "--"; |
|
146 break; |
|
147 |
|
148 default: |
|
149 retval = "<unknown>"; |
|
150 } |
|
151 |
|
152 return retval; |
|
153 } |
|
154 |
3536
|
155 std::string |
2376
|
156 octave_value::binary_op_as_string (binary_op op) |
|
157 { |
3523
|
158 std::string retval; |
2376
|
159 |
|
160 switch (op) |
|
161 { |
3533
|
162 case op_add: |
2376
|
163 retval = "+"; |
|
164 break; |
|
165 |
3533
|
166 case op_sub: |
2376
|
167 retval = "-"; |
|
168 break; |
|
169 |
3533
|
170 case op_mul: |
2376
|
171 retval = "*"; |
|
172 break; |
|
173 |
3533
|
174 case op_div: |
2376
|
175 retval = "/"; |
|
176 break; |
|
177 |
3533
|
178 case op_pow: |
2376
|
179 retval = "^"; |
|
180 break; |
|
181 |
3533
|
182 case op_ldiv: |
2376
|
183 retval = "\\"; |
|
184 break; |
|
185 |
3533
|
186 case op_lshift: |
2903
|
187 retval = "<<"; |
|
188 break; |
|
189 |
3533
|
190 case op_rshift: |
2903
|
191 retval = ">>"; |
|
192 break; |
|
193 |
3533
|
194 case op_lt: |
2376
|
195 retval = "<"; |
|
196 break; |
|
197 |
3533
|
198 case op_le: |
2376
|
199 retval = "<="; |
|
200 break; |
|
201 |
3533
|
202 case op_eq: |
2376
|
203 retval = "=="; |
|
204 break; |
|
205 |
3533
|
206 case op_ge: |
2376
|
207 retval = ">="; |
|
208 break; |
|
209 |
3533
|
210 case op_gt: |
2376
|
211 retval = ">"; |
|
212 break; |
|
213 |
3533
|
214 case op_ne: |
2376
|
215 retval = "!="; |
|
216 break; |
|
217 |
3533
|
218 case op_el_mul: |
2376
|
219 retval = ".*"; |
|
220 break; |
|
221 |
3533
|
222 case op_el_div: |
2376
|
223 retval = "./"; |
|
224 break; |
|
225 |
3533
|
226 case op_el_pow: |
2376
|
227 retval = ".^"; |
|
228 break; |
|
229 |
3533
|
230 case op_el_ldiv: |
2376
|
231 retval = ".\\"; |
|
232 break; |
|
233 |
3533
|
234 case op_el_and: |
2376
|
235 retval = "&"; |
|
236 break; |
|
237 |
3533
|
238 case op_el_or: |
2376
|
239 retval = "|"; |
|
240 break; |
|
241 |
3533
|
242 case op_struct_ref: |
2376
|
243 retval = "."; |
|
244 break; |
|
245 |
|
246 default: |
|
247 retval = "<unknown>"; |
|
248 } |
|
249 |
|
250 return retval; |
|
251 } |
|
252 |
3536
|
253 std::string |
2880
|
254 octave_value::assign_op_as_string (assign_op op) |
|
255 { |
3523
|
256 std::string retval; |
2880
|
257 |
|
258 switch (op) |
|
259 { |
3533
|
260 case op_asn_eq: |
2880
|
261 retval = "="; |
|
262 break; |
|
263 |
3533
|
264 case op_add_eq: |
2880
|
265 retval = "+="; |
|
266 break; |
|
267 |
3533
|
268 case op_sub_eq: |
2880
|
269 retval = "-="; |
|
270 break; |
|
271 |
3533
|
272 case op_mul_eq: |
2880
|
273 retval = "*="; |
|
274 break; |
|
275 |
3533
|
276 case op_div_eq: |
2880
|
277 retval = "/="; |
|
278 break; |
|
279 |
3533
|
280 case op_ldiv_eq: |
3204
|
281 retval = "\\="; |
|
282 break; |
|
283 |
4018
|
284 case op_pow_eq: |
|
285 retval = "^="; |
|
286 break; |
|
287 |
3533
|
288 case op_lshift_eq: |
2903
|
289 retval = "<<="; |
|
290 break; |
|
291 |
3533
|
292 case op_rshift_eq: |
2903
|
293 retval = ">>="; |
|
294 break; |
|
295 |
3533
|
296 case op_el_mul_eq: |
2880
|
297 retval = ".*="; |
|
298 break; |
|
299 |
3533
|
300 case op_el_div_eq: |
2880
|
301 retval = "./="; |
|
302 break; |
|
303 |
3533
|
304 case op_el_ldiv_eq: |
3204
|
305 retval = ".\\="; |
|
306 break; |
|
307 |
4018
|
308 case op_el_pow_eq: |
|
309 retval = ".^="; |
|
310 break; |
|
311 |
3533
|
312 case op_el_and_eq: |
2880
|
313 retval = "&="; |
|
314 break; |
|
315 |
3533
|
316 case op_el_or_eq: |
2880
|
317 retval = "|="; |
|
318 break; |
|
319 |
|
320 default: |
|
321 retval = "<unknown>"; |
|
322 } |
|
323 |
|
324 return retval; |
|
325 } |
|
326 |
4513
|
327 octave_value * |
|
328 octave_value::nil_rep (void) const |
|
329 { |
|
330 static octave_base_value *nr = new octave_base_value (); |
|
331 return nr; |
|
332 } |
|
333 |
2376
|
334 octave_value::octave_value (void) |
4513
|
335 : rep (nil_rep ()) |
2825
|
336 { |
4513
|
337 rep->count++; |
2825
|
338 } |
2376
|
339 |
4254
|
340 octave_value::octave_value (short int i) |
|
341 : rep (new octave_scalar (i)) |
|
342 { |
|
343 rep->count = 1; |
|
344 } |
|
345 |
|
346 octave_value::octave_value (unsigned short int i) |
|
347 : rep (new octave_scalar (i)) |
|
348 { |
|
349 rep->count = 1; |
|
350 } |
|
351 |
4233
|
352 octave_value::octave_value (int i) |
|
353 : rep (new octave_scalar (i)) |
|
354 { |
|
355 rep->count = 1; |
|
356 } |
|
357 |
4254
|
358 octave_value::octave_value (unsigned int i) |
|
359 : rep (new octave_scalar (i)) |
|
360 { |
|
361 rep->count = 1; |
|
362 } |
|
363 |
|
364 octave_value::octave_value (long int i) |
|
365 : rep (new octave_scalar (i)) |
|
366 { |
|
367 rep->count = 1; |
|
368 } |
|
369 |
|
370 octave_value::octave_value (unsigned long int i) |
|
371 : rep (new octave_scalar (i)) |
|
372 { |
|
373 rep->count = 1; |
|
374 } |
|
375 |
4353
|
376 #if defined (HAVE_LONG_LONG_INT) |
|
377 octave_value::octave_value (long long int i) |
|
378 : rep (new octave_scalar (i)) |
|
379 { |
|
380 rep->count = 1; |
|
381 } |
|
382 #endif |
|
383 |
4355
|
384 #if defined (HAVE_UNSIGNED_LONG_LONG_INT) |
4353
|
385 octave_value::octave_value (unsigned long long int i) |
|
386 : rep (new octave_scalar (i)) |
|
387 { |
|
388 rep->count = 1; |
|
389 } |
|
390 #endif |
|
391 |
4254
|
392 octave_value::octave_value (octave_time t) |
|
393 : rep (new octave_scalar (t)) |
|
394 { |
|
395 rep->count = 1; |
|
396 } |
|
397 |
2376
|
398 octave_value::octave_value (double d) |
2825
|
399 : rep (new octave_scalar (d)) |
|
400 { |
|
401 rep->count = 1; |
|
402 } |
2376
|
403 |
4587
|
404 octave_value::octave_value (const Cell& c, bool is_csl) |
4513
|
405 : rep (0) |
3351
|
406 { |
4587
|
407 if (is_csl) |
4513
|
408 rep = new octave_cs_list (c); |
|
409 else |
|
410 rep = new octave_cell (c); |
|
411 |
3351
|
412 rep->count = 1; |
|
413 } |
|
414 |
4587
|
415 octave_value::octave_value (const ArrayN<octave_value>& a, bool is_csl) |
4532
|
416 : rep (0) |
|
417 { |
|
418 Cell c (a); |
|
419 |
4587
|
420 if (is_csl) |
4532
|
421 rep = new octave_cs_list (c); |
|
422 else |
|
423 rep = new octave_cell (c); |
|
424 |
|
425 rep->count = 1; |
|
426 } |
|
427 |
2376
|
428 octave_value::octave_value (const Matrix& m) |
2423
|
429 : rep (new octave_matrix (m)) |
|
430 { |
|
431 rep->count = 1; |
|
432 maybe_mutate (); |
|
433 } |
2376
|
434 |
4507
|
435 octave_value::octave_value (const NDArray& a) |
4513
|
436 : rep (new octave_matrix (a)) |
4478
|
437 { |
|
438 rep->count = 1; |
|
439 maybe_mutate (); |
|
440 } |
|
441 |
2376
|
442 octave_value::octave_value (const DiagMatrix& d) |
2423
|
443 : rep (new octave_matrix (d)) |
|
444 { |
|
445 rep->count = 1; |
|
446 maybe_mutate (); |
|
447 } |
2376
|
448 |
3418
|
449 octave_value::octave_value (const RowVector& v) |
|
450 : rep (new octave_matrix (v)) |
2423
|
451 { |
|
452 rep->count = 1; |
|
453 maybe_mutate (); |
|
454 } |
2376
|
455 |
3418
|
456 octave_value::octave_value (const ColumnVector& v) |
|
457 : rep (new octave_matrix (v)) |
2423
|
458 { |
|
459 rep->count = 1; |
|
460 maybe_mutate (); |
|
461 } |
2376
|
462 |
|
463 octave_value::octave_value (const Complex& C) |
2423
|
464 : rep (new octave_complex (C)) |
|
465 { |
|
466 rep->count = 1; |
|
467 maybe_mutate (); |
|
468 } |
2376
|
469 |
|
470 octave_value::octave_value (const ComplexMatrix& m) |
2423
|
471 : rep (new octave_complex_matrix (m)) |
|
472 { |
|
473 rep->count = 1; |
|
474 maybe_mutate (); |
|
475 } |
2376
|
476 |
4513
|
477 octave_value::octave_value (const ComplexNDArray& a) |
|
478 : rep (new octave_complex_matrix (a)) |
4478
|
479 { |
|
480 rep->count = 1; |
|
481 maybe_mutate (); |
|
482 } |
|
483 |
2376
|
484 octave_value::octave_value (const ComplexDiagMatrix& d) |
2423
|
485 : rep (new octave_complex_matrix (d)) |
|
486 { |
|
487 rep->count = 1; |
|
488 maybe_mutate (); |
|
489 } |
2376
|
490 |
3418
|
491 octave_value::octave_value (const ComplexRowVector& v) |
|
492 : rep (new octave_complex_matrix (v)) |
2423
|
493 { |
|
494 rep->count = 1; |
|
495 maybe_mutate (); |
|
496 } |
2376
|
497 |
3418
|
498 octave_value::octave_value (const ComplexColumnVector& v) |
|
499 : rep (new octave_complex_matrix (v)) |
2423
|
500 { |
|
501 rep->count = 1; |
|
502 maybe_mutate (); |
|
503 } |
2376
|
504 |
2825
|
505 octave_value::octave_value (bool b) |
|
506 : rep (new octave_bool (b)) |
|
507 { |
|
508 rep->count = 1; |
|
509 } |
|
510 |
|
511 octave_value::octave_value (const boolMatrix& bm) |
|
512 : rep (new octave_bool_matrix (bm)) |
|
513 { |
|
514 rep->count = 1; |
|
515 maybe_mutate (); |
|
516 } |
|
517 |
4513
|
518 octave_value::octave_value (const boolNDArray& bnda) |
|
519 : rep (new octave_bool_matrix (bnda)) |
|
520 { |
|
521 rep->count = 1; |
|
522 maybe_mutate (); |
|
523 } |
|
524 |
3189
|
525 octave_value::octave_value (char c) |
|
526 : rep (new octave_char_matrix_str (c)) |
|
527 { |
|
528 rep->count = 1; |
|
529 maybe_mutate (); |
|
530 } |
|
531 |
2376
|
532 octave_value::octave_value (const char *s) |
2423
|
533 : rep (new octave_char_matrix_str (s)) |
|
534 { |
|
535 rep->count = 1; |
|
536 maybe_mutate (); |
|
537 } |
2376
|
538 |
3523
|
539 octave_value::octave_value (const std::string& s) |
2423
|
540 : rep (new octave_char_matrix_str (s)) |
|
541 { |
|
542 rep->count = 1; |
|
543 maybe_mutate (); |
|
544 } |
2376
|
545 |
|
546 octave_value::octave_value (const string_vector& s) |
2423
|
547 : rep (new octave_char_matrix_str (s)) |
|
548 { |
|
549 rep->count = 1; |
|
550 maybe_mutate (); |
|
551 } |
2376
|
552 |
4587
|
553 octave_value::octave_value (const charMatrix& chm, bool is_str) |
|
554 : rep (is_str |
4513
|
555 ? new octave_char_matrix_str (chm) |
|
556 : new octave_char_matrix (chm)) |
2409
|
557 { |
4513
|
558 rep->count = 1; |
|
559 maybe_mutate (); |
|
560 } |
2376
|
561 |
4587
|
562 octave_value::octave_value (const charNDArray& chm, bool is_str) |
|
563 : rep (is_str |
4513
|
564 ? new octave_char_matrix_str (chm) |
|
565 : new octave_char_matrix (chm)) |
|
566 { |
2409
|
567 rep->count = 1; |
2423
|
568 maybe_mutate (); |
2409
|
569 } |
2376
|
570 |
|
571 octave_value::octave_value (double base, double limit, double inc) |
2423
|
572 : rep (new octave_range (base, limit, inc)) |
|
573 { |
|
574 rep->count = 1; |
|
575 maybe_mutate (); |
|
576 } |
2376
|
577 |
|
578 octave_value::octave_value (const Range& r) |
2423
|
579 : rep (new octave_range (r)) |
|
580 { |
|
581 rep->count = 1; |
|
582 maybe_mutate (); |
|
583 } |
2376
|
584 |
|
585 octave_value::octave_value (const Octave_map& m) |
2825
|
586 : rep (new octave_struct (m)) |
|
587 { |
|
588 rep->count = 1; |
2880
|
589 } |
|
590 |
3340
|
591 octave_value::octave_value (const octave_stream& s, int n) |
2903
|
592 : rep (new octave_file (s, n)) |
|
593 { |
|
594 rep->count = 1; |
|
595 } |
|
596 |
4643
|
597 octave_value::octave_value (const streamoff_array& off) |
|
598 : rep (new octave_streamoff (off)) |
|
599 { |
|
600 rep->count = 1; |
|
601 } |
|
602 |
2974
|
603 octave_value::octave_value (octave_function *f) |
|
604 : rep (f) |
|
605 { |
|
606 rep->count = 1; |
|
607 } |
|
608 |
4654
|
609 octave_value::octave_value (const fcn_handle_array& fha) |
|
610 : rep (new octave_fcn_handle (fha)) |
|
611 { |
|
612 rep->count = 1; |
|
613 } |
|
614 |
|
615 octave_value::octave_value (octave_function *f, const std::string& nm) |
|
616 : rep (new octave_fcn_handle (f, nm)) |
4342
|
617 { |
|
618 rep->count = 1; |
|
619 } |
|
620 |
4587
|
621 octave_value::octave_value (const octave_value_list& l, bool is_csl) |
4591
|
622 : rep (0) |
2880
|
623 { |
4591
|
624 if (is_csl) |
|
625 rep = new octave_cs_list (l); |
|
626 else |
|
627 rep = new octave_list (l); |
|
628 |
2880
|
629 rep->count = 1; |
|
630 } |
2376
|
631 |
|
632 octave_value::octave_value (octave_value::magic_colon) |
2825
|
633 : rep (new octave_magic_colon ()) |
|
634 { |
|
635 rep->count = 1; |
|
636 } |
2376
|
637 |
|
638 octave_value::octave_value (octave_value::all_va_args) |
2825
|
639 : rep (new octave_all_va_args ()) |
|
640 { |
|
641 rep->count = 1; |
|
642 } |
2376
|
643 |
4276
|
644 octave_value::octave_value (octave_value *new_rep, int cnt) |
2825
|
645 : rep (new_rep) |
|
646 { |
4276
|
647 rep->count = cnt; |
2825
|
648 } |
2376
|
649 |
|
650 octave_value::~octave_value (void) |
|
651 { |
|
652 #if defined (MDEBUG) |
3531
|
653 std::cerr << "~octave_value: rep: " << rep |
|
654 << " rep->count: " << rep->count << "\n"; |
2376
|
655 #endif |
|
656 |
|
657 if (rep && --rep->count == 0) |
|
658 { |
|
659 delete rep; |
|
660 rep = 0; |
|
661 } |
|
662 } |
|
663 |
2880
|
664 octave_value * |
3933
|
665 octave_value::clone (void) const |
2880
|
666 { |
|
667 panic_impossible (); |
3546
|
668 return 0; |
2880
|
669 } |
|
670 |
2409
|
671 void |
|
672 octave_value::maybe_mutate (void) |
|
673 { |
2410
|
674 octave_value *tmp = rep->try_narrowing_conversion (); |
2409
|
675 |
|
676 if (tmp && tmp != rep) |
|
677 { |
|
678 if (--rep->count == 0) |
|
679 delete rep; |
|
680 |
|
681 rep = tmp; |
|
682 rep->count = 1; |
|
683 } |
|
684 } |
|
685 |
4247
|
686 octave_value |
4271
|
687 octave_value::single_subsref (const std::string& type, |
|
688 const octave_value_list& idx) |
4247
|
689 { |
|
690 std::list<octave_value_list> i; |
|
691 |
|
692 i.push_back (idx); |
|
693 |
|
694 return rep->subsref (type, i); |
|
695 } |
|
696 |
2974
|
697 octave_value_list |
4247
|
698 octave_value::subsref (const std::string& type, |
4219
|
699 const std::list<octave_value_list>& idx, int nargout) |
3933
|
700 { |
|
701 if (is_constant ()) |
|
702 return rep->subsref (type, idx); |
|
703 else |
|
704 return rep->subsref (type, idx, nargout); |
|
705 } |
|
706 |
|
707 octave_value |
4247
|
708 octave_value::next_subsref (const std::string& type, |
4219
|
709 const std::list<octave_value_list>& idx, |
4233
|
710 size_t skip) |
3933
|
711 { |
4582
|
712 if (! error_state && idx.size () > skip) |
3933
|
713 { |
4219
|
714 std::list<octave_value_list> new_idx (idx); |
4233
|
715 for (size_t i = 0; i < skip; i++) |
4219
|
716 new_idx.erase (new_idx.begin ()); |
3933
|
717 return subsref (type.substr (skip), new_idx); |
|
718 } |
|
719 else |
|
720 return *this; |
|
721 } |
|
722 |
|
723 octave_value_list |
3544
|
724 octave_value::do_multi_index_op (int nargout, const octave_value_list& idx) |
2974
|
725 { |
3544
|
726 return rep->do_multi_index_op (nargout, idx); |
2974
|
727 } |
|
728 |
2376
|
729 static void |
3933
|
730 gripe_no_conversion (const std::string& on, const std::string& tn1, |
|
731 const std::string& tn2) |
2376
|
732 { |
3203
|
733 error ("operator %s: no conversion for assignment of `%s' to indexed `%s'", |
|
734 on.c_str (), tn2.c_str (), tn1.c_str ()); |
2376
|
735 } |
|
736 |
3933
|
737 #if 0 |
3204
|
738 static void |
3933
|
739 gripe_assign_failed (const std::string& on, const std::string& tn1, |
|
740 const std::string& tn2) |
3204
|
741 { |
|
742 error ("assignment failed for `%s %s %s'", |
|
743 tn1.c_str (), on.c_str (), tn2.c_str ()); |
|
744 } |
3933
|
745 #endif |
3204
|
746 |
|
747 static void |
3933
|
748 gripe_assign_failed_or_no_method (const std::string& on, |
|
749 const std::string& tn1, |
3523
|
750 const std::string& tn2) |
3204
|
751 { |
|
752 error ("assignment failed, or no method for `%s %s %s'", |
|
753 tn1.c_str (), on.c_str (), tn2.c_str ()); |
|
754 } |
|
755 |
3933
|
756 octave_value |
4247
|
757 octave_value::subsasgn (const std::string& type, |
4219
|
758 const std::list<octave_value_list>& idx, |
3933
|
759 const octave_value& rhs) |
|
760 { |
|
761 return rep->subsasgn (type, idx, rhs); |
|
762 } |
|
763 |
|
764 octave_value |
4247
|
765 octave_value::assign (assign_op op, const std::string& type, |
4219
|
766 const std::list<octave_value_list>& idx, |
3933
|
767 const octave_value& rhs) |
|
768 { |
|
769 octave_value retval; |
|
770 |
|
771 make_unique (); |
|
772 |
|
773 octave_value t_rhs = rhs; |
|
774 |
|
775 if (op != op_asn_eq) |
|
776 { |
|
777 // XXX FIXME XXX -- only do the following stuff if we can't find |
|
778 // a specific function to call to handle the op= operation for |
|
779 // the types we have. |
|
780 |
|
781 octave_value t = subsref (type, idx); |
|
782 |
|
783 if (! error_state) |
|
784 { |
|
785 binary_op binop = op_eq_to_binary_op (op); |
|
786 |
|
787 if (! error_state) |
|
788 t_rhs = do_binary_op (binop, t, rhs); |
|
789 } |
|
790 } |
|
791 |
|
792 if (! error_state) |
|
793 { |
|
794 if (type[0] == '.' && ! is_map ()) |
|
795 { |
|
796 octave_value tmp = Octave_map (); |
|
797 retval = tmp.subsasgn (type, idx, t_rhs); |
|
798 } |
|
799 else |
|
800 retval = subsasgn (type, idx, t_rhs); |
|
801 } |
|
802 |
|
803 if (error_state) |
|
804 gripe_assign_failed_or_no_method (assign_op_as_string (op), |
|
805 type_name (), rhs.type_name ()); |
|
806 |
|
807 return retval; |
|
808 } |
|
809 |
|
810 const octave_value& |
3203
|
811 octave_value::assign (assign_op op, const octave_value& rhs) |
2880
|
812 { |
3533
|
813 if (op == op_asn_eq) |
3203
|
814 operator = (rhs); |
|
815 else |
|
816 { |
3204
|
817 // XXX FIXME XXX -- only do the following stuff if we can't find |
|
818 // a specific function to call to handle the op= operation for |
|
819 // the types we have. |
|
820 |
|
821 binary_op binop = op_eq_to_binary_op (op); |
|
822 |
|
823 if (! error_state) |
|
824 { |
|
825 octave_value t = do_binary_op (binop, *this, rhs); |
|
826 |
|
827 if (! error_state) |
|
828 operator = (t); |
|
829 } |
|
830 |
|
831 if (error_state) |
|
832 gripe_assign_failed_or_no_method (assign_op_as_string (op), |
|
833 type_name (), rhs.type_name ()); |
|
834 } |
|
835 |
3933
|
836 return *this; |
2376
|
837 } |
|
838 |
4563
|
839 int |
|
840 octave_value::rows (void) const |
|
841 { |
|
842 dim_vector dv = dims (); |
|
843 |
|
844 return (dv.length () > 0) ? dv(0) : -1; |
|
845 } |
|
846 |
|
847 int |
|
848 octave_value::columns (void) const |
|
849 { |
|
850 dim_vector dv = dims (); |
|
851 |
|
852 return (dv.length () > 1) ? dv(1) : -1; |
|
853 } |
|
854 |
|
855 int |
|
856 octave_value::length (void) const |
|
857 { |
|
858 int retval = 0; |
|
859 |
|
860 dim_vector dv = dims (); |
4584
|
861 |
4563
|
862 for (int i = 0; i < dv.length (); i++) |
|
863 { |
|
864 if (dv(i) < 0) |
|
865 { |
|
866 retval = -1; |
|
867 break; |
|
868 } |
|
869 |
4584
|
870 if (dv(i) == 0) |
|
871 { |
|
872 retval = 0; |
|
873 break; |
|
874 } |
|
875 |
4563
|
876 if (dv(i) > retval) |
|
877 retval = dv(i); |
|
878 } |
|
879 |
|
880 return retval; |
|
881 } |
|
882 |
|
883 int |
|
884 octave_value::ndims (void) const |
|
885 { |
|
886 dim_vector dv = dims (); |
|
887 |
|
888 int n_dims = dv.length (); |
|
889 |
|
890 // Remove trailing singleton dimensions. |
|
891 |
|
892 for (int i = n_dims; i > 2; i--) |
|
893 { |
|
894 if (dv(i-1) == 1) |
|
895 n_dims--; |
|
896 else |
|
897 break; |
|
898 } |
|
899 |
|
900 // The result is always >= 2. |
|
901 |
|
902 if (n_dims < 2) |
|
903 n_dims = 2; |
|
904 |
|
905 return n_dims; |
|
906 } |
|
907 |
|
908 int |
|
909 octave_value::numel (void) const |
|
910 { |
|
911 dim_vector dv = dims (); |
|
912 |
4567
|
913 return dv.numel (); |
4563
|
914 } |
|
915 |
3351
|
916 Cell |
|
917 octave_value::cell_value (void) const |
|
918 { |
|
919 return rep->cell_value (); |
|
920 } |
|
921 |
2376
|
922 Octave_map |
|
923 octave_value::map_value (void) const |
|
924 { |
|
925 return rep->map_value (); |
|
926 } |
|
927 |
3340
|
928 octave_stream |
2903
|
929 octave_value::stream_value (void) const |
|
930 { |
|
931 return rep->stream_value (); |
|
932 } |
|
933 |
|
934 int |
|
935 octave_value::stream_number (void) const |
|
936 { |
|
937 return rep->stream_number (); |
|
938 } |
|
939 |
4645
|
940 std::streamoff |
4643
|
941 octave_value::streamoff_value (void) const |
|
942 { |
|
943 return rep->streamoff_value (); |
|
944 } |
|
945 |
4645
|
946 streamoff_array |
|
947 octave_value::streamoff_array_value (void) const |
|
948 { |
|
949 return rep->streamoff_array_value (); |
|
950 } |
|
951 |
2974
|
952 octave_function * |
|
953 octave_value::function_value (bool silent) |
|
954 { |
|
955 return rep->function_value (silent); |
|
956 } |
|
957 |
4700
|
958 octave_user_function * |
|
959 octave_value::user_function_value (bool silent) |
|
960 { |
|
961 return rep->user_function_value (silent); |
|
962 } |
|
963 |
4346
|
964 octave_fcn_handle * |
4343
|
965 octave_value::fcn_handle_value (bool silent) |
|
966 { |
|
967 return rep->fcn_handle_value (silent); |
|
968 } |
|
969 |
2880
|
970 octave_value_list |
|
971 octave_value::list_value (void) const |
|
972 { |
|
973 return rep->list_value (); |
|
974 } |
|
975 |
2376
|
976 ColumnVector |
3419
|
977 octave_value::column_vector_value (bool force_string_conv, |
4661
|
978 bool /* frc_vec_conv */) const |
3419
|
979 { |
|
980 ColumnVector retval; |
|
981 |
|
982 Matrix m = matrix_value (force_string_conv); |
|
983 |
|
984 if (error_state) |
|
985 return retval; |
|
986 |
|
987 int nr = m.rows (); |
|
988 int nc = m.columns (); |
|
989 |
|
990 if (nc == 1) |
|
991 { |
|
992 retval.resize (nr); |
|
993 for (int i = 0; i < nr; i++) |
|
994 retval (i) = m (i, 0); |
|
995 } |
|
996 else |
|
997 { |
3523
|
998 std::string tn = type_name (); |
3419
|
999 gripe_invalid_conversion (tn.c_str (), "real column vector"); |
|
1000 } |
|
1001 |
|
1002 return retval; |
|
1003 } |
|
1004 |
|
1005 ComplexColumnVector |
|
1006 octave_value::complex_column_vector_value (bool force_string_conv, |
4661
|
1007 bool /* frc_vec_conv */) const |
3419
|
1008 { |
|
1009 ComplexColumnVector retval; |
|
1010 |
|
1011 ComplexMatrix m = complex_matrix_value (force_string_conv); |
|
1012 |
|
1013 if (error_state) |
|
1014 return retval; |
|
1015 |
|
1016 int nr = m.rows (); |
|
1017 int nc = m.columns (); |
|
1018 |
|
1019 if (nc == 1) |
|
1020 { |
3465
|
1021 retval.resize (nr); |
|
1022 for (int i = 0; i < nr; i++) |
3419
|
1023 retval (i) = m (i, 0); |
|
1024 } |
|
1025 else |
|
1026 { |
3523
|
1027 std::string tn = type_name (); |
3419
|
1028 gripe_invalid_conversion (tn.c_str (), "complex column vector"); |
|
1029 } |
|
1030 |
|
1031 return retval; |
|
1032 } |
|
1033 |
|
1034 RowVector |
|
1035 octave_value::row_vector_value (bool force_string_conv, |
4661
|
1036 bool /* frc_vec_conv */) const |
3419
|
1037 { |
|
1038 RowVector retval; |
|
1039 |
|
1040 Matrix m = matrix_value (force_string_conv); |
|
1041 |
|
1042 if (error_state) |
|
1043 return retval; |
|
1044 |
|
1045 int nr = m.rows (); |
|
1046 int nc = m.columns (); |
|
1047 |
|
1048 if (nr == 1) |
|
1049 { |
|
1050 retval.resize (nc); |
|
1051 for (int i = 0; i < nc; i++) |
|
1052 retval (i) = m (0, i); |
|
1053 } |
|
1054 else |
|
1055 { |
3523
|
1056 std::string tn = type_name (); |
3419
|
1057 gripe_invalid_conversion (tn.c_str (), "real row vector"); |
|
1058 } |
|
1059 |
|
1060 return retval; |
|
1061 } |
|
1062 |
|
1063 ComplexRowVector |
|
1064 octave_value::complex_row_vector_value (bool force_string_conv, |
4661
|
1065 bool /* frc_vec_conv */) const |
3419
|
1066 { |
|
1067 ComplexRowVector retval; |
|
1068 |
|
1069 ComplexMatrix m = complex_matrix_value (force_string_conv); |
|
1070 |
|
1071 if (error_state) |
|
1072 return retval; |
|
1073 |
|
1074 int nr = m.rows (); |
|
1075 int nc = m.columns (); |
|
1076 |
|
1077 if (nr == 1) |
|
1078 { |
|
1079 retval.resize (nc); |
|
1080 for (int i = 0; i < nc; i++) |
|
1081 retval (i) = m (0, i); |
|
1082 } |
|
1083 else |
|
1084 { |
3523
|
1085 std::string tn = type_name (); |
3419
|
1086 gripe_invalid_conversion (tn.c_str (), "complex row vector"); |
|
1087 } |
|
1088 |
|
1089 return retval; |
|
1090 } |
|
1091 |
|
1092 // Sloppy... |
|
1093 |
|
1094 Array<double> |
2376
|
1095 octave_value::vector_value (bool force_string_conv, |
|
1096 bool force_vector_conversion) const |
|
1097 { |
3419
|
1098 Array<double> retval; |
2376
|
1099 |
|
1100 Matrix m = matrix_value (force_string_conv); |
|
1101 |
|
1102 if (error_state) |
|
1103 return retval; |
|
1104 |
|
1105 int nr = m.rows (); |
|
1106 int nc = m.columns (); |
|
1107 |
|
1108 if (nr == 1) |
|
1109 { |
|
1110 retval.resize (nc); |
|
1111 for (int i = 0; i < nc; i++) |
|
1112 retval (i) = m (0, i); |
|
1113 } |
|
1114 else if (nc == 1) |
|
1115 { |
|
1116 retval.resize (nr); |
|
1117 for (int i = 0; i < nr; i++) |
|
1118 retval (i) = m (i, 0); |
|
1119 } |
4455
|
1120 else if (nr > 0 && nc > 0) |
2376
|
1121 { |
4455
|
1122 // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? |
|
1123 if (! force_vector_conversion && Vwarn_fortran_indexing) |
|
1124 gripe_implicit_conversion (type_name (), "real vector"); |
|
1125 |
2376
|
1126 retval.resize (nr * nc); |
|
1127 int k = 0; |
|
1128 for (int j = 0; j < nc; j++) |
|
1129 for (int i = 0; i < nr; i++) |
4153
|
1130 { |
|
1131 OCTAVE_QUIT; |
|
1132 |
|
1133 retval (k++) = m (i, j); |
|
1134 } |
2376
|
1135 } |
|
1136 else |
|
1137 { |
3523
|
1138 std::string tn = type_name (); |
2376
|
1139 gripe_invalid_conversion (tn.c_str (), "real vector"); |
|
1140 } |
|
1141 |
|
1142 return retval; |
|
1143 } |
|
1144 |
4044
|
1145 Array<int> |
|
1146 octave_value::int_vector_value (bool force_string_conv, bool require_int, |
|
1147 bool force_vector_conversion) const |
|
1148 { |
|
1149 Array<int> retval; |
|
1150 |
|
1151 Matrix m = matrix_value (force_string_conv); |
|
1152 |
|
1153 if (error_state) |
|
1154 return retval; |
|
1155 |
|
1156 int nr = m.rows (); |
|
1157 int nc = m.columns (); |
|
1158 |
|
1159 if (nr == 1) |
|
1160 { |
|
1161 retval.resize (nc); |
|
1162 for (int i = 0; i < nc; i++) |
|
1163 { |
4153
|
1164 OCTAVE_QUIT; |
|
1165 |
4044
|
1166 double d = m (0, i); |
|
1167 |
|
1168 if (require_int && D_NINT (d) != d) |
|
1169 { |
|
1170 error ("conversion to integer value failed"); |
|
1171 return retval; |
|
1172 } |
|
1173 |
|
1174 retval (i) = static_cast<int> (d); |
|
1175 } |
|
1176 } |
|
1177 else if (nc == 1) |
|
1178 { |
|
1179 retval.resize (nr); |
|
1180 for (int i = 0; i < nr; i++) |
|
1181 { |
4153
|
1182 OCTAVE_QUIT; |
|
1183 |
4044
|
1184 double d = m (i, 0); |
|
1185 |
|
1186 if (require_int && D_NINT (d) != d) |
|
1187 { |
|
1188 error ("conversion to integer value failed"); |
|
1189 return retval; |
|
1190 } |
|
1191 |
|
1192 retval (i) = static_cast<int> (d); |
|
1193 } |
|
1194 } |
4455
|
1195 else if (nr > 0 && nc > 0) |
4044
|
1196 { |
4455
|
1197 // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? |
|
1198 if (! force_vector_conversion && Vwarn_fortran_indexing) |
|
1199 gripe_implicit_conversion (type_name (), "real vector"); |
|
1200 |
4044
|
1201 retval.resize (nr * nc); |
|
1202 int k = 0; |
|
1203 for (int j = 0; j < nc; j++) |
|
1204 { |
|
1205 for (int i = 0; i < nr; i++) |
|
1206 { |
4153
|
1207 OCTAVE_QUIT; |
|
1208 |
4044
|
1209 double d = m (i, j); |
|
1210 |
|
1211 if (require_int && D_NINT (d) != d) |
|
1212 { |
|
1213 error ("conversion to integer value failed"); |
|
1214 return retval; |
|
1215 } |
|
1216 |
|
1217 retval (k++) = static_cast<int> (d); |
|
1218 } |
|
1219 } |
|
1220 } |
|
1221 else |
|
1222 { |
|
1223 std::string tn = type_name (); |
|
1224 gripe_invalid_conversion (tn.c_str (), "real vector"); |
|
1225 } |
|
1226 |
|
1227 return retval; |
|
1228 } |
|
1229 |
3419
|
1230 Array<Complex> |
2376
|
1231 octave_value::complex_vector_value (bool force_string_conv, |
|
1232 bool force_vector_conversion) const |
|
1233 { |
3419
|
1234 Array<Complex> retval; |
2376
|
1235 |
|
1236 ComplexMatrix m = complex_matrix_value (force_string_conv); |
|
1237 |
|
1238 if (error_state) |
|
1239 return retval; |
|
1240 |
|
1241 int nr = m.rows (); |
|
1242 int nc = m.columns (); |
|
1243 |
|
1244 if (nr == 1) |
|
1245 { |
|
1246 retval.resize (nc); |
|
1247 for (int i = 0; i < nc; i++) |
4153
|
1248 { |
|
1249 OCTAVE_QUIT; |
|
1250 retval (i) = m (0, i); |
|
1251 } |
2376
|
1252 } |
|
1253 else if (nc == 1) |
|
1254 { |
|
1255 retval.resize (nr); |
|
1256 for (int i = 0; i < nr; i++) |
4153
|
1257 { |
|
1258 OCTAVE_QUIT; |
|
1259 retval (i) = m (i, 0); |
|
1260 } |
2376
|
1261 } |
4455
|
1262 else if (nr > 0 && nc > 0) |
2376
|
1263 { |
4455
|
1264 // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? |
|
1265 if (! force_vector_conversion && Vwarn_fortran_indexing) |
|
1266 gripe_implicit_conversion (type_name (), "complex vector"); |
|
1267 |
2376
|
1268 retval.resize (nr * nc); |
|
1269 int k = 0; |
|
1270 for (int j = 0; j < nc; j++) |
|
1271 for (int i = 0; i < nr; i++) |
4153
|
1272 { |
|
1273 OCTAVE_QUIT; |
|
1274 retval (k++) = m (i, j); |
|
1275 } |
2376
|
1276 } |
|
1277 else |
|
1278 { |
3523
|
1279 std::string tn = type_name (); |
2376
|
1280 gripe_invalid_conversion (tn.c_str (), "complex vector"); |
|
1281 } |
|
1282 |
|
1283 return retval; |
|
1284 } |
|
1285 |
4452
|
1286 octave_value |
4457
|
1287 octave_value::convert_to_str (bool pad, bool force) const |
4452
|
1288 { |
4457
|
1289 octave_value retval = convert_to_str_internal (pad, force); |
4452
|
1290 |
4457
|
1291 if (! force && is_numeric_type () && Vwarn_num_to_str) |
4452
|
1292 gripe_implicit_conversion (type_name (), retval.type_name ()); |
|
1293 |
|
1294 return retval; |
|
1295 } |
|
1296 |
2376
|
1297 void |
4005
|
1298 octave_value::print_with_name (std::ostream& output_buf, |
|
1299 const std::string& name, |
2903
|
1300 bool print_padding) const |
2376
|
1301 { |
4005
|
1302 if (! (evaluating_function_body && Vsilent_functions)) |
|
1303 { |
4894
|
1304 bool pad_after = false; |
|
1305 |
|
1306 if (Vprint_answer_id_name) |
|
1307 pad_after = print_name_tag (output_buf, name); |
2376
|
1308 |
4005
|
1309 print (output_buf); |
2376
|
1310 |
4005
|
1311 if (print_padding && pad_after) |
|
1312 newline (output_buf); |
|
1313 } |
2376
|
1314 } |
|
1315 |
|
1316 static void |
3523
|
1317 gripe_indexed_assignment (const std::string& tn1, const std::string& tn2) |
2413
|
1318 { |
2903
|
1319 error ("assignment of `%s' to indexed `%s' not implemented", |
2413
|
1320 tn2.c_str (), tn1.c_str ()); |
|
1321 } |
|
1322 |
|
1323 static void |
3933
|
1324 gripe_assign_conversion_failed (const std::string& tn1, |
|
1325 const std::string& tn2) |
2413
|
1326 { |
2903
|
1327 error ("type conversion for assignment of `%s' to indexed `%s' failed", |
2413
|
1328 tn2.c_str (), tn1.c_str ()); |
|
1329 } |
|
1330 |
3933
|
1331 octave_value |
4247
|
1332 octave_value::numeric_assign (const std::string& type, |
4219
|
1333 const std::list<octave_value_list>& idx, |
2413
|
1334 const octave_value& rhs) |
|
1335 { |
3933
|
1336 octave_value retval; |
2413
|
1337 |
|
1338 int t_lhs = type_id (); |
|
1339 int t_rhs = rhs.type_id (); |
|
1340 |
2880
|
1341 assign_op_fcn f |
3933
|
1342 = octave_value_typeinfo::lookup_assign_op (op_asn_eq, t_lhs, t_rhs); |
|
1343 |
|
1344 bool done = false; |
2413
|
1345 |
|
1346 if (f) |
|
1347 { |
3933
|
1348 f (*this, idx.front (), rhs.get_rep ()); |
2413
|
1349 |
3933
|
1350 done = (! error_state); |
2413
|
1351 } |
3933
|
1352 |
|
1353 if (done) |
|
1354 retval = octave_value (this, count + 1); |
3196
|
1355 else |
|
1356 { |
3933
|
1357 int t_result |
|
1358 = octave_value_typeinfo::lookup_pref_assign_conv (t_lhs, t_rhs); |
|
1359 |
|
1360 if (t_result >= 0) |
|
1361 { |
|
1362 type_conv_fcn cf |
|
1363 = octave_value_typeinfo::lookup_widening_op (t_lhs, t_result); |
|
1364 |
|
1365 if (cf) |
|
1366 { |
|
1367 octave_value *tmp (cf (*this)); |
3196
|
1368 |
3933
|
1369 if (tmp) |
|
1370 { |
|
1371 retval = tmp->subsasgn (type, idx, rhs); |
|
1372 |
|
1373 done = (! error_state); |
|
1374 } |
|
1375 else |
|
1376 gripe_assign_conversion_failed (type_name (), |
|
1377 rhs.type_name ()); |
|
1378 } |
|
1379 else |
|
1380 gripe_indexed_assignment (type_name (), rhs.type_name ()); |
|
1381 } |
|
1382 |
|
1383 if (! (done || error_state)) |
3196
|
1384 { |
3933
|
1385 octave_value tmp_rhs; |
|
1386 type_conv_fcn cf_rhs = rhs.numeric_conversion_function (); |
|
1387 |
|
1388 if (cf_rhs) |
|
1389 { |
|
1390 octave_value *tmp = cf_rhs (rhs.get_rep ()); |
|
1391 |
|
1392 if (tmp) |
|
1393 tmp_rhs = octave_value (tmp); |
|
1394 else |
|
1395 { |
|
1396 gripe_assign_conversion_failed (type_name (), |
|
1397 rhs.type_name ()); |
|
1398 return octave_value (); |
|
1399 } |
|
1400 } |
|
1401 else |
|
1402 tmp_rhs = rhs; |
|
1403 |
|
1404 type_conv_fcn cf_this = numeric_conversion_function (); |
|
1405 |
|
1406 octave_value *tmp_lhs = this; |
3196
|
1407 |
3933
|
1408 if (cf_this) |
|
1409 { |
|
1410 octave_value *tmp = cf_this (*this); |
|
1411 |
|
1412 if (tmp) |
|
1413 tmp_lhs = tmp; |
|
1414 else |
|
1415 { |
|
1416 gripe_assign_conversion_failed (type_name (), |
|
1417 rhs.type_name ()); |
|
1418 return octave_value (); |
|
1419 } |
|
1420 } |
|
1421 |
|
1422 if (cf_this || cf_rhs) |
|
1423 { |
|
1424 retval = tmp_lhs->subsasgn (type, idx, tmp_rhs); |
|
1425 |
|
1426 done = (! error_state); |
|
1427 } |
|
1428 else |
|
1429 gripe_no_conversion (assign_op_as_string (op_asn_eq), |
|
1430 type_name (), rhs.type_name ()); |
3196
|
1431 } |
|
1432 } |
2413
|
1433 |
4858
|
1434 // The assignment may have converted to a type that is wider than |
|
1435 // necessary. |
|
1436 |
|
1437 retval.maybe_mutate (); |
|
1438 |
2413
|
1439 return retval; |
|
1440 } |
|
1441 |
|
1442 static void |
3933
|
1443 gripe_binary_op (const std::string& on, const std::string& tn1, |
|
1444 const std::string& tn2) |
2376
|
1445 { |
2903
|
1446 error ("binary operator `%s' not implemented for `%s' by `%s' operations", |
2376
|
1447 on.c_str (), tn1.c_str (), tn2.c_str ()); |
|
1448 } |
|
1449 |
3203
|
1450 static void |
3523
|
1451 gripe_binary_op_conv (const std::string& on) |
3203
|
1452 { |
|
1453 error ("type conversion failed for binary operator `%s'", on.c_str ()); |
|
1454 } |
|
1455 |
2376
|
1456 octave_value |
3933
|
1457 do_binary_op (octave_value::binary_op op, |
|
1458 const octave_value& v1, const octave_value& v2) |
2376
|
1459 { |
|
1460 octave_value retval; |
|
1461 |
|
1462 int t1 = v1.type_id (); |
|
1463 int t2 = v2.type_id (); |
|
1464 |
2427
|
1465 binary_op_fcn f = octave_value_typeinfo::lookup_binary_op (op, t1, t2); |
2376
|
1466 |
|
1467 if (f) |
|
1468 retval = f (*v1.rep, *v2.rep); |
|
1469 else |
|
1470 { |
|
1471 octave_value tv1; |
2427
|
1472 type_conv_fcn cf1 = v1.numeric_conversion_function (); |
2376
|
1473 |
|
1474 if (cf1) |
|
1475 { |
3203
|
1476 octave_value *tmp = cf1 (*v1.rep); |
|
1477 |
|
1478 if (tmp) |
|
1479 { |
|
1480 tv1 = octave_value (tmp); |
|
1481 t1 = tv1.type_id (); |
|
1482 } |
|
1483 else |
|
1484 { |
|
1485 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); |
|
1486 return retval; |
|
1487 } |
2376
|
1488 } |
|
1489 else |
|
1490 tv1 = v1; |
|
1491 |
|
1492 octave_value tv2; |
2427
|
1493 type_conv_fcn cf2 = v2.numeric_conversion_function (); |
2376
|
1494 |
|
1495 if (cf2) |
|
1496 { |
3203
|
1497 octave_value *tmp = cf2 (*v2.rep); |
|
1498 |
|
1499 if (tmp) |
|
1500 { |
|
1501 tv2 = octave_value (tmp); |
|
1502 t2 = tv2.type_id (); |
|
1503 } |
|
1504 else |
|
1505 { |
|
1506 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); |
|
1507 return retval; |
|
1508 } |
2376
|
1509 } |
|
1510 else |
|
1511 tv2 = v2; |
|
1512 |
|
1513 if (cf1 || cf2) |
|
1514 { |
4587
|
1515 f = octave_value_typeinfo::lookup_binary_op (op, t1, t2); |
2376
|
1516 |
|
1517 if (f) |
|
1518 retval = f (*tv1.rep, *tv2.rep); |
|
1519 else |
|
1520 gripe_binary_op (octave_value::binary_op_as_string (op), |
|
1521 v1.type_name (), v2.type_name ()); |
|
1522 } |
|
1523 else |
|
1524 gripe_binary_op (octave_value::binary_op_as_string (op), |
|
1525 v1.type_name (), v2.type_name ()); |
|
1526 } |
|
1527 |
|
1528 return retval; |
|
1529 } |
|
1530 |
3933
|
1531 void |
|
1532 octave_value::print_info (std::ostream& os, const std::string& prefix) const |
|
1533 { |
|
1534 os << prefix << "type_name: " << type_name () << "\n" |
|
1535 << prefix << "count: " << get_count () << "\n" |
|
1536 << prefix << "rep info: "; |
|
1537 |
|
1538 rep->print_info (os, prefix + " "); |
|
1539 } |
|
1540 |
3203
|
1541 static void |
3523
|
1542 gripe_unary_op (const std::string& on, const std::string& tn) |
3203
|
1543 { |
|
1544 error ("unary operator `%s' not implemented for `%s' operands", |
|
1545 on.c_str (), tn.c_str ()); |
|
1546 } |
|
1547 |
|
1548 static void |
3523
|
1549 gripe_unary_op_conv (const std::string& on) |
3203
|
1550 { |
|
1551 error ("type conversion failed for unary operator `%s'", on.c_str ()); |
|
1552 } |
|
1553 |
|
1554 octave_value |
|
1555 do_unary_op (octave_value::unary_op op, const octave_value& v) |
|
1556 { |
|
1557 octave_value retval; |
|
1558 |
|
1559 int t = v.type_id (); |
|
1560 |
|
1561 unary_op_fcn f = octave_value_typeinfo::lookup_unary_op (op, t); |
|
1562 |
|
1563 if (f) |
|
1564 retval = f (*v.rep); |
|
1565 else |
|
1566 { |
|
1567 octave_value tv; |
|
1568 type_conv_fcn cf = v.numeric_conversion_function (); |
|
1569 |
|
1570 if (cf) |
|
1571 { |
|
1572 octave_value *tmp = cf (*v.rep); |
|
1573 |
|
1574 if (tmp) |
|
1575 { |
|
1576 tv = octave_value (tmp); |
|
1577 t = tv.type_id (); |
|
1578 |
4587
|
1579 f = octave_value_typeinfo::lookup_unary_op (op, t); |
3203
|
1580 |
|
1581 if (f) |
|
1582 retval = f (*tv.rep); |
|
1583 else |
|
1584 gripe_unary_op (octave_value::unary_op_as_string (op), |
|
1585 v.type_name ()); |
|
1586 } |
|
1587 else |
|
1588 gripe_unary_op_conv (octave_value::unary_op_as_string (op)); |
|
1589 } |
|
1590 else |
|
1591 gripe_unary_op (octave_value::unary_op_as_string (op), |
|
1592 v.type_name ()); |
|
1593 } |
|
1594 |
|
1595 return retval; |
|
1596 } |
|
1597 |
|
1598 static void |
3933
|
1599 gripe_unary_op_conversion_failed (const std::string& op, |
|
1600 const std::string& tn) |
3203
|
1601 { |
|
1602 error ("operator %s: type conversion for `%s' failed", |
|
1603 op.c_str (), tn.c_str ()); |
|
1604 } |
|
1605 |
3933
|
1606 const octave_value& |
|
1607 octave_value::do_non_const_unary_op (unary_op op) |
3203
|
1608 { |
|
1609 octave_value retval; |
|
1610 |
|
1611 int t = type_id (); |
|
1612 |
|
1613 non_const_unary_op_fcn f |
|
1614 = octave_value_typeinfo::lookup_non_const_unary_op (op, t); |
|
1615 |
|
1616 if (f) |
|
1617 { |
|
1618 make_unique (); |
|
1619 |
|
1620 f (*rep); |
|
1621 } |
|
1622 else |
|
1623 { |
|
1624 type_conv_fcn cf = numeric_conversion_function (); |
|
1625 |
|
1626 if (cf) |
|
1627 { |
|
1628 octave_value *tmp = cf (*rep); |
|
1629 |
|
1630 if (tmp) |
|
1631 { |
|
1632 octave_value *old_rep = rep; |
|
1633 rep = tmp; |
|
1634 rep->count = 1; |
|
1635 |
|
1636 t = type_id (); |
|
1637 |
|
1638 f = octave_value_typeinfo::lookup_non_const_unary_op (op, t); |
|
1639 |
|
1640 if (f) |
|
1641 { |
|
1642 f (*rep); |
|
1643 |
|
1644 if (old_rep && --old_rep->count == 0) |
|
1645 delete old_rep; |
|
1646 } |
|
1647 else |
|
1648 { |
|
1649 if (old_rep) |
|
1650 { |
|
1651 if (--rep->count == 0) |
|
1652 delete rep; |
|
1653 |
|
1654 rep = old_rep; |
|
1655 } |
|
1656 |
|
1657 gripe_unary_op (octave_value::unary_op_as_string (op), |
|
1658 type_name ()); |
|
1659 } |
|
1660 } |
|
1661 else |
|
1662 gripe_unary_op_conversion_failed |
|
1663 (octave_value::unary_op_as_string (op), type_name ()); |
|
1664 } |
|
1665 else |
|
1666 gripe_unary_op (octave_value::unary_op_as_string (op), type_name ()); |
|
1667 } |
3933
|
1668 |
|
1669 return *this; |
3203
|
1670 } |
|
1671 |
3933
|
1672 #if 0 |
3205
|
1673 static void |
3933
|
1674 gripe_unary_op_failed_or_no_method (const std::string& on, |
|
1675 const std::string& tn) |
3205
|
1676 { |
|
1677 error ("operator %s: no method, or unable to evaluate for %s operand", |
|
1678 on.c_str (), tn.c_str ()); |
|
1679 } |
3933
|
1680 #endif |
3205
|
1681 |
|
1682 void |
4661
|
1683 octave_value::do_non_const_unary_op (unary_op, const octave_value_list&) |
3205
|
1684 { |
3933
|
1685 abort (); |
|
1686 } |
|
1687 |
|
1688 octave_value |
4247
|
1689 octave_value::do_non_const_unary_op (unary_op op, const std::string& type, |
4219
|
1690 const std::list<octave_value_list>& idx) |
3933
|
1691 { |
|
1692 octave_value retval; |
|
1693 |
|
1694 if (idx.empty ()) |
|
1695 { |
|
1696 do_non_const_unary_op (op); |
3205
|
1697 |
3933
|
1698 retval = *this; |
|
1699 } |
|
1700 else |
|
1701 { |
|
1702 // XXX FIXME XXX -- only do the following stuff if we can't find a |
|
1703 // specific function to call to handle the op= operation for the |
|
1704 // types we have. |
3205
|
1705 |
3933
|
1706 assign_op assop = unary_op_to_assign_op (op); |
|
1707 |
|
1708 retval = assign (assop, type, idx, 1.0); |
|
1709 } |
|
1710 |
|
1711 return retval; |
3205
|
1712 } |
|
1713 |
2903
|
1714 // Current indentation. |
|
1715 int octave_value::curr_print_indent_level = 0; |
|
1716 |
3018
|
1717 // TRUE means we are at the beginning of a line. |
2903
|
1718 bool octave_value::beginning_of_line = true; |
|
1719 |
|
1720 // Each print() function should call this before printing anything. |
|
1721 // |
|
1722 // This doesn't need to be fast, but isn't there a better way? |
|
1723 |
|
1724 void |
3523
|
1725 octave_value::indent (std::ostream& os) const |
2903
|
1726 { |
|
1727 assert (curr_print_indent_level >= 0); |
|
1728 |
|
1729 if (beginning_of_line) |
|
1730 { |
|
1731 // XXX FIXME XXX -- do we need this? |
|
1732 // os << prefix; |
|
1733 |
|
1734 for (int i = 0; i < curr_print_indent_level; i++) |
|
1735 os << " "; |
|
1736 |
|
1737 beginning_of_line = false; |
|
1738 } |
|
1739 } |
|
1740 |
|
1741 // All print() functions should use this to print new lines. |
|
1742 |
|
1743 void |
3523
|
1744 octave_value::newline (std::ostream& os) const |
2903
|
1745 { |
|
1746 os << "\n"; |
|
1747 |
|
1748 beginning_of_line = true; |
|
1749 } |
|
1750 |
|
1751 // For ressetting print state. |
|
1752 |
|
1753 void |
|
1754 octave_value::reset (void) const |
|
1755 { |
|
1756 beginning_of_line = true; |
|
1757 curr_print_indent_level = 0; |
|
1758 } |
|
1759 |
3205
|
1760 octave_value::assign_op |
|
1761 octave_value::unary_op_to_assign_op (unary_op op) |
|
1762 { |
|
1763 assign_op binop = unknown_assign_op; |
|
1764 |
|
1765 switch (op) |
|
1766 { |
3533
|
1767 case op_incr: |
|
1768 binop = op_add_eq; |
3205
|
1769 break; |
|
1770 |
3533
|
1771 case op_decr: |
|
1772 binop = op_sub_eq; |
3205
|
1773 break; |
|
1774 |
|
1775 default: |
|
1776 { |
3523
|
1777 std::string on = unary_op_as_string (op); |
3205
|
1778 error ("operator %s: no assign operator found", on.c_str ()); |
|
1779 } |
|
1780 } |
|
1781 |
|
1782 return binop; |
|
1783 } |
|
1784 |
3204
|
1785 octave_value::binary_op |
|
1786 octave_value::op_eq_to_binary_op (assign_op op) |
|
1787 { |
|
1788 binary_op binop = unknown_binary_op; |
|
1789 |
|
1790 switch (op) |
|
1791 { |
3533
|
1792 case op_add_eq: |
|
1793 binop = op_add; |
3204
|
1794 break; |
|
1795 |
3533
|
1796 case op_sub_eq: |
|
1797 binop = op_sub; |
3204
|
1798 break; |
|
1799 |
3533
|
1800 case op_mul_eq: |
|
1801 binop = op_mul; |
3204
|
1802 break; |
|
1803 |
3533
|
1804 case op_div_eq: |
|
1805 binop = op_div; |
3204
|
1806 break; |
|
1807 |
3533
|
1808 case op_ldiv_eq: |
|
1809 binop = op_ldiv; |
3204
|
1810 break; |
|
1811 |
4018
|
1812 case op_pow_eq: |
|
1813 binop = op_pow; |
|
1814 break; |
|
1815 |
3533
|
1816 case op_lshift_eq: |
|
1817 binop = op_lshift; |
3204
|
1818 break; |
|
1819 |
3533
|
1820 case op_rshift_eq: |
|
1821 binop = op_rshift; |
3204
|
1822 break; |
|
1823 |
3533
|
1824 case op_el_mul_eq: |
|
1825 binop = op_el_mul; |
3204
|
1826 break; |
|
1827 |
3533
|
1828 case op_el_div_eq: |
|
1829 binop = op_el_div; |
3204
|
1830 break; |
|
1831 |
3533
|
1832 case op_el_ldiv_eq: |
|
1833 binop = op_el_ldiv; |
3204
|
1834 break; |
|
1835 |
4018
|
1836 case op_el_pow_eq: |
|
1837 binop = op_el_pow; |
|
1838 break; |
|
1839 |
3533
|
1840 case op_el_and_eq: |
|
1841 binop = op_el_and; |
3204
|
1842 break; |
|
1843 |
3533
|
1844 case op_el_or_eq: |
|
1845 binop = op_el_or; |
3204
|
1846 break; |
|
1847 |
|
1848 default: |
|
1849 { |
3523
|
1850 std::string on = assign_op_as_string (op); |
3204
|
1851 error ("operator %s: no binary operator found", on.c_str ()); |
|
1852 } |
|
1853 } |
|
1854 |
|
1855 return binop; |
|
1856 } |
|
1857 |
3933
|
1858 octave_value |
|
1859 octave_value::empty_conv (const std::string& type, const octave_value& rhs) |
|
1860 { |
|
1861 octave_value retval; |
|
1862 |
|
1863 if (type.length () > 0) |
|
1864 { |
|
1865 switch (type[0]) |
|
1866 { |
|
1867 case '(': |
|
1868 { |
|
1869 if (type.length () > 1 && type[1] == '.') |
|
1870 retval = Octave_map (); |
|
1871 else |
|
1872 retval = octave_value (rhs.empty_clone ()); |
|
1873 } |
|
1874 break; |
|
1875 |
|
1876 case '{': |
|
1877 retval = Cell (); |
|
1878 break; |
|
1879 |
|
1880 case '.': |
|
1881 retval = Octave_map (); |
|
1882 break; |
|
1883 |
|
1884 default: |
|
1885 panic_impossible (); |
|
1886 } |
|
1887 } |
|
1888 else |
|
1889 retval = octave_value (rhs.empty_clone ()); |
|
1890 |
|
1891 return retval; |
|
1892 } |
|
1893 |
2376
|
1894 void |
|
1895 install_types (void) |
|
1896 { |
|
1897 octave_base_value::register_type (); |
3928
|
1898 octave_cell::register_type (); |
2376
|
1899 octave_scalar::register_type (); |
|
1900 octave_complex::register_type (); |
|
1901 octave_matrix::register_type (); |
|
1902 octave_complex_matrix::register_type (); |
|
1903 octave_range::register_type (); |
2825
|
1904 octave_bool::register_type (); |
|
1905 octave_bool_matrix::register_type (); |
2376
|
1906 octave_char_matrix::register_type (); |
|
1907 octave_char_matrix_str::register_type (); |
|
1908 octave_struct::register_type (); |
2903
|
1909 octave_file::register_type (); |
2880
|
1910 octave_list::register_type (); |
3977
|
1911 octave_cs_list::register_type (); |
2376
|
1912 octave_all_va_args::register_type (); |
|
1913 octave_magic_colon::register_type (); |
2974
|
1914 octave_builtin::register_type (); |
|
1915 octave_mapper::register_type (); |
|
1916 octave_user_function::register_type (); |
4649
|
1917 octave_dld_function::register_type (); |
4643
|
1918 octave_fcn_handle::register_type (); |
|
1919 octave_streamoff::register_type (); |
2376
|
1920 } |
|
1921 |
4791
|
1922 DEFUN (sizeof, args, , |
|
1923 "-*- texinfo -*-\n\ |
|
1924 @deftypefn {Built-in Function} {} sizeof (@var{val})\n\ |
|
1925 Return the size of @var{val} in bytes\n\ |
|
1926 @end deftypefn") |
|
1927 { |
|
1928 octave_value retval; |
|
1929 |
|
1930 if (args.length () == 1) |
|
1931 retval = args(0).byte_size (); |
|
1932 else |
|
1933 print_usage ("sizeof"); |
|
1934 |
|
1935 return retval; |
|
1936 } |
|
1937 |
2376
|
1938 static int |
4455
|
1939 warn_fortran_indexing (void) |
2376
|
1940 { |
4455
|
1941 Vwarn_fortran_indexing = check_preference ("warn_fortran_indexing"); |
2376
|
1942 |
4455
|
1943 liboctave_wfi_flag = Vwarn_fortran_indexing; |
2376
|
1944 |
|
1945 return 0; |
|
1946 } |
|
1947 |
|
1948 static int |
4452
|
1949 warn_imag_to_real (void) |
4257
|
1950 { |
4452
|
1951 Vwarn_imag_to_real = check_preference ("warn_imag_to_real"); |
4257
|
1952 |
|
1953 return 0; |
|
1954 } |
|
1955 |
|
1956 static int |
4452
|
1957 warn_num_to_str (void) |
2376
|
1958 { |
4452
|
1959 Vwarn_num_to_str = check_preference ("warn_num_to_str"); |
2376
|
1960 |
|
1961 return 0; |
|
1962 } |
|
1963 |
|
1964 static int |
4452
|
1965 warn_str_to_num (void) |
2376
|
1966 { |
4452
|
1967 Vwarn_str_to_num = check_preference ("warn_str_to_num"); |
2376
|
1968 |
|
1969 return 0; |
|
1970 } |
|
1971 |
|
1972 static int |
|
1973 print_answer_id_name (void) |
|
1974 { |
|
1975 Vprint_answer_id_name = check_preference ("print_answer_id_name"); |
|
1976 |
|
1977 return 0; |
|
1978 } |
|
1979 |
|
1980 static int |
4461
|
1981 warn_resize_on_range_error (void) |
2376
|
1982 { |
4461
|
1983 Vwarn_resize_on_range_error |
|
1984 = check_preference ("warn_resize_on_range_error"); |
2376
|
1985 |
4461
|
1986 liboctave_wrore_flag = Vwarn_resize_on_range_error; |
2376
|
1987 |
|
1988 return 0; |
|
1989 } |
|
1990 |
|
1991 static int |
4005
|
1992 silent_functions (void) |
|
1993 { |
|
1994 Vsilent_functions = check_preference ("silent_functions"); |
|
1995 |
|
1996 return 0; |
|
1997 } |
|
1998 |
|
1999 static int |
2376
|
2000 struct_levels_to_print (void) |
|
2001 { |
|
2002 double val; |
|
2003 if (builtin_real_scalar_variable ("struct_levels_to_print", val) |
|
2004 && ! xisnan (val)) |
|
2005 { |
|
2006 int ival = NINT (val); |
3961
|
2007 if (ival == val) |
2376
|
2008 { |
|
2009 Vstruct_levels_to_print = ival; |
|
2010 return 0; |
|
2011 } |
|
2012 } |
|
2013 gripe_invalid_value_specified ("struct_levels_to_print"); |
|
2014 return -1; |
|
2015 } |
|
2016 |
|
2017 static int |
|
2018 warn_divide_by_zero (void) |
|
2019 { |
|
2020 Vwarn_divide_by_zero = check_preference ("warn_divide_by_zero"); |
|
2021 |
|
2022 return 0; |
|
2023 } |
|
2024 |
|
2025 void |
2909
|
2026 symbols_of_ov (void) |
2376
|
2027 { |
4233
|
2028 DEFVAR (print_answer_id_name, true, print_answer_id_name, |
3372
|
2029 "-*- texinfo -*-\n\ |
|
2030 @defvr {Built-in Variable} print_answer_id_name\n\ |
|
2031 If the value of @code{print_answer_id_name} is nonzero, variable\n\ |
|
2032 names are printed along with the result. Otherwise, only the result\n\ |
|
2033 values are printed. The default value is 1.\n\ |
|
2034 @end defvr"); |
2376
|
2035 |
4233
|
2036 DEFVAR (silent_functions, false, silent_functions, |
4005
|
2037 "-*- texinfo -*-\n\ |
|
2038 @defvr {Built-in Variable} silent_functions\n\ |
|
2039 If the value of @code{silent_functions} is nonzero, internal output\n\ |
|
2040 from a function is suppressed. Otherwise, the results of expressions\n\ |
|
2041 within a function body that are not terminated with a semicolon will\n\ |
|
2042 have their values printed. The default value is 0.\n\ |
|
2043 \n\ |
|
2044 For example, if the function\n\ |
|
2045 \n\ |
|
2046 @example\n\ |
|
2047 function f ()\n\ |
|
2048 2 + 2\n\ |
|
2049 endfunction\n\ |
|
2050 @end example\n\ |
|
2051 \n\ |
|
2052 @noindent\n\ |
|
2053 is executed, Octave will either print @samp{ans = 4} or nothing\n\ |
|
2054 depending on the value of @code{silent_functions}.\n\ |
|
2055 @end defvr"); |
|
2056 |
3258
|
2057 DEFVAR (struct_levels_to_print, 2.0, struct_levels_to_print, |
3361
|
2058 "-*- texinfo -*-\n\ |
|
2059 @defvr {Built-in Variable} struct_levels_to_print\n\ |
|
2060 You can tell Octave how many structure levels to display by setting the\n\ |
|
2061 built-in variable @code{struct_levels_to_print}. The default value is 2.\n\ |
3363
|
2062 @end defvr"); |
2376
|
2063 |
4233
|
2064 DEFVAR (warn_divide_by_zero, true, warn_divide_by_zero, |
3371
|
2065 "-*- texinfo -*-\n\ |
|
2066 @defvr {Built-in Variable} warn_divide_by_zero\n\ |
|
2067 If the value of @code{warn_divide_by_zero} is nonzero, a warning\n\ |
|
2068 is issued when Octave encounters a division by zero. If the value is\n\ |
|
2069 0, the warning is omitted. The default value is 1.\n\ |
|
2070 @end defvr"); |
4451
|
2071 |
4455
|
2072 DEFVAR (warn_fortran_indexing, false, warn_fortran_indexing, |
|
2073 "-*- texinfo -*-\n\ |
|
2074 @defvr {Built-in Variable} warn_fortran_indexing\n\ |
|
2075 If the value of @code{warn_fortran_indexing} is nonzero, a warning is\n\ |
|
2076 printed for expressions which select elements of a two-dimensional matrix\n\ |
|
2077 using a single index. The default value is 0.\n\ |
|
2078 @end defvr"); |
|
2079 |
4451
|
2080 DEFVAR (warn_imag_to_real, false, warn_imag_to_real, |
|
2081 "-*- texinfo -*-\n\ |
|
2082 @defvr {Built-in Variable} warn_imag_to_real\n\ |
|
2083 If the value of @code{warn_imag_to_real} is nonzero, a warning is\n\ |
|
2084 printed for implicit conversions of complex numbers to real numbers.\n\ |
|
2085 The default value is 0.\n\ |
|
2086 @end defvr"); |
4452
|
2087 |
|
2088 DEFVAR (warn_num_to_str, true, warn_num_to_str, |
|
2089 "-*- texinfo -*-\n\ |
|
2090 @defvr {Built-in Variable} warn_num_to_str\n\ |
|
2091 If the value of @code{warn_num_to_str} is nonzero, a warning is\n\ |
|
2092 printed for implicit conversions of numbers to their ASCII character\n\ |
|
2093 equivalents when strings are constructed using a mixture of strings and\n\ |
|
2094 numbers in matrix notation. For example,\n\ |
|
2095 \n\ |
|
2096 @example\n\ |
|
2097 @group\n\ |
|
2098 [ \"f\", 111, 111 ]\n\ |
|
2099 @result{} \"foo\"\n\ |
|
2100 @end group\n\ |
|
2101 @end example\n\ |
|
2102 elicits a warning if @code{warn_num_to_str} is nonzero. The default\n\ |
|
2103 value is 1.\n\ |
|
2104 @end defvr"); |
|
2105 |
4461
|
2106 DEFVAR (warn_resize_on_range_error, false, warn_resize_on_range_error, |
|
2107 "-*- texinfo -*-\n\ |
|
2108 @defvr {Built-in Variable} warn_resize_on_range_error\n\ |
|
2109 If the value of @code{warn_resize_on_range_error} is nonzero, print a\n\ |
|
2110 warning when a matrix is resized by an indexed assignment with\n\ |
|
2111 indices outside the current bounds. The default value is 0.\n\ |
|
2112 @end defvr"); |
|
2113 |
4452
|
2114 DEFVAR (warn_str_to_num, false, warn_str_to_num, |
|
2115 "-*- texinfo -*-\n\ |
|
2116 @defvr {Built-in Variable} warn_str_to_num\n\ |
|
2117 If the value of @code{warn_str_to_num} is nonzero, a warning is printed\n\ |
|
2118 for implicit conversions of strings to their numeric ASCII equivalents.\n\ |
|
2119 For example,\n\ |
|
2120 @example\n\ |
|
2121 @group\n\ |
|
2122 \"abc\" + 0\n\ |
|
2123 @result{} 97 98 99\n\ |
|
2124 @end group\n\ |
|
2125 @end example\n\ |
|
2126 elicits a warning if @code{warn_str_to_num} is nonzero. The default\n\ |
|
2127 value is 0.\n\ |
|
2128 @end defvr"); |
2376
|
2129 } |
|
2130 |
|
2131 /* |
|
2132 ;;; Local Variables: *** |
|
2133 ;;; mode: C++ *** |
|
2134 ;;; End: *** |
|
2135 */ |