Mercurial > hg > octave-nkf
annotate src/pt-select.h @ 8011:3100283874d7
improve backtrace error messages
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 05 Aug 2008 23:09:32 -0400 |
parents | 71f068b22fcc |
children | 73c4516fae10 |
rev | line source |
---|---|
2982 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 2000, 2002, 2004, 2005, 2006, 2007 |
4 John W. Eaton | |
2982 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2982 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2982 | 21 |
22 */ | |
23 | |
24 #if !defined (octave_tree_select_h) | |
25 #define octave_tree_select_h 1 | |
26 | |
27 class expression; | |
28 class tree_statement_list; | |
29 | |
30 class tree_walker; | |
31 | |
4219 | 32 #include "base-list.h" |
3665 | 33 #include "comment-list.h" |
2982 | 34 #include "pt-cmd.h" |
7336 | 35 #include "symtab.h" |
2982 | 36 |
37 // If. | |
38 | |
39 class | |
40 tree_if_clause | |
41 { | |
42 public: | |
43 | |
44 tree_if_clause (void) | |
3665 | 45 : expr (0), list (0), lead_comm (0) { } |
2982 | 46 |
3665 | 47 tree_if_clause (tree_statement_list *l, octave_comment_list *lc = 0) |
48 : expr (0), list (l), lead_comm (lc) { } | |
2982 | 49 |
3665 | 50 tree_if_clause (tree_expression *e, tree_statement_list *l, |
51 octave_comment_list *lc = 0) | |
52 : expr (e), list (l), lead_comm (lc) { } | |
2982 | 53 |
54 ~tree_if_clause (void); | |
55 | |
56 bool is_else_clause (void) | |
57 { return ! expr; } | |
58 | |
59 int eval (void); | |
60 | |
61 tree_expression *condition (void) { return expr; } | |
62 | |
63 tree_statement_list *commands (void) { return list; } | |
64 | |
3665 | 65 octave_comment_list *leading_comment (void) { return lead_comm; } |
66 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
67 tree_if_clause *dup (symbol_table::scope_id scope, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
68 symbol_table::context_id context); |
5861 | 69 |
2982 | 70 void accept (tree_walker& tw); |
71 | |
72 private: | |
73 | |
74 // The condition to test. | |
75 tree_expression *expr; | |
76 | |
77 // The list of statements to evaluate if expr is true. | |
78 tree_statement_list *list; | |
2988 | 79 |
3665 | 80 // Comment preceding ELSE or ELSEIF token. |
81 octave_comment_list *lead_comm; | |
82 | |
2988 | 83 // No copying! |
84 | |
85 tree_if_clause (const tree_if_clause&); | |
86 | |
87 tree_if_clause& operator = (const tree_if_clause&); | |
2982 | 88 }; |
89 | |
90 class | |
4219 | 91 tree_if_command_list : public octave_base_list<tree_if_clause *> |
2982 | 92 { |
93 public: | |
94 | |
4219 | 95 tree_if_command_list (void) { } |
2982 | 96 |
4219 | 97 tree_if_command_list (tree_if_clause *t) { append (t); } |
2982 | 98 |
99 ~tree_if_command_list (void) | |
100 { | |
4219 | 101 while (! empty ()) |
2982 | 102 { |
4219 | 103 iterator p = begin (); |
104 delete *p; | |
105 erase (p); | |
2982 | 106 } |
107 } | |
108 | |
109 void eval (void); | |
110 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
111 tree_if_command_list *dup (symbol_table::scope_id scope, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
112 symbol_table::context_id context); |
5861 | 113 |
2982 | 114 void accept (tree_walker& tw); |
2988 | 115 |
116 private: | |
117 | |
118 // No copying! | |
119 | |
120 tree_if_command_list (const tree_if_command_list&); | |
121 | |
122 tree_if_command_list& operator = (const tree_if_command_list&); | |
2982 | 123 }; |
124 | |
125 class | |
126 tree_if_command : public tree_command | |
127 { | |
128 public: | |
129 | |
130 tree_if_command (int l = -1, int c = -1) | |
3665 | 131 : tree_command (l, c), list (0), lead_comm (0), trail_comm (0) { } |
2982 | 132 |
3665 | 133 tree_if_command (tree_if_command_list *lst, octave_comment_list *lc, |
134 octave_comment_list *tc, int l = -1, int c = -1) | |
135 : tree_command (l, c), list (lst), lead_comm (lc), trail_comm (tc) { } | |
2982 | 136 |
137 ~tree_if_command (void); | |
138 | |
139 void eval (void); | |
140 | |
141 tree_if_command_list *cmd_list (void) { return list; } | |
142 | |
3665 | 143 octave_comment_list *leading_comment (void) { return lead_comm; } |
144 | |
145 octave_comment_list *trailing_comment (void) { return trail_comm; } | |
146 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
147 tree_command *dup (symbol_table::scope_id scope, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
148 symbol_table::context_id context); |
5861 | 149 |
2982 | 150 void accept (tree_walker& tw); |
151 | |
152 private: | |
153 | |
154 // List of if commands (if, elseif, elseif, ... else, endif) | |
155 tree_if_command_list *list; | |
2988 | 156 |
3665 | 157 // Comment preceding IF token. |
158 octave_comment_list *lead_comm; | |
159 | |
160 // Comment preceding ENDIF token. | |
161 octave_comment_list *trail_comm; | |
162 | |
2988 | 163 // No copying! |
164 | |
165 tree_if_command (const tree_if_command&); | |
166 | |
167 tree_if_command& operator = (const tree_if_command&); | |
2982 | 168 }; |
169 | |
170 // Switch. | |
171 | |
172 class | |
173 tree_switch_case | |
174 { | |
175 public: | |
176 | |
177 tree_switch_case (void) | |
3665 | 178 : label (0), list (0), lead_comm (0) { } |
2982 | 179 |
3665 | 180 tree_switch_case (tree_statement_list *l, octave_comment_list *lc = 0) |
181 : label (0), list (l), lead_comm (lc) { } | |
2982 | 182 |
3665 | 183 tree_switch_case (tree_expression *e, tree_statement_list *l, |
184 octave_comment_list *lc = 0) | |
185 : label (e), list (l), lead_comm (lc) { } | |
2982 | 186 |
187 ~tree_switch_case (void); | |
188 | |
3933 | 189 bool is_default_case (void) { return ! label; } |
2982 | 190 |
191 bool label_matches (const octave_value& val); | |
192 | |
193 int eval (const octave_value& val); | |
194 | |
195 tree_expression *case_label (void) { return label; } | |
196 | |
197 tree_statement_list *commands (void) { return list; } | |
198 | |
3665 | 199 octave_comment_list *leading_comment (void) { return lead_comm; } |
200 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
201 tree_switch_case *dup (symbol_table::scope_id scope, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
202 symbol_table::context_id context); |
5861 | 203 |
2982 | 204 void accept (tree_walker& tw); |
205 | |
206 private: | |
207 | |
208 // The case label. | |
209 tree_expression *label; | |
210 | |
211 // The list of statements to evaluate if the label matches. | |
212 tree_statement_list *list; | |
2988 | 213 |
3665 | 214 // Comment preceding CASE or OTHERWISE token. |
215 octave_comment_list *lead_comm; | |
216 | |
2988 | 217 // No copying! |
218 | |
219 tree_switch_case (const tree_switch_case&); | |
220 | |
221 tree_switch_case& operator = (const tree_switch_case&); | |
2982 | 222 }; |
223 | |
224 class | |
4219 | 225 tree_switch_case_list : public octave_base_list<tree_switch_case *> |
2982 | 226 { |
227 public: | |
228 | |
4219 | 229 tree_switch_case_list (void) { } |
2982 | 230 |
4219 | 231 tree_switch_case_list (tree_switch_case *t) { append (t); } |
2982 | 232 |
233 ~tree_switch_case_list (void) | |
234 { | |
4219 | 235 while (! empty ()) |
2982 | 236 { |
4219 | 237 iterator p = begin (); |
238 delete *p; | |
239 erase (p); | |
2982 | 240 } |
241 } | |
242 | |
243 void eval (const octave_value& val); | |
244 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
245 tree_switch_case_list *dup (symbol_table::scope_id scope, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
246 symbol_table::context_id context); |
5861 | 247 |
2982 | 248 void accept (tree_walker& tw); |
2988 | 249 |
250 private: | |
251 | |
252 // No copying! | |
253 | |
254 tree_switch_case_list (const tree_switch_case_list&); | |
255 | |
256 tree_switch_case_list& operator = (const tree_switch_case_list&); | |
2982 | 257 }; |
258 | |
259 class | |
260 tree_switch_command : public tree_command | |
261 { | |
262 public: | |
263 | |
264 tree_switch_command (int l = -1, int c = -1) | |
3665 | 265 : tree_command (l, c), expr (0), list (0), lead_comm (0), |
266 trail_comm (0) { } | |
2982 | 267 |
268 tree_switch_command (tree_expression *e, tree_switch_case_list *lst, | |
3665 | 269 octave_comment_list *lc, octave_comment_list *tc, |
2982 | 270 int l = -1, int c = -1) |
3665 | 271 : tree_command (l, c), expr (e), list (lst), lead_comm (lc), |
272 trail_comm (tc) { } | |
2982 | 273 |
274 ~tree_switch_command (void); | |
275 | |
276 void eval (void); | |
277 | |
278 tree_expression *switch_value (void) { return expr; } | |
279 | |
280 tree_switch_case_list *case_list (void) { return list; } | |
281 | |
3665 | 282 octave_comment_list *leading_comment (void) { return lead_comm; } |
283 | |
284 octave_comment_list *trailing_comment (void) { return trail_comm; } | |
285 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
286 tree_command *dup (symbol_table::scope_id scope, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
287 symbol_table::context_id context); |
5861 | 288 |
2982 | 289 void accept (tree_walker& tw); |
290 | |
291 private: | |
292 | |
293 // Value on which to switch. | |
294 tree_expression *expr; | |
295 | |
296 // List of cases (case 1, case 2, ..., default) | |
297 tree_switch_case_list *list; | |
2988 | 298 |
3665 | 299 // Comment preceding SWITCH token. |
300 octave_comment_list *lead_comm; | |
301 | |
302 // Comment preceding ENDSWITCH token. | |
303 octave_comment_list *trail_comm; | |
304 | |
2988 | 305 // No copying! |
306 | |
307 tree_switch_command (const tree_switch_command&); | |
308 | |
309 tree_switch_command& operator = (const tree_switch_command&); | |
2982 | 310 }; |
311 | |
312 #endif | |
313 | |
314 /* | |
315 ;;; Local Variables: *** | |
316 ;;; mode: C++ *** | |
317 ;;; End: *** | |
318 */ |