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 |
|
34 #include "oct-obj.h" |
|
35 #include "ov-fcn.h" |
|
36 #include "ov-typeinfo.h" |
|
37 |
|
38 class string_vector; |
|
39 |
|
40 class octave_value; |
|
41 class tree_parameter_list; |
|
42 class tree_statement_list; |
|
43 class tree_va_return_list; |
|
44 class tree_walker; |
|
45 class symbol_table; |
|
46 class symbol_record; |
|
47 |
|
48 // Builtin functions. |
|
49 |
|
50 class |
|
51 octave_user_function : public octave_function |
|
52 { |
|
53 public: |
|
54 |
|
55 octave_user_function (tree_parameter_list *pl = 0, |
|
56 tree_parameter_list *rl = 0, |
|
57 tree_statement_list *cl = 0, |
|
58 symbol_table *st = 0); |
|
59 |
|
60 ~octave_user_function (void); |
|
61 |
|
62 void *operator new (size_t size) |
|
63 { return allocator.alloc (size); } |
|
64 |
|
65 void operator delete (void *p, size_t size) |
|
66 { allocator.free (p, size); } |
|
67 |
|
68 octave_function *function_value (bool) { return this; } |
|
69 |
|
70 octave_user_function *define_param_list (tree_parameter_list *t); |
|
71 |
|
72 octave_user_function *define_ret_list (tree_parameter_list *t); |
|
73 |
|
74 void stash_fcn_file_name (void); |
|
75 |
3165
|
76 void mark_fcn_file_up_to_date (time_t t) |
|
77 { t_checked = t; } |
|
78 |
2974
|
79 void stash_fcn_file_time (time_t 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 |
|
88 string fcn_file_name (void) const |
|
89 { return file_name; } |
|
90 |
|
91 time_t time_parsed (void) const |
|
92 { return t_parsed; } |
|
93 |
3165
|
94 time_t time_checked (void) const |
|
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 |
|
115 void stash_function_name (const string& s); |
|
116 |
|
117 string function_name (void) |
|
118 { return fcn_name; } |
|
119 |
|
120 octave_value_list do_index_op (int nargout, const octave_value_list& args); |
|
121 |
|
122 void traceback_error (void); |
|
123 |
|
124 tree_parameter_list *parameter_list (void) { return param_list; } |
|
125 |
|
126 tree_parameter_list *return_list (void) { return ret_list; } |
|
127 |
|
128 tree_statement_list *body (void) { return cmd_list; } |
|
129 |
|
130 void accept (tree_walker& tw); |
|
131 |
|
132 int type_id (void) const { return t_id; } |
|
133 |
|
134 string type_name (void) const { return t_name; } |
|
135 |
|
136 static int static_type_id (void) { return t_id; } |
|
137 |
|
138 static void register_type (void) |
|
139 { t_id = octave_value_typeinfo::register_type (t_name); } |
|
140 |
|
141 private: |
|
142 |
|
143 octave_user_function (void); |
|
144 |
|
145 octave_user_function (const octave_user_function& m); |
|
146 |
|
147 // List of arguments for this function. These are local variables. |
|
148 tree_parameter_list *param_list; |
|
149 |
|
150 // List of parameters we return. These are also local variables in |
|
151 // this function. |
|
152 tree_parameter_list *ret_list; |
|
153 |
|
154 // The list of commands that make up the body of this function. |
|
155 tree_statement_list *cmd_list; |
|
156 |
|
157 // The local symbol table for this function. |
|
158 symbol_table *sym_tab; |
|
159 |
|
160 // The name of the file we parsed |
|
161 string file_name; |
|
162 |
|
163 // The name of the function. |
|
164 string fcn_name; |
|
165 |
|
166 // The time the file was parsed. |
|
167 time_t t_parsed; |
|
168 |
3165
|
169 // The time the file was last checked to see if it needs to be |
|
170 // parsed again. |
|
171 time_t t_checked; |
|
172 |
2974
|
173 // True if this function came from a file that is considered to be a |
|
174 // system function. This affects whether we check the time stamp |
|
175 // on the file to see if it has changed. |
|
176 bool system_fcn_file; |
|
177 |
|
178 // Used to keep track of recursion depth. |
|
179 int call_depth; |
|
180 |
|
181 // The number of arguments that have names. |
|
182 int num_named_args; |
|
183 |
|
184 // The values that were passed as arguments. |
|
185 octave_value_list args_passed; |
|
186 |
|
187 // The number of arguments passed in. |
|
188 int num_args_passed; |
|
189 |
|
190 // Used to keep track of the current offset into the list of va_args. |
|
191 int curr_va_arg_number; |
|
192 |
|
193 // The list of return values when an unspecified number can be |
|
194 // returned. |
|
195 tree_va_return_list *vr_list; |
|
196 |
|
197 // The symbol record for this function. |
|
198 symbol_record *symtab_entry; |
|
199 |
|
200 // The symbol record for argn in the local symbol table. |
|
201 symbol_record *argn_sr; |
|
202 |
|
203 // The symbol record for nargin in the local symbol table. |
|
204 symbol_record *nargin_sr; |
|
205 |
|
206 // The symbol record for nargout in the local symbol table. |
|
207 symbol_record *nargout_sr; |
|
208 |
|
209 // For custom memory management. |
|
210 static octave_allocator allocator; |
|
211 |
|
212 // Type id of list objects, set by register_type(). |
|
213 static int t_id; |
|
214 |
|
215 // Type name of list objects, defined in ov-list.cc. |
|
216 static const string t_name; |
|
217 |
|
218 void print_code_function_header (void); |
|
219 |
|
220 void print_code_function_trailer (void); |
|
221 |
|
222 void install_automatic_vars (void); |
|
223 |
|
224 void bind_automatic_vars (const string_vector& arg_names, int nargin, |
|
225 int nargout); |
|
226 }; |
|
227 |
|
228 #endif |
|
229 |
|
230 /* |
|
231 ;;; Local Variables: *** |
|
232 ;;; mode: C++ *** |
|
233 ;;; End: *** |
|
234 */ |