1739
|
1 /* |
|
2 |
1827
|
3 Copyright (C) 1996 John W. Eaton |
1739
|
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_tree_fcn_h) |
|
24 #define octave_tree_fcn_h 1 |
|
25 |
|
26 #if defined (__GNUG__) |
|
27 #pragma interface |
|
28 #endif |
|
29 |
|
30 #include <ctime> |
|
31 |
|
32 class ostream; |
|
33 |
1755
|
34 #include <string> |
|
35 |
1739
|
36 class tree_parameter_list; |
|
37 class tree_statement_list; |
|
38 class tree_va_return_list; |
|
39 |
2124
|
40 class tree_walker; |
|
41 |
1739
|
42 #include "oct-obj.h" |
|
43 #include "symtab.h" |
|
44 #include "pt-fvc.h" |
|
45 |
|
46 // User defined functions. |
|
47 |
|
48 class |
|
49 tree_function : public tree_fvc |
|
50 { |
2124
|
51 public: |
1739
|
52 |
|
53 tree_function (int l = -1, int c = -1) : tree_fvc (l, c) |
|
54 { init (); } |
|
55 |
|
56 tree_function (tree_statement_list *cl, symbol_table *st, |
|
57 int l = -1, int c = -1) |
|
58 : tree_fvc (l, c) |
|
59 { |
|
60 init (); |
|
61 sym_tab = st; |
|
62 cmd_list = cl; |
|
63 install_nargin_and_nargout (); |
|
64 } |
|
65 |
|
66 ~tree_function (void); |
|
67 |
|
68 // tree_function *define (tree_statement_list *t); |
|
69 tree_function *define_param_list (tree_parameter_list *t); |
|
70 tree_function *define_ret_list (tree_parameter_list *t); |
|
71 |
|
72 void stash_fcn_file_name (void); |
|
73 |
|
74 void stash_fcn_file_time (time_t t) |
|
75 { t_parsed = t; } |
|
76 |
1755
|
77 string fcn_file_name (void) |
1739
|
78 { return file_name; } |
|
79 |
|
80 time_t time_parsed (void) |
|
81 { return t_parsed; } |
|
82 |
|
83 void mark_as_system_fcn_file (void); |
|
84 |
1827
|
85 bool is_system_fcn_file (void) const |
1739
|
86 { return system_fcn_file; } |
|
87 |
1827
|
88 bool takes_varargs (void) const; |
1739
|
89 |
|
90 void octave_va_start (void) |
|
91 { curr_va_arg_number = num_named_args; } |
|
92 |
2086
|
93 octave_value octave_va_arg (void); |
1739
|
94 |
2086
|
95 octave_value_list octave_all_va_args (void); |
1739
|
96 |
1827
|
97 bool takes_var_return (void) const; |
1739
|
98 |
2086
|
99 void octave_vr_val (const octave_value& val); |
1739
|
100 |
1755
|
101 void stash_function_name (const string& s); |
1739
|
102 |
1755
|
103 string function_name (void) |
1739
|
104 { return fcn_name; } |
|
105 |
2086
|
106 octave_value eval (bool print); |
1739
|
107 |
2086
|
108 octave_value_list eval (bool print, int nargout, const octave_value_list& args); |
1739
|
109 |
|
110 void traceback_error (void); |
|
111 |
2124
|
112 tree_parameter_list *parameter_list (void) { return param_list; } |
|
113 |
|
114 tree_parameter_list *return_list (void) { return ret_list; } |
|
115 |
|
116 tree_statement_list *body (void) { return cmd_list; } |
|
117 |
|
118 void accept (tree_walker& tw); |
1739
|
119 |
|
120 private: |
2124
|
121 |
|
122 // List of arguments for this function. These are local variables. |
1739
|
123 tree_parameter_list *param_list; |
2124
|
124 |
|
125 // List of parameters we return. These are also local variables in |
|
126 // this function. |
1739
|
127 tree_parameter_list *ret_list; |
2124
|
128 |
|
129 // The list of commands that make up the body of this function. |
|
130 tree_statement_list *cmd_list; |
|
131 |
|
132 // The local symbol table for this function. |
1739
|
133 symbol_table *sym_tab; |
2124
|
134 |
|
135 // Used to keep track of recursion depth. |
|
136 int call_depth; |
|
137 |
|
138 // The name of the file we parsed |
1755
|
139 string file_name; |
2124
|
140 |
|
141 // The name of the function. |
1755
|
142 string fcn_name; |
2124
|
143 |
|
144 // The time the file was parsed. |
1739
|
145 time_t t_parsed; |
2124
|
146 |
|
147 // True if this function came from a file that is considered to be a |
|
148 // system function. This affects whether we check the time stamp |
|
149 // on the file to see if it has changed. |
1827
|
150 bool system_fcn_file; |
2124
|
151 |
|
152 // The number of arguments that have names. |
1739
|
153 int num_named_args; |
2124
|
154 |
|
155 // The values that were passed as arguments. |
2086
|
156 octave_value_list args_passed; |
2124
|
157 |
|
158 // The number of arguments passed in. |
1739
|
159 int num_args_passed; |
2124
|
160 |
|
161 // Used to keep track of the current offset into the list of va_args. |
1739
|
162 int curr_va_arg_number; |
2124
|
163 |
|
164 // The list of return values when an unspecified number can be |
|
165 // returned. |
1739
|
166 tree_va_return_list *vr_list; |
2124
|
167 |
|
168 // The symbol record for nargin in the local symbol table. |
1739
|
169 symbol_record *nargin_sr; |
2124
|
170 |
|
171 // The symbol record for nargout in the local symbol table. |
1739
|
172 symbol_record *nargout_sr; |
|
173 |
|
174 void print_code_function_header (void); |
2124
|
175 void print_code_function_trailer (void); |
|
176 |
|
177 void install_nargin_and_nargout (void); |
|
178 |
|
179 void bind_nargin_and_nargout (int nargin, int nargout); |
1739
|
180 |
2124
|
181 void init (void) |
|
182 { |
|
183 call_depth = 0; |
|
184 param_list = 0; |
|
185 ret_list = 0; |
|
186 sym_tab = 0; |
|
187 cmd_list = 0; |
|
188 t_parsed = 0; |
|
189 system_fcn_file = 0; |
|
190 num_named_args = 0; |
|
191 num_args_passed = 0; |
|
192 curr_va_arg_number = 0; |
|
193 vr_list = 0; |
|
194 } |
1739
|
195 }; |
|
196 |
2168
|
197 extern void symbols_of_pt_fcn (void); |
|
198 |
1739
|
199 #endif |
|
200 |
|
201 /* |
|
202 ;;; Local Variables: *** |
|
203 ;;; mode: C++ *** |
|
204 ;;; End: *** |
|
205 */ |