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