GNU Octave 11.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-2026 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 ? m_command->beg_pos () : m_expression->beg_pos ());
113}
114
117{
118 return (m_command ? m_command->end_pos () : m_expression->end_pos ());
119}
120
123{
124 return m_command ? m_command->leading_comments () : m_expression->leading_comments ();
125}
126
129{
130 return m_command ? m_command->trailing_comments () : m_expression->trailing_comments ();
131}
132
133void
135{
136 if (m_command)
137 m_command->update_end_pos (pos);
138 else
139 error ("unexpected call to tree_statement::update_end_pos - please report this bug");
140}
141
142std::string
144{
145 return (m_command
146 ? m_command->bp_cond ()
147 : (m_expression ? m_expression->bp_cond () : "0"));
148}
149
150int
152{
153 return (m_command
154 ? m_command->line ()
155 : (m_expression ? m_expression->line () : -1));
156}
157
158int
160{
161 return (m_command
162 ? m_command->column ()
163 : (m_expression ? m_expression->column () : -1));
164}
165
166void
167tree_statement::echo_code (const std::string& prefix)
168{
169 tree_print_code tpc (octave_stdout, prefix);
170
171 accept (tpc);
172}
173
174bool
176{
177 bool retval = false;
178
179 if (m_command)
180 {
181 tree_no_op_command *no_op_cmd
182 = dynamic_cast<tree_no_op_command *> (m_command);
183
184 if (no_op_cmd)
185 retval = no_op_cmd->is_end_of_fcn_or_script ();
186 }
187
188 return retval;
189}
190
191bool
193{
194 bool retval = false;
195
196 if (m_command)
197 {
198 tree_no_op_command *no_op_cmd
199 = dynamic_cast<tree_no_op_command *> (m_command);
200
201 if (no_op_cmd)
202 retval = no_op_cmd->is_end_of_file ();
203 }
204
205 return retval;
206}
207
208// Create a "breakpoint" tree-walker, and get it to "walk" this
209// statement list
210// (FIXME: What does that do???)
211
212int
213tree_statement_list::set_breakpoint (int line, const std::string& condition)
214{
215 tree_breakpoint tbp (line, tree_breakpoint::set, condition);
216 accept (tbp);
217
218 return tbp.get_line ();
219}
220
221void
223{
224 if (line < 0)
225 {
227
228 int len = bp_lst.length ();
229
230 for (int i = 0; i < len; i++)
231 {
233 accept (tbp);
234 }
235 }
236 else
237 {
239 accept (tbp);
240 }
241}
242
245{
247 accept (tbp);
248
249 return tbp.get_list ();
250}
251
252// Get list of pairs (breakpoint line, breakpoint condition)
253std::list<bp_type>
255{
257 accept (tbp);
258
259 std::list<bp_type> retval;
260 octave_value_list lines = tbp.get_list ();
261 octave_value_list conds = tbp.get_cond_list ();
262
263 for (int i = 0; i < lines.length (); i++)
264 {
265 retval.push_back (bp_type (lines(i).double_value (),
266 conds(i).string_value ()));
267 }
268
269 return retval;
270}
271
272// Add breakpoints to file at multiple lines (the second arguments
273// of line), to stop only if condition is true.
274// Updates GUI via event_manager::update_breakpoint.
275// FIXME: COME BACK TO ME.
276
279 const std::string& file,
280 const bp_table::bp_lines& lines,
281 const std::string& condition)
282{
283 bp_table::bp_lines retval;
284
285 for (const auto& lineno : lines)
286 {
287 int line = set_breakpoint (lineno, condition);
288
289 if (line)
290 {
291 if (! file.empty ())
292 evmgr.update_breakpoint (true, file, line, condition);
293
294 retval.insert (line);
295 }
296 }
297
298 return retval;
299}
300
303 const std::string& file)
304{
305 bp_table::bp_lines retval;
306
308
309 for (int i = 0; i < bkpts.length (); i++)
310 {
311 int lineno = bkpts(i).int_value ();
312
313 delete_breakpoint (lineno);
314
315 retval.insert (lineno);
316
317 if (! file.empty ())
318 evmgr.update_breakpoint (false, file, lineno);
319 }
320
321 return retval;
322}
323
324OCTAVE_END_NAMESPACE(octave)
std::set< int > bp_lines
Definition bp-table.h:71
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:136
bool is_end_of_fcn_or_script() const
Definition pt-cmd.h:99
bool is_end_of_file() const
Definition pt-cmd.h:104
void accept(tree_walker &tw)
Definition pt-stmt.h:230
octave_value_list list_breakpoints()
Definition pt-stmt.cc:244
std::list< bp_type > breakpoints_and_conds()
Definition pt-stmt.cc:254
int set_breakpoint(int line, const std::string &condition)
Definition pt-stmt.cc:213
void delete_breakpoint(int line)
Definition pt-stmt.cc:222
bp_table::bp_lines remove_all_breakpoints(event_manager &evmgr, const std::string &file)
Definition pt-stmt.cc:302
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:278
std::string bp_cond() const
Definition pt-stmt.cc:143
bool is_active_breakpoint(tree_evaluator &tw) const
Definition pt-stmt.cc:102
void echo_code(const std::string &prefix)
Definition pt-stmt.cc:167
int column() const
Definition pt-stmt.cc:159
void set_print_flag(bool print_flag)
Definition pt-stmt.cc:63
bool is_end_of_file() const
Definition pt-stmt.cc:192
void delete_breakpoint()
Definition pt-stmt.cc:85
filepos end_pos() const
Definition pt-stmt.cc:116
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:110
bool is_breakpoint() const
Definition pt-stmt.cc:94
comment_list leading_comments() const
Definition pt-stmt.cc:122
comment_list trailing_comments() const
Definition pt-stmt.cc:128
virtual void update_end_pos(const filepos &pos)
Definition pt-stmt.cc:134
void accept(tree_walker &tw)
Definition pt-stmt.h:124
int line() const
Definition pt-stmt.cc:151
bool is_end_of_fcn_or_script() const
Definition pt-stmt.cc:175
virtual int line() const
Definition pt.cc:45
virtual filepos end_pos() const =0
virtual comment_list trailing_comments() 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 =0
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:1008
#define octave_stdout
Definition pager.h:301
F77_RET_T len
Definition xerbla.cc:61