annotate libinterp/parse-tree/oct-lvalue.cc @ 29655:32f4357ac8d9

maint: merge stable to default.
author Markus Mützel <markus.muetzel@gmx.de>
date Wed, 12 May 2021 19:28:54 +0200
parents aef11bb4e6d1 d13d090cb03a
children 796f54d4ddbf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
29358
0a5b15007766 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29029
diff changeset
3 // Copyright (C) 1996-2021 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
25
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
26 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21200
diff changeset
27 # include "config.h"
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
28 #endif
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
29
3203
bc61b0e8d60e [project @ 1998-10-30 20:26:27 by jwe]
jwe
parents: 2984
diff changeset
30 #include "error.h"
28804
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
31 #include "errwarn.h"
29029
7c9a40fb3337 recover from exceptions when execution_exception is caught
John W. Eaton <jwe@octave.org>
parents: 28804
diff changeset
32 #include "interpreter-private.h"
7c9a40fb3337 recover from exceptions when execution_exception is caught
John W. Eaton <jwe@octave.org>
parents: 28804
diff changeset
33 #include "interpreter.h"
20940
48b2ad5ee801 maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents: 20248
diff changeset
34 #include "ovl.h"
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
35 #include "oct-lvalue.h"
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
36 #include "ov.h"
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
37
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
38 namespace octave
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
39 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
40 bool octave_lvalue::is_defined (void) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
41 {
28426
9a3deb17b4ea use shared_ptr for stack frames in call stack and for accesss and static links
John W. Eaton <jwe@octave.org>
parents: 28193
diff changeset
42 return ! is_black_hole () && m_frame->is_defined (m_sym);
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
43 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
44
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
45 bool octave_lvalue::is_undefined (void) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
46 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
47 return ! is_defined ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
48 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
49
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
50 void octave_lvalue::define (const octave_value& v)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
51 {
28426
9a3deb17b4ea use shared_ptr for stack frames in call stack and for accesss and static links
John W. Eaton <jwe@octave.org>
parents: 28193
diff changeset
52 m_frame->assign (m_sym, v);
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
53 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
54
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
55 void octave_lvalue::assign (octave_value::assign_op op,
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
56 const octave_value& rhs)
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
57 {
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
58 if (! is_black_hole ())
28426
9a3deb17b4ea use shared_ptr for stack frames in call stack and for accesss and static links
John W. Eaton <jwe@octave.org>
parents: 28193
diff changeset
59 m_frame->assign (op, m_sym, m_type, m_idx, rhs);
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
60 }
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20940
diff changeset
61
28804
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
62 octave_idx_type octave_lvalue::numel (void) const
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
63 {
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
64 // Return 1 if there is no index because without an index there
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
65 // should be no way to have a cs-list here. Cs-lists may be passed
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
66 // around internally but they are not supposed to be stored as
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
67 // single symbols in a stack frame.
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
68
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
69 std::size_t num_indices = m_idx.size ();
28804
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
70
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
71 if (num_indices == 0)
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
72 return 1;
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
73
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
74 switch (m_type[num_indices-1])
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
75 {
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
76 case '(':
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
77 return 1;
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
78
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
79 case '{':
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
80 {
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
81 // FIXME: Duplicate code in '.' case below...
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
82
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
83 // Evaluate, skipping the last index.
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
84
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
85 std::string tmp_type = m_type;
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
86 std::list<octave_value_list> tmp_idx = m_idx;
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
87
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
88 tmp_type.pop_back ();
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
89 tmp_idx.pop_back ();
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
90
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
91 octave_value tmp = eval_for_numel (tmp_type, tmp_idx);
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
92
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
93 octave_value_list tidx = m_idx.back ();
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
94
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
95 if (tmp.is_undefined ())
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
96 {
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
97 if (tidx.has_magic_colon ())
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
98 err_invalid_inquiry_subscript ();
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
99
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
100 tmp = Cell ();
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
101 }
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
102 else if (tmp.is_zero_by_zero ()
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
103 && (tmp.is_matrix_type () || tmp.is_string ()))
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
104 {
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
105 tmp = Cell ();
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
106 }
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
107
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
108 return tmp.xnumel (tidx);
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
109 }
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
110 break;
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
111
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
112 case '.':
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
113 {
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
114 // Evaluate, skipping either the last index or the last two
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
115 // indices if we are looking at "(idx).field".
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
116
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
117 std::string tmp_type = m_type;
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
118 std::list<octave_value_list> tmp_idx = m_idx;
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
119
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
120 tmp_type.pop_back ();
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
121 tmp_idx.pop_back ();
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
122
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
123 bool paren_dot = num_indices > 1 && m_type[num_indices-2] == '(';
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
124
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
125 // Index for paren operator, if any.
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
126 octave_value_list pidx;
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
127
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
128 if (paren_dot)
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
129 {
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
130 pidx = tmp_idx.back ();
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
131
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
132 tmp_type.pop_back ();
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
133 tmp_idx.pop_back ();
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
134 }
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
135
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
136 octave_value tmp = eval_for_numel (tmp_type, tmp_idx);
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
137
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
138 bool autoconv = (tmp.is_zero_by_zero ()
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
139 && (tmp.is_matrix_type () || tmp.is_string ()
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
140 || tmp.iscell ()));
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
141
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
142 if (paren_dot)
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
143 {
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
144 // Use octave_map, not octave_scalar_map so that the
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
145 // dimensions are 0x0, not 1x1.
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
146
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
147 if (tmp.is_undefined ())
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
148 {
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
149 if (pidx.has_magic_colon ())
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
150 err_invalid_inquiry_subscript ();
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
151
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
152 tmp = octave_map ();
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
153 }
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
154 else if (autoconv)
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
155 tmp = octave_map ();
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
156
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
157 return tmp.xnumel (pidx);
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
158 }
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
159 else if (tmp.is_undefined () || autoconv)
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
160 return 1;
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
161 else
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
162 return tmp.xnumel (octave_value_list ());
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
163 }
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
164 break;
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
165
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
166 default:
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
167 panic_impossible ();
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
168 }
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
169 }
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
170
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
171 void octave_lvalue::set_index (const std::string& t,
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
172 const std::list<octave_value_list>& i)
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
173 {
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
174 if (! m_idx.empty ())
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
175 error ("invalid index expression in assignment");
3357
34d512262892 [project @ 1999-11-18 07:18:30 by jwe]
jwe
parents: 3205
diff changeset
176
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
177 m_type = t;
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
178 m_idx = i;
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
179 }
20248
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
180
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
181 bool octave_lvalue::index_is_empty (void) const
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
182 {
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
183 bool retval = false;
20248
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
184
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
185 if (m_idx.size () == 1)
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
186 {
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
187 octave_value_list tmp = m_idx.front ();
20248
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
188
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
189 retval = (tmp.length () == 1 && tmp(0).isempty ());
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
190 }
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
191
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
192 return retval;
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
193 }
20248
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
194
28193
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
195 bool octave_lvalue::index_is_colon (void) const
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
196 {
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
197 bool retval = false;
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
198
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
199 if (m_idx.size () == 1)
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
200 {
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
201 octave_value_list tmp = m_idx.front ();
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
202
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
203 retval = (tmp.length () == 1 && tmp(0).is_magic_colon ());
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
204 }
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
205
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
206 return retval;
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
207 }
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
208
28631
70cdf8de553d move non-member octave_value operator functions to octave namespace
John W. Eaton <jwe@octave.org>
parents: 28426
diff changeset
209 void octave_lvalue::unary_op (octave_value::unary_op op)
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
210 {
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
211 if (! is_black_hole ())
28631
70cdf8de553d move non-member octave_value operator functions to octave namespace
John W. Eaton <jwe@octave.org>
parents: 28426
diff changeset
212 m_frame->non_const_unary_op (op, m_sym, m_type, m_idx);
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
213 }
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
214
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
215 octave_value octave_lvalue::value (void) const
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
216 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
217 return (is_black_hole ()
28426
9a3deb17b4ea use shared_ptr for stack frames in call stack and for accesss and static links
John W. Eaton <jwe@octave.org>
parents: 28193
diff changeset
218 ? octave_value () : m_frame->value (m_sym, m_type, m_idx));
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
219 }
28804
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
220
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
221 octave_value
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
222 octave_lvalue::eval_for_numel (const std::string& type,
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
223 const std::list<octave_value_list>& idx) const
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
224 {
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
225 octave_value retval;
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
226
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
227 try
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
228 {
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
229 retval = m_frame->varval (m_sym);
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
230
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
231 if (retval.is_constant () && ! idx.empty ())
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
232 retval = retval.subsref (type, idx);
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
233 }
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
234 catch (const execution_exception&)
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
235 {
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
236 // Ignore an error and treat it as undefined. The error
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
237 // could happen because there is an index is out of range
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
238 // and we will be resizing a cell array.
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
239
29029
7c9a40fb3337 recover from exceptions when execution_exception is caught
John W. Eaton <jwe@octave.org>
parents: 28804
diff changeset
240 interpreter& interp
7c9a40fb3337 recover from exceptions when execution_exception is caught
John W. Eaton <jwe@octave.org>
parents: 28804
diff changeset
241 = __get_interpreter__ ("octave_lvalue::eval_for_numel");
7c9a40fb3337 recover from exceptions when execution_exception is caught
John W. Eaton <jwe@octave.org>
parents: 28804
diff changeset
242
7c9a40fb3337 recover from exceptions when execution_exception is caught
John W. Eaton <jwe@octave.org>
parents: 28804
diff changeset
243 interp.recover_from_exception ();
7c9a40fb3337 recover from exceptions when execution_exception is caught
John W. Eaton <jwe@octave.org>
parents: 28804
diff changeset
244
28804
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
245 retval = octave_value ();
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
246 }
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
247
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
248 return retval;
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
249 }
5001
6690d8cd9bee [project @ 2004-09-16 00:31:42 by jwe]
jwe
parents: 4219
diff changeset
250 }