Mercurial > hg > octave-nkf
annotate libinterp/parse-tree/pt-select.cc @ 18702:fa53284d4511 draft lyh
Fix warnings
author | LYH <lyh.kernel@gmail.com> |
---|---|
date | Fri, 21 Mar 2014 14:59:39 -0400 |
parents | d63878346099 |
children | 6113e0c6920b |
rev | line source |
---|---|
2982 | 1 /* |
2 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
3 Copyright (C) 1996-2013 John W. Eaton |
2982 | 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 | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2982 | 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 | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
2982 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #include "error.h" | |
28 #include "oct-obj.h" | |
29 #include "ov.h" | |
30 #include "pt-cmd.h" | |
31 #include "pt-exp.h" | |
32 #include "pt-select.h" | |
33 #include "pt-stmt.h" | |
34 #include "pt-walk.h" | |
3724 | 35 #include "Cell.h" |
36 #include "ov-typeinfo.h" | |
2982 | 37 |
38 // If clauses. | |
39 | |
40 tree_if_clause::~tree_if_clause (void) | |
41 { | |
42 delete expr; | |
43 delete list; | |
3665 | 44 delete lead_comm; |
2982 | 45 } |
46 | |
5861 | 47 tree_if_clause * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
48 tree_if_clause::dup (symbol_table::scope_id scope, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
49 symbol_table::context_id context) const |
5861 | 50 { |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
51 return new tree_if_clause (expr ? expr->dup (scope, context) : 0, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
52 list ? list->dup (scope, context) : 0, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
53 lead_comm ? lead_comm->dup () : 0); |
5861 | 54 } |
55 | |
2982 | 56 void |
57 tree_if_clause::accept (tree_walker& tw) | |
58 { | |
59 tw.visit_if_clause (*this); | |
60 } | |
61 | |
62 // List of if commands. | |
63 | |
5861 | 64 tree_if_command_list * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
65 tree_if_command_list::dup (symbol_table::scope_id scope, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
66 symbol_table::context_id context) const |
5861 | 67 { |
68 tree_if_command_list *new_icl = new tree_if_command_list (); | |
69 | |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8843
diff
changeset
|
70 for (const_iterator p = begin (); p != end (); p++) |
5861 | 71 { |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8843
diff
changeset
|
72 const tree_if_clause *elt = *p; |
5861 | 73 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
74 new_icl->append (elt ? elt->dup (scope, context) : 0); |
5861 | 75 } |
76 | |
77 return new_icl; | |
78 } | |
79 | |
2982 | 80 void |
81 tree_if_command_list::accept (tree_walker& tw) | |
82 { | |
83 tw.visit_if_command_list (*this); | |
84 } | |
85 | |
86 // If. | |
87 | |
88 tree_if_command::~tree_if_command (void) | |
89 { | |
90 delete list; | |
3665 | 91 delete lead_comm; |
92 delete trail_comm; | |
2982 | 93 } |
94 | |
5861 | 95 tree_command * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
96 tree_if_command::dup (symbol_table::scope_id scope, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
97 symbol_table::context_id context) const |
5861 | 98 { |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
99 return new tree_if_command (list ? list->dup (scope, context) : 0, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
100 lead_comm ? lead_comm->dup () : 0, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
101 trail_comm ? trail_comm->dup () : 0, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
102 line (), column ()); |
5861 | 103 } |
104 | |
2982 | 105 void |
106 tree_if_command::accept (tree_walker& tw) | |
107 { | |
108 tw.visit_if_command (*this); | |
109 } | |
110 | |
111 // Switch cases. | |
112 | |
113 tree_switch_case::~tree_switch_case (void) | |
114 { | |
115 delete label; | |
116 delete list; | |
3665 | 117 delete lead_comm; |
2982 | 118 } |
119 | |
3724 | 120 |
121 bool | |
122 tree_switch_case::label_matches (const octave_value& val) | |
123 { | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8346
diff
changeset
|
124 octave_value label_value = label->rvalue1 (); |
2982 | 125 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
126 if (! error_state && label_value.is_defined () ) |
2982 | 127 { |
3724 | 128 if (label_value.is_cell ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
129 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
130 Cell cell (label_value.cell_value ()); |
3724 | 131 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
132 for (octave_idx_type i = 0; i < cell.rows (); i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
133 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
134 for (octave_idx_type j = 0; j < cell.columns (); j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
135 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
136 bool match = val.is_equal (cell(i,j)); |
2982 | 137 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
138 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
139 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
140 else if (match) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
141 return true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
142 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
143 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
144 } |
3724 | 145 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
146 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
147 bool match = val.is_equal (label_value); |
3724 | 148 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
149 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
150 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
151 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
152 return match; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
153 } |
2982 | 154 } |
155 | |
3724 | 156 return false; |
2982 | 157 } |
158 | |
5861 | 159 tree_switch_case * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
160 tree_switch_case::dup (symbol_table::scope_id scope, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
161 symbol_table::context_id context) const |
5861 | 162 { |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
163 return new tree_switch_case (label ? label->dup (scope, context) : 0, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
164 list ? list->dup (scope, context) : 0, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
165 lead_comm ? lead_comm->dup () : 0); |
5861 | 166 } |
167 | |
2982 | 168 void |
169 tree_switch_case::accept (tree_walker& tw) | |
170 { | |
171 tw.visit_switch_case (*this); | |
172 } | |
173 | |
174 // List of switch cases. | |
175 | |
5861 | 176 tree_switch_case_list * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
177 tree_switch_case_list::dup (symbol_table::scope_id scope, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
178 symbol_table::context_id context) const |
5861 | 179 { |
180 tree_switch_case_list *new_scl = new tree_switch_case_list (); | |
181 | |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8843
diff
changeset
|
182 for (const_iterator p = begin (); p != end (); p++) |
5861 | 183 { |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8843
diff
changeset
|
184 const tree_switch_case *elt = *p; |
5861 | 185 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
186 new_scl->append (elt ? elt->dup (scope, context) : 0); |
5861 | 187 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
188 |
5861 | 189 return new_scl; |
190 } | |
191 | |
2982 | 192 void |
193 tree_switch_case_list::accept (tree_walker& tw) | |
194 { | |
195 tw.visit_switch_case_list (*this); | |
196 } | |
197 | |
198 // Switch. | |
199 | |
200 tree_switch_command::~tree_switch_command (void) | |
201 { | |
202 delete expr; | |
203 delete list; | |
3665 | 204 delete lead_comm; |
205 delete trail_comm; | |
2982 | 206 } |
207 | |
5861 | 208 tree_command * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
209 tree_switch_command::dup (symbol_table::scope_id scope, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
210 symbol_table::context_id context) const |
5861 | 211 { |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
212 return new tree_switch_command (expr ? expr->dup (scope, context) : 0, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
213 list ? list->dup (scope, context) : 0, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
214 lead_comm ? lead_comm->dup () : 0, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
215 trail_comm ? trail_comm->dup () : 0, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
216 line (), column ()); |
5861 | 217 } |
218 | |
2982 | 219 void |
220 tree_switch_command::accept (tree_walker& tw) | |
221 { | |
222 tw.visit_switch_command (*this); | |
223 } |