changeset 24565:dbec1e04f499

accept type_info obj as arg to binary_op, unary_op, and cat_op functions * ov.h, ov.cc (do_binary_op, do_unary_op, do_cat_op): New verloads that accept reference to type_info object as argument. (decompose_binary_op): New aregument, reference to type_info object. * pt-eval.cc (tree_evaluator::visit_binary_expression): Pass type_info object to do_binary_op. (tree_evaluator::visit_postfix_expression, tree_evaluator::visit_prefix_expression): Pass type_info object to do_unary_op. (tree_evaluator::visit_matrix): Pass type_info object to do_cat_op.
author John W. Eaton <jwe@octave.org>
date Mon, 08 Jan 2018 16:45:26 -0500
parents 07876b7127bf
children f5bcbd321ba1
files libinterp/octave-value/ov.cc libinterp/octave-value/ov.h libinterp/parse-tree/pt-eval.cc
diffstat 3 files changed, 108 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/octave-value/ov.cc	Mon Jan 08 15:51:52 2018 -0500
+++ b/libinterp/octave-value/ov.cc	Mon Jan 08 16:45:26 2018 -0500
@@ -2155,7 +2155,7 @@
 }
 
 octave_value
-do_binary_op (octave_value::binary_op op,
+do_binary_op (octave::type_info& ti, octave_value::binary_op op,
               const octave_value& v1, const octave_value& v2)
 {
   octave_value retval;
@@ -2163,8 +2163,6 @@
   int t1 = v1.type_id ();
   int t2 = v2.type_id ();
 
-  octave::type_info& ti = octave::__get_type_info__ ("do_binary_op");
-
   if (t1 == octave_class::static_type_id ()
       || t2 == octave_class::static_type_id ()
       || t1 == octave_classdef::static_type_id ()
@@ -2292,8 +2290,18 @@
   return retval;
 }
 
+octave_value
+do_binary_op (octave_value::binary_op op,
+              const octave_value& v1, const octave_value& v2)
+{
+  octave::type_info& ti = octave::__get_type_info__ ("do_binary_op");
+
+  return do_binary_op (ti, op, v1, v2);
+}
+
 static octave_value
-decompose_binary_op (octave_value::compound_binary_op op,
+decompose_binary_op (octave::type_info& ti,
+                     octave_value::compound_binary_op op,
                      const octave_value& v1, const octave_value& v2)
 {
   switch (op)
@@ -2303,39 +2311,39 @@
                            do_unary_op (octave_value::op_transpose, v1), v2);
 
     case octave_value::op_mul_trans:
-      return do_binary_op (octave_value::op_mul,
+      return do_binary_op (ti, octave_value::op_mul,
                            v1, do_unary_op (octave_value::op_transpose, v2));
 
     case octave_value::op_herm_mul:
-      return do_binary_op (octave_value::op_mul,
+      return do_binary_op (ti, octave_value::op_mul,
                            do_unary_op (octave_value::op_hermitian, v1), v2);
 
     case octave_value::op_mul_herm:
-      return do_binary_op (octave_value::op_mul,
+      return do_binary_op (ti, octave_value::op_mul,
                            v1, do_unary_op (octave_value::op_hermitian, v2));
 
     case octave_value::op_trans_ldiv:
-      return do_binary_op (octave_value::op_ldiv,
+      return do_binary_op (ti, octave_value::op_ldiv,
                            do_unary_op (octave_value::op_transpose, v1), v2);
 
     case octave_value::op_herm_ldiv:
-      return do_binary_op (octave_value::op_ldiv,
+      return do_binary_op (ti, octave_value::op_ldiv,
                            do_unary_op (octave_value::op_hermitian, v1), v2);
 
     case octave_value::op_el_not_and:
-      return do_binary_op (octave_value::op_el_and,
+      return do_binary_op (ti, octave_value::op_el_and,
                            do_unary_op (octave_value::op_not, v1), v2);
 
     case octave_value::op_el_not_or:
-      return do_binary_op (octave_value::op_el_or,
+      return do_binary_op (ti, octave_value::op_el_or,
                            do_unary_op (octave_value::op_not, v1), v2);
 
     case octave_value::op_el_and_not:
-      return do_binary_op (octave_value::op_el_and,
+      return do_binary_op (ti, octave_value::op_el_and,
                            v1, do_unary_op (octave_value::op_not, v2));
 
     case octave_value::op_el_or_not:
-      return do_binary_op (octave_value::op_el_or,
+      return do_binary_op (ti, octave_value::op_el_or,
                            v1, do_unary_op (octave_value::op_not, v2));
 
     default:
@@ -2344,7 +2352,7 @@
 }
 
 octave_value
-do_binary_op (octave_value::compound_binary_op op,
+do_binary_op (octave::type_info& ti, octave_value::compound_binary_op op,
               const octave_value& v1, const octave_value& v2)
 {
   octave_value retval;
@@ -2352,8 +2360,6 @@
   int t1 = v1.type_id ();
   int t2 = v2.type_id ();
 
-  octave::type_info& ti = octave::__get_type_info__ ("do_binary_op");
-
   if (t1 == octave_class::static_type_id ()
       || t2 == octave_class::static_type_id ()
       || t1 == octave_classdef::static_type_id ()
@@ -2364,7 +2370,7 @@
       if (f)
         retval = f (v1, v2);
       else
-        retval = decompose_binary_op (op, v1, v2);
+        retval = decompose_binary_op (ti, op, v1, v2);
     }
   else
     {
@@ -2373,12 +2379,21 @@
       if (f)
         retval = f (*v1.rep, *v2.rep);
       else
-        retval = decompose_binary_op (op, v1, v2);
+        retval = decompose_binary_op (ti, op, v1, v2);
     }
 
   return retval;
 }
 
+octave_value
+do_binary_op (octave_value::compound_binary_op op,
+              const octave_value& v1, const octave_value& v2)
+{
+  octave::type_info& ti = octave::__get_type_info__ ("do_binary_op");
+
+  return do_binary_op (ti, op, v1, v2);
+}
+
 OCTAVE_NORETURN static void
 err_cat_op (const std::string& tn1, const std::string& tn2)
 {
@@ -2393,8 +2408,8 @@
 }
 
 octave_value
-do_cat_op (const octave_value& v1, const octave_value& v2,
-           const Array<octave_idx_type>& ra_idx)
+do_cat_op (octave::type_info& ti, const octave_value& v1,
+           const octave_value& v2, const Array<octave_idx_type>& ra_idx)
 {
   octave_value retval;
 
@@ -2404,8 +2419,6 @@
   int t1 = v1.type_id ();
   int t2 = v2.type_id ();
 
-  octave::type_info& ti = octave::__get_type_info__ ("do_cat_op");
-
   octave::type_info::cat_op_fcn f = ti.lookup_cat_op (t1, t2);
 
   if (f)
@@ -2453,13 +2466,22 @@
       if (! cf1 && ! cf2)
         err_cat_op (v1.type_name (), v2.type_name ());
 
-      retval = do_cat_op (tv1, tv2, ra_idx);
+      retval = do_cat_op (ti, tv1, tv2, ra_idx);
     }
 
   return retval;
 }
 
 octave_value
+do_cat_op (const octave_value& v1, const octave_value& v2,
+           const Array<octave_idx_type>& ra_idx)
+{
+  octave::type_info& ti = octave::__get_type_info__ ("do_cat_op");
+
+  return do_cat_op (ti, v1, v2, ra_idx);
+}
+
+octave_value
 do_colon_op (const octave_value& base, const octave_value& increment,
              const octave_value& limit, bool is_for_cmd_expr)
 {
@@ -2583,14 +2605,13 @@
 }
 
 octave_value
-do_unary_op (octave_value::unary_op op, const octave_value& v)
+do_unary_op (octave::type_info& ti, octave_value::unary_op op,
+             const octave_value& v)
 {
   octave_value retval;
 
   int t = v.type_id ();
 
-  octave::type_info& ti = octave::__get_type_info__ ("do_unary_op");
-
   if (t == octave_class::static_type_id ()
       || t == octave_classdef::static_type_id ())
     {
@@ -2633,6 +2654,14 @@
   return retval;
 }
 
+octave_value
+do_unary_op (octave_value::unary_op op, const octave_value& v)
+{
+  octave::type_info& ti = octave::__get_type_info__ ("do_unary_op");
+
+  return do_unary_op (ti, op, v);
+}
+
 OCTAVE_NORETURN static void
 err_unary_op_conversion_failed (const std::string& op,
                                 const std::string& tn)
--- a/libinterp/octave-value/ov.h	Mon Jan 08 15:51:52 2018 -0500
+++ b/libinterp/octave-value/ov.h	Mon Jan 08 16:45:26 2018 -0500
@@ -1283,25 +1283,25 @@
 
   // Unary and binary operations.
 
-  friend OCTINTERP_API octave_value do_unary_op (unary_op op,
-                                                 const octave_value& a);
+  friend OCTINTERP_API octave_value
+  do_unary_op (octave::type_info& ti, unary_op op, const octave_value& a);
 
   octave_value& do_non_const_unary_op (unary_op op);
 
   octave_value& do_non_const_unary_op (unary_op op, const std::string& type,
                                        const std::list<octave_value_list>& idx);
 
-  friend OCTINTERP_API octave_value do_binary_op (binary_op op,
-                                                  const octave_value& a,
-                                                  const octave_value& b);
+  friend OCTINTERP_API octave_value
+  do_binary_op (octave::type_info& ti, binary_op op,
+                const octave_value& a, const octave_value& b);
 
-  friend OCTINTERP_API octave_value do_binary_op (compound_binary_op op,
-                                                  const octave_value& a,
-                                                  const octave_value& b);
+  friend OCTINTERP_API octave_value
+  do_binary_op (octave::type_info& ti, compound_binary_op op,
+                const octave_value& a, const octave_value& b);
 
-  friend OCTINTERP_API octave_value do_cat_op (const octave_value& a,
-                                               const octave_value& b,
-                                               const Array<octave_idx_type>& ra_idx);
+  friend OCTINTERP_API octave_value
+  do_cat_op (octave::type_info& ti, const octave_value& a,
+             const octave_value& b, const Array<octave_idx_type>& ra_idx);
 
   friend OCTINTERP_API octave_value do_colon_op (const octave_value& base,
                                                  const octave_value& limit,
@@ -1512,18 +1512,39 @@
 
 };
 
-// Publish externally used friend functions.
+// Publish externally used friend functions.  Which compiler requires
+// these extra declarations?
+
+extern OCTINTERP_API octave_value
+do_unary_op (octave::type_info& ti, octave_value::unary_op op,
+             const octave_value& a);
 
 extern OCTINTERP_API octave_value
 do_unary_op (octave_value::unary_op op, const octave_value& a);
 
 extern OCTINTERP_API octave_value
-do_binary_op (octave_value::binary_op op,
+do_binary_op (octave::type_info& ti, octave_value::binary_op op,
+              const octave_value& a, const octave_value& b);
+
+extern OCTINTERP_API octave_value
+do_binary_op (octave::type_info& ti, octave_value::compound_binary_op op,
               const octave_value& a, const octave_value& b);
 
 extern OCTINTERP_API octave_value
-do_binary_op (octave_value::compound_binary_op op,
-              const octave_value& a, const octave_value& b);
+do_binary_op (octave_value::binary_op op, const octave_value& a,
+              const octave_value& b);
+
+extern OCTINTERP_API octave_value
+do_binary_op (octave_value::compound_binary_op op, const octave_value& a,
+              const octave_value& b);
+
+extern OCTINTERP_API octave_value
+do_cat_op (octave::type_info& ti, const octave_value& a,
+           const octave_value& b, const Array<octave_idx_type>& ra_idx);
+
+extern OCTINTERP_API octave_value
+do_cat_op (const octave_value& a, const octave_value& b,
+           const Array<octave_idx_type>& ra_idx);
 
 #define OV_UNOP_FN(name)                        \
   inline octave_value                           \
--- a/libinterp/parse-tree/pt-eval.cc	Mon Jan 08 15:51:52 2018 -0500
+++ b/libinterp/parse-tree/pt-eval.cc	Mon Jan 08 16:45:26 2018 -0500
@@ -234,7 +234,9 @@
                 // is entangled and it's not clear where to start/stop
                 // timing the operator to make it reasonable.
 
-                val = ::do_binary_op (etype, a, b);
+                type_info& ti = m_interpreter.get_type_info ();
+
+                val = ::do_binary_op (ti, etype, a, b);
               }
           }
       }
@@ -317,7 +319,9 @@
               {
                 octave_value::compound_binary_op etype = expr.cop_type ();
 
-                val = ::do_binary_op (etype, a, b);
+                type_info& ti = m_interpreter.get_type_info ();
+
+                val = ::do_binary_op (ti, etype, a, b);
               }
           }
       }
@@ -1711,6 +1715,8 @@
             // Now, extract the values from the individual elements and
             // insert them in the result matrix.
 
+            type_info& ti = m_interpreter.get_type_info ();
+
             int dv_len = dv.ndims ();
             octave_idx_type ntmp = (dv_len > 1 ? dv_len : 2);
             Array<octave_idx_type> ra_idx (dim_vector (ntmp, 1), 0);
@@ -1726,7 +1732,7 @@
                     if (elt.isempty ())
                       continue;
 
-                    ctmp = do_cat_op (ctmp, elt, ra_idx);
+                    ctmp = do_cat_op (ti, ctmp, elt, ra_idx);
 
                     ra_idx (1) += elt.columns ();
                   }
@@ -2075,7 +2081,9 @@
                 profiler::enter<tree_postfix_expression>
                   block (m_profiler, expr);
 
-                val = ::do_unary_op (etype, op_val);
+                type_info& ti = m_interpreter.get_type_info ();
+
+                val = ::do_unary_op (ti, etype, op_val);
               }
           }
       }
@@ -2118,7 +2126,11 @@
                 if (op_val.get_count () == 1)
                   val = op_val.do_non_const_unary_op (etype);
                 else
-                  val = ::do_unary_op (etype, op_val);
+                  {
+                    type_info& ti = m_interpreter.get_type_info ();
+
+                    val = ::do_unary_op (ti, etype, op_val);
+                  }
               }
           }
       }