GNU Octave  8.1.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-2023 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 
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 ()
99  : false);
100 }
101 
102 bool
104 {
107  : false);
108 }
109 
110 std::string
112 {
113  return (m_command
114  ? m_command->bp_cond ()
115  : (m_expression ? m_expression->bp_cond () : "0"));
116 }
117 
118 int
120 {
121  return (m_command
122  ? m_command->line ()
123  : (m_expression ? m_expression->line () : -1));
124 }
125 
126 int
128 {
129  return (m_command
130  ? m_command->column ()
131  : (m_expression ? m_expression->column () : -1));
132 }
133 
134 void
136 {
137  if (m_command)
138  m_command->set_location (l, c);
139  else if (m_expression)
140  m_expression->set_location (l, c);
141 }
142 
143 void
144 tree_statement::echo_code (const std::string& prefix)
145 {
146  tree_print_code tpc (octave_stdout, prefix);
147 
148  accept (tpc);
149 }
150 
151 bool
153 {
154  bool retval = false;
155 
156  if (m_command)
157  {
158  tree_no_op_command *no_op_cmd
159  = dynamic_cast<tree_no_op_command *> (m_command);
160 
161  if (no_op_cmd)
162  retval = no_op_cmd->is_end_of_fcn_or_script ();
163  }
164 
165  return retval;
166 }
167 
168 bool
170 {
171  bool retval = false;
172 
173  if (m_command)
174  {
175  tree_no_op_command *no_op_cmd
176  = dynamic_cast<tree_no_op_command *> (m_command);
177 
178  if (no_op_cmd)
179  retval = no_op_cmd->is_end_of_file ();
180  }
181 
182  return retval;
183 }
184 
185 // Create a "breakpoint" tree-walker, and get it to "walk" this
186 // statement list
187 // (FIXME: What does that do???)
188 
189 int
190 tree_statement_list::set_breakpoint (int line, const std::string& condition)
191 {
192  tree_breakpoint tbp (line, tree_breakpoint::set, condition);
193  accept (tbp);
194 
195  return tbp.get_line ();
196 }
197 
198 void
200 {
201  if (line < 0)
202  {
204 
205  int len = bp_lst.length ();
206 
207  for (int i = 0; i < len; i++)
208  {
210  accept (tbp);
211  }
212  }
213  else
214  {
216  accept (tbp);
217  }
218 }
219 
222 {
224  accept (tbp);
225 
226  return tbp.get_list ();
227 }
228 
229 // Get list of pairs (breakpoint line, breakpoint condition)
230 std::list<bp_type>
232 {
234  accept (tbp);
235 
236  std::list<bp_type> retval;
237  octave_value_list lines = tbp.get_list ();
238  octave_value_list conds = tbp.get_cond_list ();
239 
240  for (int i = 0; i < lines.length (); i++)
241  {
242  retval.push_back (bp_type (lines(i).double_value (),
243  conds(i).string_value ()));
244  }
245 
246  return retval;
247 }
248 
249 // Add breakpoints to file at multiple lines (the second arguments
250 // of line), to stop only if condition is true.
251 // Updates GUI via event_manager::update_breakpoint.
252 // FIXME: COME BACK TO ME.
253 
256  const std::string& file,
257  const bp_table::bp_lines& lines,
258  const std::string& condition)
259 {
260  bp_table::bp_lines retval;
261 
262  for (const auto& lineno : lines)
263  {
264  int line = set_breakpoint (lineno, condition);
265 
266  if (line)
267  {
268  if (! file.empty ())
269  evmgr.update_breakpoint (true, file, line, condition);
270 
271  retval.insert (line);
272  }
273  }
274 
275  return retval;
276 }
277 
280  const std::string& file)
281 {
282  bp_table::bp_lines retval;
283 
285 
286  for (int i = 0; i < bkpts.length (); i++)
287  {
288  int lineno = bkpts(i).int_value ();
289 
290  delete_breakpoint (lineno);
291 
292  retval.insert (lineno);
293 
294  if (! file.empty ())
295  evmgr.update_breakpoint (false, file, lineno);
296  }
297 
298  return retval;
299 }
300 
OCTAVE_END_NAMESPACE(octave)
std::set< int > bp_lines
Definition: bp-table.h:68
Provides threadsafe access to octave.
void update_breakpoint(bool insert, const std::string &file, int line, const std::string &cond="")
octave_idx_type length(void) const
Definition: ovl.h:113
octave_value_list get_list(void)
Definition: pt-bp.h:150
int get_line(void)
Definition: pt-bp.h:154
octave_value_list get_cond_list(void)
Definition: pt-bp.h:152
tree_expression * set_print_flag(bool print)
Definition: pt-exp.h:126
bool print_result(void) const
Definition: pt-exp.h:102
bool is_end_of_file(void) const
Definition: pt-cmd.h:86
bool is_end_of_fcn_or_script(void) const
Definition: pt-cmd.h:81
void accept(tree_walker &tw)
Definition: pt-stmt.h:199
octave_value_list list_breakpoints(void)
Definition: pt-stmt.cc:221
std::list< bp_type > breakpoints_and_conds(void)
Definition: pt-stmt.cc:231
int set_breakpoint(int line, const std::string &condition)
Definition: pt-stmt.cc:190
void delete_breakpoint(int line)
Definition: pt-stmt.cc:199
bp_table::bp_lines remove_all_breakpoints(event_manager &evmgr, const std::string &file)
Definition: pt-stmt.cc:279
bp_table::bp_lines add_breakpoint(event_manager &evmgr, const std::string &file, const bp_table::bp_lines &lines, const std::string &condition)
Definition: pt-stmt.cc:255
std::string bp_cond() const
Definition: pt-stmt.cc:111
bool is_breakpoint(void) const
Definition: pt-stmt.cc:95
bool is_active_breakpoint(tree_evaluator &tw) const
Definition: pt-stmt.cc:103
bool print_result(void)
Definition: pt-stmt.cc:71
tree_command * m_command
Definition: pt-stmt.h:132
void echo_code(const std::string &prefix)
Definition: pt-stmt.cc:144
int column(void) const
Definition: pt-stmt.cc:127
void set_print_flag(bool print_flag)
Definition: pt-stmt.cc:64
void set_location(int l, int c)
Definition: pt-stmt.cc:135
int line(void) const
Definition: pt-stmt.cc:119
bool is_end_of_file(void) const
Definition: pt-stmt.cc:169
bool is_end_of_fcn_or_script(void) const
Definition: pt-stmt.cc:152
void set_breakpoint(const std::string &condition)
Definition: pt-stmt.cc:77
void delete_breakpoint(void)
Definition: pt-stmt.cc:86
tree_expression * m_expression
Definition: pt-stmt.h:135
void accept(tree_walker &tw)
Definition: pt-stmt.h:122
virtual int column(void) const
Definition: pt.h:62
const std::string bp_cond(void) const
Definition: pt.h:106
virtual void delete_breakpoint(void)
Definition: pt.h:82
bool is_active_breakpoint(tree_evaluator &tw) const
Definition: pt.h:99
virtual int line(void) const
Definition: pt.h:60
bool is_breakpoint(void) const
Definition: pt.h:94
void set_location(int l, int c)
Definition: pt.h:68
virtual void set_breakpoint(const std::string &condition)
Definition: pt.h:74
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define octave_stdout
Definition: pager.h:314
F77_RET_T len
Definition: xerbla.cc:61