00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #if !defined (octave_user_function_h)
00025 #define octave_user_function_h 1
00026
00027 #include <ctime>
00028
00029 #include <string>
00030 #include <stack>
00031
00032 #include "comment-list.h"
00033 #include "oct-obj.h"
00034 #include "ov-fcn.h"
00035 #include "ov-typeinfo.h"
00036 #include "symtab.h"
00037
00038 class string_vector;
00039
00040 class octave_value;
00041 class tree_parameter_list;
00042 class tree_statement_list;
00043 class tree_va_return_list;
00044 class tree_walker;
00045
00046 class
00047 octave_user_code : public octave_function
00048 {
00049 public:
00050 octave_user_code (void)
00051 : octave_function () { }
00052
00053 ~octave_user_code (void) { }
00054
00055 bool is_user_code (void) const { return true; }
00056
00057 virtual tree_statement_list *body (void) = 0;
00058
00059 protected:
00060
00061 octave_user_code (const std::string& nm,
00062 const std::string& ds = std::string ())
00063 : octave_function (nm, ds) { }
00064
00065 private:
00066
00067
00068
00069 octave_user_code (const octave_user_code& f);
00070
00071 octave_user_code& operator = (const octave_user_code& f);
00072 };
00073
00074
00075
00076 class
00077 octave_user_script : public octave_user_code
00078 {
00079 public:
00080
00081 octave_user_script (void);
00082
00083 octave_user_script (const std::string& fnm, const std::string& nm,
00084 tree_statement_list *cmds,
00085 const std::string& ds = std::string ());
00086
00087 octave_user_script (const std::string& fnm, const std::string& nm,
00088 const std::string& ds = std::string ());
00089
00090 ~octave_user_script (void);
00091
00092 octave_function *function_value (bool = false) { return this; }
00093
00094 const octave_function *function_value (bool = false) const { return this; }
00095
00096 octave_user_script *user_script_value (bool = false) { return this; }
00097
00098 octave_user_code *user_code_value (bool = false) { return this; }
00099
00100
00101
00102
00103 bool is_user_script (void) const { return true; }
00104
00105 void stash_fcn_file_name (const std::string& nm) { file_name = nm; }
00106
00107 void mark_fcn_file_up_to_date (const octave_time& t) { t_checked = t; }
00108
00109 void stash_fcn_file_time (const octave_time& t)
00110 {
00111 t_parsed = t;
00112 mark_fcn_file_up_to_date (t);
00113 }
00114
00115 std::string fcn_file_name (void) const { return file_name; }
00116
00117 octave_time time_parsed (void) const { return t_parsed; }
00118
00119 octave_time time_checked (void) const { return t_checked; }
00120
00121 octave_value subsref (const std::string& type,
00122 const std::list<octave_value_list>& idx)
00123 {
00124 octave_value_list tmp = subsref (type, idx, 1);
00125 return tmp.length () > 0 ? tmp(0) : octave_value ();
00126 }
00127
00128 octave_value_list subsref (const std::string& type,
00129 const std::list<octave_value_list>& idx,
00130 int nargout);
00131
00132 octave_value_list
00133 do_multi_index_op (int nargout, const octave_value_list& args);
00134
00135 tree_statement_list *body (void) { return cmd_list; }
00136
00137 void accept (tree_walker& tw);
00138
00139 private:
00140
00141
00142 tree_statement_list *cmd_list;
00143
00144
00145 std::string file_name;
00146
00147
00148 octave_time t_parsed;
00149
00150
00151
00152 octave_time t_checked;
00153
00154
00155 int call_depth;
00156
00157
00158
00159 octave_user_script (const octave_user_script& f);
00160
00161 octave_user_script& operator = (const octave_user_script& f);
00162
00163 DECLARE_OCTAVE_ALLOCATOR
00164
00165 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
00166 };
00167
00168
00169
00170 class
00171 octave_user_function : public octave_user_code
00172 {
00173 public:
00174
00175 octave_user_function (symbol_table::scope_id sid = -1,
00176 tree_parameter_list *pl = 0,
00177 tree_parameter_list *rl = 0,
00178 tree_statement_list *cl = 0);
00179
00180 ~octave_user_function (void);
00181
00182 octave_function *function_value (bool = false) { return this; }
00183
00184 const octave_function *function_value (bool = false) const { return this; }
00185
00186 octave_user_function *user_function_value (bool = false) { return this; }
00187
00188 octave_user_code *user_code_value (bool = false) { return this; }
00189
00190 octave_user_function *define_param_list (tree_parameter_list *t);
00191
00192 octave_user_function *define_ret_list (tree_parameter_list *t);
00193
00194 void stash_fcn_file_name (const std::string& nm);
00195
00196 void stash_parent_fcn_name (const std::string& p) { parent_name = p; }
00197
00198 void stash_parent_fcn_scope (symbol_table::scope_id ps) { parent_scope = ps; }
00199
00200 void stash_leading_comment (octave_comment_list *lc) { lead_comm = lc; }
00201
00202 void stash_trailing_comment (octave_comment_list *tc) { trail_comm = tc; }
00203
00204 void mark_fcn_file_up_to_date (const octave_time& t) { t_checked = t; }
00205
00206 void stash_fcn_file_time (const octave_time& t)
00207 {
00208 t_parsed = t;
00209 mark_fcn_file_up_to_date (t);
00210 }
00211
00212 std::string fcn_file_name (void) const { return file_name; }
00213
00214 std::string parent_fcn_name (void) const { return parent_name; }
00215
00216 symbol_table::scope_id parent_fcn_scope (void) const { return parent_scope; }
00217
00218 symbol_table::scope_id scope (void) { return local_scope; }
00219
00220 octave_time time_parsed (void) const { return t_parsed; }
00221
00222 octave_time time_checked (void) const { return t_checked; }
00223
00224 void mark_as_system_fcn_file (void);
00225
00226 bool is_system_fcn_file (void) const { return system_fcn_file; }
00227
00228 bool is_user_function (void) const { return true; }
00229
00230 void erase_subfunctions (void)
00231 {
00232 symbol_table::erase_subfunctions_in_scope (local_scope);
00233 }
00234
00235 bool takes_varargs (void) const;
00236
00237 bool takes_var_return (void) const;
00238
00239 void lock_subfunctions (void);
00240
00241 void unlock_subfunctions (void);
00242
00243 octave_value_list all_va_args (const octave_value_list& args);
00244
00245 void stash_function_name (const std::string& s) { my_name = s; }
00246
00247 void mark_as_nested_function (void) { nested_function = true; }
00248
00249 bool is_nested_function (void) const { return nested_function; }
00250
00251 void mark_as_inline_function (void) { inline_function = true; }
00252
00253 bool is_inline_function (void) const { return inline_function; }
00254
00255 void mark_as_class_constructor (void) { class_constructor = true; }
00256
00257 bool is_class_constructor (void) const { return class_constructor; }
00258
00259 void mark_as_class_method (void) { class_method = true; }
00260
00261 bool is_class_method (void) const { return class_method; }
00262
00263 octave_value subsref (const std::string& type,
00264 const std::list<octave_value_list>& idx)
00265 {
00266 octave_value_list tmp = subsref (type, idx, 1);
00267 return tmp.length () > 0 ? tmp(0) : octave_value ();
00268 }
00269
00270 octave_value_list subsref (const std::string& type,
00271 const std::list<octave_value_list>& idx,
00272 int nargout);
00273
00274 octave_value_list
00275 do_multi_index_op (int nargout, const octave_value_list& args);
00276
00277 tree_parameter_list *parameter_list (void) { return param_list; }
00278
00279 tree_parameter_list *return_list (void) { return ret_list; }
00280
00281 tree_statement_list *body (void) { return cmd_list; }
00282
00283 octave_comment_list *leading_comment (void) { return lead_comm; }
00284
00285 octave_comment_list *trailing_comment (void) { return trail_comm; }
00286
00287 bool subsasgn_optimization_ok (void);
00288
00289 void accept (tree_walker& tw);
00290
00291 #if 0
00292 void print_symtab_info (std::ostream& os) const;
00293 #endif
00294
00295 private:
00296
00297
00298 tree_parameter_list *param_list;
00299
00300
00301
00302 tree_parameter_list *ret_list;
00303
00304
00305 tree_statement_list *cmd_list;
00306
00307
00308 octave_comment_list *lead_comm;
00309
00310
00311 octave_comment_list *trail_comm;
00312
00313
00314 std::string file_name;
00315
00316
00317 std::string parent_name;
00318
00319
00320 octave_time t_parsed;
00321
00322
00323
00324 octave_time t_checked;
00325
00326
00327
00328
00329 bool system_fcn_file;
00330
00331
00332 int call_depth;
00333
00334
00335 int num_named_args;
00336
00337
00338 bool nested_function;
00339
00340
00341 bool inline_function;
00342
00343
00344 bool class_constructor;
00345
00346
00347 bool class_method;
00348
00349
00350 symbol_table::scope_id parent_scope;
00351
00352 symbol_table::scope_id local_scope;
00353
00354 #if 0
00355
00356 octave_value& argn_varref;
00357
00358
00359 octave_value& nargin_varref;
00360
00361
00362 octave_value& nargout_varref;
00363
00364
00365 octave_value& varargin_varref;
00366 #endif
00367
00368 void print_code_function_header (void);
00369
00370 void print_code_function_trailer (void);
00371
00372 void bind_automatic_vars (const string_vector& arg_names, int nargin,
00373 int nargout, const octave_value_list& va_args);
00374
00375
00376
00377 octave_user_function (const octave_user_function& fn);
00378
00379 octave_user_function& operator = (const octave_user_function& fn);
00380
00381 DECLARE_OCTAVE_ALLOCATOR
00382
00383 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
00384 };
00385
00386 #endif
00387
00388
00389
00390
00391
00392