Mercurial > hg > octave-nkf
annotate src/pt-select.cc @ 8658:73c4516fae10
New evaluator and debugger derived from tree-walker class
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 04 Feb 2009 00:47:53 -0500 |
parents | 8302788f09db |
children | b9ce57a309a3 |
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 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
28 #include "error.h" | |
29 #include "oct-obj.h" | |
30 #include "ov.h" | |
31 #include "pt-cmd.h" | |
32 #include "pt-exp.h" | |
33 #include "pt-select.h" | |
34 #include "pt-stmt.h" | |
35 #include "pt-walk.h" | |
3724 | 36 #include "Cell.h" |
37 #include "ov-typeinfo.h" | |
2982 | 38 |
39 // If clauses. | |
40 | |
41 tree_if_clause::~tree_if_clause (void) | |
42 { | |
43 delete expr; | |
44 delete list; | |
3665 | 45 delete lead_comm; |
2982 | 46 } |
47 | |
5861 | 48 tree_if_clause * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
49 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
|
50 symbol_table::context_id context) |
5861 | 51 { |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
52 return new tree_if_clause (expr ? expr->dup (scope, context) : 0, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
53 list ? list->dup (scope, context) : 0, |
5861 | 54 lead_comm ? lead_comm->dup () : 0); |
55 } | |
56 | |
2982 | 57 void |
58 tree_if_clause::accept (tree_walker& tw) | |
59 { | |
60 tw.visit_if_clause (*this); | |
61 } | |
62 | |
63 // List of if commands. | |
64 | |
5861 | 65 tree_if_command_list * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
66 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
|
67 symbol_table::context_id context) |
5861 | 68 { |
69 tree_if_command_list *new_icl = new tree_if_command_list (); | |
70 | |
71 for (iterator p = begin (); p != end (); p++) | |
72 { | |
73 tree_if_clause *elt = *p; | |
74 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
75 new_icl->append (elt ? elt->dup (scope, context) : 0); |
5861 | 76 } |
77 | |
78 return new_icl; | |
79 } | |
80 | |
2982 | 81 void |
82 tree_if_command_list::accept (tree_walker& tw) | |
83 { | |
84 tw.visit_if_command_list (*this); | |
85 } | |
86 | |
87 // If. | |
88 | |
89 tree_if_command::~tree_if_command (void) | |
90 { | |
91 delete list; | |
3665 | 92 delete lead_comm; |
93 delete trail_comm; | |
2982 | 94 } |
95 | |
5861 | 96 tree_command * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
97 tree_if_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
|
98 symbol_table::context_id context) |
5861 | 99 { |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
100 return new tree_if_command (list ? list->dup (scope, context) : 0, |
5861 | 101 lead_comm ? lead_comm->dup () : 0, |
102 trail_comm ? trail_comm->dup () : 0, | |
103 line (), column ()); | |
104 } | |
105 | |
2982 | 106 void |
107 tree_if_command::accept (tree_walker& tw) | |
108 { | |
109 tw.visit_if_command (*this); | |
110 } | |
111 | |
112 // Switch cases. | |
113 | |
114 tree_switch_case::~tree_switch_case (void) | |
115 { | |
116 delete label; | |
117 delete list; | |
3665 | 118 delete lead_comm; |
2982 | 119 } |
120 | |
3724 | 121 |
122 bool | |
123 tree_switch_case::label_matches (const octave_value& val) | |
124 { | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8346
diff
changeset
|
125 octave_value label_value = label->rvalue1 (); |
2982 | 126 |
3724 | 127 if (! error_state && label_value.is_defined() ) |
2982 | 128 { |
3724 | 129 if (label_value.is_cell ()) |
2982 | 130 { |
3724 | 131 Cell cell (label_value.cell_value ()); |
132 | |
5275 | 133 for (octave_idx_type i = 0; i < cell.rows (); i++) |
3724 | 134 { |
5275 | 135 for (octave_idx_type j = 0; j < cell.columns (); j++) |
3724 | 136 { |
8346
8302788f09db
fix empty matrix handling in switch statement
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
137 bool match = val.is_equal (cell(i,j)); |
2982 | 138 |
3724 | 139 if (error_state) |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7767
diff
changeset
|
140 return false; |
3724 | 141 else if (match) |
142 return true; | |
143 } | |
144 } | |
145 } | |
146 else | |
147 { | |
8346
8302788f09db
fix empty matrix handling in switch statement
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
148 bool match = val.is_equal (label_value); |
3724 | 149 |
150 if (error_state) | |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7767
diff
changeset
|
151 return false; |
2982 | 152 else |
3724 | 153 return match; |
2982 | 154 } |
155 } | |
156 | |
3724 | 157 return false; |
2982 | 158 } |
159 | |
5861 | 160 tree_switch_case * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
161 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
|
162 symbol_table::context_id context) |
5861 | 163 { |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
164 return new tree_switch_case (label ? label->dup (scope, context) : 0, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
165 list ? list->dup (scope, context) : 0, |
5861 | 166 lead_comm ? lead_comm->dup () : 0); |
167 } | |
168 | |
2982 | 169 void |
170 tree_switch_case::accept (tree_walker& tw) | |
171 { | |
172 tw.visit_switch_case (*this); | |
173 } | |
174 | |
175 // List of switch cases. | |
176 | |
5861 | 177 tree_switch_case_list * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
178 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
|
179 symbol_table::context_id context) |
5861 | 180 { |
181 tree_switch_case_list *new_scl = new tree_switch_case_list (); | |
182 | |
183 for (iterator p = begin (); p != end (); p++) | |
184 { | |
185 tree_switch_case *elt = *p; | |
186 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
187 new_scl->append (elt ? elt->dup (scope, context) : 0); |
5861 | 188 } |
189 | |
190 return new_scl; | |
191 } | |
192 | |
2982 | 193 void |
194 tree_switch_case_list::accept (tree_walker& tw) | |
195 { | |
196 tw.visit_switch_case_list (*this); | |
197 } | |
198 | |
199 // Switch. | |
200 | |
201 tree_switch_command::~tree_switch_command (void) | |
202 { | |
203 delete expr; | |
204 delete list; | |
3665 | 205 delete lead_comm; |
206 delete trail_comm; | |
2982 | 207 } |
208 | |
5861 | 209 tree_command * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
210 tree_switch_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
|
211 symbol_table::context_id context) |
5861 | 212 { |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
213 return new tree_switch_command (expr ? expr->dup (scope, context) : 0, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
214 list ? list->dup (scope, context) : 0, |
5861 | 215 lead_comm ? lead_comm->dup () : 0, |
216 trail_comm ? trail_comm->dup () : 0, | |
217 line (), column ()); | |
218 } | |
219 | |
2982 | 220 void |
221 tree_switch_command::accept (tree_walker& tw) | |
222 { | |
223 tw.visit_switch_command (*this); | |
224 } | |
225 | |
226 /* | |
227 ;;; Local Variables: *** | |
228 ;;; mode: C++ *** | |
229 ;;; End: *** | |
230 */ |