GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
pt-stmt.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1996-2025 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}
61
62void
64{
65 if (m_expression)
66 m_expression->set_print_flag (print_flag);
67}
68
69bool
71{
72 return m_expression && m_expression->print_result ();
73}
74
75void
76tree_statement::set_breakpoint (const std::string& condition)
77{
78 if (m_command)
79 m_command->set_breakpoint (condition);
80 else if (m_expression)
81 m_expression->set_breakpoint (condition);
82}
83
84void
86{
87 if (m_command)
88 m_command->delete_breakpoint ();
89 else if (m_expression)
90 m_expression->delete_breakpoint ();
91}
92
93bool
95{
96 return m_command ? m_command->is_breakpoint ()
97 : (m_expression ? m_expression->is_breakpoint ()
98 : false);
99}
100
101bool
103{
104 return m_command ? m_command->is_active_breakpoint (tw)
105 : (m_expression ? m_expression->is_active_breakpoint (tw)
106 : false);
107}
108
111{
112 return (m_command
113 ? m_command->leading_comments ()
114 : m_expression->leading_comments ());
115}
116
119{
120 return (m_command ? m_command->beg_pos () : m_expression->beg_pos ());
121}
122
125{
126 return (m_command ? m_command->end_pos () : m_expression->end_pos ());
127}
128
129void
131{
132 if (m_command)
133 m_command->update_end_pos (pos);
134 else
135 error ("unexpected call to tree_statement::update_end_pos - please report this bug");
136}
137
138std::string
140{
141 return (m_command
142 ? m_command->bp_cond ()
143 : (m_expression ? m_expression->bp_cond () : "0"));
144}
145
146int
148{
149 return (m_command
150 ? m_command->line ()
151 : (m_expression ? m_expression->line () : -1));
152}
153
154int
156{
157 return (m_command
158 ? m_command->column ()
159 : (m_expression ? m_expression->column () : -1));
160}
161
162void
163tree_statement::echo_code (const std::string& prefix)
164{
165 tree_print_code tpc (octave_stdout, prefix);
166
167 accept (tpc);
168}
169
170bool
172{
173 bool retval = false;
174
175 if (m_command)
176 {
177 tree_no_op_command *no_op_cmd
178 = dynamic_cast<tree_no_op_command *> (m_command);
179
180 if (no_op_cmd)
181 retval = no_op_cmd->is_end_of_fcn_or_script ();
182 }
183
184 return retval;
185}
186
187bool
189{
190 bool retval = false;
191
192 if (m_command)
193 {
194 tree_no_op_command *no_op_cmd
195 = dynamic_cast<tree_no_op_command *> (m_command);
196
197 if (no_op_cmd)
198 retval = no_op_cmd->is_end_of_file ();
199 }
200
201 return retval;
202}
203
206{
207 if (! empty ())
208 {
209 tree_statement *elt = front ();
210
211 if (elt)
212 return elt->leading_comments ();
213 }
214
215 return comment_list ();
216}
217
218// Create a "breakpoint" tree-walker, and get it to "walk" this
219// statement list
220// (FIXME: What does that do???)
221
222int
223tree_statement_list::set_breakpoint (int line, const std::string& condition)
224{
225 tree_breakpoint tbp (line, tree_breakpoint::set, condition);
226 accept (tbp);
227
228 return tbp.get_line ();
229}
230
231void
233{
234 if (line < 0)
235 {
237
238 int len = bp_lst.length ();
239
240 for (int i = 0; i < len; i++)
241 {
243 accept (tbp);
244 }
245 }
246 else
247 {
249 accept (tbp);
250 }
251}
252
255{
257 accept (tbp);
258
259 return tbp.get_list ();
260}
261
262// Get list of pairs (breakpoint line, breakpoint condition)
263std::list<bp_type>
265{
267 accept (tbp);
268
269 std::list<bp_type> retval;
270 octave_value_list lines = tbp.get_list ();
271 octave_value_list conds = tbp.get_cond_list ();
272
273 for (int i = 0; i < lines.length (); i++)
274 {
275 retval.push_back (bp_type (lines(i).double_value (),
276 conds(i).string_value ()));
277 }
278
279 return retval;
280}
281
282// Add breakpoints to file at multiple lines (the second arguments
283// of line), to stop only if condition is true.
284// Updates GUI via event_manager::update_breakpoint.
285// FIXME: COME BACK TO ME.
286
289 const std::string& file,
290 const bp_table::bp_lines& lines,
291 const std::string& condition)
292{
293 bp_table::bp_lines retval;
294
295 for (const auto& lineno : lines)
296 {
297 int line = set_breakpoint (lineno, condition);
298
299 if (line)
300 {
301 if (! file.empty ())
302 evmgr.update_breakpoint (true, file, line, condition);
303
304 retval.insert (line);
305 }
306 }
307
308 return retval;
309}
310
313 const std::string& file)
314{
315 bp_table::bp_lines retval;
316
318
319 for (int i = 0; i < bkpts.length (); i++)
320 {
321 int lineno = bkpts(i).int_value ();
322
323 delete_breakpoint (lineno);
324
325 retval.insert (lineno);
326
327 if (! file.empty ())
328 evmgr.update_breakpoint (false, file, lineno);
329 }
330
331 return retval;
332}
333
334OCTAVE_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:111
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
virtual void update_end_pos(const filepos &)
Definition pt-cmd.h:55
bool print_result() const
Definition pt-exp.h:107
tree_expression * set_print_flag(bool print)
Definition pt-exp.h:131
bool is_end_of_fcn_or_script() const
Definition pt-cmd.h:103
bool is_end_of_file() const
Definition pt-cmd.h:108
void accept(tree_walker &tw)
Definition pt-stmt.h:213
octave_value_list list_breakpoints()
Definition pt-stmt.cc:254
comment_list leading_comments() const
Definition pt-stmt.cc:205
std::list< bp_type > breakpoints_and_conds()
Definition pt-stmt.cc:264
int set_breakpoint(int line, const std::string &condition)
Definition pt-stmt.cc:223
void delete_breakpoint(int line)
Definition pt-stmt.cc:232
bp_table::bp_lines remove_all_breakpoints(event_manager &evmgr, const std::string &file)
Definition pt-stmt.cc:312
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:288
std::string bp_cond() const
Definition pt-stmt.cc:139
bool is_active_breakpoint(tree_evaluator &tw) const
Definition pt-stmt.cc:102
void echo_code(const std::string &prefix)
Definition pt-stmt.cc:163
int column() const
Definition pt-stmt.cc:155
void set_print_flag(bool print_flag)
Definition pt-stmt.cc:63
bool is_end_of_file() const
Definition pt-stmt.cc:188
void delete_breakpoint()
Definition pt-stmt.cc:85
filepos end_pos() const
Definition pt-stmt.cc:124
void set_breakpoint(const std::string &condition)
Definition pt-stmt.cc:76
bool print_result()
Definition pt-stmt.cc:70
filepos beg_pos() const
Definition pt-stmt.cc:118
bool is_breakpoint() const
Definition pt-stmt.cc:94
comment_list leading_comments() const
Definition pt-stmt.cc:110
virtual void update_end_pos(const filepos &pos)
Definition pt-stmt.cc:130
void accept(tree_walker &tw)
Definition pt-stmt.h:123
int line() const
Definition pt-stmt.cc:147
bool is_end_of_fcn_or_script() const
Definition pt-stmt.cc:171
virtual int line() const
Definition pt.cc:45
virtual filepos end_pos() const =0
virtual filepos beg_pos() const =0
bool is_breakpoint() const
Definition pt.h:82
virtual void delete_breakpoint()
Definition pt.h:73
virtual comment_list leading_comments() const
Definition pt.cc:57
const std::string bp_cond() const
Definition pt.h:94
bool is_active_breakpoint(tree_evaluator &tw) const
Definition pt.h:87
virtual int column() const
Definition pt.cc:51
virtual void set_breakpoint(const std::string &condition)
Definition pt.h:65
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void error(const char *fmt,...)
Definition error.cc:1003
#define octave_stdout
Definition pager.h:301
F77_RET_T len
Definition xerbla.cc:61