Mercurial > octave
comparison libinterp/parse-tree/pt-eval.h @ 22196:dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
* oct-parse.in.yy, parse.h: Move parser classes to octave namespace.
* lex.ll, lex.h: Move lexer classes to octave namespace.
* pt-eval.h, pt-eval.cc: Move evaluator class to octave namespace.
Don't define global current evaluator pointer here.
* debug.cc, error.cc, input.cc, input.h, ls-mat-ascii.cc, pt-jit.cc,
sighandlers.cc, utils.cc, variables.cc, ov-usr-fcn.cc, pt-assign.cc,
pt-exp.h, pt-id.cc: Update for namespaces.
* interpreter.cc, interpreter.h (current_evaluator): New global var.
(interpreter::m_evaluator): New data member.
(interpreter::~interpreter): Delete evaluator.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 12 Jul 2016 14:28:07 -0400 |
parents | 1473547f50f5 |
children | bac0d6f07a3e |
comparison
equal
deleted
inserted
replaced
22195:93ed9396f2c3 | 22196:dd992fd74fce |
---|---|
32 #include "ovl.h" | 32 #include "ovl.h" |
33 #include "pt-walk.h" | 33 #include "pt-walk.h" |
34 | 34 |
35 class tree_expression; | 35 class tree_expression; |
36 | 36 |
37 // How to evaluate the code that the parse trees represent. | 37 namespace octave |
38 | |
39 class | |
40 OCTINTERP_API | |
41 tree_evaluator : public tree_walker | |
42 { | 38 { |
43 public: | 39 class interpreter; |
44 | 40 |
45 typedef void (*decl_elt_init_fcn) (tree_decl_elt&); | 41 // How to evaluate the code that the parse trees represent. |
46 | 42 |
47 tree_evaluator (void) { } | 43 class |
48 | 44 OCTINTERP_API |
49 ~tree_evaluator (void) { } | 45 tree_evaluator : public tree_walker |
50 | |
51 void visit_anon_fcn_handle (tree_anon_fcn_handle&); | |
52 | |
53 void visit_argument_list (tree_argument_list&); | |
54 | |
55 void visit_binary_expression (tree_binary_expression&); | |
56 | |
57 void visit_break_command (tree_break_command&); | |
58 | |
59 void visit_colon_expression (tree_colon_expression&); | |
60 | |
61 void visit_continue_command (tree_continue_command&); | |
62 | |
63 void visit_global_command (tree_global_command&); | |
64 | |
65 void visit_persistent_command (tree_persistent_command&); | |
66 | |
67 void visit_decl_elt (tree_decl_elt&); | |
68 | |
69 void visit_decl_init_list (tree_decl_init_list&); | |
70 | |
71 void visit_simple_for_command (tree_simple_for_command&); | |
72 | |
73 void visit_complex_for_command (tree_complex_for_command&); | |
74 | |
75 void visit_octave_user_script (octave_user_script&); | |
76 | |
77 void visit_octave_user_function (octave_user_function&); | |
78 | |
79 void visit_octave_user_function_header (octave_user_function&); | |
80 | |
81 void visit_octave_user_function_trailer (octave_user_function&); | |
82 | |
83 void visit_function_def (tree_function_def&); | |
84 | |
85 void visit_identifier (tree_identifier&); | |
86 | |
87 void visit_if_clause (tree_if_clause&); | |
88 | |
89 void visit_if_command (tree_if_command&); | |
90 | |
91 void visit_if_command_list (tree_if_command_list&); | |
92 | |
93 void visit_index_expression (tree_index_expression&); | |
94 | |
95 void visit_matrix (tree_matrix&); | |
96 | |
97 void visit_cell (tree_cell&); | |
98 | |
99 void visit_multi_assignment (tree_multi_assignment&); | |
100 | |
101 void visit_no_op_command (tree_no_op_command&); | |
102 | |
103 void visit_constant (tree_constant&); | |
104 | |
105 void visit_fcn_handle (tree_fcn_handle&); | |
106 | |
107 void visit_funcall (tree_funcall&); | |
108 | |
109 void visit_parameter_list (tree_parameter_list&); | |
110 | |
111 void visit_postfix_expression (tree_postfix_expression&); | |
112 | |
113 void visit_prefix_expression (tree_prefix_expression&); | |
114 | |
115 void visit_return_command (tree_return_command&); | |
116 | |
117 void visit_return_list (tree_return_list&); | |
118 | |
119 void visit_simple_assignment (tree_simple_assignment&); | |
120 | |
121 void visit_statement (tree_statement&); | |
122 | |
123 void visit_statement_list (tree_statement_list&); | |
124 | |
125 void visit_switch_case (tree_switch_case&); | |
126 | |
127 void visit_switch_case_list (tree_switch_case_list&); | |
128 | |
129 void visit_switch_command (tree_switch_command&); | |
130 | |
131 void visit_try_catch_command (tree_try_catch_command&); | |
132 | |
133 void do_unwind_protect_cleanup_code (tree_statement_list *list); | |
134 | |
135 void visit_unwind_protect_command (tree_unwind_protect_command&); | |
136 | |
137 void visit_while_command (tree_while_command&); | |
138 | |
139 void visit_do_until_command (tree_do_until_command&); | |
140 | |
141 static void reset_debug_state (void); | |
142 | |
143 static bool statement_printing_enabled (void); | |
144 | |
145 // If > 0, stop executing at the (N-1)th stopping point, counting | |
146 // from the the current execution point in the current frame. | |
147 // | |
148 // If < 0, stop executing at the next possible stopping point. | |
149 static int dbstep_flag; | |
150 | |
151 // The number of the stack frame we are currently debugging. | |
152 static size_t current_frame; | |
153 | |
154 static bool debug_mode; | |
155 | |
156 static bool quiet_breakpoint_flag; | |
157 | |
158 // Possible types of evaluation contexts. | |
159 enum stmt_list_type | |
160 { | 46 { |
161 function, // function body | 47 public: |
162 script, // script file | 48 |
163 other // command-line input or eval string | 49 typedef void (*decl_elt_init_fcn) (tree_decl_elt&); |
50 | |
51 tree_evaluator (interpreter *interp_context) | |
52 : m_interp_context (interp_context) | |
53 { } | |
54 | |
55 ~tree_evaluator (void) { } | |
56 | |
57 void visit_anon_fcn_handle (tree_anon_fcn_handle&); | |
58 | |
59 void visit_argument_list (tree_argument_list&); | |
60 | |
61 void visit_binary_expression (tree_binary_expression&); | |
62 | |
63 void visit_break_command (tree_break_command&); | |
64 | |
65 void visit_colon_expression (tree_colon_expression&); | |
66 | |
67 void visit_continue_command (tree_continue_command&); | |
68 | |
69 void visit_global_command (tree_global_command&); | |
70 | |
71 void visit_persistent_command (tree_persistent_command&); | |
72 | |
73 void visit_decl_elt (tree_decl_elt&); | |
74 | |
75 void visit_decl_init_list (tree_decl_init_list&); | |
76 | |
77 void visit_simple_for_command (tree_simple_for_command&); | |
78 | |
79 void visit_complex_for_command (tree_complex_for_command&); | |
80 | |
81 void visit_octave_user_script (octave_user_script&); | |
82 | |
83 void visit_octave_user_function (octave_user_function&); | |
84 | |
85 void visit_octave_user_function_header (octave_user_function&); | |
86 | |
87 void visit_octave_user_function_trailer (octave_user_function&); | |
88 | |
89 void visit_function_def (tree_function_def&); | |
90 | |
91 void visit_identifier (tree_identifier&); | |
92 | |
93 void visit_if_clause (tree_if_clause&); | |
94 | |
95 void visit_if_command (tree_if_command&); | |
96 | |
97 void visit_if_command_list (tree_if_command_list&); | |
98 | |
99 void visit_index_expression (tree_index_expression&); | |
100 | |
101 void visit_matrix (tree_matrix&); | |
102 | |
103 void visit_cell (tree_cell&); | |
104 | |
105 void visit_multi_assignment (tree_multi_assignment&); | |
106 | |
107 void visit_no_op_command (tree_no_op_command&); | |
108 | |
109 void visit_constant (tree_constant&); | |
110 | |
111 void visit_fcn_handle (tree_fcn_handle&); | |
112 | |
113 void visit_funcall (tree_funcall&); | |
114 | |
115 void visit_parameter_list (tree_parameter_list&); | |
116 | |
117 void visit_postfix_expression (tree_postfix_expression&); | |
118 | |
119 void visit_prefix_expression (tree_prefix_expression&); | |
120 | |
121 void visit_return_command (tree_return_command&); | |
122 | |
123 void visit_return_list (tree_return_list&); | |
124 | |
125 void visit_simple_assignment (tree_simple_assignment&); | |
126 | |
127 void visit_statement (tree_statement&); | |
128 | |
129 void visit_statement_list (tree_statement_list&); | |
130 | |
131 void visit_switch_case (tree_switch_case&); | |
132 | |
133 void visit_switch_case_list (tree_switch_case_list&); | |
134 | |
135 void visit_switch_command (tree_switch_command&); | |
136 | |
137 void visit_try_catch_command (tree_try_catch_command&); | |
138 | |
139 void do_unwind_protect_cleanup_code (tree_statement_list *list); | |
140 | |
141 void visit_unwind_protect_command (tree_unwind_protect_command&); | |
142 | |
143 void visit_while_command (tree_while_command&); | |
144 | |
145 void visit_do_until_command (tree_do_until_command&); | |
146 | |
147 static void reset_debug_state (void); | |
148 | |
149 static bool statement_printing_enabled (void); | |
150 | |
151 // If > 0, stop executing at the (N-1)th stopping point, counting | |
152 // from the the current execution point in the current frame. | |
153 // | |
154 // If < 0, stop executing at the next possible stopping point. | |
155 static int dbstep_flag; | |
156 | |
157 // The number of the stack frame we are currently debugging. | |
158 static size_t current_frame; | |
159 | |
160 static bool debug_mode; | |
161 | |
162 static bool quiet_breakpoint_flag; | |
163 | |
164 // Possible types of evaluation contexts. | |
165 enum stmt_list_type | |
166 { | |
167 function, // function body | |
168 script, // script file | |
169 other // command-line input or eval string | |
170 }; | |
171 | |
172 // The context for the current evaluation. | |
173 static stmt_list_type statement_context; | |
174 | |
175 // TRUE means we are evaluating some kind of looping construct. | |
176 static bool in_loop_command; | |
177 | |
178 private: | |
179 | |
180 void do_decl_init_list (decl_elt_init_fcn fcn, | |
181 tree_decl_init_list *init_list); | |
182 | |
183 void do_breakpoint (tree_statement& stmt) const; | |
184 | |
185 void do_breakpoint (bool is_breakpoint, | |
186 bool is_end_of_fcn_or_script = false) const; | |
187 | |
188 virtual octave_value | |
189 do_keyboard (const octave_value_list& args = octave_value_list ()) const; | |
190 | |
191 interpreter *m_interp_context; | |
192 | |
193 // No copying! | |
194 | |
195 tree_evaluator (const tree_evaluator&); | |
196 | |
197 tree_evaluator& operator = (const tree_evaluator&); | |
164 }; | 198 }; |
165 | 199 } |
166 // The context for the current evaluation. | |
167 static stmt_list_type statement_context; | |
168 | |
169 // TRUE means we are evaluating some kind of looping construct. | |
170 static bool in_loop_command; | |
171 | |
172 private: | |
173 | |
174 void do_decl_init_list (decl_elt_init_fcn fcn, | |
175 tree_decl_init_list *init_list); | |
176 | |
177 void do_breakpoint (tree_statement& stmt) const; | |
178 | |
179 void do_breakpoint (bool is_breakpoint, | |
180 bool is_end_of_fcn_or_script = false) const; | |
181 | |
182 virtual octave_value | |
183 do_keyboard (const octave_value_list& args = octave_value_list ()) const; | |
184 | |
185 // No copying! | |
186 | |
187 tree_evaluator (const tree_evaluator&); | |
188 | |
189 tree_evaluator& operator = (const tree_evaluator&); | |
190 }; | |
191 | |
192 extern tree_evaluator *current_evaluator; | |
193 | 200 |
194 // Maximum nesting level for functions, scripts, or sourced files called | 201 // Maximum nesting level for functions, scripts, or sourced files called |
195 // recursively. | 202 // recursively. |
196 extern int Vmax_recursion_depth; | 203 extern int Vmax_recursion_depth; |
197 | 204 |