GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ov-typeinfo.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2018 John W. Eaton
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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License 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, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include "Array.h"
28 
29 #include "defun.h"
30 #include "error.h"
31 #include "interpreter.h"
32 #include "interpreter-private.h"
33 #include "ops.h"
34 #include "ov-typeinfo.h"
35 #include "ov.h"
36 
37 // FIXME: we should also store all class names and provide a
38 // way to list them (calling class with nargin == 0?).
39 
40 static NDArray
42 {
43  NDArray retval (x.dims ());
44 
45  for (int i = 0; i < x.numel (); i++)
46  retval.xelem(i) = x(i);
47 
48  return retval;
49 }
50 
51 static boolNDArray
53 {
54  boolNDArray retval (x.dims ());
55 
56  for (octave_idx_type i = 0; i < x.numel (); i++)
57  retval.xelem (i) = x(i);
58 
59  return retval;
60 }
61 
62 namespace octave
63 {
64  type_info::type_info (int init_tab_sz)
65  : num_types (0), types (dim_vector (init_tab_sz, 1), ""),
66  vals (dim_vector (init_tab_sz, 1)),
67  unary_class_ops (dim_vector (octave_value::num_unary_ops, 1), nullptr),
68  unary_ops (dim_vector (octave_value::num_unary_ops, init_tab_sz), nullptr),
69  non_const_unary_ops (dim_vector (octave_value::num_unary_ops, init_tab_sz), nullptr),
70  binary_class_ops (dim_vector (octave_value::num_binary_ops, 1), nullptr),
71  binary_ops (dim_vector (octave_value::num_binary_ops, init_tab_sz, init_tab_sz), nullptr),
72  compound_binary_class_ops (dim_vector (octave_value::num_compound_binary_ops, 1), nullptr),
73  compound_binary_ops (dim_vector (octave_value::num_compound_binary_ops, init_tab_sz, init_tab_sz), nullptr),
74  cat_ops (dim_vector (init_tab_sz, init_tab_sz), nullptr),
75  assign_ops (dim_vector (octave_value::num_assign_ops, init_tab_sz, init_tab_sz), nullptr),
76  assignany_ops (dim_vector (octave_value::num_assign_ops, init_tab_sz), nullptr),
77  pref_assign_conv (dim_vector (init_tab_sz, init_tab_sz), -1),
78  widening_ops (dim_vector (init_tab_sz, init_tab_sz), nullptr)
79  {
80  install_types (*this);
81 
82  install_ops (*this);
83  }
84 
86  const std::string& /* c_name */,
87  const octave_value& val,
88  bool abort_on_duplicate)
89  {
90  int i = 0;
91 
92  for (i = 0; i < num_types; i++)
93  {
94  if (t_name == types (i))
95  {
96  if (abort_on_duplicate)
97  {
98  std::cerr << "duplicate type " << t_name << std::endl;
99  abort ();
100  }
101 
102  warning ("duplicate type %s\n", t_name.c_str ());
103 
104  return i;
105  }
106  }
107 
108  int len = types.numel ();
109 
110  if (i == len)
111  {
112  len *= 2;
113 
114  types.resize (dim_vector (len, 1), "");
115 
116  vals.resize (dim_vector (len, 1), nullptr);
117 
119  (dim_vector (octave_value::num_unary_ops, len), nullptr);
120 
122  (dim_vector (octave_value::num_unary_ops, len), nullptr);
123 
125  (dim_vector (octave_value::num_binary_ops, len, len), nullptr);
126 
129  nullptr);
130 
131  cat_ops.resize (dim_vector (len, len), nullptr);
132 
134  (dim_vector (octave_value::num_assign_ops, len, len), nullptr);
135 
137  (dim_vector (octave_value::num_assign_ops, len), nullptr);
138 
139  pref_assign_conv.resize (dim_vector (len, len), -1);
140 
141  widening_ops.resize (dim_vector (len, len), nullptr);
142  }
143 
144  types (i) = t_name;
145 
146  // Yes, this object is intentionally not deleted in the destructor
147  // so that we avoid a crash on exit for user-defined data types.
148  // See bug #53156. If that problem is properly fixed, then this
149  // could be stored as an object instead of a pointer to an object
150  // allocated with new.
151 
152  vals(i) = new octave_value (val);
153 
154  num_types++;
155 
156  return i;
157  }
158 
161  bool abort_on_duplicate)
162  {
163  if (lookup_unary_class_op (op))
164  {
166 
167  if (abort_on_duplicate)
168  {
169  std::cerr << "duplicate unary operator '" << op_name
170  << "' for class dispatch" << std::endl;
171  abort ();
172  }
173 
174  warning ("duplicate unary operator '%s' for class dispatch",
175  op_name.c_str ());
176  }
177 
178  unary_class_ops.checkelem (static_cast<int> (op))
179  = reinterpret_cast<void *> (f);
180 
181  return false;
182  }
183 
185  unary_op_fcn f, bool abort_on_duplicate)
186  {
187  if (lookup_unary_op (op, t))
188  {
190  std::string type_name = types(t);
191 
192  if (abort_on_duplicate)
193  {
194  std::cerr << "duplicate unary operator '" << op_name
195  << "' for type '" << type_name << "'" << std::endl;
196  abort ();
197  }
198 
199  warning ("duplicate unary operator '%s' for type '%s'",
200  op_name.c_str (), type_name.c_str ());
201  }
202 
203  unary_ops.checkelem (static_cast<int> (op), t) = reinterpret_cast<void *> (f);
204 
205  return false;
206  }
207 
208  bool
211  bool abort_on_duplicate)
212  {
213  if (lookup_non_const_unary_op (op, t))
214  {
216  std::string type_name = types(t);
217 
218  if (abort_on_duplicate)
219  {
220  std::cerr << "duplicate unary operator '" << op_name
221  << "' for type '" << type_name << "'" << std::endl;
222  abort ();
223  }
224 
225  warning ("duplicate unary operator '%s' for type '%s'",
226  op_name.c_str (), type_name.c_str ());
227  }
228 
229  non_const_unary_ops.checkelem (static_cast<int> (op), t)
230  = reinterpret_cast<void *> (f);
231 
232  return false;
233  }
234 
235  bool
238  bool abort_on_duplicate)
239  {
240  if (lookup_binary_class_op (op))
241  {
243 
244  if (abort_on_duplicate)
245  {
246 
247  std::cerr << "duplicate binary operator '" << op_name
248  << "' for class dispatch" << std::endl;
249  abort ();
250  }
251 
252  warning ("duplicate binary operator '%s' for class dispatch",
253  op_name.c_str ());
254  }
255 
256  binary_class_ops.checkelem (static_cast<int> (op))
257  = reinterpret_cast<void *> (f);
258 
259  return false;
260  }
261 
263  int t1, int t2,
265  bool abort_on_duplicate)
266  {
267  if (lookup_binary_op (op, t1, t2))
268  {
270  std::string t1_name = types(t1);
271  std::string t2_name = types(t2);
272 
273  if (abort_on_duplicate)
274  {
275  std::cerr << "duplicate binary operator '" << op_name
276  << "' for types '" << t1_name << "' and '"
277  << t2_name << "'" << std::endl;
278  abort ();
279  }
280 
281  warning ("duplicate binary operator '%s' for types '%s' and '%s'",
282  op_name.c_str (), t1_name.c_str (), t1_name.c_str ());
283  }
284 
285  binary_ops.checkelem (static_cast<int> (op), t1, t2)
286  = reinterpret_cast<void *> (f);
287 
288  return false;
289  }
290 
291  bool
294  bool abort_on_duplicate)
295  {
296  if (lookup_binary_class_op (op))
297  {
299 
300  if (abort_on_duplicate)
301  {
302  std::cerr << "duplicate compound binary operator '"
303  << op_name << "' for class dispatch" << std::endl;
304  abort ();
305  }
306 
307  warning ("duplicate compound binary operator '%s' for class dispatch",
308  op_name.c_str ());
309  }
310 
311  compound_binary_class_ops.checkelem (static_cast<int> (op))
312  = reinterpret_cast<void *> (f);
313 
314  return false;
315  }
316 
318  int t1, int t2,
320  bool abort_on_duplicate)
321  {
322  if (lookup_binary_op (op, t1, t2))
323  {
325  std::string t1_name = types(t1);
326  std::string t2_name = types(t2);
327 
328  if (abort_on_duplicate)
329  {
330  std::cerr << "duplicate compound binary operator '"
331  << op_name << "' for types '" << t1_name
332  << "' and '" << t2_name << "'" << std::endl;
333  abort ();
334  }
335 
336  warning ("duplicate compound binary operator '%s' for types '%s' and '%s'",
337  op_name.c_str (), t1_name.c_str (), t1_name.c_str ());
338  }
339 
340  compound_binary_ops.checkelem (static_cast<int> (op), t1, t2)
341  = reinterpret_cast<void *> (f);
342 
343  return false;
344  }
345 
347  bool abort_on_duplicate)
348  {
349  if (lookup_cat_op (t1, t2))
350  {
351  std::string t1_name = types(t1);
352  std::string t2_name = types(t2);
353 
354  if (abort_on_duplicate)
355  {
356  std::cerr << "duplicate concatenation operator for types '"
357  << t1_name << "' and '" << t2_name << "'" << std::endl;
358  abort ();
359  }
360 
361  warning ("duplicate concatenation operator for types '%s' and '%s'",
362  t1_name.c_str (), t1_name.c_str ());
363  }
364 
365  cat_ops.checkelem (t1, t2) = reinterpret_cast<void *> (f);
366 
367  return false;
368  }
369 
371  int t_lhs, int t_rhs,
373  bool abort_on_duplicate)
374  {
375  if (lookup_assign_op (op, t_lhs, t_rhs))
376  {
378  std::string t_lhs_name = types(t_lhs);
379  std::string t_rhs_name = types(t_rhs);
380 
381  if (abort_on_duplicate)
382  {
383  std::cerr << "duplicate assignment operator '"
384  << op_name << "' for types '" << t_lhs_name
385  << "' and '" << t_rhs_name << "'" << std::endl;
386  abort ();
387  }
388 
389  warning ("duplicate assignment operator '%s' for types '%s' and '%s'",
390  op_name.c_str (), t_lhs_name.c_str (), t_rhs_name.c_str ());
391  }
392 
393  assign_ops.checkelem (static_cast<int> (op), t_lhs, t_rhs)
394  = reinterpret_cast<void *> (f);
395 
396  return false;
397  }
398 
401  bool abort_on_duplicate)
402  {
403  if (lookup_assignany_op (op, t_lhs))
404  {
406  std::string t_lhs_name = types(t_lhs);
407 
408  if (abort_on_duplicate)
409  {
410  std::cerr << "duplicate assignment operator '" << op_name
411  << "' for types '" << t_lhs_name << "'" << std::endl;
412  abort ();
413  }
414 
415  warning ("duplicate assignment operator '%s' for types '%s'",
416  op_name.c_str (), t_lhs_name.c_str ());
417  }
418 
419  assignany_ops.checkelem (static_cast<int> (op), t_lhs)
420  = reinterpret_cast<void *> (f);
421 
422  return false;
423  }
424 
425  bool type_info::register_pref_assign_conv (int t_lhs, int t_rhs,
426  int t_result,
427  bool abort_on_duplicate)
428  {
429  if (lookup_pref_assign_conv (t_lhs, t_rhs) >= 0)
430  {
431  std::string t_lhs_name = types(t_lhs);
432  std::string t_rhs_name = types(t_rhs);
433 
434  if (abort_on_duplicate)
435  {
436  std::cerr << "overriding assignment conversion for types '"
437  << t_lhs_name << "' and '" << t_rhs_name << "'"
438  << std::endl;
439  abort ();
440  }
441 
442  warning ("overriding assignment conversion for types '%s' and '%s'",
443  t_lhs_name.c_str (), t_rhs_name.c_str ());
444  }
445 
446  pref_assign_conv.checkelem (t_lhs, t_rhs) = t_result;
447 
448  return false;
449  }
450 
451  bool type_info::register_widening_op (int t, int t_result,
453  bool abort_on_duplicate)
454  {
455  if (lookup_widening_op (t, t_result))
456  {
457  std::string t_name = types(t);
458  std::string t_result_name = types(t_result);
459 
460  if (abort_on_duplicate)
461  {
462  std::cerr << "overriding widening op for '" << t_name
463  << "' to '" << t_result_name << "'" << std::endl;
464  abort ();
465  }
466 
467  warning ("overriding widening op for '%s' to '%s'",
468  t_name.c_str (), t_result_name.c_str ());
469  }
470 
471  widening_ops.checkelem (t, t_result) = reinterpret_cast<void *> (f);
472 
473  return false;
474  }
475 
477  {
479 
480  for (int i = 0; i < num_types; i++)
481  {
482  if (nm == types(i))
483  {
484  retval = *vals(i);
485  retval.make_unique ();
486  break;
487  }
488  }
489 
490  return retval;
491  }
492 
495  {
496  void *f = unary_class_ops.checkelem (static_cast<int> (op));
497  return reinterpret_cast<type_info::unary_class_op_fcn> (f);
498  }
499 
502  {
503  void *f = unary_ops.checkelem (static_cast<int> (op), t);
504  return reinterpret_cast<type_info::unary_op_fcn> (f);
505  }
506 
509  {
510  void *f = non_const_unary_ops.checkelem (static_cast<int> (op), t);
511  return reinterpret_cast<type_info::non_const_unary_op_fcn> (f);
512  }
513 
516  {
517  void *f = binary_class_ops.checkelem (static_cast<int> (op));
518  return reinterpret_cast<type_info::binary_class_op_fcn> (f);
519  }
520 
523  {
524  void *f = binary_ops.checkelem (static_cast<int> (op), t1, t2);
525  return reinterpret_cast<type_info::binary_op_fcn> (f);
526  }
527 
530  {
531  void *f = compound_binary_class_ops.checkelem (static_cast<int> (op));
532  return reinterpret_cast<type_info::binary_class_op_fcn> (f);
533  }
534 
537  int t1, int t2)
538  {
539  void *f = compound_binary_ops.checkelem (static_cast<int> (op), t1, t2);
540  return reinterpret_cast<type_info::binary_op_fcn> (f);
541  }
542 
544  type_info::lookup_cat_op (int t1, int t2)
545  {
546  void *f = cat_ops.checkelem (t1, t2);
547  return reinterpret_cast<type_info::cat_op_fcn> (f);
548  }
549 
552  int t_lhs, int t_rhs)
553  {
554  void *f = assign_ops.checkelem (static_cast<int> (op), t_lhs, t_rhs);
555  return reinterpret_cast<type_info::assign_op_fcn> (f);
556  }
557 
560  {
561  void *f = assignany_ops.checkelem (static_cast<int> (op), t_lhs);
562  return reinterpret_cast<type_info::assignany_op_fcn> (f);
563  }
564 
565  int
566  type_info::lookup_pref_assign_conv (int t_lhs, int t_rhs)
567  {
568  return pref_assign_conv.checkelem (t_lhs, t_rhs);
569  }
570 
572  type_info::lookup_widening_op (int t, int t_result)
573  {
574  void *f = widening_ops.checkelem (t, t_result);
575  return reinterpret_cast<octave_base_value::type_conv_fcn> (f);
576  }
577 
580  {
582 
583  for (int i = 0; i < num_types; i++)
584  retval(i) = types(i);
585 
586  return retval;
587  }
588 
591  {
593 
594  int len = std::min (static_cast<int> (non_const_unary_ops.columns ()),
595  num_types);
596 
597  dim_vector tab_dims (1, len);
598 
599  for (int j = 0; j < octave_value::num_unary_ops; j++)
600  {
601  boolNDArray tab (tab_dims);
602 
603  for (int i = 0; i < len; i++)
604  tab.xelem (i) = (unary_ops(j,i) != nullptr);
605 
606  octave_value::unary_op op_id = static_cast<octave_value::unary_op> (j);
607 
608  retval.setfield (octave_value::unary_op_as_string (op_id), tab);
609  }
610 
611  return retval;
612  }
613 
616  {
618 
619  int len = std::min (static_cast<int> (non_const_unary_ops.columns ()),
620  num_types);
621 
622  dim_vector tab_dims (1, len);
623 
624  for (int j = 0; j < octave_value::num_unary_ops; j++)
625  {
626  boolNDArray tab (tab_dims);
627 
628  for (int i = 0; i < len; i++)
629  tab.xelem (i) = (non_const_unary_ops(j,i) != nullptr);
630 
631  octave_value::unary_op op_id = static_cast<octave_value::unary_op> (j);
632 
633  retval.setfield (octave_value::unary_op_as_string (op_id), tab);
634  }
635 
636  return retval;
637  }
638 
641  {
643 
644  int len = std::min (static_cast<int> (binary_ops.columns ()), num_types);
645 
646  dim_vector tab_dims (len, len);
647 
648  for (int k = 0; k < octave_value::num_binary_ops; k++)
649  {
650  boolNDArray tab (tab_dims);
651 
652  for (int j = 0; j < len; j++)
653  for (int i = 0; i < len; i++)
654  tab.xelem (j,i) = (binary_ops(k,j,i) != nullptr);
655 
656  octave_value::binary_op op_id = static_cast<octave_value::binary_op> (k);
657 
658  retval.setfield (octave_value::binary_op_as_string (op_id), tab);
659  }
660 
661  return retval;
662  }
663 
666  {
668 
669  int len = std::min (static_cast<int> (compound_binary_ops.columns ()),
670  num_types);
671 
672  dim_vector tab_dims (len, len);
673 
674  for (int k = 0; k < octave_value::num_compound_binary_ops; k++)
675  {
676  boolNDArray tab (tab_dims);
677 
678  for (int j = 0; j < len; j++)
679  for (int i = 0; i < len; i++)
680  tab.xelem (j,i) = (compound_binary_ops(k,j,i) != nullptr);
681 
683  = static_cast<octave_value::compound_binary_op> (k);
684 
685  retval.setfield (octave_value::binary_op_fcn_name (op_id), tab);
686  }
687 
688  return retval;
689  }
690 
693  {
695 
696  int len = std::min (static_cast<int> (assign_ops.columns ()), num_types);
697 
698  dim_vector tab_dims (len, len);
699 
700  for (int k = 0; k < octave_value::num_assign_ops; k++)
701  {
702  boolNDArray tab (tab_dims);
703 
704  for (int j = 0; j < len; j++)
705  for (int i = 0; i < len; i++)
706  tab.xelem (j,i) = (assign_ops(k,j,i) != nullptr);
707 
708  octave_value::assign_op op_id = static_cast<octave_value::assign_op> (k);
709 
710  retval.setfield (octave_value::assign_op_as_string (op_id), tab);
711  }
712 
713  return retval;
714  }
715 
718  {
720 
721  int len = std::min (static_cast<int> (assignany_ops.columns ()), num_types);
722 
723  dim_vector tab_dims (1, len);
724 
725  for (int j = 0; j < octave_value::num_assign_ops; j++)
726  {
727  boolNDArray tab (tab_dims);
728 
729  for (int i = 0; i < len; i++)
730  tab.xelem (i) = (assignany_ops(j,i) != nullptr);
731 
732  octave_value::assign_op op_id = static_cast<octave_value::assign_op> (j);
733 
734  retval.setfield (octave_value::assign_op_as_string (op_id), tab);
735  }
736 
737  return retval;
738  }
739 
742  {
744 
745  retval.setfield ("types", octave_value (Cell (installed_type_names ())));
746  retval.setfield ("unary_ops", unary_ops_map ());
747  retval.setfield ("non_const_unary_ops", non_const_unary_ops_map ());
748  retval.setfield ("binary_ops", binary_ops_map ());
749  retval.setfield ("compound_binary_ops", compound_binary_ops_map ());
750  retval.setfield ("cat_ops", as_bool_nd_array (cat_ops));
751  retval.setfield ("assign_ops", assign_ops_map ());
752  retval.setfield ("assignany_ops", assignany_ops_map ());
753  retval.setfield ("pref_assign_conv", as_nd_array (pref_assign_conv));
754  retval.setfield ("widening_ops", as_bool_nd_array (widening_ops));
755 
756  return retval;
757  }
758 }
759 
761 {
762  int register_type (const std::string& t_name, const std::string& c_name,
763  const octave_value& val)
764  {
765  octave::type_info& type_info
766  = octave::__get_type_info__ ("register_type");
767 
768  return type_info.register_type (t_name, c_name, val);
769  }
770 
773  {
774  octave::type_info& type_info
775  = octave::__get_type_info__ ("register_unary_class_op");
776 
777  return type_info.register_unary_class_op (op, f);
778  }
779 
781  int t, unary_op_fcn f)
782  {
783  octave::type_info& type_info
784  = octave::__get_type_info__ ("register_unary_op");
785 
786  return type_info.register_unary_op (op, t, f);
787  }
788 
791  {
792  octave::type_info& type_info
793  = octave::__get_type_info__ ("register_non_const_unary_op");
794 
795  return type_info.register_non_const_unary_op (op, t, f);
796  }
797 
800  {
801  octave::type_info& type_info
802  = octave::__get_type_info__ ("register_binary_class_op");
803 
804  return type_info.register_binary_class_op (op, f);
805  }
806 
808  int t1, int t2, binary_op_fcn f)
809  {
810  octave::type_info& type_info
811  = octave::__get_type_info__ ("register_binary_op");
812 
813  return type_info.register_binary_op (op, t1, t2, f);
814  }
815 
818  {
819  octave::type_info& type_info
820  = octave::__get_type_info__ ("register_binary_class_op");
821 
822  return type_info.register_binary_class_op (op, f);
823  }
824 
826  int t1, int t2, binary_op_fcn f)
827  {
828  octave::type_info& type_info
829  = octave::__get_type_info__ ("register_binary_op");
830 
831  return type_info.register_binary_op (op, t1, t2, f);
832  }
833 
834  bool register_cat_op (int t1, int t2, cat_op_fcn f)
835  {
836  octave::type_info& type_info
837  = octave::__get_type_info__ ("register_cat_op");
838 
839  return type_info.register_cat_op (t1, t2, f);
840  }
841 
843  int t_lhs, int t_rhs, assign_op_fcn f)
844  {
845  octave::type_info& type_info
846  = octave::__get_type_info__ ("register_assign_op");
847 
848  return type_info.register_assign_op (op, t_lhs, t_rhs, f);
849  }
850 
852  int t_lhs, assignany_op_fcn f)
853  {
854  octave::type_info& type_info
855  = octave::__get_type_info__ ("register_assignany_op");
856 
857  return type_info.register_assignany_op (op, t_lhs, f);
858  }
859 
860  bool register_pref_assign_conv (int t_lhs, int t_rhs, int t_result)
861  {
862  octave::type_info& type_info
863  = octave::__get_type_info__ ("register_pref_assign_conv");
864 
865  return type_info.register_pref_assign_conv (t_lhs, t_rhs, t_result);
866  }
867 
868  bool register_widening_op (int t, int t_result,
870  {
871  octave::type_info& type_info
872  = octave::__get_type_info__ ("register_widening_op");
873 
874  return type_info.register_widening_op (t, t_result, f);
875  }
876 
878  {
879  octave::type_info& type_info
880  = octave::__get_type_info__ ("lookup_type");
881 
882  return type_info.lookup_type (nm);
883  }
884 
886  {
887  octave::type_info& type_info
888  = octave::__get_type_info__ ("lookup_unary_class_op");
889 
890  return type_info.lookup_unary_class_op (op);
891  }
892 
894  {
895  octave::type_info& type_info
896  = octave::__get_type_info__ ("lookup_unary_op");
897 
898  return type_info.lookup_unary_op (op, t);
899  }
900 
903  {
904  octave::type_info& type_info
905  = octave::__get_type_info__ ("lookup_non_const_unary_op");
906 
907  return type_info.lookup_non_const_unary_op (op, t);
908  }
909 
912  {
913  octave::type_info& type_info
914  = octave::__get_type_info__ ("lookup_binary_class_op");
915 
916  return type_info.lookup_binary_class_op (op);
917  }
918 
921  {
922  octave::type_info& type_info
923  = octave::__get_type_info__ ("lookup_binary_op");
924 
925  return type_info.lookup_binary_op (op, t1, t2);
926  }
927 
930  {
931  octave::type_info& type_info
932  = octave::__get_type_info__ ("lookup_binary_class_op");
933 
934  return type_info.lookup_binary_class_op (op);
935  }
936 
939  {
940  octave::type_info& type_info
941  = octave::__get_type_info__ ("lookup_binary_op");
942 
943  return type_info.lookup_binary_op (op, t1, t2);
944  }
945 
946  cat_op_fcn lookup_cat_op (int t1, int t2)
947  {
948  octave::type_info& type_info
949  = octave::__get_type_info__ ("lookup_cat_op");
950 
951  return type_info.lookup_cat_op (t1, t2);
952  }
953 
955  lookup_assign_op (octave_value::assign_op op, int t_lhs, int t_rhs)
956  {
957  octave::type_info& type_info
958  = octave::__get_type_info__ ("lookup_assign_op");
959 
960  return type_info.lookup_assign_op (op, t_lhs, t_rhs);
961  }
962 
965  {
966  octave::type_info& type_info
967  = octave::__get_type_info__ ("lookup_assignany_op");
968 
969  return type_info.lookup_assignany_op (op, t_lhs);
970  }
971 
972  int lookup_pref_assign_conv (int t_lhs, int t_rhs)
973  {
974  octave::type_info& type_info
975  = octave::__get_type_info__ ("lookup_pref_assign_conv");
976 
977  return type_info.lookup_pref_assign_conv (t_lhs, t_rhs);
978  }
979 
981  lookup_widening_op (int t, int t_result)
982  {
983  octave::type_info& type_info
984  = octave::__get_type_info__ ("lookup_widening_op");
985 
986  return type_info.lookup_widening_op (t, t_result);
987  }
988 
990  {
991  octave::type_info& type_info
992  = octave::__get_type_info__ ("installed_type_names");
993 
994  return type_info.installed_type_names ();
995  }
996 
998  {
999  octave::type_info& type_info
1000  = octave::__get_type_info__ ("installed_type_info");
1001 
1002  return type_info.installed_type_info ();
1003  }
1004 }
1005 
1006 DEFMETHOD (typeinfo, interp, args, ,
1007  doc: /* -*- texinfo -*-
1008 @deftypefn {} {} typeinfo ()
1009 @deftypefnx {} {} typeinfo (@var{expr})
1010 
1011 Return the type of the expression @var{expr}, as a string.
1012 
1013 If @var{expr} is omitted, return a cell array of strings containing all the
1014 currently installed data types.
1015 @seealso{class, isa}
1016 @end deftypefn */)
1017 {
1018  int nargin = args.length ();
1019 
1020  if (nargin > 1)
1021  print_usage ();
1022 
1023  if (nargin == 0)
1024  {
1025  octave::type_info& type_info = interp.get_type_info ();
1026 
1027  return ovl (Cell (type_info.installed_type_names ()));
1028  }
1029  else
1030  return ovl (args(0).type_name ());
1031 }
1032 
1033 /*
1034 %!assert (iscellstr (typeinfo ()))
1035 
1036 %!assert (typeinfo ({"cell"}), "cell")
1037 
1038 %!assert (typeinfo (1), "scalar")
1039 %!assert (typeinfo (double (1)), "scalar")
1040 %!assert (typeinfo (i), "complex scalar")
1041 
1042 %!assert (typeinfo ([1, 2]), "matrix")
1043 %!assert (typeinfo (double ([1, 2])), "matrix")
1044 %!assert (typeinfo (diag ([1, 2])), "diagonal matrix")
1045 %!assert (typeinfo ([i, 2]), "complex matrix")
1046 %!assert (typeinfo (diag ([i, 2])), "complex diagonal matrix")
1047 
1048 %!assert (typeinfo (1:2), "range")
1049 
1050 %!assert (typeinfo (false), "bool")
1051 %!assert (typeinfo ([true, false]), "bool matrix")
1052 
1053 %!assert (typeinfo ("string"), "string")
1054 %!assert (typeinfo ('string'), "sq_string")
1055 
1056 %!assert (typeinfo (int8 (1)), "int8 scalar")
1057 %!assert (typeinfo (int16 (1)), "int16 scalar")
1058 %!assert (typeinfo (int32 (1)), "int32 scalar")
1059 %!assert (typeinfo (int64 (1)), "int64 scalar")
1060 %!assert (typeinfo (uint8 (1)), "uint8 scalar")
1061 %!assert (typeinfo (uint16 (1)), "uint16 scalar")
1062 %!assert (typeinfo (uint32 (1)), "uint32 scalar")
1063 %!assert (typeinfo (uint64 (1)), "uint64 scalar")
1064 
1065 %!assert (typeinfo (int8 ([1,2])), "int8 matrix")
1066 %!assert (typeinfo (int16 ([1,2])), "int16 matrix")
1067 %!assert (typeinfo (int32 ([1,2])), "int32 matrix")
1068 %!assert (typeinfo (int64 ([1,2])), "int64 matrix")
1069 %!assert (typeinfo (uint8 ([1,2])), "uint8 matrix")
1070 %!assert (typeinfo (uint16 ([1,2])), "uint16 matrix")
1071 %!assert (typeinfo (uint32 ([1,2])), "uint32 matrix")
1072 %!assert (typeinfo (uint64 ([1,2])), "uint64 matrix")
1073 
1074 %!assert (typeinfo (sparse ([true, false])), "sparse bool matrix")
1075 %!assert (typeinfo (logical (sparse (i * eye (10)))), "sparse bool matrix")
1076 %!assert (typeinfo (sparse ([1,2])), "sparse matrix")
1077 %!assert (typeinfo (sparse (eye (10))), "sparse matrix")
1078 %!assert (typeinfo (sparse ([i,2])), "sparse complex matrix")
1079 %!assert (typeinfo (sparse (i * eye (10))), "sparse complex matrix")
1080 
1081 %!test
1082 %! s(2).a = 1;
1083 %! assert (typeinfo (s), "struct");
1084 
1085 %!test
1086 %! s.a = 1;
1087 %! assert (typeinfo (s), "scalar struct");
1088 
1089 ## FIXME: This doesn't work as a test for comma-separated list
1090 %!#test
1091 %! clist = {1, 2, 3};
1092 %! assert (typeinfo (clist{:}), "cs-list");
1093 
1094 %!assert (typeinfo (@sin), "function handle")
1095 %!assert (typeinfo (@(x) x), "function handle")
1096 
1097 %!assert (typeinfo (inline ("x^2")), "inline function")
1098 
1099 %!assert (typeinfo (single (1)), "float scalar")
1100 %!assert (typeinfo (single (i)), "float complex scalar")
1101 %!assert (typeinfo (single ([1, 2])), "float matrix")
1102 
1103 %!assert (typeinfo (single (diag ([1, 2]))), "float diagonal matrix")
1104 %!assert (typeinfo (diag (single ([1, 2]))), "float diagonal matrix")
1105 %!assert (typeinfo (single (diag ([i, 2]))), "float complex diagonal matrix")
1106 %!assert (typeinfo (diag (single ([i, 2]))), "float complex diagonal matrix")
1107 
1108 %!assert (typeinfo (eye(3)(:,[1 3 2])), "permutation matrix")
1109 %!test
1110 %! [l, u, p] = lu (rand (3));
1111 %! assert (typeinfo (p), "permutation matrix");
1112 
1113 %!assert (typeinfo ([]), "null_matrix")
1114 %!assert (typeinfo (""), "null_string")
1115 %!assert (typeinfo (''), "null_sq_string")
1116 
1117 %!test
1118 %! cvar = onCleanup (@() "");
1119 %! assert (typeinfo (cvar), "onCleanup");
1120 
1121 %!testif HAVE_JAVA; usejava ("jvm")
1122 %! x = javaObject ("java.lang.StringBuffer");
1123 %! assert (typeinfo (x), "octave_java");
1124 
1125 ## Test input validation
1126 %!error typeinfo ("foo", 1)
1127 */
1128 
1129 DEFMETHOD (__dump_typeinfo__, interp, args, ,
1130  doc: /* -*- texinfo -*-
1131 @deftypefn {} {} __dump_typeinfo__ ()
1132 Undocumented internal function.
1133 @end deftypefn */)
1134 {
1135  if (args.length () > 0)
1136  print_usage ();
1137 
1138  octave::type_info& type_info = interp.get_type_info ();
1139 
1140  return ovl (type_info.installed_type_info ());
1141 }
octave::type_info::assignany_op_fcn assignany_op_fcn
Definition: ov-typeinfo.h:283
bool register_cat_op(int t1, int t2, cat_op_fcn f)
Definition: ov-typeinfo.cc:834
octave::type_info::unary_op_fcn unary_op_fcn
Definition: ov-typeinfo.h:271
bool register_assign_op(octave_value::assign_op, int, int, assign_op_fcn, bool abort_on_duplicate=false)
Definition: ov-typeinfo.cc:370
static NDArray as_nd_array(const Array< int > &x)
Definition: ov-typeinfo.cc:41
octave_scalar_map assignany_ops_map(void) const
Definition: ov-typeinfo.cc:717
bool register_unary_op(octave_value::unary_op op, int t, unary_op_fcn f)
Definition: ov-typeinfo.cc:780
Array< void * > non_const_unary_ops
Definition: ov-typeinfo.h:245
octave_scalar_map non_const_unary_ops_map(void) const
Definition: ov-typeinfo.cc:615
octave_value lookup_type(const std::string &nm)
Definition: ov-typeinfo.cc:476
Array< std::string > types
Definition: ov-typeinfo.h:237
Definition: Cell.h:37
octave_value(* binary_class_op_fcn)(const octave_value &, const octave_value &)
Definition: ov-typeinfo.h:50
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
Definition: defun.h:135
assign_op
Definition: ov.h:136
Array< void * > cat_ops
Definition: ov-typeinfo.h:255
Array< void * > compound_binary_class_ops
Definition: ov-typeinfo.h:251
unary_op_fcn lookup_unary_op(octave_value::unary_op, int)
Definition: ov-typeinfo.cc:501
octave_value(* cat_op_fcn)(octave_base_value &, const octave_base_value &, const Array< octave_idx_type > &ra_idx)
Definition: ov-typeinfo.h:56
OCTINTERP_API void print_usage(void)
Definition: defun.cc:54
static std::string binary_op_as_string(binary_op)
Definition: ov.cc:177
octave_value(* binary_op_fcn)(const octave_base_value &, const octave_base_value &)
Definition: ov-typeinfo.h:53
Array< octave_value * > vals
Definition: ov-typeinfo.h:239
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:4986
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE * f
octave_base_value::type_conv_fcn lookup_widening_op(int t, int t_result)
Definition: ov-typeinfo.cc:981
octave_value(* assignany_op_fcn)(octave_base_value &, const octave_value_list &, const octave_value &)
Definition: ov-typeinfo.h:63
void install_types(octave::type_info &ti)
Definition: ov.cc:2894
bool register_pref_assign_conv(int, int, int, bool abort_on_duplicate=false)
Definition: ov-typeinfo.cc:425
octave_base_value::type_conv_fcn lookup_widening_op(int, int)
Definition: ov-typeinfo.cc:572
for large enough k
Definition: lu.cc:617
binary_op
Definition: ov.h:94
binary_op_fcn lookup_binary_op(octave_value::binary_op, int, int)
Definition: ov-typeinfo.cc:522
void(* non_const_unary_op_fcn)(octave_base_value &)
Definition: ov-typeinfo.h:47
void make_unique(void)
Definition: ov.h:328
octave_value lookup_type(const std::string &nm)
Definition: ov-typeinfo.cc:877
bool register_binary_op(octave_value::binary_op, int, int, binary_op_fcn, bool abort_on_duplicate=false)
Definition: ov-typeinfo.cc:262
string_vector installed_type_names(void) const
Definition: ov-typeinfo.cc:579
assignany_op_fcn lookup_assignany_op(octave_value::assign_op op, int t_lhs)
Definition: ov-typeinfo.cc:964
Array< void * > binary_class_ops
Definition: ov-typeinfo.h:247
static std::string assign_op_as_string(assign_op)
Definition: ov.cc:348
octave_idx_type columns(void) const
Definition: Array.h:413
octave::type_info::unary_class_op_fcn unary_class_op_fcn
Definition: ov-typeinfo.h:269
int lookup_pref_assign_conv(int t_lhs, int t_rhs)
Definition: ov-typeinfo.cc:972
binary_op_fcn lookup_binary_op(octave_value::binary_op op, int t1, int t2)
Definition: ov-typeinfo.cc:920
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function t
Definition: ov-usr-fcn.cc:997
binary_class_op_fcn lookup_binary_class_op(octave_value::binary_op)
Definition: ov-typeinfo.cc:515
unary_class_op_fcn lookup_unary_class_op(octave_value::unary_op op)
Definition: ov-typeinfo.cc:885
assign_op_fcn lookup_assign_op(octave_value::assign_op op, int t_lhs, int t_rhs)
Definition: ov-typeinfo.cc:955
octave::type_info::non_const_unary_op_fcn non_const_unary_op_fcn
Definition: ov-typeinfo.h:273
bool register_pref_assign_conv(int t_lhs, int t_rhs, int t_result)
Definition: ov-typeinfo.cc:860
octave_value(* unary_op_fcn)(const octave_base_value &)
Definition: ov-typeinfo.h:45
octave_scalar_map binary_ops_map(void) const
Definition: ov-typeinfo.cc:640
octave_value(* assign_op_fcn)(octave_base_value &, const octave_value_list &, const octave_base_value &)
Definition: ov-typeinfo.h:60
Array< void * > assignany_ops
Definition: ov-typeinfo.h:259
octave_scalar_map assign_ops_map(void) const
Definition: ov-typeinfo.cc:692
type_info(int init_tab_sz=16)
Definition: ov-typeinfo.cc:64
octave_scalar_map installed_type_info(void) const
Definition: ov-typeinfo.cc:741
assign_op_fcn lookup_assign_op(octave_value::assign_op, int, int)
Definition: ov-typeinfo.cc:551
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
Definition: utils.cc:975
Array< void * > widening_ops
Definition: ov-typeinfo.h:263
octave_scalar_map installed_type_info(void)
Definition: ov-typeinfo.cc:997
type_info & __get_type_info__(const std::string &who)
cat_op_fcn lookup_cat_op(int, int)
Definition: ov-typeinfo.cc:544
Array< void * > assign_ops
Definition: ov-typeinfo.h:257
bool register_unary_op(octave_value::unary_op, int, unary_op_fcn, bool abort_on_duplicate=false)
Definition: ov-typeinfo.cc:184
int lookup_pref_assign_conv(int, int)
Definition: ov-typeinfo.cc:566
bool register_non_const_unary_op(octave_value::unary_op op, int t, non_const_unary_op_fcn f)
Definition: ov-typeinfo.cc:789
unary_op_fcn lookup_unary_op(octave_value::unary_op op, int t)
Definition: ov-typeinfo.cc:893
bool register_cat_op(int, int, cat_op_fcn, bool abort_on_duplicate=false)
Definition: ov-typeinfo.cc:346
static std::string binary_op_fcn_name(binary_op)
Definition: ov.cc:244
bool register_assign_op(octave_value::assign_op op, int t_lhs, int t_rhs, assign_op_fcn f)
Definition: ov-typeinfo.cc:842
void resize(const dim_vector &dv, const T &rfv)
Resizing (with fill).
Definition: Array.cc:1010
Array< void * > compound_binary_ops
Definition: ov-typeinfo.h:253
Array< void * > unary_ops
Definition: ov-typeinfo.h:243
octave_value retval
Definition: data.cc:6246
bool register_assignany_op(octave_value::assign_op, int, assignany_op_fcn, bool abort_on_duplicate=false)
Definition: ov-typeinfo.cc:399
string_vector installed_type_names(void)
Definition: ov-typeinfo.cc:989
bool register_non_const_unary_op(octave_value::unary_op, int, non_const_unary_op_fcn, bool abort_on_duplicate=false)
Definition: ov-typeinfo.cc:209
bool register_unary_class_op(octave_value::unary_op, unary_class_op_fcn, bool abort_on_duplicate=false)
Definition: ov-typeinfo.cc:159
bool register_unary_class_op(octave_value::unary_op op, unary_class_op_fcn f)
Definition: ov-typeinfo.cc:771
bool register_binary_class_op(octave_value::binary_op, binary_class_op_fcn, bool abort_on_duplicate=false)
Definition: ov-typeinfo.cc:236
octave_scalar_map compound_binary_ops_map(void) const
Definition: ov-typeinfo.cc:665
Array< void * > binary_ops
Definition: ov-typeinfo.h:249
bool register_binary_class_op(octave_value::binary_op op, binary_class_op_fcn f)
Definition: ov-typeinfo.cc:798
T & xelem(octave_idx_type n)
Definition: Array.h:458
void install_ops(octave::type_info &)
void warning(const char *fmt,...)
Definition: error.cc:801
octave_scalar_map unary_ops_map(void) const
Definition: ov-typeinfo.cc:590
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
int register_type(const std::string &, const std::string &, const octave_value &, bool abort_on_duplicate=false)
Definition: ov-typeinfo.cc:85
non_const_unary_op_fcn lookup_non_const_unary_op(octave_value::unary_op op, int t)
Definition: ov-typeinfo.cc:902
bool register_assignany_op(octave_value::assign_op op, int t_lhs, assignany_op_fcn f)
Definition: ov-typeinfo.cc:851
OCTAVE_EXPORT octave_value_list isa nd deftypefn *return ovl(args(0).isinteger())
T & checkelem(octave_idx_type n)
Definition: Array.cc:191
static boolNDArray as_bool_nd_array(const Array< void *> &x)
Definition: ov-typeinfo.cc:52
unary_class_op_fcn lookup_unary_class_op(octave_value::unary_op)
Definition: ov-typeinfo.cc:494
bool register_widening_op(int t, int t_result, octave_base_value::type_conv_fcn f)
Definition: ov-typeinfo.cc:868
int register_type(const std::string &t_name, const std::string &c_name, const octave_value &val)
Definition: ov-typeinfo.cc:762
octave::type_info::binary_op_fcn binary_op_fcn
Definition: ov-typeinfo.h:277
octave::type_info::binary_class_op_fcn binary_class_op_fcn
Definition: ov-typeinfo.h:275
compound_binary_op
Definition: ov.h:119
Array< void * > unary_class_ops
Definition: ov-typeinfo.h:241
args.length() nargin
Definition: file-io.cc:589
octave::type_info::assign_op_fcn assign_op_fcn
Definition: ov-typeinfo.h:281
octave::type_info::cat_op_fcn cat_op_fcn
Definition: ov-typeinfo.h:279
octave_value(* unary_class_op_fcn)(const octave_value &)
Definition: ov-typeinfo.h:43
for i
Definition: data.cc:5264
binary_class_op_fcn lookup_binary_class_op(octave_value::binary_op op)
Definition: ov-typeinfo.cc:911
bool register_widening_op(int, int, octave_base_value::type_conv_fcn, bool abort_on_duplicate=false)
Definition: ov-typeinfo.cc:451
assignany_op_fcn lookup_assignany_op(octave_value::assign_op, int)
Definition: ov-typeinfo.cc:559
non_const_unary_op_fcn lookup_non_const_unary_op(octave_value::unary_op, int)
Definition: ov-typeinfo.cc:508
static std::string unary_op_as_string(unary_op)
Definition: ov.cc:121
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:366
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
unary_op
Definition: ov.h:81
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888
bool register_binary_op(octave_value::binary_op op, int t1, int t2, binary_op_fcn f)
Definition: ov-typeinfo.cc:807
octave_base_value *(* type_conv_fcn)(const octave_base_value &)
Definition: ov-base.h:207
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE * x
cat_op_fcn lookup_cat_op(int t1, int t2)
Definition: ov-typeinfo.cc:946
charNDArray min(char d, const charNDArray &m)
Definition: chNDArray.cc:204
Array< int > pref_assign_conv
Definition: ov-typeinfo.h:261