Mercurial > hg > octave-nkf
annotate libinterp/parse-tree/pt-idx.cc @ 16325:fc565603ccbb
also accept "." as possibly beginning a command
* lex.ll ("."): If it looks like a command, parse it like one.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 16 Mar 2013 04:43:30 -0400 |
parents | f2b8f90052fd |
children | 302157614308 |
rev | line source |
---|---|
2980 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13970
diff
changeset
|
3 Copyright (C) 1996-2012 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 } |
13970 | 116 |
117 while (! dyn_field.empty ()) | |
118 { | |
119 std::list<tree_expression *>::iterator p = dyn_field.begin (); | |
120 delete *p; | |
121 dyn_field.erase (p); | |
122 } | |
2980 | 123 } |
124 | |
5099 | 125 bool |
126 tree_index_expression::has_magic_end (void) const | |
127 { | |
128 for (std::list<tree_argument_list *>::const_iterator p = args.begin (); | |
129 p != args.end (); | |
130 p++) | |
131 { | |
132 tree_argument_list *elt = *p; | |
133 | |
134 if (elt && elt->has_magic_end ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
135 return true; |
5099 | 136 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
137 |
5099 | 138 return false; |
139 } | |
140 | |
2991 | 141 // This is useful for printing the name of the variable in an indexed |
142 // assignment. | |
143 | |
3536 | 144 std::string |
2991 | 145 tree_index_expression::name (void) const |
146 { | |
4131 | 147 return expr->name (); |
3933 | 148 } |
149 | |
150 static Cell | |
151 make_subs_cell (tree_argument_list *args, const string_vector& arg_nm) | |
152 { | |
153 Cell retval; | |
154 | |
155 octave_value_list arg_values; | |
156 | |
157 if (args) | |
158 arg_values = args->convert_to_const_vector (); | |
159 | |
160 if (! error_state) | |
161 { | |
162 int n = arg_values.length (); | |
163 | |
164 if (n > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
165 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
166 arg_values.stash_name_tags (arg_nm); |
3933 | 167 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
168 retval.resize (dim_vector (1, n)); |
3933 | 169 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
170 for (int i = 0; i < n; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
171 retval(0,i) = arg_values(i); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
172 } |
3933 | 173 } |
174 | |
175 return retval; | |
176 } | |
177 | |
178 static inline octave_value_list | |
4234 | 179 make_value_list (tree_argument_list *args, const string_vector& arg_nm, |
14343
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
180 const octave_value *object, bool rvalue = true) |
3933 | 181 { |
182 octave_value_list retval; | |
183 | |
184 if (args) | |
9125
8ab1e6f63cdc
gripe on magic end query for undefined variable
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
185 { |
14343
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
186 if (rvalue && object && args->has_magic_end () && object->is_undefined ()) |
9125
8ab1e6f63cdc
gripe on magic end query for undefined variable
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
187 gripe_invalid_inquiry_subscript (); |
8ab1e6f63cdc
gripe on magic end query for undefined variable
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
188 else |
8ab1e6f63cdc
gripe on magic end query for undefined variable
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
189 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
|
190 } |
3933 | 191 |
192 if (! error_state) | |
193 { | |
10659
8baff2aceabc
fix slicing value lists with name tags (bug #29960)
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
194 octave_idx_type n = retval.length (); |
3933 | 195 |
196 if (n > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
197 retval.stash_name_tags (arg_nm); |
3933 | 198 } |
199 | |
200 return retval; | |
201 } | |
202 | |
4131 | 203 std::string |
4219 | 204 tree_index_expression::get_struct_index |
205 (std::list<string_vector>::const_iterator p_arg_nm, | |
206 std::list<tree_expression *>::const_iterator p_dyn_field) const | |
4131 | 207 { |
4219 | 208 std::string fn = (*p_arg_nm)(0); |
4131 | 209 |
210 if (fn.empty ()) | |
211 { | |
4219 | 212 tree_expression *df = *p_dyn_field; |
4131 | 213 |
214 if (df) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
215 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
216 octave_value t = df->rvalue1 (); |
4131 | 217 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
218 if (! error_state) |
15614
f2b8f90052fd
warn instead of throwing an error for invalid structure field names
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
219 fn = t.string_value (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
220 } |
4131 | 221 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
222 panic_impossible (); |
4131 | 223 } |
224 | |
225 return fn; | |
226 } | |
227 | |
11056
4bec51eb58e2
replace Octave_map->octave_map in pt-idx.h
Jaroslav Hajek <highegg@gmail.com>
parents:
10832
diff
changeset
|
228 octave_map |
3933 | 229 tree_index_expression::make_arg_struct (void) const |
230 { | |
4219 | 231 int n = args.size (); |
3933 | 232 |
7336 | 233 Cell type_field (n, 1); |
234 Cell subs_field (n, 1); | |
3933 | 235 |
4219 | 236 std::list<tree_argument_list *>::const_iterator p_args = args.begin (); |
237 std::list<string_vector>::const_iterator p_arg_nm = arg_nm.begin (); | |
238 std::list<tree_expression *>::const_iterator p_dyn_field = dyn_field.begin (); | |
3933 | 239 |
11056
4bec51eb58e2
replace Octave_map->octave_map in pt-idx.h
Jaroslav Hajek <highegg@gmail.com>
parents:
10832
diff
changeset
|
240 octave_map m; |
3933 | 241 |
242 for (int i = 0; i < n; i++) | |
243 { | |
244 switch (type[i]) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
245 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
246 case '(': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
247 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
|
248 break; |
3933 | 249 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
250 case '{': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
251 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
|
252 break; |
3933 | 253 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
254 case '.': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
255 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
|
256 break; |
3933 | 257 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
258 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
259 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
260 } |
3933 | 261 |
262 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
263 return m; |
3933 | 264 |
4219 | 265 p_args++; |
266 p_arg_nm++; | |
267 p_dyn_field++; | |
3933 | 268 } |
269 | |
7336 | 270 m.assign ("type", type_field); |
271 m.assign ("subs", subs_field); | |
3933 | 272 |
273 return m; | |
2991 | 274 } |
275 | |
2980 | 276 octave_value_list |
277 tree_index_expression::rvalue (int nargout) | |
278 { | |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10659
diff
changeset
|
279 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
|
280 } |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10659
diff
changeset
|
281 |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10659
diff
changeset
|
282 octave_value_list |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10659
diff
changeset
|
283 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
|
284 { |
2980 | 285 octave_value_list retval; |
286 | |
287 if (error_state) | |
288 return retval; | |
289 | |
7336 | 290 octave_value first_expr_val; |
291 | |
292 octave_value_list first_args; | |
293 | |
294 bool have_args = false; | |
295 | |
296 if (expr->is_identifier () && type[0] == '(') | |
297 { | |
298 tree_identifier *id = dynamic_cast<tree_identifier *> (expr); | |
299 | |
300 if (! (id->is_variable () || args.empty ())) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
301 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
302 tree_argument_list *al = *(args.begin ()); |
7336 | 303 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
304 size_t n = al ? al->length () : 0; |
7336 | 305 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
306 if (n > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
307 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
308 string_vector anm = *(arg_nm.begin ()); |
9445
c5f03874ea2a
simplify symbol_table::find and associated functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
309 have_args = true; |
c5f03874ea2a
simplify symbol_table::find and associated functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
310 first_args = al -> convert_to_const_vector (); |
c5f03874ea2a
simplify symbol_table::find and associated functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
311 first_args.stash_name_tags (anm); |
7336 | 312 |
9445
c5f03874ea2a
simplify symbol_table::find and associated functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
313 if (! error_state) |
c5f03874ea2a
simplify symbol_table::find and associated functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
314 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
|
315 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
316 } |
7336 | 317 } |
2980 | 318 |
319 if (! error_state) | |
320 { | |
7336 | 321 if (first_expr_val.is_undefined ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
322 first_expr_val = expr->rvalue1 (); |
7336 | 323 |
324 octave_value tmp = first_expr_val; | |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
325 octave_idx_type tmpi = 0; |
7336 | 326 |
4219 | 327 std::list<octave_value_list> idx; |
3930 | 328 |
4219 | 329 int n = args.size (); |
3933 | 330 |
4219 | 331 std::list<tree_argument_list *>::iterator p_args = args.begin (); |
332 std::list<string_vector>::iterator p_arg_nm = arg_nm.begin (); | |
333 std::list<tree_expression *>::iterator p_dyn_field = dyn_field.begin (); | |
3930 | 334 |
3933 | 335 for (int i = 0; i < n; i++) |
10315
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 if (i > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
338 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
339 tree_argument_list *al = *p_args; |
4432 | 340 |
9692
126b49caba0d
smart splitting of index chains
Jaroslav Hajek <highegg@gmail.com>
parents:
9445
diff
changeset
|
341 // 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
|
342 // 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
|
343 // 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
|
344 // looser rules apply smoothly for Matlab overloaded subsref |
126b49caba0d
smart splitting of index chains
Jaroslav Hajek <highegg@gmail.com>
parents:
9445
diff
changeset
|
345 // codes. |
126b49caba0d
smart splitting of index chains
Jaroslav Hajek <highegg@gmail.com>
parents:
9445
diff
changeset
|
346 bool force_split = type[i-1] == '(' && type[i] != '.'; |
126b49caba0d
smart splitting of index chains
Jaroslav Hajek <highegg@gmail.com>
parents:
9445
diff
changeset
|
347 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
348 if (force_split || (al && al->has_magic_end ())) |
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 // We have an expression like |
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 // x{end}.a(end) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
353 // |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
354 // 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
|
355 // contains the second (or third, etc.) "end" token, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
356 // 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
|
357 // 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
|
358 // value to the built-in __end__ function. |
4432 | 359 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
360 const octave_value_list tmp_list |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
361 = tmp.subsref (type.substr (tmpi, i - tmpi), idx, nargout); |
4432 | 362 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
363 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
|
364 tmpi = i; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
365 idx.clear (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
366 |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
367 if (tmp.is_cs_list ()) |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
368 gripe_indexed_cs_list (); |
4432 | 369 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
370 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
371 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
372 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
373 } |
4432 | 374 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
375 switch (type[i]) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
376 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
377 case '(': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
378 if (have_args) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
379 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
380 idx.push_back (first_args); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
381 have_args = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
382 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
383 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
384 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
|
385 break; |
3930 | 386 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
387 case '{': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
388 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
|
389 break; |
2980 | 390 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
391 case '.': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
392 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
|
393 break; |
3930 | 394 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
395 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
396 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
397 } |
3930 | 398 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
399 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
400 break; |
3933 | 401 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
402 p_args++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
403 p_arg_nm++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
404 p_dyn_field++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
405 } |
3933 | 406 |
407 if (! error_state) | |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10659
diff
changeset
|
408 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
|
409 lvalue_list); |
2980 | 410 } |
411 | |
412 return retval; | |
413 } | |
414 | |
415 octave_value | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8580
diff
changeset
|
416 tree_index_expression::rvalue1 (int nargout) |
2980 | 417 { |
418 octave_value retval; | |
419 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8580
diff
changeset
|
420 const octave_value_list tmp = rvalue (nargout); |
2980 | 421 |
422 if (! tmp.empty ()) | |
423 retval = tmp(0); | |
424 | |
425 return retval; | |
426 } | |
427 | |
428 octave_lvalue | |
429 tree_index_expression::lvalue (void) | |
430 { | |
431 octave_lvalue retval; | |
432 | |
4219 | 433 std::list<octave_value_list> idx; |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
434 std::string tmp_type; |
3933 | 435 |
4219 | 436 int n = args.size (); |
3933 | 437 |
4219 | 438 std::list<tree_argument_list *>::iterator p_args = args.begin (); |
439 std::list<string_vector>::iterator p_arg_nm = arg_nm.begin (); | |
440 std::list<tree_expression *>::iterator p_dyn_field = dyn_field.begin (); | |
3933 | 441 |
4234 | 442 retval = expr->lvalue (); |
3933 | 443 |
2980 | 444 if (! error_state) |
445 { | |
4432 | 446 const octave_value *tro = retval.object (); |
447 | |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
448 octave_value tmp; |
4432 | 449 |
450 if (tro) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
451 tmp = *tro; |
4432 | 452 |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
453 octave_idx_type tmpi = 0; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
454 std::list<octave_value_list> tmpidx; |
4234 | 455 |
456 for (int i = 0; i < n; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
457 { |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
458 if (retval.numel () != 1) |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
459 gripe_indexed_cs_list (); |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
460 else if (tmpi < i) |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
461 { |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
462 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
|
463 tmpidx.clear (); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
464 } |
4432 | 465 |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
466 if (error_state) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
467 break; |
4432 | 468 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
469 switch (type[i]) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
470 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
471 case '(': |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
472 { |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
473 octave_value_list tidx |
14343
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
474 = make_value_list (*p_args, *p_arg_nm, &tmp, false); |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
475 |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
476 idx.push_back (tidx); |
9329
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 (i < n - 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 if (type[i+1] == '.') |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
481 { |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
482 tmpidx.push_back (tidx); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
483 tmpi = i+1; |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
484 } |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
485 else |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
486 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
|
487 } |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
488 } |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
489 break; |
4234 | 490 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
491 case '{': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
492 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
493 octave_value_list tidx |
14343
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
494 = make_value_list (*p_args, *p_arg_nm, &tmp, false); |
5846 | 495 |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
496 if (tmp.is_undefined ()) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
497 { |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
498 if (tidx.has_magic_colon ()) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
499 gripe_invalid_inquiry_subscript (); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
500 else |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
501 tmp = Cell (); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
502 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
503 else if (tmp.is_zero_by_zero () |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
504 && (tmp.is_matrix_type () || tmp.is_string ())) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
505 { |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
506 tmp = Cell (); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
507 } |
5846 | 508 |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
509 retval.numel (tmp.numel (tidx)); |
5846 | 510 |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
511 if (error_state) |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
512 break; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
513 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
514 idx.push_back (tidx); |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
515 tmpidx.push_back (tidx); |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
516 tmpi = i; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
517 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
518 break; |
4234 | 519 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
520 case '.': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
521 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
522 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
|
523 if (error_state) |
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
524 break; |
6833 | 525 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
526 bool autoconv = (tmp.is_zero_by_zero () |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
527 && (tmp.is_matrix_type () || tmp.is_string () |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
528 || tmp.is_cell ())); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
529 |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
14429
diff
changeset
|
530 if (i > 0 && type[i-1] == '(') |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
531 { |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
532 octave_value_list pidx = idx.back (); |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
533 |
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
|
534 // 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
|
535 // dimensions are 0x0, not 1x1. |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
536 if (tmp.is_undefined ()) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
537 { |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
538 if (pidx.has_magic_colon ()) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
539 gripe_invalid_inquiry_subscript (); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
540 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
|
541 tmp = octave_map (); |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
542 } |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
543 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
|
544 tmp = octave_map (); |
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 retval.numel (tmp.numel (pidx)); |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
547 |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
548 tmpi = i-1; |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
549 tmpidx.push_back (tidx); |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
550 } |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
551 else |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
552 { |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
553 if (tmp.is_undefined () || autoconv) |
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 tmpi = i+1; |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
556 tmp = octave_value (); |
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 else |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
559 { |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
560 retval.numel (tmp.numel (octave_value_list ())); |
7099 | 561 |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
562 tmpi = i; |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
563 tmpidx.push_back (tidx); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
564 } |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
565 } |
7057 | 566 |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
567 if (error_state) |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
568 break; |
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
569 |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
570 idx.push_back (tidx); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
571 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
572 break; |
4234 | 573 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
574 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
575 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
576 } |
4234 | 577 |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
578 if (idx.back ().empty ()) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
579 error ("invalid empty index list"); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
580 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
581 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
582 break; |
4234 | 583 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
584 p_args++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
585 p_arg_nm++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
586 p_dyn_field++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
587 } |
3930 | 588 |
3933 | 589 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
590 retval.set_index (type, idx); |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
591 |
2980 | 592 } |
593 | |
594 return retval; | |
595 } | |
596 | |
7099 | 597 /* |
598 %!test | |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14343
diff
changeset
|
599 %! clear x; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14343
diff
changeset
|
600 %! clear y; |
14343
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
601 %! y = 3; |
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
602 %! x(y(end)) = 1; |
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
603 %! assert (x, [0, 0, 1]); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14343
diff
changeset
|
604 %! clear x; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14343
diff
changeset
|
605 %! clear y; |
14343
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
606 %! y = {3}; |
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
607 %! x(y{end}) = 1; |
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
608 %! assert (x, [0, 0, 1]); |
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
609 |
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
610 %!test |
7099 | 611 %! x = {1, 2, 3}; |
612 %! [x{:}] = deal (4, 5, 6); | |
613 %! assert (x, {4, 5, 6}); | |
614 | |
615 %!test | |
616 %! [x.a, x.b.c] = deal (1, 2); | |
617 %! assert (x.a == 1 && x.b.c == 2); | |
618 | |
619 %!test | |
620 %! [x.a, x(2).b] = deal (1, 2); | |
621 %! assert (x(1).a == 1 && isempty (x(2).a) && isempty (x(1).b) && x(2).b == 2); | |
622 | |
623 %!test | |
624 %! x = struct (zeros (0, 1), {"a", "b"}); | |
625 %! x(2).b = 1; | |
626 %! assert (x(2).b == 1); | |
627 | |
628 %!test | |
629 %! x = struct (zeros (0, 1), {"a", "b"}); | |
630 %! x(2).b = 1; | |
631 %! assert (x(2).b == 1); | |
632 */ | |
633 | |
5861 | 634 tree_index_expression * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
635 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
|
636 symbol_table::context_id context) const |
5861 | 637 { |
638 tree_index_expression *new_idx_expr | |
639 = new tree_index_expression (line (), column ()); | |
640 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
641 new_idx_expr->expr = expr ? expr->dup (scope, context) : 0; |
5861 | 642 |
643 std::list<tree_argument_list *> new_args; | |
644 | |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
645 for (std::list<tree_argument_list *>::const_iterator p = args.begin (); |
5861 | 646 p != args.end (); |
647 p++) | |
648 { | |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
649 const tree_argument_list *elt = *p; |
5861 | 650 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
651 new_args.push_back (elt ? elt->dup (scope, context) : 0); |
5861 | 652 } |
653 | |
654 new_idx_expr->args = new_args; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
655 |
5861 | 656 new_idx_expr->type = type; |
657 | |
658 new_idx_expr->arg_nm = arg_nm; | |
659 | |
660 std::list<tree_expression *> new_dyn_field; | |
661 | |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
662 for (std::list<tree_expression *>::const_iterator p = dyn_field.begin (); |
5861 | 663 p != dyn_field.end (); |
664 p++) | |
665 { | |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
666 const tree_expression *elt = *p; |
5861 | 667 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
668 new_dyn_field.push_back (elt ? elt->dup (scope, context) : 0); |
5861 | 669 } |
670 | |
671 new_idx_expr->dyn_field = new_dyn_field; | |
672 | |
673 new_idx_expr->copy_base (*this); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
674 |
5861 | 675 return new_idx_expr; |
676 } | |
677 | |
2980 | 678 void |
679 tree_index_expression::accept (tree_walker& tw) | |
680 { | |
681 tw.visit_index_expression (*this); | |
682 } |