GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
symtab.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1993-2017 John W. Eaton
4 Copyright (C) 2009 VZLU Prague
5 
6 This file is part of Octave.
7 
8 Octave is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with Octave; see the file COPYING. If not, see
20 <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #if ! defined (octave_symtab_h)
25 #define octave_symtab_h 1
26 
27 #include "octave-config.h"
28 
29 #include <deque>
30 #include <list>
31 #include <map>
32 #include <set>
33 #include <string>
34 
35 #include "glob-match.h"
36 #include "lo-regexp.h"
37 
38 class tree_argument_list;
40 
41 #include "ovl.h"
42 #include "workspace-element.h"
43 #include "oct-refcount.h"
44 #include "ov.h"
45 
46 class
49 {
50 public:
51 
53 
54  typedef int scope_id;
55  typedef size_t context_id;
56 
57  class
59  {
60  protected:
61 
62  typedef std::set<scope_id>::iterator set_iterator;
63  typedef std::set<scope_id>::const_iterator set_const_iterator;
64 
65  // We start with 2 because we allocate 0 for the global symbols
66  // and 1 for the top-level workspace.
67 
68  scope_id_cache (void) : next_available (2), in_use (), free_list () { }
69 
70  public:
71 
72  ~scope_id_cache (void) { }
73 
74  static scope_id alloc (void)
75  {
76  return instance_ok () ? instance->do_alloc () : -1;
77  }
78 
79  static void free (scope_id scope)
80  {
81  if (instance_ok ())
82  return instance->do_free (scope);
83  }
84 
85  static std::list<scope_id> scopes (void)
86  {
87  return instance_ok () ? instance->do_scopes () : std::list<scope_id> ();
88  }
89 
90  static void create_instance (void);
91 
92  static bool instance_ok (void)
93  {
94  bool retval = true;
95 
96  if (! instance)
97  create_instance ();
98 
99  if (! instance)
100  error ("unable to create scope_id_cache object!");
101 
102  return retval;
103  }
104 
105  private:
106 
107  // No copying!
108 
110 
112 
114 
115  static void cleanup_instance (void) { delete instance; instance = 0; }
116 
117  // The next available scope not in the free list.
118  scope_id next_available;
119 
120  // The set of scope IDs that are currently allocated.
121  std::set<scope_id> in_use;
122 
123  // The set of scope IDs that are currently available.
124  std::set<scope_id> free_list;
125 
126  scope_id do_alloc (void)
127  {
128  scope_id retval;
129 
130  set_iterator p = free_list.begin ();
131 
132  if (p != free_list.end ())
133  {
134  retval = *p;
135  free_list.erase (p);
136  }
137  else
138  retval = next_available++;
139 
140  in_use.insert (retval);
141 
142  return retval;
143  }
144 
145  void do_free (scope_id scope)
146  {
147  set_iterator p = in_use.find (scope);
148 
149  if (p == in_use.end ())
150  error ("free_scope: scope %d not found!", scope);
151 
152  in_use.erase (p);
153  free_list.insert (scope);
154  }
155 
156  std::list<scope_id> do_scopes (void) const
157  {
158  std::list<scope_id> retval;
159 
160  for (set_const_iterator p = in_use.begin (); p != in_use.end (); p++)
161  retval.push_back (*p);
162 
163  retval.sort ();
164 
165  return retval;
166  }
167  };
168 
169  class fcn_info;
170 
171  class
173  {
174  public:
175 
176  // generic variable
177  static const unsigned int local = 1;
178 
179  // varargin, argn, .nargin., .nargout.
180  // (FIXME: is this really used now?)
181  static const unsigned int automatic = 2;
182 
183  // formal parameter
184  static const unsigned int formal = 4;
185 
186  // not listed or cleared (.nargin., .nargout.)
187  static const unsigned int hidden = 8;
188 
189  // inherited from parent scope; not cleared at function exit
190  static const unsigned int inherited = 16;
191 
192  // global (redirects to global scope)
193  static const unsigned int global = 32;
194 
195  // not cleared at function exit
196  static const unsigned int persistent = 64;
197 
198  // this symbol may NOT become a variable.
199  // (symbol added to a static workspace)
200  static const unsigned int added_static = 128;
201 
202  private:
203 
204  class
206  {
207  public:
208 
209  symbol_record_rep (scope_id s, const std::string& nm,
210  const octave_value& v, unsigned int sc)
211  : decl_scope (s), curr_fcn (0), name (nm), value_stack (),
212  storage_class (sc), finfo (), valid (true), count (1)
213  {
214  value_stack.push_back (v);
215  }
216 
217  void assign (const octave_value& value,
218  context_id context = xdefault_context)
219  {
220  varref (context) = value;
221  }
222 
224  const std::string& type,
225  const std::list<octave_value_list>& idx,
226  const octave_value& value,
227  context_id context = xdefault_context)
228  {
229  varref(context).assign (op, type, idx, value);
230  }
231 
233  context_id context = xdefault_context)
234  {
235  varref(context).assign (op, value);
236  }
237 
239  context_id context = xdefault_context)
240  {
241  varref(context).do_non_const_unary_op (op);
242  }
243 
245  const std::string& type,
246  const std::list<octave_value_list>& idx,
247  context_id context = xdefault_context)
248  {
249  varref(context).do_non_const_unary_op (op, type, idx);
250  }
251 
252  octave_value& varref (context_id context = xdefault_context)
253  {
254  // We duplicate global_varref and persistent_varref here to
255  // avoid calling deprecated functions.
256 
257  if (is_global ())
258  {
261 
262  return (p == symbol_table::global_table.end ())
263  ? symbol_table::global_table[name] : p->second;
264  }
265  else if (is_persistent ())
266  {
267  symbol_table *inst
269 
270  return inst ? inst->do_persistent_varref (name) : dummy_octave_value;
271  }
272  else
273  {
274  if (context == xdefault_context)
275  context = active_context ();
276 
277  context_id n = value_stack.size ();
278  while (n++ <= context)
279  value_stack.push_back (octave_value ());
280 
281  return value_stack[context];
282  }
283  }
284 
285  octave_value varval (context_id context = xdefault_context) const
286  {
287  if (is_global ())
289  else if (is_persistent ())
291  else
292  {
293  if (context == xdefault_context)
294  context = active_context ();
295 
296  if (context < value_stack.size ())
297  return value_stack[context];
298  else
299  return octave_value ();
300  }
301  }
302 
303  void push_context (scope_id s)
304  {
305  if (! (is_persistent () || is_global ())
306  && s == scope ())
307  value_stack.push_back (octave_value ());
308  }
309 
310  // If pop_context returns 0, we are out of values and this element
311  // of the symbol table should be deleted. This can happen for
312  // functions like
313  //
314  // function foo (n)
315  // if (n > 0)
316  // foo (n-1);
317  // else
318  // eval ("x = 1");
319  // endif
320  // endfunction
321  //
322  // Here, X should only exist in the final stack frame.
323 
324  size_t pop_context (scope_id s)
325  {
326  size_t retval = 1;
327 
328  if (! (is_persistent () || is_global ())
329  && s == scope ())
330  {
331  value_stack.pop_back ();
332  retval = value_stack.size ();
333  }
334 
335  return retval;
336  }
337 
338  void clear (void) { clear (scope ()); }
339 
340  void clear (scope_id s)
341  {
342  if (! (is_hidden () || is_inherited ())
343  && s == scope ())
344  {
345  if (is_global ())
346  unmark_global ();
347 
348  if (is_persistent ())
349  {
351 
352  unmark_persistent ();
353  }
354 
355  assign (octave_value ());
356  }
357  }
358 
359  bool is_defined (context_id context = xdefault_context) const
360  {
361  if (context == xdefault_context)
362  context = active_context ();
363 
364  return varval (context).is_defined ();
365  }
366 
367  bool is_valid (void) const
368  {
369  return valid;
370  }
371 
372  bool is_variable (context_id context) const
373  {
374  if (context == xdefault_context)
375  context = active_context ();
376 
377  return (! is_local () || is_defined (context));
378  }
379 
380  bool is_local (void) const { return storage_class & local; }
381  bool is_automatic (void) const { return storage_class & automatic; }
382  bool is_formal (void) const { return storage_class & formal; }
383  bool is_hidden (void) const { return storage_class & hidden; }
384  bool is_inherited (void) const { return storage_class & inherited; }
385  bool is_global (void) const { return storage_class & global; }
386  bool is_persistent (void) const { return storage_class & persistent; }
387  bool is_added_static (void) const {return storage_class & added_static; }
388 
389  void mark_local (void) { storage_class |= local; }
390  void mark_automatic (void) { storage_class |= automatic; }
391  void mark_formal (void) { storage_class |= formal; }
392  void mark_hidden (void) { storage_class |= hidden; }
393  void mark_inherited (void) { storage_class |= inherited; }
394  void mark_global (void)
395  {
396  if (is_persistent ())
397  error ("can't make persistent variable %s global", name.c_str ());
398 
399  storage_class |= global;
400  }
401  void mark_persistent (void)
402  {
403  if (is_global ())
404  error ("can't make global variable %s persistent", name.c_str ());
405 
406  storage_class |= persistent;
407  }
408  void mark_added_static (void) { storage_class |= added_static; }
409 
410  void unmark_local (void) { storage_class &= ~local; }
411  void unmark_automatic (void) { storage_class &= ~automatic; }
412  void unmark_formal (void) { storage_class &= ~formal; }
413  void unmark_hidden (void) { storage_class &= ~hidden; }
414  void unmark_inherited (void) { storage_class &= ~inherited; }
415  void unmark_global (void) { storage_class &= ~global; }
416  void unmark_persistent (void) { storage_class &= ~persistent; }
417  void unmark_added_static (void) { storage_class &= ~added_static; }
418 
419  void init_persistent (void)
420  {
421  if (! is_defined ())
422  {
423  mark_persistent ();
424 
426  }
427  // FIXME: this causes trouble with recursive calls.
428  // else
429  // error ("unable to declare existing variable persistent");
430  }
431 
432  void invalidate (void)
433  {
434  valid = false;
435  }
436 
437  void erase_persistent (void)
438  {
439  unmark_persistent ();
441  }
442 
443  OCTINTERP_API context_id active_context (void) const;
444 
445  scope_id scope (void) const { return decl_scope; }
446 
448  {
449  curr_fcn = fcn;
450  }
451 
452  symbol_record_rep *dup (scope_id new_scope) const
453  {
454  return new symbol_record_rep (new_scope, name, varval (),
455  storage_class);
456  }
457 
458  void dump (std::ostream& os, const std::string& prefix) const;
459 
460  scope_id decl_scope;
461 
463 
465 
466  std::deque<octave_value> value_stack;
467 
468  unsigned int storage_class;
469 
471 
472  bool valid;
473 
475 
476  private:
477 
478  // No copying!
479 
481 
482  symbol_record_rep& operator = (const symbol_record_rep&);
483  };
484 
485  public:
486 
487  symbol_record (scope_id s = xcurrent_scope,
488  const std::string& nm = "",
489  const octave_value& v = octave_value (),
490  unsigned int sc = local)
491  : rep (new symbol_record_rep (s, nm, v, sc)) { }
492 
494  : rep (sr.rep)
495  {
496  rep->count++;
497  }
498 
499  symbol_record& operator = (const symbol_record& sr)
500  {
501  if (this != &sr)
502  {
503  if (--rep->count == 0)
504  delete rep;
505 
506  rep = sr.rep;
507  rep->count++;
508  }
509 
510  return *this;
511  }
512 
514  {
515  if (--rep->count == 0)
516  delete rep;
517  }
518 
519  symbol_record dup (scope_id new_scope) const
520  {
521  return symbol_record (rep->dup (new_scope));
522  }
523 
524  const std::string& name (void) const { return rep->name; }
525 
526  void rename (const std::string& new_name) { rep->name = new_name; }
527 
529  find (const octave_value_list& args = octave_value_list ()) const;
530 
531  void assign (const octave_value& value,
532  context_id context = xdefault_context)
533  {
534  rep->assign (value, context);
535  }
536 
538  const std::string& type,
539  const std::list<octave_value_list>& idx,
540  const octave_value& value,
541  context_id context = xdefault_context)
542  {
543  rep->assign (op, type, idx, value, context);
544  }
545 
547  context_id context = xdefault_context)
548  {
549  rep->assign (op, value, context);
550  }
551 
553  {
554  rep->do_non_const_unary_op (op);
555  }
556 
558  const std::string& type,
559  const std::list<octave_value_list>& idx)
560  {
561  rep->do_non_const_unary_op (op, type, idx);
562  }
563 
564  // Delete when deprecated varref functions are removed.
565  octave_value& varref (context_id context = xdefault_context)
566  {
567  return rep->varref (context);
568  }
569 
570  octave_value varval (context_id context = xdefault_context) const
571  {
572  return rep->varval (context);
573  }
574 
575  void push_context (scope_id s) { rep->push_context (s); }
576 
577  size_t pop_context (scope_id s) { return rep->pop_context (s); }
578 
579  void clear (void) { rep->clear (); }
580 
581  void clear (scope_id s) { rep->clear (s); }
582 
583  bool is_defined (context_id context = xdefault_context) const
584  {
585  return rep->is_defined (context);
586  }
587 
588  bool is_undefined (context_id context = xdefault_context) const
589  {
590  return ! rep->is_defined (context);
591  }
592 
593  bool is_valid (void) const
594  {
595  return rep->is_valid ();
596  }
597 
598  bool is_variable (context_id context = xdefault_context) const
599  {
600  return rep->is_variable (context);
601  }
602 
603  bool is_local (void) const { return rep->is_local (); }
604  bool is_automatic (void) const { return rep->is_automatic (); }
605  bool is_formal (void) const { return rep->is_formal (); }
606  bool is_global (void) const { return rep->is_global (); }
607  bool is_hidden (void) const { return rep->is_hidden (); }
608  bool is_inherited (void) const { return rep->is_inherited (); }
609  bool is_persistent (void) const { return rep->is_persistent (); }
610  bool is_added_static (void) const { return rep->is_added_static (); }
611 
612  void mark_local (void) { rep->mark_local (); }
613  void mark_automatic (void) { rep->mark_automatic (); }
614  void mark_formal (void) { rep->mark_formal (); }
615  void mark_hidden (void) { rep->mark_hidden (); }
616  void mark_inherited (void) { rep->mark_inherited (); }
617  void mark_global (void) { rep->mark_global (); }
618  void mark_persistent (void) { rep->mark_persistent (); }
619  void mark_added_static (void) { rep->mark_added_static (); }
620 
621  void unmark_local (void) { rep->unmark_local (); }
622  void unmark_automatic (void) { rep->unmark_automatic (); }
623  void unmark_formal (void) { rep->unmark_formal (); }
624  void unmark_hidden (void) { rep->unmark_hidden (); }
625  void unmark_inherited (void) { rep->unmark_inherited (); }
626  void unmark_global (void) { rep->unmark_global (); }
627  void unmark_persistent (void) { rep->unmark_persistent (); }
628  void unmark_added_static (void) { rep->unmark_added_static (); }
629 
630  void init_persistent (void) { rep->init_persistent (); }
631 
632  void erase_persistent (void) { rep->erase_persistent (); }
633 
634  void invalidate (void) { rep->invalidate (); }
635 
636  context_id active_context (void) const { return rep->active_context (); }
637 
638  scope_id scope (void) const { return rep->scope (); }
639 
640  unsigned int xstorage_class (void) const { return rep->storage_class; }
641 
642  void set_curr_fcn (octave_user_function *fcn) { rep->set_curr_fcn (fcn); }
643 
644  void
645  dump (std::ostream& os, const std::string& prefix = "") const
646  {
647  rep->dump (os, prefix);
648  }
649 
650  private:
651 
653 
654  symbol_record (symbol_record_rep *new_rep) : rep (new_rep) { }
655  };
656 
658 
659  // Always access a symbol from the current scope.
660  // Useful for scripts, as they may be executed in more than one scope.
661  class
663  {
664  public:
665 
666  symbol_reference (void) : scope (-1) { }
667 
669  scope_id curr_scope = symbol_table::current_scope ())
670  : scope (curr_scope), sym (record)
671  { }
672 
674  : scope (ref.scope), sym (ref.sym)
675  { }
676 
677  symbol_reference& operator = (const symbol_reference& ref)
678  {
679  if (this != &ref)
680  {
681  scope = ref.scope;
682  sym = ref.sym;
683  }
684  return *this;
685  }
686 
687  bool is_black_hole (void) const { return scope < 0; }
688 
689  // The name is the same regardless of scope.
690  const std::string& name (void) const { return sym.name (); }
691 
692  symbol_record *operator-> (void)
693  {
694  update ();
695  return &sym;
696  }
697 
698  symbol_record *operator-> (void) const
699  {
700  update ();
701  return &sym;
702  }
703 
704  // can be used to place symbol_reference in maps, we don't overload < as
705  // it doesn't make any sense for symbol_reference
706  struct comparator
707  {
708  bool operator ()(const symbol_reference& lhs,
709  const symbol_reference& rhs) const
710  {
711  return lhs.name () < rhs.name ();
712  }
713  };
714  private:
715 
716  void update (void) const
717  {
718  scope_id curr_scope = symbol_table::current_scope ();
719 
720  if (scope != curr_scope || ! sym.is_valid ())
721  {
722  scope = curr_scope;
723  sym = symbol_table::insert (sym.name ());
724  }
725  }
726 
727  mutable scope_id scope;
729  };
730 
731  class
732  fcn_info
733  {
734  public:
735 
736  typedef std::map<std::string, std::string> dispatch_map_type;
737 
738  typedef std::map<scope_id, octave_value>::const_iterator
740  typedef std::map<scope_id, octave_value>::iterator scope_val_iterator;
741 
742  typedef std::map<std::string, octave_value>::const_iterator
744  typedef std::map<std::string, octave_value>::iterator str_val_iterator;
745 
746  typedef dispatch_map_type::const_iterator dispatch_map_const_iterator;
747  typedef dispatch_map_type::iterator dispatch_map_iterator;
748 
749  private:
750 
751  class
753  {
754  public:
755 
757  : name (nm), package_name (), subfunctions (), private_functions (),
758  class_constructors (), class_methods (), dispatch_map (),
759  cmdline_function (), autoload_function (), function_on_path (),
760  built_in_function (), count (1)
761  {
762  size_t pos = name.rfind ('.');
763 
764  if (pos != std::string::npos)
765  {
766  package_name = name.substr (0, pos);
767  name = name.substr (pos+1);
768  }
769  }
770 
771  octave_value load_private_function (const std::string& dir_name);
772 
773  octave_value load_class_constructor (void);
774 
775  octave_value load_class_method (const std::string& dispatch_type);
776 
777  octave_value find (const octave_value_list& args, bool local_funcs);
778 
779  octave_value builtin_find (void);
780 
781  octave_value find_method (const std::string& dispatch_type);
782 
783  octave_value find_autoload (void);
784 
785  octave_value find_package (void);
786 
787  octave_value find_user_function (void);
788 
789  bool is_user_function_defined (void) const
790  {
791  return function_on_path.is_defined ();
792  }
793 
795  bool local_funcs)
796  {
797  return find (args, local_funcs);
798  }
799 
800  void lock_subfunction (scope_id scope)
801  {
802  scope_val_iterator p = subfunctions.find (scope);
803 
804  if (p != subfunctions.end ())
805  p->second.lock ();
806  }
807 
808  void unlock_subfunction (scope_id scope)
809  {
810  scope_val_iterator p = subfunctions.find (scope);
811 
812  if (p != subfunctions.end ())
813  p->second.unlock ();
814  }
815 
816  std::pair<std::string, octave_value>
817  subfunction_defined_in_scope (scope_id scope) const
818  {
819  scope_val_const_iterator p = subfunctions.find (scope);
820 
821  return p == subfunctions.end ()
822  ? std::pair<std::string, octave_value> ()
823  : std::pair<std::string, octave_value> (name, p->second);
824  }
825 
826  void erase_subfunction (scope_id scope)
827  {
828  scope_val_iterator p = subfunctions.find (scope);
829 
830  if (p != subfunctions.end ())
831  subfunctions.erase (p);
832  }
833 
834  void mark_subfunction_in_scope_as_private (scope_id scope,
835  const std::string& class_name);
836 
838  {
839  cmdline_function = f;
840  }
841 
842  void install_subfunction (const octave_value& f, scope_id scope)
843  {
844  subfunctions[scope] = f;
845  }
846 
848  {
849  function_on_path = f;
850  }
851 
853  {
854  built_in_function = f;
855  }
856 
857  template <typename T>
858  void
859  clear_map (std::map<T, octave_value>& map, bool force = false)
860  {
861  typename std::map<T, octave_value>::iterator p = map.begin ();
862 
863  while (p != map.end ())
864  {
865  if (force || ! p->second.islocked ())
866  map.erase (p++);
867  else
868  p++;
869  }
870  }
871 
872  void clear_autoload_function (bool force = false)
873  {
874  if (force || ! autoload_function.islocked ())
875  autoload_function = octave_value ();
876  }
877 
878  // We also clear command line functions here, as these are both
879  // "user defined"
880  void clear_user_function (bool force = false)
881  {
882  clear_autoload_function (force);
883 
884  if (force || ! function_on_path.islocked ())
885  function_on_path = octave_value ();
886 
887  if (force || ! cmdline_function.islocked ())
888  cmdline_function = octave_value ();
889  }
890 
891  void clear_mex_function (void)
892  {
893  if (function_on_path.is_mex_function ())
894  clear_user_function ();
895  }
896 
897  void clear_package (void)
898  {
899  package = octave_value ();
900  }
901 
902  void clear (bool force = false)
903  {
904  clear_map (subfunctions, force);
905  clear_map (private_functions, force);
906  clear_map (class_constructors, force);
907  clear_map (class_methods, force);
908 
909  clear_autoload_function (force);
910  clear_user_function (force);
911  clear_package ();
912  }
913 
915  {
916  dispatch_map[type] = fname;
917  }
918 
920  {
921  dispatch_map_iterator p = dispatch_map.find (type);
922 
923  if (p != dispatch_map.end ())
924  dispatch_map.erase (p);
925  }
926 
927  void print_dispatch (std::ostream& os) const;
928 
929  std::string help_for_dispatch (void) const;
930 
931  dispatch_map_type get_dispatch (void) const { return dispatch_map; }
932 
933  void dump (std::ostream& os, const std::string& prefix) const;
934 
935  std::string full_name (void) const
936  {
937  if (package_name.empty ())
938  return name;
939  else
940  return package_name + "." + name;
941  }
942 
944 
946 
947  // Scope id to function object.
948  std::map<scope_id, octave_value> subfunctions;
949 
950  // Directory name to function object.
951  std::map<std::string, octave_value> private_functions;
952 
953  // Class name to function object.
954  std::map<std::string, octave_value> class_constructors;
955 
956  // Dispatch type to function object.
957  std::map<std::string, octave_value> class_methods;
958 
959  // Legacy dispatch map (dispatch type name to function name).
960  dispatch_map_type dispatch_map;
961 
963 
965 
967 
969 
971 
973 
974  private:
975 
976  octave_value xfind (const octave_value_list& args, bool local_funcs);
977 
978  octave_value x_builtin_find (void);
979 
980  // No copying!
981 
982  fcn_info_rep (const fcn_info_rep&);
983 
984  fcn_info_rep& operator = (const fcn_info_rep&);
985  };
986 
987  public:
988 
989  fcn_info (const std::string& nm = "")
990  : rep (new fcn_info_rep (nm)) { }
991 
992  fcn_info (const fcn_info& fi) : rep (fi.rep)
993  {
994  rep->count++;
995  }
996 
997  fcn_info& operator = (const fcn_info& fi)
998  {
999  if (this != &fi)
1000  {
1001  if (--rep->count == 0)
1002  delete rep;
1003 
1004  rep = fi.rep;
1005  rep->count++;
1006  }
1007 
1008  return *this;
1009  }
1010 
1011  ~fcn_info (void)
1012  {
1013  if (--rep->count == 0)
1014  delete rep;
1015  }
1016 
1018  bool local_funcs = true)
1019  {
1020  return rep->find (args, local_funcs);
1021  }
1022 
1024  {
1025  return rep->builtin_find ();
1026  }
1027 
1028  octave_value find_method (const std::string& dispatch_type) const
1029  {
1030  return rep->find_method (dispatch_type);
1031  }
1032 
1034  {
1035  return rep->built_in_function;
1036  }
1037 
1039  {
1040  return rep->cmdline_function;
1041  }
1042 
1044  {
1045  return rep->find_autoload ();
1046  }
1047 
1049  {
1050  return rep->find_user_function ();
1051  }
1052 
1053  bool is_user_function_defined (void) const
1054  {
1055  return rep->is_user_function_defined ();
1056  }
1057 
1059  = octave_value_list (),
1060  bool local_funcs = true)
1061  {
1062  return rep->find_function (args, local_funcs);
1063  }
1064 
1065  void lock_subfunction (scope_id scope)
1066  {
1067  rep->lock_subfunction (scope);
1068  }
1069 
1070  void unlock_subfunction (scope_id scope)
1071  {
1072  rep->unlock_subfunction (scope);
1073  }
1074 
1075  std::pair<std::string, octave_value>
1076  subfunction_defined_in_scope (scope_id scope = xcurrent_scope) const
1077  {
1078  return rep->subfunction_defined_in_scope (scope);
1079  }
1080 
1081  void erase_subfunction (scope_id scope)
1082  {
1083  rep->erase_subfunction (scope);
1084  }
1085 
1087  const std::string& class_name)
1088  {
1089  rep->mark_subfunction_in_scope_as_private (scope, class_name);
1090  }
1091 
1093  {
1094  rep->install_cmdline_function (f);
1095  }
1096 
1097  void install_subfunction (const octave_value& f, scope_id scope)
1098  {
1099  rep->install_subfunction (f, scope);
1100  }
1101 
1103  {
1104  rep->install_user_function (f);
1105  }
1106 
1108  {
1109  rep->install_built_in_function (f);
1110  }
1111 
1112  void clear (bool force = false) { rep->clear (force); }
1113 
1114  void clear_user_function (bool force = false)
1115  {
1116  rep->clear_user_function (force);
1117  }
1118 
1119  void clear_autoload_function (bool force = false)
1120  {
1121  rep->clear_autoload_function (force);
1122  }
1123 
1124  void clear_mex_function (void) { rep->clear_mex_function (); }
1125 
1127  {
1128  rep->add_dispatch (type, fname);
1129  }
1130 
1132  {
1133  rep->clear_dispatch (type);
1134  }
1135 
1136  void print_dispatch (std::ostream& os) const
1137  {
1138  rep->print_dispatch (os);
1139  }
1140 
1142  { return rep->help_for_dispatch (); }
1143 
1144  dispatch_map_type get_dispatch (void) const
1145  {
1146  return rep->get_dispatch ();
1147  }
1148 
1149  void
1150  dump (std::ostream& os, const std::string& prefix = "") const
1151  {
1152  rep->dump (os, prefix);
1153  }
1154 
1155  private:
1156 
1158  };
1159 
1160  static scope_id global_scope (void) { return xglobal_scope; }
1161  static scope_id top_scope (void) { return xtop_scope; }
1162 
1163  static scope_id current_scope (void) { return xcurrent_scope; }
1164 
1165  static context_id current_context (void) { return xcurrent_context; }
1166 
1167  static scope_id alloc_scope (void) { return scope_id_cache::alloc (); }
1168 
1169  static void set_scope (scope_id scope)
1170  {
1171  if (scope == xglobal_scope)
1172  error ("can't set scope to global");
1173 
1174  if (scope != xcurrent_scope)
1175  {
1176  all_instances_iterator p = all_instances.find (scope);
1177 
1178  if (p == all_instances.end ())
1179  {
1180  symbol_table *inst = new symbol_table (scope);
1181 
1182  if (inst)
1183  all_instances[scope] = instance = inst;
1184  }
1185  else
1186  instance = p->second;
1187 
1188  xcurrent_scope = scope;
1189  xcurrent_context = 0;
1190  }
1191  }
1192 
1193  static void set_scope_and_context (scope_id scope, context_id context)
1194  {
1195  if (scope == xglobal_scope)
1196  error ("can't set scope to global");
1197 
1198  if (scope != xcurrent_scope)
1199  {
1200  all_instances_iterator p = all_instances.find (scope);
1201 
1202  if (p == all_instances.end ())
1203  error ("scope not found!");
1204 
1205  instance = p->second;
1206 
1207  xcurrent_scope = scope;
1208 
1209  xcurrent_context = context;
1210  }
1211  else
1212  xcurrent_context = context;
1213  }
1214 
1215  static void erase_scope (scope_id scope)
1216  {
1217  assert (scope != xglobal_scope);
1218 
1219  erase_subfunctions_in_scope (scope);
1220 
1221  all_instances_iterator p = all_instances.find (scope);
1222 
1223  if (p != all_instances.end ())
1224  {
1225  delete p->second;
1226 
1227  all_instances.erase (p);
1228 
1229  free_scope (scope);
1230  }
1231  }
1232 
1233  static void erase_subfunctions_in_scope (scope_id scope)
1234  {
1235  for (fcn_table_iterator q = fcn_table.begin (); q != fcn_table.end (); q++)
1236  q->second.erase_subfunction (scope);
1237  }
1238 
1239  static void
1241  const std::string& class_name)
1242  {
1243  for (fcn_table_iterator q = fcn_table.begin (); q != fcn_table.end (); q++)
1244  q->second.mark_subfunction_in_scope_as_private (scope, class_name);
1245  }
1246 
1247  static scope_id dup_scope (scope_id scope)
1248  {
1249  scope_id retval = -1;
1250 
1251  symbol_table *inst = get_instance (scope);
1252 
1253  if (inst)
1254  {
1255  scope_id new_scope = alloc_scope ();
1256 
1257  symbol_table *new_symbol_table = new symbol_table (scope);
1258 
1259  if (new_symbol_table)
1260  {
1261  all_instances[new_scope] = new_symbol_table;
1262 
1263  inst->do_dup_scope (*new_symbol_table);
1264 
1265  retval = new_scope;
1266  }
1267  }
1268 
1269  return retval;
1270  }
1271 
1272  static std::list<scope_id> scopes (void)
1273  {
1274  return scope_id_cache::scopes ();
1275  }
1276 
1277  static symbol_record
1278  find_symbol (const std::string& name, scope_id scope = xcurrent_scope)
1279  {
1280  symbol_table *inst = get_instance (scope);
1281 
1282  return inst ? inst->do_find_symbol (name) :
1283  symbol_record (scope);
1284  }
1285 
1286  static void
1287  inherit (scope_id scope, scope_id donor_scope, context_id donor_context)
1288  {
1289  symbol_table *inst = get_instance (scope);
1290 
1291  if (inst)
1292  {
1293  symbol_table *donor_symbol_table = get_instance (donor_scope);
1294 
1295  if (donor_symbol_table)
1296  inst->do_inherit (*donor_symbol_table, donor_context);
1297  }
1298  }
1299 
1300  static bool at_top_level (void) { return xcurrent_scope == xtop_scope; }
1301 
1302  // Find a value corresponding to the given name in the table.
1303  static octave_value
1304  find (const std::string& name,
1306  bool skip_variables = false,
1307  bool local_funcs = true);
1308 
1309  static octave_value builtin_find (const std::string& name);
1310 
1311  // Insert a new name in the table.
1312  static symbol_record& insert (const std::string& name,
1313  scope_id scope = xcurrent_scope)
1314  {
1315  symbol_table *inst = get_instance (scope);
1316 
1317  return inst ? inst->do_insert (name) : symbol_table::dummy_symbol_record;
1318  }
1319 
1320  static void rename (const std::string& old_name,
1321  const std::string& new_name,
1322  scope_id scope = xcurrent_scope)
1323  {
1324  symbol_table *inst = get_instance (scope);
1325 
1326  if (inst)
1327  inst->do_rename (old_name, new_name);
1328  }
1329 
1330  static void assign (const std::string& name,
1331  const octave_value& value = octave_value (),
1332  scope_id scope = xcurrent_scope,
1333  context_id context = xdefault_context,
1334  bool force_add = false)
1335  {
1336  symbol_table *inst = get_instance (scope);
1337 
1338  if (inst)
1339  inst->do_assign (name, value, context, force_add);
1340  }
1341 
1342  OCTAVE_DEPRECATED ("use 'assign' instead")
1343  static octave_value&
1344  varref (const std::string& name, scope_id scope = xcurrent_scope,
1345  context_id context = xdefault_context, bool force_add = false)
1346  {
1347  symbol_table *inst = get_instance (scope);
1348 
1349  return inst ? inst->do_varref (name, context, force_add) : dummy_octave_value;
1350  }
1351 
1352  // Convenience function to simplify
1353  // octave_user_function::bind_automatic_vars
1354 
1355  static void force_assign (const std::string& name,
1356  const octave_value& value = octave_value (),
1357  scope_id scope = xcurrent_scope,
1358  context_id context = xdefault_context)
1359  {
1360  assign (name, value, scope, context, true);
1361  }
1362 
1363  OCTAVE_DEPRECATED ("use 'force_assign' instead")
1364  static octave_value&
1365  force_varref (const std::string& name, scope_id scope = xcurrent_scope,
1366  context_id context = xdefault_context)
1367  {
1368  symbol_table *inst = get_instance (scope);
1369 
1370  return inst ? inst->do_varref (name, context, true) : dummy_octave_value;
1371  }
1372 
1373  static octave_value varval (const std::string& name,
1374  scope_id scope = xcurrent_scope,
1375  context_id context = xdefault_context)
1376  {
1377  symbol_table *inst = get_instance (scope);
1378 
1379  return inst ? inst->do_varval (name, context) : octave_value ();
1380  }
1381 
1382  static void
1384  const octave_value& value = octave_value ())
1385 
1386  {
1387  global_table_iterator p = global_table.find (name);
1388 
1389  if (p == global_table.end ())
1390  global_table[name] = value;
1391  else
1392  p->second = value;
1393  }
1394 
1395  OCTAVE_DEPRECATED ("use 'global_assign' instead")
1396  static octave_value&
1397  global_varref (const std::string& name)
1398 
1399  {
1400  global_table_iterator p = global_table.find (name);
1401 
1402  return (p == global_table.end ()) ? global_table[name] : p->second;
1403  }
1404 
1405  static octave_value
1407  {
1408  global_table_const_iterator p = global_table.find (name);
1409 
1410  return (p != global_table.end ()) ? p->second : octave_value ();
1411  }
1412 
1413  static void
1415  const octave_value& value = octave_value ())
1416  {
1417  assign (name, value, top_scope (), 0);
1418  }
1419 
1420  OCTAVE_DEPRECATED ("use 'top_level_assign' instead")
1421  static octave_value&
1422  top_level_varref (const std::string& name)
1423  {
1424  symbol_table *inst = get_instance (top_scope ());
1425 
1426  return inst ? inst->do_varref (name, 0, true) : dummy_octave_value;
1427  }
1428 
1429  static octave_value
1431  {
1432  return varval (name, top_scope (), 0);
1433  }
1434 
1435  static void
1436  persistent_assign (const std::string& name, scope_id scope,
1437  const octave_value& value = octave_value ())
1438  {
1439  symbol_table *inst = get_instance (scope);
1440 
1441  if (inst)
1442  inst->do_persistent_assign (name, value);
1443  }
1444 
1445  static void
1447  const octave_value& value = octave_value ())
1448  {
1449  persistent_assign (name, xcurrent_scope, value);
1450  }
1451 
1452  OCTAVE_DEPRECATED ("use 'persistent_assign' instead")
1453  static octave_value&
1454  persistent_varref (const std::string& name)
1455  {
1456  symbol_table *inst = get_instance (xcurrent_scope);
1457 
1458  return inst ? inst->do_persistent_varref (name) : dummy_octave_value;
1459  }
1460 
1462  scope_id scope = xcurrent_scope)
1463  {
1464  symbol_table *inst = get_instance (scope);
1465 
1466  return inst ? inst->do_persistent_varval (name) : octave_value ();
1467  }
1468 
1469  static void erase_persistent (const std::string& name,
1470  scope_id scope = xcurrent_scope)
1471  {
1472  symbol_table *inst = get_instance (scope);
1473 
1474  if (inst)
1475  inst->do_erase_persistent (name);
1476  }
1477 
1478  static bool is_variable (const std::string& name,
1479  scope_id scope = xcurrent_scope)
1480  {
1481  symbol_table *inst = get_instance (scope);
1482 
1483  return inst ? inst->do_is_variable (name) : false;
1484  }
1485 
1486  static bool
1488  {
1489  octave_value val = find_built_in_function (name);
1490 
1491  return val.is_defined ();
1492  }
1493 
1494  static octave_value
1495  find_method (const std::string& name, const std::string& dispatch_type)
1496  {
1497  fcn_table_const_iterator p = fcn_table.find (name);
1498 
1499  if (p != fcn_table.end ())
1500  {
1501  octave_value fcn = p->second.find_method (dispatch_type);
1502 
1503  if (! fcn.is_defined ())
1504  fcn = find_submethod (name, dispatch_type);
1505 
1506  return fcn;
1507  }
1508  else
1509  {
1510  fcn_info finfo (name);
1511 
1512  octave_value fcn = finfo.find_method (dispatch_type);
1513 
1514  if (! fcn.is_defined ())
1515  fcn = find_submethod (name, dispatch_type);
1516 
1517  if (fcn.is_defined ())
1518  fcn_table[name] = finfo;
1519 
1520  return fcn;
1521  }
1522  }
1523 
1524  static octave_value
1525  find_submethod (const std::string& name, const std::string& dispatch_type);
1526 
1527  static octave_value
1529  {
1530  fcn_table_const_iterator p = fcn_table.find (name);
1531 
1532  return (p != fcn_table.end ())
1533  ? p->second.find_built_in_function () : octave_value ();
1534  }
1535 
1536  static octave_value
1538  {
1539  fcn_table_iterator p = fcn_table.find (name);
1540 
1541  return (p != fcn_table.end ())
1542  ? p->second.find_autoload () : octave_value ();
1543  }
1544 
1545  static octave_value
1546  find_function (const std::string& name,
1548  bool local_funcs = true);
1549 
1551  {
1552  fcn_table_iterator p = fcn_table.find (name);
1553 
1554  return (p != fcn_table.end ())
1555  ? p->second.find_user_function () : octave_value ();
1556  }
1557 
1559  {
1560  fcn_table_iterator p = fcn_table.find (name);
1561 
1562  return (p != fcn_table.end ())
1563  ? p->second.find_cmdline_function () : octave_value ();
1564  }
1565 
1566  static void install_cmdline_function (const std::string& name,
1567  const octave_value& fcn)
1568  {
1569  fcn_table_iterator p = fcn_table.find (name);
1570 
1571  if (p != fcn_table.end ())
1572  {
1573  fcn_info& finfo = p->second;
1574 
1575  finfo.install_cmdline_function (fcn);
1576  }
1577  else
1578  {
1579  fcn_info finfo (name);
1580 
1581  finfo.install_cmdline_function (fcn);
1582 
1583  fcn_table[name] = finfo;
1584  }
1585  }
1586 
1587  // Install subfunction FCN named NAME. SCOPE is the scope of the
1588  // primary function corresponding to this subfunction.
1589 
1590  static void install_subfunction (const std::string& name,
1591  const octave_value& fcn,
1592  scope_id scope)
1593  {
1594  fcn_table_iterator p = fcn_table.find (name);
1595 
1596  if (p != fcn_table.end ())
1597  {
1598  fcn_info& finfo = p->second;
1599 
1600  finfo.install_subfunction (fcn, scope);
1601  }
1602  else
1603  {
1604  fcn_info finfo (name);
1605 
1606  finfo.install_subfunction (fcn, scope);
1607 
1608  fcn_table[name] = finfo;
1609  }
1610  }
1611 
1612  static void install_nestfunction (const std::string& name,
1613  const octave_value& fcn,
1614  scope_id parent_scope);
1615 
1616  static void update_nest (scope_id scope)
1617  {
1618  symbol_table *inst = get_instance (scope);
1619  if (inst)
1620  inst->do_update_nest ();
1621  }
1622 
1623  static void install_user_function (const std::string& name,
1624  const octave_value& fcn)
1625  {
1626  fcn_table_iterator p = fcn_table.find (name);
1627 
1628  if (p != fcn_table.end ())
1629  {
1630  fcn_info& finfo = p->second;
1631 
1632  finfo.install_user_function (fcn);
1633  }
1634  else
1635  {
1636  fcn_info finfo (name);
1637 
1638  finfo.install_user_function (fcn);
1639 
1640  fcn_table[name] = finfo;
1641  }
1642  }
1643 
1644  static void install_built_in_function (const std::string& name,
1645  const octave_value& fcn)
1646  {
1647  fcn_table_iterator p = fcn_table.find (name);
1648 
1649  if (p != fcn_table.end ())
1650  {
1651  fcn_info& finfo = p->second;
1652 
1653  finfo.install_built_in_function (fcn);
1654  }
1655  else
1656  {
1657  fcn_info finfo (name);
1658 
1659  finfo.install_built_in_function (fcn);
1660 
1661  fcn_table[name] = finfo;
1662  }
1663  }
1664 
1665  static void clear (const std::string& name)
1666  {
1667  clear_variable (name);
1668  }
1669 
1670  static void clear_all (bool force = false)
1671  {
1672  clear_variables ();
1673 
1674  clear_global_pattern ("*");
1675 
1676  clear_functions (force);
1677  }
1678 
1679  // This is written as two separate functions instead of a single
1680  // function with default values so that it will work properly with
1681  // unwind_protect.
1682 
1683  static void clear_variables (scope_id scope)
1684  {
1685  symbol_table *inst = get_instance (scope);
1686 
1687  if (inst)
1688  inst->do_clear_variables ();
1689  }
1690 
1691  static void clear_variables (void)
1692  {
1693  clear_variables (xcurrent_scope);
1694  }
1695 
1696  static void clear_objects (scope_id scope = xcurrent_scope)
1697  {
1698  symbol_table *inst = get_instance (scope);
1699 
1700  if (inst)
1701  inst->do_clear_objects ();
1702  }
1703 
1704  static void clear_functions (bool force = false)
1705  {
1706  for (fcn_table_iterator p = fcn_table.begin (); p != fcn_table.end (); p++)
1707  p->second.clear (force);
1708  }
1709 
1710  static void clear_function (const std::string& name)
1711  {
1712  clear_user_function (name);
1713  }
1714 
1715  static void clear_global (const std::string& name,
1716  scope_id scope = xcurrent_scope)
1717  {
1718  symbol_table *inst = get_instance (scope);
1719 
1720  if (inst)
1721  inst->do_clear_global (name);
1722  }
1723 
1724  static void clear_variable (const std::string& name,
1725  scope_id scope = xcurrent_scope)
1726  {
1727  symbol_table *inst = get_instance (scope);
1728 
1729  if (inst)
1730  inst->do_clear_variable (name);
1731  }
1732 
1733  static void clear_symbol (const std::string& name)
1734  {
1735  // FIXME: are we supposed to do both here?
1736 
1737  clear_variable (name);
1738  clear_function (name);
1739  }
1740 
1741  static void clear_function_pattern (const std::string& pat)
1742  {
1743  glob_match pattern (pat);
1744 
1745  for (fcn_table_iterator p = fcn_table.begin (); p != fcn_table.end (); p++)
1746  {
1747  if (pattern.match (p->first))
1748  p->second.clear_user_function ();
1749  }
1750  }
1751 
1752  static void clear_global_pattern (const std::string& pat,
1753  scope_id scope = xcurrent_scope)
1754  {
1755  symbol_table *inst = get_instance (scope);
1756 
1757  if (inst)
1758  inst->do_clear_global_pattern (pat);
1759  }
1760 
1761  static void clear_variable_pattern (const std::string& pat,
1762  scope_id scope = xcurrent_scope)
1763  {
1764  symbol_table *inst = get_instance (scope);
1765 
1766  if (inst)
1767  inst->do_clear_variable_pattern (pat);
1768  }
1769 
1770  static void clear_variable_regexp (const std::string& pat,
1771  scope_id scope = xcurrent_scope)
1772  {
1773  symbol_table *inst = get_instance (scope);
1774 
1775  if (inst)
1776  inst->do_clear_variable_regexp (pat);
1777  }
1778 
1779  static void clear_symbol_pattern (const std::string& pat)
1780  {
1781  // FIXME: are we supposed to do both here?
1782 
1783  clear_variable_pattern (pat);
1784  clear_function_pattern (pat);
1785  }
1786 
1787  static void clear_user_function (const std::string& name)
1788  {
1789  fcn_table_iterator p = fcn_table.find (name);
1790 
1791  if (p != fcn_table.end ())
1792  {
1793  fcn_info& finfo = p->second;
1794 
1795  finfo.clear_user_function ();
1796  }
1797  // FIXME: is this necessary, or even useful?
1798  // else
1799  // error ("clear: no such function '%s'", name.c_str ());
1800  }
1801 
1802  // This clears oct and mex files, including autoloads.
1803  static void clear_dld_function (const std::string& name)
1804  {
1805  fcn_table_iterator p = fcn_table.find (name);
1806 
1807  if (p != fcn_table.end ())
1808  {
1809  fcn_info& finfo = p->second;
1810 
1811  finfo.clear_autoload_function ();
1812  finfo.clear_user_function ();
1813  }
1814  }
1815 
1816  static void clear_mex_functions (void)
1817  {
1818  for (fcn_table_iterator p = fcn_table.begin (); p != fcn_table.end (); p++)
1819  {
1820  fcn_info& finfo = p->second;
1821 
1822  finfo.clear_mex_function ();
1823  }
1824  }
1825 
1826  static bool set_class_relationship (const std::string& sup_class,
1827  const std::string& inf_class);
1828 
1829  static bool is_superiorto (const std::string& a, const std::string& b);
1830 
1831  static void alias_built_in_function (const std::string& alias,
1832  const std::string& name)
1833  {
1834  octave_value fcn = find_built_in_function (name);
1835 
1836  if (fcn.is_defined ())
1837  {
1838  fcn_info finfo (alias);
1839 
1840  finfo.install_built_in_function (fcn);
1841 
1842  fcn_table[alias] = finfo;
1843  }
1844  else
1845  panic ("alias: '%s' is undefined", name.c_str ());
1846  }
1847 
1848  static void add_dispatch (const std::string& name, const std::string& type,
1849  const std::string& fname)
1850  {
1851  fcn_table_iterator p = fcn_table.find (name);
1852 
1853  if (p != fcn_table.end ())
1854  {
1855  fcn_info& finfo = p->second;
1856 
1857  finfo.add_dispatch (type, fname);
1858  }
1859  else
1860  {
1861  fcn_info finfo (name);
1862 
1863  finfo.add_dispatch (type, fname);
1864 
1865  fcn_table[name] = finfo;
1866  }
1867  }
1868 
1869  static void clear_dispatch (const std::string& name, const std::string& type)
1870  {
1871  fcn_table_iterator p = fcn_table.find (name);
1872 
1873  if (p != fcn_table.end ())
1874  {
1875  fcn_info& finfo = p->second;
1876 
1877  finfo.clear_dispatch (type);
1878  }
1879  }
1880 
1881  static void print_dispatch (std::ostream& os, const std::string& name)
1882  {
1883  fcn_table_iterator p = fcn_table.find (name);
1884 
1885  if (p != fcn_table.end ())
1886  {
1887  fcn_info& finfo = p->second;
1888 
1889  finfo.print_dispatch (os);
1890  }
1891  }
1892 
1894  {
1896 
1897  fcn_table_iterator p = fcn_table.find (name);
1898 
1899  if (p != fcn_table.end ())
1900  {
1901  fcn_info& finfo = p->second;
1902 
1903  retval = finfo.get_dispatch ();
1904  }
1905 
1906  return retval;
1907  }
1908 
1910  {
1912 
1913  fcn_table_iterator p = fcn_table.find (name);
1914 
1915  if (p != fcn_table.end ())
1916  {
1917  fcn_info& finfo = p->second;
1918 
1919  retval = finfo.help_for_dispatch ();
1920  }
1921 
1922  return retval;
1923  }
1924 
1925  static void push_context (scope_id scope = xcurrent_scope)
1926  {
1927  if (scope == xglobal_scope || scope == xtop_scope)
1928  error ("invalid call to symtab::push_context");
1929 
1930  symbol_table *inst = get_instance (scope);
1931 
1932  if (inst)
1933  inst->do_push_context ();
1934  }
1935 
1936  // This is written as two separate functions instead of a single
1937  // function with default values so that it will work properly with
1938  // unwind_protect.
1939 
1940  static void pop_context (scope_id scope)
1941  {
1942  if (scope == xglobal_scope || scope == xtop_scope)
1943  error ("invalid call to symtab::pop_context");
1944 
1945  symbol_table *inst = get_instance (scope);
1946 
1947  if (inst)
1948  inst->do_pop_context ();
1949  }
1950 
1951  static void pop_context (void) { pop_context (xcurrent_scope); }
1952 
1953  // For unwind_protect where a pointer argument is needed.
1954 
1955  static void pop_context (void *) { pop_context (); }
1956 
1957  static void mark_automatic (const std::string& name,
1958  scope_id scope = xcurrent_scope)
1959  {
1960  symbol_table *inst = get_instance (scope);
1961 
1962  if (inst)
1963  inst->do_mark_automatic (name);
1964  }
1965 
1966  static void mark_hidden (const std::string& name,
1967  scope_id scope = xcurrent_scope)
1968  {
1969  symbol_table *inst = get_instance (scope);
1970 
1971  if (inst)
1972  inst->do_mark_hidden (name);
1973  }
1974 
1975  static void mark_global (const std::string& name,
1976  scope_id scope = xcurrent_scope)
1977  {
1978  symbol_table *inst = get_instance (scope);
1979 
1980  if (inst)
1981  inst->do_mark_global (name);
1982  }
1983 
1984  // exclude: Storage classes to exclude, you can OR them together
1985  static std::list<symbol_record>
1986  all_variables (scope_id scope = xcurrent_scope,
1987  context_id context = xdefault_context,
1988  bool defined_only = true,
1989  unsigned int exclude = symbol_record::hidden)
1990  {
1991  symbol_table *inst = get_instance (scope);
1992 
1993  return inst
1994  ? inst->do_all_variables (context, defined_only, exclude)
1995  : std::list<symbol_record> ();
1996  }
1997 
1998  static std::list<symbol_record> glob (const std::string& pattern,
1999  scope_id scope = xcurrent_scope)
2000  {
2001  symbol_table *inst = get_instance (scope);
2002 
2003  return inst ? inst->do_glob (pattern) : std::list<symbol_record> ();
2004  }
2005 
2006  static std::list<symbol_record> regexp (const std::string& pattern,
2007  scope_id scope = xcurrent_scope)
2008  {
2009  symbol_table *inst = get_instance (scope);
2010 
2011  return inst ? inst->do_regexp (pattern) : std::list<symbol_record> ();
2012  }
2013 
2014  static std::list<symbol_record> glob_variables (const std::string& pattern,
2015  scope_id scope = xcurrent_scope)
2016  {
2017  symbol_table *inst = get_instance (scope);
2018 
2019  return inst ? inst->do_glob (pattern, true) : std::list<symbol_record> ();
2020  }
2021 
2022  static std::list<symbol_record> regexp_variables (const std::string& pattern,
2023  scope_id scope = xcurrent_scope)
2024  {
2025  symbol_table *inst = get_instance (scope);
2026 
2027  return inst ? inst->do_regexp (pattern, true) : std::list<symbol_record> ();
2028  }
2029 
2030  static std::list<symbol_record>
2032  {
2033  std::list<symbol_record> retval;
2034 
2035  glob_match pat (pattern);
2036 
2037  for (global_table_const_iterator p = global_table.begin ();
2038  p != global_table.end (); p++)
2039  {
2040  // We generate a list of symbol_record objects so that
2041  // the results from glob_variables and glob_global_variables
2042  // may be handled the same way.
2043 
2044  if (pat.match (p->first))
2045  retval.push_back (symbol_record (xglobal_scope,
2046  p->first, p->second,
2047  symbol_record::global));
2048  }
2049 
2050  return retval;
2051  }
2052 
2053  static std::list<symbol_record>
2055  {
2056  std::list<symbol_record> retval;
2057 
2058  octave::regexp pat (pattern);
2059 
2060  for (global_table_const_iterator p = global_table.begin ();
2061  p != global_table.end (); p++)
2062  {
2063  // We generate a list of symbol_record objects so that
2064  // the results from regexp_variables and regexp_global_variables
2065  // may be handled the same way.
2066 
2067  if (pat.is_match (p->first))
2068  retval.push_back (symbol_record (xglobal_scope,
2069  p->first, p->second,
2070  symbol_record::global));
2071  }
2072 
2073  return retval;
2074  }
2075 
2076  static std::list<symbol_record> glob_variables (const string_vector& patterns)
2077  {
2078  std::list<symbol_record> retval;
2079 
2080  size_t len = patterns.numel ();
2081 
2082  for (size_t i = 0; i < len; i++)
2083  {
2084  std::list<symbol_record> tmp = glob_variables (patterns[i]);
2085 
2086  retval.insert (retval.begin (), tmp.begin (), tmp.end ());
2087  }
2088 
2089  return retval;
2090  }
2091 
2092  static std::list<symbol_record> regexp_variables
2093  (const string_vector& patterns)
2094  {
2095  std::list<symbol_record> retval;
2096 
2097  size_t len = patterns.numel ();
2098 
2099  for (size_t i = 0; i < len; i++)
2100  {
2101  std::list<symbol_record> tmp = regexp_variables (patterns[i]);
2102 
2103  retval.insert (retval.begin (), tmp.begin (), tmp.end ());
2104  }
2105 
2106  return retval;
2107  }
2108 
2109  static std::list<std::string> user_function_names (void)
2110  {
2111  std::list<std::string> retval;
2112 
2113  for (fcn_table_iterator p = fcn_table.begin ();
2114  p != fcn_table.end (); p++)
2115  {
2116  if (p->second.is_user_function_defined ())
2117  retval.push_back (p->first);
2118  }
2119 
2120  if (! retval.empty ())
2121  retval.sort ();
2122 
2123  return retval;
2124  }
2125 
2126  static std::list<std::string> global_variable_names (void)
2127  {
2128  std::list<std::string> retval;
2129 
2130  for (global_table_const_iterator p = global_table.begin ();
2131  p != global_table.end (); p++)
2132  retval.push_back (p->first);
2133 
2134  retval.sort ();
2135 
2136  return retval;
2137  }
2138 
2139  static std::list<std::string> top_level_variable_names (void)
2140  {
2141  symbol_table *inst = get_instance (xtop_scope);
2142 
2143  return inst ? inst->do_variable_names () : std::list<std::string> ();
2144  }
2145 
2146  static std::list<std::string> variable_names (scope_id scope = xcurrent_scope)
2147  {
2148  symbol_table *inst = get_instance (scope);
2149 
2150  return inst ? inst->do_variable_names () : std::list<std::string> ();
2151  }
2152 
2153  static std::list<std::string> built_in_function_names (void)
2154  {
2155  std::list<std::string> retval;
2156 
2157  for (fcn_table_const_iterator p = fcn_table.begin ();
2158  p != fcn_table.end (); p++)
2159  {
2160  octave_value fcn = p->second.find_built_in_function ();
2161 
2162  if (fcn.is_defined ())
2163  retval.push_back (p->first);
2164  }
2165 
2166  if (! retval.empty ())
2167  retval.sort ();
2168 
2169  return retval;
2170  }
2171 
2172  static std::list<std::string> cmdline_function_names (void)
2173  {
2174  std::list<std::string> retval;
2175 
2176  for (fcn_table_const_iterator p = fcn_table.begin ();
2177  p != fcn_table.end (); p++)
2178  {
2179  octave_value fcn = p->second.find_cmdline_function ();
2180 
2181  if (fcn.is_defined ())
2182  retval.push_back (p->first);
2183  }
2184 
2185  if (! retval.empty ())
2186  retval.sort ();
2187 
2188  return retval;
2189  }
2190 
2191  static bool is_local_variable (const std::string& name,
2192  scope_id scope = xcurrent_scope)
2193  {
2194  if (scope == xglobal_scope)
2195  return false;
2196  else
2197  {
2198  symbol_table *inst = get_instance (scope);
2199 
2200  return inst ? inst->do_is_local_variable (name) : false;
2201  }
2202  }
2203 
2204  static bool is_global (const std::string& name,
2205  scope_id scope = xcurrent_scope)
2206  {
2207  if (scope == xglobal_scope)
2208  return true;
2209  else
2210  {
2211  symbol_table *inst = get_instance (scope);
2212 
2213  return inst ? inst->do_is_global (name) : false;
2214  }
2215  }
2216 
2217  static std::list<workspace_element> workspace_info (scope_id scope = xcurrent_scope)
2218  {
2219  symbol_table *inst = get_instance (scope);
2220 
2221  return inst
2222  ? inst->do_workspace_info () : std::list<workspace_element> ();
2223  }
2224 
2225  static void dump (std::ostream& os, scope_id scope = xcurrent_scope);
2226 
2227  static void dump_global (std::ostream& os);
2228 
2229  static void dump_functions (std::ostream& os);
2230 
2231  static void cache_name (scope_id scope, const std::string& name)
2232  {
2233  symbol_table *inst = get_instance (scope, false);
2234 
2235  if (inst)
2236  inst->do_cache_name (name);
2237  }
2238 
2239  static void lock_subfunctions (scope_id scope = xcurrent_scope)
2240  {
2241  for (fcn_table_iterator p = fcn_table.begin ();
2242  p != fcn_table.end (); p++)
2243  p->second.lock_subfunction (scope);
2244  }
2245 
2246  static void unlock_subfunctions (scope_id scope = xcurrent_scope)
2247  {
2248  for (fcn_table_iterator p = fcn_table.begin ();
2249  p != fcn_table.end (); p++)
2250  p->second.unlock_subfunction (scope);
2251  }
2252 
2253  static std::map<std::string, octave_value>
2254  subfunctions_defined_in_scope (scope_id scope = xcurrent_scope)
2255  {
2256  std::map<std::string, octave_value> retval;
2257 
2258  for (fcn_table_const_iterator p = fcn_table.begin ();
2259  p != fcn_table.end (); p++)
2260  {
2261  std::pair<std::string, octave_value> tmp
2262  = p->second.subfunction_defined_in_scope (scope);
2263 
2264  std::string nm = tmp.first;
2265 
2266  if (! nm.empty ())
2267  retval[nm] = tmp.second;
2268  }
2269 
2270  return retval;
2271  }
2272 
2273  static void free_scope (scope_id scope)
2274  {
2275  if (scope == xglobal_scope || scope == xtop_scope)
2276  error ("can't free global or top-level scopes!");
2277 
2279  }
2280 
2281  static void stash_dir_name_for_subfunctions (scope_id scope,
2282  const std::string& dir_name);
2283 
2284  static void add_to_parent_map (const std::string& classname,
2285  const std::list<std::string>& parent_list)
2286  {
2287  parent_map[classname] = parent_list;
2288  }
2289 
2290  static std::list<std::string>
2291  parent_classes (const std::string& dispatch_type)
2292  {
2293  std::list<std::string> retval;
2294 
2295  const_parent_map_iterator it = parent_map.find (dispatch_type);
2296 
2297  if (it != parent_map.end ())
2298  retval = it->second;
2299 
2300  for (std::list<std::string>::const_iterator lit = retval.begin ();
2301  lit != retval.end (); lit++)
2302  {
2303  // Search for parents of parents and append them to the list.
2304 
2305  // FIXME: should we worry about a circular inheritance graph?
2306 
2307  std::list<std::string> parents = parent_classes (*lit);
2308 
2309  if (! parents.empty ())
2310  retval.insert (retval.end (), parents.begin (), parents.end ());
2311  }
2312 
2313  return retval;
2314  }
2315 
2316  static octave_user_function *get_curr_fcn (scope_id scope = xcurrent_scope)
2317  {
2318  symbol_table *inst = get_instance (scope);
2319  return inst->curr_fcn;
2320  }
2321 
2322  static void set_curr_fcn (octave_user_function *curr_fcn,
2323  scope_id scope = xcurrent_scope)
2324  {
2325  assert (scope != xtop_scope && scope != xglobal_scope);
2326  symbol_table *inst = get_instance (scope);
2327  // FIXME: normally, functions should not usurp each other's scope.
2328  // If for any incredible reason this is needed, call
2329  // set_user_function (0, scope) first. This may cause problems with
2330  // nested functions, as the curr_fcn of symbol_records must be updated.
2331  assert (inst->curr_fcn == 0 || curr_fcn == 0);
2332  inst->curr_fcn = curr_fcn;
2333  }
2334 
2335  static void cleanup (void);
2336 
2337 private:
2338 
2339  // No copying!
2340 
2341  symbol_table (const symbol_table&);
2342 
2343  symbol_table& operator = (const symbol_table&);
2344 
2345  typedef std::map<std::string, symbol_record>::const_iterator
2347  typedef std::map<std::string, symbol_record>::iterator
2349 
2350  typedef std::map<std::string, octave_value>::const_iterator
2352  typedef std::map<std::string, octave_value>::iterator
2354 
2355  typedef std::map<std::string, octave_value>::const_iterator
2357  typedef std::map<std::string, octave_value>::iterator
2359 
2360  typedef std::map<scope_id, symbol_table*>::const_iterator
2362  typedef std::map<scope_id, symbol_table*>::iterator
2364 
2365  typedef std::map<std::string, fcn_info>::const_iterator
2367  typedef std::map<std::string, fcn_info>::iterator
2369 
2370  // The scope of this symbol table.
2371  scope_id my_scope;
2372 
2373  // Name for this table
2374  // (usually the filename of the function corresponding to the scope);
2376 
2377  // Map from symbol names to symbol info.
2378  std::map<std::string, symbol_record> table;
2379 
2380  // Child nested functions.
2381  std::vector<symbol_table*> nest_children;
2382 
2383  // Parent nested function (may be null).
2385 
2386  // The associated user code (may be null).
2388 
2389  // If true then no variables can be added.
2391 
2392  // Map from names of global variables to values.
2393  static std::map<std::string, octave_value> global_table;
2394 
2395  // Map from names of persistent variables to values.
2396  std::map<std::string, octave_value> persistent_table;
2397 
2398  // Pointer to symbol table for current scope (variables only).
2400 
2401  // Map from scope id to symbol table instances.
2402  static std::map<scope_id, symbol_table*> all_instances;
2403 
2404  // Map from function names to function info (subfunctions, private
2405  // functions, class constructors, class methods, etc.)
2406  static std::map<std::string, fcn_info> fcn_table;
2407 
2408  // Mape from class names to set of classes that have lower
2409  // precedence.
2410  static std::map<std::string, std::set<std::string> > class_precedence_table;
2411 
2412  typedef std::map<std::string, std::set<std::string> >::const_iterator
2414  typedef std::map<std::string, std::set<std::string> >::iterator
2416 
2417  // Map from class names to parent class names.
2418  static std::map<std::string, std::list<std::string> > parent_map;
2419 
2420  typedef std::map<std::string, std::list<std::string> >::const_iterator
2422  typedef std::map<std::string, std::list<std::string> >::iterator
2424 
2425  static const scope_id xglobal_scope;
2426  static const scope_id xtop_scope;
2427 
2428  static scope_id xcurrent_scope;
2429 
2430  static context_id xcurrent_context;
2431 
2432  static const context_id xdefault_context = static_cast<context_id> (-1);
2433 
2434  symbol_table (scope_id scope)
2435  : my_scope (scope), table_name (), table (), nest_children (),
2436  nest_parent (0), curr_fcn (0), static_workspace (false),
2437  persistent_table () { }
2438 
2439  ~symbol_table (void) { }
2440 
2441  static symbol_table *get_instance (scope_id scope, bool create = true)
2442  {
2443  symbol_table *retval = 0;
2444 
2445  bool ok = true;
2446 
2447  if (scope != xglobal_scope)
2448  {
2449  if (scope == xcurrent_scope)
2450  {
2451  if (! instance && create)
2452  {
2453  symbol_table *inst = new symbol_table (scope);
2454 
2455  if (inst)
2456  {
2457  all_instances[scope] = instance = inst;
2458 
2459  if (scope == xtop_scope)
2460  instance->do_cache_name ("top-level");
2461  }
2462  }
2463 
2464  if (! instance)
2465  ok = false;
2466 
2467  retval = instance;
2468  }
2469  else
2470  {
2471  all_instances_iterator p = all_instances.find (scope);
2472 
2473  if (p == all_instances.end ())
2474  {
2475  if (create)
2476  {
2477  retval = new symbol_table (scope);
2478 
2479  if (retval)
2480  all_instances[scope] = retval;
2481  else
2482  ok = false;
2483  }
2484  else
2485  ok = false;
2486  }
2487  else
2488  retval = p->second;
2489  }
2490  }
2491 
2492  if (! ok)
2493  error ("unable to %s symbol_table object for scope %d!",
2494  create ? "create" : "find", scope);
2495 
2496  return retval;
2497  }
2498 
2500  {
2501  assert (! st.nest_parent);
2502  nest_children.push_back (&st);
2503  st.nest_parent = this;
2504  }
2505 
2507  {
2508  table[sr.name ()] = sr;
2509  }
2510 
2511  void
2512  do_dup_scope (symbol_table& new_symbol_table) const
2513  {
2514  for (table_const_iterator p = table.begin (); p != table.end (); p++)
2515  new_symbol_table.insert_symbol_record (p->second.dup (new_symbol_table
2516  .my_scope));
2517  }
2518 
2520  {
2521  table_iterator p = table.find (name);
2522 
2523  if (p == table.end ())
2524  return do_insert (name);
2525  else
2526  return p->second;
2527  }
2528 
2529  void do_inherit (symbol_table& donor_table, context_id donor_context)
2530  {
2531  for (table_iterator p = table.begin (); p != table.end (); p++)
2532  {
2533  symbol_record& sr = p->second;
2534 
2535  if (! (sr.is_automatic () || sr.is_formal ()))
2536  {
2537  std::string nm = sr.name ();
2538 
2539  if (nm != "__retval__")
2540  {
2541  octave_value val = donor_table.do_varval (nm, donor_context);
2542 
2543  if (val.is_defined ())
2544  {
2545  sr.assign (val, 0);
2546 
2547  sr.mark_inherited ();
2548  }
2549  }
2550  }
2551  }
2552  }
2553 
2554  static fcn_info *get_fcn_info (const std::string& name)
2555  {
2556  fcn_table_iterator p = fcn_table.find (name);
2557  return p != fcn_table.end () ? &p->second : 0;
2558  }
2559 
2560  octave_value
2561  do_find (const std::string& name, const octave_value_list& args,
2562  bool skip_variables, bool local_funcs);
2563 
2564  octave_value do_builtin_find (const std::string& name);
2565 
2566  symbol_record& do_insert (const std::string& name, bool force_add = false)
2567  {
2568  table_iterator p = table.find (name);
2569 
2570  if (p == table.end ())
2571  {
2572  symbol_record ret (my_scope, name);
2573 
2574  if (nest_parent && nest_parent->look_nonlocal (name, ret))
2575  return table[name] = ret;
2576  else
2577  {
2578  if (static_workspace && ! force_add)
2579  ret.mark_added_static ();
2580 
2581  return table[name] = ret;
2582  }
2583  }
2584  else
2585  return p->second;
2586  }
2587 
2588  void do_rename (const std::string& old_name, const std::string& new_name)
2589  {
2590  table_iterator p = table.find (old_name);
2591 
2592  if (p != table.end ())
2593  {
2594  symbol_record sr = p->second;
2595 
2596  sr.rename (new_name);
2597 
2598  table.erase (p);
2599 
2600  table[new_name] = sr;
2601  }
2602  }
2603 
2604  void do_assign (const std::string& name, const octave_value& value,
2605  context_id context, bool force_add)
2606  {
2607  table_iterator p = table.find (name);
2608 
2609  if (p == table.end ())
2610  {
2611  symbol_record& sr = do_insert (name, force_add);
2612 
2613  sr.assign (value, context);
2614  }
2615  else
2616  p->second.assign (value, context);
2617  }
2618 
2619  // Use do_assign (name, value, context, force_add) instead.
2620  // Delete when deprecated varref functions are removed.
2621  octave_value& do_varref (const std::string& name, context_id context,
2622  bool force_add)
2623  {
2624  table_iterator p = table.find (name);
2625 
2626  if (p == table.end ())
2627  {
2628  symbol_record& sr = do_insert (name, force_add);
2629 
2630  return sr.varref (context);
2631  }
2632  else
2633  return p->second.varref (context);
2634  }
2635 
2636  octave_value do_varval (const std::string& name, context_id context) const
2637  {
2638  table_const_iterator p = table.find (name);
2639 
2640  return (p != table.end ()) ? p->second.varval (context) : octave_value ();
2641  }
2642 
2644  {
2645  persistent_table_iterator p = persistent_table.find (name);
2646 
2647  if (p == persistent_table.end ())
2648  persistent_table[name] = value;
2649  else
2650  p->second = value;
2651  }
2652 
2653  // Use do_persistent_assign (name, value) instead.
2654  // Delete when deprecated varref functions are removed.
2656  {
2657  persistent_table_iterator p = persistent_table.find (name);
2658 
2659  return (p == persistent_table.end ())
2660  ? persistent_table[name] : p->second;
2661  }
2662 
2664  {
2665  persistent_table_const_iterator p = persistent_table.find (name);
2666 
2667  return (p != persistent_table.end ()) ? p->second : octave_value ();
2668  }
2669 
2671  {
2672  persistent_table_iterator p = persistent_table.find (name);
2673 
2674  if (p != persistent_table.end ())
2675  persistent_table.erase (p);
2676  }
2677 
2678  bool do_is_variable (const std::string& name) const
2679  {
2680  bool retval = false;
2681 
2682  table_const_iterator p = table.find (name);
2683 
2684  if (p != table.end ())
2685  {
2686  const symbol_record& sr = p->second;
2687 
2688  retval = sr.is_variable ();
2689  }
2690 
2691  return retval;
2692  }
2693 
2694  void do_push_context (void)
2695  {
2696  for (table_iterator p = table.begin (); p != table.end (); p++)
2697  p->second.push_context (my_scope);
2698  }
2699 
2700  void do_pop_context (void)
2701  {
2702  table_iterator p = table.begin ();
2703 
2704  while (p != table.end ())
2705  {
2706  if (p->second.pop_context (my_scope) == 0)
2707  table.erase (p++);
2708  else
2709  p++;
2710  }
2711  }
2712 
2714  {
2715  for (table_iterator p = table.begin (); p != table.end (); p++)
2716  p->second.clear (my_scope);
2717  }
2718 
2719  void do_clear_objects (void)
2720  {
2721  for (table_iterator p = table.begin (); p != table.end (); p++)
2722  {
2723  symbol_record& sr = p->second;
2724  octave_value val = sr.varval ();
2725  if (val.is_object ())
2726  p->second.clear (my_scope);
2727  }
2728  }
2729 
2730  void do_clear_global (const std::string& name)
2731  {
2732  table_iterator p = table.find (name);
2733 
2734  if (p != table.end ())
2735  {
2736  symbol_record& sr = p->second;
2737 
2738  if (sr.is_global ())
2739  sr.unmark_global ();
2740  }
2741 
2742  global_table_iterator q = global_table.find (name);
2743 
2744  if (q != global_table.end ())
2745  global_table.erase (q);
2746 
2747  }
2748 
2749  void do_clear_variable (const std::string& name)
2750  {
2751  table_iterator p = table.find (name);
2752 
2753  if (p != table.end ())
2754  p->second.clear (my_scope);
2755  }
2756 
2758  {
2759  glob_match pattern (pat);
2760 
2761  for (table_iterator p = table.begin (); p != table.end (); p++)
2762  {
2763  symbol_record& sr = p->second;
2764 
2765  if (sr.is_global () && pattern.match (sr.name ()))
2766  sr.unmark_global ();
2767  }
2768 
2769  global_table_iterator q = global_table.begin ();
2770 
2771  while (q != global_table.end ())
2772  {
2773  if (pattern.match (q->first))
2774  global_table.erase (q++);
2775  else
2776  q++;
2777  }
2778  }
2779 
2781  {
2782  glob_match pattern (pat);
2783 
2784  for (table_iterator p = table.begin (); p != table.end (); p++)
2785  {
2786  symbol_record& sr = p->second;
2787 
2788  if (sr.is_defined () || sr.is_global ())
2789  {
2790  if (pattern.match (sr.name ()))
2791  sr.clear (my_scope);
2792  }
2793  }
2794  }
2795 
2797  {
2798  octave::regexp pattern (pat);
2799 
2800  for (table_iterator p = table.begin (); p != table.end (); p++)
2801  {
2802  symbol_record& sr = p->second;
2803 
2804  if (sr.is_defined () || sr.is_global ())
2805  {
2806  if (pattern.is_match (sr.name ()))
2807  sr.clear (my_scope);
2808  }
2809  }
2810  }
2811 
2812  void do_mark_automatic (const std::string& name)
2813  {
2814  do_insert (name).mark_automatic ();
2815  }
2816 
2817  void do_mark_hidden (const std::string& name)
2818  {
2819  do_insert (name).mark_hidden ();
2820  }
2821 
2822  void do_mark_global (const std::string& name)
2823  {
2824  do_insert (name).mark_global ();
2825  }
2826 
2827  std::list<symbol_record>
2828  do_all_variables (context_id context, bool defined_only,
2829  unsigned int exclude) const
2830  {
2831  std::list<symbol_record> retval;
2832 
2833  for (table_const_iterator p = table.begin (); p != table.end (); p++)
2834  {
2835  const symbol_record& sr = p->second;
2836 
2837  if ((defined_only && ! sr.is_defined (context))
2838  || (sr.xstorage_class () & exclude))
2839  continue;
2840 
2841  retval.push_back (sr);
2842  }
2843 
2844  return retval;
2845  }
2846 
2847  std::list<symbol_record> do_glob (const std::string& pattern,
2848  bool vars_only = false) const
2849  {
2850  std::list<symbol_record> retval;
2851 
2852  glob_match pat (pattern);
2853 
2854  for (table_const_iterator p = table.begin (); p != table.end (); p++)
2855  {
2856  if (pat.match (p->first))
2857  {
2858  const symbol_record& sr = p->second;
2859 
2860  if (vars_only && ! sr.is_variable ())
2861  continue;
2862 
2863  retval.push_back (sr);
2864  }
2865  }
2866 
2867  return retval;
2868  }
2869 
2870  std::list<symbol_record> do_regexp (const std::string& pattern,
2871  bool vars_only = false) const
2872  {
2873  std::list<symbol_record> retval;
2874 
2875  octave::regexp pat (pattern);
2876 
2877  for (table_const_iterator p = table.begin (); p != table.end (); p++)
2878  {
2879  if (pat.is_match (p->first))
2880  {
2881  const symbol_record& sr = p->second;
2882 
2883  if (vars_only && ! sr.is_variable ())
2884  continue;
2885 
2886  retval.push_back (sr);
2887  }
2888  }
2889 
2890  return retval;
2891  }
2892 
2893  std::list<std::string> do_variable_names (void)
2894  {
2895  std::list<std::string> retval;
2896 
2897  for (table_const_iterator p = table.begin (); p != table.end (); p++)
2898  {
2899  if (p->second.is_variable ())
2900  retval.push_back (p->first);
2901  }
2902 
2903  retval.sort ();
2904 
2905  return retval;
2906  }
2907 
2908  bool do_is_local_variable (const std::string& name) const
2909  {
2910  table_const_iterator p = table.find (name);
2911 
2912  return (p != table.end ()
2913  && ! p->second.is_global ()
2914  && p->second.is_defined ());
2915  }
2916 
2917  bool do_is_global (const std::string& name) const
2918  {
2919  table_const_iterator p = table.find (name);
2920 
2921  return p != table.end () && p->second.is_global ();
2922  }
2923 
2924  std::list<workspace_element> do_workspace_info (void) const;
2925 
2926  void do_dump (std::ostream& os);
2927 
2928  void do_cache_name (const std::string& name) { table_name = name; }
2929 
2930  void do_update_nest (void);
2931 
2933  {
2934  table_iterator p = table.find (name);
2935  if (p == table.end ())
2936  {
2937  if (nest_parent)
2938  return nest_parent->look_nonlocal (name, result);
2939  }
2940  else if (! p->second.is_automatic ())
2941  {
2942  result = p->second;
2943  return true;
2944  }
2945 
2946  return false;
2947  }
2948 };
2949 
2950 extern bool out_of_date_check (octave_value& function,
2951  const std::string& dispatch_type = "",
2952  bool check_relative = true);
2953 
2957 get_dispatch_type (const octave_value_list& args, builtin_type_t& builtin_type);
2958 
2959 #endif
void unlock_subfunction(scope_id scope)
Definition: symtab.h:808
static std::list< symbol_record > glob_variables(const string_vector &patterns)
Definition: symtab.h:2076
std::list< symbol_record > do_all_variables(context_id context, bool defined_only, unsigned int exclude) const
Definition: symtab.h:2828
octave_value find_function(const octave_value_list &args, bool local_funcs)
Definition: symtab.h:794
void unmark_hidden(void)
Definition: symtab.h:624
dispatch_map_type::iterator dispatch_map_iterator
Definition: symtab.h:747
static void clear_objects(scope_id scope=xcurrent_scope)
Definition: symtab.h:1696
void panic(const char *fmt,...)
Definition: error.cc:931
bool is_object(void) const
Definition: ov.h:593
static void install_built_in_function(const std::string &name, const octave_value &fcn)
Definition: symtab.h:1644
static void pop_context(void *)
Definition: symtab.h:1955
void do_clear_variable(const std::string &name)
Definition: symtab.h:2749
std::map< std::string, std::set< std::string > >::iterator class_precedence_table_iterator
Definition: symtab.h:2415
static void free_scope(scope_id scope)
Definition: symtab.h:2273
void do_dup_scope(symbol_table &new_symbol_table) const
Definition: symtab.h:2512
void dump(std::ostream &os, const std::string &prefix="") const
Definition: symtab.h:645
static scope_id dup_scope(scope_id scope)
Definition: symtab.h:1247
static void install_subfunction(const std::string &name, const octave_value &fcn, scope_id scope)
Definition: symtab.h:1590
For example cd octave end example noindent changes the current working directory to an error message is printed and the working directory is not changed sc
Definition: dirfns.cc:120
for(octave_idx_type n=0;n< hcv.numel();n++)
Definition: graphics.cc:10128
const std::string & name(void) const
Definition: symtab.h:690
void set_curr_fcn(octave_user_function *fcn)
Definition: symtab.h:447
octave_user_function * curr_fcn
Definition: symtab.h:2387
static void clear_functions(bool force=false)
Definition: symtab.h:1704
assign_op
Definition: ov.h:131
static void rename(const std::string &old_name, const std::string &new_name, scope_id scope=xcurrent_scope)
Definition: symtab.h:1320
scope_id my_scope
Definition: symtab.h:2371
static bool at_top_level(void)
Definition: symtab.h:1300
octave_value varval(context_id context=xdefault_context) const
Definition: symtab.h:285
static scope_id alloc(void)
Definition: symtab.h:74
std::list< workspace_element > do_workspace_info(void) const
Definition: symtab.cc:1539
void clear_user_function(bool force=false)
Definition: symtab.h:1114
fname
Definition: load-save.cc:754
symbol_record & do_insert(const std::string &name, bool force_add=false)
Definition: symtab.h:2566
static std::list< std::string > cmdline_function_names(void)
Definition: symtab.h:2172
scope_id scope(void) const
Definition: symtab.h:638
std::set< scope_id > in_use
Definition: symtab.h:121
void clear_dispatch(const std::string &type)
Definition: symtab.h:919
~symbol_table(void)
Definition: symtab.h:2439
octave_value find_function(const octave_value_list &args=octave_value_list(), bool local_funcs=true)
Definition: symtab.h:1058
octave_refcount< size_t > count
Definition: symtab.h:972
octave_value find_cmdline_function(void) const
Definition: symtab.h:1038
void mark_subfunction_in_scope_as_private(scope_id scope, const std::string &class_name)
Definition: symtab.h:1086
void do_pop_context(void)
Definition: symtab.h:2700
octave_value & varref(context_id context=xdefault_context)
Definition: symtab.h:252
symbol_table * nest_parent
Definition: symtab.h:2384
std::map< std::string, octave_value > class_methods
Definition: symtab.h:957
std::map< std::string, octave_value >::const_iterator global_table_const_iterator
Definition: symtab.h:2351
static std::list< symbol_record > regexp(const std::string &pattern, scope_id scope=xcurrent_scope)
Definition: symtab.h:2006
static void clear_variable_pattern(const std::string &pat, scope_id scope=xcurrent_scope)
Definition: symtab.h:1761
static octave_value find_method(const std::string &name, const std::string &dispatch_type)
Definition: symtab.h:1495
static void install_user_function(const std::string &name, const octave_value &fcn)
Definition: symtab.h:1623
static void clear_dispatch(const std::string &name, const std::string &type)
Definition: symtab.h:1869
void do_update_nest(void)
Definition: symtab.cc:1650
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:363
void install_subfunction(const octave_value &f, scope_id scope)
Definition: symtab.h:842
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:5068
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE * f
symbol_table(scope_id scope)
Definition: symtab.h:2434
static symbol_table * get_instance(scope_id scope, bool create=true)
Definition: symtab.h:2441
static std::list< symbol_record > all_variables(scope_id scope=xcurrent_scope, context_id context=xdefault_context, bool defined_only=true, unsigned int exclude=symbol_record::hidden)
Definition: symtab.h:1986
void push_context(scope_id s)
Definition: symtab.h:575
dispatch_map_type get_dispatch(void) const
Definition: symtab.h:1144
void clear(scope_id s)
Definition: symtab.h:581
bool is_defined(void) const
Definition: ov.h:536
bool is_automatic(void) const
Definition: symtab.h:604
static void set_scope(scope_id scope)
Definition: symtab.h:1169
static std::map< std::string, fcn_info > fcn_table
Definition: symtab.h:2406
void update(void) const
Definition: symtab.h:716
std::map< std::string, std::list< std::string > >::const_iterator const_parent_map_iterator
Definition: symtab.h:2421
bool look_nonlocal(const std::string &name, symbol_record &result)
Definition: symtab.h:2932
void install_built_in_function(const octave_value &f)
Definition: symtab.h:852
bool is_variable(context_id context=xdefault_context) const
Definition: symtab.h:598
static void clear_variables(scope_id scope)
Definition: symtab.h:1683
std::set< scope_id >::iterator set_iterator
Definition: symtab.h:62
static std::list< symbol_record > regexp_variables(const std::string &pattern, scope_id scope=xcurrent_scope)
Definition: symtab.h:2022
static void add_to_parent_map(const std::string &classname, const std::list< std::string > &parent_list)
Definition: symtab.h:2284
void error(const char *fmt,...)
Definition: error.cc:570
symbol_table::scope_id scope(void)
Definition: ov-usr-fcn.h:249
std::string table_name
Definition: symtab.h:2375
symbol_reference(const symbol_reference &ref)
Definition: symtab.h:673
octave_value varval(context_id context=xdefault_context) const
Definition: symtab.h:570
static std::list< scope_id > scopes(void)
Definition: symtab.h:85
void erase_subfunction(scope_id scope)
Definition: symtab.h:826
STL namespace.
static octave_value find_built_in_function(const std::string &name)
Definition: symtab.h:1528
static void pop_context(scope_id scope)
Definition: symtab.h:1940
bool out_of_date_check(octave_value &function, const std::string &dispatch_type="", bool check_relative=true)
Definition: symtab.cc:213
void assign(octave_value::assign_op op, const std::string &type, const std::list< octave_value_list > &idx, const octave_value &value, context_id context=xdefault_context)
Definition: symtab.h:223
bool static_workspace
Definition: symtab.h:2390
static void cleanup_instance(void)
Definition: symtab.h:115
static double fi[256]
Definition: randmtzig.cc:440
static scope_id alloc_scope(void)
Definition: symtab.h:1167
bool is_user_function_defined(void) const
Definition: symtab.h:789
OCTINTERP_API std::string get_dispatch_type(const octave_value_list &args)
Definition: symtab.cc:676
static std::list< std::string > variable_names(scope_id scope=xcurrent_scope)
Definition: symtab.h:2146
static symbol_record & insert(const std::string &name, scope_id scope=xcurrent_scope)
Definition: symtab.h:1312
static void clear_mex_functions(void)
Definition: symtab.h:1816
std::map< std::string, octave_value > class_constructors
Definition: symtab.h:954
bool do_is_global(const std::string &name) const
Definition: symtab.h:2917
static void clear_dld_function(const std::string &name)
Definition: symtab.h:1803
static void lock_subfunctions(scope_id scope=xcurrent_scope)
Definition: symtab.h:2239
static std::map< std::string, octave_value > global_table
Definition: symtab.h:2393
static void mark_automatic(const std::string &name, scope_id scope=xcurrent_scope)
Definition: symtab.h:1957
static void clear(const std::string &name)
Definition: symtab.h:1665
void do_clear_global(const std::string &name)
Definition: symtab.h:2730
std::set< scope_id > free_list
Definition: symtab.h:124
std::map< scope_id, octave_value >::iterator scope_val_iterator
Definition: symtab.h:740
s
Definition: file-io.cc:2682
static bool is_local_variable(const std::string &name, scope_id scope=xcurrent_scope)
Definition: symtab.h:2191
static octave_value dummy_octave_value
Definition: symtab.h:52
builtin_type_t
Definition: ov-base.h:61
bool is_local(void) const
Definition: symtab.h:603
void clear_dispatch(const std::string &type)
Definition: symtab.h:1131
bool is_added_static(void) const
Definition: symtab.h:610
std::map< std::string, octave_value >::iterator persistent_table_iterator
Definition: symtab.h:2358
bool is_formal(void) const
Definition: symtab.h:605
static octave_value varval(const std::string &name, scope_id scope=xcurrent_scope, context_id context=xdefault_context)
Definition: symtab.h:1373
static void clear_variables(void)
Definition: symtab.h:1691
static octave_value find_cmdline_function(const std::string &name)
Definition: symtab.h:1558
octave_function * fcn
Definition: ov-class.cc:1743
void do_non_const_unary_op(octave_value::unary_op op, const std::string &type, const std::list< octave_value_list > &idx, context_id context=xdefault_context)
Definition: symtab.h:244
octave_user_function & operator=(const octave_user_function &fn)
static void cache_name(scope_id scope, const std::string &name)
Definition: symtab.h:2231
void do_persistent_assign(const std::string &name, const octave_value &value)
Definition: symtab.h:2643
void install_user_function(const octave_value &f)
Definition: symtab.h:1102
static scope_id global_scope(void)
Definition: symtab.h:1160
std::string help_for_dispatch(void) const
Definition: symtab.h:1141
std::map< std::string, symbol_record >::iterator table_iterator
Definition: symtab.h:2348
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
Definition: cellfun.cc:398
octave_value find_user_function(void)
Definition: symtab.h:1048
static void set_curr_fcn(octave_user_function *curr_fcn, scope_id scope=xcurrent_scope)
Definition: symtab.h:2322
static scope_id top_scope(void)
Definition: symtab.h:1161
static symbol_record find_symbol(const std::string &name, scope_id scope=xcurrent_scope)
Definition: symtab.h:1278
void clear_function(const std::string &nm)
Definition: variables.cc:79
static context_id current_context(void)
Definition: symtab.h:1165
JNIEnv void * args
Definition: ov-java.cc:67
symbol_record(symbol_record_rep *new_rep)
Definition: symtab.h:654
static void push_context(scope_id scope=xcurrent_scope)
Definition: symtab.h:1925
dispatch_map_type::const_iterator dispatch_map_const_iterator
Definition: symtab.h:746
static void clear_user_function(const std::string &name)
Definition: symtab.h:1787
static octave_value global_varval(const std::string &name)
Definition: symtab.h:1406
void clear(bool force=false)
Definition: symtab.h:1112
static void mark_subfunctions_in_scope_as_private(scope_id scope, const std::string &class_name)
Definition: symtab.h:1240
static std::list< std::string > global_variable_names(void)
Definition: symtab.h:2126
static void persistent_assign(const std::string &name, const octave_value &value=octave_value())
Definition: symtab.h:1446
void unlock_subfunction(scope_id scope)
Definition: symtab.h:1070
std::map< std::string, fcn_info >::iterator fcn_table_iterator
Definition: symtab.h:2368
std::map< std::string, octave_value > private_functions
Definition: symtab.h:951
bool do_is_local_variable(const std::string &name) const
Definition: symtab.h:2908
static scope_id_cache * instance
Definition: symtab.h:113
static context_id xcurrent_context
Definition: symtab.h:2430
static std::map< std::string, std::list< std::string > > parent_map
Definition: symtab.h:2418
static void clear_symbol(const std::string &name)
Definition: symtab.h:1733
static std::list< symbol_record > glob_variables(const std::string &pattern, scope_id scope=xcurrent_scope)
Definition: symtab.h:2014
symbol_record_rep(scope_id s, const std::string &nm, const octave_value &v, unsigned int sc)
Definition: symtab.h:209
OCTAVE_EXPORT octave_value_list any number nd example oindent prints the prompt xample Pick a any number!nd example oindent and waits for the user to enter a value The string entered by the user is evaluated as an so it may be a literal a variable name
Definition: input.cc:871
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
Definition: utils.cc:941
void do_assign(const std::string &name, const octave_value &value, context_id context, bool force_add)
Definition: symtab.h:2604
std::map< std::string, octave_value >::iterator global_table_iterator
Definition: symtab.h:2353
std::pair< std::string, octave_value > subfunction_defined_in_scope(scope_id scope=xcurrent_scope) const
Definition: symtab.h:1076
void do_clear_objects(void)
Definition: symtab.h:2719
dispatch_map_type dispatch_map
Definition: symtab.h:960
fcn_info(const fcn_info &fi)
Definition: symtab.h:992
std::map< std::string, octave_value >::const_iterator str_val_const_iterator
Definition: symtab.h:743
#define OCTINTERP_API
Definition: mexproto.h:69
bool is_persistent(void) const
Definition: symtab.h:609
void unmark_formal(void)
Definition: symtab.h:623
void init_persistent(void)
Definition: symtab.h:630
void clear_variable(const std::string &nm)
Definition: variables.cc:85
void do_clear_variables(void)
Definition: symtab.h:2713
void install_cmdline_function(const octave_value &f)
Definition: symtab.h:837
std::map< std::string, octave_value >::const_iterator persistent_table_const_iterator
Definition: symtab.h:2356
static std::list< symbol_record > regexp_global_variables(const std::string &pattern)
Definition: symtab.h:2054
static llvm::LLVMContext & context
Definition: jit-typeinfo.cc:76
octave_value do_varval(const std::string &name, context_id context) const
Definition: symtab.h:2636
bool is_global(void) const
Definition: symtab.h:606
std::set< scope_id >::const_iterator set_const_iterator
Definition: symtab.h:63
fcn_info_rep * rep
Definition: symtab.h:1157
static octave_value persistent_varval(const std::string &name, scope_id scope=xcurrent_scope)
Definition: symtab.h:1461
bool is_variable(context_id context) const
Definition: symtab.h:372
static void clear_variable_regexp(const std::string &pat, scope_id scope=xcurrent_scope)
Definition: symtab.h:1770
bool is_defined(context_id context=xdefault_context) const
Definition: symtab.h:583
void unmark_global(void)
Definition: symtab.h:626
void print_dispatch(std::ostream &os) const
Definition: symtab.h:1136
void lock_subfunction(scope_id scope)
Definition: symtab.h:1065
static void erase_subfunctions_in_scope(scope_id scope)
Definition: symtab.h:1233
static void force_assign(const std::string &name, const octave_value &value=octave_value(), scope_id scope=xcurrent_scope, context_id context=xdefault_context)
Definition: symtab.h:1355
static void global_assign(const std::string &name, const octave_value &value=octave_value())
Definition: symtab.h:1383
double tmp
Definition: data.cc:6300
static void pop_context(void)
Definition: symtab.h:1951
is false
Definition: cellfun.cc:398
octave_value find_autoload(void)
Definition: symtab.h:1043
void do_non_const_unary_op(octave_value::unary_op op, context_id context=xdefault_context)
Definition: symtab.h:238
static void add_dispatch(const std::string &name, const std::string &type, const std::string &fname)
Definition: symtab.h:1848
octave_value retval
Definition: data.cc:6294
static void install_cmdline_function(const std::string &name, const octave_value &fcn)
Definition: symtab.h:1566
std::map< std::string, symbol_record > table
Definition: symtab.h:2378
void install_built_in_function(const octave_value &f)
Definition: symtab.h:1107
bool is_black_hole(void) const
Definition: symtab.h:687
void clear_user_function(bool force=false)
Definition: symtab.h:880
bool match(const std::string &str) const
Definition: glob-match.cc:32
static void clear_global(const std::string &name, scope_id scope=xcurrent_scope)
Definition: symtab.h:1715
void assign(const octave_value &value, context_id context=xdefault_context)
Definition: symtab.h:217
void do_push_context(void)
Definition: symtab.h:2694
fcn_info(const std::string &nm="")
Definition: symtab.h:989
static fcn_info::dispatch_map_type get_dispatch(const std::string &name)
Definition: symtab.h:1893
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)
Definition: symtab.h:1330
void add_dispatch(const std::string &type, const std::string &fname)
Definition: symtab.h:1126
idx type
Definition: ov.cc:3129
void do_non_const_unary_op(octave_value::unary_op op)
Definition: symtab.h:552
std::map< std::string, std::list< std::string > >::iterator parent_map_iterator
Definition: symtab.h:2423
octave_value builtin_find(void)
Definition: symtab.h:1023
void mark_added_static(void)
Definition: symtab.h:619
void unmark_added_static(void)
Definition: symtab.h:628
static std::list< std::string > parent_classes(const std::string &dispatch_type)
Definition: symtab.h:2291
std::list< scope_id > do_scopes(void) const
Definition: symtab.h:156
std::deque< octave_value > value_stack
Definition: symtab.h:466
symbol_record_rep * dup(scope_id new_scope) const
Definition: symtab.h:452
bool is_match(const std::string &buffer)
Definition: lo-regexp.cc:420
static symbol_record dummy_symbol_record
Definition: symtab.h:657
unsigned int xstorage_class(void) const
Definition: symtab.h:640
void clear_map(std::map< T, octave_value > &map, bool force=false)
Definition: symtab.h:859
void install_user_function(const octave_value &f)
Definition: symtab.h:847
octave_value find_method(const std::string &dispatch_type) const
Definition: symtab.h:1028
static scope_id xcurrent_scope
Definition: symtab.h:2428
void assign(octave_value::assign_op op, const std::string &type, const std::list< octave_value_list > &idx, const octave_value &value, context_id context=xdefault_context)
Definition: symtab.h:537
static octave_value find_autoload(const std::string &name)
Definition: symtab.h:1537
void erase_persistent(void)
Definition: symtab.h:632
static octave_user_function * get_curr_fcn(scope_id scope=xcurrent_scope)
Definition: symtab.h:2316
std::map< std::string, std::string > dispatch_map_type
Definition: symtab.h:736
octave_value do_persistent_varval(const std::string &name)
Definition: symtab.h:2663
std::list< symbol_record > do_glob(const std::string &pattern, bool vars_only=false) const
Definition: symtab.h:2847
With real return the complex result
Definition: data.cc:3375
octave_value find_built_in_function(void) const
Definition: symtab.h:1033
void mark_automatic(void)
Definition: symtab.h:613
void assign(const octave_value &value, context_id context=xdefault_context)
Definition: symtab.h:531
static std::map< scope_id, symbol_table * > all_instances
Definition: symtab.h:2402
void insert_symbol_record(const symbol_record &sr)
Definition: symtab.h:2506
static std::map< std::string, std::set< std::string > > class_precedence_table
Definition: symtab.h:2410
static octave_idx_type find(octave_idx_type i, octave_idx_type *pp)
Definition: colamd.cc:112
std::map< scope_id, symbol_table * >::const_iterator all_instances_const_iterator
Definition: symtab.h:2361
void unmark_automatic(void)
Definition: symtab.h:622
static bool is_variable(const std::string &name, scope_id scope=xcurrent_scope)
Definition: symtab.h:1478
static void persistent_assign(const std::string &name, scope_id scope, const octave_value &value=octave_value())
Definition: symtab.h:1436
std::map< scope_id, symbol_table * >::iterator all_instances_iterator
Definition: symtab.h:2363
context_id active_context(void) const
Definition: symtab.h:636
static void clear_all(bool force=false)
Definition: symtab.h:1670
static std::list< std::string > user_function_names(void)
Definition: symtab.h:2109
static std::string help_for_dispatch(const std::string &name)
Definition: symtab.h:1909
void do_clear_variable_regexp(const std::string &pat)
Definition: symtab.h:2796
void erase_subfunction(scope_id scope)
Definition: symtab.h:1081
void rename(const std::string &new_name)
Definition: symtab.h:526
static void clear_variable(const std::string &name, scope_id scope=xcurrent_scope)
Definition: symtab.h:1724
static void alias_built_in_function(const std::string &alias, const std::string &name)
Definition: symtab.h:1831
void do_non_const_unary_op(octave_value::unary_op op, const std::string &type, const std::list< octave_value_list > &idx)
Definition: symtab.h:557
void do_cache_name(const std::string &name)
Definition: symtab.h:2928
std::map< std::string, symbol_record >::const_iterator table_const_iterator
Definition: symtab.h:2346
static void mark_hidden(const std::string &name, scope_id scope=xcurrent_scope)
Definition: symtab.h:1966
void do_clear_global_pattern(const std::string &pat)
Definition: symtab.h:2757
dispatch_map_type get_dispatch(void) const
Definition: symtab.h:931
symbol_record_rep * rep
Definition: symtab.h:652
std::map< std::string, octave_value >::iterator str_val_iterator
Definition: symtab.h:744
static std::list< symbol_record > glob(const std::string &pattern, scope_id scope=xcurrent_scope)
Definition: symtab.h:1998
fcn_info_rep(const std::string &nm)
Definition: symtab.h:756
static bool is_global(const std::string &name, scope_id scope=xcurrent_scope)
Definition: symtab.h:2204
static symbol_table * instance
Definition: symtab.h:2399
std::list< std::string > do_variable_names(void)
Definition: symtab.h:2893
static const scope_id xtop_scope
Definition: symtab.h:2426
static std::list< scope_id > scopes(void)
Definition: symtab.h:1272
bool is_valid(void) const
Definition: symtab.h:593
void do_mark_hidden(const std::string &name)
Definition: symtab.h:2817
bool is_user_function_defined(void) const
Definition: symtab.h:1053
void unmark_inherited(void)
Definition: symtab.h:625
bool is_defined(context_id context=xdefault_context) const
Definition: symtab.h:359
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
static void free(scope_id scope)
Definition: symtab.h:79
void clear_mex_function(void)
Definition: symtab.h:1124
is longer than or if then or only for unique occurrences of the complete pattern(false).The default is true.If a cell array of strings ar
Definition: strfind.cc:192
p
Definition: lu.cc:138
OCTAVE_EXPORT octave_value_list or N dimensional array whose elements are all equal to the IEEE symbol zero divided by nd tex zero divided by nd ifnottex and any operation involving another NaN value(5+NaN).Note that NaN always compares not equal to NaN(NaN!
symbol_reference(const symbol_record &record, scope_id curr_scope=symbol_table::current_scope())
Definition: symtab.h:668
void do_free(scope_id scope)
Definition: symtab.h:145
static std::list< std::string > top_level_variable_names(void)
Definition: symtab.h:2139
void install_cmdline_function(const octave_value &f)
Definition: symtab.h:1092
std::map< std::string, octave_value > persistent_table
Definition: symtab.h:2396
octave_map map(dims)
static std::list< symbol_record > glob_global_variables(const std::string &pattern)
Definition: symtab.h:2031
void clear(bool force=false)
Definition: symtab.h:902
void add_nest_child(symbol_table &st)
Definition: symtab.h:2499
void do_rename(const std::string &old_name, const std::string &new_name)
Definition: symtab.h:2588
std::pair< std::string, octave_value > subfunction_defined_in_scope(scope_id scope) const
Definition: symtab.h:817
void dump(std::ostream &os, const std::string &prefix="") const
Definition: symtab.h:1150
static const scope_id xglobal_scope
Definition: symtab.h:2425
scope_id do_alloc(void)
Definition: symtab.h:126
int scope_id
Definition: symtab.h:54
void lock_subfunction(scope_id scope)
Definition: symtab.h:800
octave_value & varref(context_id context=xdefault_context)
Definition: symtab.h:565
b
Definition: cellfun.cc:398
std::list< symbol_record > do_regexp(const std::string &pattern, bool vars_only=false) const
Definition: symtab.h:2870
bool is_undefined(context_id context=xdefault_context) const
Definition: symtab.h:588
octave_value & do_persistent_varref(const std::string &name)
Definition: symtab.h:2655
static void inherit(scope_id scope, scope_id donor_scope, context_id donor_context)
Definition: symtab.h:1287
void clear_autoload_function(bool force=false)
Definition: symtab.h:872
static void clear_global_pattern(const std::string &pat, scope_id scope=xcurrent_scope)
Definition: symtab.h:1752
std::map< std::string, std::set< std::string > >::const_iterator class_precedence_table_const_iterator
Definition: symtab.h:2413
void set_curr_fcn(octave_user_function *fcn)
Definition: symtab.h:642
void do_erase_persistent(const std::string &name)
Definition: symtab.h:2670
void assign(octave_value::assign_op op, const octave_value &value, context_id context=xdefault_context)
Definition: symtab.h:546
void do_inherit(symbol_table &donor_table, context_id donor_context)
Definition: symtab.h:2529
static bool instance_ok(void)
Definition: symtab.h:92
void mark_inherited(void)
Definition: symtab.h:616
static fcn_info * get_fcn_info(const std::string &name)
Definition: symtab.h:2554
symbol_record dup(scope_id new_scope) const
Definition: symtab.h:519
static bool is_built_in_function_name(const std::string &name)
Definition: symtab.h:1487
static void unlock_subfunctions(scope_id scope=xcurrent_scope)
Definition: symtab.h:2246
static void clear_symbol_pattern(const std::string &pat)
Definition: symtab.h:1779
static void erase_persistent(const std::string &name, scope_id scope=xcurrent_scope)
Definition: symtab.h:1469
static void update_nest(scope_id scope)
Definition: symtab.h:1616
size_t context_id
Definition: symtab.h:55
bool is_inherited(void) const
Definition: symtab.h:608
void do_mark_global(const std::string &name)
Definition: symtab.h:2822
std::vector< symbol_table * > nest_children
Definition: symtab.h:2381
std::string full_name(void) const
Definition: symtab.h:935
std::map< std::string, fcn_info >::const_iterator fcn_table_const_iterator
Definition: symtab.h:2366
void install_subfunction(const octave_value &f, scope_id scope)
Definition: symtab.h:1097
void mark_persistent(void)
Definition: symtab.h:618
bool do_is_variable(const std::string &name) const
Definition: symtab.h:2678
static std::list< workspace_element > workspace_info(scope_id scope=xcurrent_scope)
Definition: symtab.h:2217
static octave_value find_user_function(const std::string &name)
Definition: symtab.h:1550
static std::map< std::string, octave_value > subfunctions_defined_in_scope(scope_id scope=xcurrent_scope)
Definition: symtab.h:2254
unary_op
Definition: ov.h:76
void assign(octave_value::assign_op op, const octave_value &value, context_id context=xdefault_context)
Definition: symtab.h:232
static void print_dispatch(std::ostream &os, const std::string &name)
Definition: symtab.h:1881
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854
symbol_record(const symbol_record &sr)
Definition: symtab.h:493
static std::list< std::string > built_in_function_names(void)
Definition: symtab.h:2153
static void clear_function(const std::string &name)
Definition: symtab.h:1710
std::map< scope_id, octave_value > subfunctions
Definition: symtab.h:948
static void clear_function_pattern(const std::string &pat)
Definition: symtab.h:1741
octave_value find(const octave_value_list &args=octave_value_list(), bool local_funcs=true)
Definition: symtab.h:1017
static void set_scope_and_context(scope_id scope, context_id context)
Definition: symtab.h:1193
symbol_record(scope_id s=xcurrent_scope, const std::string &nm="", const octave_value &v=octave_value(), unsigned int sc=local)
Definition: symtab.h:487
size_t pop_context(scope_id s)
Definition: symtab.h:577
static void mark_global(const std::string &name, scope_id scope=xcurrent_scope)
Definition: symtab.h:1975
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))
void unmark_persistent(void)
Definition: symtab.h:627
static void erase_scope(scope_id scope)
Definition: symtab.h:1215
std::map< scope_id, octave_value >::const_iterator scope_val_const_iterator
Definition: symtab.h:739
static void top_level_assign(const std::string &name, const octave_value &value=octave_value())
Definition: symtab.h:1414
bool is_hidden(void) const
Definition: symtab.h:607
void do_clear_variable_pattern(const std::string &pat)
Definition: symtab.h:2780
static scope_id current_scope(void)
Definition: symtab.h:1163
octave_value & do_varref(const std::string &name, context_id context, bool force_add)
Definition: symtab.h:2621
void clear_autoload_function(bool force=false)
Definition: symtab.h:1119
static octave_value top_level_varval(const std::string &name)
Definition: symtab.h:1430
symbol_record do_find_symbol(const std::string &name)
Definition: symtab.h:2519
void do_mark_automatic(const std::string &name)
Definition: symtab.h:2812
void add_dispatch(const std::string &type, const std::string &fname)
Definition: symtab.h:914
const std::string & name(void) const
Definition: symtab.h:524