diff libinterp/parse-tree/pt-classdef.cc @ 27371:fcaecdbc8d8a

don't use visitor pattern for expression evaluation (bug #56752) Although it is desirable to have all parse tree evaluation functions grouped together in a single file, using the visitor pattern can be inefficient, especially when the visitor function is small and the extra levels of indirection and virtual function resolution can take more time than the evaluation function itself (evaluation of constants, for example). For all classes derived from tree_expression, introduce new evaluate and evaluate_n methods. Use those instead of visit_CLASS functions to perform expression evaluation. Results are now returned directly from the evaluation functions instead of storing them in the tree_evaluator object. Files affected: cdef-class.cc, oct-parse.yy, pt-assign.cc, pt-assign.h, pt-binop.cc, pt-binop.h, pt-cbinop.cc, pt-cbinop.h, pt-cell.cc, pt-cell.h, pt-classdef.cc, pt-classdef.h, pt-colon.cc, pt-colon.h, pt-const.h, pt-eval.cc, pt-eval.h, pt-exp.h, pt-fcn-handle.cc, pt-fcn-handle.h, pt-id.cc, pt-id.h, pt-idx.cc, pt-idx.h, pt-loop.cc, pt-mat.cc, pt-mat.h, pt-select.cc, pt-tm-const.cc, pt-unop.cc, and pt-unop.h.
author John W. Eaton <jwe@octave.org>
date Fri, 30 Aug 2019 15:02:14 -0400
parents 9b0335f4bc74
children c409d16b7190
line wrap: on
line diff
--- a/libinterp/parse-tree/pt-classdef.cc	Wed Aug 28 21:38:34 2019 -0400
+++ b/libinterp/parse-tree/pt-classdef.cc	Fri Aug 30 15:02:14 2019 -0400
@@ -24,8 +24,10 @@
 #  include "config.h"
 #endif
 
+#include "ov.h"
 #include "ov-classdef.h"
 #include "pt-classdef.h"
+#include "pt-eval.h"
 
 namespace octave
 {
@@ -41,6 +43,32 @@
     return new_scr;
   }
 
+  octave_value_list
+  tree_superclass_ref::evaluate_n (tree_evaluator& tw, int nargout)
+  {
+    octave_value tmp
+      = octave_classdef::superclass_ref (m_method_name, m_class_name);
+
+    if (! is_postfix_indexed ())
+      {
+        // There was no index, so this superclass_ref object is not
+        // part of an index expression.  It is also not an identifier in
+        // the syntax tree but we need to handle it as if it were.  So
+        // call the function here.
+
+        octave_function *f = tmp.function_value (true);
+
+        assert (f);
+
+        return f->call (tw, nargout);
+      }
+
+    // The superclass_ref function object will be indexed as part of the
+    // enclosing index expression.
+
+    return ovl (tmp);
+  }
+
   tree_metaclass_query *
   tree_metaclass_query::dup (symbol_scope&) const
   {
@@ -52,6 +80,12 @@
     return new_mcq;
   }
 
+  octave_value
+  tree_metaclass_query::evaluate (tree_evaluator&, int)
+  {
+    return octave_classdef::metaclass_query (m_class_name);
+  }
+
   // Classdef attribute
 
   // Classdef attribute_list