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 #if defined (__GNUG__) |
|
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" |
|
39 #include "pt-cmd.h" |
|
40 #include "pt-id.h" |
|
41 #include "pt-idx.h" |
2985
|
42 #include "pt-jump.h" |
2982
|
43 #include "pt-pr-code.h" |
|
44 #include "pt-stmt.h" |
|
45 #include "pt-walk.h" |
|
46 #include "utils.h" |
|
47 #include "variables.h" |
|
48 |
|
49 // If TRUE, turn off printing of results in functions (as if a |
|
50 // semicolon has been appended to each statement). |
|
51 static bool Vsilent_functions; |
|
52 |
|
53 // A list of commands to be executed. |
|
54 |
|
55 tree_statement::~tree_statement (void) |
|
56 { |
|
57 delete cmd; |
|
58 delete expr; |
|
59 } |
|
60 |
|
61 int |
|
62 tree_statement::line (void) |
|
63 { |
|
64 return cmd ? cmd->line () : (expr ? expr->line () : -1); |
|
65 } |
|
66 |
|
67 int |
|
68 tree_statement::column (void) |
|
69 { |
|
70 return cmd ? cmd->column () : (expr ? expr->column () : -1); |
|
71 } |
|
72 |
|
73 void |
|
74 tree_statement::maybe_echo_code (bool in_function_body) |
|
75 { |
|
76 if (in_function_body |
|
77 && (Vecho_executing_commands & ECHO_FUNCTIONS)) |
|
78 { |
|
79 tree_print_code tpc (octave_stdout, Vps4); |
|
80 |
|
81 accept (tpc); |
|
82 } |
|
83 } |
|
84 |
|
85 octave_value_list |
|
86 tree_statement::eval (bool silent, int nargout, bool in_function_body) |
|
87 { |
|
88 octave_value_list retval; |
|
89 |
|
90 bool pf = silent ? false : print_flag; |
|
91 |
|
92 if (cmd || expr) |
|
93 { |
|
94 maybe_echo_code (in_function_body); |
|
95 |
|
96 if (cmd) |
|
97 cmd->eval (); |
|
98 else |
|
99 { |
|
100 expr->set_print_flag (pf); |
|
101 |
|
102 // XXX FIXME XXX -- maybe all of this should be packaged in |
|
103 // one virtual function that returns a flag saying whether |
|
104 // or not the expression will take care of binding ans and |
|
105 // printing the result. |
|
106 |
|
107 bool do_bind_ans = false; |
|
108 |
|
109 if (expr->is_identifier ()) |
|
110 { |
|
111 bool script_file_executed = false; |
|
112 |
|
113 tree_identifier *id = static_cast<tree_identifier *> (expr); |
|
114 |
|
115 id->do_lookup (script_file_executed, false); |
|
116 |
|
117 do_bind_ans = id->is_function (); |
|
118 } |
|
119 else |
|
120 do_bind_ans = (! (expr->is_indirect_ref () |
|
121 || expr->is_assignment_expression ())); |
|
122 |
|
123 retval = expr->rvalue (nargout); |
|
124 |
|
125 if (do_bind_ans && ! (error_state || retval.empty ())) |
|
126 bind_ans (retval(0), pf); |
|
127 } |
|
128 } |
|
129 |
|
130 return retval; |
|
131 } |
|
132 |
|
133 void |
|
134 tree_statement::accept (tree_walker& tw) |
|
135 { |
|
136 tw.visit_statement (*this); |
|
137 } |
|
138 |
|
139 octave_value_list |
|
140 tree_statement_list::eval (bool silent, int nargout) |
|
141 { |
|
142 octave_value_list retval; |
|
143 |
|
144 if (error_state) |
|
145 return retval; |
|
146 |
|
147 for (Pix p = first (); p != 0; next (p)) |
|
148 { |
|
149 tree_statement *elt = this->operator () (p); |
|
150 |
|
151 if (elt) |
|
152 { |
|
153 bool silent_flag = |
|
154 silent ? true : (function_body ? Vsilent_functions : false); |
|
155 |
|
156 retval = elt->eval (silent_flag, nargout, function_body); |
|
157 |
|
158 if (error_state) |
|
159 break; |
|
160 |
2985
|
161 if (tree_break_command::breaking |
|
162 || tree_continue_command::continuing) |
2982
|
163 break; |
|
164 |
2985
|
165 if (tree_return_command::returning) |
2982
|
166 break; |
|
167 } |
|
168 else |
|
169 error ("invalid statement found in statement list!"); |
|
170 } |
|
171 |
|
172 return retval; |
|
173 } |
|
174 |
|
175 void |
|
176 tree_statement_list::accept (tree_walker& tw) |
|
177 { |
|
178 tw.visit_statement_list (*this); |
|
179 } |
|
180 |
|
181 static int |
|
182 silent_functions (void) |
|
183 { |
|
184 Vsilent_functions = check_preference ("silent_functions"); |
|
185 |
|
186 return 0; |
|
187 } |
|
188 |
|
189 void |
|
190 symbols_of_pt_stmt (void) |
|
191 { |
3258
|
192 DEFVAR (silent_functions, 0.0, silent_functions, |
2982
|
193 "suppress printing results in called functions"); |
|
194 } |
|
195 |
|
196 /* |
|
197 ;;; Local Variables: *** |
|
198 ;;; mode: C++ *** |
|
199 ;;; End: *** |
|
200 */ |