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