GNU Octave
3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
libinterp
parse-tree
pt-bp.cc
Go to the documentation of this file.
1
/*
2
3
Copyright (C) 2001-2013 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 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
#ifdef 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
// TRUE means SIGINT should put us in the debugger at the next
32
// available breakpoint.
33
bool
octave_debug_on_interrupt_state
=
false
;
34
35
void
36
tree_breakpoint::visit_while_command
(
tree_while_command
& cmd)
37
{
38
if
(cmd.
line
() >=
line
)
39
take_action
(cmd);
40
41
if
(!
found
)
42
{
43
tree_statement_list
*lst = cmd.
body
();
44
45
if
(lst)
46
lst->
accept
(*
this
);
47
}
48
}
49
50
void
51
tree_breakpoint::visit_do_until_command
(
tree_do_until_command
& cmd)
52
{
53
if
(!
found
)
54
{
55
tree_statement_list
*lst = cmd.
body
();
56
57
if
(lst)
58
lst->
accept
(*
this
);
59
60
if
(!
found
)
61
{
62
if
(cmd.
line
() >=
line
)
63
take_action
(cmd);
64
}
65
}
66
}
67
68
void
69
tree_breakpoint::visit_argument_list
(
tree_argument_list
&)
70
{
71
panic_impossible
();
72
}
73
74
void
75
tree_breakpoint::visit_binary_expression
(
tree_binary_expression
&)
76
{
77
panic_impossible
();
78
}
79
80
void
81
tree_breakpoint::visit_break_command
(
tree_break_command
& cmd)
82
{
83
if
(cmd.
line
() >=
line
)
84
take_action
(cmd);
85
}
86
87
void
88
tree_breakpoint::visit_colon_expression
(
tree_colon_expression
&)
89
{
90
panic_impossible
();
91
}
92
93
void
94
tree_breakpoint::visit_continue_command
(
tree_continue_command
& cmd)
95
{
96
if
(cmd.
line
() >=
line
)
97
take_action
(cmd);
98
}
99
100
void
101
tree_breakpoint::do_decl_command
(
tree_decl_command
& cmd)
102
{
103
if
(cmd.
line
() >=
line
)
104
take_action
(cmd);
105
}
106
107
void
108
tree_breakpoint::visit_global_command
(
tree_global_command
& cmd)
109
{
110
do_decl_command
(cmd);
111
}
112
113
void
114
tree_breakpoint::visit_persistent_command
(
tree_persistent_command
& cmd)
115
{
116
do_decl_command
(cmd);
117
}
118
119
void
120
tree_breakpoint::visit_decl_elt
(
tree_decl_elt
&)
121
{
122
panic_impossible
();
123
}
124
125
void
126
tree_breakpoint::visit_decl_init_list
(
tree_decl_init_list
&)
127
{
128
panic_impossible
();
129
}
130
131
void
132
tree_breakpoint::visit_simple_for_command
(
tree_simple_for_command
& cmd)
133
{
134
if
(cmd.
line
() >=
line
)
135
take_action
(cmd);
136
137
if
(!
found
)
138
{
139
tree_statement_list
*lst = cmd.
body
();
140
141
if
(lst)
142
lst->
accept
(*
this
);
143
}
144
}
145
146
void
147
tree_breakpoint::visit_complex_for_command
(
tree_complex_for_command
& cmd)
148
{
149
if
(cmd.
line
() >=
line
)
150
take_action
(cmd);
151
152
if
(!
found
)
153
{
154
tree_statement_list
*lst = cmd.
body
();
155
156
if
(lst)
157
lst->
accept
(*
this
);
158
}
159
}
160
161
void
162
tree_breakpoint::visit_octave_user_script
(
octave_user_script
& fcn)
163
{
164
tree_statement_list
*cmd_list = fcn.
body
();
165
166
if
(cmd_list)
167
cmd_list->
accept
(*
this
);
168
}
169
170
void
171
tree_breakpoint::visit_octave_user_function
(
octave_user_function
& fcn)
172
{
173
tree_statement_list
*cmd_list = fcn.
body
();
174
175
if
(cmd_list)
176
cmd_list->
accept
(*
this
);
177
}
178
179
void
180
tree_breakpoint::visit_octave_user_function_header
(
octave_user_function
&)
181
{
182
panic_impossible
();
183
}
184
185
void
186
tree_breakpoint::visit_octave_user_function_trailer
(
octave_user_function
&)
187
{
188
panic_impossible
();
189
}
190
191
void
192
tree_breakpoint::visit_function_def
(
tree_function_def
& fdef)
193
{
194
octave_value
fcn = fdef.
function
();
195
196
octave_function
*
f
= fcn.
function_value
();
197
198
if
(f)
199
f->
accept
(*
this
);
200
}
201
202
void
203
tree_breakpoint::visit_identifier
(
tree_identifier
&)
204
{
205
panic_impossible
();
206
}
207
208
void
209
tree_breakpoint::visit_if_clause
(
tree_if_clause
&)
210
{
211
panic_impossible
();
212
}
213
214
void
215
tree_breakpoint::visit_if_command
(
tree_if_command
& cmd)
216
{
217
tree_if_command_list
*lst = cmd.
cmd_list
();
218
219
if
(lst)
220
lst->
accept
(*
this
);
221
}
222
223
void
224
tree_breakpoint::visit_if_command_list
(
tree_if_command_list
& lst)
225
{
226
for
(
tree_if_command_list::iterator
p = lst.
begin
(); p != lst.
end
(); p++)
227
{
228
tree_if_clause
*t = *p;
229
230
if
(t->
line
() >=
line
)
231
take_action
(*t);
232
233
if
(!
found
)
234
{
235
tree_statement_list
*stmt_lst = t->
commands
();
236
237
if
(stmt_lst)
238
stmt_lst->
accept
(*
this
);
239
}
240
241
if
(
found
)
242
break
;
243
}
244
}
245
246
void
247
tree_breakpoint::visit_index_expression
(
tree_index_expression
&)
248
{
249
panic_impossible
();
250
}
251
252
void
253
tree_breakpoint::visit_matrix
(
tree_matrix
&)
254
{
255
panic_impossible
();
256
}
257
258
void
259
tree_breakpoint::visit_cell
(
tree_cell
&)
260
{
261
panic_impossible
();
262
}
263
264
void
265
tree_breakpoint::visit_multi_assignment
(
tree_multi_assignment
&)
266
{
267
panic_impossible
();
268
}
269
270
void
271
tree_breakpoint::visit_no_op_command
(
tree_no_op_command
& cmd)
272
{
273
if
(cmd.
is_end_of_fcn_or_script
() && cmd.
line
() >=
line
)
274
take_action
(cmd);
275
}
276
277
void
278
tree_breakpoint::visit_anon_fcn_handle
(
tree_anon_fcn_handle
&)
279
{
280
panic_impossible
();
281
}
282
283
void
284
tree_breakpoint::visit_constant
(
tree_constant
&)
285
{
286
panic_impossible
();
287
}
288
289
void
290
tree_breakpoint::visit_fcn_handle
(
tree_fcn_handle
&)
291
{
292
panic_impossible
();
293
}
294
295
void
296
tree_breakpoint::visit_parameter_list
(
tree_parameter_list
&)
297
{
298
panic_impossible
();
299
}
300
301
void
302
tree_breakpoint::visit_postfix_expression
(
tree_postfix_expression
&)
303
{
304
panic_impossible
();
305
}
306
307
void
308
tree_breakpoint::visit_prefix_expression
(
tree_prefix_expression
&)
309
{
310
panic_impossible
();
311
}
312
313
void
314
tree_breakpoint::visit_return_command
(
tree_return_command
& cmd)
315
{
316
if
(cmd.
line
() >=
line
)
317
take_action
(cmd);
318
}
319
320
void
321
tree_breakpoint::visit_return_list
(
tree_return_list
&)
322
{
323
panic_impossible
();
324
}
325
326
void
327
tree_breakpoint::visit_simple_assignment
(
tree_simple_assignment
&)
328
{
329
panic_impossible
();
330
}
331
332
void
333
tree_breakpoint::visit_statement
(
tree_statement
& stmt)
334
{
335
if
(stmt.
is_command
())
336
{
337
tree_command
*cmd = stmt.
command
();
338
339
cmd->
accept
(*
this
);
340
}
341
else
342
{
343
if
(stmt.
line
() >=
line
)
344
take_action
(stmt);
345
}
346
}
347
348
void
349
tree_breakpoint::visit_statement_list
(
tree_statement_list
& lst)
350
{
351
for
(
tree_statement_list::iterator
p = lst.
begin
(); p != lst.
end
(); p++)
352
{
353
tree_statement
*elt = *p;
354
355
if
(elt)
356
{
357
elt->
accept
(*
this
);
358
359
if
(
found
)
360
break
;
361
}
362
}
363
}
364
365
void
366
tree_breakpoint::visit_switch_case
(
tree_switch_case
&)
367
{
368
panic_impossible
();
369
}
370
371
void
372
tree_breakpoint::visit_switch_case_list
(
tree_switch_case_list
& lst)
373
{
374
for
(
tree_switch_case_list::iterator
p = lst.
begin
(); p != lst.
end
(); p++)
375
{
376
tree_switch_case
*t = *p;
377
378
if
(t->
line
() >=
line
)
379
take_action
(*t);
380
381
if
(!
found
)
382
{
383
tree_statement_list
*stmt_lst = t->
commands
();
384
385
if
(stmt_lst)
386
stmt_lst->
accept
(*
this
);
387
}
388
389
if
(
found
)
390
break
;
391
}
392
}
393
394
void
395
tree_breakpoint::visit_switch_command
(
tree_switch_command
& cmd)
396
{
397
if
(cmd.
line
() >=
line
)
398
take_action
(cmd);
399
400
if
(!
found
)
401
{
402
tree_switch_case_list
*lst = cmd.
case_list
();
403
404
if
(lst)
405
lst->
accept
(*
this
);
406
}
407
}
408
409
void
410
tree_breakpoint::visit_try_catch_command
(
tree_try_catch_command
& cmd)
411
{
412
tree_statement_list
*try_code = cmd.
body
();
413
414
if
(try_code)
415
try_code->
accept
(*
this
);
416
417
if
(!
found
)
418
{
419
tree_statement_list
*catch_code = cmd.
cleanup
();
420
421
if
(catch_code)
422
catch_code->
accept
(*
this
);
423
}
424
}
425
426
void
427
tree_breakpoint::visit_unwind_protect_command
(
tree_unwind_protect_command
& cmd)
428
{
429
tree_statement_list
*body = cmd.
body
();
430
431
if
(body)
432
body->
accept
(*
this
);
433
434
if
(!
found
)
435
{
436
tree_statement_list
*cleanup = cmd.
cleanup
();
437
438
if
(cleanup)
439
cleanup->
accept
(*
this
);
440
}
441
}
442
443
void
444
tree_breakpoint::take_action
(
tree
& tr)
445
{
446
if
(
act
==
set
)
447
{
448
tr.
set_breakpoint
();
449
line
= tr.
line
();
450
found
=
true
;
451
}
452
else
if
(
act
==
clear
)
453
{
454
if
(tr.
is_breakpoint
())
455
{
456
tr.
delete_breakpoint
();
457
found
=
true
;
458
}
459
}
460
else
if
(
act
==
list
)
461
{
462
if
(tr.
is_breakpoint
())
463
bp_list
.
append
(
octave_value
(tr.
line
()));
464
}
465
else
466
panic_impossible
();
467
}
468
469
void
470
tree_breakpoint::take_action
(
tree_statement
& stmt)
471
{
472
int
lineno = stmt.
line
();
473
474
if
(
act
==
set
)
475
{
476
stmt.
set_breakpoint
();
477
line
= lineno;
478
found
=
true
;
479
}
480
else
if
(
act
==
clear
)
481
{
482
if
(stmt.
is_breakpoint
())
483
{
484
stmt.
delete_breakpoint
();
485
found
=
true
;
486
}
487
}
488
else
if
(
act
==
list
)
489
{
490
if
(stmt.
is_breakpoint
())
491
bp_list
.
append
(
octave_value
(lineno));
492
}
493
else
494
panic_impossible
();
495
}
Generated on Mon Dec 30 2013 03:04:37 for GNU Octave by
1.8.1.2