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 |
|
23 #if defined (__GNUG__) |
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
3503
|
31 #include <iostream> |
|
32 #include <strstream> |
2982
|
33 #include <string> |
|
34 |
|
35 #include "str-vec.h" |
|
36 |
|
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" |
|
46 |
|
47 // Argument lists. |
|
48 |
|
49 tree_argument_list::~tree_argument_list (void) |
|
50 { |
|
51 while (! empty ()) |
|
52 { |
|
53 tree_expression *t = remove_front (); |
|
54 delete t; |
|
55 } |
|
56 } |
|
57 |
3977
|
58 int |
|
59 tree_argument_list::nargout_count (void) const |
|
60 { |
|
61 int retval = 0; |
|
62 |
|
63 for (Pix p = first (); p != 0; next (p)) |
|
64 { |
|
65 tree_expression *elt = this->operator () (p); |
|
66 |
|
67 // XXX FIXME XXX -- need to be able to determine whether elt is |
|
68 // an expression that could evaluate to a cs-list object, and if |
|
69 // so, how many elements are in that list. Ugly! |
|
70 |
|
71 retval++; |
|
72 } |
|
73 |
|
74 return retval; |
|
75 } |
|
76 |
2982
|
77 bool |
|
78 tree_argument_list::all_elements_are_constant (void) const |
|
79 { |
|
80 for (Pix p = first (); p != 0; next (p)) |
|
81 { |
|
82 tree_expression *elt = this->operator () (p); |
|
83 |
|
84 if (! elt->is_constant ()) |
|
85 return false; |
|
86 } |
|
87 |
|
88 return true; |
|
89 } |
|
90 |
|
91 octave_value_list |
|
92 tree_argument_list::convert_to_const_vector (void) |
|
93 { |
|
94 int len = length (); |
|
95 |
|
96 // XXX FIXME XXX -- would be nice to know in advance how largs args |
|
97 // needs to be even when we have a list containing an all_va_args |
|
98 // token. |
|
99 |
|
100 octave_value_list args; |
3977
|
101 int args_len = len; |
|
102 args.resize (args_len); |
2982
|
103 |
|
104 Pix p = first (); |
|
105 int j = 0; |
|
106 for (int k = 0; k < len; k++) |
|
107 { |
|
108 tree_expression *elt = this->operator () (p); |
|
109 |
|
110 if (elt) |
|
111 { |
|
112 octave_value tmp = elt->rvalue (); |
|
113 |
|
114 if (error_state) |
|
115 { |
3162
|
116 ::error ("evaluating argument list element number %d", k+1); |
2982
|
117 args = octave_value_list (); |
|
118 break; |
|
119 } |
|
120 else |
|
121 { |
|
122 if (tmp.is_all_va_args ()) |
|
123 { |
|
124 if (curr_function) |
|
125 { |
|
126 octave_value_list tva; |
|
127 tva = curr_function->octave_all_va_args (); |
|
128 int n = tva.length (); |
3977
|
129 args_len += n - 1; |
|
130 args.resize (args_len); |
2982
|
131 for (int i = 0; i < n; i++) |
|
132 args(j++) = tva(i); |
|
133 } |
|
134 else |
|
135 { |
|
136 ::error ("all_va_args is only valid inside functions"); |
|
137 args = octave_value_list (); |
|
138 break; |
|
139 } |
|
140 } |
3977
|
141 else if (tmp.is_cs_list ()) |
|
142 { |
|
143 octave_value_list tl = tmp.list_value (); |
|
144 int n = tl.length (); |
|
145 args_len += n - 1; |
|
146 args.resize (args_len); |
|
147 for (int i = 0; i < n; i++) |
|
148 args(j++) = tl(i); |
|
149 } |
2982
|
150 else |
|
151 args(j++) = tmp; |
|
152 } |
|
153 next (p); |
|
154 } |
|
155 else |
|
156 { |
|
157 args(j++) = octave_value (); |
|
158 break; |
|
159 } |
|
160 } |
|
161 |
|
162 args.resize (j); |
|
163 |
|
164 return args; |
|
165 } |
|
166 |
|
167 string_vector |
|
168 tree_argument_list::get_arg_names (void) const |
|
169 { |
|
170 int len = length (); |
|
171 |
|
172 string_vector retval (len); |
|
173 |
|
174 int k = 0; |
|
175 |
|
176 for (Pix p = first (); p; next (p)) |
|
177 { |
|
178 tree_expression *elt = this->operator () (p); |
|
179 |
2991
|
180 retval(k++) = elt->str_print_code (); |
2982
|
181 } |
|
182 |
|
183 return retval; |
|
184 } |
|
185 |
|
186 void |
|
187 tree_argument_list::accept (tree_walker& tw) |
|
188 { |
|
189 tw.visit_argument_list (*this); |
|
190 } |
|
191 |
|
192 /* |
|
193 ;;; Local Variables: *** |
|
194 ;;; mode: C++ *** |
|
195 ;;; End: *** |
|
196 */ |