577
|
1 /* |
|
2 |
1827
|
3 Copyright (C) 1996 John W. Eaton |
577
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
577
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_tree_misc_h) |
|
24 #define octave_tree_misc_h 1 |
|
25 |
1297
|
26 #if defined (__GNUG__) |
|
27 #pragma interface |
|
28 #endif |
|
29 |
581
|
30 class ostream; |
1740
|
31 |
2086
|
32 class octave_value_list; |
|
33 class octave_value; |
577
|
34 class tree_command; |
|
35 class tree_expression; |
|
36 class tree_simple_assignment_expression; |
1740
|
37 class tree_index_expression; |
577
|
38 class tree_identifier; |
|
39 class symbol_record; |
|
40 class symbol_table; |
|
41 |
|
42 class tree_statement; |
|
43 class tree_statement_list; |
|
44 class tree_argument_list; |
|
45 class tree_parameter_list; |
|
46 class tree_return_list; |
723
|
47 class tree_va_return_list; |
577
|
48 class tree_global; |
|
49 class tree_global_init_list; |
|
50 |
|
51 #include <SLList.h> |
|
52 |
1740
|
53 #include "pt-base.h" |
577
|
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) |
1827
|
64 : tree_print_code (), command (0), expression (0), print_flag (true) { } |
577
|
65 |
|
66 tree_statement (tree_command *c) |
1827
|
67 : tree_print_code (), command (c), expression (0), print_flag (true) { } |
577
|
68 |
|
69 tree_statement (tree_expression *e) |
1827
|
70 : tree_print_code (), command (0), expression (e), print_flag (true) { } |
577
|
71 |
|
72 ~tree_statement (void); |
|
73 |
1827
|
74 void set_print_flag (bool print) |
577
|
75 { print_flag = print; } |
|
76 |
1827
|
77 bool is_command (void) |
1510
|
78 { return command != 0; } |
|
79 |
1827
|
80 bool is_expression (void) |
1510
|
81 { return expression != 0; } |
|
82 |
1740
|
83 int line (void); |
|
84 int column (void); |
1510
|
85 |
1827
|
86 void maybe_echo_code (bool); |
1588
|
87 |
581
|
88 void print_code (ostream& os); |
|
89 |
577
|
90 private: |
|
91 tree_command *command; // Command to execute. |
|
92 tree_expression *expression; // Command to execute. |
1827
|
93 bool print_flag; // Print result of eval for this command? |
577
|
94 }; |
|
95 |
|
96 class |
581
|
97 tree_statement_list : public SLList<tree_statement *>, public tree_print_code |
577
|
98 { |
|
99 public: |
1227
|
100 tree_statement_list (void) |
1827
|
101 : SLList<tree_statement *> (), tree_print_code (), function_body (false) |
|
102 { } |
1227
|
103 |
|
104 tree_statement_list (tree_statement *s) |
1827
|
105 : SLList<tree_statement *> (), tree_print_code (), function_body (false) |
1740
|
106 { append (s); } |
577
|
107 |
|
108 ~tree_statement_list (void) |
|
109 { |
|
110 while (! empty ()) |
|
111 { |
|
112 tree_statement *t = remove_front (); |
|
113 delete t; |
|
114 } |
|
115 } |
|
116 |
1827
|
117 void mark_as_function_body (void) { function_body = true; } |
1588
|
118 |
2086
|
119 octave_value eval (bool print); |
581
|
120 |
2086
|
121 octave_value_list eval (bool print, int nargout); |
672
|
122 |
581
|
123 void print_code (ostream& os); |
1588
|
124 |
|
125 private: |
1827
|
126 bool function_body; |
577
|
127 }; |
|
128 |
|
129 // Argument lists. Used to hold the list of expressions that are the |
|
130 // arguments in a function call or index expression. |
|
131 |
|
132 class |
581
|
133 tree_argument_list : public SLList<tree_expression *>, public tree_print_code |
577
|
134 { |
|
135 public: |
1227
|
136 tree_argument_list (void) |
|
137 : SLList<tree_expression *> (), tree_print_code () { } |
|
138 |
|
139 tree_argument_list (tree_expression *t) |
|
140 : SLList<tree_expression *> (), tree_print_code () |
|
141 { append (t); } |
577
|
142 |
|
143 ~tree_argument_list (void) |
|
144 { |
|
145 while (! empty ()) |
|
146 { |
|
147 tree_expression *t = remove_front (); |
|
148 delete t; |
|
149 } |
|
150 } |
|
151 |
2086
|
152 octave_value_list convert_to_const_vector (void); |
581
|
153 |
|
154 void print_code (ostream& os); |
577
|
155 }; |
|
156 |
|
157 // Parameter lists. Used to hold the list of input and output |
|
158 // parameters in a function definition. Elements are identifiers |
|
159 // only. |
|
160 |
|
161 class |
581
|
162 tree_parameter_list : public SLList<tree_identifier *>, public tree_print_code |
577
|
163 { |
|
164 public: |
1227
|
165 tree_parameter_list (void) |
1740
|
166 : SLList<tree_identifier *> (), tree_print_code (), |
|
167 marked_for_varargs (0) { } |
632
|
168 |
1227
|
169 tree_parameter_list (tree_identifier *t) |
1740
|
170 : SLList<tree_identifier *> (), tree_print_code (), |
|
171 marked_for_varargs (0) |
|
172 { append (t); } |
577
|
173 |
1740
|
174 ~tree_parameter_list (void); |
577
|
175 |
|
176 // char *name (void) const; |
|
177 |
|
178 void mark_as_formal_parameters (void); |
|
179 |
|
180 void mark_varargs (void) |
|
181 { marked_for_varargs = 1; } |
|
182 |
1827
|
183 bool takes_varargs (void) const |
|
184 { return marked_for_varargs != 0; } |
577
|
185 |
|
186 void mark_varargs_only (void) |
|
187 { marked_for_varargs = -1; } |
|
188 |
1827
|
189 bool varargs_only (void) |
577
|
190 { return (marked_for_varargs < 0); } |
|
191 |
2086
|
192 void initialize_undefined_elements (octave_value& val); |
1093
|
193 |
2086
|
194 void define_from_arg_vector (const octave_value_list& args); |
577
|
195 |
1827
|
196 bool is_defined (void); |
577
|
197 |
2086
|
198 octave_value_list convert_to_const_vector (tree_va_return_list *vr_list); |
577
|
199 |
581
|
200 void print_code (ostream& os); |
|
201 |
577
|
202 private: |
|
203 int marked_for_varargs; |
|
204 }; |
|
205 |
|
206 // Return lists. Used to hold the right hand sides of multiple |
|
207 // assignment expressions. |
|
208 |
|
209 class |
581
|
210 tree_return_list : public SLList<tree_index_expression *>, |
|
211 public tree_print_code |
577
|
212 { |
|
213 public: |
1227
|
214 tree_return_list (void) |
|
215 : SLList<tree_index_expression *> (), tree_print_code () { } |
|
216 |
577
|
217 tree_return_list (tree_index_expression *t) |
1227
|
218 : SLList<tree_index_expression *> (), tree_print_code () |
577
|
219 { append (t); } |
|
220 |
1740
|
221 ~tree_return_list (void); |
581
|
222 |
|
223 void print_code (ostream& os); |
577
|
224 }; |
|
225 |
723
|
226 class |
2086
|
227 tree_va_return_list : public SLList<octave_value> |
723
|
228 { |
|
229 public: |
2086
|
230 tree_va_return_list (void) : SLList<octave_value> () { } |
1269
|
231 |
|
232 ~tree_va_return_list (void) { } |
723
|
233 }; |
|
234 |
577
|
235 // List of expressions that make up a global statement. |
|
236 |
|
237 class |
581
|
238 tree_global : public tree_print_code |
577
|
239 { |
|
240 public: |
1740
|
241 tree_global (void) : tree_print_code (), ident (0), assign_expr (0) { } |
577
|
242 |
|
243 tree_global (tree_identifier *id) |
1740
|
244 : tree_print_code (), ident (id), assign_expr (0) { } |
577
|
245 |
|
246 tree_global (tree_simple_assignment_expression *ass) |
1740
|
247 : tree_print_code (), ident (0), assign_expr (ass) { } |
577
|
248 |
1740
|
249 ~tree_global (void); |
577
|
250 |
|
251 void eval (void); |
|
252 |
581
|
253 void print_code (ostream& os); |
|
254 |
577
|
255 private: |
|
256 tree_identifier *ident; |
|
257 tree_simple_assignment_expression *assign_expr; |
|
258 }; |
|
259 |
|
260 class |
581
|
261 tree_global_init_list : public SLList<tree_global *>, public tree_print_code |
577
|
262 { |
|
263 public: |
1227
|
264 tree_global_init_list (void) |
|
265 : SLList<tree_global *> (), tree_print_code () { } |
|
266 |
|
267 tree_global_init_list (tree_global *t) |
|
268 : SLList<tree_global *> (), tree_print_code () |
|
269 { append (t); } |
577
|
270 |
|
271 ~tree_global_init_list (void) |
|
272 { |
|
273 while (! empty ()) |
|
274 { |
|
275 tree_global *t = remove_front (); |
|
276 delete t; |
|
277 } |
|
278 } |
|
279 |
|
280 void eval (void); |
581
|
281 |
|
282 void print_code (ostream& os); |
577
|
283 }; |
|
284 |
|
285 class |
581
|
286 tree_if_clause : public tree_print_code |
577
|
287 { |
|
288 public: |
1740
|
289 tree_if_clause (void) : tree_print_code (), expr (0), list (0) { } |
577
|
290 |
1740
|
291 tree_if_clause (tree_statement_list *l) |
|
292 : tree_print_code (), expr (0), list (l) { } |
577
|
293 |
|
294 tree_if_clause (tree_expression *e, tree_statement_list *l) |
1740
|
295 : tree_print_code (), expr (e), list (l) { } |
577
|
296 |
1740
|
297 ~tree_if_clause (void); |
577
|
298 |
1827
|
299 bool is_else_clause (void) |
|
300 { return ! expr; } |
1063
|
301 |
577
|
302 int eval (void); |
|
303 |
581
|
304 void print_code (ostream& os); |
|
305 |
577
|
306 private: |
|
307 tree_expression *expr; |
|
308 tree_statement_list *list; |
|
309 }; |
|
310 |
|
311 class |
581
|
312 tree_if_command_list : public SLList<tree_if_clause *>, public tree_print_code |
577
|
313 { |
|
314 public: |
1227
|
315 tree_if_command_list (void) |
|
316 : SLList<tree_if_clause *> (), tree_print_code () { } |
|
317 |
|
318 tree_if_command_list (tree_if_clause *t) |
|
319 : SLList<tree_if_clause *> (), tree_print_code () |
|
320 { append (t); } |
577
|
321 |
|
322 ~tree_if_command_list (void) |
|
323 { |
|
324 while (! empty ()) |
|
325 { |
|
326 tree_if_clause *t = remove_front (); |
|
327 delete t; |
|
328 } |
|
329 } |
|
330 |
|
331 void eval (void); |
581
|
332 |
|
333 void print_code (ostream& os); |
577
|
334 }; |
|
335 |
|
336 #endif |
|
337 |
|
338 /* |
|
339 ;;; Local Variables: *** |
|
340 ;;; mode: C++ *** |
|
341 ;;; End: *** |
|
342 */ |