GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
pt-select.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2015 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 the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 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 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if !defined (octave_pt_select_h)
24 #define octave_pt_select_h 1
25 
26 class expression;
28 
29 class tree_walker;
30 
31 #include "base-list.h"
32 #include "comment-list.h"
33 #include "pt-cmd.h"
34 #include "symtab.h"
35 
36 // If.
37 
38 class
39 tree_if_clause : public tree
40 {
41 public:
42 
43  tree_if_clause (int l = -1, int c = -1)
44  : tree (l, c), expr (0), list (0), lead_comm (0) { }
45 
47  int l = -1, int c = -1)
48  : tree (l, c), expr (0), list (sl), lead_comm (lc) { }
49 
51  octave_comment_list *lc = 0,
52  int l = -1, int c = -1)
53  : tree (l, c), expr (e), list (sl), lead_comm (lc) { }
54 
55  ~tree_if_clause (void);
56 
57  bool is_else_clause (void) { return ! expr; }
58 
59  tree_expression *condition (void) { return expr; }
60 
61  tree_statement_list *commands (void) { return list; }
62 
63  octave_comment_list *leading_comment (void) { return lead_comm; }
64 
67 
68  void accept (tree_walker& tw);
69 
70 private:
71 
72  // The condition to test.
74 
75  // The list of statements to evaluate if expr is true.
77 
78  // Comment preceding ELSE or ELSEIF token.
80 
81  // No copying!
82 
84 
86 };
87 
88 class
90 {
91 public:
92 
94 
95  tree_if_command_list (tree_if_clause *t) { append (t); }
96 
98  {
99  while (! empty ())
100  {
101  iterator p = begin ();
102  delete *p;
103  erase (p);
104  }
105  }
106 
109 
110  void accept (tree_walker& tw);
111 
112 private:
113 
114  // No copying!
115 
117 
119 };
120 
121 class
123 {
124 public:
125 
126  tree_if_command (int l = -1, int c = -1)
127  : tree_command (l, c), list (0), lead_comm (0), trail_comm (0) { }
128 
130  octave_comment_list *tc, int l = -1, int c = -1)
131  : tree_command (l, c), list (lst), lead_comm (lc), trail_comm (tc) { }
132 
133  ~tree_if_command (void);
134 
135  tree_if_command_list *cmd_list (void) { return list; }
136 
137  octave_comment_list *leading_comment (void) { return lead_comm; }
138 
139  octave_comment_list *trailing_comment (void) { return trail_comm; }
140 
143 
144  void accept (tree_walker& tw);
145 
146 private:
147 
148  // List of if commands (if, elseif, elseif, ... else, endif)
150 
151  // Comment preceding IF token.
153 
154  // Comment preceding ENDIF token.
156 
157  // No copying!
158 
160 
162 };
163 
164 // Switch.
165 
166 class
167 tree_switch_case : public tree
168 {
169 public:
170 
171  tree_switch_case (int l = -1, int c = -1)
172  : tree (l, c), label (0), list (0), lead_comm (0) { }
173 
175  int l = -1, int c = -1)
176  : tree (l, c), label (0), list (sl), lead_comm (lc) { }
177 
179  octave_comment_list *lc = 0,
180  int l = -1, int c = -1)
181  : tree (l, c), label (e), list (sl), lead_comm (lc) { }
182 
183  ~tree_switch_case (void);
184 
185  bool is_default_case (void) { return ! label; }
186 
187  bool label_matches (const octave_value& val);
188 
189  tree_expression *case_label (void) { return label; }
190 
191  tree_statement_list *commands (void) { return list; }
192 
193  octave_comment_list *leading_comment (void) { return lead_comm; }
194 
197 
198  void accept (tree_walker& tw);
199 
200 private:
201 
202  // The case label.
204 
205  // The list of statements to evaluate if the label matches.
207 
208  // Comment preceding CASE or OTHERWISE token.
210 
211  // No copying!
212 
214 
216 };
217 
218 class
220 {
221 public:
222 
224 
226 
228  {
229  while (! empty ())
230  {
231  iterator p = begin ();
232  delete *p;
233  erase (p);
234  }
235  }
236 
239 
240  void accept (tree_walker& tw);
241 
242 private:
243 
244  // No copying!
245 
247 
249 };
250 
251 class
253 {
254 public:
255 
256  tree_switch_command (int l = -1, int c = -1)
257  : tree_command (l, c), expr (0), list (0), lead_comm (0),
258  trail_comm (0) { }
259 
262  int l = -1, int c = -1)
263  : tree_command (l, c), expr (e), list (lst), lead_comm (lc),
264  trail_comm (tc) { }
265 
266  ~tree_switch_command (void);
267 
268  tree_expression *switch_value (void) { return expr; }
269 
270  tree_switch_case_list *case_list (void) { return list; }
271 
272  octave_comment_list *leading_comment (void) { return lead_comm; }
273 
274  octave_comment_list *trailing_comment (void) { return trail_comm; }
275 
278 
279  void accept (tree_walker& tw);
280 
281 private:
282 
283  // Value on which to switch.
285 
286  // List of cases (case 1, case 2, ..., default)
288 
289  // Comment preceding SWITCH token.
291 
292  // Comment preceding ENDSWITCH token.
294 
295  // No copying!
296 
298 
300 };
301 
302 #endif
octave_comment_list * leading_comment(void)
Definition: pt-select.h:137
tree_if_command(tree_if_command_list *lst, octave_comment_list *lc, octave_comment_list *tc, int l=-1, int c=-1)
Definition: pt-select.h:129
~tree_switch_case_list(void)
Definition: pt-select.h:227
tree_expression * switch_value(void)
Definition: pt-select.h:268
tree_if_command_list(void)
Definition: pt-select.h:93
bool is_default_case(void)
Definition: pt-select.h:185
octave_comment_list * lead_comm
Definition: pt-select.h:152
tree_switch_case_list * case_list(void)
Definition: pt-select.h:270
tree_switch_case(tree_statement_list *sl, octave_comment_list *lc=0, int l=-1, int c=-1)
Definition: pt-select.h:174
tree_statement_list * commands(void)
Definition: pt-select.h:61
tree_expression * case_label(void)
Definition: pt-select.h:189
octave_comment_list * leading_comment(void)
Definition: pt-select.h:272
octave_comment_list * trailing_comment(void)
Definition: pt-select.h:274
tree_if_clause(tree_statement_list *sl, octave_comment_list *lc=0, int l=-1, int c=-1)
Definition: pt-select.h:46
octave_comment_list * trail_comm
Definition: pt-select.h:155
tree_switch_case(tree_expression *e, tree_statement_list *sl, octave_comment_list *lc=0, int l=-1, int c=-1)
Definition: pt-select.h:178
tree_switch_command(tree_expression *e, tree_switch_case_list *lst, octave_comment_list *lc, octave_comment_list *tc, int l=-1, int c=-1)
Definition: pt-select.h:260
tree_switch_case_list * list
Definition: pt-select.h:287
tree_switch_command(int l=-1, int c=-1)
Definition: pt-select.h:256
tree_if_command_list * cmd_list(void)
Definition: pt-select.h:135
tree_if_command(int l=-1, int c=-1)
Definition: pt-select.h:126
tree_statement_list * list
Definition: pt-select.h:206
std::list< tree_if_clause * >::iterator iterator
Definition: base-list.h:36
tree_expression * condition(void)
Definition: pt-select.h:59
octave_comment_list * lead_comm
Definition: pt-select.h:209
static llvm::LLVMContext & context
Definition: jit-typeinfo.cc:76
tree_if_command_list(tree_if_clause *t)
Definition: pt-select.h:95
tree_statement_list * commands(void)
Definition: pt-select.h:191
tree_if_clause(tree_expression *e, tree_statement_list *sl, octave_comment_list *lc=0, int l=-1, int c=-1)
Definition: pt-select.h:50
octave_comment_list * trailing_comment(void)
Definition: pt-select.h:139
tree_expression * label
Definition: pt-select.h:203
tree_statement_list * list
Definition: pt-select.h:76
bool is_else_clause(void)
Definition: pt-select.h:57
tree_expression * expr
Definition: pt-select.h:284
Definition: pt.h:35
tree_if_clause(int l=-1, int c=-1)
Definition: pt-select.h:43
octave_comment_list * leading_comment(void)
Definition: pt-select.h:193
octave_comment_list * trail_comm
Definition: pt-select.h:293
octave_comment_list * leading_comment(void)
Definition: pt-select.h:63
tree_expression * expr
Definition: pt-select.h:73
octave_comment_list * lead_comm
Definition: pt-select.h:79
tree_switch_case(int l=-1, int c=-1)
Definition: pt-select.h:171
size_t context_id
Definition: symtab.h:51
octave_comment_list * lead_comm
Definition: pt-select.h:290
tree_switch_case_list(tree_switch_case *t)
Definition: pt-select.h:225
tree_if_command_list * list
Definition: pt-select.h:149
tree_walker & operator=(const tree_walker &)
~tree_if_command_list(void)
Definition: pt-select.h:97