GNU Octave  9.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-2024 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 {
73  return m_expression && m_expression->print_result ();
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)
89  m_command->delete_breakpoint ();
90  else if (m_expression)
91  m_expression->delete_breakpoint ();
92 }
93 
94 bool
96 {
97  return m_command ? m_command->is_breakpoint ()
98  : (m_expression ? m_expression->is_breakpoint ()
99  : false);
100 }
101 
102 bool
104 {
105  return m_command ? m_command->is_active_breakpoint (tw)
106  : (m_expression ? m_expression->is_active_breakpoint (tw)
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 
301 OCTAVE_END_NAMESPACE(octave)
std::set< int > bp_lines
Definition: bp-table.h:70
Provides threadsafe access to octave.
void update_breakpoint(bool insert, const std::string &file, int line, const std::string &cond="")
octave_idx_type length() const
Definition: ovl.h:113
octave_value_list get_list()
Definition: pt-bp.h:146
octave_value_list get_cond_list()
Definition: pt-bp.h:148
int get_line()
Definition: pt-bp.h:150
bool print_result() const
Definition: pt-exp.h:98
tree_expression * set_print_flag(bool print)
Definition: pt-exp.h:122
bool is_end_of_fcn_or_script() const
Definition: pt-cmd.h:73
bool is_end_of_file() const
Definition: pt-cmd.h:78
void accept(tree_walker &tw)
Definition: pt-stmt.h:191
octave_value_list list_breakpoints()
Definition: pt-stmt.cc:221
std::list< bp_type > breakpoints_and_conds()
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_active_breakpoint(tree_evaluator &tw) const
Definition: pt-stmt.cc:103
void echo_code(const std::string &prefix)
Definition: pt-stmt.cc:144
int column() 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
bool is_end_of_file() const
Definition: pt-stmt.cc:169
void delete_breakpoint()
Definition: pt-stmt.cc:86
void set_breakpoint(const std::string &condition)
Definition: pt-stmt.cc:77
bool print_result()
Definition: pt-stmt.cc:71
bool is_breakpoint() const
Definition: pt-stmt.cc:95
void accept(tree_walker &tw)
Definition: pt-stmt.h:118
int line() const
Definition: pt-stmt.cc:119
bool is_end_of_fcn_or_script() const
Definition: pt-stmt.cc:152
bool is_breakpoint() const
Definition: pt.h:87
virtual void delete_breakpoint()
Definition: pt.h:78
virtual int line() const
Definition: pt.h:56
const std::string bp_cond() const
Definition: pt.h:99
bool is_active_breakpoint(tree_evaluator &tw) const
Definition: pt.h:92
virtual int column() const
Definition: pt.h:58
void set_location(int l, int c)
Definition: pt.h:64
virtual void set_breakpoint(const std::string &condition)
Definition: pt.h:70
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define octave_stdout
Definition: pager.h:309
F77_RET_T len
Definition: xerbla.cc:61