Mercurial > hg > octave-lyh
comparison src/pt-misc.h @ 2124:97a566037a75
[project @ 1996-05-12 07:16:36 by jwe]
author | jwe |
---|---|
date | Sun, 12 May 1996 07:16:36 +0000 |
parents | bfb775fb6fe8 |
children | 2c0f259cf83d |
comparison
equal
deleted
inserted
replaced
2123:ee55d81f585a | 2124:97a566037a75 |
---|---|
46 class tree_return_list; | 46 class tree_return_list; |
47 class tree_va_return_list; | 47 class tree_va_return_list; |
48 class tree_global; | 48 class tree_global; |
49 class tree_global_init_list; | 49 class tree_global_init_list; |
50 | 50 |
51 class tree_walker; | |
52 | |
51 #include <SLList.h> | 53 #include <SLList.h> |
52 | 54 |
53 #include "pt-base.h" | 55 #include "pt-base.h" |
54 | 56 |
55 // A list of expressions and commands to be executed. | 57 // A statement is either a command to execute or an expression to |
56 | 58 // evaluate. |
57 class | 59 |
58 tree_statement : public tree_print_code | 60 class |
61 tree_statement | |
59 { | 62 { |
60 friend class tree_statement_list; | 63 friend class tree_statement_list; |
61 | 64 |
62 public: | 65 public: |
66 | |
63 tree_statement (void) | 67 tree_statement (void) |
64 : tree_print_code (), command (0), expression (0), print_flag (true) { } | 68 : cmd (0), expr (0), print_flag (true) { } |
65 | 69 |
66 tree_statement (tree_command *c) | 70 tree_statement (tree_command *c) |
67 : tree_print_code (), command (c), expression (0), print_flag (true) { } | 71 : cmd (c), expr (0), print_flag (true) { } |
68 | 72 |
69 tree_statement (tree_expression *e) | 73 tree_statement (tree_expression *e) |
70 : tree_print_code (), command (0), expression (e), print_flag (true) { } | 74 : cmd (0), expr (e), print_flag (true) { } |
71 | 75 |
72 ~tree_statement (void); | 76 ~tree_statement (void); |
73 | 77 |
74 void set_print_flag (bool print) | 78 void set_print_flag (bool print) |
75 { print_flag = print; } | 79 { print_flag = print; } |
76 | 80 |
77 bool is_command (void) | 81 bool is_command (void) |
78 { return command != 0; } | 82 { return cmd != 0; } |
79 | 83 |
80 bool is_expression (void) | 84 bool is_expression (void) |
81 { return expression != 0; } | 85 { return expr != 0; } |
82 | 86 |
83 int line (void); | 87 int line (void); |
84 int column (void); | 88 int column (void); |
85 | 89 |
86 void maybe_echo_code (bool); | 90 void maybe_echo_code (bool); |
87 | 91 |
88 void print_code (ostream& os); | 92 bool print_result (void) { return print_flag; } |
89 | 93 |
90 private: | 94 tree_command *command (void) { return cmd; } |
91 tree_command *command; // Command to execute. | 95 |
92 tree_expression *expression; // Command to execute. | 96 tree_expression *expression (void) { return expr; } |
93 bool print_flag; // Print result of eval for this command? | 97 |
94 }; | 98 void accept (tree_walker& tw); |
95 | 99 |
96 class | 100 private: |
97 tree_statement_list : public SLList<tree_statement *>, public tree_print_code | 101 |
98 { | 102 // Only one of cmd or expr can be valid at once. |
99 public: | 103 |
104 // Command to execute. | |
105 tree_command *cmd; | |
106 | |
107 // Expression to evaluate. | |
108 tree_expression *expr; | |
109 | |
110 // Print result of eval for this command? | |
111 bool print_flag; | |
112 }; | |
113 | |
114 // A list of statements to evaluate. | |
115 | |
116 class | |
117 tree_statement_list : public SLList<tree_statement *> | |
118 { | |
119 public: | |
120 | |
100 tree_statement_list (void) | 121 tree_statement_list (void) |
101 : SLList<tree_statement *> (), tree_print_code (), function_body (false) | 122 : SLList<tree_statement *> (), function_body (false) { } |
102 { } | |
103 | 123 |
104 tree_statement_list (tree_statement *s) | 124 tree_statement_list (tree_statement *s) |
105 : SLList<tree_statement *> (), tree_print_code (), function_body (false) | 125 : SLList<tree_statement *> (), function_body (false) { append (s); } |
106 { append (s); } | |
107 | 126 |
108 ~tree_statement_list (void) | 127 ~tree_statement_list (void) |
109 { | 128 { |
110 while (! empty ()) | 129 while (! empty ()) |
111 { | 130 { |
118 | 137 |
119 octave_value eval (bool print); | 138 octave_value eval (bool print); |
120 | 139 |
121 octave_value_list eval (bool print, int nargout); | 140 octave_value_list eval (bool print, int nargout); |
122 | 141 |
123 void print_code (ostream& os); | 142 void accept (tree_walker& tw); |
124 | 143 |
125 private: | 144 private: |
145 | |
146 // Does this list of statements make up the body of a function? | |
126 bool function_body; | 147 bool function_body; |
127 }; | 148 }; |
128 | 149 |
129 // Argument lists. Used to hold the list of expressions that are the | 150 // Argument lists. Used to hold the list of expressions that are the |
130 // arguments in a function call or index expression. | 151 // arguments in a function call or index expression. |
131 | 152 |
132 class | 153 class |
133 tree_argument_list : public SLList<tree_expression *>, public tree_print_code | 154 tree_argument_list : public SLList<tree_expression *> |
134 { | 155 { |
135 public: | 156 public: |
157 | |
136 tree_argument_list (void) | 158 tree_argument_list (void) |
137 : SLList<tree_expression *> (), tree_print_code () { } | 159 : SLList<tree_expression *> () { } |
138 | 160 |
139 tree_argument_list (tree_expression *t) | 161 tree_argument_list (tree_expression *t) |
140 : SLList<tree_expression *> (), tree_print_code () | 162 : SLList<tree_expression *> () { append (t); } |
141 { append (t); } | |
142 | 163 |
143 ~tree_argument_list (void) | 164 ~tree_argument_list (void) |
144 { | 165 { |
145 while (! empty ()) | 166 while (! empty ()) |
146 { | 167 { |
149 } | 170 } |
150 } | 171 } |
151 | 172 |
152 octave_value_list convert_to_const_vector (void); | 173 octave_value_list convert_to_const_vector (void); |
153 | 174 |
154 void print_code (ostream& os); | 175 void accept (tree_walker& tw); |
155 }; | 176 }; |
156 | 177 |
157 // Parameter lists. Used to hold the list of input and output | 178 // Parameter lists. Used to hold the list of input and output |
158 // parameters in a function definition. Elements are identifiers | 179 // parameters in a function definition. Elements are identifiers |
159 // only. | 180 // only. |
160 | 181 |
161 class | 182 class |
162 tree_parameter_list : public SLList<tree_identifier *>, public tree_print_code | 183 tree_parameter_list : public SLList<tree_identifier *> |
163 { | 184 { |
164 public: | 185 public: |
186 | |
165 tree_parameter_list (void) | 187 tree_parameter_list (void) |
166 : SLList<tree_identifier *> (), tree_print_code (), | 188 : SLList<tree_identifier *> (), marked_for_varargs (0) { } |
167 marked_for_varargs (0) { } | |
168 | 189 |
169 tree_parameter_list (tree_identifier *t) | 190 tree_parameter_list (tree_identifier *t) |
170 : SLList<tree_identifier *> (), tree_print_code (), | 191 : SLList<tree_identifier *> (), marked_for_varargs (0) { append (t); } |
171 marked_for_varargs (0) | |
172 { append (t); } | |
173 | 192 |
174 ~tree_parameter_list (void); | 193 ~tree_parameter_list (void); |
175 | |
176 // char *name (void) const; | |
177 | 194 |
178 void mark_as_formal_parameters (void); | 195 void mark_as_formal_parameters (void); |
179 | 196 |
180 void mark_varargs (void) | 197 void mark_varargs (void) |
181 { marked_for_varargs = 1; } | 198 { marked_for_varargs = 1; } |
195 | 212 |
196 bool is_defined (void); | 213 bool is_defined (void); |
197 | 214 |
198 octave_value_list convert_to_const_vector (tree_va_return_list *vr_list); | 215 octave_value_list convert_to_const_vector (tree_va_return_list *vr_list); |
199 | 216 |
200 void print_code (ostream& os); | 217 void accept (tree_walker& tw); |
201 | 218 |
202 private: | 219 private: |
220 | |
203 int marked_for_varargs; | 221 int marked_for_varargs; |
204 }; | 222 }; |
205 | 223 |
206 // Return lists. Used to hold the right hand sides of multiple | 224 // Return lists. Used to hold the right hand sides of multiple |
207 // assignment expressions. | 225 // assignment expressions. |
208 | 226 |
209 class | 227 class |
210 tree_return_list : public SLList<tree_index_expression *>, | 228 tree_return_list : public SLList<tree_index_expression *> |
211 public tree_print_code | 229 { |
212 { | 230 public: |
213 public: | 231 |
214 tree_return_list (void) | 232 tree_return_list (void) |
215 : SLList<tree_index_expression *> (), tree_print_code () { } | 233 : SLList<tree_index_expression *> () { } |
216 | 234 |
217 tree_return_list (tree_index_expression *t) | 235 tree_return_list (tree_index_expression *t) |
218 : SLList<tree_index_expression *> (), tree_print_code () | 236 : SLList<tree_index_expression *> () { append (t); } |
219 { append (t); } | |
220 | 237 |
221 ~tree_return_list (void); | 238 ~tree_return_list (void); |
222 | 239 |
223 void print_code (ostream& os); | 240 void accept (tree_walker& tw); |
224 }; | 241 }; |
225 | 242 |
226 class | 243 class |
227 tree_va_return_list : public SLList<octave_value> | 244 tree_va_return_list : public SLList<octave_value> |
228 { | 245 { |
229 public: | 246 public: |
247 | |
230 tree_va_return_list (void) : SLList<octave_value> () { } | 248 tree_va_return_list (void) : SLList<octave_value> () { } |
231 | 249 |
232 ~tree_va_return_list (void) { } | 250 ~tree_va_return_list (void) { } |
233 }; | 251 }; |
234 | 252 |
235 // List of expressions that make up a global statement. | 253 // List of expressions that make up a global statement. |
236 | 254 |
237 class | 255 class |
238 tree_global : public tree_print_code | 256 tree_global |
239 { | 257 { |
240 public: | 258 public: |
241 tree_global (void) : tree_print_code (), ident (0), assign_expr (0) { } | 259 |
242 | 260 tree_global (void) |
243 tree_global (tree_identifier *id) | 261 : id (0), ass_expr (0) { } |
244 : tree_print_code (), ident (id), assign_expr (0) { } | 262 |
263 tree_global (tree_identifier *i) | |
264 : id (i), ass_expr (0) { } | |
245 | 265 |
246 tree_global (tree_simple_assignment_expression *ass) | 266 tree_global (tree_simple_assignment_expression *ass) |
247 : tree_print_code (), ident (0), assign_expr (ass) { } | 267 : id (0), ass_expr (ass) { } |
248 | 268 |
249 ~tree_global (void); | 269 ~tree_global (void); |
250 | 270 |
251 void eval (void); | 271 void eval (void); |
252 | 272 |
253 void print_code (ostream& os); | 273 tree_identifier *ident (void) { return id; } |
254 | 274 |
255 private: | 275 tree_simple_assignment_expression *assign_expr (void) { return ass_expr; } |
256 tree_identifier *ident; | 276 |
257 tree_simple_assignment_expression *assign_expr; | 277 void accept (tree_walker& tw); |
258 }; | 278 |
259 | 279 private: |
260 class | 280 |
261 tree_global_init_list : public SLList<tree_global *>, public tree_print_code | 281 // Only one of id or ass_expr can be valid at once. |
262 { | 282 |
263 public: | 283 // An identifier to make global. |
284 tree_identifier *id; | |
285 | |
286 // An assignemnt expression. Valid only if the left hand side of | |
287 // the assignment is a simple identifier. | |
288 tree_simple_assignment_expression *ass_expr; | |
289 }; | |
290 | |
291 class | |
292 tree_global_init_list : public SLList<tree_global *> | |
293 { | |
294 public: | |
295 | |
264 tree_global_init_list (void) | 296 tree_global_init_list (void) |
265 : SLList<tree_global *> (), tree_print_code () { } | 297 : SLList<tree_global *> () { } |
266 | 298 |
267 tree_global_init_list (tree_global *t) | 299 tree_global_init_list (tree_global *t) |
268 : SLList<tree_global *> (), tree_print_code () | 300 : SLList<tree_global *> () { append (t); } |
269 { append (t); } | |
270 | 301 |
271 ~tree_global_init_list (void) | 302 ~tree_global_init_list (void) |
272 { | 303 { |
273 while (! empty ()) | 304 while (! empty ()) |
274 { | 305 { |
277 } | 308 } |
278 } | 309 } |
279 | 310 |
280 void eval (void); | 311 void eval (void); |
281 | 312 |
282 void print_code (ostream& os); | 313 void accept (tree_walker& tw); |
283 }; | 314 }; |
284 | 315 |
285 class | 316 class |
286 tree_if_clause : public tree_print_code | 317 tree_if_clause |
287 { | 318 { |
288 public: | 319 public: |
289 tree_if_clause (void) : tree_print_code (), expr (0), list (0) { } | 320 |
321 tree_if_clause (void) : expr (0), list (0) { } | |
290 | 322 |
291 tree_if_clause (tree_statement_list *l) | 323 tree_if_clause (tree_statement_list *l) |
292 : tree_print_code (), expr (0), list (l) { } | 324 : expr (0), list (l) { } |
293 | 325 |
294 tree_if_clause (tree_expression *e, tree_statement_list *l) | 326 tree_if_clause (tree_expression *e, tree_statement_list *l) |
295 : tree_print_code (), expr (e), list (l) { } | 327 : expr (e), list (l) { } |
296 | 328 |
297 ~tree_if_clause (void); | 329 ~tree_if_clause (void); |
298 | 330 |
299 bool is_else_clause (void) | 331 bool is_else_clause (void) |
300 { return ! expr; } | 332 { return ! expr; } |
301 | 333 |
302 int eval (void); | 334 int eval (void); |
303 | 335 |
304 void print_code (ostream& os); | 336 tree_expression *condition (void) { return expr; } |
305 | 337 |
306 private: | 338 tree_statement_list *commands (void) { return list; } |
339 | |
340 void accept (tree_walker& tw); | |
341 | |
342 private: | |
343 | |
344 // The condition to test. | |
307 tree_expression *expr; | 345 tree_expression *expr; |
346 | |
347 // The list of statements to evaluate if expr is true. | |
308 tree_statement_list *list; | 348 tree_statement_list *list; |
309 }; | 349 }; |
310 | 350 |
311 class | 351 class |
312 tree_if_command_list : public SLList<tree_if_clause *>, public tree_print_code | 352 tree_if_command_list : public SLList<tree_if_clause *> |
313 { | 353 { |
314 public: | 354 public: |
355 | |
315 tree_if_command_list (void) | 356 tree_if_command_list (void) |
316 : SLList<tree_if_clause *> (), tree_print_code () { } | 357 : SLList<tree_if_clause *> () { } |
317 | 358 |
318 tree_if_command_list (tree_if_clause *t) | 359 tree_if_command_list (tree_if_clause *t) |
319 : SLList<tree_if_clause *> (), tree_print_code () | 360 : SLList<tree_if_clause *> () { append (t); } |
320 { append (t); } | |
321 | 361 |
322 ~tree_if_command_list (void) | 362 ~tree_if_command_list (void) |
323 { | 363 { |
324 while (! empty ()) | 364 while (! empty ()) |
325 { | 365 { |
328 } | 368 } |
329 } | 369 } |
330 | 370 |
331 void eval (void); | 371 void eval (void); |
332 | 372 |
333 void print_code (ostream& os); | 373 void accept (tree_walker& tw); |
334 }; | 374 }; |
335 | 375 |
336 #endif | 376 #endif |
337 | 377 |
338 /* | 378 /* |