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