3011
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1996, 1997, 2000, 2002, 2003, 2004, 2005, 2006, 2007 |
|
4 John W. Eaton |
3011
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
7016
|
10 Free Software Foundation; either version 3 of the License, or (at your |
|
11 option) any later version. |
3011
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
7016
|
19 along with Octave; see the file COPYING. If not, see |
|
20 <http://www.gnu.org/licenses/>. |
3011
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
|
28 #include "error.h" |
|
29 #include "input.h" |
|
30 #include "ov-usr-fcn.h" |
|
31 #include "pt-all.h" |
|
32 |
|
33 void |
|
34 tree_checker::visit_argument_list (tree_argument_list& lst) |
|
35 { |
4219
|
36 tree_argument_list::iterator p = lst.begin (); |
3011
|
37 |
4219
|
38 while (p != lst.end ()) |
3011
|
39 { |
4219
|
40 tree_expression *elt = *p++; |
3011
|
41 |
|
42 if (elt) |
|
43 { |
|
44 if (do_lvalue_check && ! elt->lvalue_ok ()) |
|
45 gripe ("invalid lvalue in multiple assignment", elt->line ()); |
|
46 } |
|
47 } |
|
48 } |
|
49 |
|
50 void |
|
51 tree_checker::visit_binary_expression (tree_binary_expression& expr) |
|
52 { |
|
53 tree_expression *op1 = expr.lhs (); |
|
54 |
|
55 if (op1) |
|
56 op1->accept (*this); |
|
57 |
|
58 tree_expression *op2 = expr.rhs (); |
|
59 |
|
60 if (op2) |
|
61 op2->accept (*this); |
|
62 } |
|
63 |
|
64 void |
4207
|
65 tree_checker::visit_break_command (tree_break_command&) |
3011
|
66 { |
|
67 } |
|
68 |
|
69 void |
|
70 tree_checker::visit_colon_expression (tree_colon_expression& expr) |
|
71 { |
|
72 tree_expression *op1 = expr.base (); |
|
73 |
|
74 if (op1) |
|
75 op1->accept (*this); |
|
76 |
|
77 tree_expression *op3 = expr.increment (); |
|
78 |
|
79 if (op3) |
|
80 op3->accept (*this); |
|
81 |
|
82 tree_expression *op2 = expr.limit (); |
|
83 |
|
84 if (op2) |
|
85 op2->accept (*this); |
|
86 } |
|
87 |
|
88 void |
4207
|
89 tree_checker::visit_continue_command (tree_continue_command&) |
3011
|
90 { |
|
91 } |
|
92 |
|
93 void |
|
94 tree_checker::visit_decl_command (tree_decl_command& cmd) |
|
95 { |
|
96 tree_decl_init_list *init_list = cmd.initializer_list (); |
|
97 |
|
98 if (init_list) |
|
99 init_list->accept (*this); |
|
100 } |
|
101 |
|
102 void |
|
103 tree_checker::visit_decl_elt (tree_decl_elt& cmd) |
|
104 { |
|
105 tree_identifier *id = cmd.ident (); |
|
106 |
|
107 if (id) |
|
108 id->accept (*this); |
|
109 |
|
110 tree_expression *expr = cmd.expression (); |
|
111 |
|
112 if (expr) |
|
113 expr->accept (*this); |
|
114 } |
|
115 |
|
116 void |
|
117 tree_checker::visit_decl_init_list (tree_decl_init_list& lst) |
|
118 { |
4219
|
119 tree_decl_init_list::iterator p = lst.begin (); |
3011
|
120 |
4219
|
121 while (p != lst.end ()) |
3011
|
122 { |
4219
|
123 tree_decl_elt *elt = *p++; |
3011
|
124 |
|
125 if (elt) |
|
126 elt->accept (*this); |
|
127 } |
|
128 } |
|
129 |
|
130 void |
|
131 tree_checker::visit_simple_for_command (tree_simple_for_command& cmd) |
|
132 { |
|
133 tree_expression *lhs = cmd.left_hand_side (); |
|
134 |
|
135 if (lhs) |
|
136 { |
|
137 if (! lhs->lvalue_ok ()) |
|
138 gripe ("invalid lvalue in for command", cmd.line ()); |
|
139 } |
|
140 |
|
141 tree_expression *expr = cmd.control_expr (); |
|
142 |
|
143 if (expr) |
|
144 expr->accept (*this); |
|
145 |
|
146 tree_statement_list *list = cmd.body (); |
|
147 |
|
148 if (list) |
|
149 list->accept (*this); |
|
150 } |
|
151 |
|
152 void |
|
153 tree_checker::visit_complex_for_command (tree_complex_for_command& cmd) |
|
154 { |
|
155 tree_argument_list *lhs = cmd.left_hand_side (); |
|
156 |
|
157 if (lhs) |
|
158 { |
|
159 int len = lhs->length (); |
|
160 |
3018
|
161 if (len == 0 || len > 2) |
3011
|
162 gripe ("invalid number of output arguments in for command", |
|
163 cmd.line ()); |
|
164 |
|
165 do_lvalue_check = true; |
|
166 |
|
167 lhs->accept (*this); |
|
168 |
|
169 do_lvalue_check = false; |
|
170 } |
|
171 |
|
172 tree_expression *expr = cmd.control_expr (); |
|
173 |
|
174 if (expr) |
|
175 expr->accept (*this); |
|
176 |
|
177 tree_statement_list *list = cmd.body (); |
|
178 |
|
179 if (list) |
|
180 list->accept (*this); |
|
181 } |
|
182 |
|
183 void |
|
184 tree_checker::visit_octave_user_function (octave_user_function& fcn) |
|
185 { |
|
186 tree_statement_list *cmd_list = fcn.body (); |
|
187 |
|
188 if (cmd_list) |
|
189 cmd_list->accept (*this); |
|
190 } |
|
191 |
|
192 void |
|
193 tree_checker::visit_identifier (tree_identifier& /* id */) |
|
194 { |
|
195 } |
|
196 |
|
197 void |
|
198 tree_checker::visit_if_clause (tree_if_clause& cmd) |
|
199 { |
|
200 tree_expression *expr = cmd.condition (); |
|
201 |
|
202 if (expr) |
|
203 expr->accept (*this); |
|
204 |
|
205 tree_statement_list *list = cmd.commands (); |
|
206 |
|
207 if (list) |
|
208 list->accept (*this); |
|
209 } |
|
210 |
|
211 void |
|
212 tree_checker::visit_if_command (tree_if_command& cmd) |
|
213 { |
|
214 tree_if_command_list *list = cmd.cmd_list (); |
|
215 |
|
216 if (list) |
|
217 list->accept (*this); |
|
218 } |
|
219 |
|
220 void |
|
221 tree_checker::visit_if_command_list (tree_if_command_list& lst) |
|
222 { |
4219
|
223 tree_if_command_list::iterator p = lst.begin (); |
3011
|
224 |
4219
|
225 while (p != lst.end ()) |
3011
|
226 { |
4219
|
227 tree_if_clause *elt = *p++; |
3011
|
228 |
|
229 if (elt) |
|
230 elt->accept (*this); |
|
231 } |
|
232 } |
|
233 |
|
234 void |
|
235 tree_checker::visit_index_expression (tree_index_expression& expr) |
|
236 { |
|
237 tree_expression *e = expr.expression (); |
|
238 |
|
239 if (e) |
|
240 e->accept (*this); |
|
241 |
4219
|
242 std::list<tree_argument_list *> lst = expr.arg_lists (); |
3933
|
243 |
4219
|
244 std::list<tree_argument_list *>::iterator p = lst.begin (); |
3011
|
245 |
4219
|
246 while (p != lst.end ()) |
3933
|
247 { |
4219
|
248 tree_argument_list *elt = *p++; |
3933
|
249 |
|
250 if (elt) |
|
251 elt->accept (*this); |
|
252 } |
3011
|
253 } |
|
254 |
|
255 void |
|
256 tree_checker::visit_matrix (tree_matrix& lst) |
|
257 { |
4219
|
258 tree_matrix::iterator p = lst.begin (); |
3011
|
259 |
4219
|
260 while (p != lst.end ()) |
3011
|
261 { |
4219
|
262 tree_argument_list *elt = *p++; |
|
263 |
|
264 if (elt) |
|
265 elt->accept (*this); |
|
266 } |
|
267 } |
3011
|
268 |
4219
|
269 void |
|
270 tree_checker::visit_cell (tree_cell& lst) |
|
271 { |
|
272 tree_matrix::iterator p = lst.begin (); |
|
273 |
|
274 while (p != lst.end ()) |
|
275 { |
|
276 tree_argument_list *elt = *p++; |
3011
|
277 |
|
278 if (elt) |
|
279 elt->accept (*this); |
|
280 } |
|
281 } |
|
282 |
|
283 void |
|
284 tree_checker::visit_multi_assignment (tree_multi_assignment& expr) |
|
285 { |
|
286 tree_argument_list *lhs = expr.left_hand_side (); |
|
287 |
|
288 if (lhs) |
|
289 { |
|
290 do_lvalue_check = true; |
|
291 |
|
292 lhs->accept (*this); |
|
293 |
|
294 do_lvalue_check = false; |
|
295 } |
|
296 |
|
297 tree_expression *rhs = expr.right_hand_side (); |
|
298 |
|
299 if (rhs) |
|
300 rhs->accept (*this); |
|
301 } |
|
302 |
|
303 void |
|
304 tree_checker::visit_no_op_command (tree_no_op_command& /* cmd */) |
|
305 { |
|
306 } |
|
307 |
|
308 void |
5861
|
309 tree_checker::visit_anon_fcn_handle (tree_anon_fcn_handle& /* afh */) |
|
310 { |
|
311 } |
|
312 |
|
313 void |
3011
|
314 tree_checker::visit_constant (tree_constant& /* val */) |
|
315 { |
|
316 } |
|
317 |
|
318 void |
4342
|
319 tree_checker::visit_fcn_handle (tree_fcn_handle& /* fh */) |
|
320 { |
|
321 } |
|
322 |
|
323 void |
3011
|
324 tree_checker::visit_parameter_list (tree_parameter_list& lst) |
|
325 { |
4219
|
326 tree_parameter_list::iterator p = lst.begin (); |
3011
|
327 |
4219
|
328 while (p != lst.end ()) |
3011
|
329 { |
6215
|
330 tree_decl_elt *elt = *p++; |
3011
|
331 |
|
332 if (elt) |
|
333 elt->accept (*this); |
|
334 } |
|
335 } |
|
336 |
|
337 void |
|
338 tree_checker::visit_postfix_expression (tree_postfix_expression& expr) |
|
339 { |
|
340 tree_expression *e = expr.operand (); |
|
341 |
|
342 if (e) |
|
343 e->accept (*this); |
|
344 } |
|
345 |
|
346 void |
|
347 tree_checker::visit_prefix_expression (tree_prefix_expression& expr) |
|
348 { |
|
349 tree_expression *e = expr.operand (); |
|
350 |
|
351 if (e) |
|
352 e->accept (*this); |
|
353 } |
|
354 |
|
355 void |
4207
|
356 tree_checker::visit_return_command (tree_return_command&) |
3011
|
357 { |
|
358 } |
|
359 |
|
360 void |
|
361 tree_checker::visit_return_list (tree_return_list& lst) |
|
362 { |
4219
|
363 tree_return_list::iterator p = lst.begin (); |
3011
|
364 |
4219
|
365 while (p != lst.end ()) |
3011
|
366 { |
4219
|
367 tree_index_expression *elt = *p++; |
3011
|
368 |
|
369 if (elt) |
|
370 elt->accept (*this); |
|
371 } |
|
372 } |
|
373 |
|
374 void |
|
375 tree_checker::visit_simple_assignment (tree_simple_assignment& expr) |
|
376 { |
|
377 tree_expression *lhs = expr.left_hand_side (); |
|
378 |
|
379 if (lhs) |
|
380 { |
|
381 if (! lhs->lvalue_ok ()) |
|
382 gripe ("invalid lvalue in assignment", expr.line ()); |
|
383 } |
|
384 |
|
385 tree_expression *rhs = expr.right_hand_side (); |
|
386 |
|
387 if (rhs) |
|
388 rhs->accept (*this); |
|
389 } |
|
390 |
|
391 void |
|
392 tree_checker::visit_statement (tree_statement& stmt) |
|
393 { |
|
394 tree_command *cmd = stmt.command (); |
|
395 |
|
396 if (cmd) |
|
397 cmd->accept (*this); |
|
398 else |
|
399 { |
|
400 tree_expression *expr = stmt.expression (); |
|
401 |
|
402 if (expr) |
|
403 expr->accept (*this); |
|
404 } |
|
405 } |
|
406 |
|
407 void |
|
408 tree_checker::visit_statement_list (tree_statement_list& lst) |
|
409 { |
4219
|
410 for (tree_statement_list::iterator p = lst.begin (); p != lst.end (); p++) |
3011
|
411 { |
4219
|
412 tree_statement *elt = *p; |
3011
|
413 |
|
414 if (elt) |
|
415 elt->accept (*this); |
|
416 } |
|
417 } |
|
418 |
|
419 void |
|
420 tree_checker::visit_switch_case (tree_switch_case& cs) |
|
421 { |
|
422 tree_expression *label = cs.case_label (); |
|
423 |
|
424 if (label) |
|
425 label->accept (*this); |
|
426 |
|
427 tree_statement_list *list = cs.commands (); |
|
428 |
|
429 if (list) |
|
430 list->accept (*this); |
|
431 } |
|
432 |
|
433 void |
|
434 tree_checker::visit_switch_case_list (tree_switch_case_list& lst) |
|
435 { |
4219
|
436 tree_switch_case_list::iterator p = lst.begin (); |
3011
|
437 |
4219
|
438 while (p != lst.end ()) |
3011
|
439 { |
4219
|
440 tree_switch_case *elt = *p++; |
3011
|
441 |
|
442 if (elt) |
|
443 elt->accept (*this); |
|
444 } |
|
445 } |
|
446 |
|
447 void |
|
448 tree_checker::visit_switch_command (tree_switch_command& cmd) |
|
449 { |
|
450 tree_expression *expr = cmd.switch_value (); |
|
451 |
|
452 if (expr) |
|
453 expr->accept (*this); |
|
454 |
|
455 tree_switch_case_list *list = cmd.case_list (); |
|
456 |
|
457 if (list) |
|
458 list->accept (*this); |
|
459 } |
|
460 |
|
461 void |
|
462 tree_checker::visit_try_catch_command (tree_try_catch_command& cmd) |
|
463 { |
|
464 tree_statement_list *try_code = cmd.body (); |
|
465 |
|
466 if (try_code) |
|
467 try_code->accept (*this); |
|
468 |
|
469 tree_statement_list *catch_code = cmd.cleanup (); |
|
470 |
|
471 if (catch_code) |
|
472 catch_code->accept (*this); |
|
473 } |
|
474 |
|
475 void |
|
476 tree_checker::visit_unwind_protect_command |
|
477 (tree_unwind_protect_command& cmd) |
|
478 { |
|
479 tree_statement_list *unwind_protect_code = cmd.body (); |
|
480 |
|
481 if (unwind_protect_code) |
|
482 unwind_protect_code->accept (*this); |
|
483 |
|
484 tree_statement_list *cleanup_code = cmd.cleanup (); |
|
485 |
|
486 if (cleanup_code) |
|
487 cleanup_code->accept (*this); |
|
488 } |
|
489 |
|
490 void |
|
491 tree_checker::visit_while_command (tree_while_command& cmd) |
|
492 { |
|
493 tree_expression *expr = cmd.condition (); |
|
494 |
|
495 if (expr) |
|
496 expr->accept (*this); |
|
497 |
|
498 tree_statement_list *list = cmd.body (); |
|
499 |
|
500 if (list) |
|
501 list->accept (*this); |
|
502 } |
|
503 |
|
504 void |
4229
|
505 tree_checker::visit_do_until_command (tree_do_until_command& cmd) |
|
506 { |
|
507 tree_statement_list *list = cmd.body (); |
|
508 |
|
509 if (list) |
|
510 list->accept (*this); |
|
511 |
|
512 tree_expression *expr = cmd.condition (); |
|
513 |
|
514 if (expr) |
|
515 expr->accept (*this); |
|
516 } |
|
517 |
|
518 void |
3523
|
519 tree_checker::gripe (const std::string& msg, int line) |
3011
|
520 { |
|
521 if (curr_fcn_file_name.empty ()) |
|
522 error ("%s", msg.c_str ()); |
|
523 else |
|
524 error ("%s: %d: %s", curr_fcn_file_name.c_str (), line, msg.c_str ()); |
|
525 } |
|
526 |
|
527 /* |
|
528 ;;; Local Variables: *** |
|
529 ;;; mode: C++ *** |
|
530 ;;; End: *** |
|
531 */ |