GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pt-select.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_select_h)
24 #define octave_pt_select_h 1
25 
26 #include "octave-config.h"
27 
28 #include "base-list.h"
29 #include "comment-list.h"
30 #include "pt-cmd.h"
31 #include "pt-walk.h"
32 
33 namespace octave
34 {
35  class tree_expression;
36  class tree_statement_list;
37 
38  // If.
39 
40  class tree_if_clause : public tree
41  {
42  public:
43 
44  tree_if_clause (int l = -1, int c = -1)
45  : tree (l, c), m_expr (nullptr), m_list (nullptr), m_lead_comm (nullptr) { }
46 
48  int l = -1, int c = -1)
49  : tree (l, c), m_expr (nullptr), m_list (sl), m_lead_comm (lc) { }
50 
52  comment_list *lc = nullptr,
53  int l = -1, int c = -1)
54  : tree (l, c), m_expr (e), m_list (sl), m_lead_comm (lc) { }
55 
56  // No copying!
57 
58  tree_if_clause (const tree_if_clause&) = delete;
59 
60  tree_if_clause& operator = (const tree_if_clause&) = delete;
61 
62  ~tree_if_clause (void);
63 
64  bool is_else_clause (void) { return ! m_expr; }
65 
66  tree_expression * condition (void) { return m_expr; }
67 
68  tree_statement_list * commands (void) { return m_list; }
69 
71 
72  void accept (tree_walker& tw)
73  {
74  tw.visit_if_clause (*this);
75  }
76 
77  private:
78 
79  // The condition to test.
81 
82  // The list of statements to evaluate if expr is true.
84 
85  // Comment preceding ELSE or ELSEIF token.
87  };
88 
89  class tree_if_command_list : public base_list<tree_if_clause *>
90  {
91  public:
92 
94 
96 
97  // No copying!
98 
100 
102 
104  {
105  while (! empty ())
106  {
107  iterator p = begin ();
108  delete *p;
109  erase (p);
110  }
111  }
112 
113  void accept (tree_walker& tw)
114  {
115  tw.visit_if_command_list (*this);
116  }
117  };
118 
120  {
121  public:
122 
123  tree_if_command (int l = -1, int c = -1)
124  : tree_command (l, c), m_list (nullptr),
125  m_lead_comm (nullptr), m_trail_comm (nullptr)
126  { }
127 
129  comment_list *tc, int l = -1, int c = -1)
130  : tree_command (l, c), m_list (lst), m_lead_comm (lc), m_trail_comm (tc) { }
131 
132  // No copying!
133 
134  tree_if_command (const tree_if_command&) = delete;
135 
136  tree_if_command& operator = (const tree_if_command&) = delete;
137 
138  ~tree_if_command (void);
139 
140  tree_if_command_list * cmd_list (void) { return m_list; }
141 
143 
145 
146  void accept (tree_walker& tw)
147  {
148  tw.visit_if_command (*this);
149  }
150 
151  private:
152 
153  // List of if commands (if, elseif, elseif, ... else, endif)
155 
156  // Comment preceding IF token.
158 
159  // Comment preceding ENDIF token.
161  };
162 
163  // Switch.
164 
165  class tree_switch_case : public tree
166  {
167  public:
168 
169  tree_switch_case (int l = -1, int c = -1)
170  : tree (l, c), m_label (nullptr), m_list (nullptr), m_lead_comm (nullptr) { }
171 
173  int l = -1, int c = -1)
174  : tree (l, c), m_label (nullptr), m_list (sl), m_lead_comm (lc) { }
175 
177  comment_list *lc = nullptr,
178  int l = -1, int c = -1)
179  : tree (l, c), m_label (e), m_list (sl), m_lead_comm (lc) { }
180 
181  // No copying!
182 
183  tree_switch_case (const tree_switch_case&) = delete;
184 
186 
187  ~tree_switch_case (void);
188 
189  bool is_default_case (void) { return ! m_label; }
190 
191  tree_expression * case_label (void) { return m_label; }
192 
193  tree_statement_list * commands (void) { return m_list; }
194 
196 
197  void accept (tree_walker& tw)
198  {
199  tw.visit_switch_case (*this);
200  }
201 
202  private:
203 
204  // The case label.
206 
207  // The list of statements to evaluate if the label matches.
209 
210  // Comment preceding CASE or OTHERWISE token.
212  };
213 
214  class tree_switch_case_list : public base_list<tree_switch_case *>
215  {
216  public:
217 
219 
221 
222  // No copying!
223 
225 
227 
229  {
230  while (! empty ())
231  {
232  iterator p = begin ();
233  delete *p;
234  erase (p);
235  }
236  }
237 
238  void accept (tree_walker& tw)
239  {
240  tw.visit_switch_case_list (*this);
241  }
242  };
243 
245  {
246  public:
247 
248  tree_switch_command (int l = -1, int c = -1)
249  : tree_command (l, c), m_expr (nullptr), m_list (nullptr),
250  m_lead_comm (nullptr), m_trail_comm (nullptr) { }
251 
253  comment_list *lc, comment_list *tc,
254  int l = -1, int c = -1)
255  : tree_command (l, c), m_expr (e), m_list (lst), m_lead_comm (lc),
256  m_trail_comm (tc) { }
257 
258  // No copying!
259 
260  tree_switch_command (const tree_switch_command&) = delete;
261 
263 
264  ~tree_switch_command (void);
265 
266  tree_expression * switch_value (void) { return m_expr; }
267 
269 
271 
273 
274  void accept (tree_walker& tw)
275  {
276  tw.visit_switch_command (*this);
277  }
278 
279  private:
280 
281  // Value on which to switch.
283 
284  // List of cases (case 1, case 2, ..., default)
286 
287  // Comment preceding SWITCH token.
289 
290  // Comment preceding ENDSWITCH token.
292  };
293 }
294 
295 #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS)
296 
297 OCTAVE_DEPRECATED (4.4, "use 'octave::tree_if_clause' instead")
298 typedef octave::tree_if_clause tree_if_clause;
299 
300 // tree_if_command_list is derived from a template.
301 
302 OCTAVE_DEPRECATED (4.4, "use 'octave::tree_if_command' instead")
303 typedef octave::tree_if_command tree_if_command;
304 
305 OCTAVE_DEPRECATED (4.4, "use 'octave::tree_switch_case' instead")
306 typedef octave::tree_switch_case tree_switch_case;
307 
308 // tree_switch_case_list is derived from a template.
309 
310 OCTAVE_DEPRECATED (4.4, "use 'octave::tree_switch_command' instead")
311 typedef octave::tree_switch_command tree_switch_command;
312 
313 #endif
314 
315 #endif
tree_if_clause(tree_statement_list *sl, comment_list *lc=nullptr, int l=-1, int c=-1)
Definition: pt-select.h:47
comment_list * leading_comment(void)
Definition: pt-select.h:70
bool is_default_case(void)
Definition: pt-select.h:189
tree_switch_case(tree_statement_list *sl, comment_list *lc=nullptr, int l=-1, int c=-1)
Definition: pt-select.h:172
tree_expression * m_label
Definition: pt-select.h:205
tree_if_command_list & operator=(const tree_if_command_list &)=delete
virtual void visit_if_command_list(tree_if_command_list &)=0
virtual void visit_if_clause(tree_if_clause &)=0
void accept(tree_walker &tw)
Definition: pt-select.h:113
virtual void visit_if_command(tree_if_command &)=0
std::list< tree_if_clause * >::iterator iterator
Definition: base-list.h:40
comment_list * m_lead_comm
Definition: pt-select.h:157
iterator erase(iterator pos)
Definition: base-list.h:52
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function t
Definition: ov-usr-fcn.cc:997
comment_list * leading_comment(void)
Definition: pt-select.h:195
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_statement_list * commands(void)
Definition: pt-select.h:193
void accept(tree_walker &tw)
Definition: pt-select.h:72
i e
Definition: data.cc:2591
tree_switch_case_list(tree_switch_case *t)
Definition: pt-select.h:220
tree_switch_command & operator=(const tree_switch_command &)=delete
tree_if_command(int l=-1, int c=-1)
Definition: pt-select.h:123
comment_list * leading_comment(void)
Definition: pt-select.h:270
tree_if_clause(int l=-1, int c=-1)
Definition: pt-select.h:44
tree_if_clause(tree_expression *e, tree_statement_list *sl, comment_list *lc=nullptr, int l=-1, int c=-1)
Definition: pt-select.h:51
tree_switch_case_list * m_list
Definition: pt-select.h:285
tree_if_command(tree_if_command_list *lst, comment_list *lc, comment_list *tc, int l=-1, int c=-1)
Definition: pt-select.h:128
tree_statement_list * commands(void)
Definition: pt-select.h:68
comment_list * m_lead_comm
Definition: pt-select.h:288
tree_switch_command(tree_expression *e, tree_switch_case_list *lst, comment_list *lc, comment_list *tc, int l=-1, int c=-1)
Definition: pt-select.h:252
comment_list * m_lead_comm
Definition: pt-select.h:86
virtual void visit_switch_command(tree_switch_command &)=0
tree_switch_case & operator=(const tree_switch_case &)=delete
tree_if_command_list(tree_if_clause *t)
Definition: pt-select.h:95
tree_if_clause & operator=(const tree_if_clause &)=delete
void accept(tree_walker &tw)
Definition: pt-select.h:197
virtual void visit_switch_case(tree_switch_case &)=0
tree_switch_case(int l=-1, int c=-1)
Definition: pt-select.h:169
comment_list * trailing_comment(void)
Definition: pt-select.h:272
tree_switch_case(tree_expression *e, tree_statement_list *sl, comment_list *lc=nullptr, int l=-1, int c=-1)
Definition: pt-select.h:176
tree_expression * m_expr
Definition: pt-select.h:282
tree_switch_case_list & operator=(const tree_switch_case_list &)=delete
comment_list * m_trail_comm
Definition: pt-select.h:160
tree_expression * m_expr
Definition: pt-select.h:80
comment_list * leading_comment(void)
Definition: pt-select.h:142
void accept(tree_walker &tw)
Definition: pt-select.h:146
comment_list * trailing_comment(void)
Definition: pt-select.h:144
void accept(tree_walker &tw)
Definition: pt-select.h:274
tree_expression * switch_value(void)
Definition: pt-select.h:266
tree_statement_list * m_list
Definition: pt-select.h:83
comment_list * m_trail_comm
Definition: pt-select.h:291
comment_list * m_lead_comm
Definition: pt-select.h:211
bool is_else_clause(void)
Definition: pt-select.h:64
p
Definition: lu.cc:138
tree_statement_list * m_list
Definition: pt-select.h:208
virtual void visit_switch_case_list(tree_switch_case_list &)=0
tree_expression * case_label(void)
Definition: pt-select.h:191
tree_if_command & operator=(const tree_if_command &)=delete
void append(const tree_if_clause * &s)
Definition: base-list.h:110
tree_switch_command(int l=-1, int c=-1)
Definition: pt-select.h:248
void accept(tree_walker &tw)
Definition: pt-select.h:238
tree_switch_case_list * case_list(void)
Definition: pt-select.h:268
tree_if_command_list * cmd_list(void)
Definition: pt-select.h:140
tree_expression * condition(void)
Definition: pt-select.h:66
tree_if_command_list * m_list
Definition: pt-select.h:154