GNU Octave  9.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-2024 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  OCTAVE_DISABLE_COPY_MOVE (tree_while_command)
70 
72 
73  tree_expression * condition () { return m_expr; }
74 
75  tree_statement_list * body () { return m_list; }
76 
78 
80 
81  void accept (tree_walker& tw)
82  {
83  tw.visit_while_command (*this);
84  }
85 
86 protected:
87 
88  // Expression to test.
90 
91  // List of commands to execute.
93 
94  // Comment preceding WHILE token.
96 
97  // Comment preceding ENDWHILE token.
99 };
100 
101 // Do-Until.
102 
104 {
105 public:
106 
107  tree_do_until_command (int l = -1, int c = -1)
108  : tree_while_command (l, c)
109  { }
110 
112  comment_list *lc = nullptr,
113  comment_list *tc = nullptr,
114  int l = -1, int c = -1)
115  : tree_while_command (e, lc, tc, l, c)
116  { }
117 
119  comment_list *lc = nullptr,
120  comment_list *tc = nullptr,
121  int l = -1, int c = -1)
122  : tree_while_command (e, lst, lc, tc, l, c)
123  { }
124 
125  OCTAVE_DISABLE_COPY_MOVE (tree_do_until_command)
126 
128 
129  void accept (tree_walker& tw)
130  {
131  tw.visit_do_until_command (*this);
132  }
133 };
134 
135 // For.
136 
138 {
139 public:
140 
141  tree_simple_for_command (int l = -1, int c = -1)
142  : tree_command (l, c), m_parallel (false), m_lhs (nullptr),
143  m_expr (nullptr), m_maxproc (nullptr), m_list (nullptr),
144  m_lead_comm (nullptr), m_trail_comm (nullptr)
145  { }
146 
147  tree_simple_for_command (bool parallel_arg, tree_expression *le,
148  tree_expression *re,
149  tree_expression *maxproc_arg,
150  tree_statement_list *lst,
151  comment_list *lc = nullptr,
152  comment_list *tc = nullptr,
153  int l = -1, int c = -1)
154  : tree_command (l, c), m_parallel (parallel_arg), m_lhs (le),
155  m_expr (re), m_maxproc (maxproc_arg), m_list (lst),
156  m_lead_comm (lc), m_trail_comm (tc)
157  { }
158 
159  OCTAVE_DISABLE_COPY_MOVE (tree_simple_for_command)
160 
162 
163  bool in_parallel () { return m_parallel; }
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  tree_statement_list * body () { return m_list; }
172 
173  comment_list * leading_comment () { return m_lead_comm; }
174 
175  comment_list * trailing_comment () { return m_trail_comm; }
176 
177  void accept (tree_walker& tw)
178  {
179  tw.visit_simple_for_command (*this);
180  }
181 
182 private:
183  // TRUE means operate in parallel (subject to the value of the
184  // maxproc expression).
185  bool m_parallel;
186 
187  // Expression to modify.
188  tree_expression *m_lhs;
189 
190  // Expression to evaluate.
191  tree_expression *m_expr;
192 
193  // Expression to tell how many processors should be used (only valid
194  // if parallel is TRUE).
195  tree_expression *m_maxproc;
196 
197  // List of commands to execute.
198  tree_statement_list *m_list;
199 
200  // Comment preceding FOR token.
201  comment_list *m_lead_comm;
202 
203  // Comment preceding ENDFOR token.
204  comment_list *m_trail_comm;
205 };
206 
208 {
209 public:
210 
211  tree_complex_for_command (int l = -1, int c = -1)
212  : tree_command (l, c), m_lhs (nullptr), m_expr (nullptr),
213  m_list (nullptr), m_lead_comm (nullptr), m_trail_comm (nullptr)
214  { }
215 
217  tree_statement_list *lst,
218  comment_list *lc = nullptr,
219  comment_list *tc = nullptr,
220  int l = -1, int c = -1)
221  : tree_command (l, c), m_lhs (le), m_expr (re), m_list (lst),
222  m_lead_comm (lc), m_trail_comm (tc)
223  { }
224 
225  OCTAVE_DISABLE_COPY_MOVE (tree_complex_for_command)
226 
228 
229  tree_argument_list * left_hand_side () { return m_lhs; }
230 
231  tree_expression * control_expr () { return m_expr; }
232 
233  tree_statement_list * body () { return m_list; }
234 
235  comment_list * leading_comment () { return m_lead_comm; }
236 
237  comment_list * trailing_comment () { return m_trail_comm; }
238 
239  void accept (tree_walker& tw)
240  {
241  tw.visit_complex_for_command (*this);
242  }
243 
244 private:
245 
246  // Expression to modify.
247  tree_argument_list *m_lhs;
248 
249  // Expression to evaluate.
250  tree_expression *m_expr;
251 
252  // List of commands to execute.
253  tree_statement_list *m_list;
254 
255  // Comment preceding FOR token.
256  comment_list *m_lead_comm;
257 
258  // Comment preceding ENDFOR token.
259  comment_list *m_trail_comm;
260 };
261 
262 OCTAVE_END_NAMESPACE(octave)
263 
264 #endif
void accept(tree_walker &tw)
Definition: pt-loop.h:239
comment_list * trailing_comment()
Definition: pt-loop.h:237
tree_statement_list * body()
Definition: pt-loop.h:233
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:216
tree_argument_list * left_hand_side()
Definition: pt-loop.h:229
tree_complex_for_command(int l=-1, int c=-1)
Definition: pt-loop.h:211
tree_expression * control_expr()
Definition: pt-loop.h:231
comment_list * leading_comment()
Definition: pt-loop.h:235
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:118
~tree_do_until_command()=default
void accept(tree_walker &tw)
Definition: pt-loop.h:129
tree_do_until_command(int l=-1, int c=-1)
Definition: pt-loop.h:107
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:111
comment_list * leading_comment()
Definition: pt-loop.h:173
comment_list * trailing_comment()
Definition: pt-loop.h:175
tree_expression * left_hand_side()
Definition: pt-loop.h:165
tree_expression * control_expr()
Definition: pt-loop.h:167
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:147
void accept(tree_walker &tw)
Definition: pt-loop.h:177
tree_expression * maxproc_expr()
Definition: pt-loop.h:169
tree_statement_list * body()
Definition: pt-loop.h:171
tree_simple_for_command(int l=-1, int c=-1)
Definition: pt-loop.h:141
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
tree_statement_list * body()
Definition: pt-loop.h:75
tree_statement_list * m_list
Definition: pt-loop.h:92
void accept(tree_walker &tw)
Definition: pt-loop.h:81
tree_expression * m_expr
Definition: pt-loop.h:89
tree_expression * condition()
Definition: pt-loop.h:73
comment_list * m_trail_comm
Definition: pt-loop.h:98
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
comment_list * trailing_comment()
Definition: pt-loop.h:79
comment_list * leading_comment()
Definition: pt-loop.h:77
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:95
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn