view libinterp/parse-tree/pt-loop.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 00f796120a6d
children b442ec6dda5c
line wrap: on
line source

/*

Copyright (C) 1996-2019 John W. Eaton

This file is part of Octave.

Octave is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Octave is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Octave; see the file COPYING.  If not, see
<https://www.gnu.org/licenses/>.

*/

#if defined (HAVE_CONFIG_H)
#  include "config.h"
#endif

#include "pt-arg-list.h"
#include "pt-exp.h"
#include "pt-loop.h"
#include "pt-stmt.h"

namespace octave
{
  // While.

  tree_while_command::~tree_while_command (void)
  {
    delete m_expr;
    delete m_list;
    delete m_lead_comm;
    delete m_trail_comm;
#if defined (HAVE_LLVM)
    delete m_compiled;
#endif
  }

  // For.

  tree_simple_for_command::~tree_simple_for_command (void)
  {
    delete m_lhs;
    delete m_expr;
    delete m_maxproc;
    delete m_list;
    delete m_lead_comm;
    delete m_trail_comm;
#if defined (HAVE_LLVM)
    delete m_compiled;
#endif
  }

  tree_complex_for_command::~tree_complex_for_command (void)
  {
    delete m_lhs;
    delete m_expr;
    delete m_list;
    delete m_lead_comm;
    delete m_trail_comm;
  }
}