Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #if !defined (octave_user_function_h)
00024 #define octave_user_function_h 1
00025
00026 #include <ctime>
00027
00028 #include <string>
00029 #include <stack>
00030
00031 #include "comment-list.h"
00032 #include "oct-obj.h"
00033 #include "ov-fcn.h"
00034 #include "ov-typeinfo.h"
00035 #include "symtab.h"
00036 #include "unwind-prot.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 octave_user_script *user_script_value (bool = false) { return this; }
00095
00096 octave_user_code *user_code_value (bool = false) { return this; }
00097
00098
00099
00100
00101 bool is_user_script (void) const { return true; }
00102
00103 void stash_fcn_file_name (const std::string& nm) { file_name = nm; }
00104
00105 void mark_fcn_file_up_to_date (const octave_time& t) { t_checked = t; }
00106
00107 void stash_fcn_file_time (const octave_time& t)
00108 {
00109 t_parsed = t;
00110 mark_fcn_file_up_to_date (t);
00111 }
00112
00113 std::string fcn_file_name (void) const { return file_name; }
00114
00115 octave_time time_parsed (void) const { return t_parsed; }
00116
00117 octave_time time_checked (void) const { return t_checked; }
00118
00119 octave_value subsref (const std::string& type,
00120 const std::list<octave_value_list>& idx)
00121 {
00122 octave_value_list tmp = subsref (type, idx, 1);
00123 return tmp.length () > 0 ? tmp(0) : octave_value ();
00124 }
00125
00126 octave_value_list subsref (const std::string& type,
00127 const std::list<octave_value_list>& idx,
00128 int nargout);
00129
00130 octave_value_list
00131 do_multi_index_op (int nargout, const octave_value_list& args);
00132
00133 tree_statement_list *body (void) { return cmd_list; }
00134
00135 void accept (tree_walker& tw);
00136
00137 private:
00138
00139
00140 tree_statement_list *cmd_list;
00141
00142
00143 std::string file_name;
00144
00145
00146 octave_time t_parsed;
00147
00148
00149
00150 octave_time t_checked;
00151
00152
00153 int call_depth;
00154
00155
00156
00157 octave_user_script (const octave_user_script& f);
00158
00159 octave_user_script& operator = (const octave_user_script& f);
00160
00161 DECLARE_OCTAVE_ALLOCATOR
00162
00163 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
00164 };
00165
00166
00167
00168 class
00169 octave_user_function : public octave_user_code
00170 {
00171 public:
00172
00173 octave_user_function (symbol_table::scope_id sid = -1,
00174 tree_parameter_list *pl = 0,
00175 tree_parameter_list *rl = 0,
00176 tree_statement_list *cl = 0);
00177
00178 ~octave_user_function (void);
00179
00180 octave_function *function_value (bool = false) { return this; }
00181
00182 octave_user_function *user_function_value (bool = false) { return this; }
00183
00184 octave_user_code *user_code_value (bool = false) { return this; }
00185
00186 octave_user_function *define_param_list (tree_parameter_list *t);
00187
00188 octave_user_function *define_ret_list (tree_parameter_list *t);
00189
00190 void stash_fcn_file_name (const std::string& nm);
00191
00192 void stash_parent_fcn_name (const std::string& p) { parent_name = p; }
00193
00194 void stash_parent_fcn_scope (symbol_table::scope_id ps) { parent_scope = ps; }
00195
00196 void stash_leading_comment (octave_comment_list *lc) { lead_comm = lc; }
00197
00198 void stash_trailing_comment (octave_comment_list *tc) { trail_comm = tc; }
00199
00200 void mark_fcn_file_up_to_date (const octave_time& t) { t_checked = t; }
00201
00202 void stash_fcn_file_time (const octave_time& t)
00203 {
00204 t_parsed = t;
00205 mark_fcn_file_up_to_date (t);
00206 }
00207
00208 std::string fcn_file_name (void) const { return file_name; }
00209
00210 std::string parent_fcn_name (void) const { return parent_name; }
00211
00212 symbol_table::scope_id parent_fcn_scope (void) const { return parent_scope; }
00213
00214 symbol_table::scope_id scope (void) { return local_scope; }
00215
00216 octave_time time_parsed (void) const { return t_parsed; }
00217
00218 octave_time time_checked (void) const { return t_checked; }
00219
00220 void mark_as_system_fcn_file (void);
00221
00222 bool is_system_fcn_file (void) const { return system_fcn_file; }
00223
00224 bool is_user_function (void) const { return true; }
00225
00226 void erase_subfunctions (void)
00227 {
00228 symbol_table::erase_subfunctions_in_scope (local_scope);
00229 }
00230
00231 bool takes_varargs (void) const;
00232
00233 bool takes_var_return (void) const;
00234
00235 void mark_as_private_function (const std::string& cname = std::string ())
00236 {
00237 symbol_table::mark_subfunctions_in_scope_as_private (local_scope, cname);
00238
00239 octave_function::mark_as_private_function (cname);
00240 }
00241
00242 void lock_subfunctions (void);
00243
00244 void unlock_subfunctions (void);
00245
00246 octave_value_list all_va_args (const octave_value_list& args);
00247
00248 void stash_function_name (const std::string& s) { my_name = s; }
00249
00250 void mark_as_subfunction (void) { subfunction = true; }
00251
00252 bool is_subfunction (void) const { return subfunction; }
00253
00254 void mark_as_inline_function (void) { inline_function = true; }
00255
00256 bool is_inline_function (void) const { return inline_function; }
00257
00258 void mark_as_class_constructor (void) { class_constructor = true; }
00259
00260 bool is_class_constructor (const std::string& cname = std::string ()) const
00261 {
00262 return class_constructor
00263 ? (cname.empty () ? true : cname == dispatch_class ()) : false;
00264 }
00265
00266 void mark_as_class_method (void) { class_method = true; }
00267
00268 bool is_class_method (const std::string& cname = std::string ()) const
00269 {
00270 return class_method
00271 ? (cname.empty () ? true : cname == dispatch_class ()) : false;
00272 }
00273
00274 octave_value subsref (const std::string& type,
00275 const std::list<octave_value_list>& idx)
00276 {
00277 octave_value_list tmp = subsref (type, idx, 1);
00278 return tmp.length () > 0 ? tmp(0) : octave_value ();
00279 }
00280
00281 octave_value_list subsref (const std::string& type,
00282 const std::list<octave_value_list>& idx,
00283 int nargout);
00284
00285 octave_value_list subsref (const std::string& type,
00286 const std::list<octave_value_list>& idx,
00287 int nargout, const std::list<octave_lvalue>* lvalue_list);
00288
00289 octave_value_list
00290 do_multi_index_op (int nargout, const octave_value_list& args);
00291
00292 octave_value_list
00293 do_multi_index_op (int nargout, const octave_value_list& args,
00294 const std::list<octave_lvalue>* lvalue_list);
00295
00296 tree_parameter_list *parameter_list (void) { return param_list; }
00297
00298 tree_parameter_list *return_list (void) { return ret_list; }
00299
00300 tree_statement_list *body (void) { return cmd_list; }
00301
00302 octave_comment_list *leading_comment (void) { return lead_comm; }
00303
00304 octave_comment_list *trailing_comment (void) { return trail_comm; }
00305
00306 bool subsasgn_optimization_ok (void);
00307
00308 void accept (tree_walker& tw);
00309
00310 template <class T>
00311 bool local_protect (T& variable)
00312 {
00313 if (curr_unwind_protect_frame)
00314 {
00315 curr_unwind_protect_frame->protect_var (variable);
00316 return true;
00317 }
00318 else
00319 return false;
00320 }
00321
00322 #if 0
00323 void print_symtab_info (std::ostream& os) const;
00324 #endif
00325
00326 private:
00327
00328
00329 tree_parameter_list *param_list;
00330
00331
00332
00333 tree_parameter_list *ret_list;
00334
00335
00336 tree_statement_list *cmd_list;
00337
00338
00339 octave_comment_list *lead_comm;
00340
00341
00342 octave_comment_list *trail_comm;
00343
00344
00345 std::string file_name;
00346
00347
00348 std::string parent_name;
00349
00350
00351 octave_time t_parsed;
00352
00353
00354
00355 octave_time t_checked;
00356
00357
00358
00359
00360 bool system_fcn_file;
00361
00362
00363 int call_depth;
00364
00365
00366 int num_named_args;
00367
00368
00369 bool subfunction;
00370
00371
00372 bool inline_function;
00373
00374
00375 bool class_constructor;
00376
00377
00378 bool class_method;
00379
00380
00381 symbol_table::scope_id parent_scope;
00382
00383 symbol_table::scope_id local_scope;
00384
00385
00386 unwind_protect *curr_unwind_protect_frame;
00387
00388 #if 0
00389
00390 octave_value& argn_varref;
00391
00392
00393 octave_value& nargin_varref;
00394
00395
00396 octave_value& nargout_varref;
00397
00398
00399 octave_value& varargin_varref;
00400 #endif
00401
00402 void print_code_function_header (void);
00403
00404 void print_code_function_trailer (void);
00405
00406 void bind_automatic_vars (const string_vector& arg_names, int nargin,
00407 int nargout, const octave_value_list& va_args,
00408 const std::list<octave_lvalue> *lvalue_list);
00409
00410
00411
00412 octave_user_function (const octave_user_function& fn);
00413
00414 octave_user_function& operator = (const octave_user_function& fn);
00415
00416 DECLARE_OCTAVE_ALLOCATOR
00417
00418 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
00419 };
00420
00421 #endif