GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
pt-stmt.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2013 John W. Eaton
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 3 of the License, or (at your
10 option) any 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, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 #include <typeinfo>
28 
29 #include "quit.h"
30 
31 #include "defun.h"
32 #include "error.h"
33 #include "gripes.h"
34 #include "ov.h"
35 #include "octave-link.h"
36 #include "oct-lvalue.h"
37 #include "input.h"
38 #include "pager.h"
39 #include "pt-bp.h"
40 #include "pt-cmd.h"
41 #include "pt-id.h"
42 #include "pt-idx.h"
43 #include "pt-jump.h"
44 #include "pt-pr-code.h"
45 #include "pt-stmt.h"
46 #include "pt-walk.h"
47 #include "unwind-prot.h"
48 #include "utils.h"
49 #include "variables.h"
50 
51 // A list of commands to be executed.
52 
54 {
55  delete cmd;
56  delete expr;
57  delete comm;
58 }
59 
60 void
62 {
63  if (expr)
64  expr->set_print_flag (print_flag);
65 }
66 
67 bool
69 {
70  return expr && expr->print_result ();
71 }
72 
73 void
75 {
76  if (cmd)
77  cmd->set_breakpoint ();
78  else if (expr)
79  expr->set_breakpoint ();
80 }
81 
82 void
84 {
85  if (cmd)
87  else if (expr)
89 }
90 
91 bool
93 {
94  return cmd ? cmd->is_breakpoint () : (expr ? expr->is_breakpoint () : false);
95 }
96 
97 int
99 {
100  return cmd ? cmd->line () : (expr ? expr->line () : -1);
101 }
102 
103 int
105 {
106  return cmd ? cmd->column () : (expr ? expr->column () : -1);
107 }
108 
109 void
111 {
112  if (cmd)
113  cmd->set_location (l, c);
114  else if (expr)
115  expr->set_location (l, c);
116 }
117 
118 void
120 {
122 
123  accept (tpc);
124 }
125 
126 bool
128 {
129  bool retval = false;
130 
131  if (cmd)
132  {
133  tree_no_op_command *no_op_cmd
134  = dynamic_cast<tree_no_op_command *> (cmd);
135 
136  if (no_op_cmd)
137  retval = no_op_cmd->is_end_of_fcn_or_script ();
138  }
139 
140  return retval;
141 }
142 
143 bool
145 {
146  bool retval = false;
147 
148  if (cmd)
149  {
150  tree_no_op_command *no_op_cmd
151  = dynamic_cast<tree_no_op_command *> (cmd);
152 
153  if (no_op_cmd)
154  retval = no_op_cmd->is_end_of_file ();
155  }
156 
157  return retval;
158 }
159 
163 {
164  tree_statement *new_stmt = new tree_statement ();
165 
166  new_stmt->cmd = cmd ? cmd->dup (scope, context) : 0;
167 
168  new_stmt->expr = expr ? expr->dup (scope, context) : 0;
169 
170  new_stmt->comm = comm ? comm->dup () : 0;
171 
172  return new_stmt;
173 }
174 
175 void
177 {
178  tw.visit_statement (*this);
179 }
180 
181 int
183 {
185  accept (tbp);
186 
187  return tbp.get_line ();
188 }
189 
190 void
192 {
193  if (line < 0)
194  {
196 
197  int len = bp_lst.length ();
198 
199  for (int i = 0; i < len; i++)
200  {
202  accept (tbp);
203  }
204  }
205  else
206  {
208  accept (tbp);
209  }
210 }
211 
214 {
216  accept (tbp);
217 
218  return tbp.get_list ();
219 }
220 
222 tree_statement_list::add_breakpoint (const std::string& file,
223  const bp_table::intmap& line)
224 {
225  bp_table::intmap retval;
226 
227  octave_idx_type len = line.size ();
228 
229  for (int i = 0; i < len; i++)
230  {
231  bp_table::const_intmap_iterator p = line.find (i);
232 
233  if (p != line.end ())
234  {
235  int lineno = p->second;
236 
237  retval[i] = set_breakpoint (lineno);
238 
239  if (retval[i] != 0 && ! file.empty ())
240  octave_link::update_breakpoint (true, file, retval[i]);
241  }
242  }
243 
244  return retval;
245 }
246 
249 {
250  bp_table::intmap retval;
251 
253 
254  for (int i = 0; i < bkpts.length (); i++)
255  {
256  int lineno = static_cast<int> (bkpts(i).int_value ());
257 
258  delete_breakpoint (lineno);
259 
260  retval[i] = lineno;
261 
262  if (! file.empty ())
263  octave_link::update_breakpoint (false, file, lineno);
264  }
265 
266  return retval;
267 }
268 
269 
273 {
274  tree_statement_list *new_list = new tree_statement_list ();
275 
276  new_list->function_body = function_body;
277 
278  for (const_iterator p = begin (); p != end (); p++)
279  {
280  const tree_statement *elt = *p;
281 
282  new_list->append (elt ? elt->dup (scope, context) : 0);
283  }
284 
285  return new_list;
286 }
287 
288 void
290 {
291  tw.visit_statement_list (*this);
292 }