GNU Octave 7.1.0
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-2022 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_select_h)
27#define octave_pt_select_h 1
28
29#include "octave-config.h"
30
31#include "base-list.h"
32#include "comment-list.h"
33#include "pt-cmd.h"
34#include "pt-walk.h"
35
36namespace octave
37{
38 class tree_expression;
39 class tree_statement_list;
40
41 // If.
42
43 class tree_if_clause : public tree
44 {
45 public:
46
47 tree_if_clause (int l = -1, int c = -1)
48 : tree (l, c), m_expr (nullptr), m_list (nullptr), m_lead_comm (nullptr) { }
49
51 int l = -1, int c = -1)
52 : tree (l, c), m_expr (nullptr), m_list (sl), m_lead_comm (lc) { }
53
55 comment_list *lc = nullptr,
56 int l = -1, int c = -1)
57 : tree (l, c), m_expr (e), m_list (sl), m_lead_comm (lc) { }
58
59 // No copying!
60
61 tree_if_clause (const tree_if_clause&) = delete;
62
64
65 ~tree_if_clause (void);
66
67 bool is_else_clause (void) { return ! m_expr; }
68
69 tree_expression * condition (void) { return m_expr; }
70
71 tree_statement_list * commands (void) { return m_list; }
72
74
76 {
77 tw.visit_if_clause (*this);
78 }
79
80 private:
81
82 // The condition to test.
84
85 // The list of statements to evaluate if expr is true.
87
88 // Comment preceding ELSE or ELSEIF token.
90 };
91
92 class tree_if_command_list : public base_list<tree_if_clause *>
93 {
94 public:
95
97
99
100 // No copying!
101
103
105
107 {
108 while (! empty ())
109 {
110 auto p = begin ();
111 delete *p;
112 erase (p);
113 }
114 }
115
117 {
118 tw.visit_if_command_list (*this);
119 }
120 };
121
123 {
124 public:
125
126 tree_if_command (int l = -1, int c = -1)
127 : tree_command (l, c), m_list (nullptr),
128 m_lead_comm (nullptr), m_trail_comm (nullptr)
129 { }
130
132 comment_list *tc, int l = -1, int c = -1)
133 : tree_command (l, c), m_list (lst), m_lead_comm (lc), m_trail_comm (tc) { }
134
135 // No copying!
136
138
140
141 ~tree_if_command (void);
142
144
146
148
150 {
151 tw.visit_if_command (*this);
152 }
153
154 private:
155
156 // List of if commands (if, elseif, elseif, ... else, endif)
158
159 // Comment preceding IF token.
161
162 // Comment preceding ENDIF token.
164 };
165
166 // Switch.
167
168 class tree_switch_case : public tree
169 {
170 public:
171
172 tree_switch_case (int l = -1, int c = -1)
173 : tree (l, c), m_label (nullptr), m_list (nullptr), m_lead_comm (nullptr) { }
174
176 int l = -1, int c = -1)
177 : tree (l, c), m_label (nullptr), m_list (sl), m_lead_comm (lc) { }
178
180 comment_list *lc = nullptr,
181 int l = -1, int c = -1)
182 : tree (l, c), m_label (e), m_list (sl), m_lead_comm (lc) { }
183
184 // No copying!
185
187
189
190 ~tree_switch_case (void);
191
192 bool is_default_case (void) { return ! m_label; }
193
194 tree_expression * case_label (void) { return m_label; }
195
197
199
201 {
202 tw.visit_switch_case (*this);
203 }
204
205 private:
206
207 // The case label.
209
210 // The list of statements to evaluate if the label matches.
212
213 // Comment preceding CASE or OTHERWISE token.
215 };
216
217 class tree_switch_case_list : public base_list<tree_switch_case *>
218 {
219 public:
220
222
224
225 // No copying!
226
228
230
232 {
233 while (! empty ())
234 {
235 auto p = begin ();
236 delete *p;
237 erase (p);
238 }
239 }
240
242 {
243 tw.visit_switch_case_list (*this);
244 }
245 };
246
248 {
249 public:
250
251 tree_switch_command (int l = -1, int c = -1)
252 : tree_command (l, c), m_expr (nullptr), m_list (nullptr),
253 m_lead_comm (nullptr), m_trail_comm (nullptr) { }
254
256 comment_list *lc, comment_list *tc,
257 int l = -1, int c = -1)
258 : tree_command (l, c), m_expr (e), m_list (lst), m_lead_comm (lc),
259 m_trail_comm (tc) { }
260
261 // No copying!
262
264
266
268
270
272
274
276
278 {
279 tw.visit_switch_command (*this);
280 }
281
282 private:
283
284 // Value on which to switch.
286
287 // List of cases (case 1, case 2, ..., default)
289
290 // Comment preceding SWITCH token.
292
293 // Comment preceding ENDSWITCH token.
295 };
296}
297
298#endif
void append(const tree_if_clause * &s)
Definition: base-list.h:92
iterator erase(iterator pos)
Definition: base-list.h:55
tree_if_clause(tree_expression *e, tree_statement_list *sl, comment_list *lc=nullptr, int l=-1, int c=-1)
Definition: pt-select.h:54
tree_expression * condition(void)
Definition: pt-select.h:69
comment_list * leading_comment(void)
Definition: pt-select.h:73
bool is_else_clause(void)
Definition: pt-select.h:67
tree_expression * m_expr
Definition: pt-select.h:83
tree_if_clause & operator=(const tree_if_clause &)=delete
void accept(tree_walker &tw)
Definition: pt-select.h:75
tree_statement_list * commands(void)
Definition: pt-select.h:71
tree_statement_list * m_list
Definition: pt-select.h:86
tree_if_clause(const tree_if_clause &)=delete
comment_list * m_lead_comm
Definition: pt-select.h:89
tree_if_clause(int l=-1, int c=-1)
Definition: pt-select.h:47
tree_if_clause(tree_statement_list *sl, comment_list *lc=nullptr, int l=-1, int c=-1)
Definition: pt-select.h:50
tree_if_command_list & operator=(const tree_if_command_list &)=delete
void accept(tree_walker &tw)
Definition: pt-select.h:116
tree_if_command_list(const tree_if_command_list &)=delete
tree_if_command_list(tree_if_clause *t)
Definition: pt-select.h:98
tree_if_command(const tree_if_command &)=delete
tree_if_command & operator=(const tree_if_command &)=delete
void accept(tree_walker &tw)
Definition: pt-select.h:149
comment_list * trailing_comment(void)
Definition: pt-select.h:147
tree_if_command_list * cmd_list(void)
Definition: pt-select.h:143
comment_list * m_lead_comm
Definition: pt-select.h:160
comment_list * m_trail_comm
Definition: pt-select.h:163
comment_list * leading_comment(void)
Definition: pt-select.h:145
tree_if_command(int l=-1, int c=-1)
Definition: pt-select.h:126
tree_if_command(tree_if_command_list *lst, comment_list *lc, comment_list *tc, int l=-1, int c=-1)
Definition: pt-select.h:131
tree_if_command_list * m_list
Definition: pt-select.h:157
tree_switch_case_list(const tree_switch_case_list &)=delete
tree_switch_case_list(tree_switch_case *t)
Definition: pt-select.h:223
void accept(tree_walker &tw)
Definition: pt-select.h:241
tree_switch_case_list & operator=(const tree_switch_case_list &)=delete
tree_switch_case(int l=-1, int c=-1)
Definition: pt-select.h:172
tree_expression * case_label(void)
Definition: pt-select.h:194
tree_switch_case(tree_expression *e, tree_statement_list *sl, comment_list *lc=nullptr, int l=-1, int c=-1)
Definition: pt-select.h:179
tree_statement_list * m_list
Definition: pt-select.h:211
tree_statement_list * commands(void)
Definition: pt-select.h:196
comment_list * m_lead_comm
Definition: pt-select.h:214
comment_list * leading_comment(void)
Definition: pt-select.h:198
tree_switch_case(const tree_switch_case &)=delete
tree_switch_case & operator=(const tree_switch_case &)=delete
tree_expression * m_label
Definition: pt-select.h:208
bool is_default_case(void)
Definition: pt-select.h:192
tree_switch_case(tree_statement_list *sl, comment_list *lc=nullptr, int l=-1, int c=-1)
Definition: pt-select.h:175
void accept(tree_walker &tw)
Definition: pt-select.h:200
tree_expression * m_expr
Definition: pt-select.h:285
tree_switch_command(const tree_switch_command &)=delete
tree_switch_case_list * m_list
Definition: pt-select.h:288
comment_list * leading_comment(void)
Definition: pt-select.h:273
tree_switch_case_list * case_list(void)
Definition: pt-select.h:271
tree_switch_command(int l=-1, int c=-1)
Definition: pt-select.h:251
comment_list * trailing_comment(void)
Definition: pt-select.h:275
comment_list * m_lead_comm
Definition: pt-select.h:291
void accept(tree_walker &tw)
Definition: pt-select.h:277
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:255
tree_switch_command & operator=(const tree_switch_command &)=delete
comment_list * m_trail_comm
Definition: pt-select.h:294
tree_expression * switch_value(void)
Definition: pt-select.h:269
virtual void visit_if_command_list(tree_if_command_list &)
Definition: pt-walk.cc:319
virtual void visit_switch_case_list(tree_switch_case_list &)
Definition: pt-walk.cc:345
virtual void visit_switch_case(tree_switch_case &)
Definition: pt-walk.cc:332
virtual void visit_if_clause(tree_if_clause &)
Definition: pt-walk.cc:298
virtual void visit_if_command(tree_if_command &)
Definition: pt-walk.cc:311
virtual void visit_switch_command(tree_switch_command &)
Definition: pt-walk.cc:358