GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
pt-check.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2017 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 3 of the License, or (at your
10 option) any 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, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (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
34 {
36 
37  while (p != lst.end ())
38  {
39  tree_expression *elt = *p++;
40 
41  if (elt)
42  {
43  if (do_lvalue_check && ! elt->lvalue_ok ())
44  errmsg ("invalid lvalue in multiple assignment", elt->line ());
45  }
46  }
47 }
48 
49 void
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
65 { }
66 
67 void
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
88 { }
89 
90 void
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
101 {
102  do_decl_command (cmd);
103 }
104 
105 void
107 {
108  do_decl_command (cmd);
109 }
110 
111 void
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
127 {
129 
130  while (p != lst.end ())
131  {
132  tree_decl_elt *elt = *p++;
133 
134  if (elt)
135  elt->accept (*this);
136  }
137 }
138 
139 void
141 {
142  tree_expression *lhs = cmd.left_hand_side ();
143 
144  if (lhs)
145  {
146  if (! lhs->lvalue_ok ())
147  errmsg ("invalid lvalue in for command", cmd.line ());
148  }
149 
150  tree_expression *expr = cmd.control_expr ();
151 
152  if (expr)
153  expr->accept (*this);
154 
155  tree_expression *maxproc = cmd.maxproc_expr ();
156 
157  if (maxproc)
158  maxproc->accept (*this);
159 
160  tree_statement_list *list = cmd.body ();
161 
162  if (list)
163  list->accept (*this);
164 }
165 
166 void
168 {
169  tree_argument_list *lhs = cmd.left_hand_side ();
170 
171  if (lhs)
172  {
173  int len = lhs->length ();
174 
175  if (len == 0 || len > 2)
176  errmsg ("invalid number of output arguments in for command",
177  cmd.line ());
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
199 {
200  tree_statement_list *cmd_list = fcn.body ();
201 
202  if (cmd_list)
203  cmd_list->accept (*this);
204 }
205 
206 void
208 {
209  tree_statement_list *cmd_list = fcn.body ();
210 
211  if (cmd_list)
212  cmd_list->accept (*this);
213 }
214 
215 void
217 {
218  octave_value fcn = fdef.function ();
219 
220  octave_function *f = fcn.function_value ();
221 
222  if (f)
223  f->accept (*this);
224 }
225 
226 void
228 { }
229 
230 void
232 {
233  tree_expression *expr = cmd.condition ();
234 
235  if (expr)
236  expr->accept (*this);
237 
239 
240  if (list)
241  list->accept (*this);
242 }
243 
244 void
246 {
248 
249  if (list)
250  list->accept (*this);
251 }
252 
253 void
255 {
257 
258  while (p != lst.end ())
259  {
260  tree_if_clause *elt = *p++;
261 
262  if (elt)
263  elt->accept (*this);
264  }
265 }
266 
267 void
269 {
270  tree_expression *e = expr.expression ();
271 
272  if (e)
273  e->accept (*this);
274 
275  std::list<tree_argument_list *> lst = expr.arg_lists ();
276 
277  std::list<tree_argument_list *>::iterator p = lst.begin ();
278 
279  while (p != lst.end ())
280  {
281  tree_argument_list *elt = *p++;
282 
283  if (elt)
284  elt->accept (*this);
285  }
286 }
287 
288 void
290 {
291  tree_matrix::iterator p = lst.begin ();
292 
293  while (p != lst.end ())
294  {
295  tree_argument_list *elt = *p++;
296 
297  if (elt)
298  elt->accept (*this);
299  }
300 }
301 
302 void
304 {
305  tree_matrix::iterator p = lst.begin ();
306 
307  while (p != lst.end ())
308  {
309  tree_argument_list *elt = *p++;
310 
311  if (elt)
312  elt->accept (*this);
313  }
314 }
315 
316 void
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
338 { }
339 
340 void
342 { }
343 
344 void
346 { }
347 
348 void
350 { }
351 
352 void
354 { }
355 
356 void
358 {
360 
361  while (p != lst.end ())
362  {
363  tree_decl_elt *elt = *p++;
364 
365  if (elt)
366  elt->accept (*this);
367  }
368 }
369 
370 void
372 {
373  tree_expression *e = expr.operand ();
374 
375  if (e)
376  e->accept (*this);
377 }
378 
379 void
381 {
382  tree_expression *e = expr.operand ();
383 
384  if (e)
385  e->accept (*this);
386 }
387 
388 void
390 { }
391 
392 void
394 {
396 
397  while (p != lst.end ())
398  {
399  tree_index_expression *elt = *p++;
400 
401  if (elt)
402  elt->accept (*this);
403  }
404 }
405 
406 void
408 {
409  tree_expression *lhs = expr.left_hand_side ();
410 
411  if (lhs)
412  {
413  if (! lhs->lvalue_ok ())
414  errmsg ("invalid lvalue in assignment", expr.line ());
415  }
416 
417  tree_expression *rhs = expr.right_hand_side ();
418 
419  if (rhs)
420  rhs->accept (*this);
421 }
422 
423 void
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)
435  expr->accept (*this);
436  }
437 }
438 
439 void
441 {
442  for (tree_statement_list::iterator p = lst.begin (); p != lst.end (); p++)
443  {
444  tree_statement *elt = *p;
445 
446  if (elt)
447  elt->accept (*this);
448  }
449 }
450 
451 void
453 {
454  tree_expression *label = cs.case_label ();
455 
456  if (label)
457  label->accept (*this);
458 
460 
461  if (list)
462  list->accept (*this);
463 }
464 
465 void
467 {
469 
470  while (p != lst.end ())
471  {
472  tree_switch_case *elt = *p++;
473 
474  if (elt)
475  elt->accept (*this);
476  }
477 }
478 
479 void
481 {
482  tree_expression *expr = cmd.switch_value ();
483 
484  if (expr)
485  expr->accept (*this);
486 
488 
489  if (list)
490  list->accept (*this);
491 }
492 
493 void
495 {
496  tree_statement_list *try_code = cmd.body ();
497 
498  tree_identifier *expr_id = cmd.identifier ();
499 
500  if (expr_id)
501  {
502  if (! expr_id->lvalue_ok ())
503  errmsg ("invalid lvalue used for identifier in try-catch command",
504  cmd.line ());
505  }
506 
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
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
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
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
560 {
561  if (file_name.empty ())
562  error ("%s", msg.c_str ());
563  else
564  error ("%s: %d: %s", file_name.c_str (), line, msg.c_str ());
565 }
tree_expression * operand(void)
Definition: pt-unop.h:62
void visit_if_command(tree_if_command &)
Definition: pt-check.cc:245
tree_identifier * identifier(void)
Definition: pt-except.h:59
void visit_cell(tree_cell &)
Definition: pt-check.cc:303
virtual bool lvalue_ok(void) const
Definition: pt-exp.h:77
void accept(tree_walker &tw)
Definition: pt-select.cc:159
tree_statement_list * cleanup(void)
Definition: pt-except.h:127
The value of lines which begin with a space character are not saved in the history list A value of all commands are saved on the history list
Definition: oct-hist.cc:728
tree_expression * left_hand_side(void)
Definition: pt-assign.h:72
tree_expression * switch_value(void)
Definition: pt-select.h:270
void visit_identifier(tree_identifier &)
Definition: pt-check.cc:227
tree_expression * control_expr(void)
Definition: pt-loop.h:293
void visit_try_catch_command(tree_try_catch_command &)
Definition: pt-check.cc:494
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE * f
void visit_decl_init_list(tree_decl_init_list &)
Definition: pt-check.cc:126
tree_argument_list * left_hand_side(void)
Definition: pt-assign.h:139
void accept(tree_walker &tw)
Definition: pt-stmt.cc:324
tree_command * command(void)
Definition: pt-stmt.h:84
void visit_continue_command(tree_continue_command &)
Definition: pt-check.cc:87
void error(const char *fmt,...)
Definition: error.cc:570
tree_switch_case_list * case_list(void)
Definition: pt-select.h:272
std::list< tree_expression * >::iterator iterator
Definition: base-list.h:40
tree_statement_list * commands(void)
Definition: pt-select.h:63
void visit_postfix_expression(tree_postfix_expression &)
Definition: pt-check.cc:371
tree_expression * expression(void)
Definition: pt-idx.h:74
tree_expression * case_label(void)
Definition: pt-select.h:191
void visit_if_clause(tree_if_clause &)
Definition: pt-check.cc:231
i e
Definition: data.cc:2724
void visit_statement_list(tree_statement_list &)
Definition: pt-check.cc:440
void do_decl_command(tree_decl_command &)
Definition: pt-check.cc:91
void visit_prefix_expression(tree_prefix_expression &)
Definition: pt-check.cc:380
bool lvalue_ok(void) const
Definition: pt-id.h:105
tree_argument_list * left_hand_side(void)
Definition: pt-loop.h:291
octave_function * fcn
Definition: ov-class.cc:1743
tree_identifier * ident(void)
Definition: pt-decl.h:87
tree_decl_init_list * initializer_list(void)
Definition: pt-decl.h:162
void visit_simple_for_command(tree_simple_for_command &)
Definition: pt-check.cc:140
void visit_unwind_protect_command(tree_unwind_protect_command &)
Definition: pt-check.cc:517
tree_statement_list * body(void)
Definition: pt-loop.h:295
tree_expression * increment(void)
Definition: pt-colon.h:91
tree_if_command_list * cmd_list(void)
Definition: pt-select.h:137
void visit_binary_expression(tree_binary_expression &)
Definition: pt-check.cc:50
tree_statement_list * body(void)
Definition: pt-loop.h:214
void visit_if_command_list(tree_if_command_list &)
Definition: pt-check.cc:254
tree_expression * maxproc_expr(void)
Definition: pt-loop.h:212
void accept(tree_walker &tw)
Definition: pt-id.cc:153
iterator end(void)
Definition: base-list.h:86
tree_expression * right_hand_side(void)
Definition: pt-assign.h:74
std::list< tree_argument_list * > arg_lists(void)
Definition: pt-idx.h:76
tree_expression * condition(void)
Definition: pt-select.h:61
tree_expression * control_expr(void)
Definition: pt-loop.h:210
void visit_function_def(tree_function_def &)
Definition: pt-check.cc:216
void accept(tree_walker &tw)
Definition: pt-stmt.cc:185
void visit_anon_fcn_handle(tree_anon_fcn_handle &)
Definition: pt-check.cc:341
void visit_argument_list(tree_argument_list &)
Definition: pt-check.cc:33
void visit_return_list(tree_return_list &)
Definition: pt-check.cc:393
tree_expression * limit(void)
Definition: pt-colon.h:89
octave_value function(void)
Definition: pt-cmd.h:118
tree_statement_list * body(void)
Definition: pt-except.h:125
tree_expression * lhs(void)
Definition: pt-binop.h:97
tree_expression * left_hand_side(void)
Definition: pt-loop.h:208
tree_statement_list * body(void)
Definition: pt-except.h:61
void accept(tree_walker &tw)
Definition: pt-decl.cc:100
void accept(tree_walker &tw)
Definition: pt-select.cc:183
void visit_parameter_list(tree_parameter_list &)
Definition: pt-check.cc:357
tree_statement_list * commands(void)
Definition: pt-select.h:193
void visit_index_expression(tree_index_expression &)
Definition: pt-check.cc:268
tree_statement_list * cleanup(void)
Definition: pt-except.h:63
void visit_colon_expression(tree_colon_expression &)
Definition: pt-check.cc:68
virtual int line(void) const
Definition: pt.h:49
void visit_persistent_command(tree_persistent_command &)
Definition: pt-check.cc:106
octave::base_list< tree_argument_list * >::iterator iterator
Definition: pt-array-list.h:41
octave_function * function_value(bool silent=false) const
Definition: ov.cc:1705
void visit_simple_assignment(tree_simple_assignment &)
Definition: pt-check.cc:407
void accept(tree_walker &tw)
bool do_lvalue_check
Definition: pt-check.h:130
void visit_octave_user_function(octave_user_function &)
Definition: pt-check.cc:207
tree_statement_list * body(void)
Definition: ov-usr-fcn.h:142
OCTAVE_NORETURN void errmsg(const std::string &msg, int line)
Definition: pt-check.cc:559
void visit_switch_case(tree_switch_case &)
Definition: pt-check.cc:452
void visit_funcall(tree_funcall &)
Definition: pt-check.cc:353
tree_expression * rhs(void)
Definition: pt-binop.h:98
void visit_constant(tree_constant &)
Definition: pt-check.cc:345
void visit_fcn_handle(tree_fcn_handle &)
Definition: pt-check.cc:349
void visit_decl_elt(tree_decl_elt &)
Definition: pt-check.cc:112
void visit_break_command(tree_break_command &)
Definition: pt-check.cc:64
p
Definition: lu.cc:138
tree_expression * expression(void)
Definition: pt-stmt.h:86
void accept(tree_walker &tw)
Definition: pt-idx.cc:703
size_t length(void) const
Definition: base-list.h:50
void accept(tree_walker &tw)
Definition: pt-decl.cc:76
tree_expression * expression(void)
Definition: pt-decl.h:91
void accept(tree_walker &tw)
Definition: pt-select.cc:81
void visit_complex_for_command(tree_complex_for_command &)
Definition: pt-check.cc:167
void accept(tree_walker &tw)
Definition: pt-select.cc:57
virtual void accept(tree_walker &)
Definition: ov-fcn.h:179
void visit_matrix(tree_matrix &)
Definition: pt-check.cc:289
tree_expression * base(void)
Definition: pt-colon.h:87
tree_statement_list * body(void)
Definition: pt-loop.h:84
void visit_statement(tree_statement &)
Definition: pt-check.cc:424
void visit_switch_case_list(tree_switch_case_list &)
Definition: pt-check.cc:466
void visit_global_command(tree_global_command &)
Definition: pt-check.cc:100
tree_statement_list * body(void)
Definition: ov-usr-fcn.h:381
void visit_while_command(tree_while_command &)
Definition: pt-check.cc:531
std::string file_name
Definition: pt-check.h:132
tree_expression * right_hand_side(void)
Definition: pt-assign.h:141
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854
void visit_multi_assignment(tree_multi_assignment &)
Definition: pt-check.cc:317
virtual void accept(tree_walker &tw)=0
void visit_do_until_command(tree_do_until_command &)
Definition: pt-check.cc:545
void visit_octave_user_script(octave_user_script &)
Definition: pt-check.cc:198
void visit_switch_command(tree_switch_command &)
Definition: pt-check.cc:480
iterator begin(void)
Definition: base-list.h:83
void visit_return_command(tree_return_command &)
Definition: pt-check.cc:389
void visit_no_op_command(tree_no_op_command &)
Definition: pt-check.cc:337
tree_expression * condition(void)
Definition: pt-loop.h:82