3771
|
1 /* |
|
2 |
|
3 Copyright (C) 2001 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 2, or (at your option) any |
|
10 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, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if defined (__GNUG__) |
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
|
31 #include "ov-usr-fcn.h" |
|
32 #include "ov-list.h" |
|
33 #include "pager.h" |
|
34 #include "pt-all.h" |
|
35 |
|
36 void |
|
37 tree_breakpoint::take_action (tree &tr) |
|
38 { |
|
39 if (act == set) |
|
40 { |
|
41 tr.set_breakpoint (); |
|
42 line = tr.line (); |
|
43 found = true; |
|
44 } |
|
45 else if (act == clear) |
|
46 { |
|
47 tr.delete_breakpoint (); |
|
48 found = true; |
|
49 } |
|
50 else if (act == list) |
|
51 { |
|
52 if (tr.is_breakpoint ()) |
|
53 { |
3805
|
54 bp_list.append (octave_value (static_cast<double> (tr.line ()))); |
3771
|
55 line = tr.line () + 1; |
|
56 } |
|
57 } |
|
58 else |
|
59 panic_impossible (); |
|
60 |
|
61 return; |
|
62 } |
|
63 |
|
64 void |
|
65 tree_breakpoint::visit_while_command (tree_while_command& cmd) |
|
66 { |
|
67 if (found) |
|
68 return; |
|
69 |
|
70 if (cmd.line () >= line) |
|
71 take_action (cmd); |
|
72 |
|
73 tree_expression *expr = cmd.condition (); |
|
74 |
|
75 if (expr) |
|
76 expr->accept (*this); |
|
77 |
|
78 tree_statement_list *list = cmd.body (); |
|
79 |
|
80 if (list) |
|
81 list->accept (*this); |
|
82 } |
|
83 |
|
84 void |
|
85 tree_breakpoint::visit_do_until_command (tree_do_until_command& cmd) |
|
86 { |
3805
|
87 if (found) |
|
88 return; |
3771
|
89 |
|
90 if (cmd.line () >= line) |
|
91 take_action (cmd); |
|
92 |
3805
|
93 tree_statement_list *lst = cmd.body (); |
|
94 |
3771
|
95 if (lst) |
|
96 lst->accept (*this); |
|
97 |
|
98 if (found) |
|
99 return; |
|
100 |
|
101 tree_expression *expr = cmd.condition (); |
|
102 |
|
103 if (expr) |
|
104 expr->accept (*this); |
|
105 } |
|
106 |
|
107 void |
|
108 tree_breakpoint::visit_argument_list (tree_argument_list& lst) |
|
109 { |
|
110 if (found) |
|
111 return; |
|
112 |
|
113 for (Pix p = lst.first (); p != 0; lst.next (p)) |
|
114 { |
|
115 tree_expression *elt = lst(p); |
|
116 |
|
117 if (elt) |
|
118 elt->accept (*this); |
|
119 } |
|
120 } |
|
121 |
|
122 void |
|
123 tree_breakpoint::visit_binary_expression (tree_binary_expression& expr) |
|
124 { |
|
125 if (found) |
|
126 return; |
|
127 |
|
128 tree_expression *lhs = expr.lhs (); |
|
129 tree_expression *rhs = expr.rhs (); |
|
130 |
|
131 if (lhs && lhs->line () >= line) |
3805
|
132 lhs->accept (*this); |
3771
|
133 |
|
134 if (rhs && rhs->line () >= line) |
3805
|
135 rhs->accept (*this); |
3771
|
136 } |
|
137 |
|
138 void |
|
139 tree_breakpoint::visit_break_command (tree_break_command& cmd) |
|
140 { |
|
141 if (found) |
|
142 return; |
|
143 |
|
144 if (cmd.line () >= line) |
|
145 take_action (cmd); |
|
146 } |
|
147 |
|
148 void |
|
149 tree_breakpoint::visit_colon_expression (tree_colon_expression& expr) |
|
150 { |
|
151 if (found) |
|
152 return; |
|
153 |
3805
|
154 if (expr.line () >= line) |
|
155 take_action (expr); |
|
156 |
3771
|
157 tree_expression *base = expr.base (); |
|
158 |
|
159 if (base) |
|
160 base->accept (*this); |
|
161 |
|
162 tree_expression *increment = expr.increment (); |
|
163 |
|
164 if (increment) |
|
165 increment->accept (*this); |
|
166 |
|
167 tree_expression *limit = expr.limit (); |
|
168 |
|
169 if (limit) |
|
170 limit->accept (*this); |
|
171 } |
|
172 |
|
173 void |
|
174 tree_breakpoint::visit_continue_command (tree_continue_command& cmd) |
|
175 { |
|
176 if (found) |
|
177 return; |
|
178 |
|
179 if (cmd.line () >= line) |
|
180 take_action (cmd); |
|
181 } |
|
182 |
|
183 void |
|
184 tree_breakpoint::visit_decl_command (tree_decl_command& cmd) |
|
185 { |
|
186 if (found) |
|
187 return; |
|
188 |
|
189 tree_decl_init_list *init_list = cmd.initializer_list (); |
|
190 |
|
191 if (init_list) |
|
192 init_list->accept (*this); |
|
193 } |
|
194 |
|
195 void |
|
196 tree_breakpoint::visit_decl_elt (tree_decl_elt& cmd) |
|
197 { |
|
198 if (found) |
|
199 return; |
|
200 |
|
201 tree_identifier *ident = cmd.ident (); |
|
202 |
|
203 if (ident) |
|
204 ident->accept (*this); |
|
205 |
|
206 tree_expression *expr = cmd.expression (); |
|
207 |
|
208 if (expr) |
|
209 expr->accept (*this); |
|
210 |
|
211 } |
|
212 |
|
213 void |
|
214 tree_breakpoint::visit_decl_init_list (tree_decl_init_list& lst) |
|
215 { |
|
216 if (found) |
|
217 return; |
|
218 |
|
219 for (Pix p = lst.first (); p != 0; lst.next (p)) |
|
220 { |
|
221 tree_decl_elt *elt = lst(p); |
|
222 |
|
223 if (elt) |
|
224 elt->accept (*this); |
|
225 } |
|
226 } |
|
227 |
|
228 void |
|
229 tree_breakpoint::visit_simple_for_command (tree_simple_for_command& cmd) |
|
230 { |
|
231 if (found) |
|
232 return; |
|
233 |
|
234 if (cmd.line () >= line) |
|
235 take_action (cmd); |
|
236 |
|
237 tree_expression *expr = cmd.control_expr (); |
|
238 |
|
239 if (expr) |
|
240 expr->accept (*this); |
|
241 |
|
242 tree_statement_list *list = cmd.body (); |
|
243 |
|
244 if (list) |
|
245 list->accept (*this); |
|
246 } |
|
247 |
|
248 void |
|
249 tree_breakpoint::visit_complex_for_command (tree_complex_for_command& cmd) |
|
250 { |
|
251 if (found) |
|
252 return; |
|
253 |
|
254 if (cmd.line () >= line) |
|
255 take_action (cmd); |
|
256 |
|
257 tree_expression *expr = cmd.control_expr (); |
|
258 |
|
259 if (expr) |
|
260 expr->accept (*this); |
|
261 |
|
262 tree_statement_list *list = cmd.body (); |
|
263 |
|
264 if (list) |
|
265 list->accept (*this); |
|
266 |
|
267 } |
|
268 |
|
269 void |
|
270 tree_breakpoint::visit_octave_user_function (octave_user_function& cmd) |
|
271 { |
|
272 // we should not visit octave user functions because the function we are currently |
|
273 // in is the function where the breakpoint was requested |
|
274 } |
|
275 |
|
276 void |
|
277 tree_breakpoint::visit_octave_user_function_header (octave_user_function& cmd) |
|
278 { |
|
279 // Do nothing |
|
280 } |
|
281 |
|
282 void |
|
283 tree_breakpoint::visit_octave_user_function_trailer (octave_user_function& cmd) |
|
284 { |
|
285 // Do nothing |
|
286 } |
|
287 |
|
288 void |
|
289 tree_breakpoint::visit_identifier (tree_identifier& id) |
|
290 { |
|
291 if (found) |
|
292 return; |
|
293 |
|
294 if (id.line () >= line ) |
|
295 take_action (id); |
|
296 } |
|
297 |
|
298 void |
|
299 tree_breakpoint::visit_if_clause (tree_if_clause& cmd) |
|
300 { |
|
301 if (found) |
|
302 return; |
|
303 |
|
304 tree_expression *expr = cmd.condition (); |
|
305 |
|
306 if (expr) |
|
307 expr->accept (*this); |
|
308 |
|
309 tree_statement_list *list = cmd.commands (); |
|
310 |
|
311 if (list) |
|
312 list->accept (*this); |
|
313 } |
|
314 |
|
315 void |
|
316 tree_breakpoint::visit_if_command (tree_if_command& cmd) |
|
317 { |
|
318 if (found) |
|
319 return; |
|
320 |
|
321 tree_if_command_list *list = cmd.cmd_list (); |
|
322 |
|
323 if (list) |
|
324 list->accept (*this); |
|
325 } |
|
326 |
|
327 void |
|
328 tree_breakpoint::visit_if_command_list (tree_if_command_list& lst) |
|
329 { |
|
330 if (found) |
|
331 return; |
|
332 |
|
333 for (Pix p = lst.first (); p != 0; lst.next (p)) |
|
334 { |
|
335 tree_if_clause *elt = lst(p); |
|
336 |
|
337 if (elt) |
|
338 elt->accept (*this); |
|
339 } |
|
340 } |
|
341 |
|
342 void |
|
343 tree_breakpoint::visit_index_expression (tree_index_expression& cmd) |
|
344 { |
|
345 if (found) |
|
346 return; |
|
347 |
3930
|
348 if (cmd.expr_type () == tree_index_expression::dot) |
|
349 { |
|
350 if (cmd.line () >= line) |
|
351 take_action (cmd); |
|
352 } |
|
353 else |
|
354 { |
|
355 tree_expression *expr = cmd.expression (); |
3771
|
356 |
3930
|
357 if (expr && expr->line () >= line) |
|
358 take_action (*expr); |
3771
|
359 |
3930
|
360 tree_argument_list *lst = cmd.arg_list (); |
3771
|
361 |
3930
|
362 if (lst) |
|
363 lst->accept (*this); |
|
364 } |
3771
|
365 } |
|
366 |
|
367 void |
|
368 tree_breakpoint::visit_matrix (tree_matrix& mat) |
|
369 { |
|
370 if (found) |
|
371 return; |
|
372 |
|
373 Pix p = mat.first (); |
|
374 |
|
375 while (p) |
|
376 { |
|
377 tree_argument_list *elt = mat (p); |
|
378 mat.next (p); |
|
379 |
|
380 if (elt) |
|
381 elt->accept (*this); |
|
382 } |
|
383 } |
|
384 |
|
385 void |
|
386 tree_breakpoint::visit_cell (tree_cell& cell) |
|
387 { |
|
388 if (found) |
|
389 return; |
|
390 |
|
391 Pix p = cell.first (); |
|
392 |
|
393 while (p) |
|
394 { |
|
395 tree_argument_list *elt = cell (p); |
|
396 cell.next (p); |
|
397 |
|
398 if (elt) |
|
399 elt->accept (*this); |
|
400 } |
|
401 } |
|
402 |
|
403 void |
|
404 tree_breakpoint::visit_multi_assignment (tree_multi_assignment& expr) |
|
405 { |
|
406 if (found) |
|
407 return; |
|
408 |
|
409 tree_argument_list *list = expr.left_hand_side (); |
|
410 |
|
411 if (list) |
|
412 list->accept (*this); |
|
413 |
|
414 tree_expression *rhs = expr.right_hand_side (); |
|
415 |
|
416 if (rhs) |
|
417 rhs->accept (*this); |
|
418 } |
|
419 |
|
420 void |
|
421 tree_breakpoint::visit_no_op_command (tree_no_op_command& cmd) |
|
422 { |
|
423 if (found) |
|
424 return; |
|
425 |
|
426 if (cmd.line () >= line) |
|
427 take_action (cmd); |
|
428 } |
|
429 |
|
430 void |
|
431 tree_breakpoint::visit_constant (tree_constant& cmd) |
|
432 { |
|
433 if (found) |
|
434 return; |
|
435 |
|
436 if (cmd.line () >= line) |
|
437 take_action (cmd); |
|
438 } |
|
439 |
|
440 void |
|
441 tree_breakpoint::visit_parameter_list (tree_parameter_list& lst) |
|
442 { |
|
443 if (found) |
|
444 return; |
|
445 |
|
446 Pix p = lst.first (); |
|
447 |
|
448 while (p) |
|
449 { |
|
450 tree_identifier *elt = lst(p); |
|
451 lst.next (p); |
|
452 |
|
453 if (elt) |
|
454 elt->accept (*this); |
|
455 } |
|
456 } |
|
457 |
|
458 void |
|
459 tree_breakpoint::visit_plot_command (tree_plot_command& cmd) |
|
460 { |
|
461 if (found) |
|
462 return; |
|
463 |
|
464 // Don't bother looking at the range plot list since they must be |
|
465 // on the same line. |
|
466 |
|
467 if (cmd.line () >= line) |
|
468 take_action (cmd); |
|
469 } |
|
470 |
|
471 void |
|
472 tree_breakpoint::visit_plot_limits (plot_limits& cmd) |
|
473 { |
|
474 // Do nothing. This case will be handled in visit_tree_plot_command. |
|
475 } |
|
476 |
|
477 void |
|
478 tree_breakpoint::visit_plot_range (plot_range& cmd) |
|
479 { |
|
480 // Do nothing. This case will be handled in visit_tree_plot_command. |
|
481 } |
|
482 |
|
483 void |
|
484 tree_breakpoint::visit_postfix_expression (tree_postfix_expression& expr) |
|
485 { |
|
486 if (found) |
|
487 return; |
|
488 |
|
489 if (expr.line () >= line) |
|
490 take_action (expr); |
|
491 |
|
492 tree_expression *e = expr.operand (); |
|
493 |
|
494 if (e) |
|
495 e->accept (*this); |
|
496 } |
|
497 |
|
498 void |
|
499 tree_breakpoint::visit_prefix_expression (tree_prefix_expression& expr) |
|
500 { |
|
501 if (found) |
|
502 return; |
|
503 |
|
504 if (expr.line () >= line) |
|
505 take_action (expr); |
|
506 |
|
507 tree_expression *e = expr.operand (); |
|
508 |
|
509 if (e) |
|
510 e->accept (*this); |
|
511 } |
|
512 |
|
513 void |
|
514 tree_breakpoint::visit_return_command (tree_return_command& cmd) |
|
515 { |
|
516 if (found) |
|
517 return; |
|
518 |
|
519 if (cmd.line () >= line) |
|
520 take_action (cmd); |
|
521 } |
|
522 |
|
523 void |
|
524 tree_breakpoint::visit_return_list (tree_return_list& lst) |
|
525 { |
|
526 if (found) |
|
527 return; |
|
528 |
|
529 Pix p = lst.first (); |
|
530 |
|
531 while (p) |
|
532 { |
|
533 tree_index_expression *elt = lst(p); |
|
534 lst.next (p); |
|
535 |
|
536 if (elt) |
|
537 elt->accept (*this); |
|
538 } |
|
539 } |
|
540 |
|
541 void |
|
542 tree_breakpoint::visit_simple_assignment (tree_simple_assignment& expr) |
|
543 { |
|
544 if (found) |
|
545 return; |
|
546 |
|
547 if (expr.line () >= line) |
|
548 take_action (expr); |
|
549 |
|
550 } |
|
551 |
|
552 void |
|
553 tree_breakpoint::visit_statement (tree_statement& stmt) |
|
554 { |
|
555 if (found) |
|
556 return; |
|
557 |
|
558 tree_command *cmd = stmt.command (); |
|
559 |
|
560 if (cmd) |
|
561 cmd->accept (*this); |
|
562 else |
|
563 { |
|
564 tree_expression *expr = stmt.expression (); |
|
565 |
|
566 if (expr) |
|
567 expr->accept (*this); |
|
568 } |
|
569 } |
|
570 |
|
571 void |
|
572 tree_breakpoint::visit_statement_list (tree_statement_list& lst) |
|
573 { |
|
574 if (found) |
|
575 return; |
|
576 |
|
577 for (Pix p = lst.first (); p != 0; lst.next (p)) |
|
578 { |
|
579 tree_statement *elt = lst(p); |
|
580 |
|
581 if (elt) |
|
582 elt->accept (*this); |
|
583 } |
|
584 } |
|
585 |
|
586 void |
|
587 tree_breakpoint::visit_subplot (subplot& cmd) |
|
588 { |
|
589 // Do nothing. This case will be handled in visit_tree_plot_command. |
|
590 } |
|
591 |
|
592 void |
|
593 tree_breakpoint::visit_subplot_axes (subplot_axes& cmd) |
|
594 { |
|
595 // Do nothing. This caser will be handled in visit_tree_plot_command. |
|
596 } |
|
597 |
|
598 void |
|
599 tree_breakpoint::visit_subplot_list (subplot_list& cmd) |
|
600 { |
|
601 // Do nothing. This case will be handled in visit_tree_plot_command. |
|
602 } |
|
603 |
|
604 void |
|
605 tree_breakpoint::visit_subplot_style (subplot_style& cmd) |
|
606 { |
|
607 // Do nothing. This case will be handled in visit_tree_plot_command. |
|
608 } |
|
609 |
|
610 void |
|
611 tree_breakpoint::visit_subplot_using (subplot_using& cmd) |
|
612 { |
|
613 // Do nothing. This case will be handled in visit_tree_plot_command. |
|
614 } |
|
615 |
|
616 void |
|
617 tree_breakpoint::visit_switch_case (tree_switch_case& cmd) |
|
618 { |
|
619 if (found) |
|
620 return; |
|
621 |
|
622 // Disallow breakpoints on the label. |
|
623 |
|
624 tree_statement_list *lst = cmd.commands (); |
|
625 |
|
626 if (lst) |
|
627 lst->accept (*this); |
|
628 } |
|
629 |
|
630 void |
|
631 tree_breakpoint::visit_switch_case_list (tree_switch_case_list& lst) |
|
632 { |
|
633 if (found) |
|
634 return; |
|
635 |
|
636 Pix p = lst.first (); |
|
637 |
|
638 while (p) |
|
639 { |
|
640 tree_switch_case *elt = lst(p); |
|
641 |
|
642 if (elt) |
|
643 elt->accept (*this); |
|
644 |
|
645 lst.next (p); |
|
646 } |
|
647 } |
|
648 |
|
649 |
|
650 void |
|
651 tree_breakpoint::visit_switch_command (tree_switch_command& cmd) |
|
652 { |
|
653 if (found) |
|
654 return; |
|
655 |
|
656 tree_expression *expr = cmd.switch_value (); |
|
657 |
|
658 if (expr) |
|
659 expr->accept (*this); |
|
660 |
|
661 tree_switch_case_list *lst = cmd.case_list (); |
|
662 |
|
663 if (lst) |
|
664 lst->accept (*this); |
|
665 } |
|
666 |
|
667 void |
|
668 tree_breakpoint::visit_try_catch_command (tree_try_catch_command& cmd) |
|
669 { |
|
670 if (found) |
|
671 return; |
|
672 |
|
673 if (cmd.line () >= line) |
|
674 take_action (cmd); |
|
675 |
|
676 tree_statement_list *try_code = cmd.body (); |
|
677 |
|
678 if (try_code) |
|
679 try_code->accept (*this); |
|
680 |
|
681 tree_statement_list *catch_code = cmd.cleanup (); |
|
682 |
|
683 if (catch_code) |
|
684 catch_code->accept (*this); |
|
685 } |
|
686 |
|
687 void |
|
688 tree_breakpoint::visit_unwind_protect_command (tree_unwind_protect_command& cmd) |
|
689 { |
|
690 if (found) |
|
691 return; |
|
692 |
|
693 if (cmd.line () >= line) |
|
694 take_action (cmd); |
|
695 |
|
696 tree_statement_list *lst1 = cmd.body (); |
|
697 |
|
698 if (lst1) |
|
699 lst1->accept (*this); |
|
700 |
|
701 tree_statement_list *lst2 = cmd.cleanup (); |
|
702 |
|
703 if (lst2) |
|
704 lst2->accept (*this); |
|
705 } |
|
706 |
|
707 /* |
|
708 ;;; Local Variables: *** |
|
709 ;;; mode: C++ *** |
|
710 ;;; End: *** |
|
711 */ |