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