Mercurial > octave
annotate src/pt-stmt.cc @ 8843:b9ce57a309a3
don't store breakpoint info in tree_statement object
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 23 Feb 2009 12:44:57 -0500 |
parents | 33783e94fb16 |
children | c84a5b6377c4 |
rev | line source |
---|---|
2982 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003, 2004, 2005, |
4 2006, 2007 John W. Eaton | |
2982 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2982 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2982 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
28 #include <typeinfo> |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
29 |
4153 | 30 #include "quit.h" |
31 | |
2982 | 32 #include "defun.h" |
33 #include "error.h" | |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7890
diff
changeset
|
34 #include "gripes.h" |
2982 | 35 #include "ov.h" |
36 #include "oct-lvalue.h" | |
37 #include "input.h" | |
38 #include "pager.h" | |
3770 | 39 #include "pt-bp.h" |
2982 | 40 #include "pt-cmd.h" |
41 #include "pt-id.h" | |
42 #include "pt-idx.h" | |
2985 | 43 #include "pt-jump.h" |
2982 | 44 #include "pt-pr-code.h" |
45 #include "pt-stmt.h" | |
46 #include "pt-walk.h" | |
3707 | 47 #include "unwind-prot.h" |
2982 | 48 #include "utils.h" |
49 #include "variables.h" | |
50 | |
51 // A list of commands to be executed. | |
52 | |
53 tree_statement::~tree_statement (void) | |
54 { | |
55 delete cmd; | |
56 delete expr; | |
3665 | 57 delete comm; |
2982 | 58 } |
59 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
60 void |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
61 tree_statement::set_print_flag (bool print_flag) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
62 { |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
63 if (expr) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
64 expr->set_print_flag (print_flag); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
65 } |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
66 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
67 bool |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
68 tree_statement::print_result (void) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
69 { |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
70 return expr && expr->print_result (); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
71 } |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
72 |
8843
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
73 void |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
74 tree_statement::set_breakpoint (void) |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
75 { |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
76 if (cmd) |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
77 cmd->set_breakpoint (); |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
78 else if (expr) |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
79 expr->set_breakpoint (); |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
80 } |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
81 |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
82 void |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
83 tree_statement::delete_breakpoint (void) |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
84 { |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
85 if (cmd) |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
86 cmd->delete_breakpoint (); |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
87 else if (expr) |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
88 expr->delete_breakpoint (); |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
89 } |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
90 |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
91 bool |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
92 tree_statement::is_breakpoint (void) const |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
93 { |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
94 return cmd ? cmd->is_breakpoint () : (expr ? expr->is_breakpoint () : false); |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
95 } |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
96 |
2982 | 97 int |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
98 tree_statement::line (void) const |
2982 | 99 { |
100 return cmd ? cmd->line () : (expr ? expr->line () : -1); | |
101 } | |
102 | |
103 int | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
104 tree_statement::column (void) const |
2982 | 105 { |
106 return cmd ? cmd->column () : (expr ? expr->column () : -1); | |
107 } | |
108 | |
109 void | |
8669
33783e94fb16
line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
110 tree_statement::echo_code (void) |
2982 | 111 { |
8669
33783e94fb16
line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
112 tree_print_code tpc (octave_stdout, VPS4); |
2982 | 113 |
8669
33783e94fb16
line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
114 accept (tpc); |
2982 | 115 } |
116 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
117 bool |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
118 tree_statement::is_end_of_fcn_or_script (void) const |
2982 | 119 { |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
120 bool retval = false; |
2982 | 121 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
122 if (cmd) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
123 { |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
124 tree_no_op_command *no_op_cmd |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
125 = dynamic_cast<tree_no_op_command *> (cmd); |
2982 | 126 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
127 if (no_op_cmd) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
128 { |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
129 std::string type = no_op_cmd->original_command (); |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
130 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
131 retval = (type == "endfunction" || type == "endscript"); |
2982 | 132 } |
133 } | |
134 | |
135 return retval; | |
136 } | |
137 | |
5861 | 138 tree_statement * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
139 tree_statement::dup (symbol_table::scope_id scope, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
140 symbol_table::context_id context) |
5861 | 141 { |
142 tree_statement *new_stmt = new tree_statement (); | |
143 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
144 new_stmt->cmd = cmd ? cmd->dup (scope, context) : 0; |
5861 | 145 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
146 new_stmt->expr = expr ? expr->dup (scope, context) : 0; |
5861 | 147 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
148 new_stmt->comm = comm ? comm->dup () : 0; |
5861 | 149 |
150 return new_stmt; | |
151 } | |
152 | |
2982 | 153 void |
154 tree_statement::accept (tree_walker& tw) | |
155 { | |
156 tw.visit_statement (*this); | |
157 } | |
158 | |
3770 | 159 int |
160 tree_statement_list::set_breakpoint (int line) | |
161 { | |
162 tree_breakpoint tbp (line, tree_breakpoint::set); | |
163 accept (tbp); | |
164 | |
165 return tbp.get_line (); | |
166 } | |
167 | |
168 void | |
169 tree_statement_list::delete_breakpoint (int line) | |
170 { | |
3895 | 171 if (line < 0) |
172 { | |
4212 | 173 octave_value_list bp_lst = list_breakpoints (); |
3895 | 174 |
4212 | 175 int len = bp_lst.length (); |
3895 | 176 |
4587 | 177 for (int i = 0; i < len; i++) |
3895 | 178 { |
4587 | 179 tree_breakpoint tbp (i, tree_breakpoint::clear); |
3895 | 180 accept (tbp); |
181 } | |
182 } | |
183 else | |
184 { | |
185 tree_breakpoint tbp (line, tree_breakpoint::clear); | |
186 accept (tbp); | |
187 } | |
3770 | 188 } |
189 | |
190 octave_value_list | |
191 tree_statement_list::list_breakpoints (void) | |
192 { | |
193 tree_breakpoint tbp (0, tree_breakpoint::list); | |
194 accept (tbp); | |
195 | |
196 return tbp.get_list (); | |
197 } | |
198 | |
5861 | 199 tree_statement_list * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
200 tree_statement_list::dup (symbol_table::scope_id scope, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
201 symbol_table::context_id context) |
5861 | 202 { |
203 tree_statement_list *new_list = new tree_statement_list (); | |
204 | |
205 new_list->function_body = function_body; | |
206 | |
207 for (iterator p = begin (); p != end (); p++) | |
208 { | |
209 tree_statement *elt = *p; | |
210 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
211 new_list->append (elt ? elt->dup (scope, context) : 0); |
5861 | 212 } |
213 | |
214 return new_list; | |
215 } | |
216 | |
2982 | 217 void |
218 tree_statement_list::accept (tree_walker& tw) | |
219 { | |
220 tw.visit_statement_list (*this); | |
221 } | |
222 | |
223 /* | |
224 ;;; Local Variables: *** | |
225 ;;; mode: C++ *** | |
226 ;;; End: *** | |
227 */ |