Mercurial > octave
changeset 27015:4d9e1a832a55
move core of mfilename function to evaluator
* pt-eval.h, pt-eval.cc (tree_evaluator::mfilename): Move innter
workings of mfilename function here from oct-parse.yy.
* interpreter.h, interpreter.cc (interpreter::mfilename): New function.
* oct-parse.yy (Fmfilename): Extract arguments and call
interpreter::mfilename.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 31 Mar 2019 20:50:10 +0000 |
parents | daab1b311a98 |
children | 9b261300a001 |
files | libinterp/corefcn/interpreter.cc libinterp/corefcn/interpreter.h libinterp/parse-tree/oct-parse.yy libinterp/parse-tree/pt-eval.cc libinterp/parse-tree/pt-eval.h |
diffstat | 5 files changed, 50 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/interpreter.cc Sun Mar 31 19:35:39 2019 +0000 +++ b/libinterp/corefcn/interpreter.cc Sun Mar 31 20:50:10 2019 +0000 @@ -1163,6 +1163,11 @@ return retval; } + std::string interpreter::mfilename (const std::string& opt) const + { + return m_evaluator.mfilename (opt); + } + octave_value_list interpreter::eval_string (const std::string& eval_str, bool silent, int& parse_status, int nargout)
--- a/libinterp/corefcn/interpreter.h Sun Mar 31 19:35:39 2019 +0000 +++ b/libinterp/corefcn/interpreter.h Sun Mar 31 20:50:10 2019 +0000 @@ -240,6 +240,8 @@ bool mislocked (const std::string& nm); + std::string mfilename (const std::string& opt = "") const; + octave_value_list eval_string (const std::string& eval_str, bool silent, int& parse_status, int nargout);
--- a/libinterp/parse-tree/oct-parse.yy Sun Mar 31 19:35:39 2019 +0000 +++ b/libinterp/parse-tree/oct-parse.yy Sun Mar 31 20:50:10 2019 +0000 @@ -5063,7 +5063,7 @@ if (verbose) octave_stdout << "done." << std::endl; - } + } } DEFMETHOD (mfilename, interp, args, , @@ -5085,51 +5085,17 @@ @seealso{inputname, dbstack} @end deftypefn */) { - octave_value retval; - int nargin = args.length (); if (nargin > 1) print_usage (); - std::string arg; + std::string opt; if (nargin == 1) - arg = args(0).xstring_value ("mfilename: argument must be a string"); - - std::string fname; - - octave::call_stack& cs = interp.get_call_stack (); - - octave_user_code *fcn = cs.caller_user_code (); - - if (fcn) - { - fname = fcn->fcn_file_name (); - - if (fname.empty ()) - fname = fcn->name (); - } - - if (arg == "fullpathext") - retval = fname; - else - { - size_t dpos = fname.rfind (octave::sys::file_ops::dir_sep_char ()); - size_t epos = fname.rfind ('.'); - - if (epos <= dpos+1) - epos = std::string::npos; - - fname = (epos != std::string::npos) ? fname.substr (0, epos) : fname; - - if (arg == "fullpath") - retval = fname; - else - retval = (dpos != std::string::npos) ? fname.substr (dpos+1) : fname; - } - - return retval; + opt = args(0).xstring_value ("mfilename: option argument must be a string"); + + return octave_value (interp.mfilename (opt)); } DEFUN (source, args, ,
--- a/libinterp/parse-tree/pt-eval.cc Sun Mar 31 19:35:39 2019 +0000 +++ b/libinterp/parse-tree/pt-eval.cc Sun Mar 31 20:50:10 2019 +0000 @@ -201,6 +201,42 @@ return retval; } + std::string + tree_evaluator::mfilename (const std::string& opt) const + { + std::string fname; + + octave_user_code *fcn = m_call_stack.caller_user_code (); + + if (fcn) + { + fname = fcn->fcn_file_name (); + + if (fname.empty ()) + fname = fcn->name (); + } + + if (opt == "fullpathext") + return fname; + + size_t dpos = fname.rfind (sys::file_ops::dir_sep_char ()); + size_t epos = fname.rfind ('.'); + + if (epos <= dpos+1) + epos = std::string::npos; + + if (epos != std::string::npos) + fname = fname.substr (0, epos); + + if (opt == "fullpath") + return fname; + + if (dpos != std::string::npos) + fname = fname.substr (dpos+1); + + return fname; + } + octave_value_list tree_evaluator::eval_string (const std::string& eval_str, bool silent, int& parse_status, int nargout)
--- a/libinterp/parse-tree/pt-eval.h Sun Mar 31 19:35:39 2019 +0000 +++ b/libinterp/parse-tree/pt-eval.h Sun Mar 31 20:50:10 2019 +0000 @@ -156,6 +156,8 @@ int repl (bool interactive); + std::string mfilename (const std::string& opt = "") const; + octave_value_list eval_string (const std::string& eval_str, bool silent, int& parse_status, int nargout);