GNU Octave  4.0.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-2015 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 }
bool print_result(void)
Definition: pt-stmt.cc:68
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:110
tree_statement(void)
Definition: pt-stmt.h:49
intmap::const_iterator const_intmap_iterator
Definition: debug.h:50
octave_idx_type length(void) const
Definition: oct-obj.h:89
void accept(tree_walker &tw)
Definition: pt-stmt.cc:289
virtual void delete_breakpoint(void)
Definition: pt.h:61
void delete_breakpoint(int line)
Definition: pt-stmt.cc:191
tree_command * cmd
Definition: pt-stmt.h:111
tree_expression * set_print_flag(bool print)
Definition: pt-exp.h:123
bool is_end_of_fcn_or_script(void) const
Definition: pt-cmd.h:77
virtual tree_expression * dup(symbol_table::scope_id, symbol_table::context_id context) const =0
void echo_code(void)
Definition: pt-stmt.cc:119
void delete_breakpoint(void)
Definition: pt-stmt.cc:83
tree_expression * expr
Definition: pt-stmt.h:114
void set_breakpoint(void)
Definition: pt-stmt.cc:74
octave_comment_list * comm
Definition: pt-stmt.h:117
bool is_end_of_file(void) const
Definition: pt-stmt.cc:144
virtual void set_breakpoint(void)
Definition: pt.h:59
~tree_statement(void)
Definition: pt-stmt.cc:53
bp_table::intmap add_breakpoint(const std::string &file, const bp_table::intmap &line)
Definition: pt-stmt.cc:222
int get_line(void)
Definition: pt-bp.h:139
bool print_result(void) const
Definition: pt-exp.h:97
void append(const elt_type &s)
Definition: base-list.h:105
static llvm::LLVMContext & context
Definition: jit-typeinfo.cc:76
void accept(tree_walker &tw)
Definition: pt-stmt.cc:176
std::map< int, int > intmap
Definition: debug.h:48
bool is_end_of_file(void) const
Definition: pt-cmd.h:82
virtual void visit_statement(tree_statement &)=0
void set_location(int l, int c)
Definition: pt.h:53
tree_statement * dup(symbol_table::scope_id scope, symbol_table::context_id context) const
Definition: pt-stmt.cc:161
std::list< tree_statement * >::const_iterator const_iterator
Definition: base-list.h:37
bool is_breakpoint(void) const
Definition: pt.h:63
virtual int line(void) const
Definition: pt.h:45
int line(void) const
Definition: pt-stmt.cc:98
bool is_end_of_fcn_or_script(void) const
Definition: pt-stmt.cc:127
#define octave_stdout
Definition: pager.h:144
octave_value_list list_breakpoints(void)
Definition: pt-stmt.cc:213
bool is_breakpoint(void) const
Definition: pt-stmt.cc:92
void set_print_flag(bool print_flag)
Definition: pt-stmt.cc:61
int column(void) const
Definition: pt-stmt.cc:104
octave_value_list get_list(void)
Definition: pt-bp.h:137
int set_breakpoint(int line)
Definition: pt-stmt.cc:182
bp_table::intmap remove_all_breakpoints(const std::string &file)
Definition: pt-stmt.cc:248
std::string VPS4
Definition: input.cc:85
octave_comment_list * dup(void) const
Definition: comment-list.cc:33
virtual int column(void) const
Definition: pt.h:47
tree_statement_list(void)
Definition: pt-stmt.h:132
tree_statement_list * dup(symbol_table::scope_id scope, symbol_table::context_id context) const
Definition: pt-stmt.cc:271