GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pt-stmt.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2018 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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License 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 <https://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 "bp-table.h"
32 #include "comment-list.h"
33 #include "input.h"
34 #include "oct-lvalue.h"
35 #include "octave-link.h"
36 #include "ov.h"
37 #include "pager.h"
38 #include "pt-bp.h"
39 #include "pt-cmd.h"
40 #include "pt-id.h"
41 #include "pt-idx.h"
42 #include "pt-jump.h"
43 #include "pt-pr-code.h"
44 #include "pt-stmt.h"
45 #include "pt-walk.h"
46 #include "utils.h"
47 #include "variables.h"
48 
49 namespace octave
50 {
51  // A list of commands to be executed.
52 
54  {
55  delete m_command;
56  delete m_expression;
57  delete m_comment_list;
58  }
59 
60  void
62  {
63  if (m_expression)
64  m_expression->set_print_flag (print_flag);
65  }
66 
67  bool
69  {
71  }
72 
73  void
75  {
76  if (m_command)
77  m_command->set_breakpoint (condition);
78  else if (m_expression)
79  m_expression->set_breakpoint (condition);
80  }
81 
82  void
84  {
85  if (m_command)
87  else if (m_expression)
89  }
90 
91  bool
92  tree_statement::is_breakpoint (bool check_active) const
93  {
94  return m_command ? m_command->is_breakpoint (check_active)
95  : (m_expression ? m_expression->is_breakpoint (check_active) : false);
96  }
97 
100  {
101  return (m_command
102  ? m_command->bp_cond ()
103  : (m_expression ? m_expression->bp_cond () : "0"));
104  }
105 
106  int
107  tree_statement::line (void) const
108  {
109  return (m_command
110  ? m_command->line ()
111  : (m_expression ? m_expression->line () : -1));
112  }
113 
114  int
116  {
117  return (m_command
118  ? m_command->column ()
119  : (m_expression ? m_expression->column () : -1));
120  }
121 
122  void
124  {
125  if (m_command)
126  m_command->set_location (l, c);
127  else if (m_expression)
129  }
130 
131  void
133  {
134  tree_print_code tpc (octave_stdout, prefix);
135 
136  accept (tpc);
137  }
138 
139  bool
141  {
142  bool retval = false;
143 
144  if (m_command)
145  {
146  tree_no_op_command *no_op_cmd
147  = dynamic_cast<tree_no_op_command *> (m_command);
148 
149  if (no_op_cmd)
150  retval = no_op_cmd->is_end_of_fcn_or_script ();
151  }
152 
153  return retval;
154  }
155 
156  bool
158  {
159  bool retval = false;
160 
161  if (m_command)
162  {
163  tree_no_op_command *no_op_cmd
164  = dynamic_cast<tree_no_op_command *> (m_command);
165 
166  if (no_op_cmd)
167  retval = no_op_cmd->is_end_of_file ();
168  }
169 
170  return retval;
171  }
172 
173  // Create a "breakpoint" tree-walker, and get it to "walk" this
174  // statement list
175  // (FIXME: What does that do???)
176 
177  int
179  {
180  tree_breakpoint tbp (line, tree_breakpoint::set, condition);
181  accept (tbp);
182 
183  return tbp.get_line ();
184  }
185 
186  void
188  {
189  if (line < 0)
190  {
192 
193  int len = bp_lst.length ();
194 
195  for (int i = 0; i < len; i++)
196  {
198  accept (tbp);
199  }
200  }
201  else
202  {
204  accept (tbp);
205  }
206  }
207 
210  {
212  accept (tbp);
213 
214  return tbp.get_list ();
215  }
216 
217  // Get list of pairs (breakpoint line, breakpoint condition)
218  std::list<bp_type>
220  {
222  accept (tbp);
223 
224  std::list<bp_type> retval;
225  octave_value_list lines = tbp.get_list ();
226  octave_value_list conds = tbp.get_cond_list ();
227 
228  for (int i = 0; i < lines.length (); i++)
229  {
230  retval.push_back (bp_type (lines(i).double_value (),
231  conds(i).string_value ()));
232  }
233 
234  return retval;
235  }
236 
237  // Add breakpoints to file at multiple lines (the second arguments
238  // of line), to stop only if condition is true.
239  // Updates GUI via octave_link::update_breakpoint.
240  // FIXME: COME BACK TO ME.
241 
244  const bp_table::intmap& line,
245  const std::string& condition)
246  {
248 
249  octave_idx_type len = line.size ();
250 
251  for (int i = 0; i < len; i++)
252  {
254 
255  if (p != line.end ())
256  {
257  int lineno = p->second;
258 
259  retval[i] = set_breakpoint (lineno, condition);
260 
261  if (retval[i] != 0 && ! file.empty ())
262  octave_link::update_breakpoint (true, file, retval[i], condition);
263  }
264  }
265 
266  return retval;
267  }
268 
271  {
273 
275 
276  for (int i = 0; i < bkpts.length (); i++)
277  {
278  int lineno = static_cast<int> (bkpts(i).int_value ());
279 
280  delete_breakpoint (lineno);
281 
282  retval[i] = lineno;
283 
284  if (! file.empty ())
285  octave_link::update_breakpoint (false, file, lineno);
286  }
287 
288  return retval;
289  }
290 }
virtual int line(void) const
Definition: pt.h:56
void set_location(int l, int c)
Definition: pt-stmt.cc:123
void delete_breakpoint(void)
Definition: pt-stmt.cc:83
std::string bp_cond() const
Definition: pt-stmt.cc:99
For example cd octave end example noindent changes the current working directory to file
Definition: dirfns.cc:124
int line(void) const
Definition: pt-stmt.cc:107
virtual int column(void) const
Definition: pt.h:58
bool is_end_of_fcn_or_script(void) const
Definition: pt-stmt.cc:140
bp_table::intmap remove_all_breakpoints(const std::string &file)
Definition: pt-stmt.cc:270
bool is_end_of_file(void) const
Definition: pt-stmt.cc:157
intmap::const_iterator const_intmap_iterator
Definition: bp-table.h:62
void echo_code(const std::string &prefix)
Definition: pt-stmt.cc:132
tree_command * m_command
Definition: pt-stmt.h:123
void delete_breakpoint(int line)
Definition: pt-stmt.cc:187
bool is_breakpoint(bool check_active=false) const
Definition: pt.h:90
tree_expression * m_expression
Definition: pt-stmt.h:126
bool is_breakpoint(bool check_valid=false) const
Definition: pt-stmt.cc:92
octave_value_list list_breakpoints(void)
Definition: pt-stmt.cc:209
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
Definition: file-io.cc:587
int set_breakpoint(int line, const std::string &condition)
Definition: pt-stmt.cc:178
bool print_result(void)
Definition: pt-stmt.cc:68
std::list< bp_type > breakpoints_and_conds(void)
Definition: pt-stmt.cc:219
void set_breakpoint(const std::string &condition)
Definition: pt-stmt.cc:74
comment_list * m_comment_list
Definition: pt-stmt.h:129
void accept(tree_walker &tw)
Definition: pt-stmt.h:188
octave_value retval
Definition: data.cc:6246
octave_value_list get_list(void)
Definition: pt-bp.h:146
std::map< int, int > intmap
Definition: bp-table.h:60
bool is_end_of_file(void) const
Definition: pt-cmd.h:83
void set_location(int l, int c)
Definition: pt.h:64
#define octave_stdout
Definition: pager.h:174
p
Definition: lu.cc:138
const std::string bp_cond(void) const
Definition: pt.h:97
bp_table::intmap add_breakpoint(const std::string &file, const bp_table::intmap &line, const std::string &condition)
Definition: pt-stmt.cc:243
octave_idx_type length(void) const
Definition: ovl.h:96
octave_value_list get_cond_list(void)
Definition: pt-bp.h:148
int column(void) const
Definition: pt-stmt.cc:115
for i
Definition: data.cc:5264
void set_print_flag(bool print_flag)
Definition: pt-stmt.cc:61
virtual void delete_breakpoint(void)
Definition: pt.h:78
void accept(tree_walker &tw)
Definition: pt-stmt.h:113
int get_line(void)
Definition: pt-bp.h:150
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:888
bool is_end_of_fcn_or_script(void) const
Definition: pt-cmd.h:78
virtual void set_breakpoint(const std::string &condition)
Definition: pt.h:70
bool print_result(void) const
Definition: pt-exp.h:98
tree_expression * set_print_flag(bool print)
Definition: pt-exp.h:124