GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pt-walk.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2017-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if defined (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include "pt-all.h"
31 
32 namespace octave
33 {
35  {
36  // FIXME?
37  }
38 
40  {
41  auto p = lst.begin ();
42 
43  while (p != lst.end ())
44  {
45  tree_expression *elt = *p++;
46 
47  if (elt)
48  elt->accept (*this);
49  }
50  }
51 
53  {
54  tree_expression *op1 = expr.lhs ();
55 
56  if (op1)
57  op1->accept (*this);
58 
59  tree_expression *op2 = expr.rhs ();
60 
61  if (op2)
62  op2->accept (*this);
63  }
64 
66  {
68  }
69 
71  {
73  }
74 
76  {
77  // Nothing to do.
78  }
79 
81  {
82  tree_expression *op1 = expr.base ();
83 
84  if (op1)
85  op1->accept (*this);
86 
87  tree_expression *op3 = expr.increment ();
88 
89  if (op3)
90  op3->accept (*this);
91 
92  tree_expression *op2 = expr.limit ();
93 
94  if (op2)
95  op2->accept (*this);
96  }
97 
99  {
100  // Nothing to do.
101  }
102 
104  {
105  tree_decl_init_list *init_list = cmd.initializer_list ();
106 
107  if (init_list)
108  init_list->accept (*this);
109  }
110 
112  {
113  tree_identifier *id = cmd.ident ();
114 
115  if (id)
116  id->accept (*this);
117 
118  tree_expression *expr = cmd.expression ();
119 
120  if (expr)
121  expr->accept (*this);
122  }
123 
125  {
126  // FIXME: tree_decl_elt is not derived from tree, so should it
127  // really have an accept method?
128 
129  for (tree_decl_elt *elt : lst)
130  {
131  if (elt)
132  elt->accept (*this);
133  }
134  }
135 
137  {
138  tree_expression *lhs = cmd.left_hand_side ();
139 
140  if (lhs)
141  lhs->accept (*this);
142 
143  tree_expression *expr = cmd.control_expr ();
144 
145  if (expr)
146  expr->accept (*this);
147 
148  tree_expression *maxproc = cmd.maxproc_expr ();
149 
150  if (maxproc)
151  maxproc->accept (*this);
152 
153  tree_statement_list *list = cmd.body ();
154 
155  if (list)
156  list->accept (*this);
157  }
158 
160  {
161  tree_argument_list *lhs = cmd.left_hand_side ();
162 
163  if (lhs)
164  lhs->accept (*this);
165 
166  tree_expression *expr = cmd.control_expr ();
167 
168  if (expr)
169  expr->accept (*this);
170 
171  tree_statement_list *list = cmd.body ();
172 
173  if (list)
174  list->accept (*this);
175  }
176 
178  {
179  tree_statement_list *cmd_list = fcn.body ();
180 
181  if (cmd_list)
182  cmd_list->accept (*this);
183  }
184 
186  {
187  tree_statement_list *cmd_list = fcn.body ();
188 
189  if (cmd_list)
190  cmd_list->accept (*this);
191  }
192 
194  {
195  octave_value fcn = fdef.function ();
196 
197  octave_function *f = fcn.function_value ();
198 
199  if (f)
200  f->accept (*this);
201  }
202 
204  {
205  // Nothing to do.
206  }
207 
209  {
210  tree_expression *expr = cmd.condition ();
211 
212  if (expr)
213  expr->accept (*this);
214 
215  tree_statement_list *list = cmd.commands ();
216 
217  if (list)
218  list->accept (*this);
219  }
220 
222  {
223  tree_if_command_list *list = cmd.cmd_list ();
224 
225  if (list)
226  list->accept (*this);
227  }
228 
230  {
231  auto p = lst.begin ();
232 
233  while (p != lst.end ())
234  {
235  tree_if_clause *elt = *p++;
236 
237  if (elt)
238  elt->accept (*this);
239  }
240  }
241 
243  {
244  tree_expression *label = cs.case_label ();
245 
246  if (label)
247  label->accept (*this);
248 
249  tree_statement_list *list = cs.commands ();
250 
251  if (list)
252  list->accept (*this);
253  }
254 
256  {
257  auto p = lst.begin ();
258 
259  while (p != lst.end ())
260  {
261  tree_switch_case *elt = *p++;
262 
263  if (elt)
264  elt->accept (*this);
265  }
266  }
267 
269  {
270  tree_expression *expr = cmd.switch_value ();
271 
272  if (expr)
273  expr->accept (*this);
274 
275  tree_switch_case_list *list = cmd.case_list ();
276 
277  if (list)
278  list->accept (*this);
279  }
280 
282  {
283  tree_expression *e = expr.expression ();
284 
285  if (e)
286  e->accept (*this);
287 
288  std::list<tree_argument_list *> arg_lists = expr.arg_lists ();
289  std::list<string_vector> arg_names = expr.arg_names ();
290  std::list<tree_expression *> dyn_fields = expr.dyn_fields ();
291 
292  auto p_arg_lists = arg_lists.begin ();
293  auto p_arg_names = arg_names.begin ();
294  auto p_dyn_fields = dyn_fields.begin ();
295 
296  std::string type_tags = expr.type_tags ();
297  int n = type_tags.length ();
298 
299  for (int i = 0; i < n; i++)
300  {
301  switch (type_tags[i])
302  {
303  case '(':
304  case '{':
305  {
306  tree_argument_list *l = *p_arg_lists;
307  if (l)
308  l->accept (*this);
309  }
310  break;
311 
312  case '.':
313  {
314  std::string fn = (*p_arg_names)(0);
315  if (fn.empty ())
316  {
317  tree_expression *df = *p_dyn_fields;
318  if (df)
319  df->accept (*this);
320  }
321  }
322  break;
323 
324  default:
325  panic_impossible ();
326  }
327 
328  p_arg_lists++;
329  p_arg_names++;
330  p_dyn_fields++;
331  }
332  }
333 
335  {
336  auto p = lst.begin ();
337 
338  while (p != lst.end ())
339  {
340  tree_argument_list *elt = *p++;
341 
342  if (elt)
343  elt->accept (*this);
344  }
345  }
346 
348  {
349  auto p = lst.begin ();
350 
351  while (p != lst.end ())
352  {
353  tree_argument_list *elt = *p++;
354 
355  if (elt)
356  elt->accept (*this);
357  }
358  }
359 
361  {
362  tree_argument_list *lhs = expr.left_hand_side ();
363 
364  if (lhs)
365  lhs->accept (*this);
366 
367  tree_expression *rhs = expr.right_hand_side ();
368 
369  if (rhs)
370  rhs->accept (*this);
371  }
372 
374  {
375  // Nothing to do.
376  }
377 
379  {
380  // Nothing to do.
381  }
382 
384  {
385  // Nothing to do.
386  }
387 
389  {
390  auto p = lst.begin ();
391 
392  while (p != lst.end ())
393  {
394  tree_decl_elt *elt = *p++;
395 
396  if (elt)
397  elt->accept (*this);
398  }
399  }
400 
402  {
403  tree_expression *e = expr.operand ();
404 
405  if (e)
406  e->accept (*this);
407  }
408 
410  {
411  tree_expression *e = expr.operand ();
412 
413  if (e)
414  e->accept (*this);
415  }
416 
418  {
419  // Nothing to do.
420  }
421 
423  {
424  tree_expression *lhs = expr.left_hand_side ();
425 
426  if (lhs)
427  lhs->accept (*this);
428 
429  tree_expression *rhs = expr.right_hand_side ();
430 
431  if (rhs)
432  rhs->accept (*this);
433  }
434 
436  {
437  tree_command *cmd = stmt.command ();
438 
439  if (cmd)
440  cmd->accept (*this);
441  else
442  {
443  tree_expression *expr = stmt.expression ();
444 
445  if (expr)
446  expr->accept (*this);
447  }
448  }
449 
451  {
452  for (tree_statement *elt : lst)
453  {
454  if (elt)
455  elt->accept (*this);
456  }
457  }
458 
460  {
461  tree_statement_list *try_code = cmd.body ();
462 
463  if (try_code)
464  try_code->accept (*this);
465 
466  tree_identifier *expr_id = cmd.identifier ();
467 
468  if (expr_id)
469  expr_id->accept (*this);
470 
471  tree_statement_list *catch_code = cmd.cleanup ();
472 
473  if (catch_code)
474  catch_code->accept (*this);
475  }
476 
478  {
479  tree_statement_list *unwind_protect_code = cmd.body ();
480 
481  if (unwind_protect_code)
482  unwind_protect_code->accept (*this);
483 
484  tree_statement_list *cleanup_code = cmd.cleanup ();
485 
486  if (cleanup_code)
487  cleanup_code->accept (*this);
488  }
489 
491  {
492  tree_expression *expr = cmd.condition ();
493 
494  if (expr)
495  expr->accept (*this);
496 
497  tree_statement_list *list = cmd.body ();
498 
499  if (list)
500  list->accept (*this);
501  }
502 
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 
517  {
518  // FIXME?
519  }
520 
522  {
523  // FIXME?
524  }
525 
527  {
528  // FIXME?
529  }
530 
532  {
533  // FIXME?
534  }
535 
537  {
538  // FIXME?
539  }
540 
542  {
543  // FIXME?
544  }
545 
547  {
548  // FIXME?
549  }
550 
552  {
553  // FIXME?
554  }
555 
557  {
558  // FIXME?
559  }
560 
562  {
563  // FIXME?
564  }
565 
567  {
568  // FIXME?
569  }
570 
572  {
573  // FIXME?
574  }
575 
577  {
578  // FIXME?
579  }
580 
582  {
583  // FIXME?
584  }
585 
587  {
588  // FIXME?
589  }
590 
592  {
593  // FIXME?
594  }
595 
597  {
598  // FIXME?
599  }
600 
602  {
603  // FIXME?
604  }
605 
607  {
608  // FIXME?
609  }
610 }
iterator begin(void)
Definition: base-list.h:65
iterator end(void)
Definition: base-list.h:68
void accept(tree_walker &tw)
Definition: pt-arg-list.h:106
tree_expression * lhs(void)
Definition: pt-binop.h:96
tree_expression * rhs(void)
Definition: pt-binop.h:97
tree_expression * increment(void)
Definition: pt-colon.h:88
tree_expression * limit(void)
Definition: pt-colon.h:86
tree_expression * base(void)
Definition: pt-colon.h:84
tree_expression * control_expr(void)
Definition: pt-loop.h:296
tree_statement_list * body(void)
Definition: pt-loop.h:298
tree_argument_list * left_hand_side(void)
Definition: pt-loop.h:294
tree_decl_init_list * initializer_list(void)
Definition: pt-decl.h:201
tree_expression * expression(void)
Definition: pt-decl.h:92
void accept(tree_walker &tw)
Definition: pt-decl.h:96
tree_identifier * ident(void)
Definition: pt-decl.h:88
void accept(tree_walker &tw)
Definition: pt-decl.h:163
octave_value function(void)
Definition: pt-cmd.h:119
void accept(tree_walker &tw)
Definition: pt-id.h:105
tree_expression * condition(void)
Definition: pt-select.h:69
void accept(tree_walker &tw)
Definition: pt-select.h:75
tree_statement_list * commands(void)
Definition: pt-select.h:71
void accept(tree_walker &tw)
Definition: pt-select.h:116
tree_if_command_list * cmd_list(void)
Definition: pt-select.h:143
std::list< string_vector > arg_names(void)
Definition: pt-idx.h:89
std::string type_tags(void)
Definition: pt-idx.h:87
std::list< tree_argument_list * > arg_lists(void)
Definition: pt-idx.h:85
std::list< tree_expression * > dyn_fields(void)
Definition: pt-idx.h:91
tree_expression * expression(void)
Definition: pt-idx.h:83
tree_argument_list * left_hand_side(void)
Definition: pt-assign.h:148
tree_expression * right_hand_side(void)
Definition: pt-assign.h:150
tree_expression * right_hand_side(void)
Definition: pt-assign.h:79
tree_expression * left_hand_side(void)
Definition: pt-assign.h:77
tree_expression * control_expr(void)
Definition: pt-loop.h:210
tree_expression * left_hand_side(void)
Definition: pt-loop.h:208
tree_statement_list * body(void)
Definition: pt-loop.h:214
tree_expression * maxproc_expr(void)
Definition: pt-loop.h:212
void accept(tree_walker &tw)
Definition: pt-stmt.h:199
tree_expression * expression(void)
Definition: pt-stmt.h:101
tree_command * command(void)
Definition: pt-stmt.h:99
void accept(tree_walker &tw)
Definition: pt-select.h:241
tree_statement_list * commands(void)
Definition: pt-select.h:196
tree_expression * case_label(void)
Definition: pt-select.h:194
void accept(tree_walker &tw)
Definition: pt-select.h:200
tree_switch_case_list * case_list(void)
Definition: pt-select.h:271
tree_expression * switch_value(void)
Definition: pt-select.h:269
tree_statement_list * cleanup(void)
Definition: pt-except.h:74
tree_identifier * identifier(void)
Definition: pt-except.h:70
tree_statement_list * body(void)
Definition: pt-except.h:72
tree_expression * operand(void)
Definition: pt-unop.h:72
tree_statement_list * cleanup(void)
Definition: pt-except.h:141
tree_statement_list * body(void)
Definition: pt-except.h:139
virtual void visit_octave_user_script(octave_user_script &)
Definition: pt-walk.cc:177
virtual void visit_cell(tree_cell &)
Definition: pt-walk.cc:347
virtual void visit_classdef_property_list(tree_classdef_property_list &)
Definition: pt-walk.cc:551
virtual void visit_classdef_attribute(tree_classdef_attribute &)
Definition: pt-walk.cc:526
virtual void visit_statement_list(tree_statement_list &)
Definition: pt-walk.cc:450
virtual void visit_octave_user_function(octave_user_function &)
Definition: pt-walk.cc:185
virtual void visit_classdef_property(tree_classdef_property &)
Definition: pt-walk.cc:546
virtual void visit_simple_assignment(tree_simple_assignment &)
Definition: pt-walk.cc:422
virtual void visit_decl_init_list(tree_decl_init_list &)
Definition: pt-walk.cc:124
virtual void visit_classdef_events_block(tree_classdef_events_block &)
Definition: pt-walk.cc:581
virtual void visit_constant(tree_constant &)
Definition: pt-walk.cc:378
virtual void visit_classdef_methods_list(tree_classdef_methods_list &)
Definition: pt-walk.cc:561
virtual void visit_decl_command(tree_decl_command &)
Definition: pt-walk.cc:103
virtual void visit_return_command(tree_return_command &)
Definition: pt-walk.cc:417
virtual void visit_complex_for_command(tree_complex_for_command &)
Definition: pt-walk.cc:159
virtual void visit_identifier(tree_identifier &)
Definition: pt-walk.cc:203
virtual void visit_index_expression(tree_index_expression &)
Definition: pt-walk.cc:281
virtual void visit_prefix_expression(tree_prefix_expression &)
Definition: pt-walk.cc:409
virtual void visit_switch_case_list(tree_switch_case_list &)
Definition: pt-walk.cc:255
virtual void visit_binary_expression(tree_binary_expression &)
Definition: pt-walk.cc:52
virtual void visit_if_command_list(tree_if_command_list &)
Definition: pt-walk.cc:229
virtual void visit_if_clause(tree_if_clause &)
Definition: pt-walk.cc:208
virtual void visit_try_catch_command(tree_try_catch_command &)
Definition: pt-walk.cc:459
virtual void visit_boolean_expression(tree_boolean_expression &)
Definition: pt-walk.cc:65
virtual void visit_classdef(tree_classdef &)
Definition: pt-walk.cc:606
virtual void visit_classdef_body(tree_classdef_body &)
Definition: pt-walk.cc:601
virtual void visit_switch_case(tree_switch_case &)
Definition: pt-walk.cc:242
virtual void visit_break_command(tree_break_command &)
Definition: pt-walk.cc:75
virtual void visit_classdef_event(tree_classdef_event &)
Definition: pt-walk.cc:571
virtual void visit_classdef_enum_list(tree_classdef_enum_list &)
Definition: pt-walk.cc:591
virtual void visit_colon_expression(tree_colon_expression &)
Definition: pt-walk.cc:80
virtual void visit_classdef_superclass_list(tree_classdef_superclass_list &)
Definition: pt-walk.cc:541
virtual void visit_classdef_enum_block(tree_classdef_enum_block &)
Definition: pt-walk.cc:596
virtual void visit_decl_elt(tree_decl_elt &)
Definition: pt-walk.cc:111
virtual void visit_classdef_superclass(tree_classdef_superclass &)
Definition: pt-walk.cc:536
virtual void visit_compound_binary_expression(tree_compound_binary_expression &)
Definition: pt-walk.cc:70
virtual void visit_continue_command(tree_continue_command &)
Definition: pt-walk.cc:98
virtual void visit_switch_command(tree_switch_command &)
Definition: pt-walk.cc:268
virtual void visit_classdef_properties_block(tree_classdef_properties_block &)
Definition: pt-walk.cc:556
virtual void visit_multi_assignment(tree_multi_assignment &)
Definition: pt-walk.cc:360
virtual void visit_if_command(tree_if_command &)
Definition: pt-walk.cc:221
virtual void visit_classdef_methods_block(tree_classdef_methods_block &)
Definition: pt-walk.cc:566
virtual void visit_argument_list(tree_argument_list &)
Definition: pt-walk.cc:39
virtual void visit_matrix(tree_matrix &)
Definition: pt-walk.cc:334
virtual void visit_superclass_ref(tree_superclass_ref &)
Definition: pt-walk.cc:516
virtual void visit_no_op_command(tree_no_op_command &)
Definition: pt-walk.cc:373
virtual void visit_classdef_events_list(tree_classdef_events_list &)
Definition: pt-walk.cc:576
virtual void visit_simple_for_command(tree_simple_for_command &)
Definition: pt-walk.cc:136
virtual void visit_statement(tree_statement &)
Definition: pt-walk.cc:435
virtual void visit_classdef_attribute_list(tree_classdef_attribute_list &)
Definition: pt-walk.cc:531
virtual void visit_while_command(tree_while_command &)
Definition: pt-walk.cc:490
virtual void visit_anon_fcn_handle(tree_anon_fcn_handle &)
Definition: pt-walk.cc:34
virtual void visit_do_until_command(tree_do_until_command &)
Definition: pt-walk.cc:503
virtual void visit_classdef_enum(tree_classdef_enum &)
Definition: pt-walk.cc:586
virtual void visit_metaclass_query(tree_metaclass_query &)
Definition: pt-walk.cc:521
virtual void visit_postfix_expression(tree_postfix_expression &)
Definition: pt-walk.cc:401
virtual void visit_parameter_list(tree_parameter_list &)
Definition: pt-walk.cc:388
virtual void visit_function_def(tree_function_def &)
Definition: pt-walk.cc:193
virtual void visit_fcn_handle(tree_fcn_handle &)
Definition: pt-walk.cc:383
virtual void visit_unwind_protect_command(tree_unwind_protect_command &)
Definition: pt-walk.cc:477
tree_statement_list * body(void)
Definition: pt-loop.h:90
tree_expression * condition(void)
Definition: pt-loop.h:88
virtual void accept(tree_walker &tw)=0
octave::tree_statement_list * body(void)
Definition: ov-usr-fcn.h:123
octave_function * function_value(bool silent=false) const
#define panic_impossible()
Definition: error.h:380
octave_idx_type n
Definition: mx-inlines.cc:753
static double f(double k, double l_nu, double c_pm)
Definition: randpoisson.cc:118