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 |
|
23 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
|
27 #include "error.h" |
|
28 #include "input.h" |
|
29 #include "ov-usr-fcn.h" |
|
30 #include "pt-all.h" |
|
31 |
|
32 void |
|
33 tree_checker::visit_argument_list (tree_argument_list& lst) |
|
34 { |
4219
|
35 tree_argument_list::iterator p = lst.begin (); |
3011
|
36 |
4219
|
37 while (p != lst.end ()) |
3011
|
38 { |
4219
|
39 tree_expression *elt = *p++; |
3011
|
40 |
|
41 if (elt) |
|
42 { |
|
43 if (do_lvalue_check && ! elt->lvalue_ok ()) |
|
44 gripe ("invalid lvalue in multiple assignment", elt->line ()); |
|
45 } |
|
46 } |
|
47 } |
|
48 |
|
49 void |
|
50 tree_checker::visit_binary_expression (tree_binary_expression& expr) |
|
51 { |
|
52 tree_expression *op1 = expr.lhs (); |
|
53 |
|
54 if (op1) |
|
55 op1->accept (*this); |
|
56 |
|
57 tree_expression *op2 = expr.rhs (); |
|
58 |
|
59 if (op2) |
|
60 op2->accept (*this); |
|
61 } |
|
62 |
|
63 void |
4207
|
64 tree_checker::visit_break_command (tree_break_command&) |
3011
|
65 { |
|
66 } |
|
67 |
|
68 void |
|
69 tree_checker::visit_colon_expression (tree_colon_expression& expr) |
|
70 { |
|
71 tree_expression *op1 = expr.base (); |
|
72 |
|
73 if (op1) |
|
74 op1->accept (*this); |
|
75 |
|
76 tree_expression *op3 = expr.increment (); |
|
77 |
|
78 if (op3) |
|
79 op3->accept (*this); |
|
80 |
|
81 tree_expression *op2 = expr.limit (); |
|
82 |
|
83 if (op2) |
|
84 op2->accept (*this); |
|
85 } |
|
86 |
|
87 void |
4207
|
88 tree_checker::visit_continue_command (tree_continue_command&) |
3011
|
89 { |
|
90 } |
|
91 |
|
92 void |
|
93 tree_checker::visit_decl_command (tree_decl_command& cmd) |
|
94 { |
|
95 tree_decl_init_list *init_list = cmd.initializer_list (); |
|
96 |
|
97 if (init_list) |
|
98 init_list->accept (*this); |
|
99 } |
|
100 |
|
101 void |
|
102 tree_checker::visit_decl_elt (tree_decl_elt& cmd) |
|
103 { |
|
104 tree_identifier *id = cmd.ident (); |
|
105 |
|
106 if (id) |
|
107 id->accept (*this); |
|
108 |
|
109 tree_expression *expr = cmd.expression (); |
|
110 |
|
111 if (expr) |
|
112 expr->accept (*this); |
|
113 } |
|
114 |
|
115 void |
|
116 tree_checker::visit_decl_init_list (tree_decl_init_list& lst) |
|
117 { |
4219
|
118 tree_decl_init_list::iterator p = lst.begin (); |
3011
|
119 |
4219
|
120 while (p != lst.end ()) |
3011
|
121 { |
4219
|
122 tree_decl_elt *elt = *p++; |
3011
|
123 |
|
124 if (elt) |
|
125 elt->accept (*this); |
|
126 } |
|
127 } |
|
128 |
|
129 void |
|
130 tree_checker::visit_simple_for_command (tree_simple_for_command& cmd) |
|
131 { |
|
132 tree_expression *lhs = cmd.left_hand_side (); |
|
133 |
|
134 if (lhs) |
|
135 { |
|
136 if (! lhs->lvalue_ok ()) |
|
137 gripe ("invalid lvalue in for command", cmd.line ()); |
|
138 } |
|
139 |
|
140 tree_expression *expr = cmd.control_expr (); |
|
141 |
|
142 if (expr) |
|
143 expr->accept (*this); |
|
144 |
|
145 tree_statement_list *list = cmd.body (); |
|
146 |
|
147 if (list) |
|
148 list->accept (*this); |
|
149 } |
|
150 |
|
151 void |
|
152 tree_checker::visit_complex_for_command (tree_complex_for_command& cmd) |
|
153 { |
|
154 tree_argument_list *lhs = cmd.left_hand_side (); |
|
155 |
|
156 if (lhs) |
|
157 { |
|
158 int len = lhs->length (); |
|
159 |
3018
|
160 if (len == 0 || len > 2) |
3011
|
161 gripe ("invalid number of output arguments in for command", |
|
162 cmd.line ()); |
|
163 |
|
164 do_lvalue_check = true; |
|
165 |
|
166 lhs->accept (*this); |
|
167 |
|
168 do_lvalue_check = false; |
|
169 } |
|
170 |
|
171 tree_expression *expr = cmd.control_expr (); |
|
172 |
|
173 if (expr) |
|
174 expr->accept (*this); |
|
175 |
|
176 tree_statement_list *list = cmd.body (); |
|
177 |
|
178 if (list) |
|
179 list->accept (*this); |
|
180 } |
|
181 |
|
182 void |
|
183 tree_checker::visit_octave_user_function (octave_user_function& fcn) |
|
184 { |
|
185 tree_statement_list *cmd_list = fcn.body (); |
|
186 |
|
187 if (cmd_list) |
|
188 cmd_list->accept (*this); |
|
189 } |
|
190 |
|
191 void |
|
192 tree_checker::visit_identifier (tree_identifier& /* id */) |
|
193 { |
|
194 } |
|
195 |
|
196 void |
|
197 tree_checker::visit_if_clause (tree_if_clause& cmd) |
|
198 { |
|
199 tree_expression *expr = cmd.condition (); |
|
200 |
|
201 if (expr) |
|
202 expr->accept (*this); |
|
203 |
|
204 tree_statement_list *list = cmd.commands (); |
|
205 |
|
206 if (list) |
|
207 list->accept (*this); |
|
208 } |
|
209 |
|
210 void |
|
211 tree_checker::visit_if_command (tree_if_command& cmd) |
|
212 { |
|
213 tree_if_command_list *list = cmd.cmd_list (); |
|
214 |
|
215 if (list) |
|
216 list->accept (*this); |
|
217 } |
|
218 |
|
219 void |
|
220 tree_checker::visit_if_command_list (tree_if_command_list& lst) |
|
221 { |
4219
|
222 tree_if_command_list::iterator p = lst.begin (); |
3011
|
223 |
4219
|
224 while (p != lst.end ()) |
3011
|
225 { |
4219
|
226 tree_if_clause *elt = *p++; |
3011
|
227 |
|
228 if (elt) |
|
229 elt->accept (*this); |
|
230 } |
|
231 } |
|
232 |
|
233 void |
|
234 tree_checker::visit_index_expression (tree_index_expression& expr) |
|
235 { |
|
236 tree_expression *e = expr.expression (); |
|
237 |
|
238 if (e) |
|
239 e->accept (*this); |
|
240 |
4219
|
241 std::list<tree_argument_list *> lst = expr.arg_lists (); |
3933
|
242 |
4219
|
243 std::list<tree_argument_list *>::iterator p = lst.begin (); |
3011
|
244 |
4219
|
245 while (p != lst.end ()) |
3933
|
246 { |
4219
|
247 tree_argument_list *elt = *p++; |
3933
|
248 |
|
249 if (elt) |
|
250 elt->accept (*this); |
|
251 } |
3011
|
252 } |
|
253 |
|
254 void |
|
255 tree_checker::visit_matrix (tree_matrix& lst) |
|
256 { |
4219
|
257 tree_matrix::iterator p = lst.begin (); |
3011
|
258 |
4219
|
259 while (p != lst.end ()) |
3011
|
260 { |
4219
|
261 tree_argument_list *elt = *p++; |
|
262 |
|
263 if (elt) |
|
264 elt->accept (*this); |
|
265 } |
|
266 } |
3011
|
267 |
4219
|
268 void |
|
269 tree_checker::visit_cell (tree_cell& lst) |
|
270 { |
|
271 tree_matrix::iterator p = lst.begin (); |
|
272 |
|
273 while (p != lst.end ()) |
|
274 { |
|
275 tree_argument_list *elt = *p++; |
3011
|
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 |
4342
|
313 tree_checker::visit_fcn_handle (tree_fcn_handle& /* fh */) |
|
314 { |
|
315 } |
|
316 |
|
317 void |
3011
|
318 tree_checker::visit_parameter_list (tree_parameter_list& lst) |
|
319 { |
4219
|
320 tree_parameter_list::iterator p = lst.begin (); |
3011
|
321 |
4219
|
322 while (p != lst.end ()) |
3011
|
323 { |
4219
|
324 tree_identifier *elt = *p++; |
3011
|
325 |
|
326 if (elt) |
|
327 elt->accept (*this); |
|
328 } |
|
329 } |
|
330 |
|
331 void |
|
332 tree_checker::visit_postfix_expression (tree_postfix_expression& expr) |
|
333 { |
|
334 tree_expression *e = expr.operand (); |
|
335 |
|
336 if (e) |
|
337 e->accept (*this); |
|
338 } |
|
339 |
|
340 void |
|
341 tree_checker::visit_prefix_expression (tree_prefix_expression& expr) |
|
342 { |
|
343 tree_expression *e = expr.operand (); |
|
344 |
|
345 if (e) |
|
346 e->accept (*this); |
|
347 } |
|
348 |
|
349 void |
4207
|
350 tree_checker::visit_return_command (tree_return_command&) |
3011
|
351 { |
|
352 } |
|
353 |
|
354 void |
|
355 tree_checker::visit_return_list (tree_return_list& lst) |
|
356 { |
4219
|
357 tree_return_list::iterator p = lst.begin (); |
3011
|
358 |
4219
|
359 while (p != lst.end ()) |
3011
|
360 { |
4219
|
361 tree_index_expression *elt = *p++; |
3011
|
362 |
|
363 if (elt) |
|
364 elt->accept (*this); |
|
365 } |
|
366 } |
|
367 |
|
368 void |
|
369 tree_checker::visit_simple_assignment (tree_simple_assignment& expr) |
|
370 { |
|
371 tree_expression *lhs = expr.left_hand_side (); |
|
372 |
|
373 if (lhs) |
|
374 { |
|
375 if (! lhs->lvalue_ok ()) |
|
376 gripe ("invalid lvalue in assignment", expr.line ()); |
|
377 } |
|
378 |
|
379 tree_expression *rhs = expr.right_hand_side (); |
|
380 |
|
381 if (rhs) |
|
382 rhs->accept (*this); |
|
383 } |
|
384 |
|
385 void |
|
386 tree_checker::visit_statement (tree_statement& stmt) |
|
387 { |
|
388 tree_command *cmd = stmt.command (); |
|
389 |
|
390 if (cmd) |
|
391 cmd->accept (*this); |
|
392 else |
|
393 { |
|
394 tree_expression *expr = stmt.expression (); |
|
395 |
|
396 if (expr) |
|
397 expr->accept (*this); |
|
398 } |
|
399 } |
|
400 |
|
401 void |
|
402 tree_checker::visit_statement_list (tree_statement_list& lst) |
|
403 { |
4219
|
404 for (tree_statement_list::iterator p = lst.begin (); p != lst.end (); p++) |
3011
|
405 { |
4219
|
406 tree_statement *elt = *p; |
3011
|
407 |
|
408 if (elt) |
|
409 elt->accept (*this); |
|
410 } |
|
411 } |
|
412 |
|
413 void |
|
414 tree_checker::visit_switch_case (tree_switch_case& cs) |
|
415 { |
|
416 tree_expression *label = cs.case_label (); |
|
417 |
|
418 if (label) |
|
419 label->accept (*this); |
|
420 |
|
421 tree_statement_list *list = cs.commands (); |
|
422 |
|
423 if (list) |
|
424 list->accept (*this); |
|
425 } |
|
426 |
|
427 void |
|
428 tree_checker::visit_switch_case_list (tree_switch_case_list& lst) |
|
429 { |
4219
|
430 tree_switch_case_list::iterator p = lst.begin (); |
3011
|
431 |
4219
|
432 while (p != lst.end ()) |
3011
|
433 { |
4219
|
434 tree_switch_case *elt = *p++; |
3011
|
435 |
|
436 if (elt) |
|
437 elt->accept (*this); |
|
438 } |
|
439 } |
|
440 |
|
441 void |
|
442 tree_checker::visit_switch_command (tree_switch_command& cmd) |
|
443 { |
|
444 tree_expression *expr = cmd.switch_value (); |
|
445 |
|
446 if (expr) |
|
447 expr->accept (*this); |
|
448 |
|
449 tree_switch_case_list *list = cmd.case_list (); |
|
450 |
|
451 if (list) |
|
452 list->accept (*this); |
|
453 } |
|
454 |
|
455 void |
|
456 tree_checker::visit_try_catch_command (tree_try_catch_command& cmd) |
|
457 { |
|
458 tree_statement_list *try_code = cmd.body (); |
|
459 |
|
460 if (try_code) |
|
461 try_code->accept (*this); |
|
462 |
|
463 tree_statement_list *catch_code = cmd.cleanup (); |
|
464 |
|
465 if (catch_code) |
|
466 catch_code->accept (*this); |
|
467 } |
|
468 |
|
469 void |
|
470 tree_checker::visit_unwind_protect_command |
|
471 (tree_unwind_protect_command& cmd) |
|
472 { |
|
473 tree_statement_list *unwind_protect_code = cmd.body (); |
|
474 |
|
475 if (unwind_protect_code) |
|
476 unwind_protect_code->accept (*this); |
|
477 |
|
478 tree_statement_list *cleanup_code = cmd.cleanup (); |
|
479 |
|
480 if (cleanup_code) |
|
481 cleanup_code->accept (*this); |
|
482 } |
|
483 |
|
484 void |
|
485 tree_checker::visit_while_command (tree_while_command& cmd) |
|
486 { |
|
487 tree_expression *expr = cmd.condition (); |
|
488 |
|
489 if (expr) |
|
490 expr->accept (*this); |
|
491 |
|
492 tree_statement_list *list = cmd.body (); |
|
493 |
|
494 if (list) |
|
495 list->accept (*this); |
|
496 } |
|
497 |
|
498 void |
4229
|
499 tree_checker::visit_do_until_command (tree_do_until_command& cmd) |
|
500 { |
|
501 tree_statement_list *list = cmd.body (); |
|
502 |
|
503 if (list) |
|
504 list->accept (*this); |
|
505 |
|
506 tree_expression *expr = cmd.condition (); |
|
507 |
|
508 if (expr) |
|
509 expr->accept (*this); |
|
510 } |
|
511 |
|
512 void |
3523
|
513 tree_checker::gripe (const std::string& msg, int line) |
3011
|
514 { |
|
515 if (curr_fcn_file_name.empty ()) |
|
516 error ("%s", msg.c_str ()); |
|
517 else |
|
518 error ("%s: %d: %s", curr_fcn_file_name.c_str (), line, msg.c_str ()); |
|
519 } |
|
520 |
|
521 /* |
|
522 ;;; Local Variables: *** |
|
523 ;;; mode: C++ *** |
|
524 ;;; End: *** |
|
525 */ |