Mercurial > octave
annotate libinterp/parse-tree/pt-idx.cc @ 25382:749d9e858553
move convert_to_const_vector from tree_argument_list to tree_evaluator
* pt-eval.h, pt-eval.cc (tree_evaluator::convert_to_const_vector):
Move here from pt-arg-list.h and pt-arg-list.cc: Change all uses.
(tree_evaluator::m_indexed_object, tree_evaluator::m_index_position,
tree_evaluator::m_num_indices): Move here from
(tree_evaluator::m_indexed_object, tree_evaluator::m_index_position,
tree_evaluator::num_indices): Provide accessors for corresponding
member variables.
(Fend): Move here from pt-arg-list.cc. Access indexed_object,
index_position, and num_indices from evaluator instead of file scope
static variables.
* pt-arg-list.h (tree_argument_list::includes_magic_end): New function.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 15 May 2018 17:05:47 -0400 |
parents | 3ff9192b676e |
children | d3a035528c9a |
rev | line source |
---|---|
2980 | 1 /* |
2 | |
25054
6652d3823428
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
24846
diff
changeset
|
3 Copyright (C) 1996-2018 John W. Eaton |
2980 | 4 |
5 This file is part of Octave. | |
6 | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24356
diff
changeset
|
7 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24356
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
10 (at your option) any later version. |
2980 | 11 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
15 GNU General Public License for more details. |
2980 | 16 |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24356
diff
changeset
|
19 <https://www.gnu.org/licenses/>. |
2980 | 20 |
21 */ | |
22 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
24 # include "config.h" |
2980 | 25 #endif |
26 | |
3933 | 27 #include "Cell.h" |
2980 | 28 #include "error.h" |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23576
diff
changeset
|
29 #include "interpreter-private.h" |
3930 | 30 #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
|
31 #include "ovl.h" |
2980 | 32 #include "oct-lvalue.h" |
33 #include "ov.h" | |
2982 | 34 #include "pt-arg-list.h" |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23396
diff
changeset
|
35 #include "pt-eval.h" |
7336 | 36 #include "pt-id.h" |
2980 | 37 #include "pt-idx.h" |
3930 | 38 #include "utils.h" |
39 #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
|
40 #include "errwarn.h" |
2980 | 41 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
42 namespace octave |
3933 | 43 { |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
44 // Index expressions. |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
45 |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
46 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
|
47 : tree_expression (l, c), m_expr (nullptr), m_args (0), m_type (), |
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
48 m_arg_nm (), m_dyn_field () { } |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
49 |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
50 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
|
51 tree_argument_list *lst, |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
52 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
|
53 : tree_expression (l, c), m_expr (e), m_args (0), m_type (), |
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
54 m_arg_nm (), m_dyn_field () |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
55 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
56 append (lst, t); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
57 } |
4131 | 58 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
59 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
|
60 const std::string& n, |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
61 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
|
62 : tree_expression (l, c), m_expr (e), m_args (0), m_type (), |
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
63 m_arg_nm (), m_dyn_field () |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
64 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
65 append (n); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
66 } |
3930 | 67 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
68 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
|
69 tree_expression *df, |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
70 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
|
71 : tree_expression (l, c), m_expr (e), m_args (0), m_type (), |
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
72 m_arg_nm (), m_dyn_field () |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
73 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
74 append (df); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
75 } |
3933 | 76 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
77 void |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
78 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
|
79 { |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
80 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
|
81 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
|
82 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
|
83 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
|
84 |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
85 if (lst && lst->has_magic_tilde ()) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
86 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
|
87 } |
13970 | 88 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
89 void |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
90 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
|
91 { |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
92 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
|
93 m_type += '.'; |
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
94 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
|
95 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
|
96 } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
97 |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
98 void |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
99 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
|
100 { |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
101 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
|
102 m_type += '.'; |
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
103 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
|
104 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
|
105 } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
106 |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
107 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
|
108 { |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
109 delete m_expr; |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
110 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
111 while (! m_args.empty ()) |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
112 { |
25337
3ff9192b676e
use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents:
25336
diff
changeset
|
113 auto p = m_args.begin (); |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
114 delete *p; |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
115 m_args.erase (p); |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
116 } |
2980 | 117 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
118 while (! m_dyn_field.empty ()) |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
119 { |
25337
3ff9192b676e
use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents:
25336
diff
changeset
|
120 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
|
121 delete *p; |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
122 m_dyn_field.erase (p); |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
123 } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
124 } |
5099 | 125 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
126 bool |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
127 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
|
128 { |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
129 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
|
130 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
131 if (elt && elt->has_magic_end ()) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
132 return true; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
133 } |
5099 | 134 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
135 return false; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
136 } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
137 |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
138 // 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
|
139 // assignment. |
2991 | 140 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
141 std::string |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
142 tree_index_expression::name (void) const |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
143 { |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
144 return m_expr->name (); |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
145 } |
3933 | 146 |
24722
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
147 static inline octave_value_list |
25336
389757b7b6af
eliminate redundant octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
148 make_value_list (tree_evaluator *tw, |
389757b7b6af
eliminate redundant octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
149 tree_argument_list *m_args, |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
150 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
|
151 bool rvalue = true) |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
152 { |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
153 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
|
154 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
155 if (m_args) |
24722
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
156 { |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
157 if (rvalue && object && m_args->has_magic_end () |
24722
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
158 && object->is_undefined ()) |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
159 err_invalid_inquiry_subscript (); |
3933 | 160 |
25382
749d9e858553
move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents:
25337
diff
changeset
|
161 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
|
162 } |
3933 | 163 |
24722
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
164 octave_idx_type n = retval.length (); |
3933 | 165 |
24722
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
166 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
|
167 retval.stash_name_tags (m_arg_nm); |
3933 | 168 |
24722
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
169 return retval; |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
170 } |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
171 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
172 std::string |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
173 tree_index_expression::get_struct_index |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23396
diff
changeset
|
174 (tree_evaluator *tw, |
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23396
diff
changeset
|
175 std::list<string_vector>::const_iterator p_arg_nm, |
4219 | 176 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
|
177 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
178 std::string fn = (*p_arg_nm)(0); |
4131 | 179 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
180 if (fn.empty ()) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
181 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
182 tree_expression *df = *p_dyn_field; |
4131 | 183 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
184 if (df) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
185 { |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23396
diff
changeset
|
186 octave_value t = tw->evaluate (df); |
4131 | 187 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
188 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
|
189 } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
190 else |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
191 panic_impossible (); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
192 } |
4131 | 193 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
194 return fn; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
195 } |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10659
diff
changeset
|
196 |
24722
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
197 // Final step of processing an indexing error. Add the name of the |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
198 // variable being indexed, if any, then issue an error. (Will this also |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
199 // be needed by pt-lvalue, which calls subsref?) |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
200 |
24722
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
201 static void |
25336
389757b7b6af
eliminate redundant octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
202 final_index_error (index_exception& e, const tree_expression *expr) |
24722
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
203 { |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
204 std::string extra_message; |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
205 |
25336
389757b7b6af
eliminate redundant octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
206 symbol_table& symtab = __get_symbol_table__ ("final_index_error"); |
24356
8b14ba8296af
refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents:
24270
diff
changeset
|
207 |
25336
389757b7b6af
eliminate redundant octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
208 symbol_record::context_id context = symtab.current_context (); |
7336 | 209 |
24722
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
210 if (expr->is_identifier () |
25336
389757b7b6af
eliminate redundant octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
211 && dynamic_cast<const tree_identifier *> (expr)->is_variable (context)) |
24722
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
212 { |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
213 std::string var = expr->name (); |
7336 | 214 |
24722
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
215 e.set_var (var); |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
216 |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
217 octave_value fcn = symtab.find_function (var); |
7336 | 218 |
24722
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
219 if (fcn.is_function ()) |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
220 { |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
221 octave_function *fp = fcn.function_value (); |
2980 | 222 |
24722
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
223 if (fp && fp->name () == var) |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
224 extra_message = " (note: variable '" + var + "' shadows function)"; |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
225 } |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
226 } |
18439
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
227 |
24722
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
228 std::string msg = e.message () + extra_message; |
2980 | 229 |
24722
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
230 error_with_id (e.err_id (), msg.c_str ()); |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
231 } |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
232 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
233 octave_lvalue |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23396
diff
changeset
|
234 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
|
235 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
236 octave_lvalue retval; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
237 |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
238 std::list<octave_value_list> idx; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
239 std::string tmp_type; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
240 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
241 int n = m_args.size (); |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
242 |
25337
3ff9192b676e
use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents:
25336
diff
changeset
|
243 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
|
244 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
|
245 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
|
246 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
247 retval = m_expr->lvalue (tw); |
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 octave_value tmp = retval.value (); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
250 |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
251 octave_idx_type tmpi = 0; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
252 std::list<octave_value_list> tmpidx; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
253 |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
254 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
|
255 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
256 if (retval.numel () != 1) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
257 err_indexed_cs_list (); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
258 |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
259 if (tmpi < i) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
260 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
261 try |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
262 { |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
263 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
|
264 } |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23693
diff
changeset
|
265 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
|
266 { |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
267 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
|
268 } |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
269 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
270 tmpidx.clear (); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
271 } |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
272 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
273 switch (m_type[i]) |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
274 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
275 case '(': |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
276 { |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
277 octave_value_list tidx |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23396
diff
changeset
|
278 = make_value_list (tw, *p_args, *p_arg_nm, &tmp, false); |
4432 | 279 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
280 idx.push_back (tidx); |
5846 | 281 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
282 if (i < n - 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
283 { |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
284 if (m_type[i+1] != '.') |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
285 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
|
286 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
287 tmpidx.push_back (tidx); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
288 tmpi = i+1; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
289 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10206
diff
changeset
|
290 } |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
291 break; |
3930 | 292 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
293 case '{': |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
294 { |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
295 octave_value_list tidx |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23396
diff
changeset
|
296 = make_value_list (tw, *p_args, *p_arg_nm, &tmp, false); |
3933 | 297 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
298 if (tmp.is_undefined ()) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
299 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
300 if (tidx.has_magic_colon ()) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
301 err_invalid_inquiry_subscript (); |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
302 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
303 tmp = Cell (); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
304 } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
305 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
|
306 && (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
|
307 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
308 tmp = Cell (); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
309 } |
18439
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
310 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
311 retval.numel (tmp.numel (tidx)); |
18439
d5aa615dcf4c
Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
312 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
313 idx.push_back (tidx); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
314 tmpidx.push_back (tidx); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
315 tmpi = i; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
316 } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
317 break; |
2980 | 318 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
319 case '.': |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
320 { |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23396
diff
changeset
|
321 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
|
322 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
323 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
|
324 && (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
|
325 || tmp.iscell ())); |
2980 | 326 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
327 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
|
328 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
329 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
|
330 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
331 // 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
|
332 // dimensions are 0x0, not 1x1. |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
333 if (tmp.is_undefined ()) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
334 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
335 if (pidx.has_magic_colon ()) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
336 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
|
337 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
338 tmp = octave_map (); |
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 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
|
341 tmp = octave_map (); |
5846 | 342 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
343 retval.numel (tmp.numel (pidx)); |
6833 | 344 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
345 tmpi = i-1; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
346 tmpidx.push_back (tidx); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
347 } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
348 else |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
349 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
350 if (tmp.is_undefined () || autoconv) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
351 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
352 tmpi = i+1; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
353 tmp = octave_value (); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
354 } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
355 else |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
356 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
357 retval.numel (tmp.numel (octave_value_list ())); |
7099 | 358 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
359 tmpi = i; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
360 tmpidx.push_back (tidx); |
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 } |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
363 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
364 idx.push_back (tidx); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
365 } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
366 break; |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
367 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
368 default: |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
369 panic_impossible (); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
370 } |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
371 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
372 if (idx.back ().empty ()) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
373 error ("invalid empty index list"); |
5846 | 374 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
375 p_args++; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
376 p_arg_nm++; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
377 p_dyn_field++; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
378 } |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
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 retval.set_index (m_type, idx); |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
381 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
382 return retval; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
383 } |
4234 | 384 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
385 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
|
386 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
|
387 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
388 tree_index_expression *new_idx_expr |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
389 = 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
|
390 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
391 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
|
392 |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
393 std::list<tree_argument_list *> new_args; |
5846 | 394 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
395 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
|
396 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
|
397 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
398 new_idx_expr->m_args = new_args; |
3930 | 399 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
400 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
|
401 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
402 new_idx_expr->m_arg_nm = m_arg_nm; |
7099 | 403 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
404 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
|
405 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
406 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
|
407 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
|
408 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24722
diff
changeset
|
409 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
|
410 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
411 new_idx_expr->copy_base (*this); |
4234 | 412 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
413 return new_idx_expr; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23071
diff
changeset
|
414 } |
2980 | 415 } |
416 | |
7099 | 417 /* |
418 %!test | |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14343
diff
changeset
|
419 %! clear x; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14343
diff
changeset
|
420 %! clear y; |
14343
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
421 %! y = 3; |
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
422 %! x(y(end)) = 1; |
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
423 %! 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
|
424 %! clear x; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14343
diff
changeset
|
425 %! clear y; |
14343
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
426 %! y = {3}; |
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
427 %! x(y{end}) = 1; |
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
428 %! assert (x, [0, 0, 1]); |
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
429 |
acc26b860afa
fix indexed assignment bug (bug #35482)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
430 %!test |
7099 | 431 %! x = {1, 2, 3}; |
432 %! [x{:}] = deal (4, 5, 6); | |
433 %! assert (x, {4, 5, 6}); | |
434 | |
435 %!test | |
436 %! [x.a, x.b.c] = deal (1, 2); | |
437 %! assert (x.a == 1 && x.b.c == 2); | |
438 | |
439 %!test | |
440 %! [x.a, x(2).b] = deal (1, 2); | |
441 %! assert (x(1).a == 1 && isempty (x(2).a) && isempty (x(1).b) && x(2).b == 2); | |
442 | |
443 %!test | |
444 %! x = struct (zeros (0, 1), {"a", "b"}); | |
445 %! x(2).b = 1; | |
446 %! assert (x(2).b == 1); | |
447 | |
448 %!test | |
449 %! x = struct (zeros (0, 1), {"a", "b"}); | |
450 %! x(2).b = 1; | |
451 %! assert (x(2).b == 1); | |
452 */ |