Mercurial > octave
annotate src/pt-stmt.cc @ 8669:33783e94fb16
line number fixes and other evaluator tweaks
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 04 Feb 2009 13:28:06 -0500 |
parents | 73c4516fae10 |
children | b9ce57a309a3 |
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 |
2982 | 73 int |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
74 tree_statement::line (void) const |
2982 | 75 { |
76 return cmd ? cmd->line () : (expr ? expr->line () : -1); | |
77 } | |
78 | |
79 int | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
80 tree_statement::column (void) const |
2982 | 81 { |
82 return cmd ? cmd->column () : (expr ? expr->column () : -1); | |
83 } | |
84 | |
85 void | |
8669
33783e94fb16
line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
86 tree_statement::echo_code (void) |
2982 | 87 { |
8669
33783e94fb16
line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
88 tree_print_code tpc (octave_stdout, VPS4); |
2982 | 89 |
8669
33783e94fb16
line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
90 accept (tpc); |
2982 | 91 } |
92 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
93 bool |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
94 tree_statement::is_end_of_fcn_or_script (void) const |
2982 | 95 { |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
96 bool retval = false; |
2982 | 97 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
98 if (cmd) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
99 { |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
100 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
|
101 = dynamic_cast<tree_no_op_command *> (cmd); |
2982 | 102 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
103 if (no_op_cmd) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
104 { |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
105 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
|
106 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
107 retval = (type == "endfunction" || type == "endscript"); |
2982 | 108 } |
109 } | |
110 | |
111 return retval; | |
112 } | |
113 | |
5861 | 114 tree_statement * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
115 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
|
116 symbol_table::context_id context) |
5861 | 117 { |
118 tree_statement *new_stmt = new tree_statement (); | |
119 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
120 new_stmt->cmd = cmd ? cmd->dup (scope, context) : 0; |
5861 | 121 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
122 new_stmt->expr = expr ? expr->dup (scope, context) : 0; |
5861 | 123 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
124 new_stmt->bp = bp; |
5861 | 125 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
126 new_stmt->comm = comm ? comm->dup () : 0; |
5861 | 127 |
128 return new_stmt; | |
129 } | |
130 | |
2982 | 131 void |
132 tree_statement::accept (tree_walker& tw) | |
133 { | |
134 tw.visit_statement (*this); | |
135 } | |
136 | |
3770 | 137 int |
138 tree_statement_list::set_breakpoint (int line) | |
139 { | |
140 tree_breakpoint tbp (line, tree_breakpoint::set); | |
141 accept (tbp); | |
142 | |
143 return tbp.get_line (); | |
144 } | |
145 | |
146 void | |
147 tree_statement_list::delete_breakpoint (int line) | |
148 { | |
3895 | 149 if (line < 0) |
150 { | |
4212 | 151 octave_value_list bp_lst = list_breakpoints (); |
3895 | 152 |
4212 | 153 int len = bp_lst.length (); |
3895 | 154 |
4587 | 155 for (int i = 0; i < len; i++) |
3895 | 156 { |
4587 | 157 tree_breakpoint tbp (i, tree_breakpoint::clear); |
3895 | 158 accept (tbp); |
159 } | |
160 } | |
161 else | |
162 { | |
163 tree_breakpoint tbp (line, tree_breakpoint::clear); | |
164 accept (tbp); | |
165 } | |
3770 | 166 } |
167 | |
168 octave_value_list | |
169 tree_statement_list::list_breakpoints (void) | |
170 { | |
171 tree_breakpoint tbp (0, tree_breakpoint::list); | |
172 accept (tbp); | |
173 | |
174 return tbp.get_list (); | |
175 } | |
176 | |
5861 | 177 tree_statement_list * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
178 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
|
179 symbol_table::context_id context) |
5861 | 180 { |
181 tree_statement_list *new_list = new tree_statement_list (); | |
182 | |
183 new_list->function_body = function_body; | |
184 | |
185 for (iterator p = begin (); p != end (); p++) | |
186 { | |
187 tree_statement *elt = *p; | |
188 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
189 new_list->append (elt ? elt->dup (scope, context) : 0); |
5861 | 190 } |
191 | |
192 return new_list; | |
193 } | |
194 | |
2982 | 195 void |
196 tree_statement_list::accept (tree_walker& tw) | |
197 { | |
198 tw.visit_statement_list (*this); | |
199 } | |
200 | |
201 /* | |
202 ;;; Local Variables: *** | |
203 ;;; mode: C++ *** | |
204 ;;; End: *** | |
205 */ |