Mercurial > octave-nkf
annotate libinterp/parse-tree/pt-idx.cc @ 20574:dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
* lo-array-gripes.h, lo-array-gripes.cc (index_exception):
New base class for indexing errors.
(invalid_index, out_of_range): New classes.
(gripe_index_out_of_range): New overloaded function.
(gripe_invalid_index): New overloaded functions.
Delete version with no arguments.
(gripe_invalid_assignment_size, gripe_assignment_dimension_mismatch):
Delete.
Change uses of gripe functions as needed.
* Cell.cc (Cell::index, Cell::assign, Cell::delete_elements): Use
exceptions to collect error info about and handle indexing errors.
* data.cc (Fnth_element, do_accumarray_sum, F__accumarray_sum__,
do_accumarray_minmax, do_accumarray_minmax_fun, F__accumdim_sum__):
Likewise.
* oct-map.cc (octave_map::index, octave_map::assign,
octave_map::delete_elements): Likewise.
* sparse.cc (Fsparse): Likewise.
* sub2ind.cc (Fsub2ind, Find2sub): Likewise. New tests.
* utils.cc (dims_to_numel): Likewise.
* ov-base-diag.cc (octave_base_diag<DMT, MT>::do_index_op,
octave_base_diag<DMT, MT>::subsasgn): Likewise.
* ov-base-mat.cc (octave_base_matrix<MT>::subsref,
octave_base_matrix<MT>::assign): Likewise.
* ov-base-sparse.cc (octave_base_sparse<T>::do_index_op,
octave_base_sparse<T>::assign,
octave_base_sparse<MT>::delete_elements): Likewise.
* ov-classdef.cc (cdef_object_array::subsref,
cdef_object_array::subsasgn): Likewise.
* ov-java.cc (make_java_index): Likewise.
* ov-perm.cc (octave_perm_matrix::do_index_op): Likewise.
* ov-range.cc (octave_range::do_index_op): Likewise.
* ov-re-diag.cc (octave_diag_matrix::do_index_op): Likewise.
* ov-str-mat.cc (octave_char_matrix_str::do_index_op_internal): Likewise.
* pt-assign.cc (tree_simple_assignment::rvalue1): Likewise.
* pt-idx.cc (tree_index_expression::rvalue,
tree_index_expression::lvalue): Likewise.
* Array-util.cc (sub2ind): Likewise.
* toplev.cc (main_loop): Also catch unhandled index_exception
exceptions.
* ov-base.cc (octave_base_value::index_vector): Improve error message.
* ov-re-sparse.cc (octave_sparse_matrix::index_vector): Likewise.
* ov-complex.cc (complex_index): New class.
(gripe_complex_index): New function.
(octave_complex::index_vector): Use it.
* pt-id.h, pt-id.cc (tree_identifier::is_variable,
tree_black_hole::is_variable): Now const.
* pt-idx.cc (final_index_error): New static function.
(tree_index_expression::rvalue, tree_index_expression::lvalue):
Use it.
* index.tst: New tests.
author | Lachlan Andrew <lachlanbis@gmail.com> |
---|---|
date | Fri, 02 Oct 2015 15:07:37 -0400 |
parents | 4197fc428c7d |
children | 1a0a433c8263 |
rev | line source |
---|---|
2980 | 1 /* |
2 | |
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19437
diff
changeset
|
3 Copyright (C) 1996-2015 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) |
16656
cf84ea2ba2d3
require dynamic field names to be character strings
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
219 { |
16661
8291109ac3fd
require that dynamic field names have only one row
John W. Eaton <jwe@octave.org>
parents:
16656
diff
changeset
|
220 if (t.is_string () && t.rows () == 1) |
16656
cf84ea2ba2d3
require dynamic field names to be character strings
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
221 fn = t.string_value (); |
cf84ea2ba2d3
require dynamic field names to be character strings
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
222 else |
19437
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
18439
diff
changeset
|
223 error ("dynamic structure field names must be strings"); |
16656
cf84ea2ba2d3
require dynamic field names to be character strings
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
224 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
225 } |
4131 | 226 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
227 panic_impossible (); |
4131 | 228 } |
229 | |
230 return fn; | |
231 } | |
232 | |
11056
4bec51eb58e2
replace Octave_map->octave_map in pt-idx.h
Jaroslav Hajek <highegg@gmail.com>
parents:
10832
diff
changeset
|
233 octave_map |
3933 | 234 tree_index_expression::make_arg_struct (void) const |
235 { | |
4219 | 236 int n = args.size (); |
3933 | 237 |
7336 | 238 Cell type_field (n, 1); |
239 Cell subs_field (n, 1); | |
3933 | 240 |
4219 | 241 std::list<tree_argument_list *>::const_iterator p_args = args.begin (); |
242 std::list<string_vector>::const_iterator p_arg_nm = arg_nm.begin (); | |
243 std::list<tree_expression *>::const_iterator p_dyn_field = dyn_field.begin (); | |
3933 | 244 |
11056
4bec51eb58e2
replace Octave_map->octave_map in pt-idx.h
Jaroslav Hajek <highegg@gmail.com>
parents:
10832
diff
changeset
|
245 octave_map m; |
3933 | 246 |
247 for (int i = 0; i < n; i++) | |
248 { | |
249 switch (type[i]) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
250 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
251 case '(': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
252 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
|
253 break; |
3933 | 254 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
255 case '{': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
256 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
|
257 break; |
3933 | 258 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
259 case '.': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
260 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
|
261 break; |
3933 | 262 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
263 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
264 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
265 } |
3933 | 266 |
267 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
268 return m; |
3933 | 269 |
4219 | 270 p_args++; |
271 p_arg_nm++; | |
272 p_dyn_field++; | |
3933 | 273 } |
274 | |
7336 | 275 m.assign ("type", type_field); |
276 m.assign ("subs", subs_field); | |
3933 | 277 |
278 return m; | |
2991 | 279 } |
280 | |
2980 | 281 octave_value_list |
282 tree_index_expression::rvalue (int nargout) | |
283 { | |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10659
diff
changeset
|
284 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
|
285 } |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10659
diff
changeset
|
286 |
20574
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
287 // Final step of processing an indexing error. Add the name of the |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
288 // variable being indexed, if any, then issue an error. (Will this also |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
289 // be needed by pt-lvalue, which calls subsref?) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
290 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
291 static void |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
292 final_index_error (index_exception& e, const tree_expression *expr) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
293 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
294 if (expr->is_identifier () |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
295 && dynamic_cast<const tree_identifier *> (expr)->is_variable ()) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
296 e.set_var (expr->name ()); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
297 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
298 (*current_liboctave_error_with_id_handler) (e.id (), e.err ()); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
299 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
300 |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10659
diff
changeset
|
301 octave_value_list |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
302 tree_index_expression::rvalue (int nargout, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
303 const std::list<octave_lvalue> *lvalue_list) |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10659
diff
changeset
|
304 { |
2980 | 305 octave_value_list retval; |
306 | |
307 if (error_state) | |
308 return retval; | |
309 | |
7336 | 310 octave_value first_expr_val; |
311 | |
312 octave_value_list first_args; | |
313 | |
314 bool have_args = false; | |
315 | |
316 if (expr->is_identifier () && type[0] == '(') | |
317 { | |
318 tree_identifier *id = dynamic_cast<tree_identifier *> (expr); | |
319 | |
320 if (! (id->is_variable () || args.empty ())) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
321 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
322 tree_argument_list *al = *(args.begin ()); |
7336 | 323 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
324 size_t n = al ? al->length () : 0; |
7336 | 325 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
326 if (n > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
327 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
328 string_vector anm = *(arg_nm.begin ()); |
9445
c5f03874ea2a
simplify symbol_table::find and associated functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
329 have_args = true; |
c5f03874ea2a
simplify symbol_table::find and associated functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
330 first_args = al -> convert_to_const_vector (); |
c5f03874ea2a
simplify symbol_table::find and associated functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
331 first_args.stash_name_tags (anm); |
7336 | 332 |
9445
c5f03874ea2a
simplify symbol_table::find and associated functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
333 if (! error_state) |
c5f03874ea2a
simplify symbol_table::find and associated functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
334 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
|
335 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
336 } |
7336 | 337 } |
2980 | 338 |
339 if (! error_state) | |
340 { | |
7336 | 341 if (first_expr_val.is_undefined ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
342 first_expr_val = expr->rvalue1 (); |
7336 | 343 |
344 octave_value tmp = first_expr_val; | |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
345 octave_idx_type tmpi = 0; |
7336 | 346 |
4219 | 347 std::list<octave_value_list> idx; |
3930 | 348 |
4219 | 349 int n = args.size (); |
3933 | 350 |
4219 | 351 std::list<tree_argument_list *>::iterator p_args = args.begin (); |
352 std::list<string_vector>::iterator p_arg_nm = arg_nm.begin (); | |
353 std::list<tree_expression *>::iterator p_dyn_field = dyn_field.begin (); | |
3930 | 354 |
3933 | 355 for (int i = 0; i < n; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
356 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
357 if (i > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
358 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
359 tree_argument_list *al = *p_args; |
4432 | 360 |
9692
126b49caba0d
smart splitting of index chains
Jaroslav Hajek <highegg@gmail.com>
parents:
9445
diff
changeset
|
361 // 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
|
362 // 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
|
363 // 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
|
364 // looser rules apply smoothly for Matlab overloaded subsref |
126b49caba0d
smart splitting of index chains
Jaroslav Hajek <highegg@gmail.com>
parents:
9445
diff
changeset
|
365 // codes. |
126b49caba0d
smart splitting of index chains
Jaroslav Hajek <highegg@gmail.com>
parents:
9445
diff
changeset
|
366 bool force_split = type[i-1] == '(' && type[i] != '.'; |
126b49caba0d
smart splitting of index chains
Jaroslav Hajek <highegg@gmail.com>
parents:
9445
diff
changeset
|
367 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
368 if (force_split || (al && al->has_magic_end ())) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
369 { |
20574
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
370 // (we have force_split, or) we have an expression like |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
371 // |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
372 // x{end}.a(end) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
373 // |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
374 // 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
|
375 // contains the second (or third, etc.) "end" token, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
376 // 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
|
377 // that argument list so we can pass the appropriate |
17355
f0edd6c752e9
don't convert "end" token to "__end__" for indexing
John W. Eaton <jwe@octave.org>
parents:
16661
diff
changeset
|
378 // value to the built-in end function. |
4432 | 379 |
20574
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
380 try |
18439
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
381 { |
20574
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
382 octave_value_list tmp_list |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
383 =tmp.subsref (type.substr (tmpi, i-tmpi), idx, nargout); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
384 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
385 tmp = tmp_list.length () ? tmp_list(0) : octave_value (); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
386 tmpi = i; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
387 idx.clear (); |
18439
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
388 |
20574
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
389 if (tmp.is_cs_list ()) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
390 gripe_indexed_cs_list (); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
391 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
392 if (error_state) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
393 break; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
394 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
395 if (tmp.is_function ()) |
18439
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
396 { |
20574
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
397 octave_function *fcn = tmp.function_value (true); |
18439
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
398 |
20574
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
399 if (fcn && ! fcn->is_postfix_index_handled (type[i])) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
400 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
401 octave_value_list empty_args; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
402 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
403 tmp_list = tmp.do_multi_index_op (1, empty_args); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
404 tmp = (tmp_list.length () |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
405 ? tmp_list(0) : octave_value ()); |
18439
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
406 |
20574
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
407 if (tmp.is_cs_list ()) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
408 gripe_indexed_cs_list (); |
18439
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
409 |
20574
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
410 if (error_state) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
411 break; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
412 } |
18439
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
413 } |
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
414 } |
20574
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
415 catch (index_exception& e) // problems with index range, type etc. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
416 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
417 final_index_error (e, expr); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
418 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
419 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
420 } |
4432 | 421 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
422 switch (type[i]) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
423 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
424 case '(': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
425 if (have_args) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
426 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
427 idx.push_back (first_args); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
428 have_args = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
429 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
430 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
431 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
|
432 break; |
3930 | 433 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
434 case '{': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
435 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
|
436 break; |
2980 | 437 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
438 case '.': |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
439 idx.push_back (octave_value (get_struct_index (p_arg_nm, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
440 p_dyn_field))); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
441 break; |
3930 | 442 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
443 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
444 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
445 } |
3930 | 446 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
447 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
448 break; |
3933 | 449 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
450 p_args++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
451 p_arg_nm++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
452 p_dyn_field++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
453 } |
3933 | 454 |
455 if (! error_state) | |
18439
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
456 { |
20574
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
457 try |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
458 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
459 retval = tmp.subsref (type.substr (tmpi, n - tmpi), idx, nargout, |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
460 lvalue_list); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
461 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
462 catch (index_exception& e) // problems with range, invalid index type etc. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
463 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
464 final_index_error (e, expr); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
465 } |
18439
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
466 |
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
467 octave_value val = retval.length () ? retval(0) : octave_value (); |
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
468 |
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
469 if (! error_state && val.is_function ()) |
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
470 { |
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
471 octave_function *fcn = val.function_value (true); |
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
472 |
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
473 if (fcn) |
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
474 { |
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
475 octave_value_list empty_args; |
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
476 |
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
477 retval = (lvalue_list |
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
478 ? val.do_multi_index_op (nargout, empty_args, |
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
479 lvalue_list) |
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
480 : val.do_multi_index_op (nargout, empty_args)); |
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
481 } |
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
482 } |
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
483 } |
2980 | 484 } |
485 | |
486 return retval; | |
487 } | |
488 | |
489 octave_value | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8580
diff
changeset
|
490 tree_index_expression::rvalue1 (int nargout) |
2980 | 491 { |
492 octave_value retval; | |
493 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8580
diff
changeset
|
494 const octave_value_list tmp = rvalue (nargout); |
2980 | 495 |
496 if (! tmp.empty ()) | |
497 retval = tmp(0); | |
498 | |
499 return retval; | |
500 } | |
501 | |
502 octave_lvalue | |
503 tree_index_expression::lvalue (void) | |
504 { | |
505 octave_lvalue retval; | |
506 | |
4219 | 507 std::list<octave_value_list> idx; |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
508 std::string tmp_type; |
3933 | 509 |
4219 | 510 int n = args.size (); |
3933 | 511 |
4219 | 512 std::list<tree_argument_list *>::iterator p_args = args.begin (); |
513 std::list<string_vector>::iterator p_arg_nm = arg_nm.begin (); | |
514 std::list<tree_expression *>::iterator p_dyn_field = dyn_field.begin (); | |
3933 | 515 |
4234 | 516 retval = expr->lvalue (); |
3933 | 517 |
2980 | 518 if (! error_state) |
519 { | |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15614
diff
changeset
|
520 octave_value tmp = retval.value (); |
4432 | 521 |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
522 octave_idx_type tmpi = 0; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
523 std::list<octave_value_list> tmpidx; |
4234 | 524 |
525 for (int i = 0; i < n; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
526 { |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
527 if (retval.numel () != 1) |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
528 gripe_indexed_cs_list (); |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
529 else if (tmpi < i) |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
530 { |
20574
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
531 try |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
532 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
533 tmp = tmp.subsref (type.substr (tmpi, i-tmpi), tmpidx, true); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
534 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
535 catch (index_exception& e) // problems with range, invalid type etc. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
536 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
537 final_index_error (e, expr); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
538 } |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
539 tmpidx.clear (); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
540 } |
4432 | 541 |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
542 if (error_state) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
543 break; |
4432 | 544 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
545 switch (type[i]) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
546 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
547 case '(': |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
548 { |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
549 octave_value_list tidx |
14343
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
550 = 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
|
551 |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
552 idx.push_back (tidx); |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
553 |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
554 if (i < n - 1) |
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 if (type[i+1] == '.') |
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 tmpidx.push_back (tidx); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
559 tmpi = i+1; |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
560 } |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
561 else |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
562 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
|
563 } |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
564 } |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
565 break; |
4234 | 566 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
567 case '{': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
568 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
569 octave_value_list tidx |
14343
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
570 = make_value_list (*p_args, *p_arg_nm, &tmp, false); |
5846 | 571 |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
572 if (tmp.is_undefined ()) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
573 { |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
574 if (tidx.has_magic_colon ()) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
575 gripe_invalid_inquiry_subscript (); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
576 else |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
577 tmp = Cell (); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
578 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
579 else if (tmp.is_zero_by_zero () |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
580 && (tmp.is_matrix_type () || tmp.is_string ())) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
581 { |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
582 tmp = Cell (); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
583 } |
5846 | 584 |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
585 retval.numel (tmp.numel (tidx)); |
5846 | 586 |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
587 if (error_state) |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
588 break; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
589 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
590 idx.push_back (tidx); |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
591 tmpidx.push_back (tidx); |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
592 tmpi = i; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
593 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
594 break; |
4234 | 595 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
596 case '.': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
597 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
598 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
|
599 if (error_state) |
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
600 break; |
6833 | 601 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
602 bool autoconv = (tmp.is_zero_by_zero () |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
603 && (tmp.is_matrix_type () || tmp.is_string () |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
604 || tmp.is_cell ())); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
605 |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
14429
diff
changeset
|
606 if (i > 0 && type[i-1] == '(') |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
607 { |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
608 octave_value_list pidx = idx.back (); |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
609 |
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
|
610 // 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
|
611 // dimensions are 0x0, not 1x1. |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
612 if (tmp.is_undefined ()) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
613 { |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
614 if (pidx.has_magic_colon ()) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
615 gripe_invalid_inquiry_subscript (); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
616 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
|
617 tmp = octave_map (); |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
618 } |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
619 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
|
620 tmp = octave_map (); |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
621 |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
622 retval.numel (tmp.numel (pidx)); |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
623 |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
624 tmpi = i-1; |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
625 tmpidx.push_back (tidx); |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
626 } |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
627 else |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
628 { |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
629 if (tmp.is_undefined () || autoconv) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
630 { |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
631 tmpi = i+1; |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
632 tmp = octave_value (); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
633 } |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
634 else |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
635 { |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
636 retval.numel (tmp.numel (octave_value_list ())); |
7099 | 637 |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
638 tmpi = i; |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
639 tmpidx.push_back (tidx); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
640 } |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
641 } |
7057 | 642 |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
643 if (error_state) |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
644 break; |
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
645 |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
646 idx.push_back (tidx); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
647 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
648 break; |
4234 | 649 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
650 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
651 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
652 } |
4234 | 653 |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
654 if (idx.back ().empty ()) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
655 error ("invalid empty index list"); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
656 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
657 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
658 break; |
4234 | 659 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
660 p_args++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
661 p_arg_nm++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
662 p_dyn_field++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
663 } |
3930 | 664 |
3933 | 665 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
666 retval.set_index (type, idx); |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
667 |
2980 | 668 } |
669 | |
670 return retval; | |
671 } | |
672 | |
7099 | 673 /* |
674 %!test | |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14343
diff
changeset
|
675 %! clear x; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14343
diff
changeset
|
676 %! clear y; |
14343
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
677 %! y = 3; |
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
678 %! x(y(end)) = 1; |
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
679 %! 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
|
680 %! clear x; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14343
diff
changeset
|
681 %! clear y; |
14343
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
682 %! y = {3}; |
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
683 %! x(y{end}) = 1; |
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
684 %! assert (x, [0, 0, 1]); |
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
685 |
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
686 %!test |
7099 | 687 %! x = {1, 2, 3}; |
688 %! [x{:}] = deal (4, 5, 6); | |
689 %! assert (x, {4, 5, 6}); | |
690 | |
691 %!test | |
692 %! [x.a, x.b.c] = deal (1, 2); | |
693 %! assert (x.a == 1 && x.b.c == 2); | |
694 | |
695 %!test | |
696 %! [x.a, x(2).b] = deal (1, 2); | |
697 %! assert (x(1).a == 1 && isempty (x(2).a) && isempty (x(1).b) && x(2).b == 2); | |
698 | |
699 %!test | |
700 %! x = struct (zeros (0, 1), {"a", "b"}); | |
701 %! x(2).b = 1; | |
702 %! assert (x(2).b == 1); | |
703 | |
704 %!test | |
705 %! x = struct (zeros (0, 1), {"a", "b"}); | |
706 %! x(2).b = 1; | |
707 %! assert (x(2).b == 1); | |
708 */ | |
709 | |
5861 | 710 tree_index_expression * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
711 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
|
712 symbol_table::context_id context) const |
5861 | 713 { |
714 tree_index_expression *new_idx_expr | |
715 = new tree_index_expression (line (), column ()); | |
716 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
717 new_idx_expr->expr = expr ? expr->dup (scope, context) : 0; |
5861 | 718 |
719 std::list<tree_argument_list *> new_args; | |
720 | |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
721 for (std::list<tree_argument_list *>::const_iterator p = args.begin (); |
5861 | 722 p != args.end (); |
723 p++) | |
724 { | |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
725 const tree_argument_list *elt = *p; |
5861 | 726 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
727 new_args.push_back (elt ? elt->dup (scope, context) : 0); |
5861 | 728 } |
729 | |
730 new_idx_expr->args = new_args; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
731 |
5861 | 732 new_idx_expr->type = type; |
733 | |
734 new_idx_expr->arg_nm = arg_nm; | |
735 | |
736 std::list<tree_expression *> new_dyn_field; | |
737 | |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
738 for (std::list<tree_expression *>::const_iterator p = dyn_field.begin (); |
5861 | 739 p != dyn_field.end (); |
740 p++) | |
741 { | |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
742 const tree_expression *elt = *p; |
5861 | 743 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
744 new_dyn_field.push_back (elt ? elt->dup (scope, context) : 0); |
5861 | 745 } |
746 | |
747 new_idx_expr->dyn_field = new_dyn_field; | |
748 | |
749 new_idx_expr->copy_base (*this); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
750 |
5861 | 751 return new_idx_expr; |
752 } | |
753 | |
2980 | 754 void |
755 tree_index_expression::accept (tree_walker& tw) | |
756 { | |
757 tw.visit_index_expression (*this); | |
758 } |