GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
pt-eval.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2009-2025 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
47class octave_builtin;
52
54
56class symbol_scope;
57class tree_decl_elt;
58class tree_expression;
59
60class debugger;
61class interpreter;
62class push_parser;
63class unwind_protect;
64
65// How to evaluate the code that the parse trees represent.
66
67class OCTINTERP_API tree_evaluator : public tree_walker
68{
69public:
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
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
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 = "debug> ");
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 std::string inputname (int n, bool ids_only = true) const;
350
351 octave_value make_fcn_handle (const std::string& nm);
352
353 octave_value evaluate (tree_decl_elt *);
354
355 void install_variable (const std::string& name,
356 const octave_value& value, bool global);
357
358 octave_value global_varval (const std::string& name) const;
359
360 octave_value& global_varref (const std::string& name);
361
362 void global_assign (const std::string& name,
363 const octave_value& val = octave_value ());
364
365 octave_value top_level_varval (const std::string& name) const;
366
367 void top_level_assign (const std::string& name,
368 const octave_value& val = octave_value ());
369
370 bool is_variable (const std::string& name) const;
371
372 bool is_local_variable (const std::string& name) const;
373
374 bool is_variable (const tree_expression *expr) const;
375
376 bool is_defined (const tree_expression *expr) const;
377
378 bool is_variable (const symbol_record& sym) const;
379
380 bool is_defined (const symbol_record& sym) const;
381
382 bool is_global (const std::string& name) const;
383
384 octave_value varval (const symbol_record& sym) const;
385
386 octave_value varval (const std::string& name) const;
387
388 void assign (const std::string& name,
389 const octave_value& val = octave_value ());
390
391 void assignin (const std::string& context, const std::string& name,
392 const octave_value& val = octave_value ());
393
394 void source_file (const std::string& file_name,
395 const std::string& context = "",
396 bool verbose = false, bool require_file = true);
397
398 void set_auto_fcn_var (stack_frame::auto_var_type avt,
399 const octave_value& val = octave_value ());
400
401 void set_nargin (int nargin);
402 void set_nargout (int nargout);
403
404 octave_value get_auto_fcn_var (stack_frame::auto_var_type avt) const;
405
406 void define_parameter_list_from_arg_vector
407 (tree_parameter_list *param_list, const octave_value_list& args);
408
409 void undefine_parameter_list (tree_parameter_list *param_list);
410
411 octave_value_list convert_to_const_vector (tree_argument_list *arg_list);
412
414 convert_return_list_to_const_vector
415 (tree_parameter_list *ret_list, int nargout, const Cell& varargout);
416
417 bool eval_decl_elt (tree_decl_elt *elt);
418
419 bool switch_case_label_matches (tree_switch_case *expr,
420 const octave_value& val);
421
422 interpreter& get_interpreter () { return m_interpreter; }
423
424 bp_table& get_bp_table () { return m_bp_table; }
425
426 profiler& get_profiler () { return m_profiler; }
427
428 void push_stack_frame (const symbol_scope& scope);
429
430 void push_stack_frame (octave_user_function *fcn,
431 const std::shared_ptr<stack_frame>& closure_frames = std::shared_ptr<stack_frame> ());
432
433 void push_stack_frame (octave_user_function *fcn,
434 const stack_frame::local_vars_map& local_vars,
435 const std::shared_ptr<stack_frame>& closure_frames = std::shared_ptr<stack_frame> ());
436
437 void push_stack_frame (octave_user_script *script);
438
439 void push_stack_frame (octave_function *fcn);
440
441 void pop_stack_frame ();
442
443 std::shared_ptr<stack_frame> pop_return_stack_frame ();
444
445 std::shared_ptr<stack_frame> get_current_stack_frame () const
446 {
447 return m_call_stack.get_current_stack_frame ();
448 }
449
450 std::shared_ptr<stack_frame> current_user_frame () const
451 {
452 return m_call_stack.current_user_frame ();
453 }
454
455 // Current line in current function.
456 int current_line () const;
457
458 // Current column in current function.
459 int current_column () const;
460
461 // Line number in current function that we are debugging.
462 int debug_user_code_line () const;
463
464 // Column number in current function that we are debugging.
465 int debug_user_code_column () const;
466
467 void debug_where (std::ostream& os) const;
468
469 void debug_list (std::ostream& os, int num_lines) const;
470
471 void debug_type (std::ostream& os, int start_line, int end_line) const;
472
473 octave_user_code * current_user_code () const;
474
475 unwind_protect * curr_fcn_unwind_protect_frame ();
476
477 // Current function that we are debugging.
478 octave_user_code * debug_user_code () const;
479
480 octave_function * current_function (bool skip_first = false) const;
481
482 octave_function * caller_function () const;
483
484 bool goto_frame (std::size_t n = 0, bool verbose = false);
485
486 void goto_caller_frame ();
487
488 void goto_base_frame ();
489
490 void restore_frame (std::size_t n);
491
492 std::string get_dispatch_class () const;
493
494 void set_dispatch_class (const std::string& class_name);
495
496 bool is_class_method_executing (std::string& dispatch_class) const;
497
498 bool is_class_constructor_executing (std::string& dispatch_class) const;
499
500 std::list<std::shared_ptr<stack_frame>>
501 backtrace_frames (octave_idx_type& curr_user_frame) const;
502
503 std::list<std::shared_ptr<stack_frame>> backtrace_frames () const;
504
505 std::list<frame_info> backtrace_info (octave_idx_type& curr_user_frame,
506 bool print_subfn = true) const;
507
508 std::list<frame_info> backtrace_info () const;
509
510 octave_map backtrace (octave_idx_type& curr_user_frame,
511 bool print_subfn = true) const;
512
513 octave_map backtrace () const;
514
515 octave_map empty_backtrace () const;
516
517 std::string backtrace_message () const;
518
519 void push_dummy_scope (const std::string& name);
520 void pop_scope ();
521
522 symbol_scope get_top_scope () const;
523 symbol_scope get_current_scope () const;
524
525 void mlock (bool skip_first = false) const;
526
527 void munlock (bool skip_first = false) const;
528
529 bool mislocked (bool skip_first = false) const;
530
531 octave_value max_stack_depth (const octave_value_list& args, int nargout);
532
533 // Useful for debugging
534 void display_call_stack () const;
535
536 octave_value find (const std::string& name);
537
538 void clear_objects ();
539
540 void clear_variable (const std::string& name);
541
542 void clear_variable_pattern (const std::string& pattern);
543
544 void clear_variable_regexp (const std::string& pattern);
545
546 void clear_variables ();
547
548 void clear_global_variable (const std::string& name);
549
550 void clear_global_variable_pattern (const std::string& pattern);
551
552 void clear_global_variable_regexp (const std::string& pattern);
553
554 void clear_global_variables ();
555
556 void clear_all (bool force = false);
557
558 void clear_symbol (const std::string& name);
559
560 void clear_symbol_pattern (const std::string& pattern);
561
562 void clear_symbol_regexp (const std::string& pattern);
563
564 std::list<std::string> global_variable_names () const;
565
566 std::list<std::string> top_level_variable_names () const;
567
568 std::list<std::string> variable_names () const;
569
570 octave_user_code * get_user_code (const std::string& fname = "");
571
572 std::string current_function_name (bool skip_first = false) const;
573
574 bool in_user_code () const;
575
576 symbol_info_list glob_symbol_info (const std::string& pattern) const;
577
578 symbol_info_list regexp_symbol_info (const std::string& pattern) const;
579
580 symbol_info_list get_symbol_info ();
581
582 symbol_info_list top_scope_symbol_info () const;
583
584 octave_map get_autoload_map () const;
585
586 std::string lookup_autoload (const std::string& nm) const;
587
588 std::list<std::string> autoloaded_functions () const;
589
590 std::list<std::string> reverse_lookup_autoload (const std::string& nm) const;
591
592 void add_autoload (const std::string& fcn, const std::string& nm);
593
594 void remove_autoload (const std::string& fcn, const std::string& nm);
595
596 int max_recursion_depth () const { return m_max_recursion_depth; }
597
599 {
600 int val = m_max_recursion_depth;
601 m_max_recursion_depth = n;
602 return val;
603 }
604
606 max_recursion_depth (const octave_value_list& args, int nargout);
607
608 bool silent_functions () const { return m_silent_functions; }
609
610 bool silent_functions (bool b)
611 {
612 int val = m_silent_functions;
613 m_silent_functions = b;
614 return val;
615 }
616
617 octave_value whos_line_format (const octave_value_list& args, int nargout);
618
619 std::string whos_line_format () const { return m_whos_line_format; }
620
621 std::string whos_line_format (const std::string& s)
622 {
623 std::string val = m_whos_line_format;
624 m_whos_line_format = s;
625 return val;
626 }
627
629 silent_functions (const octave_value_list& args, int nargout);
630
631 std::size_t debug_frame () const { return m_debug_frame; }
632
633 std::size_t debug_frame (std::size_t n)
634 {
635 std::size_t val = m_debug_frame;
636 m_debug_frame = n;
637 return val;
638 }
639
641 {
642 return m_call_stack.current_frame ();
643 }
644
645 bool quiet_breakpoint_flag () const { return m_quiet_breakpoint_flag; }
646
647 bool quiet_breakpoint_flag (bool flag)
648 {
649 bool val = m_quiet_breakpoint_flag;
650 m_quiet_breakpoint_flag = flag;
651 return val;
652 }
653
654 char string_fill_char () const { return m_string_fill_char; }
655
656 char string_fill_char (char c)
657 {
658 int val = m_string_fill_char;
659 m_string_fill_char = c;
660 return val;
661 }
662
663 // The following functions are provided for convenience. They
664 // call the corresponding functions in the debugger class for the
665 // current debugger (if any).
666
667 bool in_debug_repl () const;
668
669 void dbcont ();
670
671 // Return true if we are in the debug repl and m_execution_mode is
672 // set to exit the debugger. Otherwise, do nothing.
673
674 void dbquit (bool all = false);
675
676 // Add EXPR to the set of expressions that may be evaluated when the
677 // debugger stops at a breakpoint.
678 void add_debug_watch_expression (const std::string& expr)
679 {
680 m_debug_watch_expressions.insert (expr);
681 }
682
683 // Remove EXPR from the set of expressions that may be evaluated
684 // when the debugger stops at a breakpoint.
685 void remove_debug_watch_expression (const std::string& expr)
686 {
687 m_debug_watch_expressions.erase (expr);
688 }
689
690 // Clear the set of expressions that may be evaluated when the
691 // debugger stops at a breakpoint.
693 {
694 m_debug_watch_expressions.clear ();
695 }
696
697 // Return the set of expressions that may be evaluated when the
698 // debugger stops at a breakpoint.
699 std::set<std::string> debug_watch_expressions () const
700 {
701 return m_debug_watch_expressions;
702 }
703
704 octave_value PS4 (const octave_value_list& args, int nargout);
705
706 std::string PS4 () const { return m_PS4; }
707
708 std::string PS4 (const std::string& s)
709 {
710 std::string val = m_PS4;
711 m_PS4 = s;
712 return val;
713 }
714
715 void set_PS4 (const std::string& s) { m_PS4 = s; }
716
718 {
719 return m_indexed_object;
720 }
721
723 {
724 m_indexed_object = obj;
725 }
726
727 const std::list<octave_value_list>& index_list () const
728 {
729 return m_index_list;
730 }
731
732 void set_index_list (const std::string& index_type,
733 const std::list<octave_value_list>& index_list)
734 {
735 m_index_type = index_type;
736 m_index_list = index_list;
737 }
738
740 {
741 m_index_type = "";
742 m_index_list.clear ();
743 }
744
745 void append_index_list (char type, const octave_value_list& idx)
746 {
747 m_index_type += type;
748 m_index_list.push_back (idx);
749 }
750
751 const std::string& index_type () const
752 {
753 return m_index_type;
754 }
755
756 int index_position () const { return m_index_position; }
757
758 int num_indices () const { return m_num_indices; }
759
760 octave_value_list evaluate_end_expression (const octave_value_list& args);
761
762 const std::list<octave_lvalue> * lvalue_list () const
763 {
764 return m_lvalue_list;
765 }
766
767 void set_lvalue_list (const std::list<octave_lvalue> *lst)
768 {
769 m_lvalue_list = lst;
770 }
771
772 int breaking () const { return m_breaking; }
773
774 int breaking (int n)
775 {
776 int val = m_breaking;
777 m_breaking = n;
778 return val;
779 }
780
781 int continuing () const { return m_continuing; }
782
783 int continuing (int n)
784 {
785 int val = m_continuing;
786 m_continuing = n;
787 return val;
788 }
789
790 int returning () const { return m_returning; }
791
792 int returning (int n)
793 {
794 int val = m_returning;
795 m_returning = n;
796 return val;
797 }
798
799 int dbstep_flag () const { return m_dbstep_flag; }
800
801 int dbstep_flag (int val)
802 {
803 int old_val = m_dbstep_flag;
804 m_dbstep_flag = val;
805 return old_val;
806 }
807
808 void set_dbstep_flag (int step) { m_dbstep_flag = step; }
809
811 {
812 return m_break_on_next_stmt;
813 }
814
816 {
817 bool old_val = m_break_on_next_stmt;
818 m_break_on_next_stmt = val;
819 return old_val;
820 }
821
823 {
824 m_break_on_next_stmt = val;
825 }
826
827 octave_value echo (const octave_value_list& args, int nargout);
828
829 int echo () const { return m_echo; }
830
831 int echo (int val)
832 {
833 int old_val = m_echo;
834 m_echo = val;
835
836 return old_val;
837 }
838
840 string_fill_char (const octave_value_list& args, int nargout);
841
842 void final_index_error (index_exception& ie, const tree_expression *expr);
843
844 octave_value do_who (int argc, const string_vector& argv,
845 bool return_list, bool verbose = false);
846
848 make_value_list (tree_argument_list *args, const string_vector& arg_nm);
849
850 std::list<octave_lvalue> make_lvalue_list (tree_argument_list *);
851
852 void push_echo_state (int type, const std::string& file_name, int pos = 1);
853
854 bool debug_mode () const { return m_debug_mode; }
855
856 int echo_state () { return m_echo_state; }
857
858 void set_echo_file_pos (int pos)
859 {
860 m_echo_file_pos = pos;
861 }
862
863private:
864
865 template <typename T>
866 void execute_range_loop (const range<T>& rng, int line,
867 octave_lvalue& ult,
868 tree_statement_list *loop_body);
869
870 void set_echo_state (int type, const std::string& file_name, int pos);
871
872 void maybe_set_echo_state ();
873
874 void push_echo_state_cleanup (unwind_protect& frame);
875
876 bool maybe_push_echo_state_cleanup ();
877
878 void do_breakpoint (tree_statement& stmt);
879
880 void do_breakpoint (bool is_breakpoint,
881 bool is_end_of_fcn_or_script = false);
882
883 bool is_logically_true (tree_expression *expr, const char *warn_for);
884
885 // For unwind-protect.
886 void uwp_set_echo_state (bool state, const std::string& file_name, int pos);
887
888 bool echo_this_file (const std::string& file, int type) const;
889
890 void echo_code (int line);
891
892 bool quit_loop_now ();
893
894 void bind_auto_fcn_vars (const string_vector& arg_names,
895 const Matrix& ignored_outputs, int nargin,
896 int nargout, bool takes_varargs,
897 const octave_value_list& va_args);
898
899 std::string check_autoload_file (const std::string& nm) const;
900
901 interpreter& m_interpreter;
902
903 std::shared_ptr<push_parser> m_parser;
904
905 // The context for the current evaluation.
906 stmt_list_type m_statement_context;
907
908 const std::list<octave_lvalue> *m_lvalue_list;
909
910 // List of autoloads (function -> file mapping).
911 std::map<std::string, std::string> m_autoload_map;
912
913 bp_table m_bp_table;
914
915 call_stack m_call_stack;
916
917 profiler m_profiler;
918
919 // The number of the stack frame we are currently debugging.
920 std::size_t m_debug_frame;
921
922 bool m_debug_mode;
923
924 bool m_quiet_breakpoint_flag;
925
926 // When entering the debugger we push it on this stack. Managing
927 // debugger invocations this way allows us to handle recursive
928 // debugger calls. When we exit a debugger the object is popped
929 // from the stack and deleted and we resume working with the
930 // previous debugger (if any) that is now at the top of the stack.
931 std::stack<debugger *> m_debugger_stack;
932
933 std::set<std::string> m_debug_watch_expressions;
934
935 int m_exit_status;
936
937 // Maximum nesting level for functions, scripts, or sourced files
938 // called recursively.
939 int m_max_recursion_depth;
940
941 // Defines layout for the whos/who -long command
942 std::string m_whos_line_format;
943
944 // If TRUE, turn off printing of results in functions (as if a
945 // semicolon has been appended to each statement).
946 bool m_silent_functions;
947
948 // The character to fill with when creating string arrays.
949 char m_string_fill_char;
950
951 // String printed before echoed commands (enabled by --echo-commands).
952 std::string m_PS4;
953
954 // If > 0, stop executing at the (N-1)th stopping point, counting
955 // from the the current execution point in the current frame.
956 //
957 // If < 0, stop executing at the next possible stopping point.
958 int m_dbstep_flag;
959
960 // If TRUE, and we are not stopping for another reason (dbstep or a
961 // breakpoint) then stop at next statement and enter the debugger.
962 bool m_break_on_next_stmt;
963
964 // Echo commands as they are executed?
965 //
966 // 1 => echo commands read from script files
967 // 2 => echo commands from functions
968 //
969 // more than one state can be active at once.
970 int m_echo;
971
972 // Are we currently echoing commands? This state is set by the
973 // functions that execute functions and scripts.
974 bool m_echo_state;
975
976 std::string m_echo_file_name;
977
978 // Next line to echo, counting from 1. We use int here because the
979 // parser does. It also initializes line and column numbers to the
980 // invalid value -1 and that can cause trouble if cast to an
981 // unsigned value. When updating this value and echoing ranges of
982 // code, we also check to ensure that the line numbers stored in the
983 // parse tree are valid. It would be better to ensure that the
984 // parser always stores valid position info, but that's more
985 // difficult to always do correctly.
986 int m_echo_file_pos;
987
988 std::map<std::string, bool> m_echo_files;
989
990 // TRUE if we are in the top level interactive read eval print loop.
991 bool m_in_top_level_repl;
992
993 // TRUE means we are executing in the server_loop function.
994 bool m_server_mode;
995
996 // TRUE means we are evaluating some kind of looping construct.
997 bool m_in_loop_command;
998
999 // Nonzero means we're breaking out of a loop or function body.
1000 int m_breaking;
1001
1002 // Nonzero means we're jumping to the end of a loop.
1003 int m_continuing;
1004
1005 // Nonzero means we're returning from a function.
1006 int m_returning;
1007
1008 // The following are all used by the END function. Maybe they
1009 // should be kept together in a separate object?
1010 octave_value m_indexed_object;
1011 std::list<octave_value_list> m_index_list;
1012 std::string m_index_type;
1013 int m_index_position;
1014 int m_num_indices;
1015};
1016
1017OCTAVE_END_NAMESPACE(octave)
1018
1019#endif
Definition Cell.h:41
std::map< std::string, octave_value > local_vars_map
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:722
int dbstep_flag(int val)
Definition pt-eval.h:801
bool debug_mode() const
Definition pt-eval.h:854
int returning(int n)
Definition pt-eval.h:792
int max_recursion_depth() const
Definition pt-eval.h:596
interpreter & get_interpreter()
Definition pt-eval.h:422
std::size_t debug_frame(std::size_t n)
Definition pt-eval.h:633
int max_recursion_depth(int n)
Definition pt-eval.h:598
int breaking(int n)
Definition pt-eval.h:774
const std::list< octave_lvalue > * lvalue_list() const
Definition pt-eval.h:762
void set_PS4(const std::string &s)
Definition pt-eval.h:715
void set_echo_file_pos(int pos)
Definition pt-eval.h:858
bool break_on_next_statement() const
Definition pt-eval.h:810
int echo(int val)
Definition pt-eval.h:831
char string_fill_char(char c)
Definition pt-eval.h:656
std::string whos_line_format(const std::string &s)
Definition pt-eval.h:621
profiler & get_profiler()
Definition pt-eval.h:426
bool silent_functions(bool b)
Definition pt-eval.h:610
bool in_top_level_repl() const
Definition pt-eval.h:174
int index_position() const
Definition pt-eval.h:756
void remove_debug_watch_expression(const std::string &expr)
Definition pt-eval.h:685
const std::list< octave_value_list > & index_list() const
Definition pt-eval.h:727
bool quiet_breakpoint_flag(bool flag)
Definition pt-eval.h:647
octave_value indexed_object() const
Definition pt-eval.h:717
bp_table & get_bp_table()
Definition pt-eval.h:424
int returning() const
Definition pt-eval.h:790
int echo() const
Definition pt-eval.h:829
std::shared_ptr< push_parser > get_parser()
Definition pt-eval.h:150
void set_break_on_next_statement(bool val)
Definition pt-eval.h:822
std::size_t current_call_stack_frame_number() const
Definition pt-eval.h:640
std::size_t debug_frame() const
Definition pt-eval.h:631
void add_debug_watch_expression(const std::string &expr)
Definition pt-eval.h:678
tree_evaluator(interpreter &interp)
Definition pt-eval.h:128
void set_parser(const std::shared_ptr< push_parser > &parser)
Definition pt-eval.h:155
bool silent_functions() const
Definition pt-eval.h:608
void server_mode(bool arg)
Definition pt-eval.h:180
int echo_state()
Definition pt-eval.h:856
char string_fill_char() const
Definition pt-eval.h:654
std::shared_ptr< stack_frame > current_user_frame() const
Definition pt-eval.h:450
bool server_mode() const
Definition pt-eval.h:178
std::string whos_line_format() const
Definition pt-eval.h:619
int num_indices() const
Definition pt-eval.h:758
std::string PS4(const std::string &s)
Definition pt-eval.h:708
int continuing(int n)
Definition pt-eval.h:783
const std::string & index_type() const
Definition pt-eval.h:751
bool break_on_next_statement(bool val)
Definition pt-eval.h:815
~tree_evaluator()=default
std::set< std::string > debug_watch_expressions() const
Definition pt-eval.h:699
bool quiet_breakpoint_flag() const
Definition pt-eval.h:645
void set_lvalue_list(const std::list< octave_lvalue > *lst)
Definition pt-eval.h:767
void set_dbstep_flag(int step)
Definition pt-eval.h:808
int breaking() const
Definition pt-eval.h:772
void clear_debug_watch_expressions()
Definition pt-eval.h:692
void append_index_list(char type, const octave_value_list &idx)
Definition pt-eval.h:745
int continuing() const
Definition pt-eval.h:781
std::string PS4() const
Definition pt-eval.h:706
std::shared_ptr< stack_frame > get_current_stack_frame() const
Definition pt-eval.h:445
void clear_index_list()
Definition pt-eval.h:739
int dbstep_flag() const
Definition pt-eval.h:799
void set_index_list(const std::string &index_type, const std::list< octave_value_list > &index_list)
Definition pt-eval.h:732
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
void source_file(const std::string &file_name, const std::string &context, bool verbose, bool require_file)