577
|
1 // tree-misc.h -*- C++ -*- |
|
2 /* |
|
3 |
|
4 Copyright (C) 1992, 1993, 1994 John W. Eaton |
|
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: |
|
99 tree_statement_list (void) : SLList<tree_statement *> () { } |
|
100 tree_statement_list (tree_statement *s) : SLList<tree_statement *> () |
|
101 { append (s); } |
|
102 |
|
103 ~tree_statement_list (void) |
|
104 { |
|
105 while (! empty ()) |
|
106 { |
|
107 tree_statement *t = remove_front (); |
|
108 delete t; |
|
109 } |
|
110 } |
|
111 |
|
112 tree_constant eval (int print); |
581
|
113 |
672
|
114 Octave_object eval (int print, int nargout); |
|
115 |
581
|
116 void print_code (ostream& os); |
577
|
117 }; |
|
118 |
|
119 // Argument lists. Used to hold the list of expressions that are the |
|
120 // arguments in a function call or index expression. |
|
121 |
|
122 class |
581
|
123 tree_argument_list : public SLList<tree_expression *>, public tree_print_code |
577
|
124 { |
|
125 public: |
|
126 tree_argument_list (void) : SLList<tree_expression *> () { } |
|
127 tree_argument_list (tree_expression *t) : SLList<tree_expression *> () |
|
128 { append (t); } |
|
129 |
|
130 ~tree_argument_list (void) |
|
131 { |
|
132 while (! empty ()) |
|
133 { |
|
134 tree_expression *t = remove_front (); |
|
135 delete t; |
|
136 } |
|
137 } |
|
138 |
|
139 Octave_object convert_to_const_vector (void); |
581
|
140 |
|
141 void print_code (ostream& os); |
577
|
142 }; |
|
143 |
|
144 // Parameter lists. Used to hold the list of input and output |
|
145 // parameters in a function definition. Elements are identifiers |
|
146 // only. |
|
147 |
|
148 class |
581
|
149 tree_parameter_list : public SLList<tree_identifier *>, public tree_print_code |
577
|
150 { |
|
151 public: |
632
|
152 tree_parameter_list (void) : SLList<tree_identifier *> () |
|
153 { marked_for_varargs = 0; } |
|
154 |
577
|
155 tree_parameter_list (tree_identifier *t) : SLList<tree_identifier *> () |
632
|
156 { |
|
157 marked_for_varargs = 0; |
|
158 append (t); |
|
159 } |
577
|
160 |
|
161 ~tree_parameter_list (void) |
|
162 { |
|
163 while (! empty ()) |
|
164 { |
|
165 tree_identifier *t = remove_front (); |
|
166 delete t; |
|
167 } |
|
168 } |
|
169 |
|
170 // char *name (void) const; |
|
171 |
|
172 void mark_as_formal_parameters (void); |
|
173 |
|
174 void mark_varargs (void) |
|
175 { marked_for_varargs = 1; } |
|
176 |
|
177 int takes_varargs (void) const |
|
178 { return marked_for_varargs; } |
|
179 |
|
180 void mark_varargs_only (void) |
|
181 { marked_for_varargs = -1; } |
|
182 |
|
183 int varargs_only (void) |
|
184 { return (marked_for_varargs < 0); } |
|
185 |
|
186 void define_from_arg_vector (const Octave_object& args); |
|
187 |
|
188 int is_defined (void); |
|
189 |
723
|
190 Octave_object convert_to_const_vector (tree_va_return_list *vr_list); |
577
|
191 |
581
|
192 void print_code (ostream& os); |
|
193 |
577
|
194 private: |
|
195 int marked_for_varargs; |
|
196 }; |
|
197 |
|
198 // Return lists. Used to hold the right hand sides of multiple |
|
199 // assignment expressions. |
|
200 |
|
201 class |
581
|
202 tree_return_list : public SLList<tree_index_expression *>, |
|
203 public tree_print_code |
577
|
204 { |
|
205 public: |
|
206 tree_return_list (void) : SLList<tree_index_expression *> () { } |
|
207 tree_return_list (tree_index_expression *t) |
|
208 : SLList<tree_index_expression *> () |
|
209 { append (t); } |
|
210 |
|
211 ~tree_return_list (void) |
|
212 { |
|
213 while (! empty ()) |
|
214 { |
|
215 tree_index_expression *t = remove_front (); |
|
216 delete t; |
|
217 } |
|
218 } |
581
|
219 |
|
220 void print_code (ostream& os); |
577
|
221 }; |
|
222 |
723
|
223 class |
|
224 tree_va_return_list : public SLList<tree_constant> |
|
225 { |
|
226 public: |
|
227 tree_va_return_list (void) : SLList<tree_constant> () { } |
|
228 }; |
|
229 |
577
|
230 // List of expressions that make up a global statement. |
|
231 |
|
232 class |
581
|
233 tree_global : public tree_print_code |
577
|
234 { |
|
235 public: |
|
236 tree_global (void) |
|
237 { |
|
238 ident = 0; |
|
239 assign_expr = 0; |
|
240 } |
|
241 |
|
242 tree_global (tree_identifier *id) |
|
243 { |
|
244 ident = id; |
|
245 assign_expr = 0; |
|
246 } |
|
247 |
|
248 tree_global (tree_simple_assignment_expression *ass) |
|
249 { |
|
250 ident = 0; |
|
251 assign_expr = ass; |
|
252 } |
|
253 |
|
254 ~tree_global (void) |
|
255 { |
|
256 delete ident; |
|
257 delete assign_expr; |
|
258 } |
|
259 |
|
260 void eval (void); |
|
261 |
581
|
262 void print_code (ostream& os); |
|
263 |
577
|
264 private: |
|
265 tree_identifier *ident; |
|
266 tree_simple_assignment_expression *assign_expr; |
|
267 }; |
|
268 |
|
269 class |
581
|
270 tree_global_init_list : public SLList<tree_global *>, public tree_print_code |
577
|
271 { |
|
272 public: |
|
273 tree_global_init_list (void) : SLList<tree_global *> () { } |
|
274 tree_global_init_list (tree_global *t) : SLList<tree_global *> () |
|
275 { append (t); } |
|
276 |
|
277 ~tree_global_init_list (void) |
|
278 { |
|
279 while (! empty ()) |
|
280 { |
|
281 tree_global *t = remove_front (); |
|
282 delete t; |
|
283 } |
|
284 } |
|
285 |
|
286 void eval (void); |
581
|
287 |
|
288 void print_code (ostream& os); |
577
|
289 }; |
|
290 |
|
291 class |
581
|
292 tree_if_clause : public tree_print_code |
577
|
293 { |
|
294 public: |
|
295 tree_if_clause (void) |
|
296 { |
|
297 expr = 0; |
|
298 list = 0; |
|
299 } |
|
300 |
|
301 tree_if_clause (tree_statement_list *l) |
|
302 { |
|
303 expr = 0; |
|
304 list = l; |
|
305 } |
|
306 |
|
307 tree_if_clause (tree_expression *e, tree_statement_list *l) |
|
308 { |
|
309 expr = e; |
|
310 list = l; |
|
311 } |
|
312 |
|
313 ~tree_if_clause (void) |
|
314 { |
|
315 delete expr; |
|
316 delete list; |
|
317 } |
|
318 |
|
319 int eval (void); |
|
320 |
581
|
321 void print_code (ostream& os); |
|
322 |
577
|
323 private: |
|
324 tree_expression *expr; |
|
325 tree_statement_list *list; |
|
326 }; |
|
327 |
|
328 class |
581
|
329 tree_if_command_list : public SLList<tree_if_clause *>, public tree_print_code |
577
|
330 { |
|
331 public: |
|
332 tree_if_command_list (void) : SLList<tree_if_clause *> () { } |
|
333 tree_if_command_list (tree_if_clause *t) : SLList<tree_if_clause *> () |
|
334 { append (t); } |
|
335 |
|
336 ~tree_if_command_list (void) |
|
337 { |
|
338 while (! empty ()) |
|
339 { |
|
340 tree_if_clause *t = remove_front (); |
|
341 delete t; |
|
342 } |
|
343 } |
|
344 |
|
345 void eval (void); |
581
|
346 |
|
347 void print_code (ostream& os); |
577
|
348 }; |
|
349 |
|
350 #endif |
|
351 |
|
352 /* |
|
353 ;;; Local Variables: *** |
|
354 ;;; mode: C++ *** |
|
355 ;;; page-delimiter: "^/\\*" *** |
|
356 ;;; End: *** |
|
357 */ |