26#if defined (HAVE_CONFIG_H)
49static int Vignore_function_time_stamp = 1;
54fcn_info::fcn_info_rep::load_private_function (
const std::string& dir_name)
62 if (file_name.empty ())
75 std::string class_name;
77 std::size_t pos = dir_name.find_last_of (sys::file_ops::dir_sep_chars ());
79 if (pos != std::string::npos)
81 std::string tmp = dir_name.substr (pos+1);
84 class_name = tmp.substr (1);
89 private_functions[sys::canonicalize_file_name (dir_name)] = ov_fcn;
95fcn_info::fcn_info_rep::load_class_constructor ()
103 std::string file_name = lp.
find_method (name, name, dir_name, package_name);
105 if (! file_name.empty ())
118 class_constructors[name] = retval;
119 class_methods[name] = retval;
139 retval = maybe_cdef_ctor;
141 class_constructors[name] = retval;
142 class_methods[name] = retval;
144 function_on_path = old_function_on_path;
153fcn_info::fcn_info_rep::load_class_method (
const std::string& dispatch_type)
157 if (full_name () == dispatch_type)
158 retval = load_class_constructor ();
167 std::string dir_name;
171 std::string file_name = lp.
find_method (dispatch_type, name,
174 if (! file_name.empty ())
188 class_methods[dispatch_type] = retval;
199 const std::list<std::string>& plist
202 auto it = plist.begin ();
204 while (it != plist.end ())
206 retval = find_method (*it);
210 class_methods[dispatch_type] = retval;
223 if (built_in_function.is_defined ())
229 retval = built_in_function;
231 class_methods[dispatch_type] = retval;
264 sup_table[i][j] = (use_j ? jtyp : ityp);
275 std::string dispatch_type;
282 builtin_type = args(0).builtin_type ();
285 for (i = 1; i < n; i++)
289 builtin_type = sup_table[builtin_type][bti];
301 dispatch_type = args(i).class_name ();
305 for (
int j = i+1; j < n; j++)
317 dispatch_type = cname;
327 return dispatch_type;
370 retval = xfind (search_scope, args);
378split_name_with_package (
const std::string& name, std::string& fname,
381 std::size_t pos = name.rfind (
'.');
386 if (pos != std::string::npos)
388 fname = name.substr (pos + 1);
389 pname = name.substr (0, pos);
409load_out_of_date_fcn (
const std::string& file_name,
410 const std::string& dir_name_arg,
412 const std::string& dispatch_type =
"",
413 const std::string& package_name =
"")
417 std::string dir_name = dir_name_arg;
419 if (dir_name.empty ())
421 std::size_t pos = file_name.find_last_of (sys::file_ops::dir_sep_chars ());
423 dir_name = file_name.substr (0, pos);
429 std::size_t pos = dir_name.find_last_of (sys::file_ops::dir_sep_chars ());
432 = pos != std::string::npos && dir_name.substr (pos+1) ==
"private";
435 dir_name = dir_name.substr (0, pos);
437 std::string class_name;
439 pos = dir_name.find_last_of (sys::file_ops::dir_sep_chars ());
441 if (pos != std::string::npos)
443 std::string tmp = dir_name.substr (pos+1);
446 class_name = tmp.substr (1);
472 const std::string& dispatch_type =
"",
473 bool check_relative =
true)
491 bool relative = check_relative && fcn->
is_relative ();
496 bool clear_breakpoints =
false;
497 std::string nm = fcn->
name ();
501 bool is_same_file =
false;
507 std::string dir_name;
511 int nm_len = nm.length ();
513 if (sys::env::absolute_pathname (nm)
515 && (nm.substr (nm_len-4) ==
".oct"
516 || nm.substr (nm_len-4) ==
".mex"))
518 && nm.substr (nm_len-2) ==
".m")))
526 if (! dispatch_type.empty ())
540 const std::list<std::string>& plist
543 std::list<std::string>::const_iterator it
546 while (it != plist.end ())
548 split_name_with_package (*it, s_name,
575 file = lp.
find_fcn (nm, dir_name, pack);
580 is_same_file = sys::same_file (file, ff);
595 clear_breakpoints =
true;
597 else if (is_same_file)
602 OCTAVE_TIME_T tp = ottp.unix_time ();
606 if (! (Vignore_function_time_stamp == 2
607 || (Vignore_function_time_stamp
610 sys::file_stat fs (ff);
614 if (fs.is_newer (tp))
616 retval = load_out_of_date_fcn (ff, dir_name,
621 clear_breakpoints =
true;
628 clear_breakpoints =
true;
637 retval = load_out_of_date_fcn (file, dir_name, function,
638 dispatch_type, pack);
640 clear_breakpoints =
true;
645 if (clear_breakpoints && is_user_code)
661fcn_info::fcn_info_rep::find_scoped_function (
const symbol_scope& search_scope)
680 if (! fcn_file.empty ())
682 auto r = local_functions.find (fcn_file);
684 if (r != local_functions.end ())
697 return find_private_function (search_scope.
dir_name ());
704fcn_info::fcn_info_rep::find_private_function (
const std::string& dir_name)
706 if (! dir_name.empty ())
708 auto q = private_functions.find (dir_name);
710 if (q == private_functions.end ())
722 out_of_date_check (fval,
"",
false);
746 return find_method (dispatch_type);
753fcn_info::fcn_info_rep::xfind (
const symbol_scope& search_scope,
760 fcn = find_scoped_function (search_scope);
767 fcn = find_method (args);
774 auto q = class_constructors.find (name);
776 if (q == class_constructors.end ())
788 out_of_date_check (fval, name);
803 if (cmdline_function.is_defined ())
804 return cmdline_function;
808 fcn = find_autoload ();
815 fcn = find_user_function ();
822 fcn = find_package ();
829 return built_in_function;
851fcn_info::fcn_info_rep::builtin_find (
const symbol_scope& scope)
869 retval = x_builtin_find (search_scope);
876fcn_info::fcn_info_rep::x_builtin_find (
const symbol_scope& search_scope)
879 if (built_in_function.is_defined ())
880 return built_in_function;
891 fcn = find_autoload ();
898 if (cmdline_function.is_defined ())
899 return cmdline_function;
907 std::string dir_name = search_scope.
dir_name ();
909 if (! dir_name.empty ())
911 auto q = private_functions.find (dir_name);
913 if (q == private_functions.end ())
925 out_of_date_check (fval);
943 if (! fcn_file.empty ())
945 auto r = local_functions.find (fcn_file);
947 if (r != local_functions.end ())
971fcn_info::fcn_info_rep::find_method (
const std::string& dispatch_type)
975 auto q = class_methods.find (dispatch_type);
977 if (q == class_methods.end ())
978 retval = load_class_method (dispatch_type);
984 out_of_date_check (retval, dispatch_type);
987 retval = load_class_method (dispatch_type);
1011fcn_info::fcn_info_rep::find_autoload ()
1015 if (autoload_function.is_defined ())
1016 out_of_date_check (autoload_function);
1018 if (! autoload_function.is_defined ())
1024 if (! file_name.empty ())
1026 std::size_t pos = file_name.find_last_of (sys::file_ops::dir_sep_chars ());
1028 std::string dir_name = file_name.substr (0, pos);
1038 return autoload_function;
1042fcn_info::fcn_info_rep::find_user_function ()
1046 if (function_on_path.is_defined ())
1047 out_of_date_check (function_on_path);
1049 if (function_on_path.is_undefined ())
1051 std::string dir_name;
1056 std::string file_name = lp.
find_fcn (name, dir_name, package_name);
1058 if (! file_name.empty ())
1064 function_on_path = ov_fcn;
1068 return function_on_path;
1072fcn_info::fcn_info_rep::find_package ()
1078 if (package.is_undefined ())
1082 package = cdm.find_package_symbol (full_name ());
1089fcn_info::fcn_info_rep::install_built_in_dispatch (
const std::string& klass)
1091 if (built_in_function.is_defined ())
1098 warning (
"install_built_in_dispatch: '%s' already defined for class '%s'",
1099 name.c_str (), klass.c_str ());
1105 error (
"install_built_in_dispatch: '%s' is not a built-in function",
1110fcn_info::fcn_info_rep::dump ()
const
1112 std::map<std::string, octave_value> m
1113 = {{
"name", full_name () },
1114 {
"package", package.
dump () },
1119 {
"cmdline_function", cmdline_function.
dump () },
1120 {
"autoload_function", autoload_function.
dump () },
1121 {
"function_on_path", function_on_path.
dump () },
1122 {
"built_in_function", built_in_function.
dump () }
1131 if (fcn_map.empty ())
1134 std::map<std::string, octave_value> info_map;
1136 for (
const auto& nm_fcn : fcn_map)
1138 std::string nm = nm_fcn.first;
1140 info_map[nm] = fcn.
dump ();
1146DEFUN (ignore_function_time_stamp, args, nargout,
1168 int nargin = args.
length ();
1175 if (nargout > 0 || nargin == 0)
1177 switch (Vignore_function_time_stamp)
1195 std::string sval = args(0).xstring_value (
"ignore_function_time_stamp: first argument must be a string");
1198 Vignore_function_time_stamp = 2;
1199 else if (sval ==
"system")
1200 Vignore_function_time_stamp = 1;
1201 else if (sval ==
"none")
1202 Vignore_function_time_stamp = 0;
1204 error (R
"(ignore_function_time_stamp: argument must be one of "all", "system", or "none")");
1228OCTAVE_END_NAMESPACE(octave)
bp_lines remove_all_breakpoints_from_function(const std::string &fcn_ident, bool silent=false)
octave_value find_method_symbol(const std::string &method_name, const std::string &class_name)
std::string find_fcn(const std::string &fcn, std::string &dir_name, const std::string &pack_name="")
std::string find_private_fcn(const std::string &dir, const std::string &fcn, const std::string &pack_name="")
std::string find_method(const std::string &class_name, const std::string &meth, std::string &dir_name, const std::string &pack_name="")
virtual bool is_anonymous_function() const
virtual bool is_user_code() const
virtual octave_function * function_value(bool silent=false)
virtual bool handles_dispatch_class(const std::string &) const
virtual bool is_subfunction() const
std::string canonical_name() const
std::string package_name() const
bool is_class_method(const std::string &cname="") const
virtual octave::sys::time time_checked() const
virtual void push_dispatch_class(const std::string &)
virtual bool is_classdef_constructor(const std::string &="") const
virtual void mark_fcn_file_up_to_date(const octave::sys::time &)
virtual octave::sys::time time_parsed() const
virtual std::string fcn_file_name() const
virtual void mark_as_private_function(const std::string &cname="")
virtual bool is_system_fcn_file() const
octave_idx_type length() const
bool is_undefined() const
std::string class_name() const
octave_function * function_value(bool silent=false) const
bool is_classdef_meta() const
octave_value dump() const
builtin_type_t builtin_type() const
std::string fcn_file_name() const
octave_value find_subfunction(const std::string &name) const
std::string dir_name() const
bool is_superiorto(const std::string &a, const std::string &b)
std::list< std::string > parent_classes(const std::string &dispatch_type)
std::string lookup_autoload(const std::string &nm) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void warning(const char *fmt,...)
void error(const char *fmt,...)
std::string get_dispatch_type(const octave_value_list &args, builtin_type_t &builtin_type)
octave_value dump_function_map(const std::map< std::string, octave_value > &fcn_map)
tree_evaluator & __get_evaluator__()
cdef_manager & __get_cdef_manager__()
symbol_table & __get_symbol_table__()
symbol_scope __get_current_scope__()
bp_table & __get_bp_table__()
load_path & __get_load_path__()
sys::time Vlast_chdir_time
octave_value load_fcn_from_file(const std::string &file_name, const std::string &dir_name, const std::string &dispatch_type, const std::string &package_name, const std::string &fcn_name, bool autoload)
std::string btyp_class_name[btyp_num_types+1]
bool btyp_isinteger(builtin_type_t btyp)
bool btyp_isarray(builtin_type_t btyp)