GNU Octave 11.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
pt-loop.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_loop_h)
27#define octave_pt_loop_h 1
28
29#include "octave-config.h"
30
31class octave_value;
32
33#include "pt-cmd.h"
34#include "pt-walk.h"
35
37
38class comment_list;
40class tree_expression;
42
43// While.
44
45class OCTINTERP_API tree_while_command : public tree_command
46{
47public:
48
49 tree_while_command (const token& while_tok, tree_expression *expr, tree_statement_list *body, const token& end_tok)
50 : m_while_tok (while_tok), m_expr (expr), m_body (body), m_end_tok (end_tok)
51 { }
52
53 OCTAVE_DISABLE_COPY_MOVE (tree_while_command)
54
56
57 filepos beg_pos () const { return m_while_tok.beg_pos (); }
58 filepos end_pos () const { return m_end_tok.end_pos (); }
59
60 comment_list leading_comments () const { return m_while_tok.leading_comments (); }
61 comment_list trailing_comments () const { return m_end_tok.trailing_comments (); }
62
63 token while_token () const { return m_while_tok; }
64
65 tree_expression * condition () { return m_expr; }
66
67 tree_statement_list * body () { return m_body; }
68
69 token end_token () const { return m_end_tok; }
70
72 {
73 tw.visit_while_command (*this);
74 }
75
76private:
77
78 token m_while_tok;
79
80 // Expression to test.
81 tree_expression *m_expr;
82
83 // List of commands to execute.
84 tree_statement_list *m_body {nullptr};
85
86 token m_end_tok;
87};
88
89// Do-Until.
90
91class OCTINTERP_API tree_do_until_command : public tree_command
92{
93public:
94
95 tree_do_until_command (const token& do_tok, tree_statement_list *body, const token& until_tok, tree_expression *expr)
96 : m_do_tok (do_tok), m_body (body), m_until_tok (until_tok), m_expr (expr)
97 { }
98
99 OCTAVE_DISABLE_COPY_MOVE (tree_do_until_command)
100
102
103 filepos beg_pos () const { return m_do_tok.beg_pos (); }
104 filepos end_pos () const { return m_expr->end_pos (); }
105
106 comment_list leading_comments () const { return m_do_tok.leading_comments (); }
107 comment_list trailing_comments () const { return m_expr->trailing_comments (); }
108
109 token do_token () const { return m_do_tok; }
110
111 tree_statement_list * body () { return m_body; }
112
113 token until_token () const { return m_until_tok; }
114
115 tree_expression * condition () { return m_expr; }
116
118 {
119 tw.visit_do_until_command (*this);
120 }
121
122private:
123
124 token m_do_tok;
125
126 // List of commands to execute.
127 tree_statement_list *m_body {nullptr};
128
129 token m_until_tok;
130
131 // Expression to test.
132 tree_expression *m_expr;
133};
134
135// For.
136
137class OCTINTERP_API tree_simple_for_command : public tree_command
138{
139public:
140
141 tree_simple_for_command (bool parfor, const token& for_tok, const token& open_paren, tree_expression *le, const token& eq_tok,
142 tree_expression *re, const token& sep_tok, tree_expression *maxproc_arg, const token& close_paren,
143 tree_statement_list *body, const token& end_tok)
144 : m_parfor (parfor), m_for_tok (for_tok), m_open_paren (open_paren), m_lhs (le), m_eq_tok (eq_tok),
145 m_expr (re), m_sep_tok (sep_tok), m_maxproc (maxproc_arg), m_close_paren (close_paren),
146 m_body (body), m_end_tok (end_tok)
147 { }
148
149 OCTAVE_DISABLE_COPY_MOVE (tree_simple_for_command)
150
152
153 bool in_parallel () { return m_parfor; }
154
155 filepos beg_pos () const { return m_for_tok.beg_pos (); }
156 filepos end_pos () const { return m_end_tok.end_pos (); }
157
158 comment_list leading_comments () const { return m_for_tok.leading_comments (); }
159 comment_list trailing_comments () const { return m_end_tok.trailing_comments (); }
160
161 token for_token () const { return m_for_tok; }
162
163 token open_paren () const { return m_open_paren; }
164
165 tree_expression * left_hand_side () { return m_lhs; }
166
167 tree_expression * control_expr () { return m_expr; }
168
169 tree_expression * maxproc_expr () { return m_maxproc; }
170
171 token close_paren () const { return m_close_paren; }
172
173 tree_statement_list * body () { return m_body; }
174
175 token end_token () const { return m_end_tok; }
176
178 {
179 tw.visit_simple_for_command (*this);
180 }
181
182private:
183
184 // FIXME: it would be better to get this info from FOR_TOK.
185 bool m_parfor {false};
186
187 token m_for_tok;
188
189 token m_open_paren;
190
191 // Expression to modify.
192 tree_expression *m_lhs;
193
194 token m_eq_tok;
195
196 // Expression to evaluate.
197 tree_expression *m_expr;
198
199 token m_sep_tok;
200
201 // Expression to tell how many processors should be used (only valid
202 // if parallel is TRUE).
203 tree_expression *m_maxproc {nullptr};
204
205 token m_close_paren;
206
207 // List of commands to execute.
208 tree_statement_list *m_body;
209
210 token m_end_tok;
211};
212
213class OCTINTERP_API tree_complex_for_command : public tree_command
214{
215public:
216
218 tree_statement_list *body, const token& end_tok)
219 : m_for_tok (for_tok), m_lhs (le), m_eq_tok (eq_tok), m_expr (re), m_body (body), m_end_tok (end_tok)
220 { }
221
222 OCTAVE_DISABLE_COPY_MOVE (tree_complex_for_command)
223
225
226 filepos beg_pos () const { return m_for_tok.beg_pos (); }
227 filepos end_pos () const { return m_end_tok.end_pos (); }
228
229 comment_list leading_comments () const { return m_for_tok.leading_comments (); }
230 comment_list trailing_comments () const { return m_end_tok.trailing_comments (); }
231
232 token for_token () const { return m_for_tok; }
233
234 tree_argument_list * left_hand_side () { return m_lhs; }
235
236 tree_expression * control_expr () { return m_expr; }
237
238 tree_statement_list * body () { return m_body; }
239
240 token end_token () { return m_end_tok; }
241
243 {
244 tw.visit_complex_for_command (*this);
245 }
246
247private:
248
249 token m_for_tok;
250
251 // Expression to modify.
252 tree_argument_list *m_lhs;
253
254 token m_eq_tok;
255
256 // Expression to evaluate.
257 tree_expression *m_expr;
258
259 // List of commands to execute.
260 tree_statement_list *m_body;
261
262 token m_end_tok;
263};
264
265OCTAVE_END_NAMESPACE(octave)
266
267#endif
Definition token.h:42
void accept(tree_walker &tw)
Definition pt-loop.h:242
tree_argument_list * left_hand_side()
Definition pt-loop.h:234
tree_statement_list * body()
Definition pt-loop.h:238
tree_complex_for_command(const token &for_tok, tree_argument_list *le, const token &eq_tok, tree_expression *re, tree_statement_list *body, const token &end_tok)
Definition pt-loop.h:217
filepos end_pos() const
Definition pt-loop.h:227
comment_list trailing_comments() const
Definition pt-loop.h:230
tree_expression * control_expr()
Definition pt-loop.h:236
token for_token() const
Definition pt-loop.h:232
comment_list leading_comments() const
Definition pt-loop.h:229
filepos beg_pos() const
Definition pt-loop.h:226
tree_expression * condition()
Definition pt-loop.h:115
void accept(tree_walker &tw)
Definition pt-loop.h:117
comment_list leading_comments() const
Definition pt-loop.h:106
token do_token() const
Definition pt-loop.h:109
tree_do_until_command(const token &do_tok, tree_statement_list *body, const token &until_tok, tree_expression *expr)
Definition pt-loop.h:95
token until_token() const
Definition pt-loop.h:113
tree_statement_list * body()
Definition pt-loop.h:111
comment_list trailing_comments() const
Definition pt-loop.h:107
filepos beg_pos() const
Definition pt-loop.h:103
filepos end_pos() const
Definition pt-loop.h:104
tree_expression * maxproc_expr()
Definition pt-loop.h:169
comment_list trailing_comments() const
Definition pt-loop.h:159
token end_token() const
Definition pt-loop.h:175
tree_simple_for_command(bool parfor, const token &for_tok, const token &open_paren, tree_expression *le, const token &eq_tok, tree_expression *re, const token &sep_tok, tree_expression *maxproc_arg, const token &close_paren, tree_statement_list *body, const token &end_tok)
Definition pt-loop.h:141
filepos end_pos() const
Definition pt-loop.h:156
token open_paren() const
Definition pt-loop.h:163
void accept(tree_walker &tw)
Definition pt-loop.h:177
token close_paren() const
Definition pt-loop.h:171
filepos beg_pos() const
Definition pt-loop.h:155
comment_list leading_comments() const
Definition pt-loop.h:158
tree_expression * left_hand_side()
Definition pt-loop.h:165
tree_expression * control_expr()
Definition pt-loop.h:167
tree_statement_list * body()
Definition pt-loop.h:173
token for_token() const
Definition pt-loop.h:161
virtual void visit_complex_for_command(tree_complex_for_command &)
Definition pt-walk.cc:259
virtual void visit_do_until_command(tree_do_until_command &)
Definition pt-walk.cc:640
virtual void visit_simple_for_command(tree_simple_for_command &)
Definition pt-walk.cc:235
virtual void visit_while_command(tree_while_command &)
Definition pt-walk.cc:626
comment_list leading_comments() const
Definition pt-loop.h:60
comment_list trailing_comments() const
Definition pt-loop.h:61
tree_while_command(const token &while_tok, tree_expression *expr, tree_statement_list *body, const token &end_tok)
Definition pt-loop.h:49
void accept(tree_walker &tw)
Definition pt-loop.h:71
filepos end_pos() const
Definition pt-loop.h:58
tree_statement_list * body()
Definition pt-loop.h:67
token while_token() const
Definition pt-loop.h:63
tree_expression * condition()
Definition pt-loop.h:65
token end_token() const
Definition pt-loop.h:69
filepos beg_pos() const
Definition pt-loop.h:57
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn