64 std::map<std::string, octave_value>
67 return std::map<std::string, octave_value> ();
74 "user-defined script",
75 "user-defined script");
79 t_parsed (static_cast<time_t> (0)),
80 t_checked (static_cast<time_t> (0)),
85 const std::string& nm,
87 const std::string& ds)
89 t_parsed (static_cast<time_t> (0)),
90 t_checked (static_cast<time_t> (0)),
98 const std::string& nm,
99 const std::string& ds)
101 t_parsed (static_cast<time_t> (0)),
102 t_checked (static_cast<time_t> (0)),
116 const std::list<octave_value_list>&,
int)
120 ::error (
"invalid use of script %s in index expression",
file_name.c_str ());
135 if (args.
length () == 0 && nargout == 0)
164 ::error (
"max_recursion_depth exceeded");
184 "user-defined function",
185 "user-defined function");
194 param_list (pl), ret_list (rl), cmd_list (cl),
195 lead_comm (), trail_comm (), file_name (),
196 location_line (0), location_column (0),
197 parent_name (), t_parsed (static_cast<time_t> (0)),
198 t_checked (static_cast<time_t> (0)),
200 num_named_args (param_list ? param_list->length () : 0),
201 subfunction (
false), inline_function (
false),
202 anonymous_function (
false), nested_function (
false),
203 class_constructor (none), class_method (
false),
204 parent_scope (-1), local_scope (sid),
205 curr_unwind_protect_frame (0)
211 cmd_list->mark_as_function_body ();
213 if (local_scope >= 0)
285 new_eof_line = next_to_last_stmt->
line ();
286 new_eof_col = next_to_last_stmt->
column ();
289 last_stmt->
set_location (new_eof_line + 1, new_eof_col);
297 std::map<std::string, octave_value> fcns =
subfunctions ();
301 for (std::map<std::string, octave_value>::iterator p = fcns.begin ();
302 p != fcns.end (); p++)
317 std::ostringstream result;
327 result <<
"@" <<
name ();
334 return result.str ();
384 std::map<std::string, octave_value>
398 (
const std::list<std::string>&
names)
400 subfcn_names =
names;
418 const std::list<octave_value_list>& idx,
426 const std::list<octave_value_list>& idx,
428 const std::list<octave_lvalue>* lvalue_list)
436 int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout;
439 idx.size () == 1 ? lvalue_list : 0);
447 error (
"%s cannot be indexed with %c", nm.c_str (), type[0]);
460 retval = retval(0).next_subsref (nargout, type, idx);
475 const std::list<octave_lvalue>* lvalue_list)
495 ret_args = args.
slice (0, 1,
true);
508 int nargin = args.
length ();
517 ::error (
"max_recursion_depth exceeded");
558 ::error (
"%s: invalid classdef constructor, no output argument defined",
621 retval = (lvalue_list
622 ? expr->
rvalue (nargout, lvalue_list)
623 : expr->
rvalue (nargout));
659 error (
"expecting varargout to be a cell array object");
697 retval = par1->
name () == ret1->
name ();
705 octave_user_function::print_symtab_info (std::ostream& os)
const
731 const std::list<octave_lvalue> *lvalue_list)
733 if (! arg_names.
empty ())
764 if (takes_varargs ())
773 for (std::list<octave_lvalue>::const_iterator p = lvalue_list->begin ();
774 p != lvalue_list->end (); p++)
775 nbh += p->is_black_hole ();
783 for (std::list<octave_lvalue>::const_iterator
784 p = lvalue_list->begin (); p != lvalue_list->end (); p++)
786 if (p->is_black_hole ())
825 DEFUN (nargin, args, ,
827 @deftypefn {Built-in Function} {} nargin ()\n\
828 @deftypefnx {Built-in Function} {} nargin (@var{fcn})\n\
829 Report the number of input arguments to a function.\n\
831 Called from within a function, return the number of arguments passed to the\n\
832 function. At the top level, return the number of command line arguments\n\
835 If called with the optional argument @var{fcn}---a function name or handle---\n\
836 return the declared number of arguments that the function can accept.\n\
838 If the last argument to @var{fcn} is @var{varargin} the returned value is\n\
839 negative. For example, the function @code{union} for sets is declared as\n\
843 function [y, ia, ib] = union (a, b, varargin)\n\
847 nargin (\"union\")\n\
852 Programming Note: @code{nargin} does not work on built-in functions.\n\
853 @seealso{nargout, narginchk, varargin, inputname}\n\
858 int nargin = args.length ();
869 error (
"nargout: invalid function name: %s", name.c_str ());
881 retval = param_list ? param_list->
length () : 0;
883 retval = -1 - retval;
889 error (
"nargin: nargin information not available for built-in functions");
893 error (
"nargin: FCN must be a string or function handle");
895 else if (nargin == 0)
908 DEFUN (nargout, args, ,
910 @deftypefn {Built-in Function} {} nargout ()\n\
911 @deftypefnx {Built-in Function} {} nargout (@var{fcn})\n\
912 Report the number of output arguments from a function.\n\
914 Called from within a function, return the number of values the caller expects\n\
915 to receive. At the top level, @code{nargout} with no argument is undefined\n\
916 and will produce an error.\n\
918 If called with the optional argument @var{fcn}---a function name or\n\
919 handle---return the number of declared output values that the function can\n\
922 If the final output argument is @var{varargout} the returned value is\n\
932 will cause @code{nargout} to return 0 inside the function @code{f} and\n\
939 will cause @code{nargout} to return 2 inside the function @code{f}.\n\
941 In the second usage,\n\
944 nargout (@@histc) \% or nargout (\"histc\")\n\
948 will return 2, because @code{histc} has two outputs, whereas\n\
951 nargout (@@imread)\n\
955 will return -2, because @code{imread} has two outputs and the second is\n\
958 Programming Note. @code{nargout} does not work for built-in functions and\n\
959 returns -1 for all anonymous functions.\n\
960 @seealso{nargin, varargout, isargout, nthargout}\n\
965 int nargin = args.length ();
976 error (
"nargout: invalid function name: %s", name.c_str ());
988 std::string fh_nm = fh->
fcn_name ();
1006 retval = ret_list ? ret_list->
length () : 0;
1009 retval = -1 - retval;
1017 error (
"nargout: nargout information not available for built-in functions.");
1021 error (
"nargout: FCN must be a string or function handle");
1023 else if (nargin == 0)
1033 error (
"nargout: invalid call at top level");
1041 DEFUN (optimize_subsasgn_calls, args, nargout,
1043 @deftypefn {Built-in Function} {@var{val} =} optimize_subsasgn_calls ()\n\
1044 @deftypefnx {Built-in Function} {@var{old_val} =} optimize_subsasgn_calls (@var{new_val})\n\
1045 @deftypefnx {Built-in Function} {} optimize_subsasgn_calls (@var{new_val}, \"local\")\n\
1046 Query or set the internal flag for subsasgn method call optimizations.\n\
1048 If true, Octave will attempt to eliminate the redundant copying when calling\n\
1049 the subsasgn method of a user-defined class.\n\
1051 When called from inside a function with the @qcode{\"local\"} option, the\n\
1052 variable is changed locally for the function and any subroutines it calls.\n\
1053 The original variable value is restored when exiting the function.\n\
1065 return (i > 0 && table(i-1) == val);
1070 if (k !=
xround (k) || k <= 0)
1072 error (
"isargout: K must be a positive integer");
1076 return (k == 1 || k <= nargout) && !
val_in_table (ignored, k);
1079 DEFUN (isargout, args, ,
1081 @deftypefn {Built-in Function} {} isargout (@var{k})\n\
1082 Within a function, return a logical value indicating whether the argument\n\
1083 @var{k} will be assigned to a variable on output.\n\
1085 If the result is false, the argument has been ignored during the function\n\
1086 call through the use of the tilde (~) special output argument. Functions\n\
1087 can use @code{isargout} to avoid performing unnecessary calculations for\n\
1088 outputs which are unwanted.\n\
1090 If @var{k} is outside the range @code{1:max (nargout)}, the function returns\n\
1091 false. @var{k} can also be an array, in which case the function works\n\
1092 element-by-element and a logical array is returned. At the top level,\n\
1093 @code{isargout} returns an error.\n\
1094 @seealso{nargout, varargout, nthargout}\n\
1099 int nargin = args.length ();
1108 error (
"isargout: internal error");
1117 if (args(0).is_scalar_type ())
1119 double k = args(0).double_value ();
1121 retval =
isargout1 (nargout1, ignored, k);
1123 else if (args(0).is_numeric_type ())
1125 const NDArray ka = args(0).array_value ();
1132 r(i) =
isargout1 (nargout1, ignored, ka(i));
1141 error (
"isargout: invalid call at top level");
reverse_iterator rbegin(void)
virtual std::map< std::string, octave_value > subfunctions(void) const
~octave_user_function(void)
bool has_subfunctions(void) const
int beginning_line(void) const
static bool Voptimize_subsasgn_calls
symbol_table::scope_id local_scope
const Cell & contents(const_iterator p) const
bool is_empty(void) const
void accept(tree_walker &tw)
size_t length(void) const
octave_user_function * user_function_value(bool=false)
static void mark_hidden(const std::string &name)
static bool val_in_table(const Matrix &table, double val)
static const std::string anonymous
std::list< std::string > subfcn_names
bool takes_var_return(void) const
void gripe_wrong_type_arg(const char *name, const char *s, bool is_error)
static bool at_top_level(void)
virtual void visit_octave_user_function(octave_user_function &)=0
octave_comment_list * trail_comm
octave_value_list slice(octave_idx_type offset, octave_idx_type len, bool tags=false) const
void set_location(int l, int c)
tree_parameter_list * parameter_list(void)
OCTINTERP_API void print_usage(void)
void visit_octave_user_function_header(octave_user_function &)
static void mark_automatic(const std::string &name)
octave_idx_type numel(void) const
Number of elements in the array.
bool is_classdef_constructor(const std::string &cname=std::string()) const
octave_idx_type length(void) const
void accept(tree_walker &tw)
virtual void visit_octave_user_script(octave_user_script &)=0
octave_map map_value(void) const
void bind_automatic_vars(const string_vector &arg_names, int nargin, int nargout, const octave_value_list &va_args, const std::list< octave_lvalue > *lvalue_list)
bool is_defined(void) const
static bool execute(tree_simple_for_command &cmd, const octave_value &bounds)
octave_value_list all_va_args(const octave_value_list &args)
void maybe_relocate_end_internal(void)
int int_value(bool req_int=false, bool frc_str_conv=false) const
string_vector name_tags(void) const
bool is_inline_function(void) const
#define DEFUN(name, args_name, nargout_name, doc)
void error(const char *fmt,...)
std::string name(void) const
#define SET_INTERNAL_VARIABLE(NM)
bool is_special_expr(void) const
std::string Vfcn_file_dir
static string_vector names(const map_type &lst)
static stmt_list_type statement_context
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
octave_comment_list * lead_comm
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
static void lock_subfunctions(scope_id scope=xcurrent_scope)
octave_idx_type numel(void) const
bool is_end_of_file(void) const
void restore_warning_states(void)
octave_fcn_handle * fcn_handle_value(bool silent=false) const
void add_method(T *obj, void(T::*method)(void))
std::string fcn_file_in_path(const std::string &name)
static octave_value find_function(const std::string &name, const octave_value_list &args=octave_value_list(), bool local_funcs=true)
std::list< tree_statement * >::reverse_iterator reverse_iterator
#define END_PROFILER_BLOCK
symbol_table::context_id active_context() const
static octave_value varval(const std::string &name, scope_id scope=xcurrent_scope, context_id context=xdefault_context)
static void clear_variables(void)
octave_idx_type lookup(const T &value, sortmode mode=UNSORTED) const
Do a binary lookup in a sorted array.
bool is_function_handle(void) const
unwind_protect * curr_unwind_protect_frame
bool takes_varargs(void) const
std::string dispatch_class(void) const
bool is_subfunction(void) const
tree_identifier * ident(void)
bool is_class_method(const std::string &cname=std::string()) const
Cell cell_value(void) const
static void set_curr_fcn(octave_user_function *curr_fcn, scope_id scope=xcurrent_scope)
Cell cell_value(void) const
void define_from_arg_vector(const octave_value_list &args)
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
void print_code_function_header(void)
bool is_anonymous_function(void) const
std::string profiler_name(void) const
virtual octave_user_function * user_function_value(bool silent=false)
F77_RET_T const double const double * f
void add_fcn(void(*fcn)(void))
void lock_subfunctions(void)
static llvm::LLVMContext & context
std::string string_value(bool force=false) const
void mark_as_system_fcn_file(void)
tree_parameter_list * return_list(void)
std::string name(void) const
reverse_iterator rend(void)
void maybe_relocate_end(void)
void stash_subfunction_names(const std::list< std::string > &names)
bool is_string(void) const
static void push_context(void)
static void force_assign(const std::string &name, const octave_value &value=octave_value(), scope_id scope=xcurrent_scope, context_id context=xdefault_context)
bool is_inline_function(void) const
octave_value_list do_multi_index_op(int nargout, const octave_value_list &args)
octave_value_list convert_to_const_vector(int nargout, const Cell &varargout)
void unlock_subfunctions(void)
static void pop_context(void)
octave_user_function(symbol_table::scope_id sid=-1, tree_parameter_list *pl=0, tree_parameter_list *rl=0, tree_statement_list *cl=0)
#define panic_impossible()
static void assign(const std::string &name, const octave_value &value=octave_value(), scope_id scope=xcurrent_scope, context_id context=xdefault_context, bool force_add=false)
static void push(octave_function *f, symbol_table::scope_id scope=symbol_table::current_scope(), symbol_table::context_id context=symbol_table::current_context())
tree_statement_list * cmd_list
std::string fcn_file_name(void) const
tree_expression * special_expr(void)
tree_evaluator * current_evaluator
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
Matrix matrix_value(bool frc_str_conv=false) const
bool takes_varargs(void) const
octave_function * function_value(bool silent=false) const
bool is_end_of_fcn_or_script(void) const
void visit_octave_user_function_trailer(octave_user_function &)
bool subsasgn_optimization_ok(void)
OCTINTERP_API octave_value_list Fwarning(const octave_value_list &=octave_value_list(), int=0)
octave_value_list ovl(const octave_value &a0)
jit_function_info * jit_info
octave_value_list do_multi_index_op(int nargout, const octave_value_list &args)
void initialize_undefined_elements(const std::string &warnfor, int nargout, const octave_value &val)
tree_expression * expression(void)
tree_statement_list * cmd_list
virtual octave_value_list rvalue(int nargout)
octave_user_function * define_ret_list(tree_parameter_list *t)
bool is_undefined(void) const
tree_parameter_list * param_list
std::map< std::string, octave_value > subfunctions(void) const
void print_code_function_trailer(void)
~octave_user_script(void)
void stash_fcn_file_name(const std::string &nm)
static void unlock_subfunctions(scope_id scope=xcurrent_scope)
static bool isargout1(int nargout, const Matrix &ignored, double k)
int beginning_column(void) const
bool is_class_constructor(const std::string &cname=std::string()) const
OCTAVE_EMPTY_CPP_ARG std::string type_name(void) const
bp_table::intmap remove_all_breakpoints(const std::string &file)
std::string parent_fcn_name(void) const
static std::map< std::string, octave_value > subfunctions_defined_in_scope(scope_id scope=xcurrent_scope)
tree_parameter_list * ret_list
void mark_as_script_body(void)
#define BEGIN_PROFILER_BLOCK(classname)
static void erase_scope(scope_id scope)
std::string fcn_name(void) const
void accept(tree_walker &tw)