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 |
|
26 #if defined (__GNUG__) |
|
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 |
3523
|
115 void stash_function_name (const std::string& s); |
2974
|
116 |
3523
|
117 std::string function_name (void) |
2974
|
118 { return fcn_name; } |
|
119 |
3875
|
120 void save_args_passed (const octave_value_list& args) |
|
121 { |
|
122 if (call_depth > 1) |
|
123 saved_args.push (args_passed); |
|
124 |
|
125 args_passed = args; |
|
126 } |
|
127 |
|
128 void restore_args_passed (void) |
|
129 { |
3933
|
130 if (saved_args.empty ()) |
|
131 args_passed = octave_value_list (); |
|
132 else |
3875
|
133 args_passed = saved_args.pop (); |
|
134 } |
3239
|
135 |
3933
|
136 octave_value_list subsref (const std::string type, |
|
137 const SLList<octave_value_list>& idx, |
|
138 int nargout); |
|
139 |
3544
|
140 octave_value_list |
|
141 do_multi_index_op (int nargout, const octave_value_list& args); |
2974
|
142 |
|
143 void traceback_error (void); |
|
144 |
|
145 tree_parameter_list *parameter_list (void) { return param_list; } |
|
146 |
|
147 tree_parameter_list *return_list (void) { return ret_list; } |
|
148 |
|
149 tree_statement_list *body (void) { return cmd_list; } |
|
150 |
3665
|
151 octave_comment_list *leading_comment (void) { return lead_comm; } |
|
152 |
|
153 octave_comment_list *trailing_comment (void) { return trail_comm; } |
|
154 |
2974
|
155 void accept (tree_walker& tw); |
|
156 |
3933
|
157 void print_symtab_info (std::ostream& os) const; |
|
158 |
2974
|
159 private: |
|
160 |
|
161 octave_user_function (void); |
|
162 |
|
163 octave_user_function (const octave_user_function& m); |
|
164 |
|
165 // List of arguments for this function. These are local variables. |
|
166 tree_parameter_list *param_list; |
|
167 |
|
168 // List of parameters we return. These are also local variables in |
|
169 // this function. |
|
170 tree_parameter_list *ret_list; |
|
171 |
|
172 // The list of commands that make up the body of this function. |
|
173 tree_statement_list *cmd_list; |
|
174 |
|
175 // The local symbol table for this function. |
|
176 symbol_table *sym_tab; |
|
177 |
3665
|
178 // The comments preceding the FUNCTION token. |
|
179 octave_comment_list *lead_comm; |
|
180 |
|
181 // The comments preceding the ENDFUNCTION token. |
|
182 octave_comment_list *trail_comm; |
|
183 |
2974
|
184 // The name of the file we parsed |
3523
|
185 std::string file_name; |
2974
|
186 |
|
187 // The name of the function. |
3523
|
188 std::string fcn_name; |
2974
|
189 |
|
190 // The time the file was parsed. |
3255
|
191 octave_time t_parsed; |
2974
|
192 |
3165
|
193 // The time the file was last checked to see if it needs to be |
|
194 // parsed again. |
3255
|
195 octave_time t_checked; |
3165
|
196 |
2974
|
197 // True if this function came from a file that is considered to be a |
|
198 // system function. This affects whether we check the time stamp |
|
199 // on the file to see if it has changed. |
|
200 bool system_fcn_file; |
|
201 |
|
202 // Used to keep track of recursion depth. |
|
203 int call_depth; |
|
204 |
|
205 // The number of arguments that have names. |
|
206 int num_named_args; |
|
207 |
|
208 // The values that were passed as arguments. |
|
209 octave_value_list args_passed; |
|
210 |
3875
|
211 // A place to store the passed args for recursive calls. |
|
212 SLStack<octave_value_list> saved_args; |
|
213 |
2974
|
214 // The number of arguments passed in. |
|
215 int num_args_passed; |
|
216 |
|
217 // Used to keep track of the current offset into the list of va_args. |
|
218 int curr_va_arg_number; |
|
219 |
|
220 // The list of return values when an unspecified number can be |
|
221 // returned. |
|
222 tree_va_return_list *vr_list; |
|
223 |
|
224 // The symbol record for this function. |
|
225 symbol_record *symtab_entry; |
|
226 |
|
227 // The symbol record for argn in the local symbol table. |
|
228 symbol_record *argn_sr; |
|
229 |
|
230 // The symbol record for nargin in the local symbol table. |
|
231 symbol_record *nargin_sr; |
|
232 |
|
233 // The symbol record for nargout in the local symbol table. |
|
234 symbol_record *nargout_sr; |
|
235 |
|
236 void print_code_function_header (void); |
|
237 |
|
238 void print_code_function_trailer (void); |
|
239 |
|
240 void install_automatic_vars (void); |
|
241 |
|
242 void bind_automatic_vars (const string_vector& arg_names, int nargin, |
|
243 int nargout); |
3219
|
244 |
|
245 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
|
246 |
|
247 DECLARE_OCTAVE_ALLOCATOR |
2974
|
248 }; |
|
249 |
|
250 #endif |
|
251 |
|
252 /* |
|
253 ;;; Local Variables: *** |
|
254 ;;; mode: C++ *** |
|
255 ;;; End: *** |
|
256 */ |