GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pt-bp.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2001-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 "ov-usr-fcn.h"
31 #include "pager.h"
32 #include "pt-all.h"
33 
34 namespace octave
35 {
36  void
38  {
39  if (cmd.line () >= m_line)
40  take_action (cmd);
41 
42  if (! m_found)
43  {
44  tree_statement_list *lst = cmd.body ();
45 
46  if (lst)
47  lst->accept (*this);
48  }
49  }
50 
51  void
53  {
54  if (! m_found)
55  {
56  tree_statement_list *lst = cmd.body ();
57 
58  if (lst)
59  lst->accept (*this);
60 
61  if (! m_found)
62  {
63  if (cmd.line () >= m_line)
64  take_action (cmd);
65  }
66  }
67  }
68 
69  void
71  {
73  }
74 
75  void
77  {
79  }
80 
81  void
83  {
84  if (cmd.line () >= m_line)
85  take_action (cmd);
86  }
87 
88  void
90  {
92  }
93 
94  void
96  {
97  if (cmd.line () >= m_line)
98  take_action (cmd);
99  }
100 
101  void
103  {
104  if (cmd.line () >= m_line)
105  take_action (cmd);
106  }
107 
108  void
110  {
111  panic_impossible ();
112  }
113 
114  void
116  {
117  panic_impossible ();
118  }
119 
120  void
122  {
123  if (cmd.line () >= m_line)
124  take_action (cmd);
125 
126  if (! m_found)
127  {
128  tree_statement_list *lst = cmd.body ();
129 
130  if (lst)
131  lst->accept (*this);
132  }
133  }
134 
135  void
137  {
138  if (cmd.line () >= m_line)
139  take_action (cmd);
140 
141  if (! m_found)
142  {
143  tree_statement_list *lst = cmd.body ();
144 
145  if (lst)
146  lst->accept (*this);
147  }
148  }
149 
150  void
152  {
153  panic_impossible ();
154  }
155 
156  void
158  {
159  panic_impossible ();
160  }
161 
162  void
164  {
165  panic_impossible ();
166  }
167 
168  void
170  {
171  panic_impossible ();
172  }
173 
174  void
176  {
177  for (tree_if_clause *t : lst)
178  {
179  if (t->line () >= m_line)
180  take_action (*t);
181 
182  if (! m_found)
183  {
184  tree_statement_list *stmt_lst = t->commands ();
185 
186  if (stmt_lst)
187  stmt_lst->accept (*this);
188  }
189 
190  if (m_found)
191  break;
192  }
193  }
194 
195  void
197  {
198  panic_impossible ();
199  }
200 
201  void
203  {
204  panic_impossible ();
205  }
206 
207  void
209  {
210  panic_impossible ();
211  }
212 
213  void
215  {
216  panic_impossible ();
217  }
218 
219  void
221  {
222  if (cmd.is_end_of_fcn_or_script () && cmd.line () >= m_line)
223  take_action (cmd);
224  }
225 
226  void
228  {
229  panic_impossible ();
230  }
231 
232  void
234  {
235  panic_impossible ();
236  }
237 
238  void
240  {
241  panic_impossible ();
242  }
243 
244  void
246  {
247  panic_impossible ();
248  }
249 
250  void
252  {
253  panic_impossible ();
254  }
255 
256  void
258  {
259  panic_impossible ();
260  }
261 
262  void
264  {
265  if (cmd.line () >= m_line)
266  take_action (cmd);
267  }
268 
269  void
271  {
272  panic_impossible ();
273  }
274 
275  void
277  {
278  if (stmt.is_command ())
279  {
280  tree_command *cmd = stmt.command ();
281 
282  cmd->accept (*this);
283  }
284  else
285  {
286  if (stmt.line () >= m_line)
287  take_action (stmt);
288  }
289  }
290 
291  // Called by
292  // tree_statement_list::set_breakpoint (int line, std::string& condition)
293  // with <lst> consisting of a user function in which to set a breakpoint.
294  void
296  {
297  for (tree_statement *elt : lst)
298  {
299  if (elt)
300  {
301  elt->accept (*this);
302 
303  if (m_found)
304  break;
305  }
306  }
307  }
308 
309  void
311  {
312  panic_impossible ();
313  }
314 
315  void
317  {
318  for (tree_switch_case *t : lst)
319  {
320  if (t->line () >= m_line)
321  take_action (*t);
322 
323  if (! m_found)
324  {
325  tree_statement_list *stmt_lst = t->commands ();
326 
327  if (stmt_lst)
328  stmt_lst->accept (*this);
329  }
330 
331  if (m_found)
332  break;
333  }
334  }
335 
336  void
338  {
339  if (cmd.line () >= m_line)
340  take_action (cmd);
341 
342  if (! m_found)
343  {
344  tree_switch_case_list *lst = cmd.case_list ();
345 
346  if (lst)
347  lst->accept (*this);
348  }
349  }
350 
351  void
353  {
354  tree_statement_list *try_code = cmd.body ();
355 
356  if (try_code)
357  try_code->accept (*this);
358 
359  if (! m_found)
360  {
361  tree_statement_list *catch_code = cmd.cleanup ();
362 
363  if (catch_code)
364  catch_code->accept (*this);
365  }
366  }
367 
368  void
370  {
371  tree_statement_list *body = cmd.body ();
372 
373  if (body)
374  body->accept (*this);
375 
376  if (! m_found)
377  {
378  tree_statement_list *cleanup = cmd.cleanup ();
379 
380  if (cleanup)
381  cleanup->accept (*this);
382  }
383  }
384 
385  void
387  {
388  if (m_action == set)
389  {
391  m_line = tr.line ();
392  m_found = true;
393  }
394  else if (m_action == clear)
395  {
396  if (tr.is_breakpoint ())
397  {
398  tr.delete_breakpoint ();
399  m_found = true;
400  }
401  }
402  else if (m_action == list)
403  {
404  if (tr.is_breakpoint ())
405  {
406  m_bp_list.append (octave_value (tr.line ()));
408  }
409  }
410  else
411  panic_impossible ();
412  }
413 
414  void
416  {
417  int lineno = stmt.line ();
418 
419  if (m_action == set)
420  {
422  m_line = lineno;
423  m_found = true;
424  }
425  else if (m_action == clear)
426  {
427  if (stmt.is_breakpoint ())
428  {
429  stmt.delete_breakpoint ();
430  m_found = true;
431  }
432  }
433  else if (m_action == list)
434  {
435  if (stmt.is_breakpoint ())
436  {
437  m_bp_list.append (octave_value (lineno));
439  }
440  }
441  else
442  panic_impossible ();
443  }
444 }
void visit_identifier(tree_identifier &)
Definition: pt-bp.cc:163
std::string m_condition
Definition: pt-bp.h:157
void visit_octave_user_function_trailer(octave_user_function &)
Definition: pt-bp.cc:157
void visit_prefix_expression(tree_prefix_expression &)
Definition: pt-bp.cc:257
void visit_continue_command(tree_continue_command &)
Definition: pt-bp.cc:95
void visit_if_clause(tree_if_clause &)
Definition: pt-bp.cc:169
octave_value_list m_bp_list
Definition: pt-bp.h:163
void visit_while_command(tree_while_command &)
Definition: pt-bp.cc:37
void visit_simple_assignment(tree_simple_assignment &)
Definition: pt-bp.cc:270
void visit_no_op_command(tree_no_op_command &)
Definition: pt-bp.cc:220
void visit_try_catch_command(tree_try_catch_command &)
Definition: pt-bp.cc:352
void visit_parameter_list(tree_parameter_list &)
Definition: pt-bp.cc:245
void visit_anon_fcn_handle(tree_anon_fcn_handle &)
Definition: pt-bp.cc:227
void visit_constant(tree_constant &)
Definition: pt-bp.cc:233
void visit_fcn_handle(tree_fcn_handle &)
Definition: pt-bp.cc:239
void take_action(tree &tr)
Definition: pt-bp.cc:386
void visit_break_command(tree_break_command &)
Definition: pt-bp.cc:82
void visit_complex_for_command(tree_complex_for_command &)
Definition: pt-bp.cc:136
void visit_argument_list(tree_argument_list &)
Definition: pt-bp.cc:70
octave_value_list m_bp_cond_list
Definition: pt-bp.h:166
void visit_colon_expression(tree_colon_expression &)
Definition: pt-bp.cc:89
void visit_decl_command(tree_decl_command &)
Definition: pt-bp.cc:102
void visit_simple_for_command(tree_simple_for_command &)
Definition: pt-bp.cc:121
void visit_binary_expression(tree_binary_expression &)
Definition: pt-bp.cc:76
void visit_statement_list(tree_statement_list &)
Definition: pt-bp.cc:295
void visit_octave_user_function_header(octave_user_function &)
Definition: pt-bp.cc:151
void visit_switch_case_list(tree_switch_case_list &)
Definition: pt-bp.cc:316
void visit_matrix(tree_matrix &)
Definition: pt-bp.cc:202
void visit_switch_case(tree_switch_case &)
Definition: pt-bp.cc:310
void visit_if_command_list(tree_if_command_list &)
Definition: pt-bp.cc:175
void visit_decl_init_list(tree_decl_init_list &)
Definition: pt-bp.cc:109
void visit_cell(tree_cell &)
Definition: pt-bp.cc:208
void visit_switch_command(tree_switch_command &)
Definition: pt-bp.cc:337
void visit_return_command(tree_return_command &)
Definition: pt-bp.cc:263
void visit_multi_assignment(tree_multi_assignment &)
Definition: pt-bp.cc:214
void visit_unwind_protect_command(tree_unwind_protect_command &)
Definition: pt-bp.cc:369
void visit_decl_elt(tree_decl_elt &)
Definition: pt-bp.cc:115
void visit_do_until_command(tree_do_until_command &)
Definition: pt-bp.cc:52
void visit_statement(tree_statement &)
Definition: pt-bp.cc:276
void visit_postfix_expression(tree_postfix_expression &)
Definition: pt-bp.cc:251
void visit_index_expression(tree_index_expression &)
Definition: pt-bp.cc:196
tree_statement_list * body(void)
Definition: pt-loop.h:298
bool is_end_of_fcn_or_script(void) const
Definition: pt-cmd.h:81
tree_statement_list * body(void)
Definition: pt-loop.h:214
void accept(tree_walker &tw)
Definition: pt-stmt.h:199
bool is_command(void) const
Definition: pt-stmt.h:78
int line(void) const
Definition: pt-stmt.cc:117
void delete_breakpoint(void)
Definition: pt-stmt.cc:86
bool is_breakpoint(void) const
Definition: pt-stmt.cc:95
void set_breakpoint(const std::string &condition)
Definition: pt-stmt.cc:77
std::string bp_cond() const
Definition: pt-stmt.cc:109
tree_command * command(void)
Definition: pt-stmt.h:99
void accept(tree_walker &tw)
Definition: pt-select.h:241
tree_switch_case_list * case_list(void)
Definition: pt-select.h:271
tree_statement_list * cleanup(void)
Definition: pt-except.h:74
tree_statement_list * body(void)
Definition: pt-except.h:72
tree_statement_list * cleanup(void)
Definition: pt-except.h:141
tree_statement_list * body(void)
Definition: pt-except.h:139
tree_statement_list * body(void)
Definition: pt-loop.h:90
virtual void delete_breakpoint(void)
Definition: pt.h:82
const std::string bp_cond(void) const
Definition: pt.h:106
virtual void accept(tree_walker &tw)=0
virtual int line(void) const
Definition: pt.h:60
virtual void set_breakpoint(const std::string &condition)
Definition: pt.h:74
bool is_breakpoint(void) const
Definition: pt.h:94
octave_value_list & append(const octave_value &val)
Definition: ovl.cc:98
#define panic_impossible()
Definition: error.h:380