2982
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 John W. Eaton |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
4153
|
27 #include "quit.h" |
|
28 |
2982
|
29 #include "defun.h" |
|
30 #include "error.h" |
|
31 #include "ov.h" |
|
32 #include "oct-lvalue.h" |
|
33 #include "input.h" |
|
34 #include "pager.h" |
3770
|
35 #include "pt-bp.h" |
2982
|
36 #include "pt-cmd.h" |
|
37 #include "pt-id.h" |
|
38 #include "pt-idx.h" |
2985
|
39 #include "pt-jump.h" |
2982
|
40 #include "pt-pr-code.h" |
|
41 #include "pt-stmt.h" |
|
42 #include "pt-walk.h" |
3707
|
43 #include "unwind-prot.h" |
2982
|
44 #include "utils.h" |
|
45 #include "variables.h" |
|
46 |
3707
|
47 // Pointer to the current statement being executed. |
|
48 tree_statement *curr_statement = 0; |
|
49 |
4975
|
50 // Pointer to the current statement being executed in the calling function. |
|
51 tree_statement *curr_caller_statement = 0; |
|
52 |
2982
|
53 // A list of commands to be executed. |
|
54 |
|
55 tree_statement::~tree_statement (void) |
|
56 { |
|
57 delete cmd; |
|
58 delete expr; |
3665
|
59 delete comm; |
2982
|
60 } |
|
61 |
|
62 int |
|
63 tree_statement::line (void) |
|
64 { |
|
65 return cmd ? cmd->line () : (expr ? expr->line () : -1); |
|
66 } |
|
67 |
|
68 int |
|
69 tree_statement::column (void) |
|
70 { |
|
71 return cmd ? cmd->column () : (expr ? expr->column () : -1); |
|
72 } |
|
73 |
|
74 void |
|
75 tree_statement::maybe_echo_code (bool in_function_body) |
|
76 { |
|
77 if (in_function_body |
|
78 && (Vecho_executing_commands & ECHO_FUNCTIONS)) |
|
79 { |
|
80 tree_print_code tpc (octave_stdout, Vps4); |
|
81 |
|
82 accept (tpc); |
|
83 } |
|
84 } |
|
85 |
|
86 octave_value_list |
|
87 tree_statement::eval (bool silent, int nargout, bool in_function_body) |
|
88 { |
|
89 octave_value_list retval; |
|
90 |
|
91 bool pf = silent ? false : print_flag; |
|
92 |
|
93 if (cmd || expr) |
|
94 { |
3708
|
95 unwind_protect_ptr (curr_statement); |
|
96 curr_statement = this; |
|
97 |
2982
|
98 maybe_echo_code (in_function_body); |
|
99 |
|
100 if (cmd) |
|
101 cmd->eval (); |
|
102 else |
|
103 { |
|
104 expr->set_print_flag (pf); |
|
105 |
|
106 // XXX FIXME XXX -- maybe all of this should be packaged in |
|
107 // one virtual function that returns a flag saying whether |
|
108 // or not the expression will take care of binding ans and |
|
109 // printing the result. |
|
110 |
4203
|
111 // XXX FIXME XXX -- it seems that we should just have to |
|
112 // call expr->rvalue () and that should take care of |
|
113 // everything, binding ans as necessary? |
|
114 |
2982
|
115 bool do_bind_ans = false; |
|
116 |
4203
|
117 bool script_file_executed = false; |
|
118 |
2982
|
119 if (expr->is_identifier ()) |
|
120 { |
|
121 tree_identifier *id = static_cast<tree_identifier *> (expr); |
|
122 |
4203
|
123 id->do_lookup (script_file_executed, true); |
2982
|
124 |
|
125 do_bind_ans = id->is_function (); |
|
126 } |
|
127 else |
3933
|
128 do_bind_ans = (! expr->is_assignment_expression ()); |
2982
|
129 |
4203
|
130 if (! script_file_executed) |
|
131 { |
|
132 retval = expr->rvalue (nargout); |
2982
|
133 |
4203
|
134 if (do_bind_ans && ! (error_state || retval.empty ())) |
|
135 bind_ans (retval(0), pf); |
|
136 } |
2982
|
137 } |
3708
|
138 |
|
139 unwind_protect::run (); |
2982
|
140 } |
|
141 |
|
142 return retval; |
|
143 } |
|
144 |
|
145 void |
|
146 tree_statement::accept (tree_walker& tw) |
|
147 { |
|
148 tw.visit_statement (*this); |
|
149 } |
|
150 |
|
151 octave_value_list |
|
152 tree_statement_list::eval (bool silent, int nargout) |
|
153 { |
|
154 octave_value_list retval; |
|
155 |
|
156 if (error_state) |
|
157 return retval; |
|
158 |
4219
|
159 for (iterator p = begin (); p != end (); p++) |
2982
|
160 { |
4219
|
161 tree_statement *elt = *p; |
2982
|
162 |
|
163 if (elt) |
|
164 { |
4153
|
165 OCTAVE_QUIT; |
|
166 |
4005
|
167 retval = elt->eval (silent, nargout, function_body); |
2982
|
168 |
|
169 if (error_state) |
|
170 break; |
|
171 |
4207
|
172 if (tree_break_command::breaking |
|
173 || tree_continue_command::continuing) |
2982
|
174 break; |
|
175 |
4207
|
176 if (tree_return_command::returning) |
2982
|
177 break; |
|
178 } |
|
179 else |
|
180 error ("invalid statement found in statement list!"); |
3707
|
181 |
|
182 |
2982
|
183 } |
|
184 |
|
185 return retval; |
|
186 } |
|
187 |
3770
|
188 int |
|
189 tree_statement_list::set_breakpoint (int line) |
|
190 { |
|
191 tree_breakpoint tbp (line, tree_breakpoint::set); |
|
192 accept (tbp); |
|
193 |
|
194 return tbp.get_line (); |
|
195 } |
|
196 |
|
197 void |
|
198 tree_statement_list::delete_breakpoint (int line) |
|
199 { |
3895
|
200 if (line < 0) |
|
201 { |
4212
|
202 octave_value_list bp_lst = list_breakpoints (); |
3895
|
203 |
4212
|
204 int len = bp_lst.length (); |
3895
|
205 |
4587
|
206 for (int i = 0; i < len; i++) |
3895
|
207 { |
4587
|
208 tree_breakpoint tbp (i, tree_breakpoint::clear); |
3895
|
209 accept (tbp); |
|
210 } |
|
211 } |
|
212 else |
|
213 { |
|
214 tree_breakpoint tbp (line, tree_breakpoint::clear); |
|
215 accept (tbp); |
|
216 } |
3770
|
217 } |
|
218 |
|
219 octave_value_list |
|
220 tree_statement_list::list_breakpoints (void) |
|
221 { |
|
222 tree_breakpoint tbp (0, tree_breakpoint::list); |
|
223 accept (tbp); |
|
224 |
|
225 return tbp.get_list (); |
|
226 } |
|
227 |
2982
|
228 void |
|
229 tree_statement_list::accept (tree_walker& tw) |
|
230 { |
|
231 tw.visit_statement_list (*this); |
|
232 } |
|
233 |
|
234 /* |
|
235 ;;; Local Variables: *** |
|
236 ;;; mode: C++ *** |
|
237 ;;; End: *** |
|
238 */ |