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 |
4466
|
28 #include "defun.h" |
2982
|
29 #include "error.h" |
|
30 #include "ov.h" |
|
31 #include "oct-lvalue.h" |
|
32 #include "pt-id.h" |
|
33 #include "pt-idx.h" |
|
34 #include "pt-misc.h" |
|
35 #include "pt-walk.h" |
4466
|
36 #include "utils.h" |
|
37 |
577
|
38 // Parameter lists. |
|
39 |
1742
|
40 tree_parameter_list::~tree_parameter_list (void) |
|
41 { |
4219
|
42 while (! empty ()) |
1742
|
43 { |
4219
|
44 iterator p = begin (); |
|
45 delete *p; |
|
46 erase (p); |
1742
|
47 } |
|
48 } |
|
49 |
577
|
50 void |
|
51 tree_parameter_list::mark_as_formal_parameters (void) |
|
52 { |
4219
|
53 for (iterator p = begin (); p != end (); p++) |
577
|
54 { |
4219
|
55 tree_identifier *elt = *p; |
577
|
56 elt->mark_as_formal_parameter (); |
|
57 } |
|
58 } |
|
59 |
|
60 void |
4466
|
61 tree_parameter_list::initialize_undefined_elements (const std::string& warnfor, |
|
62 int nargout, |
|
63 const octave_value& val) |
1093
|
64 { |
4466
|
65 bool warned = false; |
|
66 |
|
67 int count = 0; |
|
68 |
4219
|
69 for (iterator p = begin (); p != end (); p++) |
1093
|
70 { |
4466
|
71 if (++count > nargout) |
|
72 break; |
|
73 |
4219
|
74 tree_identifier *elt = *p; |
2948
|
75 |
1093
|
76 if (! elt->is_defined ()) |
2973
|
77 { |
5781
|
78 if (! warned) |
4466
|
79 { |
|
80 warned = true; |
5781
|
81 |
|
82 warning_with_id |
|
83 ("Octave:undefined-return-values", |
|
84 "%s: some elements in list of return values are undefined", |
|
85 warnfor.c_str ()); |
4466
|
86 } |
|
87 |
2979
|
88 octave_lvalue tmp = elt->lvalue (); |
2973
|
89 |
3538
|
90 tmp.assign (octave_value::op_asn_eq, val); |
2973
|
91 } |
1093
|
92 } |
|
93 } |
|
94 |
|
95 void |
2086
|
96 tree_parameter_list::define_from_arg_vector (const octave_value_list& args) |
577
|
97 { |
712
|
98 int nargin = args.length (); |
|
99 |
|
100 if (nargin <= 0) |
577
|
101 return; |
|
102 |
712
|
103 int expected_nargin = length (); |
577
|
104 |
4219
|
105 iterator p = begin (); |
577
|
106 |
712
|
107 for (int i = 0; i < expected_nargin; i++) |
577
|
108 { |
4219
|
109 tree_identifier *elt = *p++; |
577
|
110 |
2979
|
111 octave_lvalue ref = elt->lvalue (); |
2959
|
112 |
577
|
113 if (i < nargin) |
|
114 { |
620
|
115 if (args(i).is_defined () && args(i).is_magic_colon ()) |
577
|
116 { |
|
117 ::error ("invalid use of colon in function argument list"); |
|
118 return; |
|
119 } |
2891
|
120 |
3538
|
121 ref.assign (octave_value::op_asn_eq, args(i)); |
577
|
122 } |
2891
|
123 else |
3538
|
124 ref.assign (octave_value::op_asn_eq, octave_value ()); |
577
|
125 } |
|
126 } |
|
127 |
3239
|
128 void |
4219
|
129 tree_parameter_list::undefine (void) |
3239
|
130 { |
|
131 int len = length (); |
|
132 |
4219
|
133 iterator p = begin (); |
3239
|
134 |
|
135 for (int i = 0; i < len; i++) |
|
136 { |
4219
|
137 tree_identifier *elt = *p++; |
3239
|
138 |
|
139 octave_lvalue ref = elt->lvalue (); |
|
140 |
3538
|
141 ref.assign (octave_value::op_asn_eq, octave_value ()); |
3239
|
142 } |
|
143 } |
|
144 |
2086
|
145 octave_value_list |
723
|
146 tree_parameter_list::convert_to_const_vector (tree_va_return_list *vr_list) |
577
|
147 { |
|
148 int nout = length (); |
|
149 |
723
|
150 if (vr_list) |
|
151 nout += vr_list->length (); |
|
152 |
2086
|
153 octave_value_list retval; |
577
|
154 retval.resize (nout); |
|
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 |
723
|
165 if (vr_list) |
|
166 { |
4219
|
167 for (tree_va_return_list::iterator p = vr_list->begin (); |
|
168 p != vr_list->end (); |
|
169 p++) |
723
|
170 { |
4219
|
171 retval(i++) = *p; |
723
|
172 } |
|
173 } |
|
174 |
577
|
175 return retval; |
|
176 } |
|
177 |
1827
|
178 bool |
577
|
179 tree_parameter_list::is_defined (void) |
|
180 { |
1827
|
181 bool status = true; |
577
|
182 |
4219
|
183 for (iterator p = begin (); p != end (); p++) |
577
|
184 { |
4219
|
185 tree_identifier *elt = *p; |
577
|
186 |
|
187 if (! elt->is_defined ()) |
|
188 { |
1827
|
189 status = false; |
577
|
190 break; |
|
191 } |
|
192 } |
|
193 |
|
194 return status; |
|
195 } |
|
196 |
|
197 void |
2124
|
198 tree_parameter_list::accept (tree_walker& tw) |
581
|
199 { |
2124
|
200 tw.visit_parameter_list (*this); |
581
|
201 } |
|
202 |
|
203 // Return lists. |
|
204 |
1742
|
205 tree_return_list::~tree_return_list (void) |
|
206 { |
4219
|
207 while (! empty ()) |
1742
|
208 { |
4219
|
209 iterator p = begin (); |
|
210 delete *p; |
|
211 erase (p); |
1742
|
212 } |
|
213 } |
|
214 |
581
|
215 void |
2124
|
216 tree_return_list::accept (tree_walker& tw) |
581
|
217 { |
2124
|
218 tw.visit_return_list (*this); |
581
|
219 } |
|
220 |
577
|
221 /* |
|
222 ;;; Local Variables: *** |
|
223 ;;; mode: C++ *** |
|
224 ;;; End: *** |
|
225 */ |