annotate libinterp/parse-tree/oct-lvalue.cc @ 28804:3719f5d452d4 stable

refactor implementation of END indexing in interpreter (bug #58953) * oct-lvalue.h, oct-lvalue.cc (octave_lvalue::eval_for_numel): New function. (octave_lvalue::m_nel): Delete data member. (octave_lvalue::numel (octave_idx_type)): Delete. (octave_lvalue::numel (void) const): Compute result instead of returning cached value. * pt-eval.h, pt-eval.cc (tree_evaluator::convert_to_const_vector): Simplify. (Fend): Call tree_evaluator::evaluate_end_expression to do the real work. (tree_evaluator::make_value_list): Don't check for magic_end here. (end_value, tree_evaluator::evaluate_end_expression): New functions. (tree_evaluator::m_index_list, tree_evaluator::m_index_type): New data members. (tree_evaluator::set_indexed_object, tree_evaluator::index_list, tree_evaluator::set_index_list, tree_evaluator::clear_index_list, tree_evaluator::append_index_list, tree_evaluator::index_type): New functions. * pt-idx.cc (make_value_list): Delete. (tree_index_expression::lvalue, tree_index_expression::evaluate_n): Refactor to avoid evaluating partial expressions to obtain values for the END function. Instead, cache info necessary to do that job as needed and inside the END function itself.
author John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
date Mon, 21 Sep 2020 10:45:18 -0400
parents 9a3deb17b4ea
children d5efdf5cfc56 7c9a40fb3337
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 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
3 // Copyright (C) 1996-2020 The Octave Project Developers
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"
20940
48b2ad5ee801 maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents: 20248
diff changeset
32 #include "ovl.h"
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
33 #include "oct-lvalue.h"
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
34 #include "ov.h"
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
35
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
36 namespace octave
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
37 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
38 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
39 {
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
40 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
41 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
42
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
43 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
44 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
45 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
46 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
47
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
48 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
49 {
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
50 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
51 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
52
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
53 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
54 const octave_value& rhs)
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
55 {
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
56 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
57 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
58 }
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20940
diff changeset
59
28804
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
60 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
61 {
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
62 // 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
63 // 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
64 // 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
65 // 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
66
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
67 size_t num_indices = m_idx.size ();
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
68
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
69 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
70 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
71
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
72 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
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 case '(':
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
75 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
76
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
77 case '{':
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 // 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
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 // 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
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 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
84 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
85
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
86 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
87 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
88
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
89 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
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_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
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 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
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 (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
96 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
97
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
98 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
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 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
101 && (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
102 {
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 = Cell ();
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
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
106 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
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 break;
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 case '.':
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 // 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
113 // 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
114
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
115 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
116 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
117
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
118 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
119 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
120
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
121 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
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 // 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
124 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
125
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
126 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
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 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
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 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
131 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
132 }
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
133
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
134 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
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 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
137 && (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
138 || 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
139
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
140 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
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 // 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
143 // 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
144
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
145 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
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 (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
148 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
149
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
150 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
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 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
153 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
154
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
155 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
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 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
158 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
159 else
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 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
161 }
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
162 break;
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 default:
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
165 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
166 }
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
167 }
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
168
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
169 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
170 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
171 {
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
172 if (! m_idx.empty ())
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
173 error ("invalid index expression in assignment");
3357
34d512262892 [project @ 1999-11-18 07:18:30 by jwe]
jwe
parents: 3205
diff changeset
174
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
175 m_type = t;
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
176 m_idx = i;
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
177 }
20248
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
178
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
179 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
180 {
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
181 bool retval = false;
20248
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
182
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
183 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
184 {
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
185 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
186
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
187 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
188 }
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
189
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
190 return retval;
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
191 }
20248
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
192
28193
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
193 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
194 {
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
195 bool retval = false;
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 if (m_idx.size () == 1)
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 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
200
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
201 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
202 }
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
203
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
204 return retval;
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
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
207 void octave_lvalue::do_unary_op (octave_value::unary_op op)
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
208 {
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
209 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
210 m_frame->do_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
211 }
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
212
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
213 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
214 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
215 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
216 ? 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
217 }
28804
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
218
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
219 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
220 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
221 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
222 {
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
223 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
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 try
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 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
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 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
230 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
231 }
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
232 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
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 // 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
235 // 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
236 // 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
237
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
238 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
239 }
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
240
3719f5d452d4 refactor implementation of END indexing in interpreter (bug #58953)
John W. Eaton <jwe@octave.org> and Fernando Alvarruiz
parents: 28426
diff changeset
241 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
242 }
5001
6690d8cd9bee [project @ 2004-09-16 00:31:42 by jwe]
jwe
parents: 4219
diff changeset
243 }