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