GNU Octave  4.4.1
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-2018 Ben Sapp
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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License 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 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include "ov-usr-fcn.h"
28 #include "pager.h"
29 #include "pt-all.h"
30 
31 namespace octave
32 {
33  // TRUE means SIGINT should put us in the debugger at the next
34  // available breakpoint.
36 
37  void
39  {
40  if (cmd.line () >= m_line)
41  take_action (cmd);
42 
43  if (! m_found)
44  {
45  tree_statement_list *lst = cmd.body ();
46 
47  if (lst)
48  lst->accept (*this);
49  }
50  }
51 
52  void
54  {
55  if (! m_found)
56  {
57  tree_statement_list *lst = cmd.body ();
58 
59  if (lst)
60  lst->accept (*this);
61 
62  if (! m_found)
63  {
64  if (cmd.line () >= m_line)
65  take_action (cmd);
66  }
67  }
68  }
69 
70  void
72  {
74  }
75 
76  void
78  {
80  }
81 
82  void
84  {
85  if (cmd.line () >= m_line)
86  take_action (cmd);
87  }
88 
89  void
91  {
93  }
94 
95  void
97  {
98  if (cmd.line () >= m_line)
99  take_action (cmd);
100  }
101 
102  void
104  {
105  if (cmd.line () >= m_line)
106  take_action (cmd);
107  }
108 
109  void
111  {
112  panic_impossible ();
113  }
114 
115  void
117  {
118  panic_impossible ();
119  }
120 
121  void
123  {
124  if (cmd.line () >= m_line)
125  take_action (cmd);
126 
127  if (! m_found)
128  {
129  tree_statement_list *lst = cmd.body ();
130 
131  if (lst)
132  lst->accept (*this);
133  }
134  }
135 
136  void
138  {
139  if (cmd.line () >= m_line)
140  take_action (cmd);
141 
142  if (! m_found)
143  {
144  tree_statement_list *lst = cmd.body ();
145 
146  if (lst)
147  lst->accept (*this);
148  }
149  }
150 
151  void
153  {
154  tree_statement_list *cmd_list = fcn.body ();
155 
156  if (cmd_list)
157  cmd_list->accept (*this);
158  }
159 
160  void
162  {
163  tree_statement_list *cmd_list = fcn.body ();
164 
165  if (cmd_list)
166  cmd_list->accept (*this);
167  }
168 
169  void
171  {
172  panic_impossible ();
173  }
174 
175  void
177  {
178  panic_impossible ();
179  }
180 
181  void
183  {
184  octave_value fcn = fdef.function ();
185 
187 
188  if (f)
189  f->accept (*this);
190  }
191 
192  void
194  {
195  panic_impossible ();
196  }
197 
198  void
200  {
201  panic_impossible ();
202  }
203 
204  void
206  {
207  tree_if_command_list *lst = cmd.cmd_list ();
208 
209  if (lst)
210  lst->accept (*this);
211  }
212 
213  void
215  {
216  for (tree_if_clause *t : lst)
217  {
218  if (t->line () >= m_line)
219  take_action (*t);
220 
221  if (! m_found)
222  {
223  tree_statement_list *stmt_lst = t->commands ();
224 
225  if (stmt_lst)
226  stmt_lst->accept (*this);
227  }
228 
229  if (m_found)
230  break;
231  }
232  }
233 
234  void
236  {
237  panic_impossible ();
238  }
239 
240  void
242  {
243  panic_impossible ();
244  }
245 
246  void
248  {
249  panic_impossible ();
250  }
251 
252  void
254  {
255  panic_impossible ();
256  }
257 
258  void
260  {
261  if (cmd.is_end_of_fcn_or_script () && cmd.line () >= m_line)
262  take_action (cmd);
263  }
264 
265  void
267  {
268  panic_impossible ();
269  }
270 
271  void
273  {
274  panic_impossible ();
275  }
276 
277  void
279  {
280  panic_impossible ();
281  }
282 
283  void
285  {
286  panic_impossible ();
287  }
288 
289  void
291  {
292  panic_impossible ();
293  }
294 
295  void
297  {
298  panic_impossible ();
299  }
300 
301  void
303  {
304  panic_impossible ();
305  }
306 
307  void
309  {
310  if (cmd.line () >= m_line)
311  take_action (cmd);
312  }
313 
314  void
316  {
317  panic_impossible ();
318  }
319 
320  void
322  {
323  panic_impossible ();
324  }
325 
326  void
328  {
329  if (stmt.is_command ())
330  {
331  tree_command *cmd = stmt.command ();
332 
333  cmd->accept (*this);
334  }
335  else
336  {
337  if (stmt.line () >= m_line)
338  take_action (stmt);
339  }
340  }
341 
342  // Called by
343  // tree_statement_list::set_breakpoint (int line, std::string& condition)
344  // with <lst> consisting of a user function in which to set a breakpoint.
345  void
347  {
348  for (tree_statement *elt : lst)
349  {
350  if (elt)
351  {
352  elt->accept (*this);
353 
354  if (m_found)
355  break;
356  }
357  }
358  }
359 
360  void
362  {
363  panic_impossible ();
364  }
365 
366  void
368  {
369  for (tree_switch_case *t : lst)
370  {
371  if (t->line () >= m_line)
372  take_action (*t);
373 
374  if (! m_found)
375  {
376  tree_statement_list *stmt_lst = t->commands ();
377 
378  if (stmt_lst)
379  stmt_lst->accept (*this);
380  }
381 
382  if (m_found)
383  break;
384  }
385  }
386 
387  void
389  {
390  if (cmd.line () >= m_line)
391  take_action (cmd);
392 
393  if (! m_found)
394  {
395  tree_switch_case_list *lst = cmd.case_list ();
396 
397  if (lst)
398  lst->accept (*this);
399  }
400  }
401 
402  void
404  {
405  tree_statement_list *try_code = cmd.body ();
406 
407  if (try_code)
408  try_code->accept (*this);
409 
410  if (! m_found)
411  {
412  tree_statement_list *catch_code = cmd.cleanup ();
413 
414  if (catch_code)
415  catch_code->accept (*this);
416  }
417  }
418 
419  void
421  {
422  tree_statement_list *body = cmd.body ();
423 
424  if (body)
425  body->accept (*this);
426 
427  if (! m_found)
428  {
429  tree_statement_list *cleanup = cmd.cleanup ();
430 
431  if (cleanup)
432  cleanup->accept (*this);
433  }
434  }
435 
436  void
438  {
439  if (m_action == set)
440  {
442  m_line = tr.line ();
443  m_found = true;
444  }
445  else if (m_action == clear)
446  {
447  if (tr.is_breakpoint ())
448  {
449  tr.delete_breakpoint ();
450  m_found = true;
451  }
452  }
453  else if (m_action == list)
454  {
455  if (tr.is_breakpoint ())
456  {
457  m_bp_list.append (octave_value (tr.line ()));
459  }
460  }
461  else
462  panic_impossible ();
463  }
464 
465  void
467  {
468  int lineno = stmt.line ();
469 
470  if (m_action == set)
471  {
473  m_line = lineno;
474  m_found = true;
475  }
476  else if (m_action == clear)
477  {
478  if (stmt.is_breakpoint ())
479  {
480  stmt.delete_breakpoint ();
481  m_found = true;
482  }
483  }
484  else if (m_action == list)
485  {
486  if (stmt.is_breakpoint ())
487  {
488  m_bp_list.append (octave_value (lineno));
490  }
491  }
492  else
493  panic_impossible ();
494  }
495 }
void visit_if_clause(tree_if_clause &)
Definition: pt-bp.cc:199
void visit_postfix_expression(tree_postfix_expression &)
Definition: pt-bp.cc:296
virtual int line(void) const
Definition: pt.h:56
void visit_decl_elt(tree_decl_elt &)
Definition: pt-bp.cc:116
void visit_identifier(tree_identifier &)
Definition: pt-bp.cc:193
void delete_breakpoint(void)
Definition: pt-stmt.cc:83
std::string bp_cond() const
Definition: pt-stmt.cc:99
void visit_octave_user_script(octave_user_script &)
Definition: pt-bp.cc:152
void visit_statement(tree_statement &)
Definition: pt-bp.cc:327
int line(void) const
Definition: pt-stmt.cc:107
tree_statement_list * cleanup(void)
Definition: pt-except.h:138
void visit_decl_command(tree_decl_command &)
Definition: pt-bp.cc:103
octave_value_list m_bp_cond_list
Definition: pt-bp.h:174
void visit_function_def(tree_function_def &)
Definition: pt-bp.cc:182
void visit_prefix_expression(tree_prefix_expression &)
Definition: pt-bp.cc:302
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 const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE * f
void visit_switch_case(tree_switch_case &)
Definition: pt-bp.cc:361
octave_value_list & append(const octave_value &val)
Definition: ovl.cc:83
void visit_return_command(tree_return_command &)
Definition: pt-bp.cc:308
void visit_octave_user_function_trailer(octave_user_function &)
Definition: pt-bp.cc:176
virtual void accept(tree_walker &tw)=0
void visit_octave_user_function_header(octave_user_function &)
Definition: pt-bp.cc:170
void visit_multi_assignment(tree_multi_assignment &)
Definition: pt-bp.cc:253
void accept(tree_walker &tw)
Definition: pt-select.h:113
void visit_do_until_command(tree_do_until_command &)
Definition: pt-bp.cc:53
void visit_decl_init_list(tree_decl_init_list &)
Definition: pt-bp.cc:110
tree_statement_list * body(void)
Definition: pt-loop.h:87
bool is_breakpoint(bool check_active=false) const
Definition: pt.h:90
bool is_breakpoint(bool check_valid=false) const
Definition: pt-stmt.cc:92
void visit_index_expression(tree_index_expression &)
Definition: pt-bp.cc:235
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function t
Definition: ov-usr-fcn.cc:997
octave_value function(void)
Definition: pt-cmd.h:116
void visit_matrix(tree_matrix &)
Definition: pt-bp.cc:241
void visit_unwind_protect_command(tree_unwind_protect_command &)
Definition: pt-bp.cc:420
void visit_break_command(tree_break_command &)
Definition: pt-bp.cc:83
void visit_octave_user_function(octave_user_function &)
Definition: pt-bp.cc:161
void visit_while_command(tree_while_command &)
Definition: pt-bp.cc:38
void visit_statement_list(tree_statement_list &)
Definition: pt-bp.cc:346
void take_action(tree &tr)
Definition: pt-bp.cc:437
octave_function * fcn
Definition: ov-class.cc:1754
void visit_switch_case_list(tree_switch_case_list &)
Definition: pt-bp.cc:367
void visit_funcall(tree_funcall &)
Definition: pt-bp.cc:284
void visit_try_catch_command(tree_try_catch_command &)
Definition: pt-bp.cc:403
void visit_argument_list(tree_argument_list &)
Definition: pt-bp.cc:71
void visit_no_op_command(tree_no_op_command &)
Definition: pt-bp.cc:259
void visit_fcn_handle(tree_fcn_handle &)
Definition: pt-bp.cc:278
void visit_if_command_list(tree_if_command_list &)
Definition: pt-bp.cc:214
tree_statement_list * cleanup(void)
Definition: pt-except.h:71
void set_breakpoint(const std::string &condition)
Definition: pt-stmt.cc:74
void accept(tree_walker &tw)
Definition: pt-stmt.h:188
void visit_if_command(tree_if_command &)
Definition: pt-bp.cc:205
#define panic_impossible()
Definition: error.h:40
void visit_simple_assignment(tree_simple_assignment &)
Definition: pt-bp.cc:321
void visit_cell(tree_cell &)
Definition: pt-bp.cc:247
octave_value_list m_bp_list
Definition: pt-bp.h:171
bool octave_debug_on_interrupt_state
Definition: pt-bp.cc:35
tree_command * command(void)
Definition: pt-stmt.h:90
std::string m_condition
Definition: pt-bp.h:165
void visit_anon_fcn_handle(tree_anon_fcn_handle &)
Definition: pt-bp.cc:266
void visit_simple_for_command(tree_simple_for_command &)
Definition: pt-bp.cc:122
bool is_command(void) const
Definition: pt-stmt.h:72
tree_statement_list * body(void)
Definition: pt-except.h:136
tree_statement_list * body(void)
Definition: pt-loop.h:211
void visit_colon_expression(tree_colon_expression &)
Definition: pt-bp.cc:90
void visit_parameter_list(tree_parameter_list &)
Definition: pt-bp.cc:290
tree_statement_list * body(void)
Definition: pt-loop.h:295
void visit_constant(tree_constant &)
Definition: pt-bp.cc:272
const std::string bp_cond(void) const
Definition: pt.h:97
void visit_switch_command(tree_switch_command &)
Definition: pt-bp.cc:388
void visit_complex_for_command(tree_complex_for_command &)
Definition: pt-bp.cc:137
virtual octave_function * function_value(bool silent=false)
Definition: ov-base.cc:871
void visit_return_list(tree_return_list &)
Definition: pt-bp.cc:315
virtual void delete_breakpoint(void)
Definition: pt.h:78
void visit_binary_expression(tree_binary_expression &)
Definition: pt-bp.cc:77
void visit_continue_command(tree_continue_command &)
Definition: pt-bp.cc:96
bool is_end_of_fcn_or_script(void) const
Definition: pt-cmd.h:78
tree_statement_list * body(void)
Definition: pt-except.h:69
void accept(tree_walker &tw)
Definition: pt-select.h:238
tree_switch_case_list * case_list(void)
Definition: pt-select.h:268
tree_if_command_list * cmd_list(void)
Definition: pt-select.h:140
virtual void set_breakpoint(const std::string &condition)
Definition: pt.h:70