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