GNU Octave  4.4.1
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-2018 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software: you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_pt_loop_h)
24 #define octave_pt_loop_h 1
25 
26 #include "octave-config.h"
27 
28 class octave_value;
29 
30 #include "pt-cmd.h"
31 #include "pt-walk.h"
32 #include "pt-jit.h"
33 
34 namespace octave
35 {
36  class jit_info;
37  class tree_argument_list;
38  class tree_expression;
39  class tree_statement_list;
40 
41  // While.
42 
44  {
45  public:
46 
47  tree_while_command (int l = -1, int c = -1)
48  : tree_command (l, c), m_expr (nullptr), m_list (nullptr),
49  m_lead_comm (nullptr), m_trail_comm (nullptr)
50 #if defined (HAVE_LLVM)
51  , m_compiled (nullptr)
52 #endif
53  { }
54 
56  comment_list *lc = nullptr,
57  comment_list *tc = nullptr,
58  int l = -1, int c = -1)
59  : tree_command (l, c), m_expr (e), m_list (nullptr),
60  m_lead_comm (lc), m_trail_comm (tc)
61 #if defined (HAVE_LLVM)
62  , m_compiled (nullptr)
63 #endif
64  { }
65 
67  comment_list *lc = nullptr,
68  comment_list *tc = nullptr,
69  int l = -1, int c = -1)
70  : tree_command (l, c), m_expr (e), m_list (lst), m_lead_comm (lc),
71  m_trail_comm (tc)
72 #if defined (HAVE_LLVM)
73  , m_compiled (nullptr)
74 #endif
75  { }
76 
77  // No copying!
78 
79  tree_while_command (const tree_while_command&) = delete;
80 
82 
83  ~tree_while_command (void);
84 
85  tree_expression * condition (void) { return m_expr; }
86 
87  tree_statement_list * body (void) { return m_list; }
88 
90 
92 
93  void accept (tree_walker& tw)
94  {
95  tw.visit_while_command (*this);
96  }
97 
98 #if defined (HAVE_LLVM)
99  // some functions use by tree_jit
100  jit_info * get_info (void) const { return m_compiled; }
101 
102  void stash_info (jit_info *jinfo) { m_compiled = jinfo; }
103 #endif
104 
105  protected:
106 
107  // Expression to test.
109 
110  // List of commands to execute.
112 
113  // Comment preceding WHILE token.
115 
116  // Comment preceding ENDWHILE token.
118 
119  private:
120 
121 #if defined (HAVE_LLVM)
122  // compiled version of the loop
124 #endif
125  };
126 
127  // Do-Until.
128 
130  {
131  public:
132 
133  tree_do_until_command (int l = -1, int c = -1)
134  : tree_while_command (l, c)
135  { }
136 
138  comment_list *lc = nullptr,
139  comment_list *tc = nullptr,
140  int l = -1, int c = -1)
141  : tree_while_command (e, lc, tc, l, c)
142  { }
143 
145  comment_list *lc = nullptr,
146  comment_list *tc = nullptr,
147  int l = -1, int c = -1)
148  : tree_while_command (e, lst, lc, tc, l, c)
149  { }
150 
151  // No copying!
152 
154 
156 
157  ~tree_do_until_command (void) = default;
158 
159  void accept (tree_walker& tw)
160  {
161  tw.visit_do_until_command (*this);
162  }
163  };
164 
165  // For.
166 
168  {
169  public:
170 
171  tree_simple_for_command (int l = -1, int c = -1)
172  : tree_command (l, c), m_parallel (false), m_lhs (nullptr),
173  m_expr (nullptr), m_maxproc (nullptr), m_list (nullptr),
174  m_lead_comm (nullptr), m_trail_comm (nullptr)
175 #if defined (HAVE_LLVM)
176  , m_compiled (nullptr)
177 #endif
178  { }
179 
180  tree_simple_for_command (bool parallel_arg, tree_expression *le,
181  tree_expression *re,
182  tree_expression *maxproc_arg,
183  tree_statement_list *lst,
184  comment_list *lc = nullptr,
185  comment_list *tc = nullptr,
186  int l = -1, int c = -1)
187  : tree_command (l, c), m_parallel (parallel_arg), m_lhs (le),
188  m_expr (re), m_maxproc (maxproc_arg), m_list (lst),
189  m_lead_comm (lc), m_trail_comm (tc)
190 #if defined (HAVE_LLVM)
191  , m_compiled (0)
192 #endif
193  { }
194 
195  // No copying!
196 
198 
200 
202 
203  bool in_parallel (void) { return m_parallel; }
204 
205  tree_expression * left_hand_side (void) { return m_lhs; }
206 
207  tree_expression * control_expr (void) { return m_expr; }
208 
210 
211  tree_statement_list * body (void) { return m_list; }
212 
214 
216 
217  void accept (tree_walker& tw)
218  {
219  tw.visit_simple_for_command (*this);
220  }
221 
222 #if defined (HAVE_LLVM)
223  // some functions use by tree_jit
224  jit_info * get_info (void) const
225  {
226  return m_compiled;
227  }
228 
229  void stash_info (jit_info *jinfo)
230  {
231  m_compiled = jinfo;
232  }
233 #endif
234 
235  private:
236  // TRUE means operate in parallel (subject to the value of the
237  // maxproc expression).
239 
240  // Expression to modify.
242 
243  // Expression to evaluate.
245 
246  // Expression to tell how many processors should be used (only valid
247  // if parallel is TRUE).
249 
250  // List of commands to execute.
252 
253  // Comment preceding FOR token.
255 
256  // Comment preceding ENDFOR token.
258 
259 #if defined (HAVE_LLVM)
260  // compiled version of the loop
262 #endif
263  };
264 
266  {
267  public:
268 
269  tree_complex_for_command (int l = -1, int c = -1)
270  : tree_command (l, c), m_lhs (nullptr), m_expr (nullptr),
271  m_list (nullptr), m_lead_comm (nullptr), m_trail_comm (nullptr)
272  { }
273 
275  tree_statement_list *lst,
276  comment_list *lc = nullptr,
277  comment_list *tc = nullptr,
278  int l = -1, int c = -1)
279  : tree_command (l, c), m_lhs (le), m_expr (re), m_list (lst),
280  m_lead_comm (lc), m_trail_comm (tc)
281  { }
282 
283  // No copying!
284 
286 
288 
290 
292 
293  tree_expression * control_expr (void) { return m_expr; }
294 
295  tree_statement_list * body (void) { return m_list; }
296 
298 
300 
301  void accept (tree_walker& tw)
302  {
303  tw.visit_complex_for_command (*this);
304  }
305 
306  private:
307 
308  // Expression to modify.
310 
311  // Expression to evaluate.
313 
314  // List of commands to execute.
316 
317  // Comment preceding FOR token.
319 
320  // Comment preceding ENDFOR token.
322  };
323 }
324 
325 #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS)
326 
327 OCTAVE_DEPRECATED (4.4, "use 'octave::tree_while_command' instead")
328 typedef octave::tree_while_command tree_while_command;
329 
330 OCTAVE_DEPRECATED (4.4, "use 'octave::tree_do_until_command' instead")
331 typedef octave::tree_do_until_command tree_do_until_command;
332 
333 OCTAVE_DEPRECATED (4.4, "use 'octave::tree_simple_for_command' instead")
334 typedef octave::tree_simple_for_command tree_simple_for_command;
335 
336 OCTAVE_DEPRECATED (4.4, "use 'octave::tree_complex_for_command' instead")
337 typedef octave::tree_complex_for_command tree_complex_for_command;
338 
339 #endif
340 
341 #endif
comment_list * trailing_comment(void)
Definition: pt-loop.h:215
tree_while_command(tree_expression *e, comment_list *lc=nullptr, comment_list *tc=nullptr, int l=-1, int c=-1)
Definition: pt-loop.h:55
tree_expression * m_expr
Definition: pt-loop.h:244
comment_list * leading_comment(void)
Definition: pt-loop.h:213
void accept(tree_walker &tw)
Definition: pt-loop.h:217
tree_while_command(int l=-1, int c=-1)
Definition: pt-loop.h:47
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:180
tree_expression * m_maxproc
Definition: pt-loop.h:248
comment_list * trailing_comment(void)
Definition: pt-loop.h:91
virtual void visit_simple_for_command(tree_simple_for_command &)=0
tree_do_until_command(int l=-1, int c=-1)
Definition: pt-loop.h:133
tree_statement_list * body(void)
Definition: pt-loop.h:87
~tree_do_until_command(void)=default
comment_list * m_trail_comm
Definition: pt-loop.h:257
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
Definition: file-io.cc:587
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:137
i e
Definition: data.cc:2591
tree_statement_list * m_list
Definition: pt-loop.h:251
tree_complex_for_command(int l=-1, int c=-1)
Definition: pt-loop.h:269
tree_complex_for_command & operator=(const tree_complex_for_command &)=delete
tree_while_command & operator=(const tree_while_command &)=delete
tree_statement_list * m_list
Definition: pt-loop.h:111
virtual void visit_while_command(tree_while_command &)=0
comment_list * m_lead_comm
Definition: pt-loop.h:114
tree_expression * m_expr
Definition: pt-loop.h:108
tree_simple_for_command & operator=(const tree_simple_for_command &)=delete
comment_list * m_lead_comm
Definition: pt-loop.h:254
tree_do_until_command & operator=(const tree_do_until_command &)=delete
if(nargin< 2) print_usage()
Definition: cellfun.cc:407
void accept(tree_walker &tw)
Definition: pt-loop.h:159
tree_expression * control_expr(void)
Definition: pt-loop.h:293
tree_expression * control_expr(void)
Definition: pt-loop.h:207
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:66
is false
Definition: cellfun.cc:400
tree_expression * maxproc_expr(void)
Definition: pt-loop.h:209
tree_argument_list * m_lhs
Definition: pt-loop.h:309
void stash_info(jit_info *jinfo)
Definition: pt-loop.h:102
comment_list * trailing_comment(void)
Definition: pt-loop.h:299
tree_statement_list * m_list
Definition: pt-loop.h:315
void accept(tree_walker &tw)
Definition: pt-loop.h:301
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:144
defaults to zero A value of zero computes the digamma a value the trigamma and so on The digamma function is defined
Definition: psi.cc:68
tree_statement_list * body(void)
Definition: pt-loop.h:211
virtual void visit_complex_for_command(tree_complex_for_command &)=0
tree_expression * m_expr
Definition: pt-loop.h:312
comment_list * m_trail_comm
Definition: pt-loop.h:117
tree_expression * m_lhs
Definition: pt-loop.h:241
tree_statement_list * body(void)
Definition: pt-loop.h:295
tree_expression * left_hand_side(void)
Definition: pt-loop.h:205
jit_info * get_info(void) const
Definition: pt-loop.h:100
comment_list * leading_comment(void)
Definition: pt-loop.h:89
comment_list * leading_comment(void)
Definition: pt-loop.h:297
virtual void visit_do_until_command(tree_do_until_command &)=0
tree_simple_for_command(int l=-1, int c=-1)
Definition: pt-loop.h:171
tree_expression * condition(void)
Definition: pt-loop.h:85
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:274
void accept(tree_walker &tw)
Definition: pt-loop.h:93
void stash_info(jit_info *jinfo)
Definition: pt-loop.h:229
jit_info * get_info(void) const
Definition: pt-loop.h:224
tree_argument_list * left_hand_side(void)
Definition: pt-loop.h:291