577
|
1 // tree-misc.h -*- C++ -*- |
|
2 /* |
|
3 |
1009
|
4 Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton |
577
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_tree_misc_h) |
|
25 #define octave_tree_misc_h 1 |
|
26 |
581
|
27 class ostream; |
577
|
28 class Octave_object; |
|
29 class tree_constant; |
|
30 class tree_command; |
|
31 class tree_expression; |
|
32 class tree_simple_assignment_expression; |
|
33 class tree_identifier; |
|
34 class symbol_record; |
|
35 class symbol_table; |
|
36 |
|
37 class tree_statement; |
|
38 class tree_statement_list; |
|
39 class tree_argument_list; |
|
40 class tree_parameter_list; |
|
41 class tree_return_list; |
723
|
42 class tree_va_return_list; |
577
|
43 class tree_global; |
|
44 class tree_global_init_list; |
|
45 |
|
46 #include <SLList.h> |
|
47 |
|
48 #include "tree-base.h" |
|
49 #include "tree-expr.h" |
723
|
50 #include "tree-const.h" |
577
|
51 #include "tree-cmd.h" |
|
52 |
|
53 // A list of expressions and commands to be executed. |
|
54 |
|
55 class |
581
|
56 tree_statement : public tree_print_code |
577
|
57 { |
|
58 friend class tree_statement_list; |
|
59 |
|
60 public: |
|
61 tree_statement (void) |
|
62 { |
|
63 command = 0; |
|
64 expression = 0; |
|
65 print_flag = 1; |
|
66 } |
|
67 |
|
68 tree_statement (tree_command *c) |
|
69 { |
|
70 command = c; |
|
71 expression = 0; |
|
72 print_flag = 1; |
|
73 } |
|
74 |
|
75 tree_statement (tree_expression *e) |
|
76 { |
|
77 command = 0; |
|
78 expression = e; |
|
79 print_flag = 1; |
|
80 } |
|
81 |
|
82 ~tree_statement (void); |
|
83 |
|
84 void set_print_flag (int print) |
|
85 { print_flag = print; } |
|
86 |
581
|
87 void print_code (ostream& os); |
|
88 |
577
|
89 private: |
|
90 tree_command *command; // Command to execute. |
|
91 tree_expression *expression; // Command to execute. |
|
92 int print_flag; // Print result of eval for this command? |
|
93 }; |
|
94 |
|
95 class |
581
|
96 tree_statement_list : public SLList<tree_statement *>, public tree_print_code |
577
|
97 { |
|
98 public: |
1227
|
99 tree_statement_list (void) |
|
100 : SLList<tree_statement *> (), tree_print_code () { } |
|
101 |
|
102 tree_statement_list (tree_statement *s) |
|
103 : SLList<tree_statement *> (), tree_print_code () |
|
104 { append (s); } |
577
|
105 |
|
106 ~tree_statement_list (void) |
|
107 { |
|
108 while (! empty ()) |
|
109 { |
|
110 tree_statement *t = remove_front (); |
|
111 delete t; |
|
112 } |
|
113 } |
|
114 |
|
115 tree_constant eval (int print); |
581
|
116 |
672
|
117 Octave_object eval (int print, int nargout); |
|
118 |
581
|
119 void print_code (ostream& os); |
577
|
120 }; |
|
121 |
|
122 // Argument lists. Used to hold the list of expressions that are the |
|
123 // arguments in a function call or index expression. |
|
124 |
|
125 class |
581
|
126 tree_argument_list : public SLList<tree_expression *>, public tree_print_code |
577
|
127 { |
|
128 public: |
1227
|
129 tree_argument_list (void) |
|
130 : SLList<tree_expression *> (), tree_print_code () { } |
|
131 |
|
132 tree_argument_list (tree_expression *t) |
|
133 : SLList<tree_expression *> (), tree_print_code () |
|
134 { append (t); } |
577
|
135 |
|
136 ~tree_argument_list (void) |
|
137 { |
|
138 while (! empty ()) |
|
139 { |
|
140 tree_expression *t = remove_front (); |
|
141 delete t; |
|
142 } |
|
143 } |
|
144 |
|
145 Octave_object convert_to_const_vector (void); |
581
|
146 |
|
147 void print_code (ostream& os); |
577
|
148 }; |
|
149 |
|
150 // Parameter lists. Used to hold the list of input and output |
|
151 // parameters in a function definition. Elements are identifiers |
|
152 // only. |
|
153 |
|
154 class |
581
|
155 tree_parameter_list : public SLList<tree_identifier *>, public tree_print_code |
577
|
156 { |
|
157 public: |
1227
|
158 tree_parameter_list (void) |
|
159 : SLList<tree_identifier *> (), tree_print_code () |
|
160 { marked_for_varargs = 0; } |
632
|
161 |
1227
|
162 tree_parameter_list (tree_identifier *t) |
|
163 : SLList<tree_identifier *> (), tree_print_code () |
|
164 { |
|
165 marked_for_varargs = 0; |
|
166 append (t); |
|
167 } |
577
|
168 |
|
169 ~tree_parameter_list (void) |
|
170 { |
|
171 while (! empty ()) |
|
172 { |
|
173 tree_identifier *t = remove_front (); |
|
174 delete t; |
|
175 } |
|
176 } |
|
177 |
|
178 // char *name (void) const; |
|
179 |
|
180 void mark_as_formal_parameters (void); |
|
181 |
|
182 void mark_varargs (void) |
|
183 { marked_for_varargs = 1; } |
|
184 |
|
185 int takes_varargs (void) const |
|
186 { return marked_for_varargs; } |
|
187 |
|
188 void mark_varargs_only (void) |
|
189 { marked_for_varargs = -1; } |
|
190 |
|
191 int varargs_only (void) |
|
192 { return (marked_for_varargs < 0); } |
|
193 |
1127
|
194 void initialize_undefined_elements (tree_constant& val); |
1093
|
195 |
577
|
196 void define_from_arg_vector (const Octave_object& args); |
|
197 |
|
198 int is_defined (void); |
|
199 |
723
|
200 Octave_object convert_to_const_vector (tree_va_return_list *vr_list); |
577
|
201 |
581
|
202 void print_code (ostream& os); |
|
203 |
577
|
204 private: |
|
205 int marked_for_varargs; |
|
206 }; |
|
207 |
|
208 // Return lists. Used to hold the right hand sides of multiple |
|
209 // assignment expressions. |
|
210 |
|
211 class |
581
|
212 tree_return_list : public SLList<tree_index_expression *>, |
|
213 public tree_print_code |
577
|
214 { |
|
215 public: |
1227
|
216 tree_return_list (void) |
|
217 : SLList<tree_index_expression *> (), tree_print_code () { } |
|
218 |
577
|
219 tree_return_list (tree_index_expression *t) |
1227
|
220 : SLList<tree_index_expression *> (), tree_print_code () |
577
|
221 { append (t); } |
|
222 |
|
223 ~tree_return_list (void) |
|
224 { |
|
225 while (! empty ()) |
|
226 { |
|
227 tree_index_expression *t = remove_front (); |
|
228 delete t; |
|
229 } |
|
230 } |
581
|
231 |
|
232 void print_code (ostream& os); |
577
|
233 }; |
|
234 |
723
|
235 class |
|
236 tree_va_return_list : public SLList<tree_constant> |
|
237 { |
|
238 public: |
|
239 tree_va_return_list (void) : SLList<tree_constant> () { } |
1269
|
240 |
|
241 ~tree_va_return_list (void) { } |
723
|
242 }; |
|
243 |
577
|
244 // List of expressions that make up a global statement. |
|
245 |
|
246 class |
581
|
247 tree_global : public tree_print_code |
577
|
248 { |
|
249 public: |
|
250 tree_global (void) |
|
251 { |
|
252 ident = 0; |
|
253 assign_expr = 0; |
|
254 } |
|
255 |
|
256 tree_global (tree_identifier *id) |
|
257 { |
|
258 ident = id; |
|
259 assign_expr = 0; |
|
260 } |
|
261 |
|
262 tree_global (tree_simple_assignment_expression *ass) |
|
263 { |
|
264 ident = 0; |
|
265 assign_expr = ass; |
|
266 } |
|
267 |
|
268 ~tree_global (void) |
|
269 { |
|
270 delete ident; |
|
271 delete assign_expr; |
|
272 } |
|
273 |
|
274 void eval (void); |
|
275 |
581
|
276 void print_code (ostream& os); |
|
277 |
577
|
278 private: |
|
279 tree_identifier *ident; |
|
280 tree_simple_assignment_expression *assign_expr; |
|
281 }; |
|
282 |
|
283 class |
581
|
284 tree_global_init_list : public SLList<tree_global *>, public tree_print_code |
577
|
285 { |
|
286 public: |
1227
|
287 tree_global_init_list (void) |
|
288 : SLList<tree_global *> (), tree_print_code () { } |
|
289 |
|
290 tree_global_init_list (tree_global *t) |
|
291 : SLList<tree_global *> (), tree_print_code () |
|
292 { append (t); } |
577
|
293 |
|
294 ~tree_global_init_list (void) |
|
295 { |
|
296 while (! empty ()) |
|
297 { |
|
298 tree_global *t = remove_front (); |
|
299 delete t; |
|
300 } |
|
301 } |
|
302 |
|
303 void eval (void); |
581
|
304 |
|
305 void print_code (ostream& os); |
577
|
306 }; |
|
307 |
|
308 class |
581
|
309 tree_if_clause : public tree_print_code |
577
|
310 { |
|
311 public: |
|
312 tree_if_clause (void) |
|
313 { |
|
314 expr = 0; |
|
315 list = 0; |
|
316 } |
|
317 |
|
318 tree_if_clause (tree_statement_list *l) |
|
319 { |
|
320 expr = 0; |
|
321 list = l; |
|
322 } |
|
323 |
|
324 tree_if_clause (tree_expression *e, tree_statement_list *l) |
|
325 { |
|
326 expr = e; |
|
327 list = l; |
|
328 } |
|
329 |
|
330 ~tree_if_clause (void) |
|
331 { |
|
332 delete expr; |
|
333 delete list; |
|
334 } |
|
335 |
1063
|
336 int is_else_clause (void); |
|
337 |
577
|
338 int eval (void); |
|
339 |
581
|
340 void print_code (ostream& os); |
|
341 |
577
|
342 private: |
|
343 tree_expression *expr; |
|
344 tree_statement_list *list; |
|
345 }; |
|
346 |
|
347 class |
581
|
348 tree_if_command_list : public SLList<tree_if_clause *>, public tree_print_code |
577
|
349 { |
|
350 public: |
1227
|
351 tree_if_command_list (void) |
|
352 : SLList<tree_if_clause *> (), tree_print_code () { } |
|
353 |
|
354 tree_if_command_list (tree_if_clause *t) |
|
355 : SLList<tree_if_clause *> (), tree_print_code () |
|
356 { append (t); } |
577
|
357 |
|
358 ~tree_if_command_list (void) |
|
359 { |
|
360 while (! empty ()) |
|
361 { |
|
362 tree_if_clause *t = remove_front (); |
|
363 delete t; |
|
364 } |
|
365 } |
|
366 |
|
367 void eval (void); |
581
|
368 |
|
369 void print_code (ostream& os); |
577
|
370 }; |
|
371 |
|
372 #endif |
|
373 |
|
374 /* |
|
375 ;;; Local Variables: *** |
|
376 ;;; mode: C++ *** |
|
377 ;;; page-delimiter: "^/\\*" *** |
|
378 ;;; End: *** |
|
379 */ |