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