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