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 |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
577
|
20 |
|
21 */ |
|
22 |
4192
|
23 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
1297
|
24 #pragma implementation |
|
25 #endif |
|
26 |
577
|
27 #ifdef HAVE_CONFIG_H |
1192
|
28 #include <config.h> |
577
|
29 #endif |
|
30 |
4466
|
31 #include "defun.h" |
2982
|
32 #include "error.h" |
|
33 #include "ov.h" |
|
34 #include "oct-lvalue.h" |
|
35 #include "pt-id.h" |
|
36 #include "pt-idx.h" |
|
37 #include "pt-misc.h" |
|
38 #include "pt-walk.h" |
4466
|
39 #include "utils.h" |
|
40 |
|
41 // If TRUE, print a warning if a function does not define all the |
|
42 // values in the return list which are expected. |
|
43 static bool Vwarn_undefined_return_values; |
581
|
44 |
577
|
45 // Parameter lists. |
|
46 |
1742
|
47 tree_parameter_list::~tree_parameter_list (void) |
|
48 { |
4219
|
49 while (! empty ()) |
1742
|
50 { |
4219
|
51 iterator p = begin (); |
|
52 delete *p; |
|
53 erase (p); |
1742
|
54 } |
|
55 } |
|
56 |
577
|
57 void |
|
58 tree_parameter_list::mark_as_formal_parameters (void) |
|
59 { |
4219
|
60 for (iterator p = begin (); p != end (); p++) |
577
|
61 { |
4219
|
62 tree_identifier *elt = *p; |
577
|
63 elt->mark_as_formal_parameter (); |
|
64 } |
|
65 } |
|
66 |
|
67 void |
4466
|
68 tree_parameter_list::initialize_undefined_elements (const std::string& warnfor, |
|
69 int nargout, |
|
70 const octave_value& val) |
1093
|
71 { |
4466
|
72 bool warned = false; |
|
73 |
|
74 int count = 0; |
|
75 |
4219
|
76 for (iterator p = begin (); p != end (); p++) |
1093
|
77 { |
4466
|
78 if (++count > nargout) |
|
79 break; |
|
80 |
4219
|
81 tree_identifier *elt = *p; |
2948
|
82 |
1093
|
83 if (! elt->is_defined ()) |
2973
|
84 { |
4466
|
85 if (Vwarn_undefined_return_values && ! warned) |
|
86 { |
|
87 warned = true; |
|
88 warning ("%s: some elements in list of return values are undefined", |
|
89 warnfor.c_str ()); |
|
90 } |
|
91 |
2979
|
92 octave_lvalue tmp = elt->lvalue (); |
2973
|
93 |
3538
|
94 tmp.assign (octave_value::op_asn_eq, val); |
2973
|
95 } |
1093
|
96 } |
|
97 } |
|
98 |
|
99 void |
2086
|
100 tree_parameter_list::define_from_arg_vector (const octave_value_list& args) |
577
|
101 { |
712
|
102 int nargin = args.length (); |
|
103 |
|
104 if (nargin <= 0) |
577
|
105 return; |
|
106 |
712
|
107 int expected_nargin = length (); |
577
|
108 |
4219
|
109 iterator p = begin (); |
577
|
110 |
712
|
111 for (int i = 0; i < expected_nargin; i++) |
577
|
112 { |
4219
|
113 tree_identifier *elt = *p++; |
577
|
114 |
2979
|
115 octave_lvalue ref = elt->lvalue (); |
2959
|
116 |
577
|
117 if (i < nargin) |
|
118 { |
620
|
119 if (args(i).is_defined () && args(i).is_magic_colon ()) |
577
|
120 { |
|
121 ::error ("invalid use of colon in function argument list"); |
|
122 return; |
|
123 } |
2891
|
124 |
3538
|
125 ref.assign (octave_value::op_asn_eq, args(i)); |
577
|
126 } |
2891
|
127 else |
3538
|
128 ref.assign (octave_value::op_asn_eq, octave_value ()); |
577
|
129 } |
|
130 } |
|
131 |
3239
|
132 void |
4219
|
133 tree_parameter_list::undefine (void) |
3239
|
134 { |
|
135 int len = length (); |
|
136 |
4219
|
137 iterator p = begin (); |
3239
|
138 |
|
139 for (int i = 0; i < len; i++) |
|
140 { |
4219
|
141 tree_identifier *elt = *p++; |
3239
|
142 |
|
143 octave_lvalue ref = elt->lvalue (); |
|
144 |
3538
|
145 ref.assign (octave_value::op_asn_eq, octave_value ()); |
3239
|
146 } |
|
147 } |
|
148 |
2086
|
149 octave_value_list |
723
|
150 tree_parameter_list::convert_to_const_vector (tree_va_return_list *vr_list) |
577
|
151 { |
|
152 int nout = length (); |
|
153 |
723
|
154 if (vr_list) |
|
155 nout += vr_list->length (); |
|
156 |
2086
|
157 octave_value_list retval; |
577
|
158 retval.resize (nout); |
|
159 |
|
160 int i = 0; |
|
161 |
4219
|
162 for (iterator p = begin (); p != end (); p++) |
577
|
163 { |
4219
|
164 tree_identifier *elt = *p; |
577
|
165 |
4465
|
166 retval(i++) = elt->is_defined () ? elt->rvalue () : octave_value (); |
577
|
167 } |
|
168 |
723
|
169 if (vr_list) |
|
170 { |
4219
|
171 for (tree_va_return_list::iterator p = vr_list->begin (); |
|
172 p != vr_list->end (); |
|
173 p++) |
723
|
174 { |
4219
|
175 retval(i++) = *p; |
723
|
176 } |
|
177 } |
|
178 |
577
|
179 return retval; |
|
180 } |
|
181 |
1827
|
182 bool |
577
|
183 tree_parameter_list::is_defined (void) |
|
184 { |
1827
|
185 bool status = true; |
577
|
186 |
4219
|
187 for (iterator p = begin (); p != end (); p++) |
577
|
188 { |
4219
|
189 tree_identifier *elt = *p; |
577
|
190 |
|
191 if (! elt->is_defined ()) |
|
192 { |
1827
|
193 status = false; |
577
|
194 break; |
|
195 } |
|
196 } |
|
197 |
|
198 return status; |
|
199 } |
|
200 |
|
201 void |
2124
|
202 tree_parameter_list::accept (tree_walker& tw) |
581
|
203 { |
2124
|
204 tw.visit_parameter_list (*this); |
581
|
205 } |
|
206 |
|
207 // Return lists. |
|
208 |
1742
|
209 tree_return_list::~tree_return_list (void) |
|
210 { |
4219
|
211 while (! empty ()) |
1742
|
212 { |
4219
|
213 iterator p = begin (); |
|
214 delete *p; |
|
215 erase (p); |
1742
|
216 } |
|
217 } |
|
218 |
581
|
219 void |
2124
|
220 tree_return_list::accept (tree_walker& tw) |
581
|
221 { |
2124
|
222 tw.visit_return_list (*this); |
581
|
223 } |
|
224 |
4466
|
225 static int |
|
226 warn_undefined_return_values (void) |
|
227 { |
|
228 Vwarn_undefined_return_values |
|
229 = check_preference ("warn_undefined_return_values"); |
|
230 |
|
231 return 0; |
|
232 } |
|
233 |
|
234 void |
|
235 symbols_of_pt_misc (void) |
|
236 { |
|
237 DEFVAR (warn_undefined_return_values, true, warn_undefined_return_values, |
|
238 "-*- texinfo -*-\n\ |
|
239 @defvr {Built-in Variable} warn_undefined_return_values\n\ |
|
240 If the value of @code{warn_undefined_return_values} is nonzero,\n\ |
|
241 print a warning if a function does not define all the values in\n\ |
|
242 the return list which are expected. The default value is 1.\n\ |
|
243 @end defvr"); |
|
244 } |
|
245 |
577
|
246 /* |
|
247 ;;; Local Variables: *** |
|
248 ;;; mode: C++ *** |
|
249 ;;; End: *** |
|
250 */ |