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