comparison src/pt-stmt.cc @ 2982:20f5cec4f11c

[project @ 1997-05-16 03:29:26 by jwe]
author jwe
date Fri, 16 May 1997 03:30:14 +0000
parents
children aa9d0c0e0458
comparison
equal deleted inserted replaced
2981:38365813950d 2982:20f5cec4f11c
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"
42 #include "pt-pr-code.h"
43 #include "pt-stmt.h"
44 #include "pt-walk.h"
45 #include "utils.h"
46 #include "variables.h"
47
48 // Nonzero means we're breaking out of a loop or function body.
49 extern int breaking;
50
51 // Nonzero means we're jumping to the end of a loop.
52 extern int continuing;
53
54 // Nonzero means we're returning from a function.
55 extern int returning;
56
57 // If TRUE, turn off printing of results in functions (as if a
58 // semicolon has been appended to each statement).
59 static bool Vsilent_functions;
60
61 // A list of commands to be executed.
62
63 tree_statement::~tree_statement (void)
64 {
65 delete cmd;
66 delete expr;
67 }
68
69 int
70 tree_statement::line (void)
71 {
72 return cmd ? cmd->line () : (expr ? expr->line () : -1);
73 }
74
75 int
76 tree_statement::column (void)
77 {
78 return cmd ? cmd->column () : (expr ? expr->column () : -1);
79 }
80
81 void
82 tree_statement::maybe_echo_code (bool in_function_body)
83 {
84 if (in_function_body
85 && (Vecho_executing_commands & ECHO_FUNCTIONS))
86 {
87 tree_print_code tpc (octave_stdout, Vps4);
88
89 accept (tpc);
90 }
91 }
92
93 octave_value_list
94 tree_statement::eval (bool silent, int nargout, bool in_function_body)
95 {
96 octave_value_list retval;
97
98 bool pf = silent ? false : print_flag;
99
100 if (cmd || expr)
101 {
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
115 bool do_bind_ans = false;
116
117 if (expr->is_identifier ())
118 {
119 bool script_file_executed = false;
120
121 tree_identifier *id = static_cast<tree_identifier *> (expr);
122
123 id->do_lookup (script_file_executed, false);
124
125 do_bind_ans = id->is_function ();
126 }
127 else
128 do_bind_ans = (! (expr->is_indirect_ref ()
129 || expr->is_assignment_expression ()));
130
131 retval = expr->rvalue (nargout);
132
133 if (do_bind_ans && ! (error_state || retval.empty ()))
134 bind_ans (retval(0), pf);
135 }
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 {
161 bool silent_flag =
162 silent ? true : (function_body ? Vsilent_functions : false);
163
164 retval = elt->eval (silent_flag, nargout, function_body);
165
166 if (error_state)
167 break;
168
169 if (breaking || continuing)
170 break;
171
172 if (returning)
173 break;
174 }
175 else
176 error ("invalid statement found in statement list!");
177 }
178
179 return retval;
180 }
181
182 void
183 tree_statement_list::accept (tree_walker& tw)
184 {
185 tw.visit_statement_list (*this);
186 }
187
188 static int
189 silent_functions (void)
190 {
191 Vsilent_functions = check_preference ("silent_functions");
192
193 return 0;
194 }
195
196 void
197 symbols_of_pt_stmt (void)
198 {
199 DEFVAR (silent_functions, 0.0, 0, silent_functions,
200 "suppress printing results in called functions");
201 }
202
203 /*
204 ;;; Local Variables: ***
205 ;;; mode: C++ ***
206 ;;; End: ***
207 */