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.h
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 (octave_pt_stmt_h)
27#define octave_pt_stmt_h 1
28
29#include "octave-config.h"
30
32
33#include <deque>
34#include <list>
35
36#include "bp-table.h"
37#include "pt.h"
38#include "pt-walk.h"
39
40class event_manager;
41
43
44class comment_list;
45class tree_command;
46class tree_evaluator;
47class tree_expression;
48
49// A statement is either a command to execute or an expression to
50// evaluate.
51
52class tree_statement : public tree
53{
54public:
55
57 : m_command (nullptr), m_expression (nullptr)
58 { }
59
61 : m_command (c), m_expression (nullptr)
62 { }
63
65 : m_command (nullptr), m_expression (e)
66 { }
67
68 OCTAVE_DISABLE_COPY_MOVE (tree_statement)
69
71
72 void set_print_flag (bool print_flag);
73
74 bool print_result ();
75
76 bool is_command () const { return m_command != nullptr; }
77
78 bool is_expression () const { return m_expression != nullptr; }
79
80 void set_breakpoint (const std::string& condition);
81
82 void delete_breakpoint ();
83
84 bool is_breakpoint () const;
85
86 bool is_active_breakpoint (tree_evaluator& tw) const;
87
89
90 filepos beg_pos () const;
91 filepos end_pos () const;
92
93 virtual void update_end_pos (const filepos& pos);
94
95 std::string bp_cond () const;
96
97 int line () const;
98 int column () const;
99
100 void echo_code (const std::string& prefix);
101
102 tree_command * command () { return m_command; }
103
104 tree_expression * expression () { return m_expression; }
105
106 bool is_null_statement () const
107 {
108 return ! (m_command || m_expression);
109 }
110
111 bool is_end_of_fcn_or_script () const;
112
113 bool is_end_of_file () const;
114
115 // Allow modification of this statement. Note that there is no
116 // checking. If you use these, are you sure you know what you are
117 // doing?
118
119 void set_command (tree_command *c) { m_command = c; }
120
121 void set_expression (tree_expression *e) { m_expression = e; }
122
124 {
125 tw.visit_statement (*this);
126 }
127
128private:
129
130 // Only one of cmd or expr can be valid at once.
131
132 // Command to execute.
133 tree_command *m_command;
134
135 // Expression to evaluate.
136 tree_expression *m_expression;
137};
138
139// A list of statements to evaluate.
140
141class tree_statement_list : public std::list<tree_statement *>
142{
143public:
144
146 : m_function_body (false), m_anon_function_body (false),
147 m_script_body (false) { }
148
150 : m_function_body (false), m_anon_function_body (false),
151 m_script_body (false) { push_back (s); }
152
153 OCTAVE_DISABLE_COPY_MOVE (tree_statement_list)
154
156 {
157 while (! empty ())
158 {
159 auto p = begin ();
160 delete *p;
161 erase (p);
162 }
163 }
164
166 {
167 if (empty ())
168 return filepos ();
169
170 tree_statement *elt = front ();
171 return elt->beg_pos ();
172 }
173
175 {
176 if (empty ())
177 return filepos ();
178
179 tree_statement *elt = back ();
180 return elt->end_pos ();
181 }
182
183 void mark_as_function_body () { m_function_body = true; }
184
185 void mark_as_anon_function_body () { m_anon_function_body = true; }
186
187 void mark_as_script_body () { m_script_body = true; }
188
189 bool is_function_body () const { return m_function_body; }
190
191 bool is_anon_function_body () const { return m_anon_function_body; }
192
193 bool is_script_body () const { return m_script_body; }
194
196
197 int set_breakpoint (int line, const std::string& condition);
198
199 void delete_breakpoint (int line);
200
202
203 std::list<bp_type> breakpoints_and_conds ();
204
206 const std::string& file,
207 const bp_table::bp_lines& lines,
208 const std::string& condition);
209
211 const std::string& file);
212
214 {
215 tw.visit_statement_list (*this);
216 }
217
218private:
219
220 // Does this list of statements make up the body of a function?
221 bool m_function_body;
222
223 // Does this list of statements make up the body of a function?
224 bool m_anon_function_body;
225
226 // Does this list of statements make up the body of a script?
227 bool m_script_body;
228};
229
230OCTAVE_END_NAMESPACE(octave)
231
232#endif
std::set< int > bp_lines
Definition bp-table.h:70
Provides threadsafe access to octave.
void accept(tree_walker &tw)
Definition pt-stmt.h:213
bool is_function_body() const
Definition pt-stmt.h:189
octave_value_list list_breakpoints()
Definition pt-stmt.cc:254
void mark_as_anon_function_body()
Definition pt-stmt.h:185
filepos beg_pos() const
Definition pt-stmt.h:165
filepos end_pos() const
Definition pt-stmt.h:174
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
bool is_script_body() const
Definition pt-stmt.h:193
void delete_breakpoint(int line)
Definition pt-stmt.cc:232
void mark_as_script_body()
Definition pt-stmt.h:187
bp_table::bp_lines remove_all_breakpoints(event_manager &evmgr, const std::string &file)
Definition pt-stmt.cc:312
tree_statement_list(tree_statement *s)
Definition pt-stmt.h:149
bool is_anon_function_body() const
Definition pt-stmt.h:191
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
void mark_as_function_body()
Definition pt-stmt.h:183
tree_command * command()
Definition pt-stmt.h:102
std::string bp_cond() const
Definition pt-stmt.cc:139
bool is_active_breakpoint(tree_evaluator &tw) const
Definition pt-stmt.cc:102
tree_expression * expression()
Definition pt-stmt.h:104
void echo_code(const std::string &prefix)
Definition pt-stmt.cc:163
int column() const
Definition pt-stmt.cc:155
bool is_command() const
Definition pt-stmt.h:76
void set_print_flag(bool print_flag)
Definition pt-stmt.cc:63
tree_statement(tree_expression *e)
Definition pt-stmt.h:64
tree_statement(tree_command *c)
Definition pt-stmt.h:60
bool is_end_of_file() const
Definition pt-stmt.cc:188
bool is_expression() const
Definition pt-stmt.h:78
void set_expression(tree_expression *e)
Definition pt-stmt.h:121
bool is_null_statement() const
Definition pt-stmt.h:106
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
void set_command(tree_command *c)
Definition pt-stmt.h:119
bool is_end_of_fcn_or_script() const
Definition pt-stmt.cc:171
virtual void visit_statement(tree_statement &)
Definition pt-walk.cc:567
virtual void visit_statement_list(tree_statement_list &)
Definition pt-walk.cc:583
Definition pt.h:47
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn