Mercurial > hg > octave-lyh
annotate src/pt-assign.cc @ 14495:319660795df1
Fix gnuplot error when color values are within eps of each other (bug #35761).
* plot/private/__go_draw_axes__.m: Use %.15e for setting cbrange in gnuplot.
author | Marco Caliari <marco.caliari@univr.it> |
---|---|
date | Sun, 25 Mar 2012 13:53:39 -0700 |
parents | 72c96de7a403 |
children | 000cd393f3c1 |
rev | line source |
---|---|
2980 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14048
diff
changeset
|
3 Copyright (C) 1996-2012 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", | |
14048
fafd2f45bfa5
Change "default_save_format" to "default_save_options" in former_built_in_variables list.
Kris Thielemans <kris.f.thielemans@gmail.com>
parents:
13867
diff
changeset
|
76 "default_save_options", |
6253 | 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", |
13867
922bfdd80413
Clean up help about old flags for debug variables
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11523
diff
changeset
|
160 "\ |
922bfdd80413
Clean up help about old flags for debug variables
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11523
diff
changeset
|
161 In recent versions of Octave, %s is a function instead\n\ |
922bfdd80413
Clean up help about old flags for debug variables
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11523
diff
changeset
|
162 of a built-in variable.\n\n\ |
922bfdd80413
Clean up help about old flags for debug variables
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11523
diff
changeset
|
163 By assigning to %s, you have created a variable that hides\n\ |
922bfdd80413
Clean up help about old flags for debug variables
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11523
diff
changeset
|
164 the function %s. To remove the variable and restore the \n\ |
922bfdd80413
Clean up help about old flags for debug variables
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11523
diff
changeset
|
165 function, type \"clear %s\"\n", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
166 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
|
167 } |
6253 | 168 } |
169 | |
170 tree_simple_assignment::tree_simple_assignment | |
171 (tree_expression *le, tree_expression *re, | |
172 bool plhs, int l, int c, octave_value::assign_op t) | |
8038 | 173 : 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
|
174 first_execution (true) { } |
6253 | 175 |
2980 | 176 tree_simple_assignment::~tree_simple_assignment (void) |
177 { | |
178 if (! preserve) | |
179 delete lhs; | |
180 | |
181 delete rhs; | |
182 } | |
183 | |
184 octave_value_list | |
185 tree_simple_assignment::rvalue (int nargout) | |
186 { | |
187 octave_value_list retval; | |
188 | |
189 if (nargout > 1) | |
190 error ("invalid number of output arguments for expression X = RHS"); | |
191 else | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8580
diff
changeset
|
192 retval = rvalue1 (nargout); |
2980 | 193 |
194 return retval; | |
195 } | |
196 | |
197 octave_value | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8580
diff
changeset
|
198 tree_simple_assignment::rvalue1 (int) |
2980 | 199 { |
3208 | 200 octave_value retval; |
2980 | 201 |
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
|
202 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
|
203 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
|
204 |
2980 | 205 if (error_state) |
3208 | 206 return retval; |
2980 | 207 |
208 if (rhs) | |
209 { | |
8905
24dd61b36591
assign rvalue1 result to octave_value object, not octave_value_list object
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
210 octave_value rhs_val = rhs->rvalue1 (); |
2980 | 211 |
8905
24dd61b36591
assign rvalue1 result to octave_value object, not octave_value_list object
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
212 if (! error_state) |
10315
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 if (rhs_val.is_undefined ()) |
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 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
|
217 return retval; |
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 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
220 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
221 if (rhs_val.is_cs_list ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
222 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
223 const octave_value_list lst = rhs_val.list_value (); |
7389 | 224 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
225 if (! lst.empty ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
226 rhs_val = lst(0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
227 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
228 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
229 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
|
230 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
231 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
232 } |
7389 | 233 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
234 octave_lvalue ult = lhs->lvalue (); |
2980 | 235 |
10030
83bb2a78c07d
improve simple assignments error checks and messages
Jaroslav Hajek <highegg@gmail.com>
parents:
9782
diff
changeset
|
236 if (ult.numel () != 1) |
83bb2a78c07d
improve simple assignments error checks and messages
Jaroslav Hajek <highegg@gmail.com>
parents:
9782
diff
changeset
|
237 gripe_nonbraced_cs_list_assignment (); |
83bb2a78c07d
improve simple assignments error checks and messages
Jaroslav Hajek <highegg@gmail.com>
parents:
9782
diff
changeset
|
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 ult.assign (etype, rhs_val); |
2980 | 242 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
243 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
244 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
245 if (etype == octave_value::op_asn_eq) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
246 retval = rhs_val; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
247 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
248 retval = ult.value (); |
2984 | 249 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
250 if (print_result ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
251 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
252 // 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
|
253 // get the new value of the referenced |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
254 // object below, instead of the indexed |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
255 // value (which should be the same as the |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
256 // right hand side value). |
2980 | 257 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
258 ult.clear_index (); |
3208 | 259 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
260 octave_value lhs_val = ult.value (); |
3208 | 261 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
262 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
263 lhs_val.print_with_name (octave_stdout, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
264 lhs->name ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
265 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
266 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
267 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
268 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
269 } |
2980 | 270 } |
271 | |
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
|
272 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
|
273 |
3208 | 274 return retval; |
2980 | 275 } |
276 | |
3536 | 277 std::string |
2980 | 278 tree_simple_assignment::oper (void) const |
279 { | |
280 return octave_value::assign_op_as_string (etype); | |
281 } | |
282 | |
5861 | 283 tree_expression * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7389
diff
changeset
|
284 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
|
285 symbol_table::context_id context) const |
5861 | 286 { |
287 tree_simple_assignment *new_sa | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7389
diff
changeset
|
288 = 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
|
289 rhs ? rhs->dup (scope, context) : 0, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
290 preserve, etype); |
5861 | 291 |
292 new_sa->copy_base (*this); | |
293 | |
294 return new_sa; | |
295 } | |
296 | |
2980 | 297 void |
298 tree_simple_assignment::accept (tree_walker& tw) | |
299 { | |
300 tw.visit_simple_assignment (*this); | |
301 } | |
302 | |
303 // Multi-valued assignment expressions. | |
304 | |
6253 | 305 tree_multi_assignment::tree_multi_assignment |
306 (tree_argument_list *lst, tree_expression *r, | |
10230
0a5a769b8fc0
disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10227
diff
changeset
|
307 bool plhs, int l, int c) |
0a5a769b8fc0
disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10227
diff
changeset
|
308 : 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
|
309 first_execution (true) { } |
6253 | 310 |
2980 | 311 tree_multi_assignment::~tree_multi_assignment (void) |
312 { | |
313 if (! preserve) | |
314 delete lhs; | |
315 | |
316 delete rhs; | |
317 } | |
318 | |
319 octave_value | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8580
diff
changeset
|
320 tree_multi_assignment::rvalue1 (int nargout) |
2980 | 321 { |
322 octave_value retval; | |
323 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8580
diff
changeset
|
324 const octave_value_list tmp = rvalue (nargout); |
2980 | 325 |
326 if (! tmp.empty ()) | |
327 retval = tmp(0); | |
328 | |
329 return retval; | |
330 } | |
331 | |
5775 | 332 // FIXME -- this works, but it would look a little better if |
2984 | 333 // it were broken up into a couple of separate functions. |
334 | |
2980 | 335 octave_value_list |
336 tree_multi_assignment::rvalue (int) | |
337 { | |
3208 | 338 octave_value_list retval; |
2980 | 339 |
340 if (error_state) | |
3208 | 341 return retval; |
2980 | 342 |
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
|
343 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
|
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 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
|
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 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
|
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 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
|
350 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
|
351 } |
0be8cf23b95c
check for obsolete built-in variable assignment at first execution rather than parse time
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
352 } |
0be8cf23b95c
check for obsolete built-in variable assignment at first execution rather than parse time
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
353 |
2980 | 354 if (rhs) |
355 { | |
5846 | 356 std::list<octave_lvalue> lvalue_list = lhs->lvalue_list (); |
3977 | 357 |
358 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
359 return retval; |
2980 | 360 |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
361 octave_idx_type n_out = 0; |
5846 | 362 |
363 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
|
364 p != lvalue_list.end (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
365 p++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
366 n_out += p->numel (); |
5846 | 367 |
8580
188d38a553c7
further indexing optimization touches
Jaroslav Hajek <highegg@gmail.com>
parents:
8313
diff
changeset
|
368 // 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
|
369 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
|
370 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
|
371 ? rhs_val1(0).list_value () : rhs_val1); |
2980 | 372 |
3977 | 373 if (error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
374 return retval; |
2980 | 375 |
9782
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
376 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
|
377 |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
378 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
|
379 |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
380 // 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
|
381 // 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
|
382 std::list<octave_value_list> retval_list; |
2980 | 383 |
9782
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
384 tree_argument_list::iterator q = lhs->begin (); |
2980 | 385 |
9782
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
386 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
|
387 p != lvalue_list.end (); |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
388 p++) |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
389 { |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
390 tree_expression *lhs_elt = *q++; |
5846 | 391 |
9782
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
392 octave_lvalue ult = *p; |
5846 | 393 |
9782
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
394 octave_idx_type nel = ult.numel (); |
3977 | 395 |
9782
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
396 if (nel != 1) |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
397 { |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
398 if (k + nel <= n) |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
399 { |
10230
0a5a769b8fc0
disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10227
diff
changeset
|
400 // This won't do a copy. |
0a5a769b8fc0
disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10227
diff
changeset
|
401 octave_value_list ovl = rhs_val.slice (k, nel); |
5846 | 402 |
10230
0a5a769b8fc0
disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10227
diff
changeset
|
403 ult.assign (octave_value::op_asn_eq, octave_value (ovl, true)); |
2980 | 404 |
10230
0a5a769b8fc0
disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10227
diff
changeset
|
405 if (! error_state) |
0a5a769b8fc0
disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10227
diff
changeset
|
406 { |
0a5a769b8fc0
disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10227
diff
changeset
|
407 retval_list.push_back (ovl); |
5846 | 408 |
10230
0a5a769b8fc0
disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10227
diff
changeset
|
409 k += nel; |
9782
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 } |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
412 else |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
413 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
|
414 } |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
415 else |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
416 { |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
417 if (k < n) |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
418 { |
10230
0a5a769b8fc0
disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10227
diff
changeset
|
419 ult.assign (octave_value::op_asn_eq, rhs_val(k)); |
3977 | 420 |
10227
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
421 if (ult.is_black_hole ()) |
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
422 { |
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
423 k++; |
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
424 continue; |
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
425 } |
d3fc22c3071c
omit ~ values from multi-assignment return lists
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
426 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
|
427 { |
10230
0a5a769b8fc0
disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10227
diff
changeset
|
428 retval_list.push_back (rhs_val(k)); |
5846 | 429 |
9782
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
430 k++; |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
431 } |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
432 } |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
433 else |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
434 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
|
435 } |
2980 | 436 |
9782
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
437 if (error_state) |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
438 break; |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
439 else if (print_result ()) |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
440 { |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
441 // 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
|
442 // 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
|
443 // 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
|
444 // the same as the right hand side 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 ult.clear_index (); |
3208 | 447 |
9782
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
448 octave_value lhs_val = ult.value (); |
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 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
|
452 lhs_elt->name ()); |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
453 } |
3977 | 454 |
9782
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
455 if (error_state) |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
456 break; |
3977 | 457 |
9782
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
458 } |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
459 |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
460 // Concatenate return values. |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
461 retval = retval_list; |
eead00a7df05
don't skip empty multi-assignments to allow side effects
Jaroslav Hajek <highegg@gmail.com>
parents:
9421
diff
changeset
|
462 |
2980 | 463 } |
464 | |
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
|
465 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
|
466 |
3208 | 467 return retval; |
2980 | 468 } |
469 | |
3536 | 470 std::string |
3208 | 471 tree_multi_assignment::oper (void) const |
472 { | |
10230
0a5a769b8fc0
disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10227
diff
changeset
|
473 return octave_value::assign_op_as_string (op_type ()); |
3208 | 474 } |
475 | |
5861 | 476 tree_expression * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7389
diff
changeset
|
477 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
|
478 symbol_table::context_id context) const |
5861 | 479 { |
480 tree_multi_assignment *new_ma | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7389
diff
changeset
|
481 = 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
|
482 rhs ? rhs->dup (scope, context) : 0, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10230
diff
changeset
|
483 preserve); |
5861 | 484 |
485 new_ma->copy_base (*this); | |
486 | |
487 return new_ma; | |
488 } | |
489 | |
2980 | 490 void |
491 tree_multi_assignment::accept (tree_walker& tw) | |
492 { | |
493 tw.visit_multi_assignment (*this); | |
494 } |