GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pt-eval.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2009-2024 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_pt_eval_h)
27 #define octave_pt_eval_h 1
28 
29 #include "octave-config.h"
30 
31 #include <iosfwd>
32 #include <list>
33 #include <memory>
34 #include <set>
35 #include <stack>
36 #include <string>
37 
38 #include "bp-table.h"
39 #include "call-stack.h"
40 #include "oct-lvalue.h"
41 #include "ov.h"
42 #include "ovl.h"
43 #include "profiler.h"
44 #include "pt-walk.h"
45 #include "stack-frame.h"
46 
47 class octave_builtin;
49 class octave_user_code;
51 class octave_user_script;
52 
54 
55 class symbol_info_list;
56 class symbol_scope;
57 class tree_decl_elt;
58 class tree_expression;
59 
60 class debugger;
61 class interpreter;
62 class push_parser;
63 class unwind_protect;
64 
65 // How to evaluate the code that the parse trees represent.
66 
67 class OCTINTERP_API tree_evaluator : public tree_walker
68 {
69 public:
70 
72  {
73  ECHO_OFF = 0,
74  ECHO_SCRIPTS = 1,
75  ECHO_FUNCTIONS = 2,
76  ECHO_ALL = 4
77  };
78 
79  template <typename T>
81  {
82  public:
83 
84  OCTAVE_DEFAULT_CONSTRUCT_COPY_MOVE_DELETE (value_stack)
85 
86  void push (const T& val) { m_stack.push (val); }
87 
88  void pop ()
89  {
90  m_stack.pop ();
91  }
92 
93  T val_pop ()
94  {
95  T retval = m_stack.top ();
96  m_stack.pop ();
97  return retval;
98  }
99 
100  T top () const
101  {
102  return m_stack.top ();
103  }
104 
105  std::size_t size () const
106  {
107  return m_stack.size ();
108  }
109 
110  bool empty () const
111  {
112  return m_stack.empty ();
113  }
114 
115  void clear ()
116  {
117  while (! m_stack.empty ())
118  m_stack.pop ();
119  }
120 
121  private:
122 
123  std::stack<T> m_stack;
124  };
125 
126  typedef void (*decl_elt_init_fcn) (tree_decl_elt&);
127 
129  : m_interpreter (interp), m_parser (), m_statement_context (SC_OTHER),
130  m_lvalue_list (nullptr), m_autoload_map (), m_bp_table (*this),
131  m_call_stack (*this), m_profiler (), m_debug_frame (0),
132  m_debug_mode (false), m_quiet_breakpoint_flag (false),
133  m_debugger_stack (), m_exit_status (0), m_max_recursion_depth (256),
134  m_whos_line_format (" %la:5; %ln:6; %cs:16:6:1; %rb:12; %lc:-1;\n"),
135  m_silent_functions (false), m_string_fill_char (' '), m_PS4 ("+ "),
136  m_dbstep_flag (0), m_break_on_next_stmt (false), m_echo (ECHO_OFF),
137  m_echo_state (false), m_echo_file_name (),
138  m_echo_file_pos (1),
139  m_echo_files (), m_in_top_level_repl (false),
140  m_server_mode (false), m_in_loop_command (false),
141  m_breaking (0), m_continuing (0), m_returning (0),
142  m_indexed_object (), m_index_list (), m_index_type (),
143  m_index_position (0), m_num_indices (0)
144  { }
145 
146  OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (tree_evaluator)
147 
148  ~tree_evaluator () = default;
149 
150  std::shared_ptr<push_parser> get_parser ()
151  {
152  return m_parser;
153  }
154 
155  void set_parser (const std::shared_ptr<push_parser>& parser)
156  {
157  m_parser = parser;
158  }
159 
160  bool at_top_level () const;
161 
162  std::string mfilename (const std::string& opt = "") const;
163 
164  // Parse a line of input. If input ends at a complete statement
165  // boundary, execute the resulting parse tree. Useful to handle
166  // parsing user input when running in server mode.
167 
168  void parse_and_execute (const std::string& input, bool& incomplete_parse);
169 
170  void get_line_and_eval ();
171 
172  int repl ();
173 
174  bool in_top_level_repl () const { return m_in_top_level_repl; }
175 
176  int server_loop ();
177 
178  bool server_mode () const { return m_server_mode; }
179 
180  void server_mode (bool arg) { m_server_mode = arg; }
181 
182  void eval (std::shared_ptr<tree_statement_list>& stmt_list,
183  bool interactive);
184 
185  octave_value_list eval_string (const std::string& eval_str, bool silent,
186  int& parse_status, int nargout);
187 
188  octave_value eval_string (const std::string& eval_str, bool silent,
189  int& parse_status);
190 
191  octave_value_list eval_string (const octave_value& arg, bool silent,
192  int& parse_status, int nargout);
193 
194  octave_value_list eval (const std::string& try_code, int nargout);
195 
196  octave_value_list eval (const std::string& try_code,
197  const std::string& catch_code, int nargout);
198 
199  octave_value_list evalin (const std::string& context,
200  const std::string& try_code, int nargout);
201 
202  octave_value_list evalin (const std::string& context,
203  const std::string& try_code,
204  const std::string& catch_code, int nargout);
205 
207 
209 
211 
213 
215 
217 
219 
221 
223 
225 
227 
229 
231 
233 
235 
237 
239 
241 
243 
244  octave_value evaluate_anon_fcn_handle (tree_anon_fcn_handle& afh);
245 
247  execute_builtin_function (octave_builtin& builtin_function, int nargout,
248  const octave_value_list& args);
250  execute_mex_function (octave_mex_function& mex_function, int nargout,
251  const octave_value_list& args);
252 
254 
256  execute_user_script (octave_user_script& user_script, int nargout,
257  const octave_value_list& args);
258 
260 
262  execute_user_function (octave_user_function& user_function,
263  int nargout, const octave_value_list& args);
264 
265  void visit_octave_user_function_header (octave_user_function&);
266 
267  void visit_octave_user_function_trailer (octave_user_function&);
268 
270 
272 
274 
276 
278 
280 
281  void visit_matrix (tree_matrix&);
282 
283  void visit_cell (tree_cell&);
284 
286 
288 
290 
292 
294 
296 
298 
300 
302 
304 
306 
308 
310 
312 
314 
315  void do_unwind_protect_cleanup_code (tree_statement_list *list);
316 
318 
321 
324 
325  void bind_ans (const octave_value& val, bool print);
326 
327  bool statement_printing_enabled ();
328 
329  void reset_debug_state ();
330 
331  void reset_debug_state (bool mode);
332 
333  void enter_debugger (const std::string& prompt = "debug> ");
334 
335  void keyboard (const std::string& prompt = "keyboard> ");
336 
337  void dbupdown (int n, bool verbose = false);
338 
339  // Possible types of evaluation contexts.
341  {
342  SC_FUNCTION, // function body
343  SC_SCRIPT, // script file
344  SC_OTHER // command-line input or eval string
345  };
346 
347  Matrix ignored_fcn_outputs () const;
348 
349  octave_value make_fcn_handle (const std::string& nm);
350 
351  octave_value evaluate (tree_decl_elt *);
352 
353  void install_variable (const std::string& name,
354  const octave_value& value, bool global);
355 
356  octave_value global_varval (const std::string& name) const;
357 
358  octave_value& global_varref (const std::string& name);
359 
360  void global_assign (const std::string& name,
361  const octave_value& val = octave_value ());
362 
363  octave_value top_level_varval (const std::string& name) const;
364 
365  void top_level_assign (const std::string& name,
366  const octave_value& val = octave_value ());
367 
368  bool is_variable (const std::string& name) const;
369 
370  bool is_local_variable (const std::string& name) const;
371 
372  bool is_variable (const tree_expression *expr) const;
373 
374  bool is_defined (const tree_expression *expr) const;
375 
376  bool is_variable (const symbol_record& sym) const;
377 
378  bool is_defined (const symbol_record& sym) const;
379 
380  bool is_global (const std::string& name) const;
381 
382  octave_value varval (const symbol_record& sym) const;
383 
384  octave_value varval (const std::string& name) const;
385 
386  void assign (const std::string& name,
387  const octave_value& val = octave_value ());
388 
389  void assignin (const std::string& context, const std::string& name,
390  const octave_value& val = octave_value ());
391 
392  void source_file (const std::string& file_name,
393  const std::string& context = "",
394  bool verbose = false, bool require_file = true);
395 
396  void set_auto_fcn_var (stack_frame::auto_var_type avt,
397  const octave_value& val = octave_value ());
398 
399  void set_nargin (int nargin);
400  void set_nargout (int nargout);
401 
402  octave_value get_auto_fcn_var (stack_frame::auto_var_type avt) const;
403 
404  void define_parameter_list_from_arg_vector
405  (tree_parameter_list *param_list, const octave_value_list& args);
406 
407  void undefine_parameter_list (tree_parameter_list *param_list);
408 
409  octave_value_list convert_to_const_vector (tree_argument_list *arg_list);
410 
412  convert_return_list_to_const_vector
413  (tree_parameter_list *ret_list, int nargout, const Cell& varargout);
414 
415  bool eval_decl_elt (tree_decl_elt *elt);
416 
417  bool switch_case_label_matches (tree_switch_case *expr,
418  const octave_value& val);
419 
420  interpreter& get_interpreter () { return m_interpreter; }
421 
422  bp_table& get_bp_table () { return m_bp_table; }
423 
424  profiler& get_profiler () { return m_profiler; }
425 
426  void push_stack_frame (const symbol_scope& scope);
427 
428  void push_stack_frame (octave_user_function *fcn,
429  const std::shared_ptr<stack_frame>& closure_frames = std::shared_ptr<stack_frame> ());
430 
431  void push_stack_frame (octave_user_function *fcn,
432  const stack_frame::local_vars_map& local_vars,
433  const std::shared_ptr<stack_frame>& closure_frames = std::shared_ptr<stack_frame> ());
434 
435  void push_stack_frame (octave_user_script *script);
436 
437  void push_stack_frame (octave_function *fcn);
438 
439  void pop_stack_frame ();
440 
441  std::shared_ptr<stack_frame> pop_return_stack_frame ();
442 
443  std::shared_ptr<stack_frame> get_current_stack_frame () const
444  {
445  return m_call_stack.get_current_stack_frame ();
446  }
447 
448  std::shared_ptr<stack_frame> current_user_frame () const
449  {
450  return m_call_stack.current_user_frame ();
451  }
452 
453  // Current line in current function.
454  int current_line () const;
455 
456  // Current column in current function.
457  int current_column () const;
458 
459  // Line number in current function that we are debugging.
460  int debug_user_code_line () const;
461 
462  // Column number in current function that we are debugging.
463  int debug_user_code_column () const;
464 
465  void debug_where (std::ostream& os) const;
466 
467  octave_user_code * current_user_code () const;
468 
469  unwind_protect * curr_fcn_unwind_protect_frame ();
470 
471  // Current function that we are debugging.
472  octave_user_code * debug_user_code () const;
473 
474  octave_function * current_function (bool skip_first = false) const;
475 
476  octave_function * caller_function () const;
477 
478  bool goto_frame (std::size_t n = 0, bool verbose = false);
479 
480  void goto_caller_frame ();
481 
482  void goto_base_frame ();
483 
484  void restore_frame (std::size_t n);
485 
486  std::string get_dispatch_class () const;
487 
488  void set_dispatch_class (const std::string& class_name);
489 
490  bool is_class_method_executing (std::string& dispatch_class) const;
491 
492  bool is_class_constructor_executing (std::string& dispatch_class) const;
493 
494  std::list<std::shared_ptr<stack_frame>>
495  backtrace_frames (octave_idx_type& curr_user_frame) const;
496 
497  std::list<std::shared_ptr<stack_frame>> backtrace_frames () const;
498 
499  std::list<frame_info> backtrace_info (octave_idx_type& curr_user_frame,
500  bool print_subfn = true) const;
501 
502  std::list<frame_info> backtrace_info () const;
503 
504  octave_map backtrace (octave_idx_type& curr_user_frame,
505  bool print_subfn = true) const;
506 
507  octave_map backtrace () const;
508 
509  octave_map empty_backtrace () const;
510 
511  std::string backtrace_message () const;
512 
513  void push_dummy_scope (const std::string& name);
514  void pop_scope ();
515 
516  symbol_scope get_top_scope () const;
517  symbol_scope get_current_scope () const;
518 
519  void mlock (bool skip_first = false) const;
520 
521  void munlock (bool skip_first = false) const;
522 
523  bool mislocked (bool skip_first = false) const;
524 
525  octave_value max_stack_depth (const octave_value_list& args, int nargout);
526 
527  // Useful for debugging
528  void display_call_stack () const;
529 
530  octave_value find (const std::string& name);
531 
532  void clear_objects ();
533 
534  void clear_variable (const std::string& name);
535 
536  void clear_variable_pattern (const std::string& pattern);
537 
538  void clear_variable_regexp (const std::string& pattern);
539 
540  void clear_variables ();
541 
542  void clear_global_variable (const std::string& name);
543 
544  void clear_global_variable_pattern (const std::string& pattern);
545 
546  void clear_global_variable_regexp (const std::string& pattern);
547 
548  void clear_global_variables ();
549 
550  void clear_all (bool force = false);
551 
552  void clear_symbol (const std::string& name);
553 
554  void clear_symbol_pattern (const std::string& pattern);
555 
556  void clear_symbol_regexp (const std::string& pattern);
557 
558  std::list<std::string> global_variable_names () const;
559 
560  std::list<std::string> top_level_variable_names () const;
561 
562  std::list<std::string> variable_names () const;
563 
564  octave_user_code * get_user_code (const std::string& fname = "");
565 
566  std::string current_function_name (bool skip_first = false) const;
567 
568  bool in_user_code () const;
569 
570  symbol_info_list glob_symbol_info (const std::string& pattern) const;
571 
572  symbol_info_list regexp_symbol_info (const std::string& pattern) const;
573 
574  symbol_info_list get_symbol_info ();
575 
576  symbol_info_list top_scope_symbol_info () const;
577 
578  octave_map get_autoload_map () const;
579 
580  std::string lookup_autoload (const std::string& nm) const;
581 
582  std::list<std::string> autoloaded_functions () const;
583 
584  std::list<std::string> reverse_lookup_autoload (const std::string& nm) const;
585 
586  void add_autoload (const std::string& fcn, const std::string& nm);
587 
588  void remove_autoload (const std::string& fcn, const std::string& nm);
589 
590  int max_recursion_depth () const { return m_max_recursion_depth; }
591 
593  {
594  int val = m_max_recursion_depth;
595  m_max_recursion_depth = n;
596  return val;
597  }
598 
600  max_recursion_depth (const octave_value_list& args, int nargout);
601 
602  bool silent_functions () const { return m_silent_functions; }
603 
604  bool silent_functions (bool b)
605  {
606  int val = m_silent_functions;
607  m_silent_functions = b;
608  return val;
609  }
610 
611  octave_value whos_line_format (const octave_value_list& args, int nargout);
612 
613  std::string whos_line_format () const { return m_whos_line_format; }
614 
615  std::string whos_line_format (const std::string& s)
616  {
617  std::string val = m_whos_line_format;
618  m_whos_line_format = s;
619  return val;
620  }
621 
623  silent_functions (const octave_value_list& args, int nargout);
624 
625  std::size_t debug_frame () const { return m_debug_frame; }
626 
627  std::size_t debug_frame (std::size_t n)
628  {
629  std::size_t val = m_debug_frame;
630  m_debug_frame = n;
631  return val;
632  }
633 
634  std::size_t current_call_stack_frame_number () const
635  {
636  return m_call_stack.current_frame ();
637  }
638 
639  bool quiet_breakpoint_flag () const { return m_quiet_breakpoint_flag; }
640 
641  bool quiet_breakpoint_flag (bool flag)
642  {
643  bool val = m_quiet_breakpoint_flag;
644  m_quiet_breakpoint_flag = flag;
645  return val;
646  }
647 
648  char string_fill_char () const { return m_string_fill_char; }
649 
650  char string_fill_char (char c)
651  {
652  int val = m_string_fill_char;
653  m_string_fill_char = c;
654  return val;
655  }
656 
657  // The following functions are provided for convenience. They
658  // call the corresponding functions in the debugger class for the
659  // current debugger (if any).
660 
661  bool in_debug_repl () const;
662 
663  void dbcont ();
664 
665  // Return true if we are in the debug repl and m_execution_mode is
666  // set to exit the debugger. Otherwise, do nothing.
667 
668  void dbquit (bool all = false);
669 
670  // Add EXPR to the set of expressions that may be evaluated when the
671  // debugger stops at a breakpoint.
672  void add_debug_watch_expression (const std::string& expr)
673  {
674  m_debug_watch_expressions.insert (expr);
675  }
676 
677  // Remove EXPR from the set of expressions that may be evaluated
678  // when the debugger stops at a breakpoint.
679  void remove_debug_watch_expression (const std::string& expr)
680  {
681  m_debug_watch_expressions.erase (expr);
682  }
683 
684  // Clear the set of expressions that may be evaluated when the
685  // debugger stops at a breakpoint.
687  {
688  m_debug_watch_expressions.clear ();
689  }
690 
691  // Return the set of expressions that may be evaluated when the
692  // debugger stops at a breakpoint.
693  std::set<std::string> debug_watch_expressions () const
694  {
695  return m_debug_watch_expressions;
696  }
697 
698  octave_value PS4 (const octave_value_list& args, int nargout);
699 
700  std::string PS4 () const { return m_PS4; }
701 
702  std::string PS4 (const std::string& s)
703  {
704  std::string val = m_PS4;
705  m_PS4 = s;
706  return val;
707  }
708 
709  void set_PS4 (const std::string& s) { m_PS4 = s; }
710 
712  {
713  return m_indexed_object;
714  }
715 
717  {
718  m_indexed_object = obj;
719  }
720 
721  const std::list<octave_value_list>& index_list () const
722  {
723  return m_index_list;
724  }
725 
726  void set_index_list (const std::string& index_type,
727  const std::list<octave_value_list>& index_list)
728  {
729  m_index_type = index_type;
730  m_index_list = index_list;
731  }
732 
734  {
735  m_index_type = "";
736  m_index_list.clear ();
737  }
738 
739  void append_index_list (char type, const octave_value_list& idx)
740  {
741  m_index_type += type;
742  m_index_list.push_back (idx);
743  }
744 
745  const std::string& index_type () const
746  {
747  return m_index_type;
748  }
749 
750  int index_position () const { return m_index_position; }
751 
752  int num_indices () const { return m_num_indices; }
753 
754  octave_value_list evaluate_end_expression (const octave_value_list& args);
755 
756  const std::list<octave_lvalue> * lvalue_list () const
757  {
758  return m_lvalue_list;
759  }
760 
761  void set_lvalue_list (const std::list<octave_lvalue> *lst)
762  {
763  m_lvalue_list = lst;
764  }
765 
766  int breaking () const { return m_breaking; }
767 
768  int breaking (int n)
769  {
770  int val = m_breaking;
771  m_breaking = n;
772  return val;
773  }
774 
775  int continuing () const { return m_continuing; }
776 
777  int continuing (int n)
778  {
779  int val = m_continuing;
780  m_continuing = n;
781  return val;
782  }
783 
784  int returning () const { return m_returning; }
785 
786  int returning (int n)
787  {
788  int val = m_returning;
789  m_returning = n;
790  return val;
791  }
792 
793  int dbstep_flag () const { return m_dbstep_flag; }
794 
795  int dbstep_flag (int val)
796  {
797  int old_val = m_dbstep_flag;
798  m_dbstep_flag = val;
799  return old_val;
800  }
801 
802  void set_dbstep_flag (int step) { m_dbstep_flag = step; }
803 
805  {
806  return m_break_on_next_stmt;
807  }
808 
809  bool break_on_next_statement (bool val)
810  {
811  bool old_val = m_break_on_next_stmt;
812  m_break_on_next_stmt = val;
813  return old_val;
814  }
815 
817  {
818  m_break_on_next_stmt = val;
819  }
820 
821  octave_value echo (const octave_value_list& args, int nargout);
822 
823  int echo () const { return m_echo; }
824 
825  int echo (int val)
826  {
827  int old_val = m_echo;
828  m_echo = val;
829 
830  return old_val;
831  }
832 
834  string_fill_char (const octave_value_list& args, int nargout);
835 
836  void final_index_error (index_exception& ie, const tree_expression *expr);
837 
838  octave_value do_who (int argc, const string_vector& argv,
839  bool return_list, bool verbose = false);
840 
842  make_value_list (tree_argument_list *args, const string_vector& arg_nm);
843 
844  std::list<octave_lvalue> make_lvalue_list (tree_argument_list *);
845 
846  void push_echo_state (int type, const std::string& file_name, int pos = 1);
847 
848  bool debug_mode () const { return m_debug_mode; }
849 
850  int echo_state () { return m_echo_state; }
851 
852  void set_echo_file_pos (int pos)
853  {
854  m_echo_file_pos = pos;
855  }
856 
857 private:
858 
859  template <typename T>
860  void execute_range_loop (const range<T>& rng, int line,
861  octave_lvalue& ult,
862  tree_statement_list *loop_body);
863 
864  void set_echo_state (int type, const std::string& file_name, int pos);
865 
866  void maybe_set_echo_state ();
867 
868  void push_echo_state_cleanup (unwind_protect& frame);
869 
870  bool maybe_push_echo_state_cleanup ();
871 
872  void do_breakpoint (tree_statement& stmt);
873 
874  void do_breakpoint (bool is_breakpoint,
875  bool is_end_of_fcn_or_script = false);
876 
877  bool is_logically_true (tree_expression *expr, const char *warn_for);
878 
879  // For unwind-protect.
880  void uwp_set_echo_state (bool state, const std::string& file_name, int pos);
881 
882  bool echo_this_file (const std::string& file, int type) const;
883 
884  void echo_code (int line);
885 
886  bool quit_loop_now ();
887 
888  void bind_auto_fcn_vars (const string_vector& arg_names,
889  const Matrix& ignored_outputs, int nargin,
890  int nargout, bool takes_varargs,
891  const octave_value_list& va_args);
892 
893  std::string check_autoload_file (const std::string& nm) const;
894 
895  interpreter& m_interpreter;
896 
897  std::shared_ptr<push_parser> m_parser;
898 
899  // The context for the current evaluation.
900  stmt_list_type m_statement_context;
901 
902  const std::list<octave_lvalue> *m_lvalue_list;
903 
904  // List of autoloads (function -> file mapping).
905  std::map<std::string, std::string> m_autoload_map;
906 
907  bp_table m_bp_table;
908 
909  call_stack m_call_stack;
910 
911  profiler m_profiler;
912 
913  // The number of the stack frame we are currently debugging.
914  std::size_t m_debug_frame;
915 
916  bool m_debug_mode;
917 
918  bool m_quiet_breakpoint_flag;
919 
920  // When entering the debugger we push it on this stack. Managing
921  // debugger invocations this way allows us to handle recursive
922  // debugger calls. When we exit a debugger the object is popped
923  // from the stack and deleted and we resume working with the
924  // previous debugger (if any) that is now at the top of the stack.
925  std::stack<debugger *> m_debugger_stack;
926 
927  std::set<std::string> m_debug_watch_expressions;
928 
929  int m_exit_status;
930 
931  // Maximum nesting level for functions, scripts, or sourced files
932  // called recursively.
933  int m_max_recursion_depth;
934 
935  // Defines layout for the whos/who -long command
936  std::string m_whos_line_format;
937 
938  // If TRUE, turn off printing of results in functions (as if a
939  // semicolon has been appended to each statement).
940  bool m_silent_functions;
941 
942  // The character to fill with when creating string arrays.
943  char m_string_fill_char;
944 
945  // String printed before echoed commands (enabled by --echo-commands).
946  std::string m_PS4;
947 
948  // If > 0, stop executing at the (N-1)th stopping point, counting
949  // from the the current execution point in the current frame.
950  //
951  // If < 0, stop executing at the next possible stopping point.
952  int m_dbstep_flag;
953 
954  // If TRUE, and we are not stopping for another reason (dbstep or a
955  // breakpoint) then stop at next statement and enter the debugger.
956  bool m_break_on_next_stmt;
957 
958  // Echo commands as they are executed?
959  //
960  // 1 => echo commands read from script files
961  // 2 => echo commands from functions
962  //
963  // more than one state can be active at once.
964  int m_echo;
965 
966  // Are we currently echoing commands? This state is set by the
967  // functions that execute functions and scripts.
968  bool m_echo_state;
969 
970  std::string m_echo_file_name;
971 
972  // Next line to echo, counting from 1. We use int here because the
973  // parser does. It also initializes line and column numbers to the
974  // invalid value -1 and that can cause trouble if cast to an
975  // unsigned value. When updating this value and echoing ranges of
976  // code, we also check to ensure that the line numbers stored in the
977  // parse tree are valid. It would be better to ensure that the
978  // parser always stores valid position info, but that's more
979  // difficult to always do correctly.
980  int m_echo_file_pos;
981 
982  std::map<std::string, bool> m_echo_files;
983 
984  // TRUE if we are in the top level interactive read eval print loop.
985  bool m_in_top_level_repl;
986 
987  // TRUE means we are executing in the server_loop function.
988  bool m_server_mode;
989 
990  // TRUE means we are evaluating some kind of looping construct.
991  bool m_in_loop_command;
992 
993  // Nonzero means we're breaking out of a loop or function body.
994  int m_breaking;
995 
996  // Nonzero means we're jumping to the end of a loop.
997  int m_continuing;
998 
999  // Nonzero means we're returning from a function.
1000  int m_returning;
1001 
1002  // The following are all used by the END function. Maybe they
1003  // should be kept together in a separate object?
1004  octave_value m_indexed_object;
1005  std::list<octave_value_list> m_index_list;
1006  std::string m_index_type;
1007  int m_index_position;
1008  int m_num_indices;
1009 };
1010 
1011 OCTAVE_END_NAMESPACE(octave)
1012 
1013 #endif
Definition: Cell.h:43
Definition: dMatrix.h:42
Definition: parse.h:822
std::map< std::string, octave_value > local_vars_map
Definition: stack-frame.h:112
void push(const T &val)
Definition: pt-eval.h:86
std::size_t size() const
Definition: pt-eval.h:105
void set_indexed_object(const octave_value &obj=octave_value())
Definition: pt-eval.h:716
int dbstep_flag(int val)
Definition: pt-eval.h:795
bool debug_mode() const
Definition: pt-eval.h:848
std::set< std::string > debug_watch_expressions() const
Definition: pt-eval.h:693
int returning(int n)
Definition: pt-eval.h:786
int max_recursion_depth() const
Definition: pt-eval.h:590
std::size_t debug_frame(std::size_t n)
Definition: pt-eval.h:627
int max_recursion_depth(int n)
Definition: pt-eval.h:592
int breaking(int n)
Definition: pt-eval.h:768
void set_PS4(const std::string &s)
Definition: pt-eval.h:709
void set_echo_file_pos(int pos)
Definition: pt-eval.h:852
bool break_on_next_statement() const
Definition: pt-eval.h:804
int echo(int val)
Definition: pt-eval.h:825
char string_fill_char(char c)
Definition: pt-eval.h:650
std::string whos_line_format(const std::string &s)
Definition: pt-eval.h:615
bool silent_functions(bool b)
Definition: pt-eval.h:604
bool in_top_level_repl() const
Definition: pt-eval.h:174
int index_position() const
Definition: pt-eval.h:750
void remove_debug_watch_expression(const std::string &expr)
Definition: pt-eval.h:679
interpreter & get_interpreter()
Definition: pt-eval.h:420
bool quiet_breakpoint_flag(bool flag)
Definition: pt-eval.h:641
octave_value indexed_object() const
Definition: pt-eval.h:711
int returning() const
Definition: pt-eval.h:784
int echo() const
Definition: pt-eval.h:823
void set_break_on_next_statement(bool val)
Definition: pt-eval.h:816
std::size_t current_call_stack_frame_number() const
Definition: pt-eval.h:634
std::size_t debug_frame() const
Definition: pt-eval.h:625
void add_debug_watch_expression(const std::string &expr)
Definition: pt-eval.h:672
tree_evaluator(interpreter &interp)
Definition: pt-eval.h:128
std::shared_ptr< push_parser > get_parser()
Definition: pt-eval.h:150
void set_parser(const std::shared_ptr< push_parser > &parser)
Definition: pt-eval.h:155
bool silent_functions() const
Definition: pt-eval.h:602
void server_mode(bool arg)
Definition: pt-eval.h:180
int echo_state()
Definition: pt-eval.h:850
std::shared_ptr< stack_frame > current_user_frame() const
Definition: pt-eval.h:448
char string_fill_char() const
Definition: pt-eval.h:648
std::shared_ptr< stack_frame > get_current_stack_frame() const
Definition: pt-eval.h:443
const std::list< octave_lvalue > * lvalue_list() const
Definition: pt-eval.h:756
bool server_mode() const
Definition: pt-eval.h:178
std::string whos_line_format() const
Definition: pt-eval.h:613
int num_indices() const
Definition: pt-eval.h:752
bp_table & get_bp_table()
Definition: pt-eval.h:422
std::string PS4(const std::string &s)
Definition: pt-eval.h:702
int continuing(int n)
Definition: pt-eval.h:777
bool break_on_next_statement(bool val)
Definition: pt-eval.h:809
const std::list< octave_value_list > & index_list() const
Definition: pt-eval.h:721
const std::string & index_type() const
Definition: pt-eval.h:745
~tree_evaluator()=default
bool quiet_breakpoint_flag() const
Definition: pt-eval.h:639
void set_lvalue_list(const std::list< octave_lvalue > *lst)
Definition: pt-eval.h:761
void set_dbstep_flag(int step)
Definition: pt-eval.h:802
int breaking() const
Definition: pt-eval.h:766
void clear_debug_watch_expressions()
Definition: pt-eval.h:686
void append_index_list(char type, const octave_value_list &idx)
Definition: pt-eval.h:739
int continuing() const
Definition: pt-eval.h:775
std::string PS4() const
Definition: pt-eval.h:700
void clear_index_list()
Definition: pt-eval.h:733
int dbstep_flag() const
Definition: pt-eval.h:793
void set_index_list(const std::string &index_type, const std::list< octave_value_list > &index_list)
Definition: pt-eval.h:726
profiler & get_profiler()
Definition: pt-eval.h:424
virtual void visit_compound_binary_expression(tree_compound_binary_expression &)
Definition: pt-walk.cc:162
virtual void visit_boolean_expression(tree_boolean_expression &)
Definition: pt-walk.cc:156
virtual void visit_unwind_protect_command(tree_unwind_protect_command &)
Definition: pt-walk.cc:612
virtual void visit_try_catch_command(tree_try_catch_command &)
Definition: pt-walk.cc:593
virtual void visit_if_command_list(tree_if_command_list &)
Definition: pt-walk.cc:345
virtual void visit_multi_assignment(tree_multi_assignment &)
Definition: pt-walk.cc:483
virtual void visit_return_command(tree_return_command &)
Definition: pt-walk.cc:547
virtual void visit_continue_command(tree_continue_command &)
Definition: pt-walk.cc:193
virtual void visit_switch_case_list(tree_switch_case_list &)
Definition: pt-walk.cc:373
virtual void visit_complex_for_command(tree_complex_for_command &)
Definition: pt-walk.cc:259
virtual void visit_break_command(tree_break_command &)
Definition: pt-walk.cc:168
virtual void visit_matrix(tree_matrix &)
Definition: pt-walk.cc:455
virtual void visit_args_block_validation_list(tree_args_block_validation_list &)
Definition: pt-walk.cc:85
virtual void visit_fcn_handle(tree_fcn_handle &)
Definition: pt-walk.cc:509
virtual void visit_colon_expression(tree_colon_expression &)
Definition: pt-walk.cc:174
virtual void visit_arg_size_spec(tree_arg_size_spec &)
Definition: pt-walk.cc:124
virtual void visit_spmd_command(tree_spmd_command &)
Definition: pt-walk.cc:278
virtual void visit_do_until_command(tree_do_until_command &)
Definition: pt-walk.cc:640
virtual void visit_no_op_command(tree_no_op_command &)
Definition: pt-walk.cc:497
virtual void visit_binary_expression(tree_binary_expression &)
Definition: pt-walk.cc:142
virtual void visit_simple_for_command(tree_simple_for_command &)
Definition: pt-walk.cc:235
virtual void visit_postfix_expression(tree_postfix_expression &)
Definition: pt-walk.cc:529
virtual void visit_prefix_expression(tree_prefix_expression &)
Definition: pt-walk.cc:538
virtual void visit_anon_fcn_handle(tree_anon_fcn_handle &)
Definition: pt-walk.cc:34
virtual void visit_args_block_attribute_list(tree_args_block_attribute_list &)
Definition: pt-walk.cc:76
virtual void visit_parameter_list(tree_parameter_list &)
Definition: pt-walk.cc:515
virtual void visit_arguments_block(tree_arguments_block &)
Definition: pt-walk.cc:62
virtual void visit_statement(tree_statement &)
Definition: pt-walk.cc:567
virtual void visit_index_expression(tree_index_expression &)
Definition: pt-walk.cc:401
virtual void visit_decl_command(tree_decl_command &)
Definition: pt-walk.cc:199
virtual void visit_switch_case(tree_switch_case &)
Definition: pt-walk.cc:359
virtual void visit_cell(tree_cell &)
Definition: pt-walk.cc:469
virtual void visit_identifier(tree_identifier &)
Definition: pt-walk.cc:316
virtual void visit_if_clause(tree_if_clause &)
Definition: pt-walk.cc:322
virtual void visit_statement_list(tree_statement_list &)
Definition: pt-walk.cc:583
virtual void visit_arg_validation_fcns(tree_arg_validation_fcns &)
Definition: pt-walk.cc:133
virtual void visit_if_command(tree_if_command &)
Definition: pt-walk.cc:336
virtual void visit_argument_list(tree_argument_list &)
Definition: pt-walk.cc:48
virtual void visit_decl_elt(tree_decl_elt &)
Definition: pt-walk.cc:208
virtual void visit_constant(tree_constant &)
Definition: pt-walk.cc:503
virtual void visit_simple_assignment(tree_simple_assignment &)
Definition: pt-walk.cc:553
virtual void visit_superclass_ref(tree_superclass_ref &)
Definition: pt-walk.cc:654
virtual void visit_octave_user_script(octave_user_script &)
Definition: pt-walk.cc:287
virtual void visit_arg_validation(tree_arg_validation &)
Definition: pt-walk.cc:95
virtual void visit_octave_user_function(octave_user_function &)
Definition: pt-walk.cc:296
virtual void visit_function_def(tree_function_def &)
Definition: pt-walk.cc:305
virtual void visit_metaclass_query(tree_metaclass_query &)
Definition: pt-walk.cc:660
virtual void visit_while_command(tree_while_command &)
Definition: pt-walk.cc:626
virtual void visit_switch_command(tree_switch_command &)
Definition: pt-walk.cc:387
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
octave_idx_type n
Definition: mx-inlines.cc:761
void source_file(const std::string &file_name, const std::string &context="", bool verbose=false, bool require_file=true)