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