comparison libinterp/parse-tree/oct-parse.yy @ 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 823b4bcf79fc
children 9b19eec60931
comparison
equal deleted inserted replaced
27370:a2d3fa82b730 27371:fcaecdbc8d8a
2533 { 2533 {
2534 try 2534 try
2535 { 2535 {
2536 tree_evaluator& tw = interp.get_evaluator (); 2536 tree_evaluator& tw = interp.get_evaluator ();
2537 2537
2538 octave_value tmp = tw.evaluate (e); 2538 octave_value tmp = e->evaluate (tw);
2539 2539
2540 tree_constant *tc_retval 2540 tree_constant *tc_retval
2541 = new tree_constant (tmp, e->line (), e->column ()); 2541 = new tree_constant (tmp, e->line (), e->column ());
2542 2542
2543 std::ostringstream buf; 2543 std::ostringstream buf;
4110 if (e->is_constant ()) 4110 if (e->is_constant ())
4111 { 4111 {
4112 tree_evaluator& tw 4112 tree_evaluator& tw
4113 = __get_evaluator__ ("validate_matrix_for_assignment"); 4113 = __get_evaluator__ ("validate_matrix_for_assignment");
4114 4114
4115 octave_value ov = tw.evaluate (e); 4115 octave_value ov = e->evaluate (tw);
4116 4116
4117 delete e; 4117 delete e;
4118 4118
4119 if (ov.isempty ()) 4119 if (ov.isempty ())
4120 bison_error ("invalid empty left hand side of assignment"); 4120 bison_error ("invalid empty left hand side of assignment");
4185 { 4185 {
4186 try 4186 try
4187 { 4187 {
4188 tree_evaluator& tw = interp.get_evaluator (); 4188 tree_evaluator& tw = interp.get_evaluator ();
4189 4189
4190 octave_value tmp = tw.evaluate (array_list); 4190 octave_value tmp = array_list->evaluate (tw);
4191 4191
4192 tree_constant *tc_retval 4192 tree_constant *tc_retval
4193 = new tree_constant (tmp, array_list->line (), 4193 = new tree_constant (tmp, array_list->line (),
4194 array_list->column ()); 4194 array_list->column ());
4195 4195