Mercurial > hg > octave-nkf
annotate src/pt-idx.cc @ 10843:229675bb7647 ss-3-3-52
version is now 3.3.52
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 01 Aug 2010 11:49:45 -0400 |
parents | 1b2fcd122c6a |
children | 4bec51eb58e2 |
rev | line source |
---|---|
2980 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1998, 2000, 2002, 2003, 2004, 2005, 2006, |
8920 | 4 2007, 2008, 2009 John W. Eaton |
2980 | 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. | |
2980 | 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/>. | |
2980 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
3933 | 28 #include "Cell.h" |
2980 | 29 #include "error.h" |
3930 | 30 #include "oct-map.h" |
2980 | 31 #include "oct-obj.h" |
32 #include "oct-lvalue.h" | |
33 #include "ov.h" | |
3930 | 34 #include "pager.h" |
2982 | 35 #include "pt-arg-list.h" |
3930 | 36 #include "pt-bp.h" |
7336 | 37 #include "pt-id.h" |
2980 | 38 #include "pt-idx.h" |
39 #include "pt-walk.h" | |
3930 | 40 #include "utils.h" |
41 #include "variables.h" | |
8579
7e0f36dfefbe
implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents:
8564
diff
changeset
|
42 #include "gripes.h" |
2980 | 43 |
44 // Index expressions. | |
45 | |
5861 | 46 tree_index_expression::tree_index_expression (int l, int c) |
7791
975e9540be2c
pt-idx.cc: initialize fields in constructors
John W. Eaton <jwe@octave.org>
parents:
7790
diff
changeset
|
47 : tree_expression (l, c), expr (0), args (0), type (), |
5861 | 48 arg_nm (), dyn_field () { } |
49 | |
3546 | 50 tree_index_expression::tree_index_expression (tree_expression *e, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
51 tree_argument_list *lst, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
52 int l, int c, char t) |
7791
975e9540be2c
pt-idx.cc: initialize fields in constructors
John W. Eaton <jwe@octave.org>
parents:
7790
diff
changeset
|
53 : tree_expression (l, c), expr (e), args (0), type (), |
4131 | 54 arg_nm (), dyn_field () |
3933 | 55 { |
56 append (lst, t); | |
57 } | |
3215 | 58 |
3930 | 59 tree_index_expression::tree_index_expression (tree_expression *e, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
60 const std::string& n, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
61 int l, int c) |
7791
975e9540be2c
pt-idx.cc: initialize fields in constructors
John W. Eaton <jwe@octave.org>
parents:
7790
diff
changeset
|
62 : tree_expression (l, c), expr (e), args (0), type (), |
4131 | 63 arg_nm (), dyn_field () |
3933 | 64 { |
65 append (n); | |
66 } | |
67 | |
4131 | 68 tree_index_expression::tree_index_expression (tree_expression *e, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
69 tree_expression *df, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
70 int l, int c) |
7791
975e9540be2c
pt-idx.cc: initialize fields in constructors
John W. Eaton <jwe@octave.org>
parents:
7790
diff
changeset
|
71 : tree_expression (l, c), expr (e), args (0), type (), |
4131 | 72 arg_nm (), dyn_field () |
73 { | |
74 append (df); | |
75 } | |
76 | |
3933 | 77 void |
78 tree_index_expression::append (tree_argument_list *lst, char t) | |
79 { | |
4219 | 80 args.push_back (lst); |
3933 | 81 type.append (1, t); |
4219 | 82 arg_nm.push_back (lst ? lst->get_arg_names () : string_vector ()); |
83 dyn_field.push_back (static_cast<tree_expression *> (0)); | |
10206
37a08e0ce2dc
support Matlab-style empty output/input arguments
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
84 |
37a08e0ce2dc
support Matlab-style empty output/input arguments
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
85 if (lst && lst->has_magic_tilde ()) |
37a08e0ce2dc
support Matlab-style empty output/input arguments
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
86 error ("invalid use of empty argument (~) in index expression"); |
3933 | 87 } |
88 | |
89 void | |
90 tree_index_expression::append (const std::string& n) | |
91 { | |
4219 | 92 args.push_back (static_cast<tree_argument_list *> (0)); |
3933 | 93 type.append ("."); |
4219 | 94 arg_nm.push_back (n); |
95 dyn_field.push_back (static_cast<tree_expression *> (0)); | |
4131 | 96 } |
97 | |
98 void | |
99 tree_index_expression::append (tree_expression *df) | |
100 { | |
4219 | 101 args.push_back (static_cast<tree_argument_list *> (0)); |
4131 | 102 type.append ("."); |
4219 | 103 arg_nm.push_back (""); |
104 dyn_field.push_back (df); | |
3933 | 105 } |
3930 | 106 |
2980 | 107 tree_index_expression::~tree_index_expression (void) |
108 { | |
109 delete expr; | |
3933 | 110 |
111 while (! args.empty ()) | |
112 { | |
4219 | 113 std::list<tree_argument_list *>::iterator p = args.begin (); |
114 delete *p; | |
115 args.erase (p); | |
3933 | 116 } |
2980 | 117 } |
118 | |
5099 | 119 bool |
120 tree_index_expression::has_magic_end (void) const | |
121 { | |
122 for (std::list<tree_argument_list *>::const_iterator p = args.begin (); | |
123 p != args.end (); | |
124 p++) | |
125 { | |
126 tree_argument_list *elt = *p; | |
127 | |
128 if (elt && elt->has_magic_end ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
129 return true; |
5099 | 130 } |
131 | |
132 return false; | |
133 } | |
134 | |
2991 | 135 // This is useful for printing the name of the variable in an indexed |
136 // assignment. | |
137 | |
3536 | 138 std::string |
2991 | 139 tree_index_expression::name (void) const |
140 { | |
4131 | 141 return expr->name (); |
3933 | 142 } |
143 | |
144 static Cell | |
145 make_subs_cell (tree_argument_list *args, const string_vector& arg_nm) | |
146 { | |
147 Cell retval; | |
148 | |
149 octave_value_list arg_values; | |
150 | |
151 if (args) | |
152 arg_values = args->convert_to_const_vector (); | |
153 | |
154 if (! error_state) | |
155 { | |
156 int n = arg_values.length (); | |
157 | |
158 if (n > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
159 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
160 arg_values.stash_name_tags (arg_nm); |
3933 | 161 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
162 retval.resize (dim_vector (1, n)); |
3933 | 163 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
164 for (int i = 0; i < n; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
165 retval(0,i) = arg_values(i); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
166 } |
3933 | 167 } |
168 | |
169 return retval; | |
170 } | |
171 | |
172 static inline octave_value_list | |
4234 | 173 make_value_list (tree_argument_list *args, const string_vector& arg_nm, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
174 const octave_value *object) |
3933 | 175 { |
176 octave_value_list retval; | |
177 | |
178 if (args) | |
9125
8ab1e6f63cdc
gripe on magic end query for undefined variable
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
179 { |
8ab1e6f63cdc
gripe on magic end query for undefined variable
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
180 if (object && args->has_magic_end () && object->is_undefined ()) |
8ab1e6f63cdc
gripe on magic end query for undefined variable
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
181 gripe_invalid_inquiry_subscript (); |
8ab1e6f63cdc
gripe on magic end query for undefined variable
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
182 else |
8ab1e6f63cdc
gripe on magic end query for undefined variable
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
183 retval = args->convert_to_const_vector (object); |
8ab1e6f63cdc
gripe on magic end query for undefined variable
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
184 } |
3933 | 185 |
186 if (! error_state) | |
187 { | |
10659
8baff2aceabc
fix slicing value lists with name tags (bug #29960)
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
188 octave_idx_type n = retval.length (); |
3933 | 189 |
190 if (n > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
191 retval.stash_name_tags (arg_nm); |
3933 | 192 } |
193 | |
194 return retval; | |
195 } | |
196 | |
4131 | 197 std::string |
4219 | 198 tree_index_expression::get_struct_index |
199 (std::list<string_vector>::const_iterator p_arg_nm, | |
200 std::list<tree_expression *>::const_iterator p_dyn_field) const | |
4131 | 201 { |
4219 | 202 std::string fn = (*p_arg_nm)(0); |
4131 | 203 |
204 if (fn.empty ()) | |
205 { | |
4219 | 206 tree_expression *df = *p_dyn_field; |
4131 | 207 |
208 if (df) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
209 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
210 octave_value t = df->rvalue1 (); |
4131 | 211 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
212 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
213 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
214 fn = t.string_value (); |
4143 | 215 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
216 if (! valid_identifier (fn)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
217 ::error ("invalid structure field name `%s'", fn.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
218 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
219 } |
4131 | 220 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
221 panic_impossible (); |
4131 | 222 } |
223 | |
224 return fn; | |
225 } | |
226 | |
3933 | 227 Octave_map |
228 tree_index_expression::make_arg_struct (void) const | |
229 { | |
4219 | 230 int n = args.size (); |
3933 | 231 |
7336 | 232 Cell type_field (n, 1); |
233 Cell subs_field (n, 1); | |
3933 | 234 |
4219 | 235 std::list<tree_argument_list *>::const_iterator p_args = args.begin (); |
236 std::list<string_vector>::const_iterator p_arg_nm = arg_nm.begin (); | |
237 std::list<tree_expression *>::const_iterator p_dyn_field = dyn_field.begin (); | |
3933 | 238 |
239 Octave_map m; | |
240 | |
241 for (int i = 0; i < n; i++) | |
242 { | |
243 switch (type[i]) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
244 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
245 case '(': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
246 subs_field(i) = make_subs_cell (*p_args, *p_arg_nm); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
247 break; |
3933 | 248 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
249 case '{': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
250 subs_field(i) = make_subs_cell (*p_args, *p_arg_nm); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
251 break; |
3933 | 252 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
253 case '.': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
254 subs_field(i) = get_struct_index (p_arg_nm, p_dyn_field); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
255 break; |
3933 | 256 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
257 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
258 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
259 } |
3933 | 260 |
261 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
262 return m; |
3933 | 263 |
4219 | 264 p_args++; |
265 p_arg_nm++; | |
266 p_dyn_field++; | |
3933 | 267 } |
268 | |
7336 | 269 m.assign ("type", type_field); |
270 m.assign ("subs", subs_field); | |
3933 | 271 |
272 return m; | |
2991 | 273 } |
274 | |
2980 | 275 octave_value_list |
276 tree_index_expression::rvalue (int nargout) | |
277 { | |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10659
diff
changeset
|
278 return tree_index_expression::rvalue (nargout, 0); |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10659
diff
changeset
|
279 } |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10659
diff
changeset
|
280 |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10659
diff
changeset
|
281 octave_value_list |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10659
diff
changeset
|
282 tree_index_expression::rvalue (int nargout, const std::list<octave_lvalue> *lvalue_list) |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10659
diff
changeset
|
283 { |
2980 | 284 octave_value_list retval; |
285 | |
286 if (error_state) | |
287 return retval; | |
288 | |
7336 | 289 octave_value first_expr_val; |
290 | |
291 octave_value_list first_args; | |
292 | |
293 bool have_args = false; | |
294 | |
295 if (expr->is_identifier () && type[0] == '(') | |
296 { | |
297 tree_identifier *id = dynamic_cast<tree_identifier *> (expr); | |
298 | |
299 if (! (id->is_variable () || args.empty ())) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
300 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
301 tree_argument_list *al = *(args.begin ()); |
7336 | 302 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
303 size_t n = al ? al->length () : 0; |
7336 | 304 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
305 if (n > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
306 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
307 string_vector anm = *(arg_nm.begin ()); |
9445
c5f03874ea2a
simplify symbol_table::find and associated functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
308 have_args = true; |
c5f03874ea2a
simplify symbol_table::find and associated functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
309 first_args = al -> convert_to_const_vector (); |
c5f03874ea2a
simplify symbol_table::find and associated functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
310 first_args.stash_name_tags (anm); |
7336 | 311 |
9445
c5f03874ea2a
simplify symbol_table::find and associated functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
312 if (! error_state) |
c5f03874ea2a
simplify symbol_table::find and associated functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
313 first_expr_val = id->do_lookup (first_args); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
314 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
315 } |
7336 | 316 } |
2980 | 317 |
318 if (! error_state) | |
319 { | |
7336 | 320 if (first_expr_val.is_undefined ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
321 first_expr_val = expr->rvalue1 (); |
7336 | 322 |
323 octave_value tmp = first_expr_val; | |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
324 octave_idx_type tmpi = 0; |
7336 | 325 |
4219 | 326 std::list<octave_value_list> idx; |
3930 | 327 |
4219 | 328 int n = args.size (); |
3933 | 329 |
4219 | 330 std::list<tree_argument_list *>::iterator p_args = args.begin (); |
331 std::list<string_vector>::iterator p_arg_nm = arg_nm.begin (); | |
332 std::list<tree_expression *>::iterator p_dyn_field = dyn_field.begin (); | |
3930 | 333 |
3933 | 334 for (int i = 0; i < n; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
335 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
336 if (i > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
337 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
338 tree_argument_list *al = *p_args; |
4432 | 339 |
9692
126b49caba0d
smart splitting of index chains
Jaroslav Hajek <highegg@gmail.com>
parents:
9445
diff
changeset
|
340 // In Matlab, () can only be followed by . In Octave, we do not |
126b49caba0d
smart splitting of index chains
Jaroslav Hajek <highegg@gmail.com>
parents:
9445
diff
changeset
|
341 // enforce this for rvalue expressions, but we'll split the |
126b49caba0d
smart splitting of index chains
Jaroslav Hajek <highegg@gmail.com>
parents:
9445
diff
changeset
|
342 // evaluation at this point. This will, hopefully, allow Octave's |
126b49caba0d
smart splitting of index chains
Jaroslav Hajek <highegg@gmail.com>
parents:
9445
diff
changeset
|
343 // looser rules apply smoothly for Matlab overloaded subsref |
126b49caba0d
smart splitting of index chains
Jaroslav Hajek <highegg@gmail.com>
parents:
9445
diff
changeset
|
344 // codes. |
126b49caba0d
smart splitting of index chains
Jaroslav Hajek <highegg@gmail.com>
parents:
9445
diff
changeset
|
345 bool force_split = type[i-1] == '(' && type[i] != '.'; |
126b49caba0d
smart splitting of index chains
Jaroslav Hajek <highegg@gmail.com>
parents:
9445
diff
changeset
|
346 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
347 if (force_split || (al && al->has_magic_end ())) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
348 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
349 // We have an expression like |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
350 // |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
351 // x{end}.a(end) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
352 // |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
353 // and we are looking at the argument list that |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
354 // contains the second (or third, etc.) "end" token, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
355 // so we must evaluate everything up to the point of |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
356 // that argument list so we can pass the appropriate |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
357 // value to the built-in __end__ function. |
4432 | 358 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
359 const octave_value_list tmp_list |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
360 = tmp.subsref (type.substr (tmpi, i - tmpi), idx, nargout); |
4432 | 361 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
362 tmp = tmp_list.length () ? tmp_list(0) : octave_value (); |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
363 tmpi = i; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
364 idx.clear (); |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
365 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
366 if (tmp.is_cs_list ()) |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
367 gripe_indexed_cs_list (); |
4432 | 368 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
369 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
370 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
371 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
372 } |
4432 | 373 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
374 switch (type[i]) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
375 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
376 case '(': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
377 if (have_args) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
378 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
379 idx.push_back (first_args); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
380 have_args = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
381 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
382 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
383 idx.push_back (make_value_list (*p_args, *p_arg_nm, &tmp)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
384 break; |
3930 | 385 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
386 case '{': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
387 idx.push_back (make_value_list (*p_args, *p_arg_nm, &tmp)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
388 break; |
2980 | 389 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
390 case '.': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
391 idx.push_back (octave_value (get_struct_index (p_arg_nm, p_dyn_field))); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
392 break; |
3930 | 393 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
394 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
395 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
396 } |
3930 | 397 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
398 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
399 break; |
3933 | 400 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
401 p_args++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
402 p_arg_nm++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
403 p_dyn_field++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
404 } |
3933 | 405 |
406 if (! error_state) | |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10659
diff
changeset
|
407 retval = tmp.subsref (type.substr (tmpi, n - tmpi), idx, nargout, |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10659
diff
changeset
|
408 lvalue_list); |
2980 | 409 } |
410 | |
411 return retval; | |
412 } | |
413 | |
414 octave_value | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8580
diff
changeset
|
415 tree_index_expression::rvalue1 (int nargout) |
2980 | 416 { |
417 octave_value retval; | |
418 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8580
diff
changeset
|
419 const octave_value_list tmp = rvalue (nargout); |
2980 | 420 |
421 if (! tmp.empty ()) | |
422 retval = tmp(0); | |
423 | |
424 return retval; | |
425 } | |
426 | |
427 octave_lvalue | |
428 tree_index_expression::lvalue (void) | |
429 { | |
430 octave_lvalue retval; | |
431 | |
4219 | 432 std::list<octave_value_list> idx; |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
433 std::string tmp_type; |
3933 | 434 |
4219 | 435 int n = args.size (); |
3933 | 436 |
4219 | 437 std::list<tree_argument_list *>::iterator p_args = args.begin (); |
438 std::list<string_vector>::iterator p_arg_nm = arg_nm.begin (); | |
439 std::list<tree_expression *>::iterator p_dyn_field = dyn_field.begin (); | |
3933 | 440 |
4234 | 441 retval = expr->lvalue (); |
3933 | 442 |
2980 | 443 if (! error_state) |
444 { | |
4432 | 445 const octave_value *tro = retval.object (); |
446 | |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
447 octave_value tmp; |
4432 | 448 |
449 if (tro) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
450 tmp = *tro; |
4432 | 451 |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
452 octave_idx_type tmpi = 0; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
453 std::list<octave_value_list> tmpidx; |
4234 | 454 |
455 for (int i = 0; i < n; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
456 { |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
457 if (retval.numel () != 1) |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
458 gripe_indexed_cs_list (); |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
459 else if (tmpi < i) |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
460 { |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
461 tmp = tmp.subsref (type.substr (tmpi, i - tmpi), tmpidx, true); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
462 tmpidx.clear (); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
463 } |
4432 | 464 |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
465 if (error_state) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
466 break; |
4432 | 467 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
468 switch (type[i]) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
469 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
470 case '(': |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
471 { |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
472 octave_value_list tidx |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
473 = make_value_list (*p_args, *p_arg_nm, &tmp); |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
474 |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
475 idx.push_back (tidx); |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
476 |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
477 if (i < n - 1) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
478 { |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
479 if (type[i+1] == '.') |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
480 { |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
481 tmpidx.push_back (tidx); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
482 tmpi = i+1; |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
483 } |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
484 else |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
485 error ("() must be followed by . or close the index chain"); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
486 } |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
487 } |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
488 break; |
4234 | 489 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
490 case '{': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
491 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
492 octave_value_list tidx |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
493 = make_value_list (*p_args, *p_arg_nm, &tmp); |
5846 | 494 |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
495 if (tmp.is_undefined ()) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
496 { |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
497 if (tidx.has_magic_colon ()) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
498 gripe_invalid_inquiry_subscript (); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
499 else |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
500 tmp = Cell (); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
501 } |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
502 else if (tmp.is_zero_by_zero () |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
503 && (tmp.is_matrix_type () || tmp.is_string ())) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
504 { |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
505 tmp = Cell (); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
506 } |
5846 | 507 |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
508 retval.numel (tmp.numel (tidx)); |
5846 | 509 |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
510 if (error_state) |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
511 break; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
512 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
513 idx.push_back (tidx); |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
514 tmpidx.push_back (tidx); |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
515 tmpi = i; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
516 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
517 break; |
4234 | 518 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
519 case '.': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
520 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
521 octave_value tidx = get_struct_index (p_arg_nm, p_dyn_field); |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
522 if (error_state) |
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
523 break; |
6833 | 524 |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
525 bool autoconv = (tmp.is_zero_by_zero () |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
526 && (tmp.is_matrix_type () || tmp.is_string () |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
527 || tmp.is_cell ())); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
528 |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
529 if (i > 0 && type [i-1] == '(') |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
530 { |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
531 octave_value_list pidx = idx.back (); |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
532 |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
533 if (tmp.is_undefined ()) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
534 { |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
535 if (pidx.has_magic_colon ()) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
536 gripe_invalid_inquiry_subscript (); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
537 else |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
538 tmp = Octave_map (); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
539 } |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
540 else if (autoconv) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
541 tmp = Octave_map (); |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
542 |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
543 retval.numel (tmp.numel (pidx)); |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
544 |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
545 tmpi = i-1; |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
546 tmpidx.push_back (tidx); |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
547 } |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
548 else |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
549 { |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
550 if (tmp.is_undefined () || autoconv) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
551 { |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
552 tmpi = i+1; |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
553 tmp = octave_value (); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
554 } |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
555 else |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
556 { |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
557 retval.numel (tmp.numel (octave_value_list ())); |
7099 | 558 |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
559 tmpi = i; |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
560 tmpidx.push_back (tidx); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
561 } |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
562 } |
7057 | 563 |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
564 if (error_state) |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
565 break; |
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
566 |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
567 idx.push_back (tidx); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
568 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
569 break; |
4234 | 570 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
571 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
572 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
573 } |
4234 | 574 |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
575 if (idx.back ().empty ()) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
576 error ("invalid empty index list"); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
577 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
578 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
579 break; |
4234 | 580 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
581 p_args++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
582 p_arg_nm++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
583 p_dyn_field++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
584 } |
3930 | 585 |
3933 | 586 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
587 retval.set_index (type, idx); |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
588 |
2980 | 589 } |
590 | |
591 return retval; | |
592 } | |
593 | |
7099 | 594 /* |
595 %!test | |
596 %! x = {1, 2, 3}; | |
597 %! [x{:}] = deal (4, 5, 6); | |
598 %! assert (x, {4, 5, 6}); | |
599 | |
600 %!test | |
601 %! [x.a, x.b.c] = deal (1, 2); | |
602 %! assert (x.a == 1 && x.b.c == 2); | |
603 | |
604 %!test | |
605 %! [x.a, x(2).b] = deal (1, 2); | |
606 %! assert (x(1).a == 1 && isempty (x(2).a) && isempty (x(1).b) && x(2).b == 2); | |
607 | |
608 %!test | |
609 %! x = struct (zeros (0, 1), {"a", "b"}); | |
610 %! x(2).b = 1; | |
611 %! assert (x(2).b == 1); | |
612 | |
613 %!test | |
614 %! x = struct (zeros (0, 1), {"a", "b"}); | |
615 %! x(2).b = 1; | |
616 %! assert (x(2).b == 1); | |
617 */ | |
618 | |
5861 | 619 tree_index_expression * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
620 tree_index_expression::dup (symbol_table::scope_id scope, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
621 symbol_table::context_id context) const |
5861 | 622 { |
623 tree_index_expression *new_idx_expr | |
624 = new tree_index_expression (line (), column ()); | |
625 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
626 new_idx_expr->expr = expr ? expr->dup (scope, context) : 0; |
5861 | 627 |
628 std::list<tree_argument_list *> new_args; | |
629 | |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
630 for (std::list<tree_argument_list *>::const_iterator p = args.begin (); |
5861 | 631 p != args.end (); |
632 p++) | |
633 { | |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
634 const tree_argument_list *elt = *p; |
5861 | 635 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
636 new_args.push_back (elt ? elt->dup (scope, context) : 0); |
5861 | 637 } |
638 | |
639 new_idx_expr->args = new_args; | |
640 | |
641 new_idx_expr->type = type; | |
642 | |
643 new_idx_expr->arg_nm = arg_nm; | |
644 | |
645 std::list<tree_expression *> new_dyn_field; | |
646 | |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
647 for (std::list<tree_expression *>::const_iterator p = dyn_field.begin (); |
5861 | 648 p != dyn_field.end (); |
649 p++) | |
650 { | |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
651 const tree_expression *elt = *p; |
5861 | 652 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
653 new_dyn_field.push_back (elt ? elt->dup (scope, context) : 0); |
5861 | 654 } |
655 | |
656 new_idx_expr->dyn_field = new_dyn_field; | |
657 | |
658 new_idx_expr->copy_base (*this); | |
659 | |
660 return new_idx_expr; | |
661 } | |
662 | |
2980 | 663 void |
664 tree_index_expression::accept (tree_walker& tw) | |
665 { | |
666 tw.visit_index_expression (*this); | |
667 } |