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> () { } |
|
240 }; |
|
241 |
577
|
242 // List of expressions that make up a global statement. |
|
243 |
|
244 class |
581
|
245 tree_global : public tree_print_code |
577
|
246 { |
|
247 public: |
|
248 tree_global (void) |
|
249 { |
|
250 ident = 0; |
|
251 assign_expr = 0; |
|
252 } |
|
253 |
|
254 tree_global (tree_identifier *id) |
|
255 { |
|
256 ident = id; |
|
257 assign_expr = 0; |
|
258 } |
|
259 |
|
260 tree_global (tree_simple_assignment_expression *ass) |
|
261 { |
|
262 ident = 0; |
|
263 assign_expr = ass; |
|
264 } |
|
265 |
|
266 ~tree_global (void) |
|
267 { |
|
268 delete ident; |
|
269 delete assign_expr; |
|
270 } |
|
271 |
|
272 void eval (void); |
|
273 |
581
|
274 void print_code (ostream& os); |
|
275 |
577
|
276 private: |
|
277 tree_identifier *ident; |
|
278 tree_simple_assignment_expression *assign_expr; |
|
279 }; |
|
280 |
|
281 class |
581
|
282 tree_global_init_list : public SLList<tree_global *>, public tree_print_code |
577
|
283 { |
|
284 public: |
1227
|
285 tree_global_init_list (void) |
|
286 : SLList<tree_global *> (), tree_print_code () { } |
|
287 |
|
288 tree_global_init_list (tree_global *t) |
|
289 : SLList<tree_global *> (), tree_print_code () |
|
290 { append (t); } |
577
|
291 |
|
292 ~tree_global_init_list (void) |
|
293 { |
|
294 while (! empty ()) |
|
295 { |
|
296 tree_global *t = remove_front (); |
|
297 delete t; |
|
298 } |
|
299 } |
|
300 |
|
301 void eval (void); |
581
|
302 |
|
303 void print_code (ostream& os); |
577
|
304 }; |
|
305 |
|
306 class |
581
|
307 tree_if_clause : public tree_print_code |
577
|
308 { |
|
309 public: |
|
310 tree_if_clause (void) |
|
311 { |
|
312 expr = 0; |
|
313 list = 0; |
|
314 } |
|
315 |
|
316 tree_if_clause (tree_statement_list *l) |
|
317 { |
|
318 expr = 0; |
|
319 list = l; |
|
320 } |
|
321 |
|
322 tree_if_clause (tree_expression *e, tree_statement_list *l) |
|
323 { |
|
324 expr = e; |
|
325 list = l; |
|
326 } |
|
327 |
|
328 ~tree_if_clause (void) |
|
329 { |
|
330 delete expr; |
|
331 delete list; |
|
332 } |
|
333 |
1063
|
334 int is_else_clause (void); |
|
335 |
577
|
336 int eval (void); |
|
337 |
581
|
338 void print_code (ostream& os); |
|
339 |
577
|
340 private: |
|
341 tree_expression *expr; |
|
342 tree_statement_list *list; |
|
343 }; |
|
344 |
|
345 class |
581
|
346 tree_if_command_list : public SLList<tree_if_clause *>, public tree_print_code |
577
|
347 { |
|
348 public: |
1227
|
349 tree_if_command_list (void) |
|
350 : SLList<tree_if_clause *> (), tree_print_code () { } |
|
351 |
|
352 tree_if_command_list (tree_if_clause *t) |
|
353 : SLList<tree_if_clause *> (), tree_print_code () |
|
354 { append (t); } |
577
|
355 |
|
356 ~tree_if_command_list (void) |
|
357 { |
|
358 while (! empty ()) |
|
359 { |
|
360 tree_if_clause *t = remove_front (); |
|
361 delete t; |
|
362 } |
|
363 } |
|
364 |
|
365 void eval (void); |
581
|
366 |
|
367 void print_code (ostream& os); |
577
|
368 }; |
|
369 |
|
370 #endif |
|
371 |
|
372 /* |
|
373 ;;; Local Variables: *** |
|
374 ;;; mode: C++ *** |
|
375 ;;; page-delimiter: "^/\\*" *** |
|
376 ;;; End: *** |
|
377 */ |