view libinterp/parse-tree/pt-eval.h @ 31771:21f9b34eb893

maint: Eliminate "(void)" in C++ function prototypes/declarations. * mk-opts.pl, external.txi, embedded.cc, make_int.cc, standalone.cc, standalonebuiltin.cc, BaseControl.cc, BaseControl.h, ButtonControl.cc, ButtonControl.h, ButtonGroup.cc, ButtonGroup.h, Canvas.cc, Canvas.h, CheckBoxControl.cc, CheckBoxControl.h, Container.cc, Container.h, ContextMenu.cc, ContextMenu.h, EditControl.cc, EditControl.h, Figure.cc, Figure.h, FigureWindow.cc, FigureWindow.h, GLCanvas.cc, GLCanvas.h, GenericEventNotify.h, KeyMap.cc, ListBoxControl.cc, ListBoxControl.h, Logger.cc, Logger.h, Menu.cc, Menu.h, MenuContainer.h, Object.cc, Object.h, ObjectProxy.cc, ObjectProxy.h, Panel.cc, Panel.h, PopupMenuControl.cc, PopupMenuControl.h, PushButtonControl.cc, PushButtonControl.h, PushTool.cc, PushTool.h, RadioButtonControl.cc, RadioButtonControl.h, SliderControl.cc, SliderControl.h, Table.cc, Table.h, TextControl.cc, TextControl.h, TextEdit.h, ToggleButtonControl.cc, ToggleButtonControl.h, ToggleTool.cc, ToggleTool.h, ToolBar.cc, ToolBar.h, ToolBarButton.cc, ToolBarButton.h, gl-select.cc, gl-select.h, qopengl-functions.h, qt-graphics-toolkit.h, qdialog.cpp, qfontdialog.cpp, qprintdialog_win.cpp, liboctgui-build-info.h, liboctgui-build-info.in.cc, color-picker.cc, color-picker.h, command-widget.cc, command-widget.h, community-news.cc, community-news.h, dialog.cc, dialog.h, documentation-bookmarks.cc, documentation-bookmarks.h, documentation-dock-widget.cc, documentation-dock-widget.h, documentation.cc, documentation.h, dw-main-window.cc, dw-main-window.h, external-editor-interface.cc, external-editor-interface.h, files-dock-widget.cc, files-dock-widget.h, find-files-dialog.cc, find-files-dialog.h, find-files-model.cc, find-files-model.h, gui-preferences.cc, gui-preferences.h, gui-settings.cc, gui-settings.h, history-dock-widget.cc, history-dock-widget.h, interpreter-qobject.cc, interpreter-qobject.h, file-editor-interface.h, file-editor-tab.cc, file-editor-tab.h, file-editor.cc, file-editor.h, find-dialog.cc, find-dialog.h, marker.cc, marker.h, octave-qscintilla.cc, octave-qscintilla.h, octave-txt-lexer.cc, octave-txt-lexer.h, main-window.cc, main-window.h, news-reader.cc, news-reader.h, octave-dock-widget.cc, octave-dock-widget.h, octave-qobject.cc, octave-qobject.h, qt-application.cc, qt-application.h, qt-interpreter-events.cc, qt-interpreter-events.h, release-notes.cc, release-notes.h, set-path-dialog.cc, set-path-dialog.h, set-path-model.cc, set-path-model.h, settings-dialog.cc, settings-dialog.h, shortcuts-tree-widget.cc, shortcuts-tree-widget.h, tab-bar.cc, tab-bar.h, terminal-dock-widget.cc, terminal-dock-widget.h, variable-editor-model.cc, variable-editor-model.h, variable-editor.cc, variable-editor.h, welcome-wizard.cc, welcome-wizard.h, workspace-model.cc, workspace-model.h, workspace-view.cc, workspace-view.h, build-env.h, Cell.cc, Cell.h, __contourc__.cc, __magick_read__.cc, auto-shlib.cc, auto-shlib.h, base-text-renderer.h, bsxfun.cc, c-file-ptr-stream.cc, c-file-ptr-stream.h, call-stack.cc, call-stack.h, debug.cc, defaults.cc, defaults.h, defun.cc, display.cc, display.h, dynamic-ld.cc, dynamic-ld.h, environment.cc, environment.h, error.cc, error.h, errwarn.cc, errwarn.h, event-manager.cc, event-manager.h, event-queue.cc, event-queue.h, fcn-info.cc, fcn-info.h, ft-text-renderer.cc, ft-text-renderer.h, genprops.awk, gh-manager.cc, gh-manager.h, gl-render.cc, gl-render.h, gl2ps-print.cc, graphics-toolkit.h, graphics.cc, graphics.in.h, gtk-manager.cc, gtk-manager.h, help.cc, help.h, hook-fcn.h, input.cc, input.h, interpreter-private.cc, interpreter-private.h, interpreter.cc, interpreter.h, jsondecode.cc, latex-text-renderer.cc, latex-text-renderer.h, load-path.cc, load-path.h, load-save.cc, load-save.h, ls-hdf5.cc, ls-hdf5.h, mxarray.h, oct-errno.h, oct-errno.in.cc, oct-fstrm.cc, oct-fstrm.h, oct-handle.h, oct-hist.cc, oct-hist.h, oct-iostrm.cc, oct-iostrm.h, oct-map.cc, oct-map.h, oct-opengl.h, oct-prcstrm.cc, oct-prcstrm.h, oct-procbuf.cc, oct-procbuf.h, oct-process.h, oct-stdstrm.h, oct-stream.cc, oct-stream.h, oct-strstrm.cc, oct-strstrm.h, oct-tex-lexer.in.ll, pager.cc, pager.h, pr-flt-fmt.cc, pr-flt-fmt.h, pr-output.cc, pr-output.h, procstream.cc, procstream.h, settings.cc, settings.h, sighandlers.cc, sighandlers.h, stack-frame.cc, stack-frame.h, svd.cc, syminfo.cc, syminfo.h, symrec.cc, symrec.h, symscope.cc, symscope.h, symtab.cc, symtab.h, sysdep.cc, sysdep.h, text-engine.cc, text-engine.h, text-renderer.cc, text-renderer.h, toplev.cc, url-handle-manager.cc, url-handle-manager.h, variables.cc, xpow.cc, __init_fltk__.cc, __init_gnuplot__.cc, __ode15__.cc, audiodevinfo.cc, gzip.cc, liboctinterp-build-info.h, liboctinterp-build-info.in.cc, mk-build-env-features.sh, mk-builtins.pl, cdef-class.cc, cdef-class.h, cdef-manager.h, cdef-method.cc, cdef-method.h, cdef-object.cc, cdef-object.h, cdef-package.cc, cdef-package.h, cdef-property.cc, cdef-property.h, cdef-utils.cc, cdef-utils.h, ov-base-diag.cc, ov-base-diag.h, ov-base-int.cc, ov-base-int.h, ov-base-mat.cc, ov-base-mat.h, ov-base-scalar.cc, ov-base-scalar.h, ov-base-sparse.cc, ov-base-sparse.h, ov-base.cc, ov-base.h, ov-bool-mat.cc, ov-bool-mat.h, ov-bool-sparse.cc, ov-bool-sparse.h, ov-bool.cc, ov-bool.h, ov-builtin.cc, ov-builtin.h, ov-cell.cc, ov-cell.h, ov-ch-mat.cc, ov-ch-mat.h, ov-class.cc, ov-class.h, ov-classdef.cc, ov-classdef.h, ov-colon.h, ov-complex.cc, ov-complex.h, ov-cs-list.h, ov-cx-diag.cc, ov-cx-diag.h, ov-cx-mat.cc, ov-cx-mat.h, ov-cx-sparse.cc, ov-cx-sparse.h, ov-dld-fcn.cc, ov-dld-fcn.h, ov-fcn-handle.cc, ov-fcn-handle.h, ov-fcn.cc, ov-fcn.h, ov-float.cc, ov-float.h, ov-flt-complex.cc, ov-flt-complex.h, ov-flt-cx-diag.cc, ov-flt-cx-diag.h, ov-flt-cx-mat.cc, ov-flt-cx-mat.h, ov-flt-re-diag.cc, ov-flt-re-diag.h, ov-flt-re-mat.cc, ov-flt-re-mat.h, ov-intx.h, ov-java.cc, ov-java.h, ov-lazy-idx.cc, ov-lazy-idx.h, ov-legacy-range.cc, ov-legacy-range.h, ov-magic-int.cc, ov-magic-int.h, ov-mex-fcn.cc, ov-mex-fcn.h, ov-null-mat.cc, ov-null-mat.h, ov-oncleanup.cc, ov-oncleanup.h, ov-perm.cc, ov-perm.h, ov-range.cc, ov-range.h, ov-re-diag.cc, ov-re-diag.h, ov-re-mat.cc, ov-re-mat.h, ov-re-sparse.cc, ov-re-sparse.h, ov-scalar.cc, ov-scalar.h, ov-str-mat.cc, ov-str-mat.h, ov-struct.cc, ov-struct.h, ov-typeinfo.cc, ov-typeinfo.h, ov-usr-fcn.cc, ov-usr-fcn.h, ov.cc, ov.h, ovl.cc, ovl.h, octave.cc, octave.h, anon-fcn-validator.h, bp-table.cc, bp-table.h, comment-list.cc, comment-list.h, filepos.h, lex.h, lex.ll, oct-lvalue.cc, oct-lvalue.h, oct-parse.yy, parse.h, profiler.cc, profiler.h, pt-anon-scopes.h, pt-arg-list.cc, pt-arg-list.h, pt-args-block.cc, pt-args-block.h, pt-array-list.cc, pt-array-list.h, pt-assign.cc, pt-assign.h, pt-binop.cc, pt-binop.h, pt-bp.h, pt-cbinop.h, pt-cell.h, pt-check.h, pt-classdef.cc, pt-classdef.h, pt-cmd.h, pt-colon.h, pt-const.h, pt-decl.cc, pt-decl.h, pt-eval.cc, pt-eval.h, pt-except.cc, pt-except.h, pt-exp.cc, pt-exp.h, pt-fcn-handle.cc, pt-fcn-handle.h, pt-id.cc, pt-id.h, pt-idx.cc, pt-idx.h, pt-jump.h, pt-loop.cc, pt-loop.h, pt-mat.h, pt-misc.cc, pt-misc.h, pt-pr-code.cc, pt-pr-code.h, pt-select.cc, pt-select.h, pt-spmd.cc, pt-spmd.h, pt-stmt.cc, pt-stmt.h, pt-tm-const.cc, pt-tm-const.h, pt-unop.cc, pt-unop.h, pt-walk.h, pt.cc, pt.h, token.cc, token.h, usage.h, Array-base.cc, Array.h, CColVector.cc, CColVector.h, CDiagMatrix.cc, CDiagMatrix.h, CMatrix.cc, CMatrix.h, CNDArray.cc, CNDArray.h, CRowVector.cc, CRowVector.h, CSparse.cc, CSparse.h, DiagArray2.cc, DiagArray2.h, MArray.cc, MArray.h, MDiagArray2.h, MSparse.h, MatrixType.cc, MatrixType.h, PermMatrix.cc, PermMatrix.h, Range.cc, Range.h, Sparse-b.cc, Sparse.cc, Sparse.h, boolMatrix.cc, boolMatrix.h, boolNDArray.cc, boolNDArray.h, boolSparse.cc, boolSparse.h, chMatrix.h, chNDArray.h, dColVector.cc, dColVector.h, dDiagMatrix.cc, dDiagMatrix.h, dMatrix.cc, dMatrix.h, dNDArray.cc, dNDArray.h, dRowVector.cc, dRowVector.h, dSparse.cc, dSparse.h, dim-vector.cc, dim-vector.h, fCColVector.cc, fCColVector.h, fCDiagMatrix.cc, fCDiagMatrix.h, fCMatrix.cc, fCMatrix.h, fCNDArray.cc, fCNDArray.h, fCRowVector.cc, fCRowVector.h, fColVector.cc, fColVector.h, fDiagMatrix.cc, fDiagMatrix.h, fMatrix.cc, fMatrix.h, fNDArray.cc, fNDArray.h, fRowVector.cc, fRowVector.h, idx-vector.cc, idx-vector.h, intNDArray.cc, intNDArray.h, liboctave-build-info.h, liboctave-build-info.in.cc, CollocWt.cc, CollocWt.h, DAE.h, DAEFunc.h, DAERT.h, DAERTFunc.h, DASPK.cc, DASPK.h, DASRT.cc, DASRT.h, DASSL.cc, DASSL.h, DET.h, EIG.h, LSODE.cc, LSODE.h, ODE.h, ODEFunc.h, ODES.h, ODESFunc.h, Quad.h, aepbalance.cc, aepbalance.h, base-dae.h, base-de.h, chol.cc, chol.h, eigs-base.cc, fEIG.h, gepbalance.h, gsvd.cc, gsvd.h, hess.h, lu.cc, lu.h, oct-fftw.cc, oct-fftw.h, oct-rand.cc, oct-rand.h, oct-spparms.cc, oct-spparms.h, qr.cc, qr.h, qrp.cc, qrp.h, randmtzig.cc, randmtzig.h, schur.h, sparse-chol.cc, sparse-chol.h, sparse-lu.cc, sparse-lu.h, sparse-qr.cc, sparse-qr.h, svd.cc, svd.h, child-list.cc, child-list.h, dir-ops.cc, dir-ops.h, file-ops.cc, file-ops.h, file-stat.cc, file-stat.h, lo-sysdep.cc, lo-sysdep.h, lo-sysinfo.cc, lo-sysinfo.h, mach-info.cc, mach-info.h, oct-env.cc, oct-env.h, oct-group.cc, oct-group.h, oct-password.cc, oct-password.h, oct-syscalls.cc, oct-syscalls.h, oct-time.cc, oct-time.h, oct-uname.cc, oct-uname.h, action-container.h, base-list.h, caseless-str.h, cmd-edit.cc, cmd-edit.h, cmd-hist.cc, cmd-hist.h, data-conv.cc, file-info.h, glob-match.cc, glob-match.h, kpse.cc, kpse.h, lo-array-errwarn.cc, lo-array-errwarn.h, lo-hash.cc, lo-hash.h, lo-ieee.cc, lo-ieee.h, lo-regexp.cc, lo-regexp.h, oct-inttypes.cc, oct-inttypes.h, oct-mutex.cc, oct-mutex.h, oct-refcount.h, oct-shlib.cc, oct-shlib.h, oct-sort.cc, oct-sort.h, oct-sparse.cc, octave-preserve-stream-state.h, pathsearch.cc, pathsearch.h, quit.cc, singleton-cleanup.cc, singleton-cleanup.h, str-vec.cc, str-vec.h, unwind-prot.cc, unwind-prot.h, url-transfer.cc, url-transfer.h, version.cc, version.in.h, cxx-signal-helpers.cc, acinclude.m4, main-cli.cc, main-gui.cc, main.in.cc, mkoctfile.in.cc, octave-build-info.h, octave-build-info.in.cc, octave-config.in.cc, octave-svgconvert.cc, shared-fcns.h: maint: Eliminate "(void)" in C++ function prototypes/declarations.
author Rik <rik@octave.org>
date Tue, 24 Jan 2023 17:19:44 -0800
parents 1f04951057bf
children febd82d1a8de
line wrap: on
line source

////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2009-2023 The Octave Project Developers
//
// See the file COPYRIGHT.md in the top-level directory of this
// distribution or <https://octave.org/copyright/>.
//
// 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 (octave_pt_eval_h)
#define octave_pt_eval_h 1

#include "octave-config.h"

#include <iosfwd>
#include <list>
#include <memory>
#include <set>
#include <stack>
#include <string>

#include "bp-table.h"
#include "call-stack.h"
#include "oct-lvalue.h"
#include "ov.h"
#include "ovl.h"
#include "profiler.h"
#include "pt-walk.h"
#include "stack-frame.h"

class octave_builtin;
class octave_mex_function;
class octave_user_code;
class octave_user_function;
class octave_user_script;

OCTAVE_BEGIN_NAMESPACE(octave)

class symbol_info_list;
class symbol_scope;
class tree_decl_elt;
class tree_expression;

class debugger;
class interpreter;
class push_parser;
class unwind_protect;

// How to evaluate the code that the parse trees represent.

class OCTINTERP_API tree_evaluator : public tree_walker
{
public:

  enum echo_state
  {
    ECHO_OFF = 0,
    ECHO_SCRIPTS = 1,
    ECHO_FUNCTIONS = 2,
    ECHO_ALL = 4
  };

  template <typename T>
  class value_stack
  {
  public:

    value_stack () = default;

    value_stack (const value_stack&) = default;

    value_stack& operator = (const value_stack&) = default;

    ~value_stack () = default;

    void push (const T& val) { m_stack.push (val); }

    void pop ()
    {
      m_stack.pop ();
    }

    T val_pop ()
    {
      T retval = m_stack.top ();
      m_stack.pop ();
      return retval;
    }

    T top () const
    {
      return m_stack.top ();
    }

    std::size_t size () const
    {
      return m_stack.size ();
    }

    bool empty () const
    {
      return m_stack.empty ();
    }

    void clear ()
    {
      while (! m_stack.empty ())
        m_stack.pop ();
    }

  private:

    std::stack<T> m_stack;
  };

  typedef void (*decl_elt_init_fcn) (tree_decl_elt&);

  tree_evaluator (interpreter& interp)
    : m_interpreter (interp), m_parser (), m_statement_context (SC_OTHER),
      m_lvalue_list (nullptr), m_autoload_map (), m_bp_table (*this),
      m_call_stack (*this), m_profiler (), m_debug_frame (0),
      m_debug_mode (false), m_quiet_breakpoint_flag (false),
      m_debugger_stack (), m_exit_status (0), m_max_recursion_depth (256),
      m_whos_line_format ("  %la:5; %ln:6; %cs:16:6:1;  %rb:12;  %lc:-1;\n"),
      m_silent_functions (false), m_string_fill_char (' '), m_PS4 ("+ "),
      m_dbstep_flag (0), m_break_on_next_stmt (false), m_echo (ECHO_OFF),
      m_echo_state (false), m_echo_file_name (), m_echo_file_pos (1),
      m_echo_files (), m_in_top_level_repl (false),
      m_server_mode (false), m_in_loop_command (false),
      m_breaking (0), m_continuing (0), m_returning (0),
      m_indexed_object (), m_index_list (), m_index_type (),
      m_index_position (0), m_num_indices (0)
  { }

  // No copying!

  tree_evaluator (const tree_evaluator&) = delete;

  tree_evaluator& operator = (const tree_evaluator&) = delete;

  ~tree_evaluator () = default;

  std::shared_ptr<push_parser> get_parser ()
  {
    return m_parser;
  }

  void set_parser (const std::shared_ptr<push_parser>& parser)
  {
    m_parser = parser;
  }

  bool at_top_level () const;

  std::string mfilename (const std::string& opt = "") const;

  // Parse a line of input.  If input ends at a complete statement
  // boundary, execute the resulting parse tree.  Useful to handle
  // parsing user input when running in server mode.

  void parse_and_execute (const std::string& input, bool& incomplete_parse);

  void get_line_and_eval ();

  int repl ();

  bool in_top_level_repl () const { return m_in_top_level_repl; }

  int server_loop ();

  bool server_mode () const { return m_server_mode; }

  void server_mode (bool arg) { m_server_mode = arg; }

  void eval (std::shared_ptr<tree_statement_list>& stmt_list,
             bool interactive);

  octave_value_list eval_string (const std::string& eval_str, bool silent,
                                 int& parse_status, int nargout);

  octave_value eval_string (const std::string& eval_str, bool silent,
                            int& parse_status);

  octave_value_list eval_string (const octave_value& arg, bool silent,
                                 int& parse_status, int nargout);

  octave_value_list eval (const std::string& try_code, int nargout);

  octave_value_list eval (const std::string& try_code,
                          const std::string& catch_code, int nargout);

  octave_value_list evalin (const std::string& context,
                            const std::string& try_code, int nargout);

  octave_value_list evalin (const std::string& context,
                            const std::string& try_code,
                            const std::string& catch_code, int nargout);

  void visit_anon_fcn_handle (tree_anon_fcn_handle&);

  void visit_argument_list (tree_argument_list&);

  void visit_arguments_block (tree_arguments_block&);

  void visit_args_block_attribute_list (tree_args_block_attribute_list&);

  void visit_args_block_validation_list (tree_args_block_validation_list&);

  void visit_arg_validation (tree_arg_validation&);

  void visit_arg_size_spec (tree_arg_size_spec&);

  void visit_arg_validation_fcns (tree_arg_validation_fcns&);

  void visit_binary_expression (tree_binary_expression&);

  void visit_boolean_expression (tree_boolean_expression&);

  void visit_compound_binary_expression (tree_compound_binary_expression&);

  void visit_break_command (tree_break_command&);

  void visit_colon_expression (tree_colon_expression&);

  void visit_continue_command (tree_continue_command&);

  void visit_decl_command (tree_decl_command&);

  void visit_decl_elt (tree_decl_elt&);

  void visit_simple_for_command (tree_simple_for_command&);

  void visit_complex_for_command (tree_complex_for_command&);

  void visit_spmd_command (tree_spmd_command&);

  octave_value evaluate_anon_fcn_handle (tree_anon_fcn_handle& afh);

  octave_value_list
  execute_builtin_function (octave_builtin& builtin_function, int nargout,
                            const octave_value_list& args);
  octave_value_list
  execute_mex_function (octave_mex_function& mex_function, int nargout,
                        const octave_value_list& args);

  void visit_octave_user_script (octave_user_script&);

  octave_value_list
  execute_user_script (octave_user_script& user_script, int nargout,
                       const octave_value_list& args);

  void visit_octave_user_function (octave_user_function&);

  octave_value_list
  execute_user_function (octave_user_function& user_function,
                         int nargout, const octave_value_list& args);

  void visit_octave_user_function_header (octave_user_function&);

  void visit_octave_user_function_trailer (octave_user_function&);

  void visit_function_def (tree_function_def&);

  void visit_identifier (tree_identifier&);

  void visit_if_clause (tree_if_clause&);

  void visit_if_command (tree_if_command&);

  void visit_if_command_list (tree_if_command_list&);

  void visit_index_expression (tree_index_expression&);

  void visit_matrix (tree_matrix&);

  void visit_cell (tree_cell&);

  void visit_multi_assignment (tree_multi_assignment&);

  void visit_no_op_command (tree_no_op_command&);

  void visit_constant (tree_constant&);

  void visit_fcn_handle (tree_fcn_handle&);

  void visit_parameter_list (tree_parameter_list&);

  void visit_postfix_expression (tree_postfix_expression&);

  void visit_prefix_expression (tree_prefix_expression&);

  void visit_return_command (tree_return_command&);

  void visit_simple_assignment (tree_simple_assignment&);

  void visit_statement (tree_statement&);

  void visit_statement_list (tree_statement_list&);

  void visit_switch_case (tree_switch_case&);

  void visit_switch_case_list (tree_switch_case_list&);

  void visit_switch_command (tree_switch_command&);

  void visit_try_catch_command (tree_try_catch_command&);

  void do_unwind_protect_cleanup_code (tree_statement_list *list);

  void visit_unwind_protect_command (tree_unwind_protect_command&);

  void visit_while_command (tree_while_command&);
  void visit_do_until_command (tree_do_until_command&);

  void visit_superclass_ref (tree_superclass_ref&);
  void visit_metaclass_query (tree_metaclass_query&);

  void bind_ans (const octave_value& val, bool print);

  bool statement_printing_enabled ();

  void reset_debug_state ();

  void reset_debug_state (bool mode);

  void enter_debugger (const std::string& prompt = "debug> ");

  void keyboard (const std::string& prompt = "keyboard> ");

  void dbupdown (int n, bool verbose = false);

  // Possible types of evaluation contexts.
  enum stmt_list_type
  {
    SC_FUNCTION,  // function body
    SC_SCRIPT,    // script file
    SC_OTHER      // command-line input or eval string
  };

  Matrix ignored_fcn_outputs () const;

  octave_value make_fcn_handle (const std::string& nm);

  octave_value evaluate (tree_decl_elt *);

  void install_variable (const std::string& name,
                         const octave_value& value, bool global);

  octave_value global_varval (const std::string& name) const;

  octave_value& global_varref (const std::string& name);

  void global_assign (const std::string& name,
                      const octave_value& val = octave_value ());

  octave_value top_level_varval (const std::string& name) const;

  void top_level_assign (const std::string& name,
                         const octave_value& val = octave_value ());

  bool is_variable (const std::string& name) const;

  bool is_local_variable (const std::string& name) const;

  bool is_variable (const tree_expression *expr) const;

  bool is_defined (const tree_expression *expr) const;

  bool is_variable (const symbol_record& sym) const;

  bool is_defined (const symbol_record& sym) const;

  bool is_global (const std::string& name) const;

  octave_value varval (const symbol_record& sym) const;

  octave_value varval (const std::string& name) const;

  void assign (const std::string& name,
               const octave_value& val = octave_value ());

  void assignin (const std::string& context, const std::string& name,
                 const octave_value& val = octave_value ());

  void source_file (const std::string& file_name,
                    const std::string& context = "",
                    bool verbose = false, bool require_file = true);

  void set_auto_fcn_var (stack_frame::auto_var_type avt,
                         const octave_value& val = octave_value ());

  octave_value get_auto_fcn_var (stack_frame::auto_var_type avt) const;

  void define_parameter_list_from_arg_vector
  (tree_parameter_list *param_list, const octave_value_list& args);

  void undefine_parameter_list (tree_parameter_list *param_list);

  octave_value_list convert_to_const_vector (tree_argument_list *arg_list);

  octave_value_list
  convert_return_list_to_const_vector
  (tree_parameter_list *ret_list, int nargout,
   const Matrix& ignored_outputs, const Cell& varargout);

  bool eval_decl_elt (tree_decl_elt *elt);

  bool switch_case_label_matches (tree_switch_case *expr,
                                  const octave_value& val);

  interpreter& get_interpreter () { return m_interpreter; }

  bp_table& get_bp_table () { return m_bp_table; }

  profiler& get_profiler () { return m_profiler; }

  void push_stack_frame (const symbol_scope& scope);

  void push_stack_frame (octave_user_function *fcn,
                         const std::shared_ptr<stack_frame>& closure_frames = std::shared_ptr<stack_frame> ());

  void push_stack_frame (octave_user_function *fcn,
                         const stack_frame::local_vars_map& local_vars,
                         const std::shared_ptr<stack_frame>& closure_frames = std::shared_ptr<stack_frame> ());

  void push_stack_frame (octave_user_script *script);

  void push_stack_frame (octave_function *fcn);

  void pop_stack_frame ();

  std::shared_ptr<stack_frame> get_current_stack_frame () const
  {
    return m_call_stack.get_current_stack_frame ();
  }

  std::shared_ptr<stack_frame> current_user_frame () const
  {
    return m_call_stack.current_user_frame ();
  }

  // Current line in current function.
  int current_line () const;

  // Current column in current function.
  int current_column () const;

  // Line number in current function that we are debugging.
  int debug_user_code_line () const;

  // Column number in current function that we are debugging.
  int debug_user_code_column () const;

  void debug_where (std::ostream& os) const;

  octave_user_code * current_user_code () const;

  unwind_protect * curr_fcn_unwind_protect_frame ();

  // Current function that we are debugging.
  octave_user_code * debug_user_code () const;

  octave_function * current_function (bool skip_first = false) const;

  octave_function * caller_function () const;

  bool goto_frame (std::size_t n = 0, bool verbose = false);

  void goto_caller_frame ();

  void goto_base_frame ();

  void restore_frame (std::size_t n);

  std::string get_dispatch_class () const;

  void set_dispatch_class (const std::string& class_name);

  bool is_class_method_executing (std::string& dispatch_class) const;

  bool is_class_constructor_executing (std::string& dispatch_class) const;

  std::list<std::shared_ptr<stack_frame>>
                                       backtrace_frames (octave_idx_type& curr_user_frame) const;

  std::list<std::shared_ptr<stack_frame>> backtrace_frames () const;

  std::list<frame_info> backtrace_info (octave_idx_type& curr_user_frame,
                                        bool print_subfn = true) const;

  std::list<frame_info> backtrace_info () const;

  octave_map backtrace (octave_idx_type& curr_user_frame,
                        bool print_subfn = true) const;

  octave_map backtrace () const;

  octave_map empty_backtrace () const;

  std::string backtrace_message () const;

  void push_dummy_scope (const std::string& name);
  void pop_scope ();

  symbol_scope get_top_scope () const;
  symbol_scope get_current_scope () const;

  void mlock (bool skip_first = false) const;

  void munlock (bool skip_first = false) const;

  bool mislocked (bool skip_first = false) const;

  octave_value max_stack_depth (const octave_value_list& args, int nargout);

  // Useful for debugging
  void display_call_stack () const;

  octave_value find (const std::string& name);

  void clear_objects ();

  void clear_variable (const std::string& name);

  void clear_variable_pattern (const std::string& pattern);

  void clear_variable_regexp (const std::string& pattern);

  void clear_variables ();

  void clear_global_variable (const std::string& name);

  void clear_global_variable_pattern (const std::string& pattern);

  void clear_global_variable_regexp (const std::string& pattern);

  void clear_global_variables ();

  void clear_all (bool force = false);

  void clear_symbol (const std::string& name);

  void clear_symbol_pattern (const std::string& pattern);

  void clear_symbol_regexp (const std::string& pattern);

  std::list<std::string> global_variable_names () const;

  std::list<std::string> top_level_variable_names () const;

  std::list<std::string> variable_names () const;

  octave_user_code * get_user_code (const std::string& fname = "",
                                   const std::string& class_name = "");

  std::string current_function_name (bool skip_first = false) const;

  bool in_user_code () const;

  symbol_info_list glob_symbol_info (const std::string& pattern) const;

  symbol_info_list regexp_symbol_info (const std::string& pattern) const;

  symbol_info_list get_symbol_info ();

  symbol_info_list top_scope_symbol_info () const;

  octave_map get_autoload_map () const;

  std::string lookup_autoload (const std::string& nm) const;

  std::list<std::string> autoloaded_functions () const;

  std::list<std::string> reverse_lookup_autoload (const std::string& nm) const;

  void add_autoload (const std::string& fcn, const std::string& nm);

  void remove_autoload (const std::string& fcn, const std::string& nm);

  int max_recursion_depth () const { return m_max_recursion_depth; }

  int max_recursion_depth (int n)
  {
    int val = m_max_recursion_depth;
    m_max_recursion_depth = n;
    return val;
  }

  octave_value
  max_recursion_depth (const octave_value_list& args, int nargout);

  bool silent_functions () const { return m_silent_functions; }

  bool silent_functions (bool b)
  {
    int val = m_silent_functions;
    m_silent_functions = b;
    return val;
  }

  octave_value whos_line_format (const octave_value_list& args, int nargout);

  std::string whos_line_format () const { return m_whos_line_format; }

  std::string whos_line_format (const std::string& s)
  {
    std::string val = m_whos_line_format;
    m_whos_line_format = s;
    return val;
  }

  octave_value
  silent_functions (const octave_value_list& args, int nargout);

  std::size_t debug_frame () const { return m_debug_frame; }

  std::size_t debug_frame (std::size_t n)
  {
    std::size_t val = m_debug_frame;
    m_debug_frame = n;
    return val;
  }

  std::size_t current_call_stack_frame_number () const
  {
    return m_call_stack.current_frame ();
  }

  bool quiet_breakpoint_flag () const { return m_quiet_breakpoint_flag; }

  bool quiet_breakpoint_flag (bool flag)
  {
    bool val = m_quiet_breakpoint_flag;
    m_quiet_breakpoint_flag = flag;
    return val;
  }

  char string_fill_char () const { return m_string_fill_char; }

  char string_fill_char (char c)
  {
    int val = m_string_fill_char;
    m_string_fill_char = c;
    return val;
  }

  // The following functions are provided for convenience.  They
  // call the corresponding functions in the debugger class for the
  // current debugger (if any).

  bool in_debug_repl () const;

  void dbcont ();

  // Return true if we are in the debug repl and m_execution_mode is
  // set to exit the debugger.  Otherwise, do nothing.

  void dbquit (bool all = false);

  // Add EXPR to the set of expressions that may be evaluated when the
  // debugger stops at a breakpoint.
  void add_debug_watch_expression (const std::string& expr)
  {
    m_debug_watch_expressions.insert (expr);
  }

  // Remove EXPR from the set of expressions that may be evaluated
  // when the debugger stops at a breakpoint.
  void remove_debug_watch_expression (const std::string& expr)
  {
    m_debug_watch_expressions.erase (expr);
  }

  // Clear the set of expressions that may be evaluated when the
  // debugger stops at a breakpoint.
  void clear_debug_watch_expressions ()
  {
    m_debug_watch_expressions.clear ();
  }

  // Return the set of expressions that may be evaluated when the
  // debugger stops at a breakpoint.
  std::set<std::string> debug_watch_expressions () const
  {
    return m_debug_watch_expressions;
  }

  octave_value PS4 (const octave_value_list& args, int nargout);

  std::string PS4 () const { return m_PS4; }

  std::string PS4 (const std::string& s)
  {
    std::string val = m_PS4;
    m_PS4 = s;
    return val;
  }

  void set_PS4 (const std::string& s) { m_PS4 = s; }

  octave_value indexed_object () const
  {
    return m_indexed_object;
  }

  void set_indexed_object (const octave_value& obj = octave_value ())
  {
    m_indexed_object = obj;
  }

  const std::list<octave_value_list>& index_list () const
  {
    return m_index_list;
  }

  void set_index_list (const std::string& index_type,
                       const std::list<octave_value_list>& index_list)
  {
    m_index_type = index_type;
    m_index_list = index_list;
  }

  void clear_index_list ()
  {
    m_index_type = "";
    m_index_list.clear ();
  }

  void append_index_list (char type, const octave_value_list& idx)
  {
    m_index_type += type;
    m_index_list.push_back (idx);
  }

  const std::string& index_type () const
  {
    return m_index_type;
  }

  int index_position () const { return m_index_position; }

  int num_indices () const { return m_num_indices; }

  octave_value_list evaluate_end_expression (const octave_value_list& args);

  const std::list<octave_lvalue> * lvalue_list () const
  {
    return m_lvalue_list;
  }

  void set_lvalue_list (const std::list<octave_lvalue> *lst)
  {
    m_lvalue_list = lst;
  }

  int breaking () const { return m_breaking; }

  int breaking (int n)
  {
    int val = m_breaking;
    m_breaking = n;
    return val;
  }

  int continuing () const { return m_continuing; }

  int continuing (int n)
  {
    int val = m_continuing;
    m_continuing = n;
    return val;
  }

  int returning () const { return m_returning; }

  int returning (int n)
  {
    int val = m_returning;
    m_returning = n;
    return val;
  }

  int dbstep_flag () const { return m_dbstep_flag; }

  int dbstep_flag (int val)
  {
    int old_val = m_dbstep_flag;
    m_dbstep_flag = val;
    return old_val;
  }

  void set_dbstep_flag (int step) { m_dbstep_flag = step; }

  bool break_on_next_statement () const
  {
    return m_break_on_next_stmt;
  }

  bool break_on_next_statement (bool val)
  {
    bool old_val = m_break_on_next_stmt;
    m_break_on_next_stmt = val;
    return old_val;
  }

  void set_break_on_next_statement (bool val)
  {
    m_break_on_next_stmt = val;
  }

  octave_value echo (const octave_value_list& args, int nargout);

  int echo () const { return m_echo; }

  int echo (int val)
  {
    int old_val = m_echo;
    m_echo = val;
    return old_val;
  }

  octave_value
  string_fill_char (const octave_value_list& args, int nargout);

  void final_index_error (index_exception& ie, const tree_expression *expr);

  octave_value do_who (int argc, const string_vector& argv,
                       bool return_list, bool verbose = false);

  octave_value_list
  make_value_list (tree_argument_list *args, const string_vector& arg_nm);

  std::list<octave_lvalue> make_lvalue_list (tree_argument_list *);

  void push_echo_state (int type, const std::string& file_name, int pos = 1);

private:

  template <typename T>
  void execute_range_loop (const range<T>& rng, int line,
                           octave_lvalue& ult,
                           tree_statement_list *loop_body);

  void set_echo_state (int type, const std::string& file_name, int pos);

  void maybe_set_echo_state ();

  void push_echo_state_cleanup (unwind_protect& frame);

  bool maybe_push_echo_state_cleanup ();

  void do_breakpoint (tree_statement& stmt);

  void do_breakpoint (bool is_breakpoint,
                      bool is_end_of_fcn_or_script = false);

  bool is_logically_true (tree_expression *expr, const char *warn_for);

  // For unwind-protect.
  void uwp_set_echo_state (bool state, const std::string& file_name, int pos);

  bool echo_this_file (const std::string& file, int type) const;

  void echo_code (int line);

  bool quit_loop_now ();

  void bind_auto_fcn_vars (const string_vector& arg_names,
                           const Matrix& ignored_outputs, int nargin,
                           int nargout, bool takes_varargs,
                           const octave_value_list& va_args);

  std::string check_autoload_file (const std::string& nm) const;

  interpreter& m_interpreter;

  std::shared_ptr<push_parser> m_parser;

  // The context for the current evaluation.
  stmt_list_type m_statement_context;

  const std::list<octave_lvalue> *m_lvalue_list;

  // List of autoloads (function -> file mapping).
  std::map<std::string, std::string> m_autoload_map;

  bp_table m_bp_table;

  call_stack m_call_stack;

  profiler m_profiler;

  // The number of the stack frame we are currently debugging.
  std::size_t m_debug_frame;

  bool m_debug_mode;

  bool m_quiet_breakpoint_flag;

  // When entering the debugger we push it on this stack.  Managing
  // debugger invocations this way allows us to handle recursive
  // debugger calls.  When we exit a debugger the object is popped
  // from the stack and deleted and we resume working with the
  // previous debugger (if any) that is now at the top of the stack.
  std::stack<debugger *> m_debugger_stack;

  std::set<std::string> m_debug_watch_expressions;

  int m_exit_status;

  // Maximum nesting level for functions, scripts, or sourced files
  // called recursively.
  int m_max_recursion_depth;

  // Defines layout for the whos/who -long command
  std::string m_whos_line_format;

  // If TRUE, turn off printing of results in functions (as if a
  // semicolon has been appended to each statement).
  bool m_silent_functions;

  // The character to fill with when creating string arrays.
  char m_string_fill_char;

  // String printed before echoed commands (enabled by --echo-commands).
  std::string m_PS4;

  // If > 0, stop executing at the (N-1)th stopping point, counting
  //         from the the current execution point in the current frame.
  //
  // If < 0, stop executing at the next possible stopping point.
  int m_dbstep_flag;

  // If TRUE, and we are not stopping for another reason (dbstep or a
  // breakpoint) then stop at next statement and enter the debugger.
  bool m_break_on_next_stmt;

  // Echo commands as they are executed?
  //
  //   1  ==>  echo commands read from script files
  //   2  ==>  echo commands from functions
  //
  // more than one state can be active at once.
  int m_echo;

  // Are we currently echoing commands?  This state is set by the
  // functions that execute functions and scripts.
  bool m_echo_state;

  std::string m_echo_file_name;

  // Next line to echo, counting from 1.  We use int here because the
  // parser does.  It also initializes line and column numbers to the
  // invalid value -1 and that can cause trouble if cast to an
  // unsigned value.  When updating this value and echoing ranges of
  // code, we also check to ensure that the line numbers stored in the
  // parse tree are valid.  It would be better to ensure that the
  // parser always stores valid position info, but that's more
  // difficult to always do correctly.
  int m_echo_file_pos;

  std::map<std::string, bool> m_echo_files;

  // TRUE if we are in the top level interactive read eval print loop.
  bool m_in_top_level_repl;

  // TRUE means we are executing in the server_loop function.
  bool m_server_mode;

  // TRUE means we are evaluating some kind of looping construct.
  bool m_in_loop_command;

  // Nonzero means we're breaking out of a loop or function body.
  int m_breaking;

  // Nonzero means we're jumping to the end of a loop.
  int m_continuing;

  // Nonzero means we're returning from a function.
  int m_returning;

  // The following are all used by the END function.  Maybe they
  // should be kept together in a separate object?
  octave_value m_indexed_object;
  std::list<octave_value_list> m_index_list;
  std::string m_index_type;
  int m_index_position;
  int m_num_indices;
};

OCTAVE_END_NAMESPACE(octave)

#endif