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