GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
symscope.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1993-2018 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
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License 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 <https://www.gnu.org/licenses/>.
21 
22 */
23 
24 #if ! defined (octave_symscope_h)
25 #define octave_symscope_h 1
26 
27 #include "octave-config.h"
28 
29 #include <deque>
30 #include <limits>
31 #include <list>
32 #include <map>
33 #include <memory>
34 #include <set>
35 #include <string>
36 
37 #include "glob-match.h"
38 #include "lo-regexp.h"
39 #include "oct-refcount.h"
40 
41 class tree_argument_list;
43 
44 #include "ov.h"
45 #include "ovl.h"
46 #include "symrec.h"
47 
48 namespace octave
49 {
50  class symbol_scope;
51 
53  : public std::enable_shared_from_this<symbol_scope_rep>
54  {
55  public:
56 
57  typedef std::map<std::string, symbol_record>::const_iterator
59  typedef std::map<std::string, symbol_record>::iterator
61 
62  typedef std::map<std::string, octave_value>::const_iterator
64  typedef std::map<std::string, octave_value>::iterator
66 
68  : m_name (name), m_symbols (), m_subfunctions (), m_fcn (nullptr),
71  { }
72 
73  // No copying!
74 
75  symbol_scope_rep (const symbol_scope&) = delete;
76 
77  symbol_scope_rep& operator = (const symbol_scope&) = delete;
78 
79  ~symbol_scope_rep (void) = default;
80 
82  {
83  m_symbols[sr.name ()] = sr;
84  }
85 
86  bool is_nested (void) const { return m_is_nested; }
87 
88  void mark_nested (void) { m_is_nested = true; }
89 
90  bool is_static (void) const { return m_is_static; }
91 
92  void mark_static (void) { m_is_static = true; }
93 
94  std::shared_ptr<symbol_scope_rep> parent_scope_rep (void) const
95  {
96  return m_parent.lock ();
97  }
98 
99  std::shared_ptr<symbol_scope_rep> dup (void) const
100  {
101  std::shared_ptr<symbol_scope_rep> new_sid
102  = std::shared_ptr<symbol_scope_rep> (new symbol_scope_rep (m_name));
103 
104  for (const auto& nm_sr : m_symbols)
105  new_sid->insert_symbol_record (nm_sr.second.dup (new_sid));
106 
107  new_sid->m_parent = m_parent;
108 
109  return new_sid;
110  }
111 
113  {
114  m_context = context;
115  }
116 
118  {
119  return m_context;
120  }
121 
123  {
124  table_iterator p = m_symbols.find (name);
125 
126  if (p == m_symbols.end ())
127  return insert (name);
128  else
129  return p->second;
130  }
131 
132  void inherit_internal
133  (const std::shared_ptr<symbol_scope_rep>& donor_scope_rep)
134  {
135  for (auto& nm_sr : m_symbols)
136  {
137  symbol_record& sr = nm_sr.second;
138 
139  if (! (sr.is_automatic () || sr.is_formal ()))
140  {
141  std::string nm = sr.name ();
142 
143  if (nm != "__retval__")
144  {
145  octave_value val = donor_scope_rep->varval (nm);
146 
147  if (val.is_defined ())
148  {
149  sr.assign (val, m_context);
150 
151  sr.mark_inherited ();
152  }
153  }
154  }
155  }
156  }
157 
158  void inherit (const std::shared_ptr<symbol_scope_rep>& donor_scope_rep)
159  {
160  std::shared_ptr<symbol_scope_rep> dsr = donor_scope_rep;
161 
162  while (dsr)
163  {
164  inherit_internal (dsr);
165 
166  if (dsr->is_nested ())
167  dsr = parent_scope_rep ();
168  else
169  break;
170  }
171  }
172 
174  find (const std::string& name, const octave_value_list& args,
175  bool skip_variables, bool local_funcs);
176 
178  insert (const std::string& name, bool force_add = false);
179 
180  void rename (const std::string& old_name, const std::string& new_name)
181  {
182  table_iterator p = m_symbols.find (old_name);
183 
184  if (p != m_symbols.end ())
185  {
186  symbol_record sr = p->second;
187 
188  sr.rename (new_name);
189 
190  m_symbols.erase (p);
191 
192  m_symbols[new_name] = sr;
193  }
194  }
195 
196  void assign (const std::string& name, const octave_value& value,
197  bool force_add)
198  {
199  table_iterator p = m_symbols.find (name);
200 
201  if (p == m_symbols.end ())
202  {
203  symbol_record& sr = insert (name, force_add);
204 
205  sr.assign (value, m_context);
206  }
207  else
208  p->second.assign (value, m_context);
209  }
210 
211  void assign (const std::string& name,
212  const octave_value& value = octave_value ())
213  {
214  assign (name, value, false);
215  }
216 
218  {
219  table_iterator p = m_symbols.find (name);
220 
221  if (p == m_symbols.end ())
222  {
223  symbol_record& sr = insert (name, true);
224 
225  sr.assign (value, m_context);
226  }
227  else
228  p->second.assign (value, m_context);
229  }
230 
232  {
234 
235  return (p != m_symbols.end ()
236  ? p->second.varval (m_context) : octave_value ());
237  }
238 
239  bool is_variable (const std::string& name) const
240  {
241  bool retval = false;
242 
244 
245  if (p != m_symbols.end ())
246  {
247  const symbol_record& sr = p->second;
248 
250  }
251 
252  return retval;
253  }
254 
255  void push_context (void)
256  {
257  for (auto& nm_sr : m_symbols)
258  nm_sr.second.push_context ();
259  }
260 
261  void pop_context (void)
262  {
263  table_iterator tbl_it = m_symbols.begin ();
264 
265  while (tbl_it != m_symbols.end ())
266  {
267  if (tbl_it->second.pop_context () == 0)
268  m_symbols.erase (tbl_it++);
269  else
270  tbl_it++;
271  }
272  }
273 
274  void refresh (void)
275  {
276  for (auto& nm_sr : m_symbols)
277  {
278  symbol_record& sr = nm_sr.second;
279 
280  if (sr.is_global ())
281  sr.unbind_global_rep ();
282  else if (! (sr.is_persistent () || sr.is_forwarded ()))
283  sr.clear (m_context);
284  }
285  }
286 
287  void clear_variables (void)
288  {
289  for (auto& nm_sr : m_symbols)
290  nm_sr.second.clear (m_context);
291  }
292 
293  void clear_objects (void)
294  {
295  for (auto& nm_sr : m_symbols)
296  {
297  symbol_record& sr = nm_sr.second;
299  if (val.isobject ())
300  nm_sr.second.clear (m_context);
301  }
302  }
303 
305  {
306  table_iterator p = m_symbols.find (name);
307 
308  if (p != m_symbols.end ())
309  p->second.clear (m_context);
310  else if (m_is_nested)
311  {
312  std::shared_ptr<symbol_scope_rep> psr = parent_scope_rep ();
313 
314  if (psr)
315  psr->clear_variable (name);
316  }
317  }
318 
320  {
321  glob_match pattern (pat);
322 
323  for (auto& nm_sr : m_symbols)
324  {
325  symbol_record& sr = nm_sr.second;
326 
327  if (sr.is_defined (m_context) || sr.is_global ())
328  {
329  if (pattern.match (sr.name ()))
330  sr.clear (m_context);
331  }
332  }
333 
334  if (m_is_nested)
335  {
336  std::shared_ptr<symbol_scope_rep> psr = parent_scope_rep ();
337 
338  if (psr)
339  psr->clear_variable_pattern (pat);
340  }
341  }
342 
344  {
345  octave::regexp pattern (pat);
346 
347  for (auto& nm_sr : m_symbols)
348  {
349  symbol_record& sr = nm_sr.second;
350 
351  if (sr.is_defined (m_context) || sr.is_global ())
352  {
353  if (pattern.is_match (sr.name ()))
354  sr.clear (m_context);
355  }
356  }
357 
358  if (m_is_nested)
359  {
360  std::shared_ptr<symbol_scope_rep> psr = parent_scope_rep ();
361 
362  if (psr)
363  psr->clear_variable_regexp (pat);
364  }
365  }
366 
368  {
370  }
371 
373  {
374  insert (name).mark_hidden ();
375  }
376 
378  {
379  insert (name).mark_global ();
380  }
381 
382  std::list<symbol_record>
383  all_variables (bool defined_only = true,
384  unsigned int exclude = symbol_record::hidden) const
385  {
386  std::list<symbol_record> retval;
387 
388  for (const auto& nm_sr : m_symbols)
389  {
390  const symbol_record& sr = nm_sr.second;
391 
392  if ((defined_only && ! sr.is_defined (m_context))
393  || (sr.storage_class () & exclude))
394  continue;
395 
396  retval.push_back (sr);
397  }
398 
399  return retval;
400  }
401 
402  std::list<symbol_record>
403  glob (const std::string& pattern, bool vars_only = false) const
404  {
405  std::list<symbol_record> retval;
406 
407  glob_match pat (pattern);
408 
409  for (const auto& nm_sr : m_symbols)
410  {
411  if (pat.match (nm_sr.first))
412  {
413  const symbol_record& sr = nm_sr.second;
414 
415  if (vars_only && ! sr.is_variable (m_context))
416  continue;
417 
418  retval.push_back (sr);
419  }
420  }
421 
422  return retval;
423  }
424 
425  std::list<symbol_record>
426  regexp (const std::string& pattern, bool vars_only = false) const
427  {
428  std::list<symbol_record> retval;
429 
430  octave::regexp pat (pattern);
431 
432  for (const auto& nm_sr : m_symbols)
433  {
434  if (pat.is_match (nm_sr.first))
435  {
436  const symbol_record& sr = nm_sr.second;
437 
438  if (vars_only && ! sr.is_variable (m_context))
439  continue;
440 
441  retval.push_back (sr);
442  }
443  }
444 
445  return retval;
446  }
447 
448  std::list<std::string> variable_names (void)
449  {
450  std::list<std::string> retval;
451 
452  for (const auto& nm_sr : m_symbols)
453  {
454  if (nm_sr.second.is_variable (m_context))
455  retval.push_back (nm_sr.first);
456  }
457 
458  retval.sort ();
459 
460  return retval;
461  }
462 
463  bool is_local_variable (const std::string& name) const
464  {
466 
467  return (p != m_symbols.end ()
468  && ! p->second.is_global ()
469  && p->second.is_defined (m_context));
470  }
471 
472  bool is_global (const std::string& name) const
473  {
475 
476  return p != m_symbols.end () && p->second.is_global ();
477  }
478 
480  const octave_value& fval)
481  {
482  m_subfunctions[name] = fval;
483  }
484 
486  const octave_value& fval,
487  const symbol_scope& fcn_scope)
488  {
489  m_subfunctions[name] = fval;
490 
491  m_children.push_back (fcn_scope);
492  }
493 
495 
496  void lock_subfunctions (void)
497  {
498  for (auto& nm_sf : m_subfunctions)
499  nm_sf.second.lock ();
500  }
501 
503  {
504  for (auto& nm_sf : m_subfunctions)
505  nm_sf.second.unlock ();
506  }
507 
508  std::map<std::string, octave_value> subfunctions (void) const
509  {
510  return m_subfunctions;
511  }
512 
513  void erase_subfunctions (void)
514  {
515  m_subfunctions.clear ();
516  }
517 
518  void mark_subfunctions_in_scope_as_private (const std::string& class_name);
519 
520  bool has_subfunctions (void) const
521  {
522  return ! m_subfunction_names.empty ();
523  }
524 
525  void stash_subfunction_names (const std::list<std::string>& names)
526  {
527  m_subfunction_names = names;
528  }
529 
530  std::list<std::string> subfunction_names (void) const
531  {
532  return m_subfunction_names;
533  }
534 
535  octave_value dump (void) const;
536 
537  std::string name (void) const { return m_name; }
538 
539  void cache_name (const std::string& name) { m_name = name; }
540 
541  octave_user_function *function (void) { return m_fcn; }
542 
544 
545  void set_parent (const std::shared_ptr<symbol_scope_rep>& parent);
546 
547  void update_nest (void);
548 
550 
551  void bind_script_symbols (const std::shared_ptr<symbol_scope_rep>& curr_scope);
552 
553  void unbind_script_symbols (void);
554 
555  octave_value dump_symbols_map (void) const;
556 
557  private:
558 
559  //! Name for this scope (usually the corresponding filename of the
560  //! function corresponding to the scope).
561 
563 
564  //! Map from symbol names to symbol info.
565 
566  std::map<std::string, symbol_record> m_symbols;
567 
568  //! Map from symbol names to subfunctions.
569 
570  std::map<std::string, octave_value> m_subfunctions;
571 
572  //! The list of subfunctions (if any) in the order they appear in
573  //! the function file.
574 
575  std::list<std::string> m_subfunction_names;
576 
577  //! The associated user code (may be null).
578 
580 
581  //! Parent of nested function (may be null).
582 
583  std::weak_ptr<symbol_scope_rep> m_parent;
584 
585  //! Child nested functions.
586 
587  std::vector<symbol_scope> m_children;
588 
589  //! If true, then this scope belongs to a nested function.
590 
592 
593  //! If true then no variables can be added.
594 
596 
598  };
599 
601  {
602  public:
603 
604  // Create a valid but possibly unnamed scope.
606  : m_rep (new symbol_scope_rep (name))
607  { }
608 
609  // NEW_REP must be dynamically allocated or nullptr. If it is
610  // nullptr, the scope is invalid.
611  symbol_scope (const std::shared_ptr<symbol_scope_rep> new_rep = nullptr)
612  : m_rep (new_rep)
613  { }
614 
615  symbol_scope (const symbol_scope&) = default;
616 
617  symbol_scope& operator = (const symbol_scope&) = default;
618 
619  ~symbol_scope (void) = default;
620 
621  bool is_valid (void) const { return bool (m_rep); }
622 
623  explicit operator bool () const { return bool (m_rep); }
624 
626  {
627  if (m_rep)
628  m_rep->insert_symbol_record (sr);
629  }
630 
631  bool is_nested (void) const
632  {
633  return m_rep ? m_rep->is_nested () : false;
634  }
635 
636  void mark_nested (void)
637  {
638  if (m_rep)
639  m_rep->mark_nested ();
640  }
641 
642  bool is_static (void) const
643  {
644  return m_rep ? m_rep->is_static () : false;
645  }
646 
647  void mark_static (void)
648  {
649  if (m_rep)
650  m_rep->mark_static ();
651  }
652 
653  std::shared_ptr<symbol_scope_rep> parent_scope (void) const
654  {
655  return m_rep ? m_rep->parent_scope_rep () : nullptr;
656  }
657 
658  symbol_scope dup (void) const
659  {
660  return symbol_scope (m_rep ? m_rep->dup () : nullptr);
661  }
662 
664  {
665  if (m_rep)
666  m_rep->set_context (context);
667  }
668 
670  {
671  return m_rep ? m_rep->current_context () : 0;
672  }
673 
675  {
676  return m_rep ? m_rep->find_symbol (name) : symbol_record ();
677  }
678 
679  void inherit (const symbol_scope& donor_scope)
680  {
681  if (m_rep)
682  m_rep->inherit (donor_scope.get_rep ());
683  }
684 
686  find (const std::string& name, const octave_value_list& args,
687  bool skip_variables, bool local_funcs)
688  {
689  return (m_rep
690  ? m_rep->find (name, args, skip_variables, local_funcs)
691  : octave_value ());
692  }
693 
695  insert (const std::string& name, bool force_add = false)
696  {
697  static symbol_record dummy_symrec;
698  return m_rep ? m_rep->insert (name, force_add) : dummy_symrec;
699  }
700 
701  void rename (const std::string& old_name, const std::string& new_name)
702  {
703  if (m_rep)
704  m_rep->rename (old_name, new_name);
705  }
706 
707  void assign (const std::string& name, const octave_value& value,
708  bool force_add)
709  {
710  if (m_rep)
711  m_rep->assign (name, value, force_add);
712  }
713 
714  void assign (const std::string& name,
715  const octave_value& value = octave_value ())
716  {
717  if (m_rep)
718  m_rep->assign (name, value);
719  }
720 
722  {
723  if (m_rep)
724  m_rep->force_assign (name, value);
725  }
726 
728  {
729  return m_rep ? m_rep->varval (name) : octave_value ();
730  }
731 
732  bool is_variable (const std::string& name) const
733  {
734  return m_rep ? m_rep->is_variable (name) : false;
735  }
736 
737  void push_context (void)
738  {
739  if (m_rep)
740  m_rep->push_context ();
741  }
742 
743  void pop_context (void)
744  {
745  if (m_rep)
746  m_rep->pop_context ();
747  }
748 
749  void refresh (void)
750  {
751  if (m_rep)
752  m_rep->refresh ();
753  }
754 
755  void clear_variables (void)
756  {
757  if (m_rep)
758  m_rep->clear_variables ();
759  }
760 
761  void clear_objects (void)
762  {
763  if (m_rep)
764  m_rep->clear_objects ();
765  }
766 
768  {
769  if (m_rep)
770  m_rep->clear_variable (name);
771  }
772 
774  {
775  if (m_rep)
776  m_rep->clear_variable_pattern (pat);
777  }
778 
780  {
781  if (m_rep)
782  m_rep->clear_variable_regexp (pat);
783  }
784 
786  {
787  if (m_rep)
788  m_rep->mark_automatic (name);
789  }
790 
792  {
793  if (m_rep)
794  m_rep->mark_hidden (name);
795  }
796 
797  // This function should only be called for the global
798  // symbol_scope, and that should only happen when it is added to
799  // the global symbol_scope.
800 
802  {
803  if (m_rep)
804  m_rep->mark_global (name);
805  }
806 
807  std::list<symbol_record>
808  all_variables (bool defined_only = true,
809  unsigned int exclude = symbol_record::hidden) const
810  {
811  return (m_rep
812  ? m_rep->all_variables (defined_only, exclude)
813  : std::list<symbol_record> ());
814  }
815 
816  std::list<symbol_record>
817  glob (const std::string& pattern, bool vars_only = false) const
818  {
819  return (m_rep
820  ? m_rep->glob (pattern, vars_only)
821  : std::list<symbol_record> ());
822  }
823 
824  std::list<symbol_record>
825  regexp (const std::string& pattern, bool vars_only = false) const
826  {
827  return (m_rep
828  ? m_rep->regexp (pattern, vars_only)
829  : std::list<symbol_record> ());
830  }
831 
832  std::list<std::string> variable_names (void)
833  {
834  return m_rep ? m_rep->variable_names () : std::list<std::string> ();
835  }
836 
837  bool is_local_variable (const std::string& name) const
838  {
839  return m_rep ? m_rep->is_local_variable (name) : false;
840  }
841 
842  bool is_global (const std::string& name) const
843  {
844  return m_rep ? m_rep->is_global (name) : false;
845  }
846 
848  const octave_value& fval)
849  {
850  if (m_rep)
851  m_rep->install_subfunction (name, fval);
852  }
853 
855  const octave_value& fval,
856  const symbol_scope& fcn_scope)
857  {
858  if (m_rep)
859  m_rep->install_nestfunction (name, fval, fcn_scope);
860  }
861 
863  {
864  return m_rep ? m_rep->find_subfunction (name) : octave_value ();
865  }
866 
867  void lock_subfunctions (void)
868  {
869  if (m_rep)
870  m_rep->lock_subfunctions ();
871  }
872 
874  {
875  if (m_rep)
876  m_rep->unlock_subfunctions ();
877  }
878 
879  std::map<std::string, octave_value> subfunctions (void) const
880  {
881  return (m_rep
882  ? m_rep->subfunctions ()
883  : std::map<std::string, octave_value> ());
884  }
885 
886  void erase_subfunctions (void)
887  {
888  if (m_rep)
889  m_rep->erase_subfunctions ();
890  }
891 
893  {
894  if (m_rep)
895  m_rep->mark_subfunctions_in_scope_as_private (class_name);
896  }
897 
898  bool has_subfunctions (void) const
899  {
900  return m_rep ? m_rep->has_subfunctions () : false;
901  }
902 
903  void stash_subfunction_names (const std::list<std::string>& names)
904  {
905  if (m_rep)
906  m_rep->stash_subfunction_names (names);
907  }
908 
909  std::list<std::string> subfunction_names (void) const
910  {
911  return m_rep ? m_rep->subfunction_names () : std::list<std::string> ();
912  }
913 
914  octave_value dump (void) const
915  {
916  return m_rep ? m_rep->dump () : octave_value ();
917  }
918 
919  std::string name (void) const
920  {
921  return m_rep ? m_rep->name () : "";
922  }
923 
925  {
926  if (m_rep)
927  m_rep->cache_name (name);
928  }
929 
930  octave_user_function * function (void)
931  {
932  return m_rep ? m_rep->function () : nullptr;
933  }
934 
936  {
937  if (m_rep)
938  m_rep->set_function (fcn);
939  }
940 
941  void set_parent (const symbol_scope& p)
942  {
943  if (m_rep)
944  m_rep->set_parent (p.get_rep ());
945  }
946 
947  void update_nest (void)
948  {
949  if (m_rep)
950  m_rep->update_nest ();
951  }
952 
954  {
955  return m_rep ? m_rep->look_nonlocal (name, result) : false;
956  }
957 
958  void bind_script_symbols (const symbol_scope& curr_scope)
959  {
960  if (m_rep)
961  m_rep->bind_script_symbols (curr_scope.get_rep ());
962  }
963 
965  {
966  if (m_rep)
967  m_rep->unbind_script_symbols ();
968  }
969 
970  std::shared_ptr<symbol_scope_rep> get_rep (void) const
971  {
972  return m_rep;
973  }
974 
975  friend bool operator == (const symbol_scope& a, const symbol_scope& b)
976  {
977  return a.m_rep == b.m_rep;
978  }
979 
980  friend bool operator != (const symbol_scope& a, const symbol_scope& b)
981  {
982  return a.m_rep != b.m_rep;
983  }
984 
985  private:
986 
987  std::shared_ptr<symbol_scope_rep> m_rep;
988 
990  {
991  return m_rep ? m_rep->dump_symbols_map () : octave_value ();
992  }
993  };
994 }
995 
996 #endif
void mark_static(void)
Definition: symscope.h:92
void set_parent(const std::shared_ptr< symbol_scope_rep > &parent)
Definition: symscope.cc:167
octave_value varval(const std::string &name) const
Definition: symscope.h:231
void mark_global(const std::string &name)
Definition: symscope.h:801
void unbind_script_symbols(void)
Definition: symscope.h:964
void lock_subfunctions(void)
Definition: symscope.h:867
bool is_nested(void) const
Definition: symscope.h:631
void set_context(symbol_record::context_id context)
Definition: symscope.h:663
std::shared_ptr< symbol_scope_rep > parent_scope_rep(void) const
Definition: symscope.h:94
void stash_subfunction_names(const std::list< std::string > &names)
Definition: symscope.h:525
symbol_record::context_id current_context(void) const
Definition: symscope.h:117
symbol_record & insert(const std::string &name, bool force_add=false)
Definition: symscope.h:695
void bind_script_symbols(const std::shared_ptr< symbol_scope_rep > &curr_scope)
Definition: symscope.cc:229
octave_value dump(void) const
Definition: symscope.cc:113
bool is_global(void) const
Definition: symrec.h:653
void stash_subfunction_names(const std::list< std::string > &names)
Definition: symscope.h:903
void mark_static(void)
Definition: symscope.h:647
void mark_global(void)
Definition: symrec.h:677
void assign(const std::string &name, const octave_value &value, bool force_add)
Definition: symscope.h:707
void lock_subfunctions(void)
Definition: symscope.h:496
void unbind_script_symbols(void)
Definition: symscope.cc:237
void insert_symbol_record(const symbol_record &sr)
Definition: symscope.h:625
void inherit(const symbol_scope &donor_scope)
Definition: symscope.h:679
symbol_record::context_id m_context
Definition: symscope.h:597
void assign(const octave_value &value, context_id context)
Definition: symrec.h:592
void assign(const std::string &name, const octave_value &value=octave_value())
Definition: symscope.h:211
void mark_inherited(void)
Definition: symrec.h:664
bool look_nonlocal(const std::string &name, symbol_record &result)
Definition: symscope.h:953
octave_value find(const std::string &name, const octave_value_list &args, bool skip_variables, bool local_funcs)
Definition: symscope.cc:43
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:4986
void inherit(const std::shared_ptr< symbol_scope_rep > &donor_scope_rep)
Definition: symscope.h:158
void mark_subfunctions_in_scope_as_private(const std::string &class_name)
Definition: symscope.h:892
void inherit_internal(const std::shared_ptr< symbol_scope_rep > &donor_scope_rep)
Definition: symscope.h:133
symbol_record find_symbol(const std::string &name)
Definition: symscope.h:122
symbol_record find_symbol(const std::string &name)
Definition: symscope.h:674
symbol_scope_rep(const std::string &name="")
Definition: symscope.h:67
unsigned int storage_class(void) const
Definition: symrec.h:681
bool is_variable(context_id context) const
Definition: symrec.h:645
void erase_subfunctions(void)
Definition: symscope.h:513
symbol_scope dup(void) const
Definition: symscope.h:658
void bind_script_symbols(const symbol_scope &curr_scope)
Definition: symscope.h:958
bool is_static(void) const
Definition: symscope.h:90
std::vector< symbol_scope > m_children
Child nested functions.
Definition: symscope.h:587
symbol_scope(const std::string &name)
Definition: symscope.h:605
void rename(const std::string &old_name, const std::string &new_name)
Definition: symscope.h:180
void push_context(void)
Definition: symscope.h:255
void clear_variable(const std::string &name)
Definition: symscope.h:767
~symbol_scope(void)=default
void assign(const std::string &name, const octave_value &value=octave_value())
Definition: symscope.h:714
static llvm::LLVMContext & context
Definition: jit-typeinfo.cc:79
std::map< std::string, octave_value > m_subfunctions
Map from symbol names to subfunctions.
Definition: symscope.h:570
void install_nestfunction(const std::string &name, const octave_value &fval, const symbol_scope &fcn_scope)
Definition: symscope.h:854
octave_user_function * m_fcn
The associated user code (may be null).
Definition: symscope.h:579
std::map< std::string, symbol_record > m_symbols
Map from symbol names to symbol info.
Definition: symscope.h:566
void mark_automatic(const std::string &name)
Definition: symscope.h:785
void clear_variable_regexp(const std::string &pat)
Definition: symscope.h:779
bool has_subfunctions(void) const
Definition: symscope.h:520
void push_context(void)
Definition: symscope.h:737
void install_subfunction(const std::string &name, const octave_value &fval)
Definition: symscope.h:479
octave_function * fcn
Definition: ov-class.cc:1754
bool is_local_variable(const std::string &name) const
Definition: symscope.h:463
void mark_hidden(const std::string &name)
Definition: symscope.h:791
void pop_context(void)
Definition: symscope.h:743
std::map< std::string, symbol_record >::const_iterator table_const_iterator
Definition: symscope.h:58
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:400
bool is_global(const std::string &name) const
Definition: symscope.h:472
bool is_persistent(void) const
Definition: symrec.h:657
bool m_is_nested
If true, then this scope belongs to a nested function.
Definition: symscope.h:591
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov.h:1374
std::list< symbol_record > all_variables(bool defined_only=true, unsigned int exclude=symbol_record::hidden) const
Definition: symscope.h:808
std::string name(void) const
Definition: symscope.h:537
bool m_is_static
If true then no variables can be added.
Definition: symscope.h:595
void set_function(octave_user_function *fcn)
Definition: symscope.h:543
void cache_name(const std::string &name)
Definition: symscope.h:924
std::shared_ptr< symbol_scope_rep > parent_scope(void) const
Definition: symscope.h:653
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
Definition: utils.cc:975
void set_context(symbol_record::context_id context)
Definition: symscope.h:112
void clear(context_id context)
Definition: symrec.h:633
void pop_context(void)
Definition: symscope.h:261
std::list< std::string > subfunction_names(void) const
Definition: symscope.h:909
void mark_hidden(const std::string &name)
Definition: symscope.h:372
friend bool operator==(const symbol_scope &a, const symbol_scope &b)
Definition: symscope.h:975
std::string name(void) const
Definition: symrec.h:576
std::map< std::string, octave_value > subfunctions(void) const
Definition: symscope.h:879
std::list< symbol_record > glob(const std::string &pattern, bool vars_only=false) const
Definition: symscope.h:817
void refresh(void)
Definition: symscope.h:749
void insert_symbol_record(const symbol_record &sr)
Definition: symscope.h:81
void clear_objects(void)
Definition: symscope.h:761
symbol_record::context_id current_context(void) const
Definition: symscope.h:669
std::shared_ptr< symbol_scope_rep > dup(void) const
Definition: symscope.h:99
bool is_valid(void) const
Definition: symscope.h:621
bool match(const std::string &str) const
Definition: glob-match.cc:32
void unbind_global_rep(void)
Definition: symrec.h:689
std::list< symbol_record > glob(const std::string &pattern, bool vars_only=false) const
Definition: symscope.h:403
void mark_automatic(const std::string &name)
Definition: symscope.h:367
std::shared_ptr< symbol_scope_rep > get_rep(void) const
Definition: symscope.h:970
void clear_variables(void)
Definition: symscope.h:287
void clear_variables(void)
Definition: symscope.h:755
void clear_variable(const std::string &name)
Definition: symscope.h:304
std::list< symbol_record > regexp(const std::string &pattern, bool vars_only=false) const
Definition: symscope.h:426
octave_value find_subfunction(const std::string &name) const
Definition: symscope.h:862
octave_value dump_symbols_map(void) const
Definition: symscope.h:989
void erase_subfunctions(void)
Definition: symscope.h:886
is false
Definition: cellfun.cc:400
octave_value retval
Definition: data.cc:6246
bool is_forwarded(void) const
Definition: symrec.h:656
bool is_nested(void) const
Definition: symscope.h:86
std::list< symbol_record > all_variables(bool defined_only=true, unsigned int exclude=symbol_record::hidden) const
Definition: symscope.h:383
symbol_scope_rep & operator=(const symbol_scope &)=delete
void mark_hidden(void)
Definition: symrec.h:663
void rename(const std::string &old_name, const std::string &new_name)
Definition: symscope.h:701
std::list< std::string > subfunction_names(void) const
Definition: symscope.h:530
void force_assign(const std::string &name, const octave_value &value)
Definition: symscope.h:217
bool is_formal(void) const
Definition: symrec.h:652
void mark_nested(void)
Definition: symscope.h:636
bool is_variable(const std::string &name) const
Definition: symscope.h:239
std::list< std::string > variable_names(void)
Definition: symscope.h:448
bool is_automatic(void) const
Definition: symrec.h:651
bool is_match(const std::string &buffer)
Definition: lo-regexp.cc:430
bool is_static(void) const
Definition: symscope.h:642
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:190
void assign(const std::string &name, const octave_value &value, bool force_add)
Definition: symscope.h:196
void cache_name(const std::string &name)
Definition: symscope.h:539
octave_value varval(const std::string &name) const
Definition: symscope.h:727
With real return the complex result
Definition: data.cc:3260
void update_nest(void)
Definition: symscope.h:947
void clear_variable_pattern(const std::string &pat)
Definition: symscope.h:319
void mark_nested(void)
Definition: symscope.h:88
std::string m_name
Name for this scope (usually the corresponding filename of the function corresponding to the scope)...
Definition: symscope.h:562
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
void unlock_subfunctions(void)
Definition: symscope.h:502
symbol_record & insert(const std::string &name, bool force_add=false)
Definition: symscope.cc:88
void mark_global(const std::string &name)
Definition: symscope.h:377
bool is_variable(const std::string &name) const
Definition: symscope.h:732
void unlock_subfunctions(void)
Definition: symscope.h:873
bool has_subfunctions(void) const
Definition: symscope.h:898
std::weak_ptr< symbol_scope_rep > m_parent
Parent of nested function (may be null).
Definition: symscope.h:583
p
Definition: lu.cc:138
void force_assign(const std::string &name, const octave_value &value)
Definition: symscope.h:721
static const unsigned int hidden
Definition: symrec.h:60
void install_nestfunction(const std::string &name, const octave_value &fval, const symbol_scope &fcn_scope)
Definition: symscope.h:485
std::map< std::string, octave_value > subfunctions(void) const
Definition: symscope.h:508
void set_function(octave_user_function *fcn)
Definition: symscope.h:935
void mark_automatic(void)
Definition: symrec.h:661
b
Definition: cellfun.cc:400
bool is_defined(context_id context) const
Definition: symrec.h:635
std::map< std::string, octave_value >::const_iterator subfunctions_const_iterator
Definition: symscope.h:63
friend bool operator!=(const symbol_scope &a, const symbol_scope &b)
Definition: symscope.h:980
~symbol_scope_rep(void)=default
std::list< std::string > m_subfunction_names
The list of subfunctions (if any) in the order they appear in the function file.
Definition: symscope.h:575
std::map< std::string, symbol_record >::iterator table_iterator
Definition: symscope.h:60
void install_subfunction(const std::string &name, const octave_value &fval)
Definition: symscope.h:847
void rename(const std::string &new_name)
Definition: symrec.h:578
std::map< std::string, octave_value >::iterator subfunctions_iterator
Definition: symscope.h:65
octave_value varval(context_id context) const
Definition: symrec.h:624
octave_value dump(void) const
Definition: symscope.h:914
bool is_local_variable(const std::string &name) const
Definition: symscope.h:837
void set_parent(const symbol_scope &p)
Definition: symscope.h:941
octave_value find_subfunction(const std::string &name) const
Definition: symscope.cc:139
std::string name(void) const
Definition: symscope.h:919
void mark_subfunctions_in_scope_as_private(const std::string &class_name)
Definition: symscope.cc:155
bool is_global(const std::string &name) const
Definition: symscope.h:842
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:888
nd group nd example For each display the value
Definition: sysdep.cc:866
octave_value find(const std::string &name, const octave_value_list &args, bool skip_variables, bool local_funcs)
Definition: symscope.h:686
void clear_objects(void)
Definition: symscope.h:293
std::shared_ptr< symbol_scope_rep > m_rep
Definition: symscope.h:987
octave_value dump_symbols_map(void) const
Definition: symscope.cc:124
symbol_scope(const std::shared_ptr< symbol_scope_rep > new_rep=nullptr)
Definition: symscope.h:611
bool look_nonlocal(const std::string &name, symbol_record &result)
Definition: symscope.cc:207
void clear_variable_regexp(const std::string &pat)
Definition: symscope.h:343
std::list< std::string > variable_names(void)
Definition: symscope.h:832
void clear_variable_pattern(const std::string &pat)
Definition: symscope.h:773
symbol_scope & operator=(const symbol_scope &)=default
std::list< symbol_record > regexp(const std::string &pattern, bool vars_only=false) const
Definition: symscope.h:825