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