annotate libinterp/parse-tree/pt-assign.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 011a364b4d78
children b10432a40432
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
1 /*
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
2
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
3 Copyright (C) 1996-2015 John W. Eaton
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
4
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
6
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6483
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6483
diff changeset
10 option) any later version.
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
11
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
15 for more details.
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
16
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6483
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6483
diff changeset
19 <http://www.gnu.org/licenses/>.
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
20
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
21 */
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
22
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
24 #include <config.h>
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
25 #endif
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
26
3503
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3448
diff changeset
27 #include <iostream>
6253
f1676652d808 [project @ 2007-01-24 20:43:36 by jwe]
jwe
parents: 5861
diff changeset
28 #include <set>
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
29
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
30 #include "defun.h"
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
31 #include "error.h"
10030
83bb2a78c07d improve simple assignments error checks and messages
Jaroslav Hajek <highegg@gmail.com>
parents: 9782
diff changeset
32 #include "gripes.h"
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
33 #include "input.h"
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
34 #include "oct-obj.h"
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
35 #include "oct-lvalue.h"
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
36 #include "pager.h"
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
37 #include "ov.h"
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents: 2980
diff changeset
38 #include "pt-arg-list.h"
3770
bf6116ca10eb [project @ 2001-02-02 02:21:40 by jwe]
jwe
parents: 3536
diff changeset
39 #include "pt-bp.h"
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
40 #include "pt-assign.h"
15606
fb9dffe5fbfb The silent_functions flag no longer modifies the parse tree
Max Brister <max@2bass.com>
parents: 15195
diff changeset
41 #include "pt-eval.h"
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
42 #include "pt-walk.h"
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
43 #include "utils.h"
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
44 #include "variables.h"
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
45
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
46 // Simple assignment expressions.
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
47
6253
f1676652d808 [project @ 2007-01-24 20:43:36 by jwe]
jwe
parents: 5861
diff changeset
48 tree_simple_assignment::tree_simple_assignment
f1676652d808 [project @ 2007-01-24 20:43:36 by jwe]
jwe
parents: 5861
diff changeset
49 (tree_expression *le, tree_expression *re,
f1676652d808 [project @ 2007-01-24 20:43:36 by jwe]
jwe
parents: 5861
diff changeset
50 bool plhs, int l, int c, octave_value::assign_op t)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
51 : tree_expression (l, c), lhs (le), rhs (re), preserve (plhs), etype (t)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
52 { }
6253
f1676652d808 [project @ 2007-01-24 20:43:36 by jwe]
jwe
parents: 5861
diff changeset
53
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
54 tree_simple_assignment::~tree_simple_assignment (void)
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
55 {
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
56 if (! preserve)
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
57 delete lhs;
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
58
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
59 delete rhs;
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
60 }
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
61
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
62 octave_value_list
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
63 tree_simple_assignment::rvalue (int nargout)
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
64 {
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
65 octave_value_list retval;
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
66
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
67 if (nargout > 1)
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
68 error ("invalid number of output arguments for expression X = RHS");
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
69 else
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8580
diff changeset
70 retval = rvalue1 (nargout);
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
71
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
72 return retval;
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
73 }
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
74
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
75 octave_value
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8580
diff changeset
76 tree_simple_assignment::rvalue1 (int)
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
77 {
3208
e8a7163701be [project @ 1998-11-03 05:12:47 by jwe]
jwe
parents: 2991
diff changeset
78 octave_value retval;
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
79
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
80 if (error_state)
3208
e8a7163701be [project @ 1998-11-03 05:12:47 by jwe]
jwe
parents: 2991
diff changeset
81 return retval;
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
82
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
83 if (rhs)
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
84 {
8905
24dd61b36591 assign rvalue1 result to octave_value object, not octave_value_list object
John W. Eaton <jwe@octave.org>
parents: 8658
diff changeset
85 octave_value rhs_val = rhs->rvalue1 ();
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
86
8905
24dd61b36591 assign rvalue1 result to octave_value object, not octave_value_list object
John W. Eaton <jwe@octave.org>
parents: 8658
diff changeset
87 if (! error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
88 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
89 if (rhs_val.is_undefined ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
90 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
91 error ("value on right hand side of assignment is undefined");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
92 return retval;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
93 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
94 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
95 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
96 if (rhs_val.is_cs_list ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
97 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
98 const octave_value_list lst = rhs_val.list_value ();
7389
4d0d6c357bc6 [project @ 2008-01-16 08:32:13 by jwe]
jwe
parents: 7336
diff changeset
99
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
100 if (! lst.empty ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
101 rhs_val = lst(0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
102 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
103 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
104 error ("invalid number of elements on RHS of assignment");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
105 return retval;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
106 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
107 }
7389
4d0d6c357bc6 [project @ 2008-01-16 08:32:13 by jwe]
jwe
parents: 7336
diff changeset
108
20574
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20283
diff changeset
109 try
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20283
diff changeset
110 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20283
diff changeset
111 octave_lvalue ult = lhs->lvalue ();
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
112
20574
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20283
diff changeset
113 if (ult.numel () != 1)
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20283
diff changeset
114 gripe_nonbraced_cs_list_assignment ();
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
115
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
116 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
117 {
20574
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20283
diff changeset
118 ult.assign (etype, rhs_val);
2984
84c33881d0bc [project @ 1997-05-16 05:14:33 by jwe]
jwe
parents: 2982
diff changeset
119
20574
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20283
diff changeset
120 if (! error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
121 {
20574
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20283
diff changeset
122 if (etype == octave_value::op_asn_eq)
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20283
diff changeset
123 retval = rhs_val;
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20283
diff changeset
124 else
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20283
diff changeset
125 retval = ult.value ();
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
126
20574
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20283
diff changeset
127 if (print_result ()
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20283
diff changeset
128 && tree_evaluator::statement_printing_enabled ())
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20283
diff changeset
129 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20283
diff changeset
130 // We clear any index here so that we can
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20283
diff changeset
131 // get the new value of the referenced
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20283
diff changeset
132 // object below, instead of the indexed
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20283
diff changeset
133 // value (which should be the same as the
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20283
diff changeset
134 // right hand side value).
3208
e8a7163701be [project @ 1998-11-03 05:12:47 by jwe]
jwe
parents: 2991
diff changeset
135
20574
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20283
diff changeset
136 ult.clear_index ();
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20283
diff changeset
137
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20283
diff changeset
138 octave_value lhs_val = ult.value ();
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20283
diff changeset
139
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20283
diff changeset
140 if (! error_state)
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20283
diff changeset
141 lhs_val.print_with_name (octave_stdout,
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20283
diff changeset
142 lhs->name ());
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20283
diff changeset
143 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
144 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
145 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
146 }
20574
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20283
diff changeset
147 catch (index_exception& e)
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20283
diff changeset
148 { // problems with range, invalid index type etc.
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20283
diff changeset
149 e.set_var (lhs->name ());
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20283
diff changeset
150 (*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: 20283
diff changeset
151 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
152 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
153 }
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
154 }
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
155
3208
e8a7163701be [project @ 1998-11-03 05:12:47 by jwe]
jwe
parents: 2991
diff changeset
156 return retval;
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
157 }
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
158
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3534
diff changeset
159 std::string
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
160 tree_simple_assignment::oper (void) const
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
161 {
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
162 return octave_value::assign_op_as_string (etype);
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
163 }
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
164
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5846
diff changeset
165 tree_expression *
7767
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7389
diff changeset
166 tree_simple_assignment::dup (symbol_table::scope_id scope,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
167 symbol_table::context_id context) const
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5846
diff changeset
168 {
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5846
diff changeset
169 tree_simple_assignment *new_sa
7767
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7389
diff changeset
170 = new tree_simple_assignment (lhs ? lhs->dup (scope, context) : 0,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
171 rhs ? rhs->dup (scope, context) : 0,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
172 preserve, etype);
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5846
diff changeset
173
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5846
diff changeset
174 new_sa->copy_base (*this);
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5846
diff changeset
175
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5846
diff changeset
176 return new_sa;
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5846
diff changeset
177 }
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5846
diff changeset
178
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
179 void
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
180 tree_simple_assignment::accept (tree_walker& tw)
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
181 {
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
182 tw.visit_simple_assignment (*this);
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
183 }
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
184
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
185 // Multi-valued assignment expressions.
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
186
6253
f1676652d808 [project @ 2007-01-24 20:43:36 by jwe]
jwe
parents: 5861
diff changeset
187 tree_multi_assignment::tree_multi_assignment
f1676652d808 [project @ 2007-01-24 20:43:36 by jwe]
jwe
parents: 5861
diff changeset
188 (tree_argument_list *lst, tree_expression *r,
10230
0a5a769b8fc0 disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10227
diff changeset
189 bool plhs, int l, int c)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
190 : tree_expression (l, c), lhs (lst), rhs (r), preserve (plhs)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
191 { }
6253
f1676652d808 [project @ 2007-01-24 20:43:36 by jwe]
jwe
parents: 5861
diff changeset
192
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
193 tree_multi_assignment::~tree_multi_assignment (void)
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
194 {
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
195 if (! preserve)
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
196 delete lhs;
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
197
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
198 delete rhs;
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
199 }
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
200
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
201 octave_value
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8580
diff changeset
202 tree_multi_assignment::rvalue1 (int nargout)
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
203 {
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
204 octave_value retval;
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
205
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8580
diff changeset
206 const octave_value_list tmp = rvalue (nargout);
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
207
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
208 if (! tmp.empty ())
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
209 retval = tmp(0);
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
210
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
211 return retval;
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
212 }
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
213
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
214 // FIXME: this works, but it would look a little better if
2984
84c33881d0bc [project @ 1997-05-16 05:14:33 by jwe]
jwe
parents: 2982
diff changeset
215 // it were broken up into a couple of separate functions.
84c33881d0bc [project @ 1997-05-16 05:14:33 by jwe]
jwe
parents: 2982
diff changeset
216
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
217 octave_value_list
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
218 tree_multi_assignment::rvalue (int)
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
219 {
3208
e8a7163701be [project @ 1998-11-03 05:12:47 by jwe]
jwe
parents: 2991
diff changeset
220 octave_value_list retval;
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
221
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
222 if (error_state)
3208
e8a7163701be [project @ 1998-11-03 05:12:47 by jwe]
jwe
parents: 2991
diff changeset
223 return retval;
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
224
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
225 if (rhs)
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
226 {
5846
db0598f94c0f [project @ 2006-06-07 18:16:16 by jwe]
jwe
parents: 5841
diff changeset
227 std::list<octave_lvalue> lvalue_list = lhs->lvalue_list ();
3977
95663a3a2682 [project @ 2002-07-05 17:43:37 by jwe]
jwe
parents: 3965
diff changeset
228
95663a3a2682 [project @ 2002-07-05 17:43:37 by jwe]
jwe
parents: 3965
diff changeset
229 if (error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
230 return retval;
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
231
10832
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
232 octave_idx_type n_out = 0;
5846
db0598f94c0f [project @ 2006-06-07 18:16:16 by jwe]
jwe
parents: 5841
diff changeset
233
db0598f94c0f [project @ 2006-06-07 18:16:16 by jwe]
jwe
parents: 5841
diff changeset
234 for (std::list<octave_lvalue>::const_iterator p = lvalue_list.begin ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
235 p != lvalue_list.end ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
236 p++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
237 n_out += p->numel ();
5846
db0598f94c0f [project @ 2006-06-07 18:16:16 by jwe]
jwe
parents: 5841
diff changeset
238
8580
188d38a553c7 further indexing optimization touches
Jaroslav Hajek <highegg@gmail.com>
parents: 8313
diff changeset
239 // The following trick is used to keep rhs_val constant.
10832
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
240 const octave_value_list rhs_val1 = rhs->rvalue (n_out, &lvalue_list);
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
241 const octave_value_list rhs_val = (rhs_val1.length () == 1
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
242 && rhs_val1(0).is_cs_list ()
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
243 ? rhs_val1(0).list_value ()
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
244 : rhs_val1);
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
245
3977
95663a3a2682 [project @ 2002-07-05 17:43:37 by jwe]
jwe
parents: 3965
diff changeset
246 if (error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
247 return retval;
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
248
9782
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
249 octave_idx_type k = 0;
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
250
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
251 octave_idx_type n = rhs_val.length ();
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
252
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
253 // To avoid copying per elements and possible optimizations, we
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
254 // postpone joining the final values.
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
255 std::list<octave_value_list> retval_list;
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
256
9782
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
257 tree_argument_list::iterator q = lhs->begin ();
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
258
9782
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
259 for (std::list<octave_lvalue>::iterator p = lvalue_list.begin ();
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
260 p != lvalue_list.end ();
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
261 p++)
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
262 {
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
263 tree_expression *lhs_elt = *q++;
5846
db0598f94c0f [project @ 2006-06-07 18:16:16 by jwe]
jwe
parents: 5841
diff changeset
264
9782
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
265 octave_lvalue ult = *p;
5846
db0598f94c0f [project @ 2006-06-07 18:16:16 by jwe]
jwe
parents: 5841
diff changeset
266
9782
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
267 octave_idx_type nel = ult.numel ();
3977
95663a3a2682 [project @ 2002-07-05 17:43:37 by jwe]
jwe
parents: 3965
diff changeset
268
9782
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
269 if (nel != 1)
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
270 {
20283
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
271 // Huge kluge so that wrapper scripts with lines like
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
272 //
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
273 // [varargout{1:nargout}] = fcn (args);
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
274 //
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
275 // Will work the same as calling fcn directly when nargout
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
276 // is 0 and fcn produces more than one output even when
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
277 // nargout is 0. This only works if varargout has not yet
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
278 // been defined. See also bug #43813.
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
279
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
280 if (lvalue_list.size () == 1 && nel == 0 && n > 0
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
281 && ! ult.is_black_hole () && ult.is_undefined ()
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
282 && ult.index_type () == "{" && ult.index_is_empty ())
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
283 {
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
284 // Convert undefined lvalue with empty index to a cell
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
285 // array with a single value and indexed by 1 to
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
286 // handle a single output.
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
287
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
288 nel = 1;
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
289
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
290 ult.define (Cell (1, 1));
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
291
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
292 ult.clear_index ();
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
293 std::list<octave_value_list> idx;
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
294 idx.push_back (octave_value_list (octave_value (1)));
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
295 ult.set_index ("{", idx);
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
296 }
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
297
9782
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
298 if (k + nel <= n)
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
299 {
10230
0a5a769b8fc0 disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10227
diff changeset
300 // This won't do a copy.
0a5a769b8fc0 disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10227
diff changeset
301 octave_value_list ovl = rhs_val.slice (k, nel);
5846
db0598f94c0f [project @ 2006-06-07 18:16:16 by jwe]
jwe
parents: 5841
diff changeset
302
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
303 ult.assign (octave_value::op_asn_eq,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
304 octave_value (ovl, true));
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
305
10230
0a5a769b8fc0 disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10227
diff changeset
306 if (! error_state)
0a5a769b8fc0 disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10227
diff changeset
307 {
0a5a769b8fc0 disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10227
diff changeset
308 retval_list.push_back (ovl);
5846
db0598f94c0f [project @ 2006-06-07 18:16:16 by jwe]
jwe
parents: 5841
diff changeset
309
10230
0a5a769b8fc0 disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10227
diff changeset
310 k += nel;
9782
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
311 }
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
312 }
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
313 else
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
314 error ("some elements undefined in return list");
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
315 }
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
316 else
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
317 {
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
318 if (k < n)
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
319 {
10230
0a5a769b8fc0 disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10227
diff changeset
320 ult.assign (octave_value::op_asn_eq, rhs_val(k));
3977
95663a3a2682 [project @ 2002-07-05 17:43:37 by jwe]
jwe
parents: 3965
diff changeset
321
10227
d3fc22c3071c omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents: 10160
diff changeset
322 if (ult.is_black_hole ())
d3fc22c3071c omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents: 10160
diff changeset
323 {
d3fc22c3071c omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents: 10160
diff changeset
324 k++;
d3fc22c3071c omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents: 10160
diff changeset
325 continue;
d3fc22c3071c omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents: 10160
diff changeset
326 }
d3fc22c3071c omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents: 10160
diff changeset
327 else if (! error_state)
9782
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
328 {
10230
0a5a769b8fc0 disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10227
diff changeset
329 retval_list.push_back (rhs_val(k));
5846
db0598f94c0f [project @ 2006-06-07 18:16:16 by jwe]
jwe
parents: 5841
diff changeset
330
9782
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
331 k++;
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
332 }
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
333 }
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
334 else
14572
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
335 {
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
336 // This can happen for a function like
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
337 //
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
338 // function varargout = f ()
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
339 // varargout{1} = nargout;
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
340 // endfunction
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
341 //
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
342 // called with
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
343 //
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
344 // [a, ~] = f ();
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
345 //
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
346 // Then the list of of RHS values will contain one
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
347 // element but we are iterating over the list of all
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
348 // RHS values. We shouldn't complain that a value we
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
349 // don't need is missing from the list.
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
350
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
351 if (ult.is_black_hole ())
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
352 {
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
353 k++;
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
354 continue;
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
355 }
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
356 else
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
357 error ("element number %d undefined in return list", k+1);
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
358 }
9782
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
359 }
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
360
9782
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
361 if (error_state)
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
362 break;
15606
fb9dffe5fbfb The silent_functions flag no longer modifies the parse tree
Max Brister <max@2bass.com>
parents: 15195
diff changeset
363 else if (print_result ()
fb9dffe5fbfb The silent_functions flag no longer modifies the parse tree
Max Brister <max@2bass.com>
parents: 15195
diff changeset
364 && tree_evaluator::statement_printing_enabled ())
9782
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
365 {
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
366 // We clear any index here so that we can get
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
367 // the new value of the referenced object below,
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
368 // instead of the indexed value (which should be
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
369 // the same as the right hand side value).
3977
95663a3a2682 [project @ 2002-07-05 17:43:37 by jwe]
jwe
parents: 3965
diff changeset
370
9782
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
371 ult.clear_index ();
3208
e8a7163701be [project @ 1998-11-03 05:12:47 by jwe]
jwe
parents: 2991
diff changeset
372
9782
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
373 octave_value lhs_val = ult.value ();
3977
95663a3a2682 [project @ 2002-07-05 17:43:37 by jwe]
jwe
parents: 3965
diff changeset
374
9782
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
375 if (! error_state)
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
376 lhs_val.print_with_name (octave_stdout,
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
377 lhs_elt->name ());
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
378 }
3977
95663a3a2682 [project @ 2002-07-05 17:43:37 by jwe]
jwe
parents: 3965
diff changeset
379
9782
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
380 if (error_state)
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
381 break;
3977
95663a3a2682 [project @ 2002-07-05 17:43:37 by jwe]
jwe
parents: 3965
diff changeset
382
9782
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
383 }
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
384
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
385 // Concatenate return values.
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
386 retval = retval_list;
eead00a7df05 don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents: 9421
diff changeset
387
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
388 }
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
389
3208
e8a7163701be [project @ 1998-11-03 05:12:47 by jwe]
jwe
parents: 2991
diff changeset
390 return retval;
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
391 }
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
392
14572
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
393 /*
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
394 %!function varargout = f ()
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
395 %! varargout{1} = nargout;
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
396 %!endfunction
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
397 %!
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
398 %!test
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
399 %! [a, ~] = f ();
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
400 %! assert (a, 2);
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
401 %!test
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
402 %! [a, ~, ~, ~, ~] = f ();
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
403 %! assert (a, 5);
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
404 */
000cd393f3c1 avoid error for calls to functions returning varargout that ignore final outputs (bug #36221)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
405
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3534
diff changeset
406 std::string
3208
e8a7163701be [project @ 1998-11-03 05:12:47 by jwe]
jwe
parents: 2991
diff changeset
407 tree_multi_assignment::oper (void) const
e8a7163701be [project @ 1998-11-03 05:12:47 by jwe]
jwe
parents: 2991
diff changeset
408 {
10230
0a5a769b8fc0 disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10227
diff changeset
409 return octave_value::assign_op_as_string (op_type ());
3208
e8a7163701be [project @ 1998-11-03 05:12:47 by jwe]
jwe
parents: 2991
diff changeset
410 }
e8a7163701be [project @ 1998-11-03 05:12:47 by jwe]
jwe
parents: 2991
diff changeset
411
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5846
diff changeset
412 tree_expression *
7767
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7389
diff changeset
413 tree_multi_assignment::dup (symbol_table::scope_id scope,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
414 symbol_table::context_id context) const
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5846
diff changeset
415 {
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5846
diff changeset
416 tree_multi_assignment *new_ma
7767
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7389
diff changeset
417 = new tree_multi_assignment (lhs ? lhs->dup (scope, context) : 0,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
418 rhs ? rhs->dup (scope, context) : 0,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
419 preserve);
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5846
diff changeset
420
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5846
diff changeset
421 new_ma->copy_base (*this);
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5846
diff changeset
422
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5846
diff changeset
423 return new_ma;
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5846
diff changeset
424 }
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5846
diff changeset
425
2980
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
426 void
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
427 tree_multi_assignment::accept (tree_walker& tw)
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
428 {
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
429 tw.visit_multi_assignment (*this);
cd5ad3fd8049 [project @ 1997-05-16 01:12:13 by jwe]
jwe
parents:
diff changeset
430 }