2982
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 John W. Eaton |
|
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 |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
4192
|
23 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
2982
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
3503
|
31 #include <iostream> |
2982
|
32 #include <string> |
|
33 |
|
34 #include "str-vec.h" |
|
35 |
4234
|
36 #include "defun.h" |
2982
|
37 #include "error.h" |
|
38 #include "oct-obj.h" |
|
39 #include "ov.h" |
|
40 #include "ov-usr-fcn.h" |
|
41 #include "pt-arg-list.h" |
|
42 #include "pt-exp.h" |
|
43 #include "pt-pr-code.h" |
|
44 #include "pt-walk.h" |
|
45 #include "toplev.h" |
4234
|
46 #include "unwind-prot.h" |
2982
|
47 |
|
48 // Argument lists. |
|
49 |
|
50 tree_argument_list::~tree_argument_list (void) |
|
51 { |
4219
|
52 while (! empty ()) |
2982
|
53 { |
4219
|
54 iterator p = begin (); |
|
55 delete *p; |
|
56 erase (p); |
2982
|
57 } |
|
58 } |
|
59 |
3977
|
60 int |
|
61 tree_argument_list::nargout_count (void) const |
|
62 { |
|
63 int retval = 0; |
|
64 |
4219
|
65 for (const_iterator p = begin (); p != end (); p++) |
3977
|
66 { |
4219
|
67 tree_expression *elt = *p; |
3977
|
68 |
|
69 // XXX FIXME XXX -- need to be able to determine whether elt is |
|
70 // an expression that could evaluate to a cs-list object, and if |
|
71 // so, how many elements are in that list. Ugly! |
|
72 |
|
73 retval++; |
|
74 } |
|
75 |
|
76 return retval; |
|
77 } |
|
78 |
2982
|
79 bool |
|
80 tree_argument_list::all_elements_are_constant (void) const |
|
81 { |
4219
|
82 for (const_iterator p = begin (); p != end (); p++) |
2982
|
83 { |
4219
|
84 tree_expression *elt = *p; |
2982
|
85 |
|
86 if (! elt->is_constant ()) |
|
87 return false; |
|
88 } |
|
89 |
|
90 return true; |
|
91 } |
|
92 |
4234
|
93 static const octave_value *indexed_object = 0; |
|
94 static int index_position = 0; |
|
95 |
|
96 DEFCONSTFUN (__end__, , , |
|
97 "internal function") |
|
98 { |
|
99 octave_value retval; |
|
100 |
|
101 if (indexed_object) |
|
102 { |
|
103 switch (index_position) |
|
104 { |
|
105 case -1: |
|
106 // XXX FIXME XXX -- we really want "numel" here. |
|
107 retval = indexed_object->rows () * indexed_object->columns (); |
|
108 break; |
|
109 |
|
110 case 0: |
|
111 retval = indexed_object->rows (); |
|
112 break; |
|
113 |
|
114 case 1: |
|
115 retval = indexed_object->columns (); |
|
116 break; |
|
117 |
|
118 default: |
|
119 ::error ("__end__: internal error"); |
|
120 break; |
|
121 } |
|
122 } |
|
123 else |
|
124 ::error ("__end__: internal error"); |
|
125 |
|
126 return retval; |
|
127 } |
|
128 |
2982
|
129 octave_value_list |
4234
|
130 tree_argument_list::convert_to_const_vector (const octave_value *object) |
2982
|
131 { |
4234
|
132 unwind_protect::begin_frame ("convert_to_const_vector"); |
|
133 |
|
134 unwind_protect_ptr (indexed_object); |
|
135 |
|
136 indexed_object = object; |
|
137 |
2982
|
138 int len = length (); |
|
139 |
|
140 // XXX FIXME XXX -- would be nice to know in advance how largs args |
|
141 // needs to be even when we have a list containing an all_va_args |
|
142 // token. |
|
143 |
|
144 octave_value_list args; |
3977
|
145 int args_len = len; |
|
146 args.resize (args_len); |
2982
|
147 |
4219
|
148 iterator p = begin (); |
2982
|
149 int j = 0; |
|
150 for (int k = 0; k < len; k++) |
|
151 { |
4234
|
152 index_position = (len == 1) ? -1 : k; |
|
153 |
4219
|
154 tree_expression *elt = *p++; |
2982
|
155 |
|
156 if (elt) |
|
157 { |
|
158 octave_value tmp = elt->rvalue (); |
|
159 |
|
160 if (error_state) |
|
161 { |
3162
|
162 ::error ("evaluating argument list element number %d", k+1); |
2982
|
163 args = octave_value_list (); |
|
164 break; |
|
165 } |
|
166 else |
|
167 { |
|
168 if (tmp.is_all_va_args ()) |
|
169 { |
|
170 if (curr_function) |
|
171 { |
|
172 octave_value_list tva; |
|
173 tva = curr_function->octave_all_va_args (); |
|
174 int n = tva.length (); |
3977
|
175 args_len += n - 1; |
|
176 args.resize (args_len); |
2982
|
177 for (int i = 0; i < n; i++) |
|
178 args(j++) = tva(i); |
|
179 } |
|
180 else |
|
181 { |
|
182 ::error ("all_va_args is only valid inside functions"); |
|
183 args = octave_value_list (); |
|
184 break; |
|
185 } |
|
186 } |
3977
|
187 else if (tmp.is_cs_list ()) |
|
188 { |
|
189 octave_value_list tl = tmp.list_value (); |
|
190 int n = tl.length (); |
|
191 args_len += n - 1; |
|
192 args.resize (args_len); |
|
193 for (int i = 0; i < n; i++) |
|
194 args(j++) = tl(i); |
|
195 } |
2982
|
196 else |
|
197 args(j++) = tmp; |
|
198 } |
|
199 } |
|
200 else |
|
201 { |
|
202 args(j++) = octave_value (); |
|
203 break; |
|
204 } |
|
205 } |
|
206 |
|
207 args.resize (j); |
|
208 |
4234
|
209 unwind_protect::run_frame ("convert_to_const_vector"); |
|
210 |
2982
|
211 return args; |
|
212 } |
|
213 |
|
214 string_vector |
|
215 tree_argument_list::get_arg_names (void) const |
|
216 { |
|
217 int len = length (); |
|
218 |
|
219 string_vector retval (len); |
|
220 |
|
221 int k = 0; |
|
222 |
4219
|
223 for (const_iterator p = begin (); p != end (); p++) |
2982
|
224 { |
4219
|
225 tree_expression *elt = *p; |
2982
|
226 |
2991
|
227 retval(k++) = elt->str_print_code (); |
2982
|
228 } |
|
229 |
|
230 return retval; |
|
231 } |
|
232 |
|
233 void |
|
234 tree_argument_list::accept (tree_walker& tw) |
|
235 { |
|
236 tw.visit_argument_list (*this); |
|
237 } |
|
238 |
|
239 /* |
|
240 ;;; Local Variables: *** |
|
241 ;;; mode: C++ *** |
|
242 ;;; End: *** |
|
243 */ |