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.h
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 (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 OCTINTERP_API 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
88 filepos beg_pos () const;
89 filepos end_pos () const;
90
93
94 virtual void update_end_pos (const filepos& pos);
95
96 std::string bp_cond () const;
97
98 int line () const;
99 int column () const;
100
101 void echo_code (const std::string& prefix);
102
103 tree_command * command () { return m_command; }
104
105 tree_expression * expression () { return m_expression; }
106
107 bool is_null_statement () const
108 {
109 return ! (m_command || m_expression);
110 }
111
112 bool is_end_of_fcn_or_script () const;
113
114 bool is_end_of_file () const;
115
116 // Allow modification of this statement. Note that there is no
117 // checking. If you use these, are you sure you know what you are
118 // doing?
119
120 void set_command (tree_command *c) { m_command = c; }
121
122 void set_expression (tree_expression *e) { m_expression = e; }
123
125 {
126 tw.visit_statement (*this);
127 }
128
129private:
130
131 // Only one of cmd or expr can be valid at once.
132
133 // Command to execute.
134 tree_command *m_command;
135
136 // Expression to evaluate.
137 tree_expression *m_expression;
138};
139
140// A list of statements to evaluate.
141
142class OCTINTERP_API tree_statement_list : public std::list<tree_statement *>
143{
144public:
145
147 : m_function_body (false), m_anon_function_body (false),
148 m_script_body (false) { }
149
151 : m_function_body (false), m_anon_function_body (false),
152 m_script_body (false) { push_back (s); }
153
154 OCTAVE_DISABLE_COPY_MOVE (tree_statement_list)
155
157 {
158 while (! empty ())
159 {
160 auto p = begin ();
161 delete *p;
162 erase (p);
163 }
164 }
165
167 {
168 if (empty ())
169 return filepos ();
170
171 tree_statement *elt = front ();
172 return elt->beg_pos ();
173 }
174
176 {
177 if (empty ())
178 return filepos ();
179
180 tree_statement *elt = back ();
181 return elt->end_pos ();
182 }
183
185 {
186 if (empty ())
187 return comment_list ();
188
189 tree_statement *elt = front ();
190 return elt->leading_comments ();
191 }
192
194 {
195 if (empty ())
196 return comment_list ();
197
198 tree_statement *elt = back ();
199 return elt->trailing_comments ();
200 }
201
202 void mark_as_function_body () { m_function_body = true; }
203
204 void mark_as_anon_function_body () { m_anon_function_body = true; }
205
206 void mark_as_script_body () { m_script_body = true; }
207
208 bool is_function_body () const { return m_function_body; }
209
210 bool is_anon_function_body () const { return m_anon_function_body; }
211
212 bool is_script_body () const { return m_script_body; }
213
214 int set_breakpoint (int line, const std::string& condition);
215
216 void delete_breakpoint (int line);
217
218 octave_value_list list_breakpoints ();
219
220 std::list<bp_type> breakpoints_and_conds ();
221
222 bp_table::bp_lines add_breakpoint (event_manager& evmgr,
223 const std::string& file,
224 const bp_table::bp_lines& lines,
225 const std::string& condition);
226
227 bp_table::bp_lines remove_all_breakpoints (event_manager& evmgr,
228 const std::string& file);
229
231 {
232 tw.visit_statement_list (*this);
233 }
234
235private:
236
237 // Does this list of statements make up the body of a function?
238 bool m_function_body;
239
240 // Does this list of statements make up the body of a function?
241 bool m_anon_function_body;
242
243 // Does this list of statements make up the body of a script?
244 bool m_script_body;
245};
246
247OCTAVE_END_NAMESPACE(octave)
248
249#endif
std::set< int > bp_lines
Definition bp-table.h:71
Provides threadsafe access to octave.
void accept(tree_walker &tw)
Definition pt-stmt.h:230
bool is_function_body() const
Definition pt-stmt.h:208
void mark_as_anon_function_body()
Definition pt-stmt.h:204
filepos beg_pos() const
Definition pt-stmt.h:166
filepos end_pos() const
Definition pt-stmt.h:175
comment_list leading_comments() const
Definition pt-stmt.h:184
bool is_script_body() const
Definition pt-stmt.h:212
comment_list trailing_comments() const
Definition pt-stmt.h:193
void mark_as_script_body()
Definition pt-stmt.h:206
tree_statement_list(tree_statement *s)
Definition pt-stmt.h:150
bool is_anon_function_body() const
Definition pt-stmt.h:210
void mark_as_function_body()
Definition pt-stmt.h:202
tree_command * command()
Definition pt-stmt.h:103
tree_expression * expression()
Definition pt-stmt.h:105
bool is_command() const
Definition pt-stmt.h:76
tree_statement(tree_expression *e)
Definition pt-stmt.h:64
tree_statement(tree_command *c)
Definition pt-stmt.h:60
bool is_expression() const
Definition pt-stmt.h:78
void set_expression(tree_expression *e)
Definition pt-stmt.h:122
bool is_null_statement() const
Definition pt-stmt.h:107
filepos end_pos() const
Definition pt-stmt.cc:116
filepos beg_pos() const
Definition pt-stmt.cc:110
comment_list leading_comments() const
Definition pt-stmt.cc:122
comment_list trailing_comments() const
Definition pt-stmt.cc:128
void accept(tree_walker &tw)
Definition pt-stmt.h:124
void set_command(tree_command *c)
Definition pt-stmt.h:120
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
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