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 |
|
31 #include <string> |
|
32 |
|
33 #include <iostream.h> |
|
34 #include <strstream.h> |
|
35 |
|
36 #include "str-vec.h" |
|
37 |
|
38 #include "error.h" |
|
39 #include "oct-obj.h" |
|
40 #include "ov.h" |
|
41 #include "ov-usr-fcn.h" |
|
42 #include "pt-arg-list.h" |
|
43 #include "pt-exp.h" |
|
44 #include "pt-pr-code.h" |
|
45 #include "pt-walk.h" |
|
46 #include "toplev.h" |
|
47 |
|
48 // Argument lists. |
|
49 |
|
50 tree_argument_list::~tree_argument_list (void) |
|
51 { |
|
52 while (! empty ()) |
|
53 { |
|
54 tree_expression *t = remove_front (); |
|
55 delete t; |
|
56 } |
|
57 } |
|
58 |
|
59 bool |
|
60 tree_argument_list::all_elements_are_constant (void) const |
|
61 { |
|
62 for (Pix p = first (); p != 0; next (p)) |
|
63 { |
|
64 tree_expression *elt = this->operator () (p); |
|
65 |
|
66 if (! elt->is_constant ()) |
|
67 return false; |
|
68 } |
|
69 |
|
70 return true; |
|
71 } |
|
72 |
|
73 octave_value_list |
|
74 tree_argument_list::convert_to_const_vector (void) |
|
75 { |
|
76 int len = length (); |
|
77 |
|
78 // XXX FIXME XXX -- would be nice to know in advance how largs args |
|
79 // needs to be even when we have a list containing an all_va_args |
|
80 // token. |
|
81 |
|
82 octave_value_list args; |
|
83 args.resize (len); |
|
84 |
|
85 Pix p = first (); |
|
86 int j = 0; |
|
87 for (int k = 0; k < len; k++) |
|
88 { |
|
89 tree_expression *elt = this->operator () (p); |
|
90 |
|
91 if (elt) |
|
92 { |
|
93 octave_value tmp = elt->rvalue (); |
|
94 |
|
95 if (error_state) |
|
96 { |
|
97 ::error ("evaluating argument list element number %d", k); |
|
98 args = octave_value_list (); |
|
99 break; |
|
100 } |
|
101 else |
|
102 { |
|
103 if (tmp.is_all_va_args ()) |
|
104 { |
|
105 if (curr_function) |
|
106 { |
|
107 octave_value_list tva; |
|
108 tva = curr_function->octave_all_va_args (); |
|
109 int n = tva.length (); |
|
110 for (int i = 0; i < n; i++) |
|
111 args(j++) = tva(i); |
|
112 } |
|
113 else |
|
114 { |
|
115 ::error ("all_va_args is only valid inside functions"); |
|
116 args = octave_value_list (); |
|
117 break; |
|
118 } |
|
119 } |
|
120 else |
|
121 args(j++) = tmp; |
|
122 } |
|
123 next (p); |
|
124 } |
|
125 else |
|
126 { |
|
127 args(j++) = octave_value (); |
|
128 break; |
|
129 } |
|
130 } |
|
131 |
|
132 args.resize (j); |
|
133 |
|
134 return args; |
|
135 } |
|
136 |
|
137 string_vector |
|
138 tree_argument_list::get_arg_names (void) const |
|
139 { |
|
140 int len = length (); |
|
141 |
|
142 string_vector retval (len); |
|
143 |
|
144 int k = 0; |
|
145 |
|
146 for (Pix p = first (); p; next (p)) |
|
147 { |
|
148 tree_expression *elt = this->operator () (p); |
|
149 |
2991
|
150 retval(k++) = elt->str_print_code (); |
2982
|
151 } |
|
152 |
|
153 return retval; |
|
154 } |
|
155 |
|
156 void |
|
157 tree_argument_list::accept (tree_walker& tw) |
|
158 { |
|
159 tw.visit_argument_list (*this); |
|
160 } |
|
161 |
|
162 /* |
|
163 ;;; Local Variables: *** |
|
164 ;;; mode: C++ *** |
|
165 ;;; End: *** |
|
166 */ |