Mercurial > octave-nkf
annotate src/pt-check.cc @ 12770:3666e8e6f96e stable release-3-4-2
Version 3.4.2 released.
* configure.ac (AC_INIT): Version is now 3.4.2.
(OCTAVE_RELEASE_DATE): Now 2011-06-24.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 24 Jun 2011 10:36:40 -0400 |
parents | fd0a3ac60b0e |
children | 027a2186cd90 |
rev | line source |
---|---|
3011 | 1 /* |
2 | |
11523 | 3 Copyright (C) 1996-2011 John W. Eaton |
3011 | 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 | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
3011 | 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 | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
3011 | 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) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
42 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
43 if (do_lvalue_check && ! elt->lvalue_ok ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
44 gripe ("invalid lvalue in multiple assignment", elt->line ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
45 } |
3011 | 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 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
93 tree_checker::do_decl_command (tree_decl_command& cmd) |
3011 | 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 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
102 tree_checker::visit_global_command (tree_global_command& cmd) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
103 { |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
104 do_decl_command (cmd); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
105 } |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
106 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
107 void |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
108 tree_checker::visit_static_command (tree_static_command& cmd) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
109 { |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
110 do_decl_command (cmd); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
111 } |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
112 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
113 void |
3011 | 114 tree_checker::visit_decl_elt (tree_decl_elt& cmd) |
115 { | |
116 tree_identifier *id = cmd.ident (); | |
117 | |
118 if (id) | |
119 id->accept (*this); | |
120 | |
121 tree_expression *expr = cmd.expression (); | |
122 | |
123 if (expr) | |
124 expr->accept (*this); | |
125 } | |
126 | |
127 void | |
128 tree_checker::visit_decl_init_list (tree_decl_init_list& lst) | |
129 { | |
4219 | 130 tree_decl_init_list::iterator p = lst.begin (); |
3011 | 131 |
4219 | 132 while (p != lst.end ()) |
3011 | 133 { |
4219 | 134 tree_decl_elt *elt = *p++; |
3011 | 135 |
136 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
137 elt->accept (*this); |
3011 | 138 } |
139 } | |
140 | |
141 void | |
142 tree_checker::visit_simple_for_command (tree_simple_for_command& cmd) | |
143 { | |
144 tree_expression *lhs = cmd.left_hand_side (); | |
145 | |
146 if (lhs) | |
147 { | |
148 if (! lhs->lvalue_ok ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
149 gripe ("invalid lvalue in for command", cmd.line ()); |
3011 | 150 } |
151 | |
152 tree_expression *expr = cmd.control_expr (); | |
153 | |
154 if (expr) | |
155 expr->accept (*this); | |
156 | |
157 tree_statement_list *list = cmd.body (); | |
158 | |
159 if (list) | |
160 list->accept (*this); | |
161 } | |
162 | |
163 void | |
164 tree_checker::visit_complex_for_command (tree_complex_for_command& cmd) | |
165 { | |
166 tree_argument_list *lhs = cmd.left_hand_side (); | |
167 | |
168 if (lhs) | |
169 { | |
170 int len = lhs->length (); | |
171 | |
3018 | 172 if (len == 0 || len > 2) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
173 gripe ("invalid number of output arguments in for command", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
174 cmd.line ()); |
3011 | 175 |
176 do_lvalue_check = true; | |
177 | |
178 lhs->accept (*this); | |
179 | |
180 do_lvalue_check = false; | |
181 } | |
182 | |
183 tree_expression *expr = cmd.control_expr (); | |
184 | |
185 if (expr) | |
186 expr->accept (*this); | |
187 | |
188 tree_statement_list *list = cmd.body (); | |
189 | |
190 if (list) | |
191 list->accept (*this); | |
192 } | |
193 | |
194 void | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
195 tree_checker::visit_octave_user_script (octave_user_script& fcn) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
196 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
197 tree_statement_list *cmd_list = fcn.body (); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
198 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
199 if (cmd_list) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
200 cmd_list->accept (*this); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
201 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
202 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
203 void |
3011 | 204 tree_checker::visit_octave_user_function (octave_user_function& fcn) |
205 { | |
206 tree_statement_list *cmd_list = fcn.body (); | |
207 | |
208 if (cmd_list) | |
209 cmd_list->accept (*this); | |
210 } | |
211 | |
212 void | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
213 tree_checker::visit_function_def (tree_function_def& fdef) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
214 { |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
215 octave_value fcn = fdef.function (); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
216 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
217 octave_function *f = fcn.function_value (); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
218 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
219 if (f) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
220 f->accept (*this); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
221 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
222 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
223 void |
3011 | 224 tree_checker::visit_identifier (tree_identifier& /* id */) |
225 { | |
226 } | |
227 | |
228 void | |
229 tree_checker::visit_if_clause (tree_if_clause& cmd) | |
230 { | |
231 tree_expression *expr = cmd.condition (); | |
232 | |
233 if (expr) | |
234 expr->accept (*this); | |
235 | |
236 tree_statement_list *list = cmd.commands (); | |
237 | |
238 if (list) | |
239 list->accept (*this); | |
240 } | |
241 | |
242 void | |
243 tree_checker::visit_if_command (tree_if_command& cmd) | |
244 { | |
245 tree_if_command_list *list = cmd.cmd_list (); | |
246 | |
247 if (list) | |
248 list->accept (*this); | |
249 } | |
250 | |
251 void | |
252 tree_checker::visit_if_command_list (tree_if_command_list& lst) | |
253 { | |
4219 | 254 tree_if_command_list::iterator p = lst.begin (); |
3011 | 255 |
4219 | 256 while (p != lst.end ()) |
3011 | 257 { |
4219 | 258 tree_if_clause *elt = *p++; |
3011 | 259 |
260 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
261 elt->accept (*this); |
3011 | 262 } |
263 } | |
264 | |
265 void | |
266 tree_checker::visit_index_expression (tree_index_expression& expr) | |
267 { | |
268 tree_expression *e = expr.expression (); | |
269 | |
270 if (e) | |
271 e->accept (*this); | |
272 | |
4219 | 273 std::list<tree_argument_list *> lst = expr.arg_lists (); |
3933 | 274 |
4219 | 275 std::list<tree_argument_list *>::iterator p = lst.begin (); |
3011 | 276 |
4219 | 277 while (p != lst.end ()) |
3933 | 278 { |
4219 | 279 tree_argument_list *elt = *p++; |
3933 | 280 |
281 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
282 elt->accept (*this); |
3933 | 283 } |
3011 | 284 } |
285 | |
286 void | |
287 tree_checker::visit_matrix (tree_matrix& lst) | |
288 { | |
4219 | 289 tree_matrix::iterator p = lst.begin (); |
3011 | 290 |
4219 | 291 while (p != lst.end ()) |
3011 | 292 { |
4219 | 293 tree_argument_list *elt = *p++; |
294 | |
295 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
296 elt->accept (*this); |
4219 | 297 } |
298 } | |
3011 | 299 |
4219 | 300 void |
301 tree_checker::visit_cell (tree_cell& lst) | |
302 { | |
303 tree_matrix::iterator p = lst.begin (); | |
304 | |
305 while (p != lst.end ()) | |
306 { | |
307 tree_argument_list *elt = *p++; | |
3011 | 308 |
309 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
310 elt->accept (*this); |
3011 | 311 } |
312 } | |
313 | |
314 void | |
315 tree_checker::visit_multi_assignment (tree_multi_assignment& expr) | |
316 { | |
317 tree_argument_list *lhs = expr.left_hand_side (); | |
318 | |
319 if (lhs) | |
320 { | |
321 do_lvalue_check = true; | |
322 | |
323 lhs->accept (*this); | |
324 | |
325 do_lvalue_check = false; | |
326 } | |
327 | |
328 tree_expression *rhs = expr.right_hand_side (); | |
329 | |
330 if (rhs) | |
331 rhs->accept (*this); | |
332 } | |
333 | |
334 void | |
335 tree_checker::visit_no_op_command (tree_no_op_command& /* cmd */) | |
336 { | |
337 } | |
338 | |
339 void | |
5861 | 340 tree_checker::visit_anon_fcn_handle (tree_anon_fcn_handle& /* afh */) |
341 { | |
342 } | |
343 | |
344 void | |
3011 | 345 tree_checker::visit_constant (tree_constant& /* val */) |
346 { | |
347 } | |
348 | |
349 void | |
4342 | 350 tree_checker::visit_fcn_handle (tree_fcn_handle& /* fh */) |
351 { | |
352 } | |
353 | |
354 void | |
3011 | 355 tree_checker::visit_parameter_list (tree_parameter_list& lst) |
356 { | |
4219 | 357 tree_parameter_list::iterator p = lst.begin (); |
3011 | 358 |
4219 | 359 while (p != lst.end ()) |
3011 | 360 { |
6215 | 361 tree_decl_elt *elt = *p++; |
3011 | 362 |
363 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
364 elt->accept (*this); |
3011 | 365 } |
366 } | |
367 | |
368 void | |
369 tree_checker::visit_postfix_expression (tree_postfix_expression& expr) | |
370 { | |
371 tree_expression *e = expr.operand (); | |
372 | |
373 if (e) | |
374 e->accept (*this); | |
375 } | |
376 | |
377 void | |
378 tree_checker::visit_prefix_expression (tree_prefix_expression& expr) | |
379 { | |
380 tree_expression *e = expr.operand (); | |
381 | |
382 if (e) | |
383 e->accept (*this); | |
384 } | |
385 | |
386 void | |
4207 | 387 tree_checker::visit_return_command (tree_return_command&) |
3011 | 388 { |
389 } | |
390 | |
391 void | |
392 tree_checker::visit_return_list (tree_return_list& lst) | |
393 { | |
4219 | 394 tree_return_list::iterator p = lst.begin (); |
3011 | 395 |
4219 | 396 while (p != lst.end ()) |
3011 | 397 { |
4219 | 398 tree_index_expression *elt = *p++; |
3011 | 399 |
400 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
401 elt->accept (*this); |
3011 | 402 } |
403 } | |
404 | |
405 void | |
406 tree_checker::visit_simple_assignment (tree_simple_assignment& expr) | |
407 { | |
408 tree_expression *lhs = expr.left_hand_side (); | |
409 | |
410 if (lhs) | |
411 { | |
412 if (! lhs->lvalue_ok ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
413 gripe ("invalid lvalue in assignment", expr.line ()); |
3011 | 414 } |
415 | |
416 tree_expression *rhs = expr.right_hand_side (); | |
417 | |
418 if (rhs) | |
419 rhs->accept (*this); | |
420 } | |
421 | |
422 void | |
423 tree_checker::visit_statement (tree_statement& stmt) | |
424 { | |
425 tree_command *cmd = stmt.command (); | |
426 | |
427 if (cmd) | |
428 cmd->accept (*this); | |
429 else | |
430 { | |
431 tree_expression *expr = stmt.expression (); | |
432 | |
433 if (expr) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
434 expr->accept (*this); |
3011 | 435 } |
436 } | |
437 | |
438 void | |
439 tree_checker::visit_statement_list (tree_statement_list& lst) | |
440 { | |
4219 | 441 for (tree_statement_list::iterator p = lst.begin (); p != lst.end (); p++) |
3011 | 442 { |
4219 | 443 tree_statement *elt = *p; |
3011 | 444 |
445 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
446 elt->accept (*this); |
3011 | 447 } |
448 } | |
449 | |
450 void | |
451 tree_checker::visit_switch_case (tree_switch_case& cs) | |
452 { | |
453 tree_expression *label = cs.case_label (); | |
454 | |
455 if (label) | |
456 label->accept (*this); | |
457 | |
458 tree_statement_list *list = cs.commands (); | |
459 | |
460 if (list) | |
461 list->accept (*this); | |
462 } | |
463 | |
464 void | |
465 tree_checker::visit_switch_case_list (tree_switch_case_list& lst) | |
466 { | |
4219 | 467 tree_switch_case_list::iterator p = lst.begin (); |
3011 | 468 |
4219 | 469 while (p != lst.end ()) |
3011 | 470 { |
4219 | 471 tree_switch_case *elt = *p++; |
3011 | 472 |
473 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
474 elt->accept (*this); |
3011 | 475 } |
476 } | |
477 | |
478 void | |
479 tree_checker::visit_switch_command (tree_switch_command& cmd) | |
480 { | |
481 tree_expression *expr = cmd.switch_value (); | |
482 | |
483 if (expr) | |
484 expr->accept (*this); | |
485 | |
486 tree_switch_case_list *list = cmd.case_list (); | |
487 | |
488 if (list) | |
489 list->accept (*this); | |
490 } | |
491 | |
492 void | |
493 tree_checker::visit_try_catch_command (tree_try_catch_command& cmd) | |
494 { | |
495 tree_statement_list *try_code = cmd.body (); | |
496 | |
497 if (try_code) | |
498 try_code->accept (*this); | |
499 | |
500 tree_statement_list *catch_code = cmd.cleanup (); | |
501 | |
502 if (catch_code) | |
503 catch_code->accept (*this); | |
504 } | |
505 | |
506 void | |
507 tree_checker::visit_unwind_protect_command | |
508 (tree_unwind_protect_command& cmd) | |
509 { | |
510 tree_statement_list *unwind_protect_code = cmd.body (); | |
511 | |
512 if (unwind_protect_code) | |
513 unwind_protect_code->accept (*this); | |
514 | |
515 tree_statement_list *cleanup_code = cmd.cleanup (); | |
516 | |
517 if (cleanup_code) | |
518 cleanup_code->accept (*this); | |
519 } | |
520 | |
521 void | |
522 tree_checker::visit_while_command (tree_while_command& cmd) | |
523 { | |
524 tree_expression *expr = cmd.condition (); | |
525 | |
526 if (expr) | |
527 expr->accept (*this); | |
528 | |
529 tree_statement_list *list = cmd.body (); | |
530 | |
531 if (list) | |
532 list->accept (*this); | |
533 } | |
534 | |
535 void | |
4229 | 536 tree_checker::visit_do_until_command (tree_do_until_command& cmd) |
537 { | |
538 tree_statement_list *list = cmd.body (); | |
539 | |
540 if (list) | |
541 list->accept (*this); | |
542 | |
543 tree_expression *expr = cmd.condition (); | |
544 | |
545 if (expr) | |
546 expr->accept (*this); | |
547 } | |
548 | |
549 void | |
3523 | 550 tree_checker::gripe (const std::string& msg, int line) |
3011 | 551 { |
552 if (curr_fcn_file_name.empty ()) | |
553 error ("%s", msg.c_str ()); | |
554 else | |
555 error ("%s: %d: %s", curr_fcn_file_name.c_str (), line, msg.c_str ()); | |
556 } |