2974
|
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 (octave_user_function_h) |
|
24 #define octave_user_function_h 1 |
|
25 |
4192
|
26 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
2974
|
27 #pragma interface |
|
28 #endif |
|
29 |
|
30 #include <ctime> |
|
31 |
|
32 #include <string> |
4214
|
33 #include <stack> |
2974
|
34 |
3665
|
35 #include "comment-list.h" |
2974
|
36 #include "oct-obj.h" |
|
37 #include "ov-fcn.h" |
|
38 #include "ov-typeinfo.h" |
|
39 |
|
40 class string_vector; |
|
41 |
|
42 class octave_value; |
|
43 class tree_parameter_list; |
|
44 class tree_statement_list; |
|
45 class tree_va_return_list; |
|
46 class tree_walker; |
|
47 class symbol_table; |
|
48 class symbol_record; |
|
49 |
|
50 // Builtin functions. |
|
51 |
|
52 class |
|
53 octave_user_function : public octave_function |
|
54 { |
|
55 public: |
|
56 |
|
57 octave_user_function (tree_parameter_list *pl = 0, |
|
58 tree_parameter_list *rl = 0, |
|
59 tree_statement_list *cl = 0, |
|
60 symbol_table *st = 0); |
|
61 |
|
62 ~octave_user_function (void); |
|
63 |
|
64 octave_function *function_value (bool) { return this; } |
|
65 |
|
66 octave_user_function *define_param_list (tree_parameter_list *t); |
|
67 |
|
68 octave_user_function *define_ret_list (tree_parameter_list *t); |
|
69 |
|
70 void stash_fcn_file_name (void); |
|
71 |
3665
|
72 void stash_leading_comment (octave_comment_list *lc) { lead_comm = lc; } |
|
73 |
|
74 void stash_trailing_comment (octave_comment_list *tc) { trail_comm = tc; } |
|
75 |
3325
|
76 void mark_fcn_file_up_to_date (const octave_time& t) { t_checked = t; } |
3165
|
77 |
3255
|
78 void stash_fcn_file_time (const octave_time& t) |
3165
|
79 { |
|
80 t_parsed = t; |
|
81 mark_fcn_file_up_to_date (t); |
|
82 } |
2974
|
83 |
|
84 void stash_symtab_ptr (symbol_record *sr) |
|
85 { symtab_entry = sr; } |
|
86 |
3523
|
87 std::string fcn_file_name (void) const |
2974
|
88 { return file_name; } |
|
89 |
3255
|
90 octave_time time_parsed (void) const |
2974
|
91 { return t_parsed; } |
|
92 |
3255
|
93 octave_time time_checked (void) const |
3165
|
94 { return t_checked; } |
|
95 |
2974
|
96 void mark_as_system_fcn_file (void); |
|
97 |
|
98 bool is_system_fcn_file (void) const |
|
99 { return system_fcn_file; } |
|
100 |
|
101 bool takes_varargs (void) const; |
|
102 |
|
103 void octave_va_start (void) |
|
104 { curr_va_arg_number = num_named_args; } |
|
105 |
|
106 octave_value octave_va_arg (void); |
|
107 |
|
108 octave_value_list octave_all_va_args (void); |
|
109 |
|
110 bool takes_var_return (void) const; |
|
111 |
|
112 void octave_vr_val (const octave_value& val); |
|
113 |
3974
|
114 void varargout_to_vr_val (void); |
|
115 |
|
116 bool has_varargout (void) const; |
|
117 |
3523
|
118 void stash_function_name (const std::string& s); |
2974
|
119 |
3523
|
120 std::string function_name (void) |
2974
|
121 { return fcn_name; } |
|
122 |
3875
|
123 void save_args_passed (const octave_value_list& args) |
|
124 { |
|
125 if (call_depth > 1) |
|
126 saved_args.push (args_passed); |
|
127 |
|
128 args_passed = args; |
|
129 } |
|
130 |
|
131 void restore_args_passed (void) |
|
132 { |
3933
|
133 if (saved_args.empty ()) |
|
134 args_passed = octave_value_list (); |
|
135 else |
4214
|
136 { |
|
137 args_passed = saved_args.top (); |
|
138 saved_args.pop (); |
|
139 } |
3875
|
140 } |
3239
|
141 |
3933
|
142 octave_value_list subsref (const std::string type, |
4219
|
143 const std::list<octave_value_list>& idx, |
3933
|
144 int nargout); |
|
145 |
3544
|
146 octave_value_list |
|
147 do_multi_index_op (int nargout, const octave_value_list& args); |
2974
|
148 |
|
149 void traceback_error (void); |
|
150 |
|
151 tree_parameter_list *parameter_list (void) { return param_list; } |
|
152 |
|
153 tree_parameter_list *return_list (void) { return ret_list; } |
|
154 |
|
155 tree_statement_list *body (void) { return cmd_list; } |
|
156 |
3665
|
157 octave_comment_list *leading_comment (void) { return lead_comm; } |
|
158 |
|
159 octave_comment_list *trailing_comment (void) { return trail_comm; } |
|
160 |
2974
|
161 void accept (tree_walker& tw); |
|
162 |
3933
|
163 void print_symtab_info (std::ostream& os) const; |
|
164 |
2974
|
165 private: |
|
166 |
|
167 octave_user_function (void); |
|
168 |
|
169 octave_user_function (const octave_user_function& m); |
|
170 |
|
171 // List of arguments for this function. These are local variables. |
|
172 tree_parameter_list *param_list; |
|
173 |
|
174 // List of parameters we return. These are also local variables in |
|
175 // this function. |
|
176 tree_parameter_list *ret_list; |
|
177 |
|
178 // The list of commands that make up the body of this function. |
|
179 tree_statement_list *cmd_list; |
|
180 |
|
181 // The local symbol table for this function. |
|
182 symbol_table *sym_tab; |
|
183 |
3665
|
184 // The comments preceding the FUNCTION token. |
|
185 octave_comment_list *lead_comm; |
|
186 |
|
187 // The comments preceding the ENDFUNCTION token. |
|
188 octave_comment_list *trail_comm; |
|
189 |
2974
|
190 // The name of the file we parsed |
3523
|
191 std::string file_name; |
2974
|
192 |
|
193 // The name of the function. |
3523
|
194 std::string fcn_name; |
2974
|
195 |
|
196 // The time the file was parsed. |
3255
|
197 octave_time t_parsed; |
2974
|
198 |
3165
|
199 // The time the file was last checked to see if it needs to be |
|
200 // parsed again. |
3255
|
201 octave_time t_checked; |
3165
|
202 |
2974
|
203 // True if this function came from a file that is considered to be a |
|
204 // system function. This affects whether we check the time stamp |
|
205 // on the file to see if it has changed. |
|
206 bool system_fcn_file; |
|
207 |
|
208 // Used to keep track of recursion depth. |
|
209 int call_depth; |
|
210 |
|
211 // The number of arguments that have names. |
|
212 int num_named_args; |
|
213 |
|
214 // The values that were passed as arguments. |
|
215 octave_value_list args_passed; |
|
216 |
3875
|
217 // A place to store the passed args for recursive calls. |
4214
|
218 std::stack<octave_value_list> saved_args; |
3875
|
219 |
2974
|
220 // The number of arguments passed in. |
|
221 int num_args_passed; |
|
222 |
|
223 // Used to keep track of the current offset into the list of va_args. |
|
224 int curr_va_arg_number; |
|
225 |
|
226 // The list of return values when an unspecified number can be |
|
227 // returned. |
|
228 tree_va_return_list *vr_list; |
|
229 |
|
230 // The symbol record for this function. |
|
231 symbol_record *symtab_entry; |
|
232 |
|
233 // The symbol record for argn in the local symbol table. |
|
234 symbol_record *argn_sr; |
|
235 |
|
236 // The symbol record for nargin in the local symbol table. |
|
237 symbol_record *nargin_sr; |
|
238 |
|
239 // The symbol record for nargout in the local symbol table. |
|
240 symbol_record *nargout_sr; |
|
241 |
3974
|
242 // The symbol record for varargin in the local symbol table. |
|
243 symbol_record *varargin_sr; |
|
244 |
2974
|
245 void print_code_function_header (void); |
|
246 |
|
247 void print_code_function_trailer (void); |
|
248 |
|
249 void install_automatic_vars (void); |
|
250 |
|
251 void bind_automatic_vars (const string_vector& arg_names, int nargin, |
3974
|
252 int nargout, const octave_value_list& va_args); |
3219
|
253 |
|
254 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
|
255 |
|
256 DECLARE_OCTAVE_ALLOCATOR |
2974
|
257 }; |
|
258 |
|
259 #endif |
|
260 |
|
261 /* |
|
262 ;;; Local Variables: *** |
|
263 ;;; mode: C++ *** |
|
264 ;;; End: *** |
|
265 */ |