Mercurial > octave
annotate libinterp/parse-tree/pt-check.cc @ 23219:3ac9f9ecfae5 stable
maint: Update copyright dates.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 22 Feb 2017 12:39:29 -0500 |
parents | e9a0469dedd9 |
children | 092078913d54 |
rev | line source |
---|---|
3011 | 1 /* |
2 | |
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
3 Copyright (C) 1996-2017 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 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
24 # include "config.h" |
3011 | 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 ()) |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
44 errmsg ("invalid lvalue in multiple assignment", elt->line ()); |
10315
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&) |
22417
48c00363dc74
maint: Use '{ }' for empty function bodies in C++.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
65 { } |
3011 | 66 |
67 void | |
68 tree_checker::visit_colon_expression (tree_colon_expression& expr) | |
69 { | |
70 tree_expression *op1 = expr.base (); | |
71 | |
72 if (op1) | |
73 op1->accept (*this); | |
74 | |
75 tree_expression *op3 = expr.increment (); | |
76 | |
77 if (op3) | |
78 op3->accept (*this); | |
79 | |
80 tree_expression *op2 = expr.limit (); | |
81 | |
82 if (op2) | |
83 op2->accept (*this); | |
84 } | |
85 | |
86 void | |
4207 | 87 tree_checker::visit_continue_command (tree_continue_command&) |
22417
48c00363dc74
maint: Use '{ }' for empty function bodies in C++.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
88 { } |
3011 | 89 |
90 void | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
91 tree_checker::do_decl_command (tree_decl_command& cmd) |
3011 | 92 { |
93 tree_decl_init_list *init_list = cmd.initializer_list (); | |
94 | |
95 if (init_list) | |
96 init_list->accept (*this); | |
97 } | |
98 | |
99 void | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
100 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
|
101 { |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
102 do_decl_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 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
105 void |
14294
9e3983c8963c
deprecate the static keyword
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
106 tree_checker::visit_persistent_command (tree_persistent_command& cmd) |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
107 { |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
108 do_decl_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 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
111 void |
3011 | 112 tree_checker::visit_decl_elt (tree_decl_elt& cmd) |
113 { | |
114 tree_identifier *id = cmd.ident (); | |
115 | |
116 if (id) | |
117 id->accept (*this); | |
118 | |
119 tree_expression *expr = cmd.expression (); | |
120 | |
121 if (expr) | |
122 expr->accept (*this); | |
123 } | |
124 | |
125 void | |
126 tree_checker::visit_decl_init_list (tree_decl_init_list& lst) | |
127 { | |
4219 | 128 tree_decl_init_list::iterator p = lst.begin (); |
3011 | 129 |
4219 | 130 while (p != lst.end ()) |
3011 | 131 { |
4219 | 132 tree_decl_elt *elt = *p++; |
3011 | 133 |
134 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
135 elt->accept (*this); |
3011 | 136 } |
137 } | |
138 | |
139 void | |
140 tree_checker::visit_simple_for_command (tree_simple_for_command& cmd) | |
141 { | |
142 tree_expression *lhs = cmd.left_hand_side (); | |
143 | |
144 if (lhs) | |
145 { | |
146 if (! lhs->lvalue_ok ()) | |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
147 errmsg ("invalid lvalue in for command", cmd.line ()); |
3011 | 148 } |
149 | |
150 tree_expression *expr = cmd.control_expr (); | |
151 | |
152 if (expr) | |
153 expr->accept (*this); | |
154 | |
13245
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
155 tree_expression *maxproc = cmd.maxproc_expr (); |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
156 |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
157 if (maxproc) |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
158 maxproc->accept (*this); |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
159 |
3011 | 160 tree_statement_list *list = cmd.body (); |
161 | |
162 if (list) | |
163 list->accept (*this); | |
164 } | |
165 | |
166 void | |
167 tree_checker::visit_complex_for_command (tree_complex_for_command& cmd) | |
168 { | |
169 tree_argument_list *lhs = cmd.left_hand_side (); | |
170 | |
171 if (lhs) | |
172 { | |
173 int len = lhs->length (); | |
174 | |
3018 | 175 if (len == 0 || len > 2) |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
176 errmsg ("invalid number of output arguments in for command", |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
177 cmd.line ()); |
3011 | 178 |
179 do_lvalue_check = true; | |
180 | |
181 lhs->accept (*this); | |
182 | |
183 do_lvalue_check = false; | |
184 } | |
185 | |
186 tree_expression *expr = cmd.control_expr (); | |
187 | |
188 if (expr) | |
189 expr->accept (*this); | |
190 | |
191 tree_statement_list *list = cmd.body (); | |
192 | |
193 if (list) | |
194 list->accept (*this); | |
195 } | |
196 | |
197 void | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
198 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
|
199 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
200 tree_statement_list *cmd_list = fcn.body (); |
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 if (cmd_list) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
203 cmd_list->accept (*this); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
204 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
205 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
206 void |
3011 | 207 tree_checker::visit_octave_user_function (octave_user_function& fcn) |
208 { | |
209 tree_statement_list *cmd_list = fcn.body (); | |
210 | |
211 if (cmd_list) | |
212 cmd_list->accept (*this); | |
213 } | |
214 | |
215 void | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
216 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
|
217 { |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
218 octave_value fcn = fdef.function (); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
219 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
220 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
|
221 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
222 if (f) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
223 f->accept (*this); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
224 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
225 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
226 void |
3011 | 227 tree_checker::visit_identifier (tree_identifier& /* id */) |
22417
48c00363dc74
maint: Use '{ }' for empty function bodies in C++.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
228 { } |
3011 | 229 |
230 void | |
231 tree_checker::visit_if_clause (tree_if_clause& cmd) | |
232 { | |
233 tree_expression *expr = cmd.condition (); | |
234 | |
235 if (expr) | |
236 expr->accept (*this); | |
237 | |
238 tree_statement_list *list = cmd.commands (); | |
239 | |
240 if (list) | |
241 list->accept (*this); | |
242 } | |
243 | |
244 void | |
245 tree_checker::visit_if_command (tree_if_command& cmd) | |
246 { | |
247 tree_if_command_list *list = cmd.cmd_list (); | |
248 | |
249 if (list) | |
250 list->accept (*this); | |
251 } | |
252 | |
253 void | |
254 tree_checker::visit_if_command_list (tree_if_command_list& lst) | |
255 { | |
4219 | 256 tree_if_command_list::iterator p = lst.begin (); |
3011 | 257 |
4219 | 258 while (p != lst.end ()) |
3011 | 259 { |
4219 | 260 tree_if_clause *elt = *p++; |
3011 | 261 |
262 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
263 elt->accept (*this); |
3011 | 264 } |
265 } | |
266 | |
267 void | |
268 tree_checker::visit_index_expression (tree_index_expression& expr) | |
269 { | |
270 tree_expression *e = expr.expression (); | |
271 | |
272 if (e) | |
273 e->accept (*this); | |
274 | |
4219 | 275 std::list<tree_argument_list *> lst = expr.arg_lists (); |
3933 | 276 |
4219 | 277 std::list<tree_argument_list *>::iterator p = lst.begin (); |
3011 | 278 |
4219 | 279 while (p != lst.end ()) |
3933 | 280 { |
4219 | 281 tree_argument_list *elt = *p++; |
3933 | 282 |
283 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
284 elt->accept (*this); |
3933 | 285 } |
3011 | 286 } |
287 | |
288 void | |
289 tree_checker::visit_matrix (tree_matrix& lst) | |
290 { | |
4219 | 291 tree_matrix::iterator p = lst.begin (); |
3011 | 292 |
4219 | 293 while (p != lst.end ()) |
3011 | 294 { |
4219 | 295 tree_argument_list *elt = *p++; |
296 | |
297 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
298 elt->accept (*this); |
4219 | 299 } |
300 } | |
3011 | 301 |
4219 | 302 void |
303 tree_checker::visit_cell (tree_cell& lst) | |
304 { | |
305 tree_matrix::iterator p = lst.begin (); | |
306 | |
307 while (p != lst.end ()) | |
308 { | |
309 tree_argument_list *elt = *p++; | |
3011 | 310 |
311 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
312 elt->accept (*this); |
3011 | 313 } |
314 } | |
315 | |
316 void | |
317 tree_checker::visit_multi_assignment (tree_multi_assignment& expr) | |
318 { | |
319 tree_argument_list *lhs = expr.left_hand_side (); | |
320 | |
321 if (lhs) | |
322 { | |
323 do_lvalue_check = true; | |
324 | |
325 lhs->accept (*this); | |
326 | |
327 do_lvalue_check = false; | |
328 } | |
329 | |
330 tree_expression *rhs = expr.right_hand_side (); | |
331 | |
332 if (rhs) | |
333 rhs->accept (*this); | |
334 } | |
335 | |
336 void | |
337 tree_checker::visit_no_op_command (tree_no_op_command& /* cmd */) | |
22417
48c00363dc74
maint: Use '{ }' for empty function bodies in C++.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
338 { } |
3011 | 339 |
340 void | |
5861 | 341 tree_checker::visit_anon_fcn_handle (tree_anon_fcn_handle& /* afh */) |
22417
48c00363dc74
maint: Use '{ }' for empty function bodies in C++.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
342 { } |
5861 | 343 |
344 void | |
3011 | 345 tree_checker::visit_constant (tree_constant& /* val */) |
22417
48c00363dc74
maint: Use '{ }' for empty function bodies in C++.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
346 { } |
3011 | 347 |
348 void | |
4342 | 349 tree_checker::visit_fcn_handle (tree_fcn_handle& /* fh */) |
22417
48c00363dc74
maint: Use '{ }' for empty function bodies in C++.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
350 { } |
4342 | 351 |
352 void | |
15035 | 353 tree_checker::visit_funcall (tree_funcall& /* fc */) |
22417
48c00363dc74
maint: Use '{ }' for empty function bodies in C++.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
354 { } |
15035 | 355 |
356 void | |
3011 | 357 tree_checker::visit_parameter_list (tree_parameter_list& lst) |
358 { | |
4219 | 359 tree_parameter_list::iterator p = lst.begin (); |
3011 | 360 |
4219 | 361 while (p != lst.end ()) |
3011 | 362 { |
6215 | 363 tree_decl_elt *elt = *p++; |
3011 | 364 |
365 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
366 elt->accept (*this); |
3011 | 367 } |
368 } | |
369 | |
370 void | |
371 tree_checker::visit_postfix_expression (tree_postfix_expression& expr) | |
372 { | |
373 tree_expression *e = expr.operand (); | |
374 | |
375 if (e) | |
376 e->accept (*this); | |
377 } | |
378 | |
379 void | |
380 tree_checker::visit_prefix_expression (tree_prefix_expression& expr) | |
381 { | |
382 tree_expression *e = expr.operand (); | |
383 | |
384 if (e) | |
385 e->accept (*this); | |
386 } | |
387 | |
388 void | |
4207 | 389 tree_checker::visit_return_command (tree_return_command&) |
22417
48c00363dc74
maint: Use '{ }' for empty function bodies in C++.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
390 { } |
3011 | 391 |
392 void | |
393 tree_checker::visit_return_list (tree_return_list& lst) | |
394 { | |
4219 | 395 tree_return_list::iterator p = lst.begin (); |
3011 | 396 |
4219 | 397 while (p != lst.end ()) |
3011 | 398 { |
4219 | 399 tree_index_expression *elt = *p++; |
3011 | 400 |
401 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
402 elt->accept (*this); |
3011 | 403 } |
404 } | |
405 | |
406 void | |
407 tree_checker::visit_simple_assignment (tree_simple_assignment& expr) | |
408 { | |
409 tree_expression *lhs = expr.left_hand_side (); | |
410 | |
411 if (lhs) | |
412 { | |
413 if (! lhs->lvalue_ok ()) | |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
414 errmsg ("invalid lvalue in assignment", expr.line ()); |
3011 | 415 } |
416 | |
417 tree_expression *rhs = expr.right_hand_side (); | |
418 | |
419 if (rhs) | |
420 rhs->accept (*this); | |
421 } | |
422 | |
423 void | |
424 tree_checker::visit_statement (tree_statement& stmt) | |
425 { | |
426 tree_command *cmd = stmt.command (); | |
427 | |
428 if (cmd) | |
429 cmd->accept (*this); | |
430 else | |
431 { | |
432 tree_expression *expr = stmt.expression (); | |
433 | |
434 if (expr) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
435 expr->accept (*this); |
3011 | 436 } |
437 } | |
438 | |
439 void | |
440 tree_checker::visit_statement_list (tree_statement_list& lst) | |
441 { | |
4219 | 442 for (tree_statement_list::iterator p = lst.begin (); p != lst.end (); p++) |
3011 | 443 { |
4219 | 444 tree_statement *elt = *p; |
3011 | 445 |
446 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
447 elt->accept (*this); |
3011 | 448 } |
449 } | |
450 | |
451 void | |
452 tree_checker::visit_switch_case (tree_switch_case& cs) | |
453 { | |
454 tree_expression *label = cs.case_label (); | |
455 | |
456 if (label) | |
457 label->accept (*this); | |
458 | |
459 tree_statement_list *list = cs.commands (); | |
460 | |
461 if (list) | |
462 list->accept (*this); | |
463 } | |
464 | |
465 void | |
466 tree_checker::visit_switch_case_list (tree_switch_case_list& lst) | |
467 { | |
4219 | 468 tree_switch_case_list::iterator p = lst.begin (); |
3011 | 469 |
4219 | 470 while (p != lst.end ()) |
3011 | 471 { |
4219 | 472 tree_switch_case *elt = *p++; |
3011 | 473 |
474 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
475 elt->accept (*this); |
3011 | 476 } |
477 } | |
478 | |
479 void | |
480 tree_checker::visit_switch_command (tree_switch_command& cmd) | |
481 { | |
482 tree_expression *expr = cmd.switch_value (); | |
483 | |
484 if (expr) | |
485 expr->accept (*this); | |
486 | |
487 tree_switch_case_list *list = cmd.case_list (); | |
488 | |
489 if (list) | |
490 list->accept (*this); | |
491 } | |
492 | |
493 void | |
494 tree_checker::visit_try_catch_command (tree_try_catch_command& cmd) | |
495 { | |
496 tree_statement_list *try_code = cmd.body (); | |
497 | |
17249
923ce8b42db2
improve try-catch-statement to save exception to a variable (bug #33217)
Stefan Mahr <dac922@gmx.de>
parents:
16203
diff
changeset
|
498 tree_identifier *expr_id = cmd.identifier (); |
923ce8b42db2
improve try-catch-statement to save exception to a variable (bug #33217)
Stefan Mahr <dac922@gmx.de>
parents:
16203
diff
changeset
|
499 |
923ce8b42db2
improve try-catch-statement to save exception to a variable (bug #33217)
Stefan Mahr <dac922@gmx.de>
parents:
16203
diff
changeset
|
500 if (expr_id) |
923ce8b42db2
improve try-catch-statement to save exception to a variable (bug #33217)
Stefan Mahr <dac922@gmx.de>
parents:
16203
diff
changeset
|
501 { |
923ce8b42db2
improve try-catch-statement to save exception to a variable (bug #33217)
Stefan Mahr <dac922@gmx.de>
parents:
16203
diff
changeset
|
502 if (! expr_id->lvalue_ok ()) |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
503 errmsg ("invalid lvalue used for identifier in try-catch command", |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
504 cmd.line ()); |
17249
923ce8b42db2
improve try-catch-statement to save exception to a variable (bug #33217)
Stefan Mahr <dac922@gmx.de>
parents:
16203
diff
changeset
|
505 } |
923ce8b42db2
improve try-catch-statement to save exception to a variable (bug #33217)
Stefan Mahr <dac922@gmx.de>
parents:
16203
diff
changeset
|
506 |
3011 | 507 if (try_code) |
508 try_code->accept (*this); | |
509 | |
510 tree_statement_list *catch_code = cmd.cleanup (); | |
511 | |
512 if (catch_code) | |
513 catch_code->accept (*this); | |
514 } | |
515 | |
516 void | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
517 tree_checker::visit_unwind_protect_command (tree_unwind_protect_command& cmd) |
3011 | 518 { |
519 tree_statement_list *unwind_protect_code = cmd.body (); | |
520 | |
521 if (unwind_protect_code) | |
522 unwind_protect_code->accept (*this); | |
523 | |
524 tree_statement_list *cleanup_code = cmd.cleanup (); | |
525 | |
526 if (cleanup_code) | |
527 cleanup_code->accept (*this); | |
528 } | |
529 | |
530 void | |
531 tree_checker::visit_while_command (tree_while_command& cmd) | |
532 { | |
533 tree_expression *expr = cmd.condition (); | |
534 | |
535 if (expr) | |
536 expr->accept (*this); | |
537 | |
538 tree_statement_list *list = cmd.body (); | |
539 | |
540 if (list) | |
541 list->accept (*this); | |
542 } | |
543 | |
544 void | |
4229 | 545 tree_checker::visit_do_until_command (tree_do_until_command& cmd) |
546 { | |
547 tree_statement_list *list = cmd.body (); | |
548 | |
549 if (list) | |
550 list->accept (*this); | |
551 | |
552 tree_expression *expr = cmd.condition (); | |
553 | |
554 if (expr) | |
555 expr->accept (*this); | |
556 } | |
557 | |
558 void | |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
559 tree_checker::errmsg (const std::string& msg, int line) |
3011 | 560 { |
16203
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
561 if (file_name.empty ()) |
3011 | 562 error ("%s", msg.c_str ()); |
563 else | |
16203
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
564 error ("%s: %d: %s", file_name.c_str (), line, msg.c_str ()); |
3011 | 565 } |