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