Mercurial > octave
comparison src/pt-misc.h @ 2982:20f5cec4f11c
[project @ 1997-05-16 03:29:26 by jwe]
author | jwe |
---|---|
date | Fri, 16 May 1997 03:30:14 +0000 |
parents | ef3379196bcf |
children | daa1ed1f5462 |
comparison
equal
deleted
inserted
replaced
2981:38365813950d | 2982:20f5cec4f11c |
---|---|
25 | 25 |
26 #if defined (__GNUG__) | 26 #if defined (__GNUG__) |
27 #pragma interface | 27 #pragma interface |
28 #endif | 28 #endif |
29 | 29 |
30 class ostream; | 30 #include <SLList.h> |
31 | 31 |
32 class string_vector; | 32 class octave_value; |
33 class octave_value_list; | |
33 | 34 |
34 class octave_value_list; | 35 class tree_identifier; |
35 class octave_value; | |
36 class tree_command; | |
37 class tree_expression; | |
38 class tree_simple_assignment; | |
39 class tree_index_expression; | 36 class tree_index_expression; |
40 class tree_identifier; | |
41 class symbol_record; | |
42 class symbol_table; | |
43 | |
44 class tree_statement; | |
45 class tree_statement_list; | |
46 class tree_argument_list; | |
47 class tree_parameter_list; | |
48 class tree_return_list; | |
49 class tree_va_return_list; | 37 class tree_va_return_list; |
50 class tree_decl_elt; | |
51 class tree_decl_init_list; | |
52 class tree_if_clause; | |
53 class tree_if_command_list; | |
54 class tree_switch_case; | |
55 class tree_switch_case_list; | |
56 | 38 |
57 class tree_walker; | 39 class tree_walker; |
58 | |
59 #include <SLList.h> | |
60 | |
61 // A statement is either a command to execute or an expression to | |
62 // evaluate. | |
63 | |
64 class | |
65 tree_statement | |
66 { | |
67 public: | |
68 | |
69 tree_statement (void) | |
70 : cmd (0), expr (0), print_flag (true) { } | |
71 | |
72 tree_statement (tree_command *c) | |
73 : cmd (c), expr (0), print_flag (true) { } | |
74 | |
75 tree_statement (tree_expression *e) | |
76 : cmd (0), expr (e), print_flag (true) { } | |
77 | |
78 ~tree_statement (void); | |
79 | |
80 void set_print_flag (bool print) | |
81 { print_flag = print; } | |
82 | |
83 bool is_command (void) | |
84 { return cmd != 0; } | |
85 | |
86 bool is_expression (void) | |
87 { return expr != 0; } | |
88 | |
89 int line (void); | |
90 int column (void); | |
91 | |
92 void maybe_echo_code (bool in_function_body); | |
93 | |
94 bool print_result (void) { return print_flag; } | |
95 | |
96 tree_command *command (void) { return cmd; } | |
97 | |
98 octave_value_list eval (bool silent, int nargout, bool in_function_body); | |
99 | |
100 tree_expression *expression (void) { return expr; } | |
101 | |
102 void accept (tree_walker& tw); | |
103 | |
104 private: | |
105 | |
106 // Only one of cmd or expr can be valid at once. | |
107 | |
108 // Command to execute. | |
109 tree_command *cmd; | |
110 | |
111 // Expression to evaluate. | |
112 tree_expression *expr; | |
113 | |
114 // Print result of eval for this command? | |
115 bool print_flag; | |
116 }; | |
117 | |
118 // A list of statements to evaluate. | |
119 | |
120 class | |
121 tree_statement_list : public SLList<tree_statement *> | |
122 { | |
123 public: | |
124 | |
125 tree_statement_list (void) | |
126 : SLList<tree_statement *> (), function_body (false) { } | |
127 | |
128 tree_statement_list (tree_statement *s) | |
129 : SLList<tree_statement *> (), function_body (false) { append (s); } | |
130 | |
131 ~tree_statement_list (void) | |
132 { | |
133 while (! empty ()) | |
134 { | |
135 tree_statement *t = remove_front (); | |
136 delete t; | |
137 } | |
138 } | |
139 | |
140 void mark_as_function_body (void) { function_body = true; } | |
141 | |
142 octave_value_list eval (bool silent = false, int nargout = 0); | |
143 | |
144 void accept (tree_walker& tw); | |
145 | |
146 private: | |
147 | |
148 // Does this list of statements make up the body of a function? | |
149 bool function_body; | |
150 }; | |
151 | |
152 // Argument lists. Used to hold the list of expressions that are the | |
153 // arguments in a function call or index expression. | |
154 | |
155 class | |
156 tree_argument_list : public SLList<tree_expression *> | |
157 { | |
158 public: | |
159 | |
160 tree_argument_list (void) | |
161 : SLList<tree_expression *> () { } | |
162 | |
163 tree_argument_list (tree_expression *t) | |
164 : SLList<tree_expression *> () { append (t); } | |
165 | |
166 ~tree_argument_list (void); | |
167 | |
168 bool all_elements_are_constant (void) const; | |
169 | |
170 octave_value_list convert_to_const_vector (void); | |
171 | |
172 string_vector get_arg_names (void) const; | |
173 | |
174 void accept (tree_walker& tw); | |
175 }; | |
176 | 40 |
177 // Parameter lists. Used to hold the list of input and output | 41 // Parameter lists. Used to hold the list of input and output |
178 // parameters in a function definition. Elements are identifiers | 42 // parameters in a function definition. Elements are identifiers |
179 // only. | 43 // only. |
180 | 44 |
247 tree_va_return_list (void) : SLList<octave_value> () { } | 111 tree_va_return_list (void) : SLList<octave_value> () { } |
248 | 112 |
249 ~tree_va_return_list (void) { } | 113 ~tree_va_return_list (void) { } |
250 }; | 114 }; |
251 | 115 |
252 // List of expressions that make up a declaration statement. | |
253 | |
254 class | |
255 tree_decl_elt | |
256 { | |
257 public: | |
258 | |
259 typedef void (*eval_fcn) (tree_decl_elt &, bool); | |
260 | |
261 tree_decl_elt (tree_identifier *i = 0, tree_expression *e = 0) | |
262 : id (i), expr (e) { } | |
263 | |
264 ~tree_decl_elt (void); | |
265 | |
266 void eval (void); | |
267 | |
268 tree_identifier *ident (void) { return id; } | |
269 | |
270 tree_expression *expression (void) { return expr; } | |
271 | |
272 void accept (tree_walker& tw); | |
273 | |
274 private: | |
275 | |
276 // An identifier to tag with the declared property. | |
277 tree_identifier *id; | |
278 | |
279 // An initializer expression (may be zero); | |
280 tree_expression *expr; | |
281 }; | |
282 | |
283 class | |
284 tree_decl_init_list : public SLList<tree_decl_elt *> | |
285 { | |
286 public: | |
287 | |
288 tree_decl_init_list (void) | |
289 : SLList<tree_decl_elt *> () { } | |
290 | |
291 tree_decl_init_list (tree_decl_elt *t) | |
292 : SLList<tree_decl_elt *> () { append (t); } | |
293 | |
294 ~tree_decl_init_list (void) | |
295 { | |
296 while (! empty ()) | |
297 { | |
298 tree_decl_elt *t = remove_front (); | |
299 delete t; | |
300 } | |
301 } | |
302 | |
303 void eval (tree_decl_elt::eval_fcn, bool); | |
304 | |
305 void accept (tree_walker& tw); | |
306 }; | |
307 | |
308 class | |
309 tree_if_clause | |
310 { | |
311 public: | |
312 | |
313 tree_if_clause (void) : expr (0), list (0) { } | |
314 | |
315 tree_if_clause (tree_statement_list *l) | |
316 : expr (0), list (l) { } | |
317 | |
318 tree_if_clause (tree_expression *e, tree_statement_list *l) | |
319 : expr (e), list (l) { } | |
320 | |
321 ~tree_if_clause (void); | |
322 | |
323 bool is_else_clause (void) | |
324 { return ! expr; } | |
325 | |
326 int eval (void); | |
327 | |
328 tree_expression *condition (void) { return expr; } | |
329 | |
330 tree_statement_list *commands (void) { return list; } | |
331 | |
332 void accept (tree_walker& tw); | |
333 | |
334 private: | |
335 | |
336 // The condition to test. | |
337 tree_expression *expr; | |
338 | |
339 // The list of statements to evaluate if expr is true. | |
340 tree_statement_list *list; | |
341 }; | |
342 | |
343 class | |
344 tree_if_command_list : public SLList<tree_if_clause *> | |
345 { | |
346 public: | |
347 | |
348 tree_if_command_list (void) | |
349 : SLList<tree_if_clause *> () { } | |
350 | |
351 tree_if_command_list (tree_if_clause *t) | |
352 : SLList<tree_if_clause *> () { append (t); } | |
353 | |
354 ~tree_if_command_list (void) | |
355 { | |
356 while (! empty ()) | |
357 { | |
358 tree_if_clause *t = remove_front (); | |
359 delete t; | |
360 } | |
361 } | |
362 | |
363 void eval (void); | |
364 | |
365 void accept (tree_walker& tw); | |
366 }; | |
367 | |
368 class | |
369 tree_switch_case | |
370 { | |
371 public: | |
372 | |
373 tree_switch_case (void) : label (0), list (0) { } | |
374 | |
375 tree_switch_case (tree_statement_list *l) | |
376 : label (0), list (l) { } | |
377 | |
378 tree_switch_case (tree_expression *e, tree_statement_list *l) | |
379 : label (e), list (l) { } | |
380 | |
381 ~tree_switch_case (void); | |
382 | |
383 bool is_default_case (void) | |
384 { return ! label; } | |
385 | |
386 bool label_matches (const octave_value& val); | |
387 | |
388 int eval (const octave_value& val); | |
389 | |
390 void eval_error (void); | |
391 | |
392 tree_expression *case_label (void) { return label; } | |
393 | |
394 tree_statement_list *commands (void) { return list; } | |
395 | |
396 void accept (tree_walker& tw); | |
397 | |
398 private: | |
399 | |
400 // The case label. | |
401 tree_expression *label; | |
402 | |
403 // The list of statements to evaluate if the label matches. | |
404 tree_statement_list *list; | |
405 }; | |
406 | |
407 class | |
408 tree_switch_case_list : public SLList<tree_switch_case *> | |
409 { | |
410 public: | |
411 | |
412 tree_switch_case_list (void) | |
413 : SLList<tree_switch_case *> () { } | |
414 | |
415 tree_switch_case_list (tree_switch_case *t) | |
416 : SLList<tree_switch_case *> () { append (t); } | |
417 | |
418 ~tree_switch_case_list (void) | |
419 { | |
420 while (! empty ()) | |
421 { | |
422 tree_switch_case *t = remove_front (); | |
423 delete t; | |
424 } | |
425 } | |
426 | |
427 void eval (const octave_value& val); | |
428 | |
429 void accept (tree_walker& tw); | |
430 }; | |
431 | |
432 #endif | 116 #endif |
433 | 117 |
434 /* | 118 /* |
435 ;;; Local Variables: *** | 119 ;;; Local Variables: *** |
436 ;;; mode: C++ *** | 120 ;;; mode: C++ *** |