GNU Octave  6.2.0
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-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if defined (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include <typeinfo>
31 
32 #include "quit.h"
33 
34 #include "bp-table.h"
35 #include "comment-list.h"
36 #include "event-manager.h"
37 #include "input.h"
38 #include "oct-lvalue.h"
39 #include "ov.h"
40 #include "pager.h"
41 #include "pt-bp.h"
42 #include "pt-cmd.h"
43 #include "pt-eval.h"
44 #include "pt-id.h"
45 #include "pt-idx.h"
46 #include "pt-jump.h"
47 #include "pt-pr-code.h"
48 #include "pt-stmt.h"
49 #include "utils.h"
50 #include "variables.h"
51 
52 namespace octave
53 {
54  // A list of commands to be executed.
55 
57  {
58  delete m_command;
59  delete m_expression;
60  delete m_comment_list;
61  }
62 
63  void
65  {
66  if (m_expression)
67  m_expression->set_print_flag (print_flag);
68  }
69 
70  bool
72  {
74  }
75 
76  void
77  tree_statement::set_breakpoint (const std::string& condition)
78  {
79  if (m_command)
80  m_command->set_breakpoint (condition);
81  else if (m_expression)
82  m_expression->set_breakpoint (condition);
83  }
84 
85  void
87  {
88  if (m_command)
90  else if (m_expression)
92  }
93 
94  bool
96  {
97  return m_command ? m_command->is_breakpoint ()
98  : (m_expression ? m_expression->is_breakpoint () : false);
99  }
100 
101  bool
103  {
105  : (m_expression ? m_expression->is_active_breakpoint (tw) : false);
106  }
107 
108  std::string
110  {
111  return (m_command
112  ? m_command->bp_cond ()
113  : (m_expression ? m_expression->bp_cond () : "0"));
114  }
115 
116  int
117  tree_statement::line (void) const
118  {
119  return (m_command
120  ? m_command->line ()
121  : (m_expression ? m_expression->line () : -1));
122  }
123 
124  int
126  {
127  return (m_command
128  ? m_command->column ()
129  : (m_expression ? m_expression->column () : -1));
130  }
131 
132  void
134  {
135  if (m_command)
136  m_command->set_location (l, c);
137  else if (m_expression)
138  m_expression->set_location (l, c);
139  }
140 
141  void
142  tree_statement::echo_code (const std::string& prefix)
143  {
144  tree_print_code tpc (octave_stdout, prefix);
145 
146  accept (tpc);
147  }
148 
149  bool
151  {
152  bool retval = false;
153 
154  if (m_command)
155  {
156  tree_no_op_command *no_op_cmd
157  = dynamic_cast<tree_no_op_command *> (m_command);
158 
159  if (no_op_cmd)
160  retval = no_op_cmd->is_end_of_fcn_or_script ();
161  }
162 
163  return retval;
164  }
165 
166  bool
168  {
169  bool retval = false;
170 
171  if (m_command)
172  {
173  tree_no_op_command *no_op_cmd
174  = dynamic_cast<tree_no_op_command *> (m_command);
175 
176  if (no_op_cmd)
177  retval = no_op_cmd->is_end_of_file ();
178  }
179 
180  return retval;
181  }
182 
183  // Create a "breakpoint" tree-walker, and get it to "walk" this
184  // statement list
185  // (FIXME: What does that do???)
186 
187  int
188  tree_statement_list::set_breakpoint (int line, const std::string& condition)
189  {
190  tree_breakpoint tbp (line, tree_breakpoint::set, condition);
191  accept (tbp);
192 
193  return tbp.get_line ();
194  }
195 
196  void
198  {
199  if (line < 0)
200  {
202 
203  int len = bp_lst.length ();
204 
205  for (int i = 0; i < len; i++)
206  {
208  accept (tbp);
209  }
210  }
211  else
212  {
214  accept (tbp);
215  }
216  }
217 
220  {
222  accept (tbp);
223 
224  return tbp.get_list ();
225  }
226 
227  // Get list of pairs (breakpoint line, breakpoint condition)
228  std::list<bp_type>
230  {
232  accept (tbp);
233 
234  std::list<bp_type> retval;
235  octave_value_list lines = tbp.get_list ();
236  octave_value_list conds = tbp.get_cond_list ();
237 
238  for (int i = 0; i < lines.length (); i++)
239  {
240  retval.push_back (bp_type (lines(i).double_value (),
241  conds(i).string_value ()));
242  }
243 
244  return retval;
245  }
246 
247  // Add breakpoints to file at multiple lines (the second arguments
248  // of line), to stop only if condition is true.
249  // Updates GUI via event_manager::update_breakpoint.
250  // FIXME: COME BACK TO ME.
251 
254  const std::string& file,
255  const bp_table::intmap& line,
256  const std::string& condition)
257  {
259 
260  octave_idx_type len = line.size ();
261 
262  for (int i = 0; i < len; i++)
263  {
265 
266  if (p != line.end ())
267  {
268  int lineno = p->second;
269 
270  retval[i] = set_breakpoint (lineno, condition);
271 
272  if (retval[i] != 0 && ! file.empty ())
273  evmgr.update_breakpoint (true, file, retval[i], condition);
274  }
275  }
276 
277  return retval;
278  }
279 
282  const std::string& file)
283  {
285 
287 
288  for (int i = 0; i < bkpts.length (); i++)
289  {
290  int lineno = static_cast<int> (bkpts(i).int_value ());
291 
292  delete_breakpoint (lineno);
293 
294  retval[i] = lineno;
295 
296  if (! file.empty ())
297  evmgr.update_breakpoint (false, file, lineno);
298  }
299 
300  return retval;
301  }
302 }
intmap::const_iterator const_intmap_iterator
Definition: bp-table.h:67
std::map< int, int > intmap
Definition: bp-table.h:65
Provides threadsafe access to octave.
void update_breakpoint(bool insert, const std::string &file, int line, const std::string &cond="")
octave_value_list get_cond_list(void)
Definition: pt-bp.h:140
octave_value_list get_list(void)
Definition: pt-bp.h:138
int get_line(void)
Definition: pt-bp.h:142
tree_expression * set_print_flag(bool print)
Definition: pt-exp.h:125
bool print_result(void) const
Definition: pt-exp.h:99
bool is_end_of_fcn_or_script(void) const
Definition: pt-cmd.h:81
bool is_end_of_file(void) const
Definition: pt-cmd.h:86
void accept(tree_walker &tw)
Definition: pt-stmt.h:199
int set_breakpoint(int line, const std::string &condition)
Definition: pt-stmt.cc:188
void delete_breakpoint(int line)
Definition: pt-stmt.cc:197
octave_value_list list_breakpoints(void)
Definition: pt-stmt.cc:219
bp_table::intmap remove_all_breakpoints(event_manager &evmgr, const std::string &file)
Definition: pt-stmt.cc:281
std::list< bp_type > breakpoints_and_conds(void)
Definition: pt-stmt.cc:229
bp_table::intmap add_breakpoint(event_manager &evmgr, const std::string &file, const bp_table::intmap &line, const std::string &condition)
Definition: pt-stmt.cc:253
bool is_end_of_fcn_or_script(void) const
Definition: pt-stmt.cc:150
bool is_active_breakpoint(tree_evaluator &tw) const
Definition: pt-stmt.cc:102
int column(void) const
Definition: pt-stmt.cc:125
int line(void) const
Definition: pt-stmt.cc:117
comment_list * m_comment_list
Definition: pt-stmt.h:138
bool is_end_of_file(void) const
Definition: pt-stmt.cc:167
tree_expression * m_expression
Definition: pt-stmt.h:135
void accept(tree_walker &tw)
Definition: pt-stmt.h:122
bool print_result(void)
Definition: pt-stmt.cc:71
void set_print_flag(bool print_flag)
Definition: pt-stmt.cc:64
void delete_breakpoint(void)
Definition: pt-stmt.cc:86
void echo_code(const std::string &prefix)
Definition: pt-stmt.cc:142
tree_command * m_command
Definition: pt-stmt.h:132
void set_location(int l, int c)
Definition: pt-stmt.cc:133
bool is_breakpoint(void) const
Definition: pt-stmt.cc:95
void set_breakpoint(const std::string &condition)
Definition: pt-stmt.cc:77
std::string bp_cond() const
Definition: pt-stmt.cc:109
virtual int column(void) const
Definition: pt.h:62
void set_location(int l, int c)
Definition: pt.h:68
virtual void delete_breakpoint(void)
Definition: pt.h:82
bool is_active_breakpoint(tree_evaluator &tw) const
Definition: pt.h:99
const std::string bp_cond(void) const
Definition: pt.h:106
virtual int line(void) const
Definition: pt.h:60
virtual void set_breakpoint(const std::string &condition)
Definition: pt.h:74
bool is_breakpoint(void) const
Definition: pt.h:94
octave_idx_type length(void) const
Definition: ovl.h:113
octave_value::octave_value(const Array< char > &chm, char type) return retval
Definition: ov.cc:811
#define octave_stdout
Definition: pager.h:313
F77_RET_T len
Definition: xerbla.cc:61