Mercurial > hg > octave-lyh
annotate src/pt-assign.cc @ 11523:fd0a3ac60b0e
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 14 Jan 2011 05:47:45 -0500 |
parents | 1b2fcd122c6a |
children | 922bfdd80413 |
rev | line source |
---|---|
2980 | 1 /* |
2 | |
11523 | 3 Copyright (C) 1996-2011 John W. Eaton |
2980 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2980 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
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 |
19 <http://www.gnu.org/licenses/>. | |
2980 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
3503 | 27 #include <iostream> |
6253 | 28 #include <set> |
2980 | 29 |
30 #include "defun.h" | |
31 #include "error.h" | |
10030
83bb2a78c07d
improve simple assignments error checks and messages
Jaroslav Hajek <highegg@gmail.com>
parents:
9782
diff
changeset
|
32 #include "gripes.h" |
2980 | 33 #include "input.h" |
34 #include "oct-obj.h" | |
35 #include "oct-lvalue.h" | |
36 #include "pager.h" | |
37 #include "ov.h" | |
2982 | 38 #include "pt-arg-list.h" |
3770 | 39 #include "pt-bp.h" |
2980 | 40 #include "pt-assign.h" |
41 #include "pt-walk.h" | |
42 #include "utils.h" | |
5794 | 43 #include "variables.h" |
2980 | 44 |
45 // Simple assignment expressions. | |
46 | |
8037
0be8cf23b95c
check for obsolete built-in variable assignment at first execution rather than parse time
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
47 // FIXME -- the following variable and the function that uses it |
0be8cf23b95c
check for obsolete built-in variable assignment at first execution rather than parse time
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
48 // should be removed from some future version of Octave. |
0be8cf23b95c
check for obsolete built-in variable assignment at first execution rather than parse time
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
49 |
6253 | 50 static const char *former_built_in_variables[] = |
51 { | |
52 "DEFAULT_EXEC_PATH", | |
53 "DEFAULT_LOADPATH", | |
54 "EDITOR", | |
55 "EXEC_PATH", | |
56 "FFTW_WISDOM_PROGRAM", | |
57 "IMAGEPATH", | |
58 "INFO_FILE", | |
59 "INFO_PROGRAM", | |
60 "LOADPATH", | |
61 "MAKEINFO_PROGRAM", | |
62 "PAGER", | |
63 "PS1", | |
64 "PS2", | |
65 "PS4", | |
66 "__kluge_procbuf_delay__", | |
67 "automatic_replot", | |
68 "beep_on_error", | |
69 "completion_append_char", | |
70 "crash_dumps_octave_core", | |
71 "current_script_file_name", | |
72 "debug_on_error", | |
73 "debug_on_interrupt", | |
74 "debug_on_warning", | |
75 "debug_symtab_lookups", | |
76 "default_save_format", | |
77 "echo_executing_commands", | |
78 "fixed_point_format", | |
79 "gnuplot_binary", | |
80 "gnuplot_command_axes", | |
81 "gnuplot_command_end", | |
82 "gnuplot_command_plot", | |
83 "gnuplot_command_replot", | |
84 "gnuplot_command_splot", | |
85 "gnuplot_command_title", | |
86 "gnuplot_command_using", | |
87 "gnuplot_command_with", | |
88 "gnuplot_has_frames", | |
89 "history_file", | |
90 "history_size", | |
91 "ignore_function_time_stamp", | |
92 "max_recursion_depth", | |
93 "octave_core_file_format", | |
94 "octave_core_file_limit", | |
95 "octave_core_file_name", | |
96 "output_max_field_width", | |
97 "output_precision", | |
98 "page_output_immediately", | |
99 "page_screen_output", | |
100 "print_answer_id_name", | |
101 "print_empty_dimensions", | |
102 "print_rhs_assign_val", | |
103 "save_header_format_string", | |
104 "save_precision", | |
105 "saving_history", | |
106 "sighup_dumps_octave_core", | |
107 "sigterm_dumps_octave_core", | |
108 "silent_functions", | |
109 "split_long_rows", | |
110 "string_fill_char", | |
111 "struct_levels_to_print", | |
112 "suppress_verbose_help_message", | |
113 "variables_can_hide_functions", | |
114 "warn_assign_as_truth_value", | |
115 "warn_associativity_change", | |
116 "warn_divide_by_zero", | |
117 "warn_empty_list_elements", | |
118 "warn_fortran_indexing", | |
119 "warn_function_name_clash", | |
120 "warn_future_time_stamp", | |
121 "warn_imag_to_real", | |
122 "warn_matlab_incompatible", | |
123 "warn_missing_semicolon", | |
124 "warn_neg_dim_as_zero", | |
125 "warn_num_to_str", | |
126 "warn_precedence_change", | |
127 "warn_reload_forces_clear", | |
128 "warn_resize_on_range_error", | |
129 "warn_separator_insert", | |
130 "warn_single_quote_string", | |
131 "warn_str_to_num", | |
132 "warn_undefined_return_values", | |
133 "warn_variable_switch_label", | |
134 "whos_line_format", | |
135 0, | |
136 }; | |
137 | |
138 static void | |
139 maybe_warn_former_built_in_variable (const std::string& nm) | |
140 { | |
141 static bool initialized = false; | |
142 | |
143 static std::set<std::string> vars; | |
144 | |
145 if (! initialized) | |
146 { | |
147 const char **p = former_built_in_variables; | |
148 | |
149 while (*p) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
150 vars.insert (*p++); |
9224
a6422d81bee7
pt-assign.cc (maybe_warn_former_built_in_variable): set initialized to true on first call
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
151 |
a6422d81bee7
pt-assign.cc (maybe_warn_former_built_in_variable): set initialized to true on first call
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
152 initialized = true; |
6253 | 153 } |
154 | |
155 if (vars.find (nm) != vars.end ()) | |
9421
86eb5ff921d0
pt-assign.cc (maybe_warn_former_built_in_variable): improve message
John W. Eaton <jwe@octave.org>
parents:
9387
diff
changeset
|
156 { |
86eb5ff921d0
pt-assign.cc (maybe_warn_former_built_in_variable): improve message
John W. Eaton <jwe@octave.org>
parents:
9387
diff
changeset
|
157 const char *nm_c_str = nm.c_str (); |
86eb5ff921d0
pt-assign.cc (maybe_warn_former_built_in_variable): improve message
John W. Eaton <jwe@octave.org>
parents:
9387
diff
changeset
|
158 |
86eb5ff921d0
pt-assign.cc (maybe_warn_former_built_in_variable): improve message
John W. Eaton <jwe@octave.org>
parents:
9387
diff
changeset
|
159 warning_with_id ("Octave:built-in-variable-assignment", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
160 "%s is now a function instead of a built-in variable. By assigning to %s, you have created a variable that hides the function %s. To remove the variable and restore the function, type \"clear %s\"", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
161 nm_c_str, nm_c_str, nm_c_str, nm_c_str); |
9421
86eb5ff921d0
pt-assign.cc (maybe_warn_former_built_in_variable): improve message
John W. Eaton <jwe@octave.org>
parents:
9387
diff
changeset
|
162 } |
6253 | 163 } |
164 | |
165 tree_simple_assignment::tree_simple_assignment | |
166 (tree_expression *le, tree_expression *re, | |
167 bool plhs, int l, int c, octave_value::assign_op t) | |
8038 | 168 : tree_expression (l, c), lhs (le), rhs (re), preserve (plhs), etype (t), |
8037
0be8cf23b95c
check for obsolete built-in variable assignment at first execution rather than parse time
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
169 first_execution (true) { } |
6253 | 170 |
2980 | 171 tree_simple_assignment::~tree_simple_assignment (void) |
172 { | |
173 if (! preserve) | |
174 delete lhs; | |
175 | |
176 delete rhs; | |
177 } | |
178 | |
179 octave_value_list | |
180 tree_simple_assignment::rvalue (int nargout) | |
181 { | |
182 octave_value_list retval; | |
183 | |
184 if (nargout > 1) | |
185 error ("invalid number of output arguments for expression X = RHS"); | |
186 else | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8580
diff
changeset
|
187 retval = rvalue1 (nargout); |
2980 | 188 |
189 return retval; | |
190 } | |
191 | |
192 octave_value | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8580
diff
changeset
|
193 tree_simple_assignment::rvalue1 (int) |
2980 | 194 { |
3208 | 195 octave_value retval; |
2980 | 196 |
8037
0be8cf23b95c
check for obsolete built-in variable assignment at first execution rather than parse time
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
197 if (first_execution && lhs) |
0be8cf23b95c
check for obsolete built-in variable assignment at first execution rather than parse time
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
198 maybe_warn_former_built_in_variable (lhs->name ()); |
0be8cf23b95c
check for obsolete built-in variable assignment at first execution rather than parse time
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
199 |
2980 | 200 if (error_state) |
3208 | 201 return retval; |
2980 | 202 |
203 if (rhs) | |
204 { | |
8905
24dd61b36591
assign rvalue1 result to octave_value object, not octave_value_list object
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
205 octave_value rhs_val = rhs->rvalue1 (); |
2980 | 206 |
8905
24dd61b36591
assign rvalue1 result to octave_value object, not octave_value_list object
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
207 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
208 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
209 if (rhs_val.is_undefined ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
210 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
211 error ("value on right hand side of assignment is undefined"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
212 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
213 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
214 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
215 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
216 if (rhs_val.is_cs_list ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
217 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
218 const octave_value_list lst = rhs_val.list_value (); |
7389 | 219 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
220 if (! lst.empty ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
221 rhs_val = lst(0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
222 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
223 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
224 error ("invalid number of elements on RHS of assignment"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
225 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
226 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
227 } |
7389 | 228 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
229 octave_lvalue ult = lhs->lvalue (); |
2980 | 230 |
10030
83bb2a78c07d
improve simple assignments error checks and messages
Jaroslav Hajek <highegg@gmail.com>
parents:
9782
diff
changeset
|
231 if (ult.numel () != 1) |
83bb2a78c07d
improve simple assignments error checks and messages
Jaroslav Hajek <highegg@gmail.com>
parents:
9782
diff
changeset
|
232 gripe_nonbraced_cs_list_assignment (); |
83bb2a78c07d
improve simple assignments error checks and messages
Jaroslav Hajek <highegg@gmail.com>
parents:
9782
diff
changeset
|
233 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
234 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
235 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
236 ult.assign (etype, rhs_val); |
2980 | 237 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
238 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
239 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
240 if (etype == octave_value::op_asn_eq) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
241 retval = rhs_val; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
242 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
243 retval = ult.value (); |
2984 | 244 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
245 if (print_result ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
246 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
247 // We clear any index here so that we can |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
248 // get the new value of the referenced |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
249 // object below, instead of the indexed |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
250 // value (which should be the same as the |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
251 // right hand side value). |
2980 | 252 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
253 ult.clear_index (); |
3208 | 254 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
255 octave_value lhs_val = ult.value (); |
3208 | 256 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
257 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
258 lhs_val.print_with_name (octave_stdout, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
259 lhs->name ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
260 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
261 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
262 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
263 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
264 } |
2980 | 265 } |
266 | |
8037
0be8cf23b95c
check for obsolete built-in variable assignment at first execution rather than parse time
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
267 first_execution = false; |
0be8cf23b95c
check for obsolete built-in variable assignment at first execution rather than parse time
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
268 |
3208 | 269 return retval; |
2980 | 270 } |
271 | |
3536 | 272 std::string |
2980 | 273 tree_simple_assignment::oper (void) const |
274 { | |
275 return octave_value::assign_op_as_string (etype); | |
276 } | |
277 | |
5861 | 278 tree_expression * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7389
diff
changeset
|
279 tree_simple_assignment::dup (symbol_table::scope_id scope, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
280 symbol_table::context_id context) const |
5861 | 281 { |
282 tree_simple_assignment *new_sa | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7389
diff
changeset
|
283 = new tree_simple_assignment (lhs ? lhs->dup (scope, context) : 0, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
284 rhs ? rhs->dup (scope, context) : 0, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
285 preserve, etype); |
5861 | 286 |
287 new_sa->copy_base (*this); | |
288 | |
289 return new_sa; | |
290 } | |
291 | |
2980 | 292 void |
293 tree_simple_assignment::accept (tree_walker& tw) | |
294 { | |
295 tw.visit_simple_assignment (*this); | |
296 } | |
297 | |
298 // Multi-valued assignment expressions. | |
299 | |
6253 | 300 tree_multi_assignment::tree_multi_assignment |
301 (tree_argument_list *lst, tree_expression *r, | |
10230
0a5a769b8fc0
disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10227
diff
changeset
|
302 bool plhs, int l, int c) |
0a5a769b8fc0
disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10227
diff
changeset
|
303 : tree_expression (l, c), lhs (lst), rhs (r), preserve (plhs), |
8037
0be8cf23b95c
check for obsolete built-in variable assignment at first execution rather than parse time
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
304 first_execution (true) { } |
6253 | 305 |
2980 | 306 tree_multi_assignment::~tree_multi_assignment (void) |
307 { | |
308 if (! preserve) | |
309 delete lhs; | |
310 | |
311 delete rhs; | |
312 } | |
313 | |
314 octave_value | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8580
diff
changeset
|
315 tree_multi_assignment::rvalue1 (int nargout) |
2980 | 316 { |
317 octave_value retval; | |
318 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8580
diff
changeset
|
319 const octave_value_list tmp = rvalue (nargout); |
2980 | 320 |
321 if (! tmp.empty ()) | |
322 retval = tmp(0); | |
323 | |
324 return retval; | |
325 } | |
326 | |
5775 | 327 // FIXME -- this works, but it would look a little better if |
2984 | 328 // it were broken up into a couple of separate functions. |
329 | |
2980 | 330 octave_value_list |
331 tree_multi_assignment::rvalue (int) | |
332 { | |
3208 | 333 octave_value_list retval; |
2980 | 334 |
335 if (error_state) | |
3208 | 336 return retval; |
2980 | 337 |
8037
0be8cf23b95c
check for obsolete built-in variable assignment at first execution rather than parse time
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
338 if (first_execution) |
0be8cf23b95c
check for obsolete built-in variable assignment at first execution rather than parse time
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
339 { |
0be8cf23b95c
check for obsolete built-in variable assignment at first execution rather than parse time
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
340 for (tree_argument_list::iterator p = lhs->begin (); p != lhs->end (); p++) |
0be8cf23b95c
check for obsolete built-in variable assignment at first execution rather than parse time
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
341 { |
0be8cf23b95c
check for obsolete built-in variable assignment at first execution rather than parse time
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
342 tree_expression *lhs_expr = *p; |
0be8cf23b95c
check for obsolete built-in variable assignment at first execution rather than parse time
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
343 |
0be8cf23b95c
check for obsolete built-in variable assignment at first execution rather than parse time
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
344 if (lhs_expr) |
0be8cf23b95c
check for obsolete built-in variable assignment at first execution rather than parse time
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
345 maybe_warn_former_built_in_variable (lhs_expr->name ()); |
0be8cf23b95c
check for obsolete built-in variable assignment at first execution rather than parse time
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
346 } |
0be8cf23b95c
check for obsolete built-in variable assignment at first execution rather than parse time
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
347 } |
0be8cf23b95c
check for obsolete built-in variable assignment at first execution rather than parse time
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
348 |
2980 | 349 if (rhs) |
350 { | |
5846 | 351 std::list<octave_lvalue> lvalue_list = lhs->lvalue_list (); |
3977 | 352 |
353 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
354 return retval; |
2980 | 355 |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
356 octave_idx_type n_out = 0; |
5846 | 357 |
358 for (std::list<octave_lvalue>::const_iterator p = lvalue_list.begin (); | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
359 p != lvalue_list.end (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
360 p++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
361 n_out += p->numel (); |
5846 | 362 |
8580
188d38a553c7
further indexing optimization touches
Jaroslav Hajek <highegg@gmail.com>
parents:
8313
diff
changeset
|
363 // The following trick is used to keep rhs_val constant. |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
364 const octave_value_list rhs_val1 = rhs->rvalue (n_out, &lvalue_list); |
8580
188d38a553c7
further indexing optimization touches
Jaroslav Hajek <highegg@gmail.com>
parents:
8313
diff
changeset
|
365 const octave_value_list rhs_val = (rhs_val1.length () == 1 && rhs_val1(0).is_cs_list () |
188d38a553c7
further indexing optimization touches
Jaroslav Hajek <highegg@gmail.com>
parents:
8313
diff
changeset
|
366 ? rhs_val1(0).list_value () : rhs_val1); |
2980 | 367 |
3977 | 368 if (error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
369 return retval; |
2980 | 370 |
9782
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
371 octave_idx_type k = 0; |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
372 |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
373 octave_idx_type n = rhs_val.length (); |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
374 |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
375 // To avoid copying per elements and possible optimizations, we |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
376 // postpone joining the final values. |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
377 std::list<octave_value_list> retval_list; |
2980 | 378 |
9782
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
379 tree_argument_list::iterator q = lhs->begin (); |
2980 | 380 |
9782
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
381 for (std::list<octave_lvalue>::iterator p = lvalue_list.begin (); |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
382 p != lvalue_list.end (); |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
383 p++) |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
384 { |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
385 tree_expression *lhs_elt = *q++; |
5846 | 386 |
9782
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
387 octave_lvalue ult = *p; |
5846 | 388 |
9782
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
389 octave_idx_type nel = ult.numel (); |
3977 | 390 |
9782
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
391 if (nel != 1) |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
392 { |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
393 if (k + nel <= n) |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
394 { |
10230
0a5a769b8fc0
disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10227
diff
changeset
|
395 // This won't do a copy. |
0a5a769b8fc0
disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10227
diff
changeset
|
396 octave_value_list ovl = rhs_val.slice (k, nel); |
5846 | 397 |
10230
0a5a769b8fc0
disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10227
diff
changeset
|
398 ult.assign (octave_value::op_asn_eq, octave_value (ovl, true)); |
2980 | 399 |
10230
0a5a769b8fc0
disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10227
diff
changeset
|
400 if (! error_state) |
0a5a769b8fc0
disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10227
diff
changeset
|
401 { |
0a5a769b8fc0
disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10227
diff
changeset
|
402 retval_list.push_back (ovl); |
5846 | 403 |
10230
0a5a769b8fc0
disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10227
diff
changeset
|
404 k += nel; |
9782
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
405 } |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
406 } |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
407 else |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
408 error ("some elements undefined in return list"); |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
409 } |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
410 else |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
411 { |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
412 if (k < n) |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
413 { |
10230
0a5a769b8fc0
disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10227
diff
changeset
|
414 ult.assign (octave_value::op_asn_eq, rhs_val(k)); |
3977 | 415 |
10227
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
416 if (ult.is_black_hole ()) |
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
417 { |
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
418 k++; |
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
419 continue; |
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
420 } |
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
421 else if (! error_state) |
9782
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
422 { |
10230
0a5a769b8fc0
disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10227
diff
changeset
|
423 retval_list.push_back (rhs_val(k)); |
5846 | 424 |
9782
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
425 k++; |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
426 } |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
427 } |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
428 else |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
429 error ("element number %d undefined in return list", k+1); |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
430 } |
2980 | 431 |
9782
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
432 if (error_state) |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
433 break; |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
434 else if (print_result ()) |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
435 { |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
436 // We clear any index here so that we can get |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
437 // the new value of the referenced object below, |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
438 // instead of the indexed value (which should be |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
439 // the same as the right hand side value). |
3977 | 440 |
9782
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
441 ult.clear_index (); |
3208 | 442 |
9782
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
443 octave_value lhs_val = ult.value (); |
3977 | 444 |
9782
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
445 if (! error_state) |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
446 lhs_val.print_with_name (octave_stdout, |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
447 lhs_elt->name ()); |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
448 } |
3977 | 449 |
9782
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
450 if (error_state) |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
451 break; |
3977 | 452 |
9782
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
453 } |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
454 |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
455 // Concatenate return values. |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
456 retval = retval_list; |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
457 |
2980 | 458 } |
459 | |
8037
0be8cf23b95c
check for obsolete built-in variable assignment at first execution rather than parse time
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
460 first_execution = false; |
0be8cf23b95c
check for obsolete built-in variable assignment at first execution rather than parse time
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
461 |
3208 | 462 return retval; |
2980 | 463 } |
464 | |
3536 | 465 std::string |
3208 | 466 tree_multi_assignment::oper (void) const |
467 { | |
10230
0a5a769b8fc0
disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10227
diff
changeset
|
468 return octave_value::assign_op_as_string (op_type ()); |
3208 | 469 } |
470 | |
5861 | 471 tree_expression * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7389
diff
changeset
|
472 tree_multi_assignment::dup (symbol_table::scope_id scope, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
473 symbol_table::context_id context) const |
5861 | 474 { |
475 tree_multi_assignment *new_ma | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7389
diff
changeset
|
476 = new tree_multi_assignment (lhs ? lhs->dup (scope, context) : 0, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
477 rhs ? rhs->dup (scope, context) : 0, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
478 preserve); |
5861 | 479 |
480 new_ma->copy_base (*this); | |
481 | |
482 return new_ma; | |
483 } | |
484 | |
2980 | 485 void |
486 tree_multi_assignment::accept (tree_walker& tw) | |
487 { | |
488 tw.visit_multi_assignment (*this); | |
489 } |