577
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
577
|
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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
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 |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
577
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
1192
|
25 #include <config.h> |
577
|
26 #endif |
|
27 |
5848
|
28 #include "Cell.h" |
|
29 |
4466
|
30 #include "defun.h" |
2982
|
31 #include "error.h" |
|
32 #include "ov.h" |
|
33 #include "oct-lvalue.h" |
|
34 #include "pt-id.h" |
|
35 #include "pt-idx.h" |
|
36 #include "pt-misc.h" |
|
37 #include "pt-walk.h" |
4466
|
38 #include "utils.h" |
|
39 |
577
|
40 // Parameter lists. |
|
41 |
1742
|
42 tree_parameter_list::~tree_parameter_list (void) |
|
43 { |
4219
|
44 while (! empty ()) |
1742
|
45 { |
4219
|
46 iterator p = begin (); |
|
47 delete *p; |
|
48 erase (p); |
1742
|
49 } |
|
50 } |
|
51 |
577
|
52 void |
|
53 tree_parameter_list::mark_as_formal_parameters (void) |
|
54 { |
4219
|
55 for (iterator p = begin (); p != end (); p++) |
577
|
56 { |
4219
|
57 tree_identifier *elt = *p; |
577
|
58 elt->mark_as_formal_parameter (); |
|
59 } |
|
60 } |
|
61 |
|
62 void |
4466
|
63 tree_parameter_list::initialize_undefined_elements (const std::string& warnfor, |
|
64 int nargout, |
|
65 const octave_value& val) |
1093
|
66 { |
4466
|
67 bool warned = false; |
|
68 |
|
69 int count = 0; |
|
70 |
4219
|
71 for (iterator p = begin (); p != end (); p++) |
1093
|
72 { |
4466
|
73 if (++count > nargout) |
|
74 break; |
|
75 |
4219
|
76 tree_identifier *elt = *p; |
2948
|
77 |
1093
|
78 if (! elt->is_defined ()) |
2973
|
79 { |
5781
|
80 if (! warned) |
4466
|
81 { |
|
82 warned = true; |
5781
|
83 |
|
84 warning_with_id |
|
85 ("Octave:undefined-return-values", |
|
86 "%s: some elements in list of return values are undefined", |
|
87 warnfor.c_str ()); |
4466
|
88 } |
|
89 |
2979
|
90 octave_lvalue tmp = elt->lvalue (); |
2973
|
91 |
3538
|
92 tmp.assign (octave_value::op_asn_eq, val); |
2973
|
93 } |
1093
|
94 } |
|
95 } |
|
96 |
|
97 void |
2086
|
98 tree_parameter_list::define_from_arg_vector (const octave_value_list& args) |
577
|
99 { |
712
|
100 int nargin = args.length (); |
|
101 |
|
102 if (nargin <= 0) |
577
|
103 return; |
|
104 |
712
|
105 int expected_nargin = length (); |
577
|
106 |
4219
|
107 iterator p = begin (); |
577
|
108 |
712
|
109 for (int i = 0; i < expected_nargin; i++) |
577
|
110 { |
4219
|
111 tree_identifier *elt = *p++; |
577
|
112 |
2979
|
113 octave_lvalue ref = elt->lvalue (); |
2959
|
114 |
577
|
115 if (i < nargin) |
|
116 { |
620
|
117 if (args(i).is_defined () && args(i).is_magic_colon ()) |
577
|
118 { |
|
119 ::error ("invalid use of colon in function argument list"); |
|
120 return; |
|
121 } |
2891
|
122 |
3538
|
123 ref.assign (octave_value::op_asn_eq, args(i)); |
577
|
124 } |
2891
|
125 else |
3538
|
126 ref.assign (octave_value::op_asn_eq, octave_value ()); |
577
|
127 } |
|
128 } |
|
129 |
3239
|
130 void |
4219
|
131 tree_parameter_list::undefine (void) |
3239
|
132 { |
|
133 int len = length (); |
|
134 |
4219
|
135 iterator p = begin (); |
3239
|
136 |
|
137 for (int i = 0; i < len; i++) |
|
138 { |
4219
|
139 tree_identifier *elt = *p++; |
3239
|
140 |
|
141 octave_lvalue ref = elt->lvalue (); |
|
142 |
3538
|
143 ref.assign (octave_value::op_asn_eq, octave_value ()); |
3239
|
144 } |
|
145 } |
|
146 |
2086
|
147 octave_value_list |
5848
|
148 tree_parameter_list::convert_to_const_vector (const Cell& varargout) |
577
|
149 { |
5848
|
150 octave_idx_type vlen = varargout.numel (); |
577
|
151 |
5848
|
152 int nout = length () + vlen; |
723
|
153 |
5848
|
154 octave_value_list retval (nout, octave_value ()); |
577
|
155 |
|
156 int i = 0; |
|
157 |
4219
|
158 for (iterator p = begin (); p != end (); p++) |
577
|
159 { |
4219
|
160 tree_identifier *elt = *p; |
577
|
161 |
4465
|
162 retval(i++) = elt->is_defined () ? elt->rvalue () : octave_value (); |
577
|
163 } |
|
164 |
5848
|
165 for (octave_idx_type j = 0; j < vlen; j++) |
|
166 retval(i++) = varargout(j); |
723
|
167 |
577
|
168 return retval; |
|
169 } |
|
170 |
1827
|
171 bool |
577
|
172 tree_parameter_list::is_defined (void) |
|
173 { |
1827
|
174 bool status = true; |
577
|
175 |
4219
|
176 for (iterator p = begin (); p != end (); p++) |
577
|
177 { |
4219
|
178 tree_identifier *elt = *p; |
577
|
179 |
|
180 if (! elt->is_defined ()) |
|
181 { |
1827
|
182 status = false; |
577
|
183 break; |
|
184 } |
|
185 } |
|
186 |
|
187 return status; |
|
188 } |
|
189 |
5861
|
190 tree_parameter_list * |
|
191 tree_parameter_list::dup (symbol_table *sym_tab) |
|
192 { |
|
193 tree_parameter_list *new_list = new tree_parameter_list (); |
|
194 |
|
195 if (takes_varargs ()) |
|
196 new_list->mark_varargs (); |
|
197 |
|
198 for (iterator p = begin (); p != end (); p++) |
|
199 { |
|
200 tree_identifier *elt = *p; |
|
201 |
|
202 new_list->append (elt->dup (sym_tab)); |
|
203 } |
|
204 |
|
205 return new_list; |
|
206 } |
|
207 |
577
|
208 void |
2124
|
209 tree_parameter_list::accept (tree_walker& tw) |
581
|
210 { |
2124
|
211 tw.visit_parameter_list (*this); |
581
|
212 } |
|
213 |
|
214 // Return lists. |
|
215 |
1742
|
216 tree_return_list::~tree_return_list (void) |
|
217 { |
4219
|
218 while (! empty ()) |
1742
|
219 { |
4219
|
220 iterator p = begin (); |
|
221 delete *p; |
|
222 erase (p); |
1742
|
223 } |
|
224 } |
|
225 |
5861
|
226 tree_return_list * |
|
227 tree_return_list::dup (symbol_table *sym_tab) |
|
228 { |
|
229 tree_return_list *new_list = new tree_return_list (); |
|
230 |
|
231 for (iterator p = begin (); p != end (); p++) |
|
232 { |
|
233 tree_index_expression *elt = *p; |
|
234 |
|
235 new_list->append (elt->dup (sym_tab)); |
|
236 } |
|
237 |
|
238 return new_list; |
|
239 } |
|
240 |
581
|
241 void |
2124
|
242 tree_return_list::accept (tree_walker& tw) |
581
|
243 { |
2124
|
244 tw.visit_return_list (*this); |
581
|
245 } |
|
246 |
577
|
247 /* |
|
248 ;;; Local Variables: *** |
|
249 ;;; mode: C++ *** |
|
250 ;;; End: *** |
|
251 */ |