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