GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pt-loop.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1996-2023 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 
31 class octave_value;
32 
33 #include "pt-cmd.h"
34 #include "pt-walk.h"
35 
37 
38 class tree_argument_list;
39 class tree_expression;
41 
42 // While.
43 
45 {
46 public:
47 
48  tree_while_command (int l = -1, int c = -1)
49  : tree_command (l, c), m_expr (nullptr), m_list (nullptr),
50  m_lead_comm (nullptr), m_trail_comm (nullptr)
51  { }
52 
54  comment_list *lc = nullptr,
55  comment_list *tc = nullptr,
56  int l = -1, int c = -1)
57  : tree_command (l, c), m_expr (e), m_list (nullptr),
58  m_lead_comm (lc), m_trail_comm (tc)
59  { }
60 
62  comment_list *lc = nullptr,
63  comment_list *tc = nullptr,
64  int l = -1, int c = -1)
65  : tree_command (l, c), m_expr (e), m_list (lst), m_lead_comm (lc),
66  m_trail_comm (tc)
67  { }
68 
69  // No copying!
70 
72 
74 
75  ~tree_while_command (void);
76 
77  tree_expression * condition (void) { return m_expr; }
78 
79  tree_statement_list * body (void) { return m_list; }
80 
82 
84 
85  void accept (tree_walker& tw)
86  {
87  tw.visit_while_command (*this);
88  }
89 
90 protected:
91 
92  // Expression to test.
94 
95  // List of commands to execute.
97 
98  // Comment preceding WHILE token.
100 
101  // Comment preceding ENDWHILE token.
103 };
104 
105 // Do-Until.
106 
108 {
109 public:
110 
111  tree_do_until_command (int l = -1, int c = -1)
112  : tree_while_command (l, c)
113  { }
114 
116  comment_list *lc = nullptr,
117  comment_list *tc = nullptr,
118  int l = -1, int c = -1)
119  : tree_while_command (e, lc, tc, l, c)
120  { }
121 
123  comment_list *lc = nullptr,
124  comment_list *tc = nullptr,
125  int l = -1, int c = -1)
126  : tree_while_command (e, lst, lc, tc, l, c)
127  { }
128 
129  // No copying!
130 
132 
134 
135  ~tree_do_until_command (void) = default;
136 
137  void accept (tree_walker& tw)
138  {
139  tw.visit_do_until_command (*this);
140  }
141 };
142 
143 // For.
144 
146 {
147 public:
148 
149  tree_simple_for_command (int l = -1, int c = -1)
150  : tree_command (l, c), m_parallel (false), m_lhs (nullptr),
151  m_expr (nullptr), m_maxproc (nullptr), m_list (nullptr),
152  m_lead_comm (nullptr), m_trail_comm (nullptr)
153  { }
154 
155  tree_simple_for_command (bool parallel_arg, tree_expression *le,
156  tree_expression *re,
157  tree_expression *maxproc_arg,
158  tree_statement_list *lst,
159  comment_list *lc = nullptr,
160  comment_list *tc = nullptr,
161  int l = -1, int c = -1)
162  : tree_command (l, c), m_parallel (parallel_arg), m_lhs (le),
163  m_expr (re), m_maxproc (maxproc_arg), m_list (lst),
164  m_lead_comm (lc), m_trail_comm (tc)
165  { }
166 
167  // No copying!
168 
170 
172 
174 
175  bool in_parallel (void) { return m_parallel; }
176 
177  tree_expression * left_hand_side (void) { return m_lhs; }
178 
179  tree_expression * control_expr (void) { return m_expr; }
180 
182 
183  tree_statement_list * body (void) { return m_list; }
184 
186 
188 
189  void accept (tree_walker& tw)
190  {
191  tw.visit_simple_for_command (*this);
192  }
193 
194 private:
195  // TRUE means operate in parallel (subject to the value of the
196  // maxproc expression).
198 
199  // Expression to modify.
201 
202  // Expression to evaluate.
204 
205  // Expression to tell how many processors should be used (only valid
206  // if parallel is TRUE).
208 
209  // List of commands to execute.
211 
212  // Comment preceding FOR token.
214 
215  // Comment preceding ENDFOR token.
217 };
218 
220 {
221 public:
222 
223  tree_complex_for_command (int l = -1, int c = -1)
224  : tree_command (l, c), m_lhs (nullptr), m_expr (nullptr),
225  m_list (nullptr), m_lead_comm (nullptr), m_trail_comm (nullptr)
226  { }
227 
229  tree_statement_list *lst,
230  comment_list *lc = nullptr,
231  comment_list *tc = nullptr,
232  int l = -1, int c = -1)
233  : tree_command (l, c), m_lhs (le), m_expr (re), m_list (lst),
234  m_lead_comm (lc), m_trail_comm (tc)
235  { }
236 
237  // No copying!
238 
240 
242 
244 
246 
247  tree_expression * control_expr (void) { return m_expr; }
248 
249  tree_statement_list * body (void) { return m_list; }
250 
252 
254 
255  void accept (tree_walker& tw)
256  {
257  tw.visit_complex_for_command (*this);
258  }
259 
260 private:
261 
262  // Expression to modify.
264 
265  // Expression to evaluate.
267 
268  // List of commands to execute.
270 
271  // Comment preceding FOR token.
273 
274  // Comment preceding ENDFOR token.
276 };
277 
279 
280 #endif
OCTAVE_END_NAMESPACE(octave)
tree_statement_list * body(void)
Definition: pt-loop.h:249
comment_list * m_lead_comm
Definition: pt-loop.h:272
tree_argument_list * m_lhs
Definition: pt-loop.h:263
void accept(tree_walker &tw)
Definition: pt-loop.h:255
tree_complex_for_command(tree_argument_list *le, tree_expression *re, tree_statement_list *lst, comment_list *lc=nullptr, comment_list *tc=nullptr, int l=-1, int c=-1)
Definition: pt-loop.h:228
tree_complex_for_command(const tree_complex_for_command &)=delete
comment_list * trailing_comment(void)
Definition: pt-loop.h:253
tree_complex_for_command(int l=-1, int c=-1)
Definition: pt-loop.h:223
tree_complex_for_command & operator=(const tree_complex_for_command &)=delete
tree_expression * m_expr
Definition: pt-loop.h:266
~tree_complex_for_command(void)
Definition: pt-loop.cc:59
comment_list * m_trail_comm
Definition: pt-loop.h:275
comment_list * leading_comment(void)
Definition: pt-loop.h:251
tree_expression * control_expr(void)
Definition: pt-loop.h:247
tree_argument_list * left_hand_side(void)
Definition: pt-loop.h:245
tree_statement_list * m_list
Definition: pt-loop.h:269
tree_do_until_command(tree_expression *e, tree_statement_list *lst, comment_list *lc=nullptr, comment_list *tc=nullptr, int l=-1, int c=-1)
Definition: pt-loop.h:122
void accept(tree_walker &tw)
Definition: pt-loop.h:137
tree_do_until_command(const tree_do_until_command &)=delete
tree_do_until_command(int l=-1, int c=-1)
Definition: pt-loop.h:111
tree_do_until_command(tree_expression *e, comment_list *lc=nullptr, comment_list *tc=nullptr, int l=-1, int c=-1)
Definition: pt-loop.h:115
~tree_do_until_command(void)=default
tree_do_until_command & operator=(const tree_do_until_command &)=delete
~tree_simple_for_command(void)
Definition: pt-loop.cc:49
comment_list * trailing_comment(void)
Definition: pt-loop.h:187
tree_expression * m_lhs
Definition: pt-loop.h:200
comment_list * m_trail_comm
Definition: pt-loop.h:216
comment_list * leading_comment(void)
Definition: pt-loop.h:185
tree_simple_for_command(bool parallel_arg, tree_expression *le, tree_expression *re, tree_expression *maxproc_arg, tree_statement_list *lst, comment_list *lc=nullptr, comment_list *tc=nullptr, int l=-1, int c=-1)
Definition: pt-loop.h:155
tree_expression * m_maxproc
Definition: pt-loop.h:207
void accept(tree_walker &tw)
Definition: pt-loop.h:189
bool in_parallel(void)
Definition: pt-loop.h:175
tree_simple_for_command & operator=(const tree_simple_for_command &)=delete
tree_simple_for_command(const tree_simple_for_command &)=delete
comment_list * m_lead_comm
Definition: pt-loop.h:213
tree_expression * left_hand_side(void)
Definition: pt-loop.h:177
tree_expression * m_expr
Definition: pt-loop.h:203
tree_statement_list * m_list
Definition: pt-loop.h:210
tree_simple_for_command(int l=-1, int c=-1)
Definition: pt-loop.h:149
tree_expression * maxproc_expr(void)
Definition: pt-loop.h:181
tree_statement_list * body(void)
Definition: pt-loop.h:183
tree_expression * control_expr(void)
Definition: pt-loop.h:179
virtual void visit_complex_for_command(tree_complex_for_command &)
Definition: pt-walk.cc:241
virtual void visit_do_until_command(tree_do_until_command &)
Definition: pt-walk.cc:593
virtual void visit_simple_for_command(tree_simple_for_command &)
Definition: pt-walk.cc:218
virtual void visit_while_command(tree_while_command &)
Definition: pt-walk.cc:580
tree_statement_list * m_list
Definition: pt-loop.h:96
void accept(tree_walker &tw)
Definition: pt-loop.h:85
tree_expression * m_expr
Definition: pt-loop.h:93
comment_list * leading_comment(void)
Definition: pt-loop.h:81
tree_expression * condition(void)
Definition: pt-loop.h:77
comment_list * m_trail_comm
Definition: pt-loop.h:102
~tree_while_command(void)
Definition: pt-loop.cc:39
tree_while_command & operator=(const tree_while_command &)=delete
tree_while_command(int l=-1, int c=-1)
Definition: pt-loop.h:48
tree_while_command(tree_expression *e, comment_list *lc=nullptr, comment_list *tc=nullptr, int l=-1, int c=-1)
Definition: pt-loop.h:53
tree_while_command(const tree_while_command &)=delete
comment_list * trailing_comment(void)
Definition: pt-loop.h:83
tree_while_command(tree_expression *e, tree_statement_list *lst, comment_list *lc=nullptr, comment_list *tc=nullptr, int l=-1, int c=-1)
Definition: pt-loop.h:61
comment_list * m_lead_comm
Definition: pt-loop.h:99
tree_statement_list * body(void)
Definition: pt-loop.h:79
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn