Mercurial > hg > octave-nkf
comparison src/pt-check.cc @ 3011:2ad9af85b89b
[project @ 1997-06-01 19:34:20 by jwe]
author | jwe |
---|---|
date | Sun, 01 Jun 1997 19:37:26 +0000 |
parents | |
children | 5708b8bb4f06 |
comparison
equal
deleted
inserted
replaced
3010:1aeb8869e464 | 3011:2ad9af85b89b |
---|---|
1 /* | |
2 | |
3 Copyright (C) 1996, 1997 John W. Eaton | |
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 | |
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
20 | |
21 */ | |
22 | |
23 #if defined (__GNUG__) | |
24 #pragma implementation | |
25 #endif | |
26 | |
27 #ifdef HAVE_CONFIG_H | |
28 #include <config.h> | |
29 #endif | |
30 | |
31 #include "error.h" | |
32 #include "input.h" | |
33 #include "ov-usr-fcn.h" | |
34 #include "pt-all.h" | |
35 | |
36 void | |
37 tree_checker::visit_argument_list (tree_argument_list& lst) | |
38 { | |
39 Pix p = lst.first (); | |
40 | |
41 while (p) | |
42 { | |
43 tree_expression *elt = lst (p); | |
44 | |
45 lst.next (p); | |
46 | |
47 if (elt) | |
48 { | |
49 if (do_lvalue_check && ! elt->lvalue_ok ()) | |
50 gripe ("invalid lvalue in multiple assignment", elt->line ()); | |
51 } | |
52 } | |
53 } | |
54 | |
55 void | |
56 tree_checker::visit_binary_expression (tree_binary_expression& expr) | |
57 { | |
58 tree_expression *op1 = expr.lhs (); | |
59 | |
60 if (op1) | |
61 op1->accept (*this); | |
62 | |
63 tree_expression *op2 = expr.rhs (); | |
64 | |
65 if (op2) | |
66 op2->accept (*this); | |
67 } | |
68 | |
69 void | |
70 tree_checker::visit_break_command (tree_break_command&) | |
71 { | |
72 } | |
73 | |
74 void | |
75 tree_checker::visit_colon_expression (tree_colon_expression& expr) | |
76 { | |
77 tree_expression *op1 = expr.base (); | |
78 | |
79 if (op1) | |
80 op1->accept (*this); | |
81 | |
82 tree_expression *op3 = expr.increment (); | |
83 | |
84 if (op3) | |
85 op3->accept (*this); | |
86 | |
87 tree_expression *op2 = expr.limit (); | |
88 | |
89 if (op2) | |
90 op2->accept (*this); | |
91 } | |
92 | |
93 void | |
94 tree_checker::visit_continue_command (tree_continue_command&) | |
95 { | |
96 } | |
97 | |
98 void | |
99 tree_checker::visit_decl_command (tree_decl_command& cmd) | |
100 { | |
101 tree_decl_init_list *init_list = cmd.initializer_list (); | |
102 | |
103 if (init_list) | |
104 init_list->accept (*this); | |
105 } | |
106 | |
107 void | |
108 tree_checker::visit_decl_elt (tree_decl_elt& cmd) | |
109 { | |
110 tree_identifier *id = cmd.ident (); | |
111 | |
112 if (id) | |
113 id->accept (*this); | |
114 | |
115 tree_expression *expr = cmd.expression (); | |
116 | |
117 if (expr) | |
118 expr->accept (*this); | |
119 } | |
120 | |
121 void | |
122 tree_checker::visit_decl_init_list (tree_decl_init_list& lst) | |
123 { | |
124 Pix p = lst.first (); | |
125 | |
126 while (p) | |
127 { | |
128 tree_decl_elt *elt = lst (p); | |
129 | |
130 lst.next (p); | |
131 | |
132 if (elt) | |
133 elt->accept (*this); | |
134 } | |
135 } | |
136 | |
137 void | |
138 tree_checker::visit_simple_for_command (tree_simple_for_command& cmd) | |
139 { | |
140 tree_expression *lhs = cmd.left_hand_side (); | |
141 | |
142 if (lhs) | |
143 { | |
144 if (! lhs->lvalue_ok ()) | |
145 gripe ("invalid lvalue in for command", cmd.line ()); | |
146 } | |
147 | |
148 tree_expression *expr = cmd.control_expr (); | |
149 | |
150 if (expr) | |
151 expr->accept (*this); | |
152 | |
153 tree_statement_list *list = cmd.body (); | |
154 | |
155 if (list) | |
156 list->accept (*this); | |
157 } | |
158 | |
159 void | |
160 tree_checker::visit_complex_for_command (tree_complex_for_command& cmd) | |
161 { | |
162 tree_argument_list *lhs = cmd.left_hand_side (); | |
163 | |
164 if (lhs) | |
165 { | |
166 int len = lhs->length (); | |
167 | |
168 if (len == 0 || lhs > 2) | |
169 gripe ("invalid number of output arguments in for command", | |
170 cmd.line ()); | |
171 | |
172 do_lvalue_check = true; | |
173 | |
174 lhs->accept (*this); | |
175 | |
176 do_lvalue_check = false; | |
177 } | |
178 | |
179 tree_expression *expr = cmd.control_expr (); | |
180 | |
181 if (expr) | |
182 expr->accept (*this); | |
183 | |
184 tree_statement_list *list = cmd.body (); | |
185 | |
186 if (list) | |
187 list->accept (*this); | |
188 } | |
189 | |
190 void | |
191 tree_checker::visit_octave_user_function (octave_user_function& fcn) | |
192 { | |
193 tree_statement_list *cmd_list = fcn.body (); | |
194 | |
195 if (cmd_list) | |
196 cmd_list->accept (*this); | |
197 } | |
198 | |
199 void | |
200 tree_checker::visit_identifier (tree_identifier& /* id */) | |
201 { | |
202 } | |
203 | |
204 void | |
205 tree_checker::visit_if_clause (tree_if_clause& cmd) | |
206 { | |
207 tree_expression *expr = cmd.condition (); | |
208 | |
209 if (expr) | |
210 expr->accept (*this); | |
211 | |
212 tree_statement_list *list = cmd.commands (); | |
213 | |
214 if (list) | |
215 list->accept (*this); | |
216 } | |
217 | |
218 void | |
219 tree_checker::visit_if_command (tree_if_command& cmd) | |
220 { | |
221 tree_if_command_list *list = cmd.cmd_list (); | |
222 | |
223 if (list) | |
224 list->accept (*this); | |
225 } | |
226 | |
227 void | |
228 tree_checker::visit_if_command_list (tree_if_command_list& lst) | |
229 { | |
230 Pix p = lst.first (); | |
231 | |
232 while (p) | |
233 { | |
234 tree_if_clause *elt = lst (p); | |
235 | |
236 if (elt) | |
237 elt->accept (*this); | |
238 | |
239 lst.next (p); | |
240 } | |
241 } | |
242 | |
243 void | |
244 tree_checker::visit_index_expression (tree_index_expression& expr) | |
245 { | |
246 tree_expression *e = expr.expression (); | |
247 | |
248 if (e) | |
249 e->accept (*this); | |
250 | |
251 tree_argument_list *list = expr.arg_list (); | |
252 | |
253 if (list) | |
254 list->accept (*this); | |
255 } | |
256 | |
257 void | |
258 tree_checker::visit_indirect_ref (tree_indirect_ref& expr) | |
259 { | |
260 tree_expression *e = expr.expression (); | |
261 | |
262 if (e) | |
263 e->accept (*this); | |
264 } | |
265 | |
266 void | |
267 tree_checker::visit_matrix (tree_matrix& lst) | |
268 { | |
269 Pix p = lst.first (); | |
270 | |
271 while (p) | |
272 { | |
273 tree_argument_list *elt = lst (p); | |
274 | |
275 lst.next (p); | |
276 | |
277 if (elt) | |
278 elt->accept (*this); | |
279 } | |
280 } | |
281 | |
282 void | |
283 tree_checker::visit_multi_assignment (tree_multi_assignment& expr) | |
284 { | |
285 tree_argument_list *lhs = expr.left_hand_side (); | |
286 | |
287 if (lhs) | |
288 { | |
289 do_lvalue_check = true; | |
290 | |
291 lhs->accept (*this); | |
292 | |
293 do_lvalue_check = false; | |
294 } | |
295 | |
296 tree_expression *rhs = expr.right_hand_side (); | |
297 | |
298 if (rhs) | |
299 rhs->accept (*this); | |
300 } | |
301 | |
302 void | |
303 tree_checker::visit_no_op_command (tree_no_op_command& /* cmd */) | |
304 { | |
305 } | |
306 | |
307 void | |
308 tree_checker::visit_constant (tree_constant& /* val */) | |
309 { | |
310 } | |
311 | |
312 void | |
313 tree_checker::visit_parameter_list (tree_parameter_list& lst) | |
314 { | |
315 Pix p = lst.first (); | |
316 | |
317 while (p) | |
318 { | |
319 tree_identifier *elt = lst (p); | |
320 | |
321 lst.next (p); | |
322 | |
323 if (elt) | |
324 elt->accept (*this); | |
325 } | |
326 } | |
327 | |
328 void | |
329 tree_checker::visit_plot_command (tree_plot_command& cmd) | |
330 { | |
331 plot_limits *range = cmd.limits (); | |
332 | |
333 if (range) | |
334 range->accept (*this); | |
335 | |
336 subplot_list *plot_list = cmd.subplots (); | |
337 | |
338 if (plot_list) | |
339 plot_list->accept (*this); | |
340 } | |
341 | |
342 void | |
343 tree_checker::visit_plot_limits (plot_limits& cmd) | |
344 { | |
345 plot_range *x_range = cmd.x_limits (); | |
346 | |
347 if (x_range) | |
348 x_range->accept (*this); | |
349 | |
350 plot_range *y_range = cmd.y_limits (); | |
351 | |
352 if (y_range) | |
353 y_range->accept (*this); | |
354 | |
355 plot_range *z_range = cmd.z_limits (); | |
356 | |
357 if (z_range) | |
358 z_range->accept (*this); | |
359 } | |
360 | |
361 void | |
362 tree_checker::visit_plot_range (plot_range& cmd) | |
363 { | |
364 tree_expression *lower = cmd.lower_bound (); | |
365 | |
366 if (lower) | |
367 lower->accept (*this); | |
368 | |
369 tree_expression *upper = cmd.upper_bound (); | |
370 | |
371 if (upper) | |
372 upper->accept (*this); | |
373 } | |
374 | |
375 void | |
376 tree_checker::visit_postfix_expression (tree_postfix_expression& expr) | |
377 { | |
378 tree_expression *e = expr.operand (); | |
379 | |
380 if (e) | |
381 e->accept (*this); | |
382 } | |
383 | |
384 void | |
385 tree_checker::visit_prefix_expression (tree_prefix_expression& expr) | |
386 { | |
387 tree_expression *e = expr.operand (); | |
388 | |
389 if (e) | |
390 e->accept (*this); | |
391 } | |
392 | |
393 void | |
394 tree_checker::visit_return_command (tree_return_command&) | |
395 { | |
396 } | |
397 | |
398 void | |
399 tree_checker::visit_return_list (tree_return_list& lst) | |
400 { | |
401 Pix p = lst.first (); | |
402 | |
403 while (p) | |
404 { | |
405 tree_index_expression *elt = lst (p); | |
406 | |
407 lst.next (p); | |
408 | |
409 if (elt) | |
410 elt->accept (*this); | |
411 } | |
412 } | |
413 | |
414 void | |
415 tree_checker::visit_simple_assignment (tree_simple_assignment& expr) | |
416 { | |
417 tree_expression *lhs = expr.left_hand_side (); | |
418 | |
419 if (lhs) | |
420 { | |
421 if (! lhs->lvalue_ok ()) | |
422 gripe ("invalid lvalue in assignment", expr.line ()); | |
423 } | |
424 | |
425 tree_expression *rhs = expr.right_hand_side (); | |
426 | |
427 if (rhs) | |
428 rhs->accept (*this); | |
429 } | |
430 | |
431 void | |
432 tree_checker::visit_statement (tree_statement& stmt) | |
433 { | |
434 tree_command *cmd = stmt.command (); | |
435 | |
436 if (cmd) | |
437 cmd->accept (*this); | |
438 else | |
439 { | |
440 tree_expression *expr = stmt.expression (); | |
441 | |
442 if (expr) | |
443 expr->accept (*this); | |
444 } | |
445 } | |
446 | |
447 void | |
448 tree_checker::visit_statement_list (tree_statement_list& lst) | |
449 { | |
450 for (Pix p = lst.first (); p != 0; lst.next (p)) | |
451 { | |
452 tree_statement *elt = lst (p); | |
453 | |
454 if (elt) | |
455 elt->accept (*this); | |
456 } | |
457 } | |
458 | |
459 void | |
460 tree_checker::visit_subplot (subplot& cmd) | |
461 { | |
462 tree_expression *sp_plot_data = cmd.plot_data (); | |
463 | |
464 if (sp_plot_data) | |
465 sp_plot_data->accept (*this); | |
466 | |
467 subplot_using *sp_using_clause = cmd.using_clause (); | |
468 | |
469 if (sp_using_clause) | |
470 sp_using_clause->accept (*this); | |
471 | |
472 tree_expression *sp_title_clause = cmd.title_clause (); | |
473 | |
474 if (sp_title_clause) | |
475 sp_title_clause->accept (*this); | |
476 | |
477 subplot_style *sp_style_clause = cmd.style_clause (); | |
478 | |
479 if (sp_style_clause) | |
480 sp_style_clause->accept (*this); | |
481 } | |
482 | |
483 void | |
484 tree_checker::visit_subplot_list (subplot_list& lst) | |
485 { | |
486 Pix p = lst.first (); | |
487 | |
488 while (p) | |
489 { | |
490 subplot *elt = lst (p); | |
491 | |
492 lst.next (p); | |
493 | |
494 if (elt) | |
495 elt->accept (*this); | |
496 } | |
497 } | |
498 | |
499 void | |
500 tree_checker::visit_subplot_style (subplot_style& cmd) | |
501 { | |
502 tree_expression *sp_linetype = cmd.linetype (); | |
503 | |
504 if (sp_linetype) | |
505 sp_linetype->accept (*this); | |
506 | |
507 tree_expression *sp_pointtype = cmd.pointtype (); | |
508 | |
509 if (sp_pointtype) | |
510 sp_pointtype->accept (*this); | |
511 } | |
512 | |
513 void | |
514 tree_checker::visit_subplot_using (subplot_using& cmd) | |
515 { | |
516 int qual_count = cmd.qualifier_count (); | |
517 | |
518 if (qual_count > 0) | |
519 { | |
520 tree_expression **x = cmd.qualifiers (); | |
521 | |
522 for (int i = 0; i < qual_count; i++) | |
523 { | |
524 if (x[i]) | |
525 x[i]->accept (*this); | |
526 } | |
527 } | |
528 else | |
529 { | |
530 tree_expression *scanf_fmt = cmd.scanf_format (); | |
531 | |
532 if (scanf_fmt) | |
533 scanf_fmt->accept (*this); | |
534 } | |
535 } | |
536 | |
537 void | |
538 tree_checker::visit_switch_case (tree_switch_case& cs) | |
539 { | |
540 tree_expression *label = cs.case_label (); | |
541 | |
542 if (label) | |
543 label->accept (*this); | |
544 | |
545 tree_statement_list *list = cs.commands (); | |
546 | |
547 if (list) | |
548 list->accept (*this); | |
549 } | |
550 | |
551 void | |
552 tree_checker::visit_switch_case_list (tree_switch_case_list& lst) | |
553 { | |
554 Pix p = lst.first (); | |
555 | |
556 while (p) | |
557 { | |
558 tree_switch_case *elt = lst (p); | |
559 | |
560 if (elt) | |
561 elt->accept (*this); | |
562 | |
563 lst.next (p); | |
564 } | |
565 } | |
566 | |
567 void | |
568 tree_checker::visit_switch_command (tree_switch_command& cmd) | |
569 { | |
570 tree_expression *expr = cmd.switch_value (); | |
571 | |
572 if (expr) | |
573 expr->accept (*this); | |
574 | |
575 tree_switch_case_list *list = cmd.case_list (); | |
576 | |
577 if (list) | |
578 list->accept (*this); | |
579 } | |
580 | |
581 void | |
582 tree_checker::visit_try_catch_command (tree_try_catch_command& cmd) | |
583 { | |
584 tree_statement_list *try_code = cmd.body (); | |
585 | |
586 if (try_code) | |
587 try_code->accept (*this); | |
588 | |
589 tree_statement_list *catch_code = cmd.cleanup (); | |
590 | |
591 if (catch_code) | |
592 catch_code->accept (*this); | |
593 } | |
594 | |
595 void | |
596 tree_checker::visit_unwind_protect_command | |
597 (tree_unwind_protect_command& cmd) | |
598 { | |
599 tree_statement_list *unwind_protect_code = cmd.body (); | |
600 | |
601 if (unwind_protect_code) | |
602 unwind_protect_code->accept (*this); | |
603 | |
604 tree_statement_list *cleanup_code = cmd.cleanup (); | |
605 | |
606 if (cleanup_code) | |
607 cleanup_code->accept (*this); | |
608 } | |
609 | |
610 void | |
611 tree_checker::visit_while_command (tree_while_command& cmd) | |
612 { | |
613 tree_expression *expr = cmd.condition (); | |
614 | |
615 if (expr) | |
616 expr->accept (*this); | |
617 | |
618 tree_statement_list *list = cmd.body (); | |
619 | |
620 if (list) | |
621 list->accept (*this); | |
622 } | |
623 | |
624 void | |
625 tree_checker::gripe (const string& msg, int line) | |
626 { | |
627 if (curr_fcn_file_name.empty ()) | |
628 error ("%s", msg.c_str ()); | |
629 else | |
630 error ("%s: %d: %s", curr_fcn_file_name.c_str (), line, msg.c_str ()); | |
631 } | |
632 | |
633 /* | |
634 ;;; Local Variables: *** | |
635 ;;; mode: C++ *** | |
636 ;;; End: *** | |
637 */ |