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 { |
|
54 lst.append (octave_value (static_cast<double> (tr.line ()))); |
|
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 { |
|
87 tree_statement_list *lst = cmd.body (); |
|
88 |
|
89 if (cmd.line () >= line) |
|
90 take_action (cmd); |
|
91 |
|
92 if (lst) |
|
93 lst->accept (*this); |
|
94 |
|
95 if (found) |
|
96 return; |
|
97 |
|
98 tree_expression *expr = cmd.condition (); |
|
99 |
|
100 if (expr) |
|
101 expr->accept (*this); |
|
102 } |
|
103 |
|
104 void |
|
105 tree_breakpoint::visit_argument_list (tree_argument_list& lst) |
|
106 { |
|
107 if (found) |
|
108 return; |
|
109 |
|
110 for (Pix p = lst.first (); p != 0; lst.next (p)) |
|
111 { |
|
112 tree_expression *elt = lst(p); |
|
113 |
|
114 if (elt) |
|
115 elt->accept (*this); |
|
116 } |
|
117 } |
|
118 |
|
119 void |
|
120 tree_breakpoint::visit_binary_expression (tree_binary_expression& expr) |
|
121 { |
|
122 if (found) |
|
123 return; |
|
124 |
|
125 tree_expression *lhs = expr.lhs (); |
|
126 tree_expression *rhs = expr.rhs (); |
|
127 |
|
128 if (lhs && lhs->line () >= line) |
|
129 { |
|
130 take_action (expr); |
|
131 return; |
|
132 } |
|
133 |
|
134 if (rhs && rhs->line () >= line) |
|
135 take_action (expr); |
|
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 |
|
154 tree_expression *base = expr.base (); |
|
155 |
|
156 if (base) |
|
157 base->accept (*this); |
|
158 |
|
159 tree_expression *increment = expr.increment (); |
|
160 |
|
161 if (increment) |
|
162 increment->accept (*this); |
|
163 |
|
164 tree_expression *limit = expr.limit (); |
|
165 |
|
166 if (limit) |
|
167 limit->accept (*this); |
|
168 } |
|
169 |
|
170 void |
|
171 tree_breakpoint::visit_continue_command (tree_continue_command& cmd) |
|
172 { |
|
173 if (found) |
|
174 return; |
|
175 |
|
176 if (cmd.line () >= line) |
|
177 take_action (cmd); |
|
178 } |
|
179 |
|
180 void |
|
181 tree_breakpoint::visit_decl_command (tree_decl_command& cmd) |
|
182 { |
|
183 if (found) |
|
184 return; |
|
185 |
|
186 tree_decl_init_list *init_list = cmd.initializer_list (); |
|
187 |
|
188 if (init_list) |
|
189 init_list->accept (*this); |
|
190 } |
|
191 |
|
192 void |
|
193 tree_breakpoint::visit_decl_elt (tree_decl_elt& cmd) |
|
194 { |
|
195 if (found) |
|
196 return; |
|
197 |
|
198 tree_identifier *ident = cmd.ident (); |
|
199 |
|
200 if (ident) |
|
201 ident->accept (*this); |
|
202 |
|
203 tree_expression *expr = cmd.expression (); |
|
204 |
|
205 if (expr) |
|
206 expr->accept (*this); |
|
207 |
|
208 } |
|
209 |
|
210 void |
|
211 tree_breakpoint::visit_decl_init_list (tree_decl_init_list& lst) |
|
212 { |
|
213 if (found) |
|
214 return; |
|
215 |
|
216 for (Pix p = lst.first (); p != 0; lst.next (p)) |
|
217 { |
|
218 tree_decl_elt *elt = lst(p); |
|
219 |
|
220 if (elt) |
|
221 elt->accept (*this); |
|
222 } |
|
223 } |
|
224 |
|
225 void |
|
226 tree_breakpoint::visit_simple_for_command (tree_simple_for_command& cmd) |
|
227 { |
|
228 if (found) |
|
229 return; |
|
230 |
|
231 if (cmd.line () >= line) |
|
232 take_action (cmd); |
|
233 |
|
234 tree_expression *expr = cmd.control_expr (); |
|
235 |
|
236 if (expr) |
|
237 expr->accept (*this); |
|
238 |
|
239 tree_statement_list *list = cmd.body (); |
|
240 |
|
241 if (list) |
|
242 list->accept (*this); |
|
243 } |
|
244 |
|
245 void |
|
246 tree_breakpoint::visit_complex_for_command (tree_complex_for_command& cmd) |
|
247 { |
|
248 if (found) |
|
249 return; |
|
250 |
|
251 if (cmd.line () >= line) |
|
252 take_action (cmd); |
|
253 |
|
254 tree_expression *expr = cmd.control_expr (); |
|
255 |
|
256 if (expr) |
|
257 expr->accept (*this); |
|
258 |
|
259 tree_statement_list *list = cmd.body (); |
|
260 |
|
261 if (list) |
|
262 list->accept (*this); |
|
263 |
|
264 } |
|
265 |
|
266 void |
|
267 tree_breakpoint::visit_octave_user_function (octave_user_function& cmd) |
|
268 { |
|
269 // we should not visit octave user functions because the function we are currently |
|
270 // in is the function where the breakpoint was requested |
|
271 } |
|
272 |
|
273 void |
|
274 tree_breakpoint::visit_octave_user_function_header (octave_user_function& cmd) |
|
275 { |
|
276 // Do nothing |
|
277 } |
|
278 |
|
279 void |
|
280 tree_breakpoint::visit_octave_user_function_trailer (octave_user_function& cmd) |
|
281 { |
|
282 // Do nothing |
|
283 } |
|
284 |
|
285 void |
|
286 tree_breakpoint::visit_identifier (tree_identifier& id) |
|
287 { |
|
288 if (found) |
|
289 return; |
|
290 |
|
291 if (id.line () >= line ) |
|
292 take_action (id); |
|
293 } |
|
294 |
|
295 void |
|
296 tree_breakpoint::visit_if_clause (tree_if_clause& cmd) |
|
297 { |
|
298 if (found) |
|
299 return; |
|
300 |
|
301 tree_expression *expr = cmd.condition (); |
|
302 |
|
303 if (expr) |
|
304 expr->accept (*this); |
|
305 |
|
306 tree_statement_list *list = cmd.commands (); |
|
307 |
|
308 if (list) |
|
309 list->accept (*this); |
|
310 } |
|
311 |
|
312 void |
|
313 tree_breakpoint::visit_if_command (tree_if_command& cmd) |
|
314 { |
|
315 if (found) |
|
316 return; |
|
317 |
|
318 tree_if_command_list *list = cmd.cmd_list (); |
|
319 |
|
320 if (list) |
|
321 list->accept (*this); |
|
322 } |
|
323 |
|
324 void |
|
325 tree_breakpoint::visit_if_command_list (tree_if_command_list& lst) |
|
326 { |
|
327 if (found) |
|
328 return; |
|
329 |
|
330 for (Pix p = lst.first (); p != 0; lst.next (p)) |
|
331 { |
|
332 tree_if_clause *elt = lst(p); |
|
333 |
|
334 if (elt) |
|
335 elt->accept (*this); |
|
336 } |
|
337 } |
|
338 |
|
339 void |
|
340 tree_breakpoint::visit_index_expression (tree_index_expression& cmd) |
|
341 { |
|
342 if (found) |
|
343 return; |
|
344 |
|
345 tree_expression *expr = cmd.expression (); |
|
346 |
|
347 if (expr) |
|
348 if (expr->line () >= line) |
|
349 take_action (*expr); |
|
350 |
|
351 tree_argument_list *lst = cmd.arg_list (); |
|
352 |
|
353 if (lst) |
|
354 lst->accept (*this); |
|
355 } |
|
356 |
|
357 void |
|
358 tree_breakpoint::visit_indirect_ref (tree_indirect_ref& cmd) |
|
359 { |
|
360 if (found) |
|
361 return; |
|
362 |
|
363 if (cmd.line () >= line) |
|
364 take_action (cmd); |
|
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 */ |