Mercurial > octave
annotate libinterp/parse-tree/pt-idx.cc @ 21100:e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
* libinterp/corefcn/errwarn.h, libinterp/corefcn/errwarn.cc: New header and .cc
file with common errors and warnings for libinterp.
* libinterp/corefcn/module.mk: Add errwarn.h, errwarn.cc to build system.
* liboctave/util/lo-array-errwarn.h, liboctave/util/lo-array-errwarn.cc: New
header and .cc file with common errors and warnings for liboctave.
* liboctave/util/module.mk: Add lo-array-errwarn.h, lo-array-errwarn.cc to
build system.
* lo-array-gripes.h: #include "lo-array-errwarn.h" for access to class
index_exception. Remove const char *error_id_XXX prototypes.
* lo-array-gripes.cc: Remove const char *error_id_XXX initializations.
Remove index_exception method definitions.
* Cell.cc, __pchip_deriv__.cc, __qp__.cc, balance.cc, betainc.cc, cellfun.cc,
daspk.cc, dasrt.cc, dassl.cc, data.cc, debug.cc, defaults.cc, det.cc,
dirfns.cc, eig.cc, fft.cc, fft2.cc, fftn.cc, find.cc, gammainc.cc, gcd.cc,
getgrent.cc, getpwent.cc, graphics.in.h, help.cc, hess.cc, hex2num.cc,
input.cc, inv.cc, jit-typeinfo.cc, load-save.cc, lookup.cc, ls-hdf5.cc,
ls-mat-ascii.cc, ls-mat4.cc, ls-mat5.cc, ls-oct-binary.cc, ls-oct-text.cc,
lsode.cc, lu.cc, luinc.cc, max.cc, mgorth.cc, oct-hist.cc, oct-procbuf.cc,
oct-stream.cc, oct.h, pager.cc, pinv.cc, pr-output.cc, quad.cc, qz.cc, rand.cc,
rcond.cc, regexp.cc, schur.cc, sparse-xdiv.cc, sparse-xpow.cc, sparse.cc,
spparms.cc, sqrtm.cc, str2double.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc,
sylvester.cc, syscalls.cc, typecast.cc, utils.cc, variables.cc, xdiv.cc,
xnorm.cc, xpow.cc, __eigs__.cc, __glpk__.cc, __magick_read__.cc,
__osmesa_print__.cc, audiodevinfo.cc, audioread.cc, chol.cc, dmperm.cc,
fftw.cc, qr.cc, symbfact.cc, symrcm.cc, ov-base-diag.cc, ov-base-int.cc,
ov-base-mat.cc, ov-base-scalar.cc, ov-base-sparse.cc, ov-base.cc,
ov-bool-mat.cc, ov-bool-sparse.cc, ov-bool.cc, ov-builtin.cc, ov-cell.cc,
ov-ch-mat.cc, ov-class.cc, ov-complex.cc, ov-complex.h, ov-cs-list.cc,
ov-cx-diag.cc, ov-cx-mat.cc, ov-cx-sparse.cc, ov-fcn-handle.cc,
ov-fcn-inline.cc, ov-float.cc, ov-float.h, ov-flt-complex.cc, ov-flt-complex.h,
ov-flt-cx-diag.cc, ov-flt-cx-mat.cc, ov-flt-re-mat.cc, ov-int16.cc,
ov-int32.cc, ov-int64.cc, ov-int8.cc, ov-intx.h, ov-mex-fcn.cc, ov-perm.cc,
ov-range.cc, ov-re-mat.cc, ov-re-sparse.cc, ov-scalar.cc, ov-scalar.h,
ov-str-mat.cc, ov-struct.cc, ov-type-conv.h, ov-uint16.cc, ov-uint32.cc,
ov-uint64.cc, ov-uint8.cc, ov-usr-fcn.cc, ov.cc, op-b-b.cc, op-b-bm.cc,
op-b-sbm.cc, op-bm-b.cc, op-bm-bm.cc, op-bm-sbm.cc, op-cdm-cdm.cc, op-cell.cc,
op-chm.cc, op-class.cc, op-cm-cm.cc, op-cm-cs.cc, op-cm-m.cc, op-cm-s.cc,
op-cm-scm.cc, op-cm-sm.cc, op-cs-cm.cc, op-cs-cs.cc, op-cs-m.cc, op-cs-s.cc,
op-cs-scm.cc, op-cs-sm.cc, op-dm-dm.cc, op-dm-scm.cc, op-dm-sm.cc,
op-dms-template.cc, op-double-conv.cc, op-fcdm-fcdm.cc, op-fcdm-fdm.cc,
op-fcm-fcm.cc, op-fcm-fcs.cc, op-fcm-fm.cc, op-fcm-fs.cc, op-fcn.cc,
op-fcs-fcm.cc, op-fcs-fcs.cc, op-fcs-fm.cc, op-fcs-fs.cc, op-fdm-fdm.cc,
op-float-conv.cc, op-fm-fcm.cc, op-fm-fcs.cc, op-fm-fm.cc, op-fm-fs.cc,
op-fs-fcm.cc, op-fs-fcs.cc, op-fs-fm.cc, op-fs-fs.cc, op-i16-i16.cc,
op-i32-i32.cc, op-i64-i64.cc, op-i8-i8.cc, op-int-concat.cc, op-int-conv.cc,
op-int.h, op-m-cm.cc, op-m-cs.cc, op-m-m.cc, op-m-s.cc, op-m-scm.cc,
op-m-sm.cc, op-pm-pm.cc, op-pm-scm.cc, op-pm-sm.cc, op-range.cc, op-s-cm.cc,
op-s-cs.cc, op-s-m.cc, op-s-s.cc, op-s-scm.cc, op-s-sm.cc, op-sbm-b.cc,
op-sbm-bm.cc, op-sbm-sbm.cc, op-scm-cm.cc, op-scm-cs.cc, op-scm-m.cc,
op-scm-s.cc, op-scm-scm.cc, op-scm-sm.cc, op-sm-cm.cc, op-sm-cs.cc, op-sm-m.cc,
op-sm-s.cc, op-sm-scm.cc, op-sm-sm.cc, op-str-m.cc, op-str-s.cc, op-str-str.cc,
op-struct.cc, op-ui16-ui16.cc, op-ui32-ui32.cc, op-ui64-ui64.cc, op-ui8-ui8.cc,
ops.h, lex.ll, pt-assign.cc, pt-eval.cc, pt-idx.cc, pt-loop.cc, pt-mat.cc,
pt-stmt.cc, Array-util.cc, Array-util.h, Array.cc, CColVector.cc,
CDiagMatrix.cc, CMatrix.cc, CNDArray.cc, CRowVector.cc, CSparse.cc,
DiagArray2.cc, MDiagArray2.cc, MSparse.cc, PermMatrix.cc, Range.cc, Sparse.cc,
dColVector.cc, dDiagMatrix.cc, dMatrix.cc, dNDArray.cc, dRowVector.cc,
dSparse.cc, fCColVector.cc, fCDiagMatrix.cc, fCMatrix.cc, fCNDArray.cc,
fCRowVector.cc, fColVector.cc, fDiagMatrix.cc, fMatrix.cc, fNDArray.cc,
fRowVector.cc, idx-vector.cc, CmplxGEPBAL.cc, dbleGEPBAL.cc, fCmplxGEPBAL.cc,
floatGEPBAL.cc, Sparse-diag-op-defs.h, Sparse-op-defs.h, Sparse-perm-op-defs.h,
mx-inlines.cc, mx-op-defs.h, oct-binmap.h:
Replace 'include "gripes.h"' with 'include "errwarn.h". Change all gripe_XXX
to err_XXX or warn_XXX or errwarn_XXX.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 18 Jan 2016 18:28:06 -0800 |
parents | c6a170510735 |
children | 3ac9f47fb04b |
rev | line source |
---|---|
2980 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19403
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" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20700
diff
changeset
|
30 #include "ovl.h" |
2980 | 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" | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20977
diff
changeset
|
41 #include "errwarn.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 | |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
160 int n = arg_values.length (); |
3933 | 161 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
162 if (n > 0) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
163 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
164 arg_values.stash_name_tags (arg_nm); |
3933 | 165 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
166 retval.resize (dim_vector (1, n)); |
3933 | 167 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
168 for (int i = 0; i < n; i++) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
169 retval(0,i) = arg_values(i); |
3933 | 170 } |
171 | |
172 return retval; | |
173 } | |
174 | |
175 static inline octave_value_list | |
4234 | 176 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
|
177 const octave_value *object, bool rvalue = true) |
3933 | 178 { |
179 octave_value_list retval; | |
180 | |
181 if (args) | |
9125
8ab1e6f63cdc
gripe on magic end query for undefined variable
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
182 { |
14343
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
183 if (rvalue && object && args->has_magic_end () && object->is_undefined ()) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20977
diff
changeset
|
184 err_invalid_inquiry_subscript (); |
9125
8ab1e6f63cdc
gripe on magic end query for undefined variable
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
185 else |
8ab1e6f63cdc
gripe on magic end query for undefined variable
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
186 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
|
187 } |
3933 | 188 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
189 octave_idx_type n = retval.length (); |
3933 | 190 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
191 if (n > 0) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
192 retval.stash_name_tags (arg_nm); |
3933 | 193 |
194 return retval; | |
195 } | |
196 | |
4131 | 197 std::string |
4219 | 198 tree_index_expression::get_struct_index |
199 (std::list<string_vector>::const_iterator p_arg_nm, | |
200 std::list<tree_expression *>::const_iterator p_dyn_field) const | |
4131 | 201 { |
4219 | 202 std::string fn = (*p_arg_nm)(0); |
4131 | 203 |
204 if (fn.empty ()) | |
205 { | |
4219 | 206 tree_expression *df = *p_dyn_field; |
4131 | 207 |
208 if (df) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
209 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
210 octave_value t = df->rvalue1 (); |
4131 | 211 |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20652
diff
changeset
|
212 fn = t.xstring_value ("dynamic structure field names must be strings"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
213 } |
4131 | 214 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
215 panic_impossible (); |
4131 | 216 } |
217 | |
218 return fn; | |
219 } | |
220 | |
11056
4bec51eb58e2
replace Octave_map->octave_map in pt-idx.h
Jaroslav Hajek <highegg@gmail.com>
parents:
10832
diff
changeset
|
221 octave_map |
3933 | 222 tree_index_expression::make_arg_struct (void) const |
223 { | |
4219 | 224 int n = args.size (); |
3933 | 225 |
7336 | 226 Cell type_field (n, 1); |
227 Cell subs_field (n, 1); | |
3933 | 228 |
4219 | 229 std::list<tree_argument_list *>::const_iterator p_args = args.begin (); |
230 std::list<string_vector>::const_iterator p_arg_nm = arg_nm.begin (); | |
231 std::list<tree_expression *>::const_iterator p_dyn_field = dyn_field.begin (); | |
3933 | 232 |
11056
4bec51eb58e2
replace Octave_map->octave_map in pt-idx.h
Jaroslav Hajek <highegg@gmail.com>
parents:
10832
diff
changeset
|
233 octave_map m; |
3933 | 234 |
235 for (int i = 0; i < n; i++) | |
236 { | |
237 switch (type[i]) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
238 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
239 case '(': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
240 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
|
241 break; |
3933 | 242 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
243 case '{': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
244 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
|
245 break; |
3933 | 246 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
247 case '.': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
248 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
|
249 break; |
3933 | 250 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
251 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
252 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
253 } |
3933 | 254 |
4219 | 255 p_args++; |
256 p_arg_nm++; | |
257 p_dyn_field++; | |
3933 | 258 } |
259 | |
7336 | 260 m.assign ("type", type_field); |
261 m.assign ("subs", subs_field); | |
3933 | 262 |
263 return m; | |
2991 | 264 } |
265 | |
2980 | 266 octave_value_list |
267 tree_index_expression::rvalue (int nargout) | |
268 { | |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10659
diff
changeset
|
269 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
|
270 } |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10659
diff
changeset
|
271 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
272 // 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:
19697
diff
changeset
|
273 // 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:
19697
diff
changeset
|
274 // 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:
19697
diff
changeset
|
275 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
276 static void |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
277 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:
19697
diff
changeset
|
278 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
279 if (expr->is_identifier () |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
280 && 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:
19697
diff
changeset
|
281 e.set_var (expr->name ()); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
282 |
20652
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
283 std::string msg = e.message (); |
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
284 error_with_id (e.err_id (), msg.c_str ()); |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
285 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
286 |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10659
diff
changeset
|
287 octave_value_list |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
288 tree_index_expression::rvalue (int nargout, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
289 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
|
290 { |
2980 | 291 octave_value_list retval; |
292 | |
7336 | 293 octave_value first_expr_val; |
294 | |
295 octave_value_list first_args; | |
296 | |
297 bool have_args = false; | |
298 | |
299 if (expr->is_identifier () && type[0] == '(') | |
300 { | |
301 tree_identifier *id = dynamic_cast<tree_identifier *> (expr); | |
302 | |
303 if (! (id->is_variable () || args.empty ())) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
304 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
305 tree_argument_list *al = *(args.begin ()); |
7336 | 306 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
307 size_t n = al ? al->length () : 0; |
7336 | 308 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
309 if (n > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
310 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
311 string_vector anm = *(arg_nm.begin ()); |
9445
c5f03874ea2a
simplify symbol_table::find and associated functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
312 have_args = true; |
c5f03874ea2a
simplify symbol_table::find and associated functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
313 first_args = al -> convert_to_const_vector (); |
c5f03874ea2a
simplify symbol_table::find and associated functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
314 first_args.stash_name_tags (anm); |
7336 | 315 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
316 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
|
317 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
318 } |
7336 | 319 } |
2980 | 320 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
321 if (first_expr_val.is_undefined ()) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
322 first_expr_val = expr->rvalue1 (); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
323 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
324 octave_value tmp = first_expr_val; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
325 octave_idx_type tmpi = 0; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
326 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
327 std::list<octave_value_list> idx; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
328 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
329 int n = args.size (); |
7336 | 330 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
331 std::list<tree_argument_list *>::iterator p_args = args.begin (); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
332 std::list<string_vector>::iterator p_arg_nm = arg_nm.begin (); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
333 std::list<tree_expression *>::iterator p_dyn_field = dyn_field.begin (); |
7336 | 334 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
335 for (int i = 0; i < n; i++) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
336 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
337 if (i > 0) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
338 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
339 tree_argument_list *al = *p_args; |
3933 | 340 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
341 // In Matlab, () can only be followed by . In Octave, we do not |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
342 // enforce this for rvalue expressions, but we'll split the |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
343 // evaluation at this point. This will, hopefully, allow Octave's |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
344 // looser rules apply smoothly for Matlab overloaded subsref |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
345 // codes. |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
346 bool force_split = type[i-1] == '(' && type[i] != '.'; |
3930 | 347 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
348 if (force_split || (al && al->has_magic_end ())) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
349 { |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
350 // (we have force_split, or) we have an expression like |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
351 // |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
352 // x{end}.a(end) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
353 // |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
354 // and we are looking at the argument list that |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
355 // contains the second (or third, etc.) "end" token, |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
356 // so we must evaluate everything up to the point of |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
357 // that argument list so we can pass the appropriate |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
358 // value to the built-in end function. |
4432 | 359 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
360 try |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
361 { |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
362 octave_value_list tmp_list |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
363 =tmp.subsref (type.substr (tmpi, i-tmpi), idx, nargout); |
4432 | 364 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
365 tmp = tmp_list.length () ? tmp_list(0) : octave_value (); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
366 tmpi = i; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
367 idx.clear (); |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
368 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
369 if (tmp.is_cs_list ()) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20977
diff
changeset
|
370 err_indexed_cs_list (); |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
371 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
372 if (tmp.is_function ()) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
373 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
374 octave_function *fcn = tmp.function_value (true); |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
375 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
376 if (fcn && ! fcn->is_postfix_index_handled (type[i])) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
377 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
378 octave_value_list empty_args; |
18439
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
379 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
380 tmp_list = tmp.do_multi_index_op (1, empty_args); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
381 tmp = (tmp_list.length () |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
382 ? 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
|
383 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
384 if (tmp.is_cs_list ()) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20977
diff
changeset
|
385 err_indexed_cs_list (); |
18439
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
386 } |
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
387 } |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
388 } |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
389 catch (index_exception& e) // problems with index range, type etc. |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
390 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
391 final_index_error (e, expr); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
392 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
393 } |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
394 } |
3930 | 395 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
396 switch (type[i]) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
397 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
398 case '(': |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
399 if (have_args) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
400 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
401 idx.push_back (first_args); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
402 have_args = false; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
403 } |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
404 else |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
405 idx.push_back (make_value_list (*p_args, *p_arg_nm, &tmp)); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
406 break; |
3930 | 407 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
408 case '{': |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
409 idx.push_back (make_value_list (*p_args, *p_arg_nm, &tmp)); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
410 break; |
3930 | 411 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
412 case '.': |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
413 idx.push_back (octave_value (get_struct_index (p_arg_nm, |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
414 p_dyn_field))); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
415 break; |
3933 | 416 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
417 default: |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
418 panic_impossible (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
419 } |
3933 | 420 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
421 p_args++; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
422 p_arg_nm++; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
423 p_dyn_field++; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
424 } |
18439
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
425 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
426 try |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
427 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
428 retval = tmp.subsref (type.substr (tmpi, n - tmpi), idx, nargout, |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
429 lvalue_list); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
430 } |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
431 catch (index_exception& e) // problems with range, invalid index type etc. |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
432 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
433 final_index_error (e, expr); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
434 } |
18439
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
435 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
436 octave_value val = retval.length () ? retval(0) : octave_value (); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
437 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
438 if (val.is_function ()) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
439 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
440 octave_function *fcn = val.function_value (true); |
18439
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
441 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
442 if (fcn) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
443 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
444 octave_value_list empty_args; |
18439
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
445 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
446 retval = (lvalue_list |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
447 ? val.do_multi_index_op (nargout, empty_args, |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
448 lvalue_list) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
449 : val.do_multi_index_op (nargout, empty_args)); |
18439
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
450 } |
2980 | 451 } |
452 | |
453 return retval; | |
454 } | |
455 | |
456 octave_value | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8580
diff
changeset
|
457 tree_index_expression::rvalue1 (int nargout) |
2980 | 458 { |
459 octave_value retval; | |
460 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8580
diff
changeset
|
461 const octave_value_list tmp = rvalue (nargout); |
2980 | 462 |
463 if (! tmp.empty ()) | |
464 retval = tmp(0); | |
465 | |
466 return retval; | |
467 } | |
468 | |
469 octave_lvalue | |
470 tree_index_expression::lvalue (void) | |
471 { | |
472 octave_lvalue retval; | |
473 | |
4219 | 474 std::list<octave_value_list> idx; |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
475 std::string tmp_type; |
3933 | 476 |
4219 | 477 int n = args.size (); |
3933 | 478 |
4219 | 479 std::list<tree_argument_list *>::iterator p_args = args.begin (); |
480 std::list<string_vector>::iterator p_arg_nm = arg_nm.begin (); | |
481 std::list<tree_expression *>::iterator p_dyn_field = dyn_field.begin (); | |
3933 | 482 |
4234 | 483 retval = expr->lvalue (); |
3933 | 484 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
485 octave_value tmp = retval.value (); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
486 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
487 octave_idx_type tmpi = 0; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
488 std::list<octave_value_list> tmpidx; |
4432 | 489 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
490 for (int i = 0; i < n; i++) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
491 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
492 if (retval.numel () != 1) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20977
diff
changeset
|
493 err_indexed_cs_list (); |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
494 else if (tmpi < i) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
495 { |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
496 try |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
497 { |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
498 tmp = tmp.subsref (type.substr (tmpi, i-tmpi), tmpidx, true); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
499 } |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
500 catch (index_exception& e) // problems with range, invalid type etc. |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
501 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
502 final_index_error (e, expr); |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
503 } |
20977
c6a170510735
maint: pt-idx.cc, pt-assign.cc: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
504 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
505 tmpidx.clear (); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
506 } |
4432 | 507 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
508 switch (type[i]) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
509 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
510 case '(': |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
511 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
512 octave_value_list tidx |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
513 = make_value_list (*p_args, *p_arg_nm, &tmp, false); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
514 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
515 idx.push_back (tidx); |
4432 | 516 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
517 if (i < n - 1) |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
518 { |
20977
c6a170510735
maint: pt-idx.cc, pt-assign.cc: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
519 if (type[i+1] != '.') |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
520 error ("() must be followed by . or close the index chain"); |
20977
c6a170510735
maint: pt-idx.cc, pt-assign.cc: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
521 |
c6a170510735
maint: pt-idx.cc, pt-assign.cc: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
522 tmpidx.push_back (tidx); |
c6a170510735
maint: pt-idx.cc, pt-assign.cc: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
523 tmpi = i+1; |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
524 } |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
525 } |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
526 break; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
527 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
528 case '{': |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
529 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
530 octave_value_list tidx |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
531 = make_value_list (*p_args, *p_arg_nm, &tmp, false); |
4234 | 532 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
533 if (tmp.is_undefined ()) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
534 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
535 if (tidx.has_magic_colon ()) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20977
diff
changeset
|
536 err_invalid_inquiry_subscript (); |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
537 else |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
538 tmp = Cell (); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
539 } |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
540 else if (tmp.is_zero_by_zero () |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
541 && (tmp.is_matrix_type () || tmp.is_string ())) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
542 { |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
543 tmp = Cell (); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
544 } |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
545 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
546 retval.numel (tmp.numel (tidx)); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
547 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
548 idx.push_back (tidx); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
549 tmpidx.push_back (tidx); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
550 tmpi = i; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
551 } |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
552 break; |
5846 | 553 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
554 case '.': |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
555 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
556 octave_value tidx = get_struct_index (p_arg_nm, p_dyn_field); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
557 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
558 bool autoconv = (tmp.is_zero_by_zero () |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
559 && (tmp.is_matrix_type () || tmp.is_string () |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
560 || tmp.is_cell ())); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
561 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
562 if (i > 0 && type[i-1] == '(') |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
563 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
564 octave_value_list pidx = idx.back (); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
565 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
566 // Use octave_map, not octave_scalar_map so that the |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
567 // dimensions are 0x0, not 1x1. |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
568 if (tmp.is_undefined ()) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
569 { |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
570 if (pidx.has_magic_colon ()) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20977
diff
changeset
|
571 err_invalid_inquiry_subscript (); |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
572 else |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
573 tmp = octave_map (); |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9125
diff
changeset
|
574 } |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
575 else if (autoconv) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
576 tmp = octave_map (); |
5846 | 577 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
578 retval.numel (tmp.numel (pidx)); |
6833 | 579 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
580 tmpi = i-1; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
581 tmpidx.push_back (tidx); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
582 } |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
583 else |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
584 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
585 if (tmp.is_undefined () || autoconv) |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
586 { |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
587 tmpi = i+1; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
588 tmp = octave_value (); |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
589 } |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
590 else |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
591 { |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
592 retval.numel (tmp.numel (octave_value_list ())); |
7099 | 593 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
594 tmpi = i; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
595 tmpidx.push_back (tidx); |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
596 } |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
597 } |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
598 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
599 idx.push_back (tidx); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
600 } |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
601 break; |
4234 | 602 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
603 default: |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
604 panic_impossible (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
605 } |
3930 | 606 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
607 if (idx.back ().empty ()) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
608 error ("invalid empty index list"); |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
609 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
610 p_args++; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
611 p_arg_nm++; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
612 p_dyn_field++; |
2980 | 613 } |
614 | |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
615 retval.set_index (type, idx); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
616 |
2980 | 617 return retval; |
618 } | |
619 | |
7099 | 620 /* |
621 %!test | |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14343
diff
changeset
|
622 %! clear x; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14343
diff
changeset
|
623 %! clear y; |
14343
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
624 %! y = 3; |
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
625 %! x(y(end)) = 1; |
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
626 %! 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
|
627 %! clear x; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14343
diff
changeset
|
628 %! clear y; |
14343
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
629 %! y = {3}; |
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
630 %! x(y{end}) = 1; |
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
631 %! assert (x, [0, 0, 1]); |
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
632 |
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
633 %!test |
7099 | 634 %! x = {1, 2, 3}; |
635 %! [x{:}] = deal (4, 5, 6); | |
636 %! assert (x, {4, 5, 6}); | |
637 | |
638 %!test | |
639 %! [x.a, x.b.c] = deal (1, 2); | |
640 %! assert (x.a == 1 && x.b.c == 2); | |
641 | |
642 %!test | |
643 %! [x.a, x(2).b] = deal (1, 2); | |
644 %! assert (x(1).a == 1 && isempty (x(2).a) && isempty (x(1).b) && x(2).b == 2); | |
645 | |
646 %!test | |
647 %! x = struct (zeros (0, 1), {"a", "b"}); | |
648 %! x(2).b = 1; | |
649 %! assert (x(2).b == 1); | |
650 | |
651 %!test | |
652 %! x = struct (zeros (0, 1), {"a", "b"}); | |
653 %! x(2).b = 1; | |
654 %! assert (x(2).b == 1); | |
655 */ | |
656 | |
5861 | 657 tree_index_expression * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
658 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
|
659 symbol_table::context_id context) const |
5861 | 660 { |
661 tree_index_expression *new_idx_expr | |
662 = new tree_index_expression (line (), column ()); | |
663 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
664 new_idx_expr->expr = expr ? expr->dup (scope, context) : 0; |
5861 | 665 |
666 std::list<tree_argument_list *> new_args; | |
667 | |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
668 for (std::list<tree_argument_list *>::const_iterator p = args.begin (); |
5861 | 669 p != args.end (); |
670 p++) | |
671 { | |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
672 const tree_argument_list *elt = *p; |
5861 | 673 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
674 new_args.push_back (elt ? elt->dup (scope, context) : 0); |
5861 | 675 } |
676 | |
677 new_idx_expr->args = new_args; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
678 |
5861 | 679 new_idx_expr->type = type; |
680 | |
681 new_idx_expr->arg_nm = arg_nm; | |
682 | |
683 std::list<tree_expression *> new_dyn_field; | |
684 | |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
685 for (std::list<tree_expression *>::const_iterator p = dyn_field.begin (); |
5861 | 686 p != dyn_field.end (); |
687 p++) | |
688 { | |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
689 const tree_expression *elt = *p; |
5861 | 690 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
691 new_dyn_field.push_back (elt ? elt->dup (scope, context) : 0); |
5861 | 692 } |
693 | |
694 new_idx_expr->dyn_field = new_dyn_field; | |
695 | |
696 new_idx_expr->copy_base (*this); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
697 |
5861 | 698 return new_idx_expr; |
699 } | |
700 | |
2980 | 701 void |
702 tree_index_expression::accept (tree_walker& tw) | |
703 { | |
704 tw.visit_index_expression (*this); | |
705 } |