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 |
|
27 #if defined (__GNUG__) |
|
28 #pragma interface |
|
29 #endif |
|
30 |
581
|
31 class ostream; |
577
|
32 class Octave_object; |
|
33 class tree_constant; |
|
34 class tree_command; |
|
35 class tree_expression; |
|
36 class tree_simple_assignment_expression; |
|
37 class tree_identifier; |
|
38 class symbol_record; |
|
39 class symbol_table; |
|
40 |
|
41 class tree_statement; |
|
42 class tree_statement_list; |
|
43 class tree_argument_list; |
|
44 class tree_parameter_list; |
|
45 class tree_return_list; |
|
46 class tree_global; |
|
47 class tree_global_init_list; |
|
48 |
|
49 #include <SLList.h> |
|
50 |
|
51 #include "tree-base.h" |
|
52 #include "tree-expr.h" |
|
53 #include "tree-cmd.h" |
|
54 |
|
55 // A list of expressions and commands to be executed. |
|
56 |
|
57 class |
581
|
58 tree_statement : public tree_print_code |
577
|
59 { |
|
60 friend class tree_statement_list; |
|
61 |
|
62 public: |
|
63 tree_statement (void) |
|
64 { |
|
65 command = 0; |
|
66 expression = 0; |
|
67 print_flag = 1; |
|
68 } |
|
69 |
|
70 tree_statement (tree_command *c) |
|
71 { |
|
72 command = c; |
|
73 expression = 0; |
|
74 print_flag = 1; |
|
75 } |
|
76 |
|
77 tree_statement (tree_expression *e) |
|
78 { |
|
79 command = 0; |
|
80 expression = e; |
|
81 print_flag = 1; |
|
82 } |
|
83 |
|
84 ~tree_statement (void); |
|
85 |
|
86 void set_print_flag (int print) |
|
87 { print_flag = print; } |
|
88 |
581
|
89 void print_code (ostream& os); |
|
90 |
577
|
91 private: |
|
92 tree_command *command; // Command to execute. |
|
93 tree_expression *expression; // Command to execute. |
|
94 int print_flag; // Print result of eval for this command? |
|
95 }; |
|
96 |
|
97 class |
581
|
98 tree_statement_list : public SLList<tree_statement *>, public tree_print_code |
577
|
99 { |
|
100 public: |
|
101 tree_statement_list (void) : SLList<tree_statement *> () { } |
|
102 tree_statement_list (tree_statement *s) : SLList<tree_statement *> () |
|
103 { append (s); } |
|
104 |
|
105 ~tree_statement_list (void) |
|
106 { |
|
107 while (! empty ()) |
|
108 { |
|
109 tree_statement *t = remove_front (); |
|
110 delete t; |
|
111 } |
|
112 } |
|
113 |
|
114 tree_constant eval (int print); |
581
|
115 |
|
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: |
|
152 tree_parameter_list (void) : SLList<tree_identifier *> () { } |
|
153 tree_parameter_list (tree_identifier *t) : SLList<tree_identifier *> () |
|
154 { append (t); } |
|
155 |
|
156 ~tree_parameter_list (void) |
|
157 { |
|
158 while (! empty ()) |
|
159 { |
|
160 tree_identifier *t = remove_front (); |
|
161 delete t; |
|
162 } |
|
163 } |
|
164 |
|
165 // char *name (void) const; |
|
166 |
|
167 void mark_as_formal_parameters (void); |
|
168 |
|
169 void mark_varargs (void) |
|
170 { marked_for_varargs = 1; } |
|
171 |
|
172 int takes_varargs (void) const |
|
173 { return marked_for_varargs; } |
|
174 |
|
175 void mark_varargs_only (void) |
|
176 { marked_for_varargs = -1; } |
|
177 |
|
178 int varargs_only (void) |
|
179 { return (marked_for_varargs < 0); } |
|
180 |
|
181 void define_from_arg_vector (const Octave_object& args); |
|
182 |
|
183 int is_defined (void); |
|
184 |
|
185 Octave_object convert_to_const_vector (void); |
|
186 |
581
|
187 void print_code (ostream& os); |
|
188 |
577
|
189 private: |
|
190 int marked_for_varargs; |
|
191 }; |
|
192 |
|
193 // Return lists. Used to hold the right hand sides of multiple |
|
194 // assignment expressions. |
|
195 |
|
196 class |
581
|
197 tree_return_list : public SLList<tree_index_expression *>, |
|
198 public tree_print_code |
577
|
199 { |
|
200 public: |
|
201 tree_return_list (void) : SLList<tree_index_expression *> () { } |
|
202 tree_return_list (tree_index_expression *t) |
|
203 : SLList<tree_index_expression *> () |
|
204 { append (t); } |
|
205 |
|
206 ~tree_return_list (void) |
|
207 { |
|
208 while (! empty ()) |
|
209 { |
|
210 tree_index_expression *t = remove_front (); |
|
211 delete t; |
|
212 } |
|
213 } |
581
|
214 |
|
215 void print_code (ostream& os); |
577
|
216 }; |
|
217 |
|
218 // List of expressions that make up a global statement. |
|
219 |
|
220 class |
581
|
221 tree_global : public tree_print_code |
577
|
222 { |
|
223 public: |
|
224 tree_global (void) |
|
225 { |
|
226 ident = 0; |
|
227 assign_expr = 0; |
|
228 } |
|
229 |
|
230 tree_global (tree_identifier *id) |
|
231 { |
|
232 ident = id; |
|
233 assign_expr = 0; |
|
234 } |
|
235 |
|
236 tree_global (tree_simple_assignment_expression *ass) |
|
237 { |
|
238 ident = 0; |
|
239 assign_expr = ass; |
|
240 } |
|
241 |
|
242 ~tree_global (void) |
|
243 { |
|
244 delete ident; |
|
245 delete assign_expr; |
|
246 } |
|
247 |
|
248 void eval (void); |
|
249 |
581
|
250 void print_code (ostream& os); |
|
251 |
577
|
252 private: |
|
253 tree_identifier *ident; |
|
254 tree_simple_assignment_expression *assign_expr; |
|
255 }; |
|
256 |
|
257 class |
581
|
258 tree_global_init_list : public SLList<tree_global *>, public tree_print_code |
577
|
259 { |
|
260 public: |
|
261 tree_global_init_list (void) : SLList<tree_global *> () { } |
|
262 tree_global_init_list (tree_global *t) : SLList<tree_global *> () |
|
263 { append (t); } |
|
264 |
|
265 ~tree_global_init_list (void) |
|
266 { |
|
267 while (! empty ()) |
|
268 { |
|
269 tree_global *t = remove_front (); |
|
270 delete t; |
|
271 } |
|
272 } |
|
273 |
|
274 void eval (void); |
581
|
275 |
|
276 void print_code (ostream& os); |
577
|
277 }; |
|
278 |
|
279 class |
581
|
280 tree_if_clause : public tree_print_code |
577
|
281 { |
|
282 public: |
|
283 tree_if_clause (void) |
|
284 { |
|
285 expr = 0; |
|
286 list = 0; |
|
287 } |
|
288 |
|
289 tree_if_clause (tree_statement_list *l) |
|
290 { |
|
291 expr = 0; |
|
292 list = l; |
|
293 } |
|
294 |
|
295 tree_if_clause (tree_expression *e, tree_statement_list *l) |
|
296 { |
|
297 expr = e; |
|
298 list = l; |
|
299 } |
|
300 |
|
301 ~tree_if_clause (void) |
|
302 { |
|
303 delete expr; |
|
304 delete list; |
|
305 } |
|
306 |
|
307 int eval (void); |
|
308 |
581
|
309 void print_code (ostream& os); |
|
310 |
577
|
311 private: |
|
312 tree_expression *expr; |
|
313 tree_statement_list *list; |
|
314 }; |
|
315 |
|
316 class |
581
|
317 tree_if_command_list : public SLList<tree_if_clause *>, public tree_print_code |
577
|
318 { |
|
319 public: |
|
320 tree_if_command_list (void) : SLList<tree_if_clause *> () { } |
|
321 tree_if_command_list (tree_if_clause *t) : SLList<tree_if_clause *> () |
|
322 { append (t); } |
|
323 |
|
324 ~tree_if_command_list (void) |
|
325 { |
|
326 while (! empty ()) |
|
327 { |
|
328 tree_if_clause *t = remove_front (); |
|
329 delete t; |
|
330 } |
|
331 } |
|
332 |
|
333 void eval (void); |
581
|
334 |
|
335 void print_code (ostream& os); |
577
|
336 }; |
|
337 |
|
338 #endif |
|
339 |
|
340 /* |
|
341 ;;; Local Variables: *** |
|
342 ;;; mode: C++ *** |
|
343 ;;; page-delimiter: "^/\\*" *** |
|
344 ;;; End: *** |
|
345 */ |