Mercurial > hg > octave-nkf
changeset 15004:ea6997657614
which: provide source file name for built-in functions
* defun-int.h, defun.cc (install_builtin_function): New arg, FILE.
Pass file to octave_builtin constructor.
* mkbuiltins: Redefine XDEFUN_FILE_NAME to create a local FILE
variable. Pass FILE to install_builtin_function.
* ov-builtin.h (octave_builtin::file): New member variable.
(octave_builtin::octave_builtin): Handle file name.
(octave_builtin::fcn_file_name): New function.
* ov-fcn-handle.cc (octave_fcn_handle::set_fcn): Only attempt to load
functions from .oct, .mex, or .m files.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 23 Jul 2012 12:59:44 -0400 |
parents | 1f5dbfc23fc2 |
children | 74c7265c057a |
files | src/defun-int.h src/defun.cc src/mkbuiltins src/ov-builtin.h src/ov-fcn-handle.cc |
diffstat | 5 files changed, 26 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/src/defun-int.h +++ b/src/defun-int.h @@ -39,7 +39,7 @@ extern OCTINTERP_API void install_builtin_function (octave_builtin::fcn f, const std::string& name, - const std::string& doc, + const std::string& file, const std::string& doc, bool can_hide_function = true); extern OCTINTERP_API void
--- a/src/defun.cc +++ b/src/defun.cc @@ -80,10 +80,10 @@ void install_builtin_function (octave_builtin::fcn f, const std::string& name, - const std::string& doc, + const std::string& file, const std::string& doc, bool /* can_hide_function -- not yet implemented */) { - octave_value fcn (new octave_builtin (f, name, doc)); + octave_value fcn (new octave_builtin (f, name, file, doc)); symbol_table::install_built_in_function (name, fcn); }
--- a/src/mkbuiltins +++ b/src/mkbuiltins @@ -57,19 +57,20 @@ #endif -#define XDEFUN_FILE_NAME(name) +#define XDEFUN_FILE_NAME(name) \ + std::string file = name; #define XDEFUN_INTERNAL(name, args_name, nargout_name, doc) \ extern DECLARE_FUN (name, args_name, nargout_name); \ - install_builtin_function (F ## name, #name, doc); \ + install_builtin_function (F ## name, #name, file, doc); \ #define XDEFCONSTFUN_INTERNAL(name, args_name, nargout_name, doc) \ extern DECLARE_FUN (name, args_name, nargout_name); \ - install_builtin_function (F ## name, #name, doc, false); \ + install_builtin_function (F ## name, #name, file, doc, false); \ #define XDEFUNX_INTERNAL(name, fname, args_name, nargout_name, doc) \ extern DECLARE_FUNX (fname, args_name, nargout_name); \ - install_builtin_function (fname, name, doc); \ + install_builtin_function (fname, name, file, doc); \ #define XDEFALIAS_INTERNAL(alias, name) \ alias_builtin (#alias, #name);
--- a/src/ov-builtin.h +++ b/src/ov-builtin.h @@ -40,16 +40,22 @@ { public: - octave_builtin (void) : octave_function (), f (0), jtype (0) { } + octave_builtin (void) : octave_function (), f (0), file (), jtype (0) { } typedef octave_value_list (*fcn) (const octave_value_list&, int); octave_builtin (fcn ff, const std::string& nm = std::string (), const std::string& ds = std::string ()) - : octave_function (nm, ds), f (ff), jtype (0) { } + : octave_function (nm, ds), f (ff), file (), jtype (0) { } + + octave_builtin (fcn ff, const std::string& nm, const std::string& fnm, + const std::string& ds) + : octave_function (nm, ds), f (ff), file (fnm), jtype (0) { } ~octave_builtin (void) { } + std::string fcn_file_name (void) const { return file; } + octave_value subsref (const std::string& type, const std::list<octave_value_list>& idx) { @@ -89,6 +95,9 @@ // A pointer to the actual function. fcn f; + // The name of the file where this function was defined. + std::string file; + // A pointer to the jit type that represents the function. jit_type *jtype;
--- a/src/ov-fcn-handle.cc +++ b/src/ov-fcn-handle.cc @@ -313,7 +313,11 @@ } else { - if (fpath.length () > 0) + size_t fpath_len = fpath.length (); + + if ((fpath_len > 4 && fpath.substr (fpath_len-4) == ".oct") + || (fpath_len > 4 && fpath.substr (fpath_len-4) == ".mex") + || (fpath_len > 2 && fpath.substr (fpath_len-4) == ".m")) { size_t xpos = fpath.find_last_of (file_ops::dir_sep_chars ()); @@ -327,11 +331,6 @@ fcn = octave_value (new octave_fcn_handle (tmp, nm)); } - else - { - error ("function handle points to non-existent function"); - success = false; - } } else { @@ -384,9 +383,10 @@ { octave_function *f = function_value (); std::string fnm = f ? f->fcn_file_name () : std::string (); + bool is_builtin = f && f->is_builtin_function (); os << "# octaveroot: " << OCTAVE_EXEC_PREFIX << "\n"; - if (! fnm.empty ()) + if (! (is_builtin || fnm.empty ())) os << "# path: " << fnm << "\n"; os << nm << "\n"; }