GNU Octave  4.2.1
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-2017 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 #if defined (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 "errwarn.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 #include "debug.h"
52 
53 // A list of commands to be executed.
54 
56 {
57  delete cmd;
58  delete expr;
59  delete comm;
60 }
61 
62 void
64 {
65  if (expr)
66  expr->set_print_flag (print_flag);
67 }
68 
69 bool
71 {
72  return expr && expr->print_result ();
73 }
74 
75 void
77 {
78  if (cmd)
79  cmd->set_breakpoint (condition);
80  else if (expr)
81  expr->set_breakpoint (condition);
82 }
83 
84 void
86 {
87  if (cmd)
89  else if (expr)
91 }
92 
93 bool
94 tree_statement::is_breakpoint (bool check_active) const
95 {
96  return cmd ? cmd->is_breakpoint (check_active)
97  : (expr ? expr->is_breakpoint (check_active) : false);
98 }
99 
102 {
103  return cmd ? cmd->bp_cond () : (expr ? expr->bp_cond () : "0");
104 }
105 
106 int
108 {
109  return cmd ? cmd->line () : (expr ? expr->line () : -1);
110 }
111 
112 int
114 {
115  return cmd ? cmd->column () : (expr ? expr->column () : -1);
116 }
117 
118 void
120 {
121  if (cmd)
122  cmd->set_location (l, c);
123  else if (expr)
124  expr->set_location (l, c);
125 }
126 
127 void
129 {
131 
132  accept (tpc);
133 }
134 
135 bool
137 {
138  bool retval = false;
139 
140  if (cmd)
141  {
142  tree_no_op_command *no_op_cmd
143  = dynamic_cast<tree_no_op_command *> (cmd);
144 
145  if (no_op_cmd)
146  retval = no_op_cmd->is_end_of_fcn_or_script ();
147  }
148 
149  return retval;
150 }
151 
152 bool
154 {
155  bool retval = false;
156 
157  if (cmd)
158  {
159  tree_no_op_command *no_op_cmd
160  = dynamic_cast<tree_no_op_command *> (cmd);
161 
162  if (no_op_cmd)
163  retval = no_op_cmd->is_end_of_file ();
164  }
165 
166  return retval;
167 }
168 
172 {
173  tree_statement *new_stmt = new tree_statement ();
174 
175  new_stmt->cmd = cmd ? cmd->dup (scope, context) : 0;
176 
177  new_stmt->expr = expr ? expr->dup (scope, context) : 0;
178 
179  new_stmt->comm = comm ? comm->dup () : 0;
180 
181  return new_stmt;
182 }
183 
184 void
186 {
187  tw.visit_statement (*this);
188 }
189 
190 // Create a "breakpoint" tree-walker, and get it to "walk" this statement list
191 // (FIXME: What does that do???)
192 int
194 {
195  tree_breakpoint tbp (line, tree_breakpoint::set, condition);
196  accept (tbp);
197 
198  return tbp.get_line ();
199 }
200 
201 void
203 {
204  if (line < 0)
205  {
207 
208  int len = bp_lst.length ();
209 
210  for (int i = 0; i < len; i++)
211  {
213  accept (tbp);
214  }
215  }
216  else
217  {
219  accept (tbp);
220  }
221 }
222 
225 {
227  accept (tbp);
228 
229  return tbp.get_list ();
230 }
231 
232 // Get list of pairs (breakpoint line, breakpoint condition)
233 std::list<bp_type>
235 {
237  accept (tbp);
238 
239  std::list<bp_type> retval;
240  octave_value_list lines = tbp.get_list ();
241  octave_value_list conds = tbp.get_cond_list ();
242 
243  for (int i = 0; i < lines.length (); i++)
244  {
245  retval.push_back (bp_type (lines(i).double_value (),
246  conds(i).string_value ()));
247  }
248 
249  return retval;
250 }
251 
252 // Add breakpoints to file at multiple lines (the second arguments of line),
253 // to stop only if condition is true.
254 // Updates GUI via octave_link::update_breakpoint.
255 // FIXME: COME BACK TO ME.
258  const bp_table::intmap& line,
259  const std::string& condition)
260 {
262 
263  octave_idx_type len = line.size ();
264 
265  for (int i = 0; i < len; i++)
266  {
267  bp_table::const_intmap_iterator p = line.find (i);
268 
269  if (p != line.end ())
270  {
271  int lineno = p->second;
272 
273  retval[i] = set_breakpoint (lineno, condition);
274 
275  if (retval[i] != 0 && ! file.empty ())
276  octave_link::update_breakpoint (true, file, retval[i], condition);
277  }
278  }
279 
280  return retval;
281 }
282 
285 {
287 
289 
290  for (int i = 0; i < bkpts.length (); i++)
291  {
292  int lineno = static_cast<int> (bkpts(i).int_value ());
293 
294  delete_breakpoint (lineno);
295 
296  retval[i] = lineno;
297 
298  if (! file.empty ())
299  octave_link::update_breakpoint (false, file, lineno);
300  }
301 
302  return retval;
303 }
304 
308 {
309  tree_statement_list *new_list = new tree_statement_list ();
310 
311  new_list->function_body = function_body;
312 
313  for (const_iterator p = begin (); p != end (); p++)
314  {
315  const tree_statement *elt = *p;
316 
317  new_list->append (elt ? elt->dup (scope, context) : 0);
318  }
319 
320  return new_list;
321 }
322 
323 void
325 {
326  tw.visit_statement_list (*this);
327 }
const std::string bp_cond(void) const
Definition: pt.h:80
int set_breakpoint(int line, const std::string &condition)
Definition: pt-stmt.cc:193
For example cd octave end example noindent changes the current working directory to file
Definition: dirfns.cc:120
bool print_result(void)
Definition: pt-stmt.cc:70
std::list< bp_type > breakpoints_and_conds(void)
Definition: pt-stmt.cc:234
virtual tree_command * dup(symbol_table::scope_id, symbol_table::context_id context) const =0
virtual void visit_statement_list(tree_statement_list &)=0
void set_location(int l, int c)
Definition: pt-stmt.cc:119
tree_statement(void)
Definition: pt-stmt.h:51
intmap::const_iterator const_intmap_iterator
Definition: debug.h:62
octave_idx_type length(void) const
Definition: ovl.h:96
void accept(tree_walker &tw)
Definition: pt-stmt.cc:324
virtual void delete_breakpoint(void)
Definition: pt.h:71
void delete_breakpoint(int line)
Definition: pt-stmt.cc:202
tree_command * cmd
Definition: pt-stmt.h:114
tree_expression * set_print_flag(bool print)
Definition: pt-exp.h:125
bool is_end_of_fcn_or_script(void) const
Definition: pt-cmd.h:79
virtual tree_expression * dup(symbol_table::scope_id, symbol_table::context_id context) const =0
void echo_code(void)
Definition: pt-stmt.cc:128
void delete_breakpoint(void)
Definition: pt-stmt.cc:85
tree_expression * expr
Definition: pt-stmt.h:117
octave_comment_list * comm
Definition: pt-stmt.h:120
bool is_end_of_file(void) const
Definition: pt-stmt.cc:153
~tree_statement(void)
Definition: pt-stmt.cc:55
bool is_breakpoint(bool check_valid=false) const
Definition: pt-stmt.cc:94
int get_line(void)
Definition: pt-bp.h:143
bool print_result(void) const
Definition: pt-exp.h:99
static llvm::LLVMContext & context
Definition: jit-typeinfo.cc:76
void accept(tree_walker &tw)
Definition: pt-stmt.cc:185
std::map< int, int > intmap
Definition: debug.h:60
bool is_end_of_file(void) const
Definition: pt-cmd.h:84
virtual void visit_statement(tree_statement &)=0
Definition: debug.h:37
octave_value retval
Definition: data.cc:6294
void set_location(int l, int c)
Definition: pt.h:57
tree_statement * dup(symbol_table::scope_id scope, symbol_table::context_id context) const
Definition: pt-stmt.cc:170
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
Definition: lu.cc:138
octave_value_list get_cond_list(void)
Definition: pt-bp.h:141
virtual int line(void) const
Definition: pt.h:49
void set_breakpoint(const std::string &condition)
Definition: pt-stmt.cc:76
std::string bp_cond() const
Definition: pt-stmt.cc:101
int line(void) const
Definition: pt-stmt.cc:107
bool is_end_of_fcn_or_script(void) const
Definition: pt-stmt.cc:136
std::list< tree_statement * >::const_iterator const_iterator
Definition: base-list.h:41
#define octave_stdout
Definition: pager.h:146
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
octave_value_list list_breakpoints(void)
Definition: pt-stmt.cc:224
p
Definition: lu.cc:138
bool is_breakpoint(bool check_active=false) const
Definition: pt.h:75
bp_table::intmap add_breakpoint(const std::string &file, const bp_table::intmap &line, const std::string &condition)
Definition: pt-stmt.cc:257
void set_print_flag(bool print_flag)
Definition: pt-stmt.cc:63
int column(void) const
Definition: pt-stmt.cc:113
octave_value_list get_list(void)
Definition: pt-bp.h:140
void append(const elt_type &s)
Definition: base-list.h:110
bp_table::intmap remove_all_breakpoints(const std::string &file)
Definition: pt-stmt.cc:284
std::string VPS4
Definition: input.cc:84
octave_comment_list * dup(void) const
Definition: comment-list.cc:33
virtual int column(void) const
Definition: pt.h:51
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854
virtual void set_breakpoint(const std::string &condition)
Definition: pt.h:63
tree_statement_list(void)
Definition: pt-stmt.h:135
tree_statement_list * dup(symbol_table::scope_id scope, symbol_table::context_id context) const
Definition: pt-stmt.cc:306