Mercurial > octave
annotate libinterp/parse-tree/pt-idx.cc @ 28726:0a4dcea2987a stable
stash (shallow) copy of indexed object instead of pointer
* pt-eval.h, pt-eval.cc (tree_evaluator::m_indexed_object): Now
"octave_value" instead of "const octave_value *". Change all uses.
(tree_evaluator::indexed_object): Return octave_value instead of
"const octave_value *". Change all uses.
(tree_evaluator::convert_to_const_vector,
tree_evaluator::make_value_list): Pass reference to indexed object
instead of pointer. Change all uses.
* pt-idx.cc (make_value_list): Pass reference to indexed object
instead of pointer. Change all uses.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 12 Sep 2020 14:52:03 -0400 |
parents | af302efce502 |
children | 3719f5d452d4 |
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 //////////////////////////////////////////////////////////////////////// |
2980 | 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" |
2980 | 28 #endif |
29 | |
3933 | 30 #include "Cell.h" |
2980 | 31 #include "error.h" |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23576
diff
changeset
|
32 #include "interpreter-private.h" |
3930 | 33 #include "oct-map.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20700
diff
changeset
|
34 #include "ovl.h" |
2980 | 35 #include "oct-lvalue.h" |
36 #include "ov.h" | |
2982 | 37 #include "pt-arg-list.h" |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23396
diff
changeset
|
38 #include "pt-eval.h" |
7336 | 39 #include "pt-id.h" |
2980 | 40 #include "pt-idx.h" |
3930 | 41 #include "utils.h" |
42 #include "variables.h" | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20977
diff
changeset
|
43 #include "errwarn.h" |
2980 | 44 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
45 namespace octave |
3933 | 46 { |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
47 // Index expressions. |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
48 |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
49 tree_index_expression::tree_index_expression (int l, int c) |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
50 : tree_expression (l, c), m_expr (nullptr), m_args (0), m_type (), |
26662
05fc703b419a
update handling of command-style function call syntax in eval
John W. Eaton <jwe@octave.org>
parents:
26660
diff
changeset
|
51 m_arg_nm (), m_dyn_field (), m_word_list_cmd (false) { } |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
52 |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
53 tree_index_expression::tree_index_expression (tree_expression *e, |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
54 tree_argument_list *lst, |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
55 int l, int c, char t) |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
56 : tree_expression (l, c), m_expr (e), m_args (0), m_type (), |
26662
05fc703b419a
update handling of command-style function call syntax in eval
John W. Eaton <jwe@octave.org>
parents:
26660
diff
changeset
|
57 m_arg_nm (), m_dyn_field (), m_word_list_cmd (false) |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
58 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
59 append (lst, t); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
60 } |
4131 | 61 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
62 tree_index_expression::tree_index_expression (tree_expression *e, |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
63 const std::string& n, |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
64 int l, int c) |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
65 : tree_expression (l, c), m_expr (e), m_args (0), m_type (), |
26662
05fc703b419a
update handling of command-style function call syntax in eval
John W. Eaton <jwe@octave.org>
parents:
26660
diff
changeset
|
66 m_arg_nm (), m_dyn_field (), m_word_list_cmd (false) |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
67 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
68 append (n); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
69 } |
3930 | 70 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
71 tree_index_expression::tree_index_expression (tree_expression *e, |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
72 tree_expression *df, |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
73 int l, int c) |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
74 : tree_expression (l, c), m_expr (e), m_args (0), m_type (), |
26662
05fc703b419a
update handling of command-style function call syntax in eval
John W. Eaton <jwe@octave.org>
parents:
26660
diff
changeset
|
75 m_arg_nm (), m_dyn_field (), m_word_list_cmd (false) |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
76 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
77 append (df); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
78 } |
3933 | 79 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
80 void |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
81 tree_index_expression::append (tree_argument_list *lst, char t) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
82 { |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
83 m_args.push_back (lst); |
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
84 m_type.append (1, t); |
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
85 m_arg_nm.push_back (lst ? lst->get_arg_names () : string_vector ()); |
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
86 m_dyn_field.push_back (static_cast<tree_expression *> (nullptr)); |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
87 |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
88 if (lst && lst->has_magic_tilde ()) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
89 error ("invalid use of empty argument (~) in index expression"); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
90 } |
13970 | 91 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
92 void |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
93 tree_index_expression::append (const std::string& n) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
94 { |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
95 m_args.push_back (static_cast<tree_argument_list *> (nullptr)); |
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
96 m_type += '.'; |
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
97 m_arg_nm.push_back (n); |
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
98 m_dyn_field.push_back (static_cast<tree_expression *> (nullptr)); |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
99 } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
100 |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
101 void |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
102 tree_index_expression::append (tree_expression *df) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
103 { |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
104 m_args.push_back (static_cast<tree_argument_list *> (nullptr)); |
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
105 m_type += '.'; |
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
106 m_arg_nm.push_back (""); |
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
107 m_dyn_field.push_back (df); |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
108 } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
109 |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
110 tree_index_expression::~tree_index_expression (void) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
111 { |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
112 delete m_expr; |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
113 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
114 while (! m_args.empty ()) |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
115 { |
25337
3ff9192b676e
use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents:
25336
diff
changeset
|
116 auto p = m_args.begin (); |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
117 delete *p; |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
118 m_args.erase (p); |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
119 } |
2980 | 120 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
121 while (! m_dyn_field.empty ()) |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
122 { |
25337
3ff9192b676e
use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents:
25336
diff
changeset
|
123 auto p = m_dyn_field.begin (); |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
124 delete *p; |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
125 m_dyn_field.erase (p); |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
126 } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
127 } |
5099 | 128 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
129 bool |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
130 tree_index_expression::has_magic_end (void) const |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
131 { |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
132 for (const tree_argument_list *elt : m_args) |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
133 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
134 if (elt && elt->has_magic_end ()) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
135 return true; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
136 } |
5099 | 137 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
138 return false; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
139 } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
140 |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
141 // This is useful for printing the name of the variable in an indexed |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
142 // assignment. |
2991 | 143 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
144 std::string |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
145 tree_index_expression::name (void) const |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
146 { |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
147 return m_expr->name (); |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
148 } |
3933 | 149 |
24722
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
150 static inline octave_value_list |
25383
d3a035528c9a
use reference to tree_evaluator instead of pointer
John W. Eaton <jwe@octave.org>
parents:
25382
diff
changeset
|
151 make_value_list (tree_evaluator& tw, |
25336
389757b7b6af
eliminate redundant octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
152 tree_argument_list *m_args, |
28726
0a4dcea2987a
stash (shallow) copy of indexed object instead of pointer
John W. Eaton <jwe@octave.org>
parents:
28618
diff
changeset
|
153 const string_vector& m_arg_nm, const octave_value& object, |
24722
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
154 bool rvalue = true) |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
155 { |
28552
aa47120a505d
set correct info for isargout when evaluating index expr args (bug #58727)
John W. Eaton <jwe@octave.org>
parents:
27971
diff
changeset
|
156 // FIXME: This function duplicates tree_evaluator::make_value_list. |
aa47120a505d
set correct info for isargout when evaluating index expr args (bug #58727)
John W. Eaton <jwe@octave.org>
parents:
27971
diff
changeset
|
157 // See also the way convert_to_const_vector is used in |
aa47120a505d
set correct info for isargout when evaluating index expr args (bug #58727)
John W. Eaton <jwe@octave.org>
parents:
27971
diff
changeset
|
158 // tree_index_expression::evaluate_n. |
aa47120a505d
set correct info for isargout when evaluating index expr args (bug #58727)
John W. Eaton <jwe@octave.org>
parents:
27971
diff
changeset
|
159 |
24722
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
160 octave_value_list retval; |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
161 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
162 if (m_args) |
24722
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
163 { |
28552
aa47120a505d
set correct info for isargout when evaluating index expr args (bug #58727)
John W. Eaton <jwe@octave.org>
parents:
27971
diff
changeset
|
164 unwind_action act ([&tw] (const std::list<octave_lvalue> *lvl) |
aa47120a505d
set correct info for isargout when evaluating index expr args (bug #58727)
John W. Eaton <jwe@octave.org>
parents:
27971
diff
changeset
|
165 { |
aa47120a505d
set correct info for isargout when evaluating index expr args (bug #58727)
John W. Eaton <jwe@octave.org>
parents:
27971
diff
changeset
|
166 tw.set_lvalue_list (lvl); |
aa47120a505d
set correct info for isargout when evaluating index expr args (bug #58727)
John W. Eaton <jwe@octave.org>
parents:
27971
diff
changeset
|
167 }, tw.lvalue_list ()); |
aa47120a505d
set correct info for isargout when evaluating index expr args (bug #58727)
John W. Eaton <jwe@octave.org>
parents:
27971
diff
changeset
|
168 tw.set_lvalue_list (nullptr); |
aa47120a505d
set correct info for isargout when evaluating index expr args (bug #58727)
John W. Eaton <jwe@octave.org>
parents:
27971
diff
changeset
|
169 |
28726
0a4dcea2987a
stash (shallow) copy of indexed object instead of pointer
John W. Eaton <jwe@octave.org>
parents:
28618
diff
changeset
|
170 if (rvalue && m_args->has_magic_end () && object.is_undefined ()) |
24722
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
171 err_invalid_inquiry_subscript (); |
3933 | 172 |
25383
d3a035528c9a
use reference to tree_evaluator instead of pointer
John W. Eaton <jwe@octave.org>
parents:
25382
diff
changeset
|
173 retval = tw.convert_to_const_vector (m_args, object); |
24722
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
174 } |
3933 | 175 |
24722
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
176 octave_idx_type n = retval.length (); |
3933 | 177 |
24722
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
178 if (n > 0) |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
179 retval.stash_name_tags (m_arg_nm); |
3933 | 180 |
24722
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
181 return retval; |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
182 } |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
183 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
184 std::string |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
185 tree_index_expression::get_struct_index |
25383
d3a035528c9a
use reference to tree_evaluator instead of pointer
John W. Eaton <jwe@octave.org>
parents:
25382
diff
changeset
|
186 (tree_evaluator& tw, |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23396
diff
changeset
|
187 std::list<string_vector>::const_iterator p_arg_nm, |
4219 | 188 std::list<tree_expression *>::const_iterator p_dyn_field) const |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
189 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
190 std::string fn = (*p_arg_nm)(0); |
4131 | 191 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
192 if (fn.empty ()) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
193 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
194 tree_expression *df = *p_dyn_field; |
4131 | 195 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
196 if (df) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
197 { |
27371
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
198 octave_value t = df->evaluate (tw); |
4131 | 199 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
200 fn = t.xstring_value ("dynamic structure field names must be strings"); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
201 } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
202 else |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
203 panic_impossible (); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
204 } |
4131 | 205 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
206 return fn; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
207 } |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10659
diff
changeset
|
208 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
209 octave_lvalue |
25383
d3a035528c9a
use reference to tree_evaluator instead of pointer
John W. Eaton <jwe@octave.org>
parents:
25382
diff
changeset
|
210 tree_index_expression::lvalue (tree_evaluator& tw) |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
211 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
212 std::list<octave_value_list> idx; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
213 std::string tmp_type; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
214 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
215 int n = m_args.size (); |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
216 |
25337
3ff9192b676e
use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents:
25336
diff
changeset
|
217 auto p_args = m_args.begin (); |
3ff9192b676e
use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents:
25336
diff
changeset
|
218 auto p_arg_nm = m_arg_nm.begin (); |
3ff9192b676e
use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents:
25336
diff
changeset
|
219 auto p_dyn_field = m_dyn_field.begin (); |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
220 |
26660
e4909f142491
* pt-idx.cc (tree_index_expression::lvalue): Style fix.
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
221 octave_lvalue retval = m_expr->lvalue (tw); |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
222 |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
223 octave_value tmp = retval.value (); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
224 |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
225 octave_idx_type tmpi = 0; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
226 std::list<octave_value_list> tmpidx; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
227 |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
228 for (int i = 0; i < n; i++) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
229 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
230 if (retval.numel () != 1) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
231 err_indexed_cs_list (); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
232 |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
233 if (tmpi < i) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
234 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
235 try |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
236 { |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
237 tmp = tmp.subsref (m_type.substr (tmpi, i-tmpi), tmpidx, true); |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
238 } |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23693
diff
changeset
|
239 catch (index_exception& e) // problems with range, invalid type etc. |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
240 { |
26094
8fb0df0c8772
eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents:
25383
diff
changeset
|
241 tw.final_index_error (e, m_expr); |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
242 } |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
243 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
244 tmpidx.clear (); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
245 } |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
246 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
247 switch (m_type[i]) |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
248 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
249 case '(': |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
250 { |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
251 octave_value_list tidx |
28726
0a4dcea2987a
stash (shallow) copy of indexed object instead of pointer
John W. Eaton <jwe@octave.org>
parents:
28618
diff
changeset
|
252 = make_value_list (tw, *p_args, *p_arg_nm, tmp, false); |
4432 | 253 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
254 idx.push_back (tidx); |
5846 | 255 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
256 if (i < n - 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
257 { |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
258 if (m_type[i+1] != '.') |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
259 error ("() must be followed by . or close the index chain"); |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
260 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
261 tmpidx.push_back (tidx); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
262 tmpi = i+1; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
263 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
264 } |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
265 break; |
3930 | 266 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
267 case '{': |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
268 { |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
269 octave_value_list tidx |
28726
0a4dcea2987a
stash (shallow) copy of indexed object instead of pointer
John W. Eaton <jwe@octave.org>
parents:
28618
diff
changeset
|
270 = make_value_list (tw, *p_args, *p_arg_nm, tmp, false); |
3933 | 271 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
272 if (tmp.is_undefined ()) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
273 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
274 if (tidx.has_magic_colon ()) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
275 err_invalid_inquiry_subscript (); |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
276 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
277 tmp = Cell (); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
278 } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
279 else if (tmp.is_zero_by_zero () |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
280 && (tmp.is_matrix_type () || tmp.is_string ())) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
281 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
282 tmp = Cell (); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
283 } |
18439
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
284 |
26922
072d0610cc56
avoid some overloaded virtual warnings (bug #55741)
John W. Eaton <jwe@octave.org>
parents:
26662
diff
changeset
|
285 retval.numel (tmp.xnumel (tidx)); |
18439
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
286 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
287 idx.push_back (tidx); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
288 tmpidx.push_back (tidx); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
289 tmpi = i; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
290 } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
291 break; |
2980 | 292 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
293 case '.': |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
294 { |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23396
diff
changeset
|
295 octave_value tidx = get_struct_index (tw, p_arg_nm, p_dyn_field); |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
296 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
297 bool autoconv = (tmp.is_zero_by_zero () |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
298 && (tmp.is_matrix_type () || tmp.is_string () |
23576
00e518162fda
maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents:
23450
diff
changeset
|
299 || tmp.iscell ())); |
2980 | 300 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
301 if (i > 0 && m_type[i-1] == '(') |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
302 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
303 octave_value_list pidx = idx.back (); |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
304 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
305 // Use octave_map, not octave_scalar_map so that the |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
306 // dimensions are 0x0, not 1x1. |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
307 if (tmp.is_undefined ()) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
308 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
309 if (pidx.has_magic_colon ()) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
310 err_invalid_inquiry_subscript (); |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21118
diff
changeset
|
311 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
312 tmp = octave_map (); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
313 } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
314 else if (autoconv) |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
315 tmp = octave_map (); |
5846 | 316 |
26922
072d0610cc56
avoid some overloaded virtual warnings (bug #55741)
John W. Eaton <jwe@octave.org>
parents:
26662
diff
changeset
|
317 retval.numel (tmp.xnumel (pidx)); |
6833 | 318 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
319 tmpi = i-1; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
320 tmpidx.push_back (tidx); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
321 } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
322 else |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
323 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
324 if (tmp.is_undefined () || autoconv) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
325 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
326 tmpi = i+1; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
327 tmp = octave_value (); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
328 } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
329 else |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
330 { |
26922
072d0610cc56
avoid some overloaded virtual warnings (bug #55741)
John W. Eaton <jwe@octave.org>
parents:
26662
diff
changeset
|
331 retval.numel (tmp.xnumel (octave_value_list ())); |
7099 | 332 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
333 tmpi = i; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
334 tmpidx.push_back (tidx); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
335 } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
336 } |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
337 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
338 idx.push_back (tidx); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
339 } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
340 break; |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
341 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
342 default: |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
343 panic_impossible (); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
344 } |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
345 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
346 if (idx.back ().empty ()) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
347 error ("invalid empty index list"); |
5846 | 348 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
349 p_args++; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
350 p_arg_nm++; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
351 p_dyn_field++; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
352 } |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
353 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
354 retval.set_index (m_type, idx); |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
355 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
356 return retval; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
357 } |
4234 | 358 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
359 tree_index_expression * |
24270
bc3819b7cca1
don't use symbol_table:: nesting for symbol_record, symbol_scope, or fcn_info
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
360 tree_index_expression::dup (symbol_scope& scope) const |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
361 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
362 tree_index_expression *new_idx_expr |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
363 = new tree_index_expression (line (), column ()); |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
364 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
365 new_idx_expr->m_expr = (m_expr ? m_expr->dup (scope) : nullptr); |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
366 |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
367 std::list<tree_argument_list *> new_args; |
5846 | 368 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
369 for (const tree_argument_list *elt : m_args) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23696
diff
changeset
|
370 new_args.push_back (elt ? elt->dup (scope) : nullptr); |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
371 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
372 new_idx_expr->m_args = new_args; |
3930 | 373 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
374 new_idx_expr->m_type = m_type; |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
375 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
376 new_idx_expr->m_arg_nm = m_arg_nm; |
7099 | 377 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
378 std::list<tree_expression *> new_dyn_field; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
379 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
380 for (const tree_expression *elt : m_dyn_field) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23696
diff
changeset
|
381 new_dyn_field.push_back (elt ? elt->dup (scope) : nullptr); |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
382 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
383 new_idx_expr->m_dyn_field = new_dyn_field; |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
384 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
385 new_idx_expr->copy_base (*this); |
4234 | 386 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
387 return new_idx_expr; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
388 } |
27371
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
389 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
390 // Unlike Matlab, which does not allow the result of a function call |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
391 // or array indexing expression to be further indexed, Octave attempts |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
392 // to handle arbitrary index expressions. For example, Octave allows |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
393 // expressions like |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
394 // |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
395 // svd (rand (10))(1:5) |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
396 // |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
397 // Although octave_value objects may contain function objects, no |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
398 // indexing operation or function call is supposed to return them |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
399 // directly. Instead, the language is supposed to only allow function |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
400 // objects to be stored as function handles (named or anonymous) or as |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
401 // inline functions. The only place a function object should appear |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
402 // directly is if the symbol stored in a tree_identifier object |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
403 // resolves to a function. This means that the only place we need to |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
404 // look for functions is in the first element of the index |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
405 // expression. |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
406 // |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
407 // Steps: |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
408 // |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
409 // * Obtain the initial value from the expression component of the |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
410 // tree_index_expression object. If it is a tree_identifier object |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
411 // indexed by '(args)' and the identifier is not a variable, then |
27971
ec769a7ab9fb
fix more spelling errors (bug #57613)
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
412 // perform a function call. Use the (optional) arguments to perform |
27371
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
413 // the function lookup so we choose the correct function or class |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
414 // method to call. Otherwise, evaluate the first expression |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
415 // without any additional arguments. |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
416 // |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
417 // * Iterate over the remaining elements of the index expression and |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
418 // call the octave_value::subsref method. If indexing a class or |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
419 // classdef object, build up a list of indices for a call to the |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
420 // subsref method for the object. Otherwise, use the result of |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
421 // each temporary evaluation for the next index element. |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
422 // |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
423 // * If not indexing a class or classdef object and any partial |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
424 // expression evaluation produces a class or classdef object, then |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
425 // build up a complete argument list from that point on for a final |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
426 // subsref call for that object. |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
427 // |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
428 // Multiple partial evaluations may be required. For example, |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
429 // given a class or classdef object X, then for the expression |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
430 // |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
431 // x.a{end}(2:end).b |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
432 // |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
433 // we must evaluate x.a to obtain the size for the first {end} |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
434 // expression, then we must evaluate x.a{end} to obtain the size |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
435 // for the second (2:end) expression. Finally, the complete |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
436 // expression may be evaluated. |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
437 // |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
438 // If X is a cell array in the above expression, and none of the |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
439 // intermediate evaluations produces a class or classdef object, |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
440 // then the evaluation is performed as the following series of |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
441 // steps |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
442 // |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
443 // tmp = x.a |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
444 // tmp = tmp{end} |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
445 // tmp = tmp(2:end) |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
446 // result = tmp.b |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
447 // |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
448 // If any of the partial evaluations produces a class or classdef |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
449 // object, then the subsref method for that object is called as |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
450 // described above. For example, suppose x.a produces a classdef |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
451 // object. Then the evaluation is performed as the following |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
452 // series of steps |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
453 // |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
454 // base_expr = tmp = x.a |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
455 // tmp = base_expr{end} |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
456 // base_expr{end}(2:end).b |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
457 // |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
458 // In the last two steps, the partial value computed in the |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
459 // previous step is used to determine the value of END. |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
460 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
461 octave_value_list |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
462 tree_index_expression::evaluate_n (tree_evaluator& tw, int nargout) |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
463 { |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
464 octave_value_list retval; |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
465 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
466 assert (! m_args.empty ()); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
467 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
468 auto p_args = m_args.begin (); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
469 auto p_arg_nm = m_arg_nm.begin (); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
470 auto p_dyn_field = m_dyn_field.begin (); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
471 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
472 int n = m_args.size (); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
473 int beg = 0; |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
474 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
475 octave_value base_expr_val; |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
476 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
477 if (m_expr->is_identifier () && m_type[beg] == '(') |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
478 { |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
479 tree_identifier *id = dynamic_cast<tree_identifier *> (m_expr); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
480 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
481 bool is_var = tw.is_variable (m_expr); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
482 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
483 std::string nm = id->name (); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
484 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
485 if (is_var && is_word_list_cmd ()) |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
486 error ("%s used as variable and later as function", nm.c_str ()); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
487 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
488 if (! is_var) |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
489 { |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
490 octave_value_list first_args; |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
491 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
492 tree_argument_list *al = *p_args; |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
493 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
494 if (al && al->length () > 0) |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
495 { |
27373
25627c524ad8
where possible, use new unwind-protect classes in evaluator
John W. Eaton <jwe@octave.org>
parents:
27371
diff
changeset
|
496 unwind_action act ([&tw] (const std::list<octave_lvalue> *lvl) |
25627c524ad8
where possible, use new unwind-protect classes in evaluator
John W. Eaton <jwe@octave.org>
parents:
27371
diff
changeset
|
497 { |
25627c524ad8
where possible, use new unwind-protect classes in evaluator
John W. Eaton <jwe@octave.org>
parents:
27371
diff
changeset
|
498 tw.set_lvalue_list (lvl); |
25627c524ad8
where possible, use new unwind-protect classes in evaluator
John W. Eaton <jwe@octave.org>
parents:
27371
diff
changeset
|
499 }, tw.lvalue_list ()); |
27371
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
500 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
501 tw.set_lvalue_list (nullptr); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
502 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
503 string_vector anm = *p_arg_nm; |
28618
af302efce502
avoid some unnecessary work when evaluating index expressions
John W. Eaton <jwe@octave.org>
parents:
28552
diff
changeset
|
504 |
27371
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
505 first_args = tw.convert_to_const_vector (al); |
28618
af302efce502
avoid some unnecessary work when evaluating index expressions
John W. Eaton <jwe@octave.org>
parents:
28552
diff
changeset
|
506 |
27371
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
507 first_args.stash_name_tags (anm); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
508 } |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
509 |
28618
af302efce502
avoid some unnecessary work when evaluating index expressions
John W. Eaton <jwe@octave.org>
parents:
28552
diff
changeset
|
510 interpreter& interp = tw.get_interpreter (); |
27371
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
511 |
28618
af302efce502
avoid some unnecessary work when evaluating index expressions
John W. Eaton <jwe@octave.org>
parents:
28552
diff
changeset
|
512 symbol_table& symtab = interp.get_symbol_table (); |
27371
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
513 |
28618
af302efce502
avoid some unnecessary work when evaluating index expressions
John W. Eaton <jwe@octave.org>
parents:
28552
diff
changeset
|
514 octave_value val = symtab.find_function (nm, first_args); |
27371
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
515 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
516 octave_function *fcn = nullptr; |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
517 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
518 if (val.is_function ()) |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
519 fcn = val.function_value (true); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
520 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
521 if (fcn) |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
522 { |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
523 try |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
524 { |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
525 retval = fcn->call (tw, nargout, first_args); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
526 } |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
527 catch (index_exception& e) |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
528 { |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
529 tw.final_index_error (e, m_expr); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
530 } |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
531 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
532 beg++; |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
533 p_args++; |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
534 p_arg_nm++; |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
535 p_dyn_field++; |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
536 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
537 if (n > beg) |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
538 { |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
539 // More indices to follow. Silently ignore |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
540 // extra output values. |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
541 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
542 if (retval.length () == 0) |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
543 error ("indexing undefined value"); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
544 else |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
545 base_expr_val = retval(0); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
546 } |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
547 else |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
548 { |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
549 // No more indices, so we are done. |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
550 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
551 // See note at end of function about deleting |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
552 // temporaries prior to pushing result. |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
553 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
554 base_expr_val = octave_value (); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
555 first_args = octave_value_list (); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
556 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
557 return retval; |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
558 } |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
559 } |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
560 } |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
561 } |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
562 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
563 if (base_expr_val.is_undefined ()) |
27374
d171d356767b
don't apply std::move to temporary values
John W. Eaton <jwe@octave.org>
parents:
27373
diff
changeset
|
564 base_expr_val = m_expr->evaluate (tw); |
27371
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
565 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
566 // If we are indexing an object or looking at something like |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
567 // |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
568 // classname.static_function (args, ...); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
569 // |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
570 // then we'll just build a complete index list for one big subsref |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
571 // call. If the expression we are indexing is a classname then |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
572 // base_expr_val will be an octave_classdef_meta object. If we have |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
573 // files in a +packagename folder, they will also be an |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
574 // octave_classdef_meta object, but we don't want to index them. |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
575 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
576 bool indexing_object = (base_expr_val.isobject () |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
577 || base_expr_val.isjava () |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
578 || (base_expr_val.is_classdef_meta () |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
579 && ! base_expr_val.is_package ())); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
580 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
581 std::list<octave_value_list> idx_list; |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
582 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
583 octave_value partial_expr_val = base_expr_val; |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
584 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
585 for (int i = beg; i < n; i++) |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
586 { |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
587 if (i > beg) |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
588 { |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
589 tree_argument_list *al = *p_args; |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
590 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
591 if (! indexing_object || (al && al->has_magic_end ())) |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
592 { |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
593 // Evaluate what we have so far to find the value to |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
594 // pass to the END function. |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
595 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
596 try |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
597 { |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
598 // Silently ignore extra output values. |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
599 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
600 octave_value_list tmp_list |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
601 = base_expr_val.subsref (m_type.substr (beg, i-beg), |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
602 idx_list, nargout); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
603 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
604 partial_expr_val |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
605 = tmp_list.length () ? tmp_list(0) : octave_value (); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
606 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
607 if (! indexing_object) |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
608 { |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
609 base_expr_val = partial_expr_val; |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
610 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
611 if (partial_expr_val.is_cs_list ()) |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
612 err_indexed_cs_list (); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
613 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
614 retval = partial_expr_val; |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
615 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
616 beg = i; |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
617 idx_list.clear (); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
618 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
619 if (partial_expr_val.isobject () |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
620 || partial_expr_val.isjava () |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
621 || (partial_expr_val.is_classdef_meta () |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
622 && ! partial_expr_val.is_package ())) |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
623 { |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
624 // Found an object, so now we'll build up |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
625 // complete index list for one big subsref |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
626 // call from this point on. |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
627 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
628 // FIXME: is is also possible to have a |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
629 // static method call buried somewhere in |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
630 // the depths of a complex indexing |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
631 // expression so that we would also need to |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
632 // check for an octave_classdef_meta object |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
633 // here? |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
634 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
635 indexing_object = true; |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
636 } |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
637 } |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
638 } |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
639 catch (index_exception& e) |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
640 { |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
641 tw.final_index_error (e, m_expr); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
642 } |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
643 } |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
644 } |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
645 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
646 switch (m_type[i]) |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
647 { |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
648 case '(': |
27932
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
649 idx_list.push_back (make_value_list (tw, *p_args, *p_arg_nm, |
28726
0a4dcea2987a
stash (shallow) copy of indexed object instead of pointer
John W. Eaton <jwe@octave.org>
parents:
28618
diff
changeset
|
650 partial_expr_val)); |
27371
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
651 break; |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
652 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
653 case '{': |
27932
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
654 idx_list.push_back (make_value_list (tw, *p_args, *p_arg_nm, |
28726
0a4dcea2987a
stash (shallow) copy of indexed object instead of pointer
John W. Eaton <jwe@octave.org>
parents:
28618
diff
changeset
|
655 partial_expr_val)); |
27371
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
656 break; |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
657 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
658 case '.': |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
659 idx_list.push_back (octave_value |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
660 (get_struct_index (tw, p_arg_nm, p_dyn_field))); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
661 break; |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
662 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
663 default: |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
664 panic_impossible (); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
665 } |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
666 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
667 p_args++; |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
668 p_arg_nm++; |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
669 p_dyn_field++; |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
670 } |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
671 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
672 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
673 // If ! idx_list.empty () that means we still have stuff to index |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
674 // otherwise they would have been dealt with and idx_list would have |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
675 // been emptied. |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
676 if (! idx_list.empty ()) |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
677 { |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
678 // This is for +package and other classdef_meta objects |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
679 if (! base_expr_val.is_function () |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
680 || base_expr_val.is_classdef_meta ()) |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
681 { |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
682 try |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
683 { |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
684 retval = base_expr_val.subsref (m_type.substr (beg, n-beg), |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
685 idx_list, nargout); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
686 beg = n; |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
687 idx_list.clear (); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
688 } |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
689 catch (index_exception& e) |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
690 { |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
691 tw.final_index_error (e, m_expr); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
692 } |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
693 } |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
694 else |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
695 { |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
696 // FIXME: we want this to only be a superclass constructor |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
697 // call Should we actually make a check for this or are all |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
698 // other types of calls already dealt with? |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
699 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
700 octave_function *fcn = base_expr_val.function_value (); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
701 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
702 if (fcn) |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
703 { |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
704 try |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
705 { |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
706 // FIXME: is it possible for the IDX_LIST to have |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
707 // more than one element here? Do we need to check? |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
708 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
709 octave_value_list final_args; |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
710 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
711 if (idx_list.size () != 1) |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
712 error ("unexpected extra index at end of expression"); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
713 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
714 if (m_type[beg] != '(') |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
715 error ("invalid index type '%c' for function call", |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
716 m_type[beg]); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
717 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
718 final_args = idx_list.front (); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
719 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
720 // FIXME: Do we ever need the names of the arguments |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
721 // passed to FCN here? |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
722 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
723 retval = fcn->call (tw, nargout, final_args); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
724 } |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
725 catch (index_exception& e) |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
726 { |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
727 tw.final_index_error (e, m_expr); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
728 } |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
729 } |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
730 } |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
731 } |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
732 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
733 // FIXME: when can the following happen? In what case does indexing |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
734 // result in a value that is a function? Classdef method calls? |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
735 // Something else? |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
736 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
737 octave_value val = (retval.length () ? retval(0) : octave_value ()); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
738 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
739 if (val.is_function ()) |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
740 { |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
741 octave_function *fcn = val.function_value (true); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
742 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
743 if (fcn) |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
744 { |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
745 octave_value_list final_args; |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
746 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
747 if (! idx_list.empty ()) |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
748 { |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
749 if (n - beg != 1) |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
750 error ("unexpected extra index at end of expression"); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
751 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
752 if (m_type[beg] != '(') |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
753 error ("invalid index type '%c' for function call", |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
754 m_type[beg]); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
755 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
756 final_args = idx_list.front (); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
757 } |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
758 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
759 retval = fcn->call (tw, nargout, final_args); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
760 } |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
761 } |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
762 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
763 // Delete any temporary values prior to pushing the result and |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
764 // returning so that destructors for any temporary classdef handle |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
765 // objects will be called before we return. Otherwise, the |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
766 // destructor may push result values that will wipe out the result |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
767 // that we push below. Although the method name is "push_result" |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
768 // there is only a single register (either an octave_value or an |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
769 // octave_value_list) not a stack. |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
770 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
771 idx_list.clear (); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
772 partial_expr_val = octave_value (); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
773 base_expr_val = octave_value (); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
774 val = octave_value (); |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
775 |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
776 return retval; |
fcaecdbc8d8a
don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
777 } |
2980 | 778 } |
779 | |
7099 | 780 /* |
781 %!test | |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14343
diff
changeset
|
782 %! clear x; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14343
diff
changeset
|
783 %! clear y; |
14343
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
784 %! y = 3; |
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
785 %! x(y(end)) = 1; |
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
786 %! assert (x, [0, 0, 1]); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14343
diff
changeset
|
787 %! clear x; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14343
diff
changeset
|
788 %! clear y; |
14343
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
789 %! y = {3}; |
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
790 %! x(y{end}) = 1; |
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
791 %! assert (x, [0, 0, 1]); |
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
792 |
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
793 %!test |
7099 | 794 %! x = {1, 2, 3}; |
795 %! [x{:}] = deal (4, 5, 6); | |
796 %! assert (x, {4, 5, 6}); | |
797 | |
798 %!test | |
799 %! [x.a, x.b.c] = deal (1, 2); | |
800 %! assert (x.a == 1 && x.b.c == 2); | |
801 | |
802 %!test | |
803 %! [x.a, x(2).b] = deal (1, 2); | |
804 %! assert (x(1).a == 1 && isempty (x(2).a) && isempty (x(1).b) && x(2).b == 2); | |
805 | |
806 %!test | |
807 %! x = struct (zeros (0, 1), {"a", "b"}); | |
808 %! x(2).b = 1; | |
809 %! assert (x(2).b == 1); | |
810 | |
811 %!test | |
812 %! x = struct (zeros (0, 1), {"a", "b"}); | |
813 %! x(2).b = 1; | |
814 %! assert (x(2).b == 1); | |
815 */ |