26 #if defined (HAVE_CONFIG_H)
37 #include "builtin-defun-decls.h"
73 m_scope.set_user_code (
nullptr);
95 warning (
"function file '%s' changed since it was parsed",
108 std::deque<std::string>
119 const octave::sys::time& timestamp)
125 warning (
"help text for function is newer than function");
127 m_file_info =
new octave::file_info (text, timestamp);
130 std::map<std::string, octave_value>
133 return std::map<std::string, octave_value> ();
139 std::map<std::string, octave_value>
m
153 "user-defined script",
154 "user-defined script");
161 (
const std::string& fnm,
const std::string& nm,
162 const octave::symbol_scope& scope, octave::tree_statement_list *cmds,
163 const std::string& ds)
171 (
const std::string& fnm,
const std::string& nm,
172 const octave::symbol_scope& scope,
const std::string& ds)
185 tw.push_stack_frame (
this);
187 octave::unwind_action act ([&tw] () { tw.pop_stack_frame (); });
189 return execute (tw, nargout, args);
196 return tw.execute_user_script (*
this, nargout, args);
202 tw.visit_octave_user_script (*
this);
208 "user-defined function",
209 "user-defined function");
215 (
const octave::symbol_scope& scope, octave::tree_parameter_list *pl,
216 octave::tree_parameter_list *rl, octave::tree_statement_list *cl)
218 m_param_list (pl), m_ret_list (rl),
219 m_lead_comm (), m_trail_comm (),
220 m_location_line (0), m_location_column (0),
221 m_system_fcn_file (false),
222 m_num_named_args (m_param_list ? m_param_list->length () : 0),
223 m_subfunction (false), m_inline_function (false),
224 m_anonymous_function (false), m_nested_function (false),
225 m_class_constructor (none), m_class_method (none)
260 octave::tree_statement *last_stmt =
m_cmd_list->back ();
262 if (last_stmt && last_stmt->is_end_of_fcn_or_script ()
263 && last_stmt->is_end_of_file ())
265 octave::tree_statement_list::reverse_iterator
280 octave::tree_statement *next_to_last_stmt = *next_to_last_elt;
282 new_eof_line = next_to_last_stmt->line ();
283 new_eof_col = next_to_last_stmt->column ();
286 last_stmt->set_location (new_eof_line + 1, new_eof_col);
294 std::map<std::string, octave_value> fcns =
subfunctions ();
298 for (
auto& nm_fnval : fcns)
303 f->maybe_relocate_end_internal ();
319 std::ostringstream result;
329 result <<
'@' <<
name ();
336 return result.str ();
355 static const std::string canonical_fcn_file_dir
360 : canonical_fcn_file_dir;
390 m_scope.mark_subfunctions_in_scope_as_private (cname);
404 m_scope.unlock_subfunctions ();
407 std::map<std::string, octave_value>
410 return m_scope.subfunctions ();
420 std::string subfcns = subfcns_arg;
422 std::string first_fcn = subfcns;
424 std::size_t pos = subfcns.find (
'>');
426 if (pos == std::string::npos)
430 first_fcn = subfcns.substr (0, pos-1);
431 subfcns = subfcns.substr (pos+1);
436 if (subfcns.empty ())
447 return m_scope.has_subfunctions ();
453 m_scope.stash_subfunction_names (names);
456 std::list<std::string>
459 return m_scope.subfunction_names ();
484 tw.push_stack_frame (
this);
486 octave::unwind_action act ([&tw] () { tw.pop_stack_frame (); });
488 return execute (tw, nargout, args);
495 return tw.execute_user_function (*
this, nargout, args);
501 tw.visit_octave_user_function (*
this);
504 octave::tree_expression *
510 octave::tree_statement *stmt =
m_cmd_list->front ();
511 return stmt->expression ();
523 octave::tree_identifier *par1 =
m_param_list->front ()->ident ();
524 octave::tree_identifier *ret1 =
m_ret_list->front ()->ident ();
525 retval = par1->name () == ret1->name ();
551 retval =
"unrecognized enum value";
578 retval =
"unrecognized enum value";
588 std::map<std::string, octave_value>
m
612 tpc.visit_octave_user_function_header (*
this);
620 tpc.visit_octave_user_function_trailer (*
this);
628 octave::tree_evaluator& tw = interp.get_evaluator ();
631 = tw.get_auto_fcn_var (octave::stack_frame::SAVED_WARNING_STATES);
643 Cell ids =
m.contents (
"identifier");
644 Cell states =
m.contents (
"state");
686 int nargin = args.length ();
704 error (
"nargin: invalid function name: %s", name.c_str ());
709 error (
"nargin: FCN must be a string or function handle");
718 std::string type = fcn_val->
type_name ();
719 error (
"nargin: number of input arguments unavailable for %s objects",
725 retval = (m_param_list ? m_param_list->
length () : 0);
727 retval = -1 - retval;
797 int nargin = args.length ();
815 error (
"nargout: invalid function name: %s", name.c_str ());
831 error (
"nargout: FCN must be a string or function handle");
840 std::string type = fcn_val->
type_name ();
841 error (
"nargout: number of output arguments unavailable for %s objects",
847 retval = (m_ret_list ? m_ret_list->
length () : 0);
850 retval = -1 - retval;
854 if (interp.at_top_level ())
855 error (
"nargout: invalid call at top level");
868 DEFUN (optimize_subsasgn_calls, args, nargout,
886 "optimize_subsasgn_calls");
895 return (i > 0 && table(i-1) == val);
901 error (
"isargout: K must be a positive integer");
903 return (k == 1 || k <= nargout) && !
val_in_table (ignored, k);
924 if (args.length () != 1)
927 if (interp.at_top_level ())
928 error (
"isargout: invalid call at top level");
944 if (args(0).is_scalar_type ())
946 double k = args(0).double_value ();
950 else if (args(0).isnumeric ())
952 const NDArray ka = args(0).array_value ();
OCTARRAY_OVERRIDABLE_FUNC_API bool isempty(void) const
Size of the specified dimension.
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type numel(void) const
Number of elements in the array.
OCTARRAY_OVERRIDABLE_FUNC_API const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
OCTARRAY_API octave_idx_type lookup(const T &value, sortmode mode=UNSORTED) const
Do a binary lookup in a sorted array.
std::size_t length(void) const
virtual octave_user_function * user_function_value(bool silent=false)
virtual std::string type_name(void) const
friend class octave_value
bool is_anonymous(void) const
std::string dispatch_class(void) const
bool is_class_method(const std::string &cname="") const
bool is_class_constructor(const std::string &cname="") const
virtual void mark_as_private_function(const std::string &cname="")
std::string name(void) const
octave_value dump(void) const
std::string fcn_file_name(void) const
std::string get_code_line(std::size_t line)
octave::sys::time m_t_checked
std::deque< std::string > get_code_lines(std::size_t line, std::size_t num_lines)
octave::tree_statement_list * m_cmd_list
octave::sys::time m_t_parsed
octave::file_info * m_file_info
octave::sys::time time_parsed(void) const
void cache_function_text(const std::string &text, const octave::sys::time ×tamp)
virtual std::map< std::string, octave_value > subfunctions(void) const
octave::symbol_scope m_scope
std::string parent_fcn_name(void) const
void restore_warning_states(void)
octave::tree_expression * special_expr(void)
void unlock_subfunctions(void)
void erase_subfunctions(void)
void mark_as_system_fcn_file(void)
octave_value_list call(octave::tree_evaluator &tw, int nargout=0, const octave_value_list &args=octave_value_list())
bool is_special_expr(void) const
octave::tree_parameter_list * return_list(void)
octave::comment_list * m_trail_comm
octave::tree_parameter_list * m_param_list
void stash_parent_fcn_scope(const octave::symbol_scope &ps)
void maybe_relocate_end(void)
int m_end_location_column
octave_user_function * define_ret_list(octave::tree_parameter_list *t)
octave_value_list all_va_args(const octave_value_list &args)
void stash_subfunction_names(const std::list< std::string > &names)
std::string profiler_name(void) const
bool is_classdef_constructor(const std::string &cname="") const
bool takes_varargs(void) const
octave_value_list execute(octave::tree_evaluator &tw, int nargout=0, const octave_value_list &args=octave_value_list())
octave::tree_parameter_list * parameter_list(void)
bool takes_var_return(void) const
void mark_as_private_function(const std::string &cname="")
std::list< std::string > subfunction_names(void) const
int beginning_column(void) const
class_method_type m_class_method
void print_code_function_header(const std::string &prefix)
octave::tree_parameter_list * m_ret_list
void accept(octave::tree_walker &tw)
bool is_inline_function(void) const
void print_code_function_trailer(const std::string &prefix)
std::map< std::string, octave_value > subfunctions(void) const
bool has_subfunctions(void) const
~octave_user_function(void)
octave_value find_subfunction(const std::string &subfuns) const
octave_user_function(const octave::symbol_scope &scope=octave::symbol_scope(), octave::tree_parameter_list *pl=nullptr, octave::tree_parameter_list *rl=nullptr, octave::tree_statement_list *cl=nullptr)
class_method_type m_class_constructor
bool is_subfunction(void) const
bool subsasgn_optimization_ok(void)
int beginning_line(void) const
void lock_subfunctions(void)
std::string method_type_str(void) const
bool m_anonymous_function
octave::comment_list * m_lead_comm
std::string ctor_type_str(void) const
octave_value dump(void) const
bool is_anonymous_function(void) const
void maybe_relocate_end_internal(void)
void accept(octave::tree_walker &tw)
octave_value_list call(octave::tree_evaluator &tw, int nargout=0, const octave_value_list &args=octave_value_list())
octave_value_list execute(octave::tree_evaluator &tw, int nargout=0, const octave_value_list &args=octave_value_list())
octave_idx_type length(void) const
octave_value_list slice(octave_idx_type offset, octave_idx_type len, bool tags=false) const
OCTINTERP_API octave_function * function_value(bool silent=false) const
int int_value(bool req_int=false, bool frc_str_conv=false) const
bool is_string(void) const
bool is_defined(void) const
bool is_function_handle(void) const
OCTINTERP_API octave_user_function * user_function_value(bool silent=false) const
bool isstruct(void) const
OCTINTERP_API octave_fcn_handle * fcn_handle_value(bool silent=false) const
std::string string_value(bool force=false) const
OCTINTERP_API octave_map map_value(void) const
bool is_undefined(void) const
bool is_inline_function(void) const
Matrix matrix_value(bool frc_str_conv=false) const
octave_value find_function(const std::string &name, const symbol_scope &search_scope=symbol_scope())
octave_value get_auto_fcn_var(stack_frame::auto_var_type avt) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
std::string fcn_file_dir(void)
OCTINTERP_API void print_usage(void)
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void warning(const char *fmt,...)
OCTAVE_EXPORT octave_value_list Fwarning(octave::interpreter &interp, const octave_value_list &args, int nargout)
void error(const char *fmt,...)
void panic_unless(bool cond)
#define panic_impossible()
void err_wrong_type_arg(const char *name, const char *s)
std::string canonicalize_file_name(const std::string &name)
interpreter & __get_interpreter__(void)
event_manager & __get_event_manager__(void)
F77_RET_T const F77_DBLE const F77_DBLE * f
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
static bool Voptimize_subsasgn_calls
static bool val_in_table(const Matrix &table, double val)
static bool isargout1(int nargout, const Matrix &ignored, double k)
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
std::string fcn_file_in_path(const std::string &name)
octave_value set_internal_variable(bool &var, const octave_value_list &args, int nargout, const char *nm)