577
|
1 /* |
|
2 |
1827
|
3 Copyright (C) 1996 John W. Eaton |
577
|
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 |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
577
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_tree_misc_h) |
|
24 #define octave_tree_misc_h 1 |
|
25 |
1297
|
26 #if defined (__GNUG__) |
|
27 #pragma interface |
|
28 #endif |
|
29 |
581
|
30 class ostream; |
1740
|
31 |
2086
|
32 class octave_value_list; |
|
33 class octave_value; |
577
|
34 class tree_command; |
|
35 class tree_expression; |
|
36 class tree_simple_assignment_expression; |
1740
|
37 class tree_index_expression; |
577
|
38 class tree_identifier; |
|
39 class symbol_record; |
|
40 class symbol_table; |
|
41 |
|
42 class tree_statement; |
|
43 class tree_statement_list; |
|
44 class tree_argument_list; |
|
45 class tree_parameter_list; |
|
46 class tree_return_list; |
723
|
47 class tree_va_return_list; |
577
|
48 class tree_global; |
|
49 class tree_global_init_list; |
|
50 |
2124
|
51 class tree_walker; |
|
52 |
577
|
53 #include <SLList.h> |
|
54 |
1740
|
55 #include "pt-base.h" |
577
|
56 |
2124
|
57 // A statement is either a command to execute or an expression to |
|
58 // evaluate. |
577
|
59 |
|
60 class |
2124
|
61 tree_statement |
577
|
62 { |
|
63 friend class tree_statement_list; |
|
64 |
|
65 public: |
2124
|
66 |
577
|
67 tree_statement (void) |
2124
|
68 : cmd (0), expr (0), print_flag (true) { } |
577
|
69 |
|
70 tree_statement (tree_command *c) |
2124
|
71 : cmd (c), expr (0), print_flag (true) { } |
577
|
72 |
|
73 tree_statement (tree_expression *e) |
2124
|
74 : cmd (0), expr (e), print_flag (true) { } |
577
|
75 |
|
76 ~tree_statement (void); |
|
77 |
1827
|
78 void set_print_flag (bool print) |
577
|
79 { print_flag = print; } |
|
80 |
1827
|
81 bool is_command (void) |
2124
|
82 { return cmd != 0; } |
1510
|
83 |
1827
|
84 bool is_expression (void) |
2124
|
85 { return expr != 0; } |
1510
|
86 |
1740
|
87 int line (void); |
|
88 int column (void); |
1510
|
89 |
1827
|
90 void maybe_echo_code (bool); |
1588
|
91 |
2124
|
92 bool print_result (void) { return print_flag; } |
|
93 |
|
94 tree_command *command (void) { return cmd; } |
|
95 |
|
96 tree_expression *expression (void) { return expr; } |
|
97 |
|
98 void accept (tree_walker& tw); |
581
|
99 |
577
|
100 private: |
2124
|
101 |
|
102 // Only one of cmd or expr can be valid at once. |
|
103 |
|
104 // Command to execute. |
|
105 tree_command *cmd; |
|
106 |
|
107 // Expression to evaluate. |
|
108 tree_expression *expr; |
|
109 |
|
110 // Print result of eval for this command? |
|
111 bool print_flag; |
577
|
112 }; |
|
113 |
2124
|
114 // A list of statements to evaluate. |
|
115 |
577
|
116 class |
2124
|
117 tree_statement_list : public SLList<tree_statement *> |
577
|
118 { |
|
119 public: |
2124
|
120 |
1227
|
121 tree_statement_list (void) |
2124
|
122 : SLList<tree_statement *> (), function_body (false) { } |
1227
|
123 |
|
124 tree_statement_list (tree_statement *s) |
2124
|
125 : SLList<tree_statement *> (), function_body (false) { append (s); } |
577
|
126 |
|
127 ~tree_statement_list (void) |
|
128 { |
|
129 while (! empty ()) |
|
130 { |
|
131 tree_statement *t = remove_front (); |
|
132 delete t; |
|
133 } |
|
134 } |
|
135 |
1827
|
136 void mark_as_function_body (void) { function_body = true; } |
1588
|
137 |
2086
|
138 octave_value eval (bool print); |
581
|
139 |
2086
|
140 octave_value_list eval (bool print, int nargout); |
672
|
141 |
2124
|
142 void accept (tree_walker& tw); |
1588
|
143 |
|
144 private: |
2124
|
145 |
|
146 // Does this list of statements make up the body of a function? |
1827
|
147 bool function_body; |
577
|
148 }; |
|
149 |
|
150 // Argument lists. Used to hold the list of expressions that are the |
|
151 // arguments in a function call or index expression. |
|
152 |
|
153 class |
2124
|
154 tree_argument_list : public SLList<tree_expression *> |
577
|
155 { |
|
156 public: |
2124
|
157 |
1227
|
158 tree_argument_list (void) |
2124
|
159 : SLList<tree_expression *> () { } |
1227
|
160 |
|
161 tree_argument_list (tree_expression *t) |
2124
|
162 : SLList<tree_expression *> () { append (t); } |
577
|
163 |
|
164 ~tree_argument_list (void) |
|
165 { |
|
166 while (! empty ()) |
|
167 { |
|
168 tree_expression *t = remove_front (); |
|
169 delete t; |
|
170 } |
|
171 } |
|
172 |
2086
|
173 octave_value_list convert_to_const_vector (void); |
581
|
174 |
2124
|
175 void accept (tree_walker& tw); |
577
|
176 }; |
|
177 |
|
178 // Parameter lists. Used to hold the list of input and output |
|
179 // parameters in a function definition. Elements are identifiers |
|
180 // only. |
|
181 |
|
182 class |
2124
|
183 tree_parameter_list : public SLList<tree_identifier *> |
577
|
184 { |
|
185 public: |
2124
|
186 |
1227
|
187 tree_parameter_list (void) |
2124
|
188 : SLList<tree_identifier *> (), marked_for_varargs (0) { } |
632
|
189 |
1227
|
190 tree_parameter_list (tree_identifier *t) |
2124
|
191 : SLList<tree_identifier *> (), marked_for_varargs (0) { append (t); } |
577
|
192 |
1740
|
193 ~tree_parameter_list (void); |
577
|
194 |
|
195 void mark_as_formal_parameters (void); |
|
196 |
|
197 void mark_varargs (void) |
|
198 { marked_for_varargs = 1; } |
|
199 |
1827
|
200 bool takes_varargs (void) const |
|
201 { return marked_for_varargs != 0; } |
577
|
202 |
|
203 void mark_varargs_only (void) |
|
204 { marked_for_varargs = -1; } |
|
205 |
1827
|
206 bool varargs_only (void) |
577
|
207 { return (marked_for_varargs < 0); } |
|
208 |
2086
|
209 void initialize_undefined_elements (octave_value& val); |
1093
|
210 |
2086
|
211 void define_from_arg_vector (const octave_value_list& args); |
577
|
212 |
1827
|
213 bool is_defined (void); |
577
|
214 |
2086
|
215 octave_value_list convert_to_const_vector (tree_va_return_list *vr_list); |
577
|
216 |
2124
|
217 void accept (tree_walker& tw); |
581
|
218 |
577
|
219 private: |
2124
|
220 |
577
|
221 int marked_for_varargs; |
|
222 }; |
|
223 |
|
224 // Return lists. Used to hold the right hand sides of multiple |
|
225 // assignment expressions. |
|
226 |
|
227 class |
2124
|
228 tree_return_list : public SLList<tree_index_expression *> |
577
|
229 { |
|
230 public: |
2124
|
231 |
1227
|
232 tree_return_list (void) |
2124
|
233 : SLList<tree_index_expression *> () { } |
1227
|
234 |
577
|
235 tree_return_list (tree_index_expression *t) |
2124
|
236 : SLList<tree_index_expression *> () { append (t); } |
577
|
237 |
1740
|
238 ~tree_return_list (void); |
581
|
239 |
2124
|
240 void accept (tree_walker& tw); |
577
|
241 }; |
|
242 |
723
|
243 class |
2086
|
244 tree_va_return_list : public SLList<octave_value> |
723
|
245 { |
|
246 public: |
2124
|
247 |
2086
|
248 tree_va_return_list (void) : SLList<octave_value> () { } |
1269
|
249 |
|
250 ~tree_va_return_list (void) { } |
723
|
251 }; |
|
252 |
577
|
253 // List of expressions that make up a global statement. |
|
254 |
|
255 class |
2124
|
256 tree_global |
577
|
257 { |
|
258 public: |
|
259 |
2124
|
260 tree_global (void) |
|
261 : id (0), ass_expr (0) { } |
|
262 |
|
263 tree_global (tree_identifier *i) |
|
264 : id (i), ass_expr (0) { } |
577
|
265 |
|
266 tree_global (tree_simple_assignment_expression *ass) |
2124
|
267 : id (0), ass_expr (ass) { } |
577
|
268 |
1740
|
269 ~tree_global (void); |
577
|
270 |
|
271 void eval (void); |
|
272 |
2124
|
273 tree_identifier *ident (void) { return id; } |
|
274 |
|
275 tree_simple_assignment_expression *assign_expr (void) { return ass_expr; } |
|
276 |
|
277 void accept (tree_walker& tw); |
581
|
278 |
577
|
279 private: |
2124
|
280 |
|
281 // Only one of id or ass_expr can be valid at once. |
|
282 |
|
283 // An identifier to make global. |
|
284 tree_identifier *id; |
|
285 |
|
286 // An assignemnt expression. Valid only if the left hand side of |
|
287 // the assignment is a simple identifier. |
|
288 tree_simple_assignment_expression *ass_expr; |
577
|
289 }; |
|
290 |
|
291 class |
2124
|
292 tree_global_init_list : public SLList<tree_global *> |
577
|
293 { |
|
294 public: |
2124
|
295 |
1227
|
296 tree_global_init_list (void) |
2124
|
297 : SLList<tree_global *> () { } |
1227
|
298 |
|
299 tree_global_init_list (tree_global *t) |
2124
|
300 : SLList<tree_global *> () { append (t); } |
577
|
301 |
|
302 ~tree_global_init_list (void) |
|
303 { |
|
304 while (! empty ()) |
|
305 { |
|
306 tree_global *t = remove_front (); |
|
307 delete t; |
|
308 } |
|
309 } |
|
310 |
|
311 void eval (void); |
581
|
312 |
2124
|
313 void accept (tree_walker& tw); |
577
|
314 }; |
|
315 |
|
316 class |
2124
|
317 tree_if_clause |
577
|
318 { |
|
319 public: |
2124
|
320 |
|
321 tree_if_clause (void) : expr (0), list (0) { } |
577
|
322 |
1740
|
323 tree_if_clause (tree_statement_list *l) |
2124
|
324 : expr (0), list (l) { } |
577
|
325 |
|
326 tree_if_clause (tree_expression *e, tree_statement_list *l) |
2124
|
327 : expr (e), list (l) { } |
577
|
328 |
1740
|
329 ~tree_if_clause (void); |
577
|
330 |
1827
|
331 bool is_else_clause (void) |
|
332 { return ! expr; } |
1063
|
333 |
577
|
334 int eval (void); |
|
335 |
2124
|
336 tree_expression *condition (void) { return expr; } |
|
337 |
|
338 tree_statement_list *commands (void) { return list; } |
|
339 |
|
340 void accept (tree_walker& tw); |
581
|
341 |
577
|
342 private: |
2124
|
343 |
|
344 // The condition to test. |
577
|
345 tree_expression *expr; |
2124
|
346 |
|
347 // The list of statements to evaluate if expr is true. |
577
|
348 tree_statement_list *list; |
|
349 }; |
|
350 |
|
351 class |
2124
|
352 tree_if_command_list : public SLList<tree_if_clause *> |
577
|
353 { |
|
354 public: |
2124
|
355 |
1227
|
356 tree_if_command_list (void) |
2124
|
357 : SLList<tree_if_clause *> () { } |
1227
|
358 |
|
359 tree_if_command_list (tree_if_clause *t) |
2124
|
360 : SLList<tree_if_clause *> () { append (t); } |
577
|
361 |
|
362 ~tree_if_command_list (void) |
|
363 { |
|
364 while (! empty ()) |
|
365 { |
|
366 tree_if_clause *t = remove_front (); |
|
367 delete t; |
|
368 } |
|
369 } |
|
370 |
|
371 void eval (void); |
581
|
372 |
2124
|
373 void accept (tree_walker& tw); |
577
|
374 }; |
|
375 |
|
376 #endif |
|
377 |
|
378 /* |
|
379 ;;; Local Variables: *** |
|
380 ;;; mode: C++ *** |
|
381 ;;; End: *** |
|
382 */ |