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