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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
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 |
|
309 tree_checker::visit_constant (tree_constant& /* val */) |
|
310 { |
|
311 } |
|
312 |
|
313 void |
4342
|
314 tree_checker::visit_fcn_handle (tree_fcn_handle& /* fh */) |
|
315 { |
|
316 } |
|
317 |
|
318 void |
3011
|
319 tree_checker::visit_parameter_list (tree_parameter_list& lst) |
|
320 { |
4219
|
321 tree_parameter_list::iterator p = lst.begin (); |
3011
|
322 |
4219
|
323 while (p != lst.end ()) |
3011
|
324 { |
4219
|
325 tree_identifier *elt = *p++; |
3011
|
326 |
|
327 if (elt) |
|
328 elt->accept (*this); |
|
329 } |
|
330 } |
|
331 |
|
332 void |
|
333 tree_checker::visit_postfix_expression (tree_postfix_expression& expr) |
|
334 { |
|
335 tree_expression *e = expr.operand (); |
|
336 |
|
337 if (e) |
|
338 e->accept (*this); |
|
339 } |
|
340 |
|
341 void |
|
342 tree_checker::visit_prefix_expression (tree_prefix_expression& expr) |
|
343 { |
|
344 tree_expression *e = expr.operand (); |
|
345 |
|
346 if (e) |
|
347 e->accept (*this); |
|
348 } |
|
349 |
|
350 void |
4207
|
351 tree_checker::visit_return_command (tree_return_command&) |
3011
|
352 { |
|
353 } |
|
354 |
|
355 void |
|
356 tree_checker::visit_return_list (tree_return_list& lst) |
|
357 { |
4219
|
358 tree_return_list::iterator p = lst.begin (); |
3011
|
359 |
4219
|
360 while (p != lst.end ()) |
3011
|
361 { |
4219
|
362 tree_index_expression *elt = *p++; |
3011
|
363 |
|
364 if (elt) |
|
365 elt->accept (*this); |
|
366 } |
|
367 } |
|
368 |
|
369 void |
|
370 tree_checker::visit_simple_assignment (tree_simple_assignment& expr) |
|
371 { |
|
372 tree_expression *lhs = expr.left_hand_side (); |
|
373 |
|
374 if (lhs) |
|
375 { |
|
376 if (! lhs->lvalue_ok ()) |
|
377 gripe ("invalid lvalue in assignment", expr.line ()); |
|
378 } |
|
379 |
|
380 tree_expression *rhs = expr.right_hand_side (); |
|
381 |
|
382 if (rhs) |
|
383 rhs->accept (*this); |
|
384 } |
|
385 |
|
386 void |
|
387 tree_checker::visit_statement (tree_statement& stmt) |
|
388 { |
|
389 tree_command *cmd = stmt.command (); |
|
390 |
|
391 if (cmd) |
|
392 cmd->accept (*this); |
|
393 else |
|
394 { |
|
395 tree_expression *expr = stmt.expression (); |
|
396 |
|
397 if (expr) |
|
398 expr->accept (*this); |
|
399 } |
|
400 } |
|
401 |
|
402 void |
|
403 tree_checker::visit_statement_list (tree_statement_list& lst) |
|
404 { |
4219
|
405 for (tree_statement_list::iterator p = lst.begin (); p != lst.end (); p++) |
3011
|
406 { |
4219
|
407 tree_statement *elt = *p; |
3011
|
408 |
|
409 if (elt) |
|
410 elt->accept (*this); |
|
411 } |
|
412 } |
|
413 |
|
414 void |
|
415 tree_checker::visit_switch_case (tree_switch_case& cs) |
|
416 { |
|
417 tree_expression *label = cs.case_label (); |
|
418 |
|
419 if (label) |
|
420 label->accept (*this); |
|
421 |
|
422 tree_statement_list *list = cs.commands (); |
|
423 |
|
424 if (list) |
|
425 list->accept (*this); |
|
426 } |
|
427 |
|
428 void |
|
429 tree_checker::visit_switch_case_list (tree_switch_case_list& lst) |
|
430 { |
4219
|
431 tree_switch_case_list::iterator p = lst.begin (); |
3011
|
432 |
4219
|
433 while (p != lst.end ()) |
3011
|
434 { |
4219
|
435 tree_switch_case *elt = *p++; |
3011
|
436 |
|
437 if (elt) |
|
438 elt->accept (*this); |
|
439 } |
|
440 } |
|
441 |
|
442 void |
|
443 tree_checker::visit_switch_command (tree_switch_command& cmd) |
|
444 { |
|
445 tree_expression *expr = cmd.switch_value (); |
|
446 |
|
447 if (expr) |
|
448 expr->accept (*this); |
|
449 |
|
450 tree_switch_case_list *list = cmd.case_list (); |
|
451 |
|
452 if (list) |
|
453 list->accept (*this); |
|
454 } |
|
455 |
|
456 void |
|
457 tree_checker::visit_try_catch_command (tree_try_catch_command& cmd) |
|
458 { |
|
459 tree_statement_list *try_code = cmd.body (); |
|
460 |
|
461 if (try_code) |
|
462 try_code->accept (*this); |
|
463 |
|
464 tree_statement_list *catch_code = cmd.cleanup (); |
|
465 |
|
466 if (catch_code) |
|
467 catch_code->accept (*this); |
|
468 } |
|
469 |
|
470 void |
|
471 tree_checker::visit_unwind_protect_command |
|
472 (tree_unwind_protect_command& cmd) |
|
473 { |
|
474 tree_statement_list *unwind_protect_code = cmd.body (); |
|
475 |
|
476 if (unwind_protect_code) |
|
477 unwind_protect_code->accept (*this); |
|
478 |
|
479 tree_statement_list *cleanup_code = cmd.cleanup (); |
|
480 |
|
481 if (cleanup_code) |
|
482 cleanup_code->accept (*this); |
|
483 } |
|
484 |
|
485 void |
|
486 tree_checker::visit_while_command (tree_while_command& cmd) |
|
487 { |
|
488 tree_expression *expr = cmd.condition (); |
|
489 |
|
490 if (expr) |
|
491 expr->accept (*this); |
|
492 |
|
493 tree_statement_list *list = cmd.body (); |
|
494 |
|
495 if (list) |
|
496 list->accept (*this); |
|
497 } |
|
498 |
|
499 void |
4229
|
500 tree_checker::visit_do_until_command (tree_do_until_command& cmd) |
|
501 { |
|
502 tree_statement_list *list = cmd.body (); |
|
503 |
|
504 if (list) |
|
505 list->accept (*this); |
|
506 |
|
507 tree_expression *expr = cmd.condition (); |
|
508 |
|
509 if (expr) |
|
510 expr->accept (*this); |
|
511 } |
|
512 |
|
513 void |
3523
|
514 tree_checker::gripe (const std::string& msg, int line) |
3011
|
515 { |
|
516 if (curr_fcn_file_name.empty ()) |
|
517 error ("%s", msg.c_str ()); |
|
518 else |
|
519 error ("%s: %d: %s", curr_fcn_file_name.c_str (), line, msg.c_str ()); |
|
520 } |
|
521 |
|
522 /* |
|
523 ;;; Local Variables: *** |
|
524 ;;; mode: C++ *** |
|
525 ;;; End: *** |
|
526 */ |