Classes | Defines | Functions | Variables

variables.cc File Reference

#include <cstdio>
#include <cstring>
#include <iomanip>
#include <set>
#include <string>
#include "file-stat.h"
#include "oct-env.h"
#include "file-ops.h"
#include "glob-match.h"
#include "regexp.h"
#include "str-vec.h"
#include <defaults.h>
#include "Cell.h"
#include "defun.h"
#include "dirfns.h"
#include "error.h"
#include "gripes.h"
#include "help.h"
#include "input.h"
#include "lex.h"
#include "load-path.h"
#include "oct-map.h"
#include "oct-obj.h"
#include "ov.h"
#include "ov-class.h"
#include "ov-usr-fcn.h"
#include "pager.h"
#include "parse.h"
#include "symtab.h"
#include "toplev.h"
#include "unwind-prot.h"
#include "utils.h"
#include "variables.h"
Include dependency graph for variables.cc:

Go to the source code of this file.

Classes

struct  symbol_info_list::symbol_info
class  symbol_info_list
struct  whos_parameter

Defines

#define CLEAR_OPTION_ERROR(cond)
#define GET_IDX(LEN)   static_cast<int> ((LEN-1) * static_cast<double> (rand ()) / RAND_MAX)

Functions

void bind_ans (const octave_value &val, bool print)
void bind_internal_variable (const std::string &fname, const octave_value &val)
void clear_function (const std::string &nm)
void clear_mex_functions (void)
void clear_symbol (const std::string &nm)
void clear_variable (const std::string &nm)
 DEFUN (exist, args,,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} exist (@var{name}, @var{type})\n\ Return 1 if the name exists as a variable, 2 if the name is an\n\ absolute file name, an ordinary file in Octave's @code{path}, or (after\n\ appending @samp{.m}) a function file in Octave's @code{path}, 3 if the\n\ name is a @samp{.oct} or @samp{.mex} file in Octave's @code{path},\n\ 5 if the name is a built-in function, 7 if the name is a directory, or 103\n\ if the name is a function not associated with a file (entered on\n\ the command line).\n\ \n\ Otherwise, return 0.\n\ \n\ This function also returns 2 if a regular file called @var{name}\n\ exists in Octave's search path. If you want information about\n\ other types of files, you should use some combination of the functions\n\ @code{file_in_path} and @code{stat} instead.\n\ \n\ If the optional argument @var{type} is supplied, check only for\n\ symbols of the specified type. Valid types are\n\ \n\ @table @asis\n\ @item \"var\"\n\ Check only for variables.\n\ \n\ @item \"builtin\"\n\ Check only for built-in functions.\n\ \n\ @item \"file\"\n\ Check only for files.\n\ \n\ @item \"dir\"\n\ Check only for directories.\n\ @end table\n\ @seealso{file_in_loadpath}\n\ @end deftypefn")
 DEFUN (who, args, nargout,"-*- texinfo -*-\n\ @deftypefn {Command} {} who\n\ @deftypefnx {Command} {} who pattern @dots{}\n\ @deftypefnx {Command} {} who option pattern @dots{}\n\ @deftypefnx {Command} {C =} who (\"pattern\", @dots{})\n\ List currently defined variables matching the given patterns. Valid\n\ pattern syntax is the same as described for the @code{clear} command.\n\ If no patterns are supplied, all variables are listed.\n\ By default, only variables visible in the local scope are displayed.\n\ \n\ The following are valid options but may not be combined.\n\ \n\ @table @code\n\ @item global\n\ List variables in the global scope rather than the current scope.\n\ \n\ @item -regexp\n\ The patterns are considered to be regular expressions when matching the\n\ variables to display. The same pattern syntax accepted by\n\ the @code{regexp} function is used.\n\ \n\ @item -file\n\ The next argument is treated as a filename. All variables found within the\n\ specified file are listed. No patterns are accepted when reading variables\n\ from a file.\n\ @end table\n\ \n\ If called as a function, return a cell array of defined variable names\n\ matching the given patterns.\n\ @seealso{whos, isglobal, isvarname, exist, regexp}\n\ @end deftypefn")
 DEFUN (whos, args, nargout,"-*- texinfo -*-\n\ @deftypefn {Command} {} whos\n\ @deftypefnx {Command} {} whos pattern @dots{}\n\ @deftypefnx {Command} {} whos option pattern @dots{}\n\ @deftypefnx {Command} {S =} whos (\"pattern\", @dots{})\n\ Provide detailed information on currently defined variables matching the\n\ given patterns. Options and pattern syntax are the same as for the\n\ @code{who} command. Extended information about each variable is\n\ summarized in a table with the following default entries.\n\ \n\ @table @asis\n\ @item Attr\n\ Attributes of the listed variable. Possible attributes are:\n\ @table @asis\n\ @item blank\n\ Variable in local scope\n\ \n\ @item @code{a}\n\ Automatic variable. An automatic variable is one created by the\n\ interpreter, for example @code{argn}.\n\ \n\ @item @code{c}\n\ Variable of complex type.\n\ \n\ @item @code{f}\n\ Formal parameter (function argument).\n\ \n\ @item @code{g}\n\ Variable with global scope.\n\ \n\ @item @code{p}\n\ Persistent variable.\n\ @end table\n\ \n\ @item Name\n\ The name of the variable.\n\ \n\ @item Size\n\ The logical size of the variable. A scalar is 1x1, a vector is\n\ @nospell{1xN} or @nospell{Nx1}, a 2-D matrix is @nospell{MxN}.\n\ \n\ @item Bytes\n\ The amount of memory currently used to store the variable.\n\ \n\ @item Class\n\ The class of the variable. Examples include double, single, char, uint16,\n\ cell, and struct.\n\ @end table\n\ \n\ The table can be customized to display more or less information through\n\ the function @code{whos_line_format}.\n\ \n\ If @code{whos} is called as a function, return a struct array of defined\n\ variable names matching the given patterns. Fields in the structure\n\ describing each variable are: name, size, bytes, class, global, sparse,\n\ complex, nesting, persistent.\n\ @seealso{who, whos_line_format}\n\ @end deftypefn")
 DEFUN (mlock, args,,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} mlock ()\n\ Lock the current function into memory so that it can't be cleared.\n\ @seealso{munlock, mislocked, persistent}\n\ @end deftypefn")
 DEFUN (munlock, args,,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} munlock ()\n\ @deftypefnx {Built-in Function} {} munlock (@var{fcn})\n\ Unlock the named function @var{fcn}. If no function is named\n\ then unlock the current function.\n\ @seealso{mlock, mislocked, persistent}\n\ @end deftypefn")
 DEFUN (mislocked, args,,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} mislocked ()\n\ @deftypefnx {Built-in Function} {} mislocked (@var{fcn})\n\ Return true if the named function @var{fcn} is locked. If no function is\n\ named then return true if the current function is locked.\n\ @seealso{mlock, munlock, persistent}\n\ @end deftypefn")
 DEFUN (isglobal, args,,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} isglobal (@var{name})\n\ Return true if @var{name} is a globally visible variable.\n\ For example:\n\ \n\ @example\n\ @group\n\ global x\n\ isglobal (\"x\")\n\ @result{} 1\n\ @end group\n\ @end example\n\ @seealso{isvarname, exist}\n\ @end deftypefn")
 DEFUN (clear, args,,"-*- texinfo -*-\n\ @deftypefn {Command} {} clear [options] pattern @dots{}\n\ Delete the names matching the given patterns from the symbol table. The\n\ pattern may contain the following special characters:\n\ \n\ @table @code\n\ @item ?\n\ Match any single character.\n\ \n\ @item *\n\ Match zero or more characters.\n\ \n\ @item [ @var{list} ]\n\ Match the list of characters specified by @var{list}. If the first\n\ character is @code{!} or @code{^}, match all characters except those\n\ specified by @var{list}. For example, the pattern @samp{[a-zA-Z]} will\n\ match all lowercase and uppercase alphabetic characters.\n\ @end table\n\ \n\ For example, the command\n\ \n\ @example\n\ clear foo b*r\n\ @end example\n\ \n\ @noindent\n\ clears the name @code{foo} and all names that begin with the letter\n\ @code{b} and end with the letter @code{r}.\n\ \n\ If @code{clear} is called without any arguments, all user-defined\n\ variables (local and global) are cleared from the symbol table. If\n\ @code{clear} is called with at least one argument, only the visible\n\ names matching the arguments are cleared. For example, suppose you have\n\ defined a function @code{foo}, and then hidden it by performing the\n\ assignment @code{foo = 2}. Executing the command @kbd{clear foo} once\n\ will clear the variable definition and restore the definition of\n\ @code{foo} as a function. Executing @kbd{clear foo} a second time will\n\ clear the function definition.\n\ \n\ The following options are available in both long and short form\n\ @table @code\n\ @item -all, -a\n\ Clears all local and global user-defined variables and all functions\n\ from the symbol table.\n\ \n\ @item -exclusive, -x\n\ Clears the variables that don't match the following pattern.\n\ \n\ @item -functions, -f\n\ Clears the function names and the built-in symbols names.\n\ \n\ @item -global, -g\n\ Clears the global symbol names.\n\ \n\ @item -variables, -v\n\ Clears the local variable names.\n\ \n\ @item -classes, -c\n\ Clears the class structure table and clears all objects.\n\ \n\ @item -regexp, -r\n\ The arguments are treated as regular expressions as any variables that\n\ match will be cleared.\n\ @end table\n\ With the exception of @code{exclusive}, all long options can be used\n\ without the dash as well.\n\ @end deftypefn")
 DEFUN (whos_line_format, args, nargout,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {@var{val} =} whos_line_format ()\n\ @deftypefnx {Built-in Function} {@var{old_val} =} whos_line_format (@var{new_val})\n\ @deftypefnx {Built-in Function} {} whos_line_format (@var{new_val}, \"local\")\n\ Query or set the format string used by the command @code{whos}.\n\ \n\ A full format string is:\n\ @c Set example in small font to prevent overfull line\n\ \n\ @smallexample\n\ %[modifier]<command>[:width[:left-min[:balance]]];\n\ @end smallexample\n\ \n\ The following command sequences are available:\n\ \n\ @table @code\n\ @item %a\n\ Prints attributes of variables (g=global, p=persistent,\n\ f=formal parameter, a=automatic variable).\n\ \n\ @item %b\n\ Prints number of bytes occupied by variables.\n\ \n\ @item %c\n\ Prints class names of variables.\n\ \n\ @item %e\n\ Prints elements held by variables.\n\ \n\ @item %n\n\ Prints variable names.\n\ \n\ @item %s\n\ Prints dimensions of variables.\n\ \n\ @item %t\n\ Prints type names of variables.\n\ @end table\n\ \n\ Every command may also have an alignment modifier:\n\ \n\ @table @code\n\ @item l\n\ Left alignment.\n\ \n\ @item r\n\ Right alignment (default).\n\ \n\ @item c\n\ Column-aligned (only applicable to command %s).\n\ @end table\n\ \n\ The @code{width} parameter is a positive integer specifying the minimum\n\ number of columns used for printing. No maximum is needed as the field will\n\ auto-expand as required.\n\ \n\ The parameters @code{left-min} and @code{balance} are only available when the\n\ column-aligned modifier is used with the command @samp{%s}.\n\ @code{balance} specifies the column number within the field width which will\n\ be aligned between entries. Numbering starts from 0 which indicates the\n\ leftmost column. @code{left-min} specifies the minimum field width to the\n\ left of the specified balance column.\n\ \n\ The default format is\n\ @code{\" %a:4; %ln:6; %cs:16:6:1; %rb:12; %lc:-1;\\n\"}.\n\ \n\ When called from inside a function with the \"local\" option, the variable is\n\ changed locally for the function and any subroutines it calls. The original\n\ variable value is restored when exiting the function.\n\ @seealso{whos}\n\ @end deftypefn")
 DEFUN (missing_function_hook, args, nargout,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {@var{val} =} missing_function_hook ()\n\ @deftypefnx {Built-in Function} {@var{old_val} =} missing_function_hook (@var{new_val})\n\ @deftypefnx {Built-in Function} {} missing_function_hook (@var{new_val}, \"local\")\n\ Query or set the internal variable that specifies the function to call when\n\ an unknown identifier is requested.\n\ \n\ When called from inside a function with the \"local\" option, the variable is\n\ changed locally for the function and any subroutines it calls. The original\n\ variable value is restored when exiting the function.\n\ @end deftypefn")
 DEFUN (__varval__, args,,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} __varval__ (@var{name})\n\ Undocumented internal function.\n\ @end deftypefn")
static void do_clear_functions (const string_vector &argv, int argc, int idx, bool exclusive=false)
static void do_clear_globals (const string_vector &argv, int argc, int idx, bool exclusive=false)
static void do_clear_symbols (const string_vector &argv, int argc, int idx, bool exclusive=false)
static void do_clear_variables (const string_vector &argv, int argc, int idx, bool exclusive=false, bool have_regexp=false)
static octave_value do_isglobal (const octave_value_list &args)
static void do_matlab_compatible_clear (const string_vector &argv, int argc, int idx)
static octave_value do_who (int argc, const string_vector &argv, bool return_list, bool verbose=false, std::string msg=std::string())
octave_functionextract_function (const octave_value &arg, const std::string &warn_for, const std::string &fname, const std::string &header, const std::string &trailer)
string_vector generate_struct_completions (const std::string &text, std::string &prefix, std::string &hint)
std::string get_dims_str (const octave_value &val)
octave_value get_global_value (const std::string &nm, bool silent)
string_vector get_struct_elts (const std::string &text)
octave_value get_top_level_value (const std::string &nm, bool silent)
octave_functionis_valid_function (const octave_value &arg, const std::string &warn_for, bool warn)
octave_functionis_valid_function (const std::string &fcn_name, const std::string &warn_for, bool warn)
static bool is_variable (const std::string &name)
bool looks_like_struct (const std::string &text)
octave_value lookup_function_handle (const std::string &nm)
void maybe_missing_function_hook (const std::string &name)
static void maybe_warn_exclusive (bool exclusive)
bool mislocked (const std::string &nm)
void mlock (void)
void munlock (const std::string &nm)
static bool name_matches_any_pattern (const std::string &nm, const string_vector &argv, int argc, int idx, bool have_regexp=false)
static void print_descriptor (std::ostream &os, std::list< whos_parameter > params)
static octave_value safe_symbol_lookup (const std::string &symbol_name)
void set_global_value (const std::string &nm, const octave_value &val)
octave_value set_internal_variable (std::string &var, const octave_value_list &args, int nargout, const char *nm, bool empty_ok)
octave_value set_internal_variable (int &var, const octave_value_list &args, int nargout, const char *nm, const char **choices)
octave_value set_internal_variable (char &var, const octave_value_list &args, int nargout, const char *nm)
octave_value set_internal_variable (double &var, const octave_value_list &args, int nargout, const char *nm, double minval, double maxval)
octave_value set_internal_variable (int &var, const octave_value_list &args, int nargout, const char *nm, int minval, int maxval)
octave_value set_internal_variable (bool &var, const octave_value_list &args, int nargout, const char *nm)
void set_top_level_value (const std::string &nm, const octave_value &val)
int symbol_exist (const std::string &name, const std::string &type)
template<class T >
bool try_local_protect (T &var)
std::string unique_symbol_name (const std::string &basename)
static bool wants_local_change (const octave_value_list &args, int &nargin)

Variables

static std::string Vmissing_function_hook = "unimplemented"
static std::string Vwhos_line_format = " %a:4; %ln:6; %cs:16:6:1; %rb:12; %lc:-1;\n"

Define Documentation

#define CLEAR_OPTION_ERROR (   cond  ) 
Value:
do \
    { \
      if (cond) \
        { \
          print_usage (); \
          return retval; \
        } \
    } \
  while (0)

Definition at line 2249 of file variables.cc.

Referenced by DEFUN().

#define GET_IDX (   LEN  )     static_cast<int> ((LEN-1) * static_cast<double> (rand ()) / RAND_MAX)

Definition at line 493 of file variables.cc.

Referenced by unique_symbol_name().


Function Documentation

void bind_ans ( const octave_value val,
bool  print 
)
void bind_internal_variable ( const std::string &  fname,
const octave_value val 
)

Definition at line 1891 of file variables.cc.

References feval().

Referenced by maximum_braindamage(), and octave_main().

void clear_function ( const std::string &  nm  ) 

Definition at line 76 of file variables.cc.

References symbol_table::clear_function().

Referenced by symbol_table::clear_symbol(), and DEFUN_DLD().

void clear_mex_functions ( void   ) 

Definition at line 70 of file variables.cc.

References symbol_table::clear_mex_functions().

Referenced by do_octave_atexit().

void clear_symbol ( const std::string &  nm  ) 

Definition at line 88 of file variables.cc.

References symbol_table::clear_symbol().

void clear_variable ( const std::string &  nm  ) 

Definition at line 82 of file variables.cc.

References symbol_table::clear_variable().

Referenced by symbol_table::clear(), and symbol_table::clear_symbol().

DEFUN ( exist  ,
args   
)

Definition at line 517 of file variables.cc.

References error(), error_state, print_usage(), and symbol_exist().

DEFUN ( who  ,
args  ,
nargout   
)

Definition at line 1737 of file variables.cc.

References do_who(), error_state, and print_usage().

DEFUN ( whos  ,
args  ,
nargout   
)

Definition at line 1787 of file variables.cc.

References do_who(), error_state, and print_usage().

DEFUN ( mlock  ,
args   
)
DEFUN ( munlock  ,
args   
)
DEFUN ( mislocked  ,
args   
)
DEFUN ( isglobal  ,
args   
)

Definition at line 354 of file variables.cc.

References do_isglobal().

DEFUN ( clear  ,
args   
)
DEFUN ( whos_line_format  ,
args  ,
nargout   
)

Definition at line 2459 of file variables.cc.

References SET_INTERNAL_VARIABLE.

DEFUN ( missing_function_hook  ,
args  ,
nargout   
)

Definition at line 2537 of file variables.cc.

References SET_INTERNAL_VARIABLE.

DEFUN ( __varval__  ,
args   
)

Definition at line 2571 of file variables.cc.

References error(), error_state, print_usage(), and symbol_table::varval().

static void do_clear_functions ( const string_vector argv,
int  argc,
int  idx,
bool  exclusive = false 
) [static]
static void do_clear_globals ( const string_vector argv,
int  argc,
int  idx,
bool  exclusive = false 
) [static]
static void do_clear_symbols ( const string_vector argv,
int  argc,
int  idx,
bool  exclusive = false 
) [static]
static void do_clear_variables ( const string_vector argv,
int  argc,
int  idx,
bool  exclusive = false,
bool  have_regexp = false 
) [static]
static octave_value do_isglobal ( const octave_value_list args  )  [static]

Definition at line 331 of file variables.cc.

References error(), error_state, symbol_table::is_global(), octave_value_list::length(), and print_usage().

Referenced by DEFUN().

static void do_matlab_compatible_clear ( const string_vector argv,
int  argc,
int  idx 
) [static]
static octave_value do_who ( int  argc,
const string_vector argv,
bool  return_list,
bool  verbose = false,
std::string  msg = std::string () 
) [static]
octave_function* extract_function ( const octave_value arg,
const std::string &  warn_for,
const std::string &  fname,
const std::string &  header,
const std::string &  trailer 
)
string_vector generate_struct_completions ( const std::string &  text,
std::string &  prefix,
std::string &  hint 
)
std::string get_dims_str ( const octave_value val  ) 
octave_value get_global_value ( const std::string &  nm,
bool  silent 
)

Definition at line 605 of file variables.cc.

References error(), symbol_table::global_varval(), and octave_value::is_undefined().

Referenced by mexGetVariable().

string_vector get_struct_elts ( const std::string &  text  ) 

Definition at line 191 of file variables.cc.

References Array< T >::length().

octave_value get_top_level_value ( const std::string &  nm,
bool  silent 
)
octave_function* is_valid_function ( const octave_value arg,
const std::string &  warn_for,
bool  warn 
)
octave_function* is_valid_function ( const std::string &  fcn_name,
const std::string &  warn_for,
bool  warn 
)
static bool is_variable ( const std::string &  name  )  [inline, static]

Definition at line 228 of file variables.cc.

References octave_value::is_defined(), and symbol_table::varval().

Referenced by generate_struct_completions().

bool looks_like_struct ( const std::string &  text  ) 
octave_value lookup_function_handle ( const std::string &  nm  ) 
void maybe_missing_function_hook ( const std::string &  name  ) 
static void maybe_warn_exclusive ( bool  exclusive  )  [inline, static]

Definition at line 2076 of file variables.cc.

References warning().

Referenced by DEFUN().

bool mislocked ( const std::string &  nm  ) 
void mlock ( void   ) 

Definition at line 1901 of file variables.cc.

References octave_call_stack::current(), error(), and octave_function::lock().

Referenced by DEFUN_DLD(), and mexLock().

void munlock ( const std::string &  nm  ) 
static bool name_matches_any_pattern ( const std::string &  nm,
const string_vector argv,
int  argc,
int  idx,
bool  have_regexp = false 
) [inline, static]

Definition at line 2041 of file variables.cc.

References is_regexp_match(), and glob_match::match().

Referenced by do_clear_functions(), do_clear_globals(), and do_clear_variables().

static void print_descriptor ( std::ostream &  os,
std::list< whos_parameter params 
) [static]
static octave_value safe_symbol_lookup ( const std::string &  symbol_name  )  [static]

Definition at line 374 of file variables.cc.

References error_state, symbol_table::find(), and interpreter_try().

Referenced by symbol_exist().

void set_global_value ( const std::string &  nm,
const octave_value val 
)

Definition at line 616 of file variables.cc.

References symbol_table::global_varref().

Referenced by mexPutVariable().

octave_value set_internal_variable ( std::string &  var,
const octave_value_list args,
int  nargout,
const char nm,
bool  empty_ok 
)
octave_value set_internal_variable ( int var,
const octave_value_list args,
int  nargout,
const char nm,
const char **  choices 
)
octave_value set_internal_variable ( char var,
const octave_value_list args,
int  nargout,
const char nm 
)
octave_value set_internal_variable ( double var,
const octave_value_list args,
int  nargout,
const char nm,
double  minval,
double  maxval 
)
octave_value set_internal_variable ( int var,
const octave_value_list args,
int  nargout,
const char nm,
int  minval,
int  maxval 
)
octave_value set_internal_variable ( bool var,
const octave_value_list args,
int  nargout,
const char nm 
)
void set_top_level_value ( const std::string &  nm,
const octave_value val 
)

Definition at line 633 of file variables.cc.

References symbol_table::top_level_varref().

int symbol_exist ( const std::string &  name,
const std::string &  type 
)
template<class T >
bool try_local_protect ( T &  var  ) 
std::string unique_symbol_name ( const std::string &  basename  ) 

Definition at line 497 of file variables.cc.

References GET_IDX, and symbol_exist().

Referenced by DEFUN_DLD().

static bool wants_local_change ( const octave_value_list args,
int nargin 
) [static]

Definition at line 641 of file variables.cc.

References error_with_cfn().

Referenced by set_internal_variable().


Variable Documentation

std::string Vmissing_function_hook = "unimplemented" [static]

Definition at line 2535 of file variables.cc.

std::string Vwhos_line_format = " %a:4; %ln:6; %cs:16:6:1; %rb:12; %lc:-1;\n" [static]

Definition at line 67 of file variables.cc.

Referenced by symbol_info_list::parse_whos_line_format().

 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines