GNU Octave 7.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
stack-frame.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1995-2022 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if defined (HAVE_CONFIG_H)
27# include "config.h"
28#endif
29
30#include "lo-regexp.h"
31#include "str-vec.h"
32
33#include "defun.h"
34#include "interpreter.h"
35#include "interpreter-private.h"
36#include "oct-map.h"
37#include "ov.h"
38#include "ov-fcn.h"
39#include "ov-fcn-handle.h"
40#include "ov-usr-fcn.h"
41#include "pager.h"
42#include "parse.h"
43#include "pt-eval.h"
44#include "stack-frame.h"
45#include "syminfo.h"
46#include "symrec.h"
47#include "symscope.h"
48#include "variables.h"
49
50namespace octave
51{
53 {
54 public:
55
56 compiled_fcn_stack_frame (void) = delete;
57
59 std::size_t index,
60 const std::shared_ptr<stack_frame>& parent_link,
61 const std::shared_ptr<stack_frame>& static_link)
64 m_fcn (fcn)
65 { }
66
68
71
72 ~compiled_fcn_stack_frame (void) = default;
73
74 bool is_compiled_fcn_frame (void) const { return true; }
75
77 {
78 return m_static_link->get_scope ();
79 }
80
81 octave_function * function (void) const { return m_fcn; }
82
83 symbol_record lookup_symbol (const std::string& name) const
84 {
85 return m_static_link->lookup_symbol (name);
86 }
87
88 symbol_record insert_symbol (const std::string& name)
89 {
90 return m_static_link->insert_symbol (name);
91 }
92
94 {
95 // Look in closest stack frame that contains values (either the
96 // top scope, or a user-defined function or script).
97
98 return m_static_link->scope_flag (sym);
99 }
100
102 {
103 m_static_link->set_auto_fcn_var (avt, val);
104 }
105
107 {
108 return m_static_link->get_auto_fcn_var (avt);
109 }
110
111 // We only need to override one of each of these functions. The
112 // using declaration will avoid warnings about partially-overloaded
113 // virtual functions.
116
118 {
119 // Look in closest stack frame that contains values (either the
120 // top scope, or a user-defined function or script).
121
122 return m_static_link->varval (sym);
123 }
124
126 {
127 // Look in closest stack frame that contains values (either the
128 // top scope, or a user-defined function or script).
129
130 return m_static_link->varref (sym);
131 }
132
133 void mark_scope (const symbol_record& sym, scope_flags flag)
134 {
135 // Look in closest stack frame that contains values (either the
136 // top scope, or a user-defined function or script).
137
138 m_static_link->mark_scope (sym, flag);
139 }
140
141 void display (bool follow = true) const;
142
143 void accept (stack_frame_walker& sfw);
144
145 private:
146
147 // Compiled function object associated with this stack frame.
148 // Should always be a built-in, .oct or .mex file function and
149 // should always be valid.
151 };
152
153 // Scripts have a symbol_scope object to store the set of variables
154 // in the script, but values for those variables are stored in the
155 // stack frame corresponding to the nearest calling function or in
156 // the top-level scope (the evaluation stack frame).
157 //
158 // Accessing values in a scope requires a mapping from the index of
159 // the variable for the script scope to the list of values in the
160 // evaluation frame(s). The frame offset tells us how many access
161 // links we must follow to find the stack frame that holds the
162 // value. The value offset is the index into the vector of values
163 // in that stack frame that we should use to find the value.
164 //
165 // Frame and value offsets are set in this stack frame when it is
166 // created using information from the script and enclosing scopes.
167 //
168 // If a script is invoked in a nested function context, the frame
169 // offsets for individual values may be different. Some may be
170 // accessed from the invoking function and some may come from a
171 // parent function.
172
174 {
175 public:
176
177 script_stack_frame (void) = delete;
178
180 std::size_t index,
181 const std::shared_ptr<stack_frame>& parent_link,
182 const std::shared_ptr<stack_frame>& static_link);
183
185
187
189 {
191 }
192
193 bool is_user_script_frame (void) const { return true; }
194
195 static std::shared_ptr<stack_frame>
196 get_access_link (const std::shared_ptr<stack_frame>& static_link);
197
198 static std::size_t get_num_symbols (octave_user_script *script);
199
200 void set_script_offsets (void);
201
202 void set_script_offsets_internal (const std::map<std::string,
203 symbol_record>& symbols);
204
206
207 symbol_scope get_scope (void) const { return m_script->scope (); }
208
209 octave_function * function (void) const { return m_script; }
210
212
213 symbol_record lookup_symbol (const std::string& name) const;
214
215 symbol_record insert_symbol (const std::string&);
216
217 std::size_t size (void) const { return m_lexical_frame_offsets.size (); }
218
219 void resize (std::size_t size)
220 {
221 m_lexical_frame_offsets.resize (size, 0);
222 m_value_offsets.resize (size, 0);
223 }
224
226 std::size_t& frame_offset,
227 std::size_t& data_offset);
228
230 std::size_t& frame_offset,
231 std::size_t& data_offset) const;
232
233 bool get_val_offsets (const symbol_record& sym, std::size_t& frame_offset,
234 std::size_t& data_offset) const;
235
236 scope_flags scope_flag (const symbol_record& sym) const;
237
239 {
240 m_access_link->set_auto_fcn_var (avt, val);
241 }
242
244 {
245 return m_access_link->get_auto_fcn_var (avt);
246 }
247
248 // We only need to override one of each of these functions. The
249 // using declaration will avoid warnings about partially-overloaded
250 // virtual functions.
253
254 octave_value varval (const symbol_record& sym) const;
255
256 octave_value& varref (const symbol_record& sym);
257
258 void mark_scope (const symbol_record& sym, scope_flags flag);
259
260 void display (bool follow = true) const;
261
262 void accept (stack_frame_walker& sfw);
263
264 private:
265
266 // Script object associated with this stack frame. Should always
267 // be valid.
269
270 // The nearest unwind protect frame that was active when this
271 // stack frame was created. Should always be valid.
273
274 // Mapping between the symbols in the symbol_scope object of the
275 // script to the stack frame in which the script is executed. The
276 // frame offsets may be greater than one if the script is executed
277 // in a nested function context.
278
279 std::vector<std::size_t> m_lexical_frame_offsets;
280 std::vector<std::size_t> m_value_offsets;
281 };
282
283 // Base class for values and offsets shared by user_fcn and scope
284 // frames.
285
287 {
288 public:
289
290 base_value_stack_frame (void) = delete;
291
292 base_value_stack_frame (tree_evaluator& tw, std::size_t num_symbols,
293 std::size_t index,
294 const std::shared_ptr<stack_frame>& parent_link,
295 const std::shared_ptr<stack_frame>& static_link,
296 const std::shared_ptr<stack_frame>& access_link)
298 m_values (num_symbols, octave_value ()),
299 m_flags (num_symbols, LOCAL),
301 { }
302
304
307
308 ~base_value_stack_frame (void) = default;
309
310 std::size_t size (void) const
311 {
312 return m_values.size ();
313 }
314
315 void resize (std::size_t size)
316 {
317 m_values.resize (size, octave_value ());
318 m_flags.resize (size, LOCAL);
319 }
320
321 stack_frame::scope_flags get_scope_flag (std::size_t data_offset) const
322 {
323 return m_flags.at (data_offset);
324 }
325
326 void set_scope_flag (std::size_t data_offset, scope_flags flag)
327 {
328 m_flags.at (data_offset) = flag;
329 }
330
332 {
333 return m_auto_vars.at (avt);
334 }
335
337 {
338 m_auto_vars.at (avt) = val;
339 }
340
341 // We only need to override one of each of these functions. The
342 // using declaration will avoid warnings about partially-overloaded
343 // virtual functions.
346
347 octave_value varval (std::size_t data_offset) const
348 {
349 return m_values.at (data_offset);
350 }
351
352 octave_value& varref (std::size_t data_offset)
353 {
354 return m_values.at (data_offset);
355 }
356
357 void display (bool follow = true) const;
358
359 protected:
360
361 // Variable values. This array is indexed by the data_offset
362 // value stored in the symbol_record objects of the scope
363 // associated with this stack frame.
364 std::vector<octave_value> m_values;
365
366 // The type of each variable (local, global, persistent) of each
367 // value. This array is indexed by the data_offset value stored
368 // in the symbol_record objects of the scope associated with this
369 // stack frame. Local values are found in the M_VALUES array.
370 // Global values are stored in the tree_evaluator object that contains
371 // the stack frame. Persistent values are stored in the function
372 // scope corresponding to the stack frame.
373 std::vector<scope_flags> m_flags;
374
375 // A fixed list of Automatic variables created for this function.
376 // The elements of this vector correspond to the auto_var_type
377 // enum.
378 std::vector<octave_value> m_auto_vars;
379 };
380
381 // User-defined functions have a symbol_scope object to store the set
382 // of variables in the function and values are stored in the stack
383 // frame corresponding to the invocation of the function or one of
384 // its parents. The frame offset tells us how many access links we
385 // must follow to find the stack frame that holds the value. The
386 // value offset is the index into the vector of values in that stack
387 // frame that we should use to find the value.
388 //
389 // Frame and value offsets are determined when the corresponding
390 // function is parsed.
391
393 {
394 public:
395
396 user_fcn_stack_frame (void) = delete;
397
399 std::size_t index,
400 const std::shared_ptr<stack_frame>& parent_link,
401 const std::shared_ptr<stack_frame>& static_link,
402 const std::shared_ptr<stack_frame>& access_link = std::shared_ptr<stack_frame> ())
407 : get_access_link (fcn, static_link))),
408 m_fcn (fcn), m_unwind_protect_frame (nullptr)
409 { }
410
412 std::size_t index,
413 const std::shared_ptr<stack_frame>& parent_link,
414 const std::shared_ptr<stack_frame>& static_link,
415 const local_vars_map& local_vars,
416 const std::shared_ptr<stack_frame>& access_link = std::shared_ptr<stack_frame> ())
421 : get_access_link (fcn, static_link))),
422 m_fcn (fcn), m_unwind_protect_frame (nullptr)
423 {
424 // Initialize local variable values.
425
426 for (const auto& nm_ov : local_vars)
427 assign (nm_ov.first, nm_ov.second);
428 }
429
431
433 operator = (const user_fcn_stack_frame& elt) = delete;
434
436 {
438 }
439
440 bool is_user_fcn_frame (void) const { return true; }
441
442 static std::shared_ptr<stack_frame>
444 const std::shared_ptr<stack_frame>& static_link);
445
446 static std::size_t get_num_symbols (octave_user_function *fcn)
447 {
448 symbol_scope fcn_scope = fcn->scope ();
449
450 return fcn_scope.num_symbols ();
451 }
452
453 void clear_values (void);
454
455 symbol_scope get_scope (void) const { return m_fcn->scope (); }
456
457 octave_function * function (void) const { return m_fcn; }
458
460
461 symbol_record lookup_symbol (const std::string& name) const;
462
463 symbol_record insert_symbol (const std::string&);
464
465 scope_flags scope_flag (const symbol_record& sym) const;
466
467 // We only need to override one of each of these functions. The
468 // using declaration will avoid warnings about partially-overloaded
469 // virtual functions.
472
473 octave_value varval (const symbol_record& sym) const;
474
475 octave_value& varref (const symbol_record& sym);
476
477 void mark_scope (const symbol_record& sym, scope_flags flag);
478
479 void display (bool follow = true) const;
480
481 void accept (stack_frame_walker& sfw);
482
483 void break_closure_cycles (const std::shared_ptr<stack_frame>& frame);
484
485 private:
486
487 // User-defined object associated with this stack frame. Should
488 // always be valid.
490
491 // The nearest unwind protect frame that was active when this
492 // stack frame was created. Should always be valid.
494 };
495
496 // Pure scope stack frames (primarily the top-level workspace) have
497 // a set of variables and values are stored in the stack frame. All
498 // variable accesses are direct as there are no parent stack frames.
499 //
500 // Value offsets are determined when the corresponding variable is
501 // entered into the symbol_scope object corresponding to the frame.
502
504 {
505 public:
506
507 scope_stack_frame (void) = delete;
508
510 std::size_t index,
511 const std::shared_ptr<stack_frame>& parent_link,
512 const std::shared_ptr<stack_frame>& static_link)
513 : base_value_stack_frame (tw, scope.num_symbols (), index,
514 parent_link, static_link, nullptr),
515 m_scope (scope)
516 { }
517
518 scope_stack_frame (const scope_stack_frame& elt) = default;
519
521
522 ~scope_stack_frame (void) = default;
523
524 bool is_scope_frame (void) const { return true; }
525
526 symbol_scope get_scope (void) const { return m_scope; }
527
528 symbol_record lookup_symbol (const std::string& name) const
529 {
530 return m_scope.lookup_symbol (name);
531 }
532
533 symbol_record insert_symbol (const std::string&);
534
535 scope_flags scope_flag (const symbol_record& sym) const;
536
537 // We only need to override one of each of these functions. The
538 // using declaration will avoid warnings about partially-overloaded
539 // virtual functions.
542
543 octave_value varval (const symbol_record& sym) const;
544
545 octave_value& varref (const symbol_record& sym);
546
547 void mark_scope (const symbol_record& sym, scope_flags flag);
548
549 void display (bool follow = true) const;
550
551 void accept (stack_frame_walker& sfw);
552
553 private:
554
555 // The scope object associated with this stack frame.
557 };
558
559 // FIXME: There should probably be a display method for the script,
560 // fcn, and scope objects and the script and function objects should
561 // be responsible for displaying the scopes they contain.
562
563 static void display_scope (std::ostream& os, const symbol_scope& scope)
564 {
565 if (scope)
566 {
567 os << "scope: " << scope.name () << std::endl;
568
569 if (scope.num_symbols () > 0)
570 {
571 os << "name (frame offset, data offset, storage class):"
572 << std::endl;
573
574 std::list<symbol_record> symbols = scope.symbol_list ();
575
576 for (auto& sym : symbols)
577 {
578 os << " " << sym.name () << " (" << sym.frame_offset ()
579 << ", " << sym.data_offset () << ", " << sym.storage_class ()
580 << ")" << std::endl;
581 }
582 }
583 }
584 }
585
587 {
588 protected:
589
591
592 virtual ~stack_frame_walker (void) = default;
593
594 public:
595
596 // No copying!
597
599
601
602 virtual void
604
605 virtual void
607
608 virtual void
610
611 virtual void
613 };
614
616 {
617 public:
618
619 symbol_cleaner (const std::string& pattern, bool have_regexp = false)
620 : stack_frame_walker (), m_patterns (pattern),
621 m_clear_all_names (false), m_clear_objects (false),
622 m_have_regexp (have_regexp), m_cleared_names ()
623 { }
624
625 symbol_cleaner (const string_vector& patterns, bool have_regexp = false)
626 : stack_frame_walker (), m_patterns (patterns),
627 m_clear_all_names (false), m_clear_objects (false),
628 m_have_regexp (have_regexp), m_cleared_names ()
629 { }
630
631 symbol_cleaner (bool clear_all_names = true, bool clear_objects = false)
633 m_clear_all_names (clear_all_names), m_clear_objects (clear_objects),
635 { }
636
638
640
641 ~symbol_cleaner (void) = default;
642
644 {
645 // This one follows static link always. Hmm, should the access
646 // link for a compiled_fcn_stack_frame be the same as the static
647 // link?
648
649 std::shared_ptr<stack_frame> slink = frame.static_link ();
650
651 if (slink)
652 slink->accept (*this);
653 }
654
656 {
657 std::shared_ptr<stack_frame> alink = frame.access_link ();
658
659 if (alink)
660 alink->accept (*this);
661 }
662
664 {
665 clean_frame (frame);
666
667 std::shared_ptr<stack_frame> alink = frame.access_link ();
668
669 if (alink)
670 alink->accept (*this);
671 }
672
674 {
675 clean_frame (frame);
676
677 std::shared_ptr<stack_frame> alink = frame.access_link ();
678
679 if (alink)
680 alink->accept (*this);
681 }
682
683 private:
684
686 {
687 std::string name = sym.name ();
688
689 if (m_cleared_names.find (name) == m_cleared_names.end ())
690 {
691 // FIXME: Should we check that the name is defined and skip if
692 // it is not? Is it possible for another symbol with the same
693 // name to appear in a later stack frame?
694
695 // FIXME: If we are clearing objects and a symbol is found,
696 // should we add it to the list of cleared names (since
697 // we did find a symbol) but skip clearing the object?
698
699 if (m_clear_objects && ! frame.is_object (sym))
700 return;
701
702 m_cleared_names.insert (name);
703
704 frame.clear (sym);
705 }
706 }
707
708 // FIXME: It would be nice to avoid the duplication in the following
709 // function.
710
712 const std::list<symbol_record>& symbols)
713 {
715 {
716 for (const auto& sym : symbols)
717 maybe_clear_symbol (frame, sym);
718 }
719 else if (m_have_regexp)
720 {
721 octave_idx_type npatterns = m_patterns.numel ();
722
723 for (octave_idx_type j = 0; j < npatterns; j++)
724 {
725 std::string pattern = m_patterns[j];
726
727 regexp pat (pattern);
728
729 for (const auto& sym : symbols)
730 {
731 if (pat.is_match (sym.name ()))
732 maybe_clear_symbol (frame, sym);
733 }
734 }
735 }
736 else
737 {
738 octave_idx_type npatterns = m_patterns.numel ();
739
740 for (octave_idx_type j = 0; j < npatterns; j++)
741 {
742 std::string pattern = m_patterns[j];
743
744 glob_match pat (pattern);
745
746 for (const auto& sym : symbols)
747 {
748 if (pat.match (sym.name ()))
749 maybe_clear_symbol (frame, sym);
750 }
751 }
752 }
753 }
754
756 {
757 symbol_scope scope = frame.get_scope ();
758
759 std::list<symbol_record> symbols = scope.symbol_list ();
760
762 clear_symbols (frame, symbols);
763 }
764
766
770
771 std::set<std::string> m_cleared_names;
772 };
773
775 {
776 public:
777
778 symbol_info_accumulator (const std::string& pattern,
779 bool have_regexp = false)
780 : stack_frame_walker (), m_patterns (pattern), m_match_all (false),
781 m_first_only (false), m_have_regexp (have_regexp), m_sym_inf_list (),
783 { }
784
786 bool have_regexp = false)
787 : stack_frame_walker (), m_patterns (patterns), m_match_all (false),
788 m_first_only (false), m_have_regexp (have_regexp), m_sym_inf_list (),
790 { }
791
792 symbol_info_accumulator (bool match_all = true, bool first_only = true)
793 : stack_frame_walker (), m_patterns (), m_match_all (match_all),
794 m_first_only (first_only), m_have_regexp (false),
796 { }
797
799
801
802 ~symbol_info_accumulator (void) = default;
803
804 bool is_empty (void) const
805 {
806 for (const auto& nm_sil : m_sym_inf_list)
807 {
808 const symbol_info_list& lst = nm_sil.second;
809
810 if (! lst.empty ())
811 return false;
812 }
813
814 return true;
815 }
816
817 std::list<std::string> names (void) const
818 {
819 std::list<std::string> retval;
820
821 for (const auto& nm_sil : m_sym_inf_list)
822 {
823 const symbol_info_list& lst = nm_sil.second;
824
825 std::list<std::string> nm_list = lst.names ();
826
827 for (const auto& nm : nm_list)
828 retval.push_back (nm);
829 }
830
831 return retval;
832 }
833
835 {
836 symbol_info_list retval;
837
838 for (const auto& nm_sil : m_sym_inf_list)
839 {
840 const symbol_info_list& lst = nm_sil.second;
841
842 for (const auto& syminf : lst)
843 retval.push_back (syminf);
844 }
845
846 return retval;
847 }
848
850 {
851 octave_map retval;
852
853 // FIXME: is there a better way to concatenate structures?
854
855 std::size_t n_frames = m_sym_inf_list.size ();
856
857 OCTAVE_LOCAL_BUFFER (octave_map, map_list, n_frames);
858
859 std::size_t j = 0;
860 for (const auto& nm_sil : m_sym_inf_list)
861 {
862 std::string scope_name = nm_sil.first;
863 const symbol_info_list& lst = nm_sil.second;
864
865 map_list[j] = lst.map_value (scope_name, n_frames-j);
866
867 j++;
868 }
869
870 return octave_map::cat (-1, n_frames, map_list);
871 }
872
873 void display (std::ostream& os, const std::string& format) const
874 {
875 for (const auto& nm_sil : m_sym_inf_list)
876 {
877 os << "\nvariables in scope: " << nm_sil.first << "\n\n";
878
879 const symbol_info_list& lst = nm_sil.second;
880
881 lst.display (os, format);
882 }
883 }
884
886 {
887 // This one follows static link always. Hmm, should the access
888 // link for a compiled_fcn_stack_frame be the same as the static
889 // link?
890
891 std::shared_ptr<stack_frame> slink = frame.static_link ();
892
893 if (slink)
894 slink->accept (*this);
895 }
896
898 {
899 std::shared_ptr<stack_frame> alink = frame.access_link ();
900
901 if (alink)
902 alink->accept (*this);
903 }
904
906 {
907 append_list (frame);
908
909 std::shared_ptr<stack_frame> alink = frame.access_link ();
910
911 if (alink)
912 alink->accept (*this);
913 }
914
916 {
917 append_list (frame);
918
919 std::shared_ptr<stack_frame> alink = frame.access_link ();
920
921 if (alink)
922 alink->accept (*this);
923 }
924
925 private:
926
927 typedef std::pair<std::string, symbol_info_list> syminf_list_elt;
928
929 // FIXME: the following is too complex and duplicates too much
930 // code. Maybe it should be split up so we have separate classes
931 // that do each job that is needed?
932
933 std::list<symbol_record>
934 filter (stack_frame& frame, const std::list<symbol_record>& symbols)
935 {
936 std::list<symbol_record> new_symbols;
937
938 if (m_match_all)
939 {
940 for (const auto& sym : symbols)
941 {
942 if (frame.is_defined (sym))
943 {
944 std::string name = sym.name ();
945
946 if (m_first_only
947 && m_found_names.find (name) != m_found_names.end ())
948 continue;
949
950 m_found_names.insert (name);
951
952 new_symbols.push_back (sym);
953 }
954 }
955 }
956 else if (m_have_regexp)
957 {
958 octave_idx_type npatterns = m_patterns.numel ();
959
960 for (octave_idx_type j = 0; j < npatterns; j++)
961 {
962 std::string pattern = m_patterns[j];
963
964 regexp pat (pattern);
965
966 for (const auto& sym : symbols)
967 {
968 std::string name = sym.name ();
969
970 if (pat.is_match (name) && frame.is_defined (sym))
971 {
972 if (m_first_only
973 && m_found_names.find (name) != m_found_names.end ())
974 continue;
975
976 m_found_names.insert (name);
977
978 new_symbols.push_back (sym);
979 }
980 }
981 }
982 }
983 else
984 {
985 octave_idx_type npatterns = m_patterns.numel ();
986
987 for (octave_idx_type j = 0; j < npatterns; j++)
988 {
989 std::string pattern = m_patterns[j];
990
991 glob_match pat (pattern);
992
993 for (const auto& sym : symbols)
994 {
995 std::string name = sym.name ();
996
997 if (pat.match (name) && frame.is_defined (sym))
998 {
999 if (m_first_only
1000 && m_found_names.find (name) == m_found_names.end ())
1001 continue;
1002
1003 m_found_names.insert (name);
1004
1005 new_symbols.push_back (sym);
1006 }
1007 }
1008 }
1009 }
1010
1011 return new_symbols;
1012 }
1013
1015 {
1016 symbol_scope scope = frame.get_scope ();
1017
1018 std::list<symbol_record> symbols = scope.symbol_list ();
1019
1020 if (m_match_all || ! m_patterns.empty ())
1021 symbols = filter (frame, symbols);
1022
1023 symbol_info_list syminf_list = frame.make_symbol_info_list (symbols);
1024
1025 m_sym_inf_list.push_back (syminf_list_elt (scope.name (), syminf_list));
1026 }
1027
1029
1033
1034 std::list<std::pair<std::string, symbol_info_list>> m_sym_inf_list;
1035
1036 std::set<std::string> m_found_names;
1037 };
1038
1040 std::size_t index,
1041 const std::shared_ptr<stack_frame>& parent_link,
1042 const std::shared_ptr<stack_frame>& static_link)
1043 {
1044 return new compiled_fcn_stack_frame (tw, fcn, index, parent_link, static_link);
1045 }
1046
1048 octave_user_script *script,
1049 std::size_t index,
1050 const std::shared_ptr<stack_frame>& parent_link,
1051 const std::shared_ptr<stack_frame>& static_link)
1052 {
1053 return new script_stack_frame (tw, script, index, parent_link, static_link);
1054 }
1055
1057 octave_user_function *fcn, std::size_t index,
1058 const std::shared_ptr<stack_frame>& parent_link,
1059 const std::shared_ptr<stack_frame>& static_link,
1060 const std::shared_ptr<stack_frame>& access_link)
1061 {
1063 }
1064
1066 octave_user_function *fcn, std::size_t index,
1067 const std::shared_ptr<stack_frame>& parent_link,
1068 const std::shared_ptr<stack_frame>& static_link,
1069 const local_vars_map& local_vars,
1070 const std::shared_ptr<stack_frame>& access_link)
1071 {
1072 return new user_fcn_stack_frame (tw, fcn, index, parent_link, static_link, local_vars, access_link);
1073 }
1074
1076 const symbol_scope& scope, std::size_t index,
1077 const std::shared_ptr<stack_frame>& parent_link,
1078 const std::shared_ptr<stack_frame>& static_link)
1079 {
1080 return new scope_stack_frame (tw, scope, index, parent_link, static_link);
1081 }
1082
1083 // This function is only implemented and should only be called for
1084 // user_fcn stack frames. Anything else indicates an error in the
1085 // implementation, but we'll simply warn if that happens.
1086
1088 {
1089 warning ("invalid call to stack_frame::clear_values; please report");
1090 }
1091
1093 stack_frame::make_symbol_info_list (const std::list<symbol_record>& symrec_list) const
1094 {
1095 symbol_info_list symbol_stats;
1096
1097 for (const auto& sym : symrec_list)
1098 {
1099 octave_value value = varval (sym);
1100
1101 if (! value.is_defined ()
1102 || (is_user_fcn_frame () && sym.frame_offset () > 0))
1103 continue;
1104
1105 symbol_info syminf (sym.name (), value, sym.is_formal (),
1106 is_global (sym), is_persistent (sym));
1107
1108 symbol_stats.append (syminf);
1109 }
1110
1111 return symbol_stats;
1112 }
1113
1115 bool have_regexp, bool return_list,
1116 bool verbose, const std::string& whos_line_fmt,
1117 const std::string& msg)
1118 {
1119 symbol_info_accumulator sym_inf_accum (patterns, have_regexp);
1120
1121 accept (sym_inf_accum);
1122
1123 if (return_list)
1124 {
1125 if (verbose)
1126 return sym_inf_accum.map_value ();
1127 else
1128 return Cell (string_vector (sym_inf_accum.names ()));
1129 }
1130 else if (! sym_inf_accum.is_empty ())
1131 {
1132
1133 if (msg.empty ())
1134 octave_stdout << "Variables visible from the current scope:\n";
1135 else
1136 octave_stdout << msg;
1137
1138 if (verbose)
1139 sym_inf_accum.display (octave_stdout, whos_line_fmt);
1140 else
1141 {
1142 octave_stdout << "\n";
1143 string_vector names (sym_inf_accum.names ());
1145 }
1146
1147 octave_stdout << "\n";
1148 }
1149
1150 return octave_value ();
1151 }
1152
1153 // Return first occurrence of variables in current stack frame and any
1154 // parent frames reachable through access links.
1155
1157 {
1158 symbol_info_accumulator sia (true, true);
1159
1160 accept (sia);
1161
1162 return sia.symbol_info ();
1163 }
1164
1166 {
1167 std::list<octave_scalar_map> ws_list;
1168
1169 stack_frame *frame = this;
1170
1171 while (frame)
1172 {
1173 symbol_info_list symbols = frame->all_variables ();
1174
1176
1177 for (const auto& sym_name : symbols.names ())
1178 {
1179 octave_value val = symbols.varval (sym_name);
1180
1181 if (val.is_defined ())
1182 ws.assign (sym_name, val);
1183 }
1184
1185 ws_list.push_back (ws);
1186
1187 std::shared_ptr<stack_frame> nxt = frame->access_link ();
1188 frame = nxt.get ();
1189 }
1190
1191 Cell ws_frames (ws_list.size (), 1);
1192
1193 octave_idx_type i = 0;
1194 for (const auto& elt : ws_list)
1195 ws_frames(i++) = elt;
1196
1197 return ws_frames;
1198 }
1199
1200 // FIXME: Should this function also find any variables in parent
1201 // scopes accessible through access_links?
1202
1203 std::list<std::string> stack_frame::variable_names (void) const
1204 {
1205 std::list<std::string> retval;
1206
1207 symbol_scope scope = get_scope ();
1208
1209 const std::map<std::string, symbol_record>& symbols = scope.symbols ();
1210
1211 for (const auto& nm_sr : symbols)
1212 {
1213 if (is_variable (nm_sr.second))
1214 retval.push_back (nm_sr.first);
1215 }
1216
1217 retval.sort ();
1218
1219 return retval;
1220 }
1221
1223 {
1224 symbol_info_accumulator sia (pattern, false);
1225
1226 accept (sia);
1227
1228 return sia.symbol_info ();
1229 }
1230
1232 {
1233 symbol_info_accumulator sia (pattern, true);
1234
1235 accept (sia);
1236
1237 return sia.symbol_info ();
1238 }
1239
1240 std::size_t stack_frame::size (void) const
1241 {
1242 // This function should only be called for user_fcn_stack_frame or
1243 // scope_stack_frame objects. Anything else indicates an error in
1244 // the implementation.
1245
1247 }
1248
1249 void stack_frame::resize (std::size_t)
1250 {
1251 // This function should only be called for user_fcn_stack_frame or
1252 // scope_stack_frame objects. Anything else indicates an error in
1253 // the implementation.
1254
1256 }
1257
1259 {
1260 // This function should only be called for user_fcn_stack_frame or
1261 // scope_stack_frame objects. Anything else indicates an error in
1262 // the implementation.
1263
1265 }
1266
1268 {
1269 // This function should only be called for user_fcn_stack_frame or
1270 // scope_stack_frame objects. Anything else indicates an error in
1271 // the implementation.
1272
1274 }
1275
1277 const octave_value& value, bool global)
1278 {
1279 if (global && ! is_global (sym))
1280 {
1281 octave_value val = varval (sym);
1282
1283 if (val.is_defined ())
1284 {
1285 std::string nm = sym.name ();
1286
1287 warning_with_id ("Octave:global-local-conflict",
1288 "global: '%s' is defined in the current scope.\n",
1289 nm.c_str ());
1290 warning_with_id ("Octave:global-local-conflict",
1291 "global: in a future version, global variables must be declared before use.\n");
1292
1293 // If the symbol is defined in the local but not the
1294 // global scope, then use the local value as the
1295 // initial value. This value will also override any
1296 // initializer in the global statement.
1297 octave_value global_val = m_evaluator.global_varval (nm);
1298
1299 if (global_val.is_defined ())
1300 {
1301 warning_with_id ("Octave:global-local-conflict",
1302 "global: global value overrides existing local value");
1303
1304 clear (sym);
1305 }
1306 else
1307 {
1308 warning_with_id ("Octave:global-local-conflict",
1309 "global: existing local value used to initialize global variable");
1310
1311 m_evaluator.global_varref (nm) = val;
1312 }
1313 }
1314
1315 mark_global (sym);
1316 }
1317
1318 if (value.is_defined ())
1319 assign (sym, value);
1320 }
1321
1323 {
1324 // This function should only be called for user_fcn_stack_frame or
1325 // scope_stack_frame objects. Anything else indicates an error in
1326 // the implementation.
1327
1329 }
1330
1332 {
1333 // This function should only be called for user_fcn_stack_frame or
1334 // scope_stack_frame objects. Anything else indicates an error in
1335 // the implementation.
1336
1338 }
1339
1341 {
1342 symbol_cleaner sc (true, true);
1343
1344 accept (sc);
1345 }
1346
1347 void stack_frame::clear_variable (const std::string& name)
1348 {
1349 symbol_cleaner sc (name);
1350
1351 accept (sc);
1352 }
1353
1354 void stack_frame::clear_variable_pattern (const std::string& pattern)
1355 {
1356 symbol_cleaner sc (pattern);
1357
1358 accept (sc);
1359 }
1360
1362 {
1363 symbol_cleaner sc (patterns);
1364
1365 accept (sc);
1366 }
1367
1368 void stack_frame::clear_variable_regexp (const std::string& pattern)
1369 {
1370 symbol_cleaner sc (pattern, true);
1371
1372 accept (sc);
1373 }
1374
1376 {
1377 symbol_cleaner sc (patterns, true);
1378
1379 accept (sc);
1380 }
1381
1383 {
1384 symbol_cleaner sc;
1385
1386 accept (sc);
1387 }
1388
1389 void stack_frame::display_stopped_in_message (std::ostream& os) const
1390 {
1391 if (index () == 0)
1392 os << "at top level" << std::endl;
1393 else
1394 {
1395 os << "stopped in " << fcn_name ();
1396
1397 int l = line ();
1398 if (l > 0)
1399 os << " at line " << line ();
1400
1401 os << " [" << fcn_file_name () << "] " << std::endl;
1402 }
1403 }
1404
1405 void stack_frame::display (bool follow) const
1406 {
1407 std::ostream& os = octave_stdout;
1408
1409 os << "-- [stack_frame] (" << this << ") --" << std::endl;
1410
1411 os << "parent link: ";
1412 if (m_parent_link)
1413 os << m_parent_link.get ();
1414 else
1415 os << "NULL";
1416 os << std::endl;
1417
1418 os << "static link: ";
1419 if (m_static_link)
1420 os << m_static_link.get ();
1421 else
1422 os << "NULL";
1423 os << std::endl;
1424
1425 os << "access link: ";
1426 if (m_access_link)
1427 os << m_access_link.get ();
1428 else
1429 os << "NULL";
1430 os << std::endl;
1431
1432 os << "line: " << m_line << std::endl;
1433 os << "column: " << m_column << std::endl;
1434 os << "index: " << m_index << std::endl;
1435
1436 os << std::endl;
1437
1438 if (! follow)
1439 return;
1440
1441 os << "FOLLOWING ACCESS LINKS:" << std::endl;
1442 std::shared_ptr<stack_frame> frm = access_link ();
1443 while (frm)
1444 {
1445 frm->display (false);
1446 os << std::endl;
1447
1448 frm = frm->access_link ();
1449 }
1450 }
1451
1452 void compiled_fcn_stack_frame::display (bool follow) const
1453 {
1454 std::ostream& os = octave_stdout;
1455
1456 os << "-- [compiled_fcn_stack_frame] (" << this << ") --" << std::endl;
1457 stack_frame::display (follow);
1458
1459 os << "fcn: " << m_fcn->name ()
1460 << " (" << m_fcn->type_name () << ")" << std::endl;
1461 }
1462
1464 {
1466 }
1467
1469 octave_user_script *script,
1470 std::size_t index,
1471 const std::shared_ptr<stack_frame>& parent_link,
1472 const std::shared_ptr<stack_frame>& static_link)
1473 : stack_frame (tw, index, parent_link, static_link,
1474 get_access_link (static_link)),
1475 m_script (script), m_unwind_protect_frame (nullptr),
1476 m_lexical_frame_offsets (get_num_symbols (script), 1),
1477 m_value_offsets (get_num_symbols (script), 0)
1478 {
1480 }
1481
1483 {
1484 symbol_scope script_scope = script->scope ();
1485
1486 return script_scope.num_symbols ();
1487 }
1488
1490 {
1491 // Set frame and data offsets inside stack frame based on enclosing
1492 // scope(s).
1493
1494 symbol_scope script_scope = m_script->scope ();
1495
1496 std::size_t num_script_symbols = script_scope.num_symbols ();
1497
1498 resize (num_script_symbols);
1499
1500 const std::map<std::string, symbol_record>& script_symbols
1501 = script_scope.symbols ();
1502
1503 set_script_offsets_internal (script_symbols);
1504 }
1505
1507 (const std::map<std::string, symbol_record>& script_symbols)
1508 {
1509 // This scope will be used to evaluate the script. Find (or
1510 // possibly insert) symbols from the dummy script scope here.
1511
1512 symbol_scope eval_scope = m_access_link->get_scope ();
1513
1514 if (eval_scope.is_nested ())
1515 {
1516 bool found = false;
1517
1518 for (const auto& nm_sr : script_symbols)
1519 {
1520 std::string name = nm_sr.first;
1521 symbol_record script_sr = nm_sr.second;
1522
1523 symbol_scope parent_scope = eval_scope;
1524
1525 std::size_t count = 1;
1526
1527 while (parent_scope)
1528 {
1529 const std::map<std::string, symbol_record>& parent_scope_symbols
1530 = parent_scope.symbols ();
1531
1532 auto p = parent_scope_symbols.find (name);
1533
1534 if (p != parent_scope_symbols.end ())
1535 {
1536 found = true;
1537 symbol_record parent_scope_sr = p->second;
1538
1539 std::size_t script_sr_data_offset = script_sr.data_offset ();
1540
1541 m_lexical_frame_offsets.at (script_sr_data_offset)
1542 = parent_scope_sr.frame_offset () + count;
1543
1544 m_value_offsets.at (script_sr_data_offset)
1545 = parent_scope_sr.data_offset ();
1546
1547 break;
1548 }
1549 else
1550 {
1551 count++;
1552 parent_scope = parent_scope.parent_scope ();
1553 }
1554 }
1555
1556 if (! found)
1557 error ("symbol '%s' cannot be added to static scope",
1558 name.c_str ());
1559 }
1560 }
1561 else
1562 {
1563 const std::map<std::string, symbol_record>& eval_scope_symbols
1564 = eval_scope.symbols ();
1565
1566 for (const auto& nm_sr : script_symbols)
1567 {
1568 std::string name = nm_sr.first;
1569 symbol_record script_sr = nm_sr.second;
1570
1571 auto p = eval_scope_symbols.find (name);
1572
1573 symbol_record eval_scope_sr;
1574
1575 if (p == eval_scope_symbols.end ())
1576 eval_scope_sr = eval_scope.insert (name);
1577 else
1578 eval_scope_sr = p->second;
1579
1580 std::size_t script_sr_data_offset = script_sr.data_offset ();
1581
1582 // The +1 is for going from the script frame to the eval
1583 // frame. Only one access_link should need to be followed.
1584
1585 m_lexical_frame_offsets.at (script_sr_data_offset)
1586 = eval_scope_sr.frame_offset () + 1;
1587
1588 m_value_offsets.at (script_sr_data_offset)
1589 = eval_scope_sr.data_offset ();
1590 }
1591 }
1592 }
1593
1595 {
1596 std::size_t data_offset = sym.data_offset ();
1597
1598 // This function is called when adding new symbols to a script
1599 // scope. If the symbol wasn't present before, it should be outside
1600 // the range so we need to resize then update offsets.
1601
1602 assert (data_offset >= size ());
1603
1604 resize (data_offset+1);
1605
1606 // FIXME: We should be able to avoid creating the map object and the
1607 // looping in the set_scripts_offsets_internal function. Can we do
1608 // that without (or with minimal) code duplication?
1609
1610 std::map<std::string, symbol_record> tmp_symbols;
1611 tmp_symbols[sym.name ()] = sym;
1612 set_script_offsets_internal (tmp_symbols);
1613 }
1614
1615 // If this is a nested scope, set access_link to nearest parent
1616 // stack frame that corresponds to the lexical parent of this scope.
1617
1618 std::shared_ptr<stack_frame>
1619 script_stack_frame::get_access_link (const std::shared_ptr<stack_frame>& static_link)
1620 {
1621 // If this script is called from another script, set access
1622 // link to ultimate parent stack frame.
1623
1624 std::shared_ptr<stack_frame> alink = static_link;
1625
1626 while (alink->is_user_script_frame ())
1627 {
1628 if (alink->access_link ())
1629 alink = alink->access_link ();
1630 else
1631 break;
1632 }
1633
1634 return alink;
1635 }
1636
1638 {
1641
1643 }
1644
1646 {
1647 symbol_scope scope = get_scope ();
1648
1649 symbol_record sym = scope.lookup_symbol (name);
1650
1651 if (sym)
1652 {
1653 assert (sym.frame_offset () == 0);
1654
1655 return sym;
1656 }
1657
1658 sym = m_access_link->lookup_symbol (name);
1659
1660 // Return symbol record with adjusted frame offset.
1661 symbol_record new_sym = sym.dup ();
1662
1663 new_sym.set_frame_offset (sym.frame_offset () + 1);
1664
1665 return new_sym;
1666 }
1667
1669 {
1670 // If the symbols is already in the immediate scope, there is
1671 // nothing more to do.
1672
1673 symbol_scope scope = get_scope ();
1674
1675 symbol_record sym = scope.lookup_symbol (name);
1676
1677 if (sym)
1678 {
1679 // All symbol records in a script scope should have zero offset,
1680 // which means we redirect our lookup using
1681 // lexical_frame_offsets and values_offets.
1682 assert (sym.frame_offset () == 0);
1683
1684 return sym;
1685 }
1686
1687 // Insert the symbol in the current scope then resize and update
1688 // offsets. This operation should never fail.
1689
1690 sym = scope.find_symbol (name);
1691
1692 assert (sym);
1693
1695
1696 return sym;
1697 }
1698
1699 // Similar to set_script_offsets_internal except that we only return
1700 // frame and data offsets for symbols found by name in parent scopes
1701 // instead of updating the offsets stored in the script frame itself.
1702
1703 bool
1705 std::size_t& frame_offset,
1706 std::size_t& data_offset) const
1707 {
1708 bool found = false;
1709
1710 // This scope will be used to evaluate the script. Find symbols
1711 // here by name.
1712
1713 symbol_scope eval_scope = m_access_link->get_scope ();
1714
1715 if (eval_scope.is_nested ())
1716 {
1717 std::string name = script_sr.name ();
1718
1719 symbol_scope parent_scope = eval_scope;
1720
1721 std::size_t count = 1;
1722
1723 while (parent_scope)
1724 {
1725 const std::map<std::string, symbol_record>& parent_scope_symbols
1726 = parent_scope.symbols ();
1727
1728 auto p = parent_scope_symbols.find (name);
1729
1730 if (p != parent_scope_symbols.end ())
1731 {
1732 found = true;
1733 symbol_record parent_scope_sr = p->second;
1734
1735 frame_offset = parent_scope_sr.frame_offset () + count;
1736
1737 data_offset = parent_scope_sr.data_offset ();
1738
1739 break;
1740 }
1741 else
1742 {
1743 count++;
1744 parent_scope = parent_scope.parent_scope ();
1745 }
1746 }
1747 }
1748 else
1749 {
1750 const std::map<std::string, symbol_record>& eval_scope_symbols
1751 = eval_scope.symbols ();
1752
1753 std::string name = script_sr.name ();
1754
1755 auto p = eval_scope_symbols.find (name);
1756
1757 symbol_record eval_scope_sr;
1758
1759 if (p != eval_scope_symbols.end ())
1760 {
1761 found = true;
1762 eval_scope_sr = p->second;
1763
1764 // The +1 is for going from the script frame to the eval
1765 // frame. Only one access_link should need to be followed.
1766
1767 frame_offset = eval_scope_sr.frame_offset () + 1;
1768
1769 data_offset = eval_scope_sr.data_offset ();
1770 }
1771 }
1772
1773 return found;
1774 }
1775
1777 std::size_t& frame_offset,
1778 std::size_t& data_offset) const
1779 {
1780 data_offset = sym.data_offset ();
1781 frame_offset = sym.frame_offset ();
1782
1783 if (frame_offset == 0)
1784 {
1785 // An out of range data_offset value here means that we have a
1786 // symbol that was not originally in the script. But this
1787 // function is called in places where we can't insert a new
1788 // symbol, so we fail and it is up to the caller to decide what
1789 // to do.
1790
1791 if (data_offset >= size ())
1792 return get_val_offsets_internal (sym, frame_offset, data_offset);
1793
1794 // Use frame and value offsets stored in this stack frame,
1795 // indexed by data_offset from the symbol_record to find the
1796 // values. These offsets were determined by
1797 // script_stack_frame::set_script_offsets when this script was
1798 // invoked.
1799
1800 frame_offset = m_lexical_frame_offsets.at (data_offset);
1801
1802 if (frame_offset == 0)
1803 {
1804 // If the frame offset stored in m_lexical_frame_offsets is
1805 // zero, then the data offset in the evaluation scope has
1806 // not been determined so try to do that now. The symbol
1807 // may have been added by eval and without calling
1808 // resize_and_update_script_offsets.
1809
1810 return get_val_offsets_internal (sym, frame_offset, data_offset);
1811 }
1812
1813 data_offset = m_value_offsets.at (data_offset);
1814 }
1815 else
1816 {
1817 // If frame_offset is not zero, then then we must have a symbol
1818 // that was not originally in the script. The values should
1819 // have been determined by the script_stack_frame::lookup function.
1820 }
1821
1822 return true;
1823 }
1824
1826 std::size_t& frame_offset,
1827 std::size_t& data_offset)
1828 {
1829 data_offset = sym.data_offset ();
1830 frame_offset = sym.frame_offset ();
1831
1832 if (frame_offset == 0)
1833 {
1834 if (data_offset >= size ())
1835 {
1836 // If the data_offset is out of range, then we must have a
1837 // symbol that was not originally in the script. Resize and
1838 // update the offsets.
1839
1841 }
1842
1843 // Use frame and value offsets stored in this stack frame,
1844 // indexed by data_offset from the symbol_record to find the
1845 // values. These offsets were determined by
1846 // script_stack_frame::set_script_offsets when this script was
1847 // invoked.
1848
1849 frame_offset = m_lexical_frame_offsets.at (data_offset);
1850
1851 if (frame_offset == 0)
1852 {
1853 // If the frame offset stored in m_lexical_frame_offsets is
1854 // zero, then the data offset in the evaluation scope has
1855 // not been determined so try to do that now. The symbol
1856 // may have been added by eval and without calling
1857 // resize_and_update_script_offsets.
1858
1859 // We don't need to resize here. That case is handled above.
1860
1861 // FIXME: We should be able to avoid creating the map object
1862 // and the looping in the set_scripts_offsets_internal
1863 // function. Can we do that without (or with minimal) code
1864 // duplication?
1865
1866 std::map<std::string, symbol_record> tmp_symbols;
1867 tmp_symbols[sym.name ()] = sym;
1868 set_script_offsets_internal (tmp_symbols);
1869
1870 // set_script_offsets_internal may have modified
1871 // m_lexical_frame_offsets and m_value_offsets.
1872
1873 frame_offset = m_lexical_frame_offsets.at (data_offset);
1874 }
1875
1876 data_offset = m_value_offsets.at (data_offset);
1877 }
1878 else
1879 {
1880 // If frame_offset is not zero, then then we must have a symbol
1881 // that was not originally in the script. The values were
1882 // determined by the script_stack_frame::lookup function.
1883 }
1884 }
1885
1888 {
1889 std::size_t frame_offset;
1890 std::size_t data_offset;
1891
1892 bool found = get_val_offsets (sym, frame_offset, data_offset);
1893
1894 // It can't be global or persistent, so call it local.
1895 if (! found)
1896 return LOCAL;
1897
1898 // Follow frame_offset access links to stack frame that holds
1899 // the value.
1900
1901 const stack_frame *frame = this;
1902
1903 for (std::size_t i = 0; i < frame_offset; i++)
1904 {
1905 std::shared_ptr<stack_frame> nxt = frame->access_link ();
1906 frame = nxt.get ();
1907 }
1908
1909 if (! frame)
1910 error ("internal error: invalid access link in function call stack");
1911
1912 if (data_offset >= frame->size ())
1913 return LOCAL;
1914
1915 return frame->get_scope_flag (data_offset);
1916 }
1917
1919 {
1920 std::size_t frame_offset;
1921 std::size_t data_offset;
1922
1923 bool found = get_val_offsets (sym, frame_offset, data_offset);
1924
1925 if (! found)
1926 return octave_value ();
1927
1928 // Follow frame_offset access links to stack frame that holds
1929 // the value.
1930
1931 const stack_frame *frame = this;
1932
1933 for (std::size_t i = 0; i < frame_offset; i++)
1934 {
1935 std::shared_ptr<stack_frame> nxt = frame->access_link ();
1936 frame = nxt.get ();
1937 }
1938
1939 if (! frame)
1940 error ("internal error: invalid access link in function call stack");
1941
1942 if (data_offset >= frame->size ())
1943 return octave_value ();
1944
1945 switch (frame->get_scope_flag (data_offset))
1946 {
1947 case LOCAL:
1948 return frame->varval (data_offset);
1949
1950 case PERSISTENT:
1951 {
1952 symbol_scope scope = frame->get_scope ();
1953
1954 return scope.persistent_varval (data_offset);
1955 }
1956
1957 case GLOBAL:
1958 return m_evaluator.global_varval (sym.name ());
1959 }
1960
1961 error ("internal error: invalid switch case");
1962 }
1963
1965 {
1966 std::size_t frame_offset;
1967 std::size_t data_offset;
1968 get_val_offsets_with_insert (sym, frame_offset, data_offset);
1969
1970 // Follow frame_offset access links to stack frame that holds
1971 // the value.
1972
1973 stack_frame *frame = this;
1974
1975 for (std::size_t i = 0; i < frame_offset; i++)
1976 {
1977 std::shared_ptr<stack_frame> nxt = frame->access_link ();
1978 frame = nxt.get ();
1979 }
1980
1981 if (data_offset >= frame->size ())
1982 frame->resize (data_offset+1);
1983
1984 switch (frame->get_scope_flag (data_offset))
1985 {
1986 case LOCAL:
1987 return frame->varref (data_offset);
1988
1989 case PERSISTENT:
1990 {
1991 symbol_scope scope = frame->get_scope ();
1992
1993 return scope.persistent_varref (data_offset);
1994 }
1995
1996 case GLOBAL:
1997 return m_evaluator.global_varref (sym.name ());
1998 }
1999
2000 error ("internal error: invalid switch case");
2001 }
2002
2004 scope_flags flag)
2005 {
2006 std::size_t data_offset = sym.data_offset ();
2007
2008 if (data_offset >= size ())
2010
2011 // Redirection to evaluation context for the script.
2012
2013 std::size_t frame_offset = m_lexical_frame_offsets.at (data_offset);
2014 data_offset = m_value_offsets.at (data_offset);
2015
2016 if (frame_offset > 1)
2017 error ("variables must be made PERSISTENT or GLOBAL in the first scope in which they are used");
2018
2019 std::shared_ptr<stack_frame> frame = access_link ();
2020
2021 if (data_offset >= frame->size ())
2022 frame->resize (data_offset+1);
2023
2024 frame->set_scope_flag (data_offset, flag);
2025 }
2026
2027 void script_stack_frame::display (bool follow) const
2028 {
2029 std::ostream& os = octave_stdout;
2030
2031 os << "-- [script_stack_frame] (" << this << ") --" << std::endl;
2032 stack_frame::display (follow);
2033
2034 os << "script: " << m_script->name ()
2035 << " (" << m_script->type_name () << ")" << std::endl;
2036
2037 os << "lexical_offsets: " << m_lexical_frame_offsets.size ()
2038 << " elements:";
2039
2040 for (std::size_t i = 0; i < m_lexical_frame_offsets.size (); i++)
2041 os << " " << m_lexical_frame_offsets.at (i);
2042 os << std::endl;
2043
2044 os << "value_offsets: " << m_value_offsets.size () << " elements:";
2045 for (std::size_t i = 0; i < m_value_offsets.size (); i++)
2046 os << " " << m_value_offsets.at (i);
2047 os << std::endl;
2048
2049 display_scope (os, get_scope ());
2050 }
2051
2053 {
2054 sfw.visit_script_stack_frame (*this);
2055 }
2056
2057 void base_value_stack_frame::display (bool follow) const
2058 {
2059 std::ostream& os = octave_stdout;
2060
2061 os << "-- [base_value_stack_frame] (" << this << ") --" << std::endl;
2062 stack_frame::display (follow);
2063
2064 os << "values: " << m_values.size ()
2065 << " elements (idx, scope flag, type):" << std::endl;
2066
2067 for (std::size_t i = 0; i < m_values.size (); i++)
2068 {
2069 os << " (" << i << ", " << m_flags.at (i) << ", ";
2070
2071 octave_value val = varval (i);
2072
2073 os << (val.is_defined () ? val.type_name () : " UNDEFINED") << ")"
2074 << std::endl;
2075 }
2076 }
2077
2078 // If this is a nested scope, set access_link to nearest parent
2079 // stack frame that corresponds to the lexical parent of this scope.
2080
2081 std::shared_ptr<stack_frame>
2083 const std::shared_ptr<stack_frame>& static_link)
2084 {
2085 std::shared_ptr<stack_frame> alink;
2086
2087 symbol_scope fcn_scope = fcn->scope ();
2088
2089 if (fcn_scope.is_nested ())
2090 {
2091 if (! static_link)
2092 error ("internal call stack error (invalid static link)");
2093
2094 symbol_scope caller_scope = static_link->get_scope ();
2095
2096 int nesting_depth = fcn_scope.nesting_depth ();
2097 int caller_nesting_depth = caller_scope.nesting_depth ();
2098
2099 if (caller_nesting_depth < nesting_depth)
2100 {
2101 // FIXME: do we need to ensure that the called
2102 // function is a child of the caller? Does it hurt
2103 // to assert this condition, at least for now?
2104
2105 alink = static_link;
2106 }
2107 else
2108 {
2109 // FIXME: do we need to check that the parent of the
2110 // called function is also a parent of the caller?
2111 // Does it hurt to assert this condition, at least
2112 // for now?
2113
2114 int links_to_follow = caller_nesting_depth - nesting_depth + 1;
2115
2116 alink = static_link;
2117
2118 while (alink && --links_to_follow >= 0)
2119 alink = alink->access_link ();
2120
2121 if (! alink)
2122 error ("internal function nesting error (invalid access link)");
2123 }
2124 }
2125
2126 return alink;
2127 }
2128
2130 {
2131 symbol_scope fcn_scope = m_fcn->scope ();
2132
2133 const std::list<symbol_record>& symbols = fcn_scope.symbol_list ();
2134
2135 if (size () == 0)
2136 return;
2137
2138 for (const auto& sym : symbols)
2139 {
2140 std::size_t frame_offset = sym.frame_offset ();
2141
2142 if (frame_offset > 0)
2143 continue;
2144
2145 std::size_t data_offset = sym.data_offset ();
2146
2147 if (data_offset >= size ())
2148 continue;
2149
2150 if (get_scope_flag (data_offset) == LOCAL)
2151 {
2152 octave_value& ref = m_values.at (data_offset);
2153
2154 if (ref.get_count () == 1)
2155 {
2157 ref = octave_value ();
2158 }
2159 }
2160 }
2161 }
2162
2164 {
2167
2169 }
2170
2172 {
2173 const stack_frame *frame = this;
2174
2175 while (frame)
2176 {
2177 symbol_scope scope = frame->get_scope ();
2178
2179 symbol_record sym = scope.lookup_symbol (name);
2180
2181 if (sym)
2182 return sym;
2183
2184 std::shared_ptr<stack_frame> nxt = frame->access_link ();
2185 frame = nxt.get ();
2186 }
2187
2188 return symbol_record ();
2189 }
2190
2192 {
2193 // If the symbols is already in the immediate scope, there is
2194 // nothing more to do.
2195
2196 symbol_scope scope = get_scope ();
2197
2198 symbol_record sym = scope.lookup_symbol (name);
2199
2200 if (sym)
2201 return sym;
2202
2203 // FIXME: This needs some thought... We may need to add a symbol to
2204 // a static workspace, but the symbol can never be defined as a
2205 // variable. This currently works by tagging the added symbol as
2206 // "added_static". Aside from the bad name, this doesn't seem like
2207 // the best solution. Maybe scopes should have a separate set of
2208 // symbols that may only be defined as functions?
2209
2210 // Insert the symbol in the current scope. This is not possible for
2211 // anonymous functions, nested functions, or functions that contain
2212 // nested functions (their scopes will all be marked static).
2213
2214 // if (scope.is_static ())
2215 // error ("can not add variable '%s' to a static workspace",
2216 // name.c_str ());
2217
2218 // At this point, non-local references are not possible so we only
2219 // need to look in the current scope and insert there. This
2220 // operation should never fail.
2221
2222 sym = scope.find_symbol (name);
2223
2224 assert (sym);
2225
2226 return sym;
2227 }
2228
2231 {
2232 std::size_t frame_offset = sym.frame_offset ();
2233 std::size_t data_offset = sym.data_offset ();
2234
2235 // Follow frame_offset access links to stack frame that holds
2236 // the value.
2237
2238 const stack_frame *frame = this;
2239
2240 for (std::size_t i = 0; i < frame_offset; i++)
2241 {
2242 std::shared_ptr<stack_frame> nxt = frame->access_link ();
2243 frame = nxt.get ();
2244 }
2245
2246 if (! frame)
2247 error ("internal error: invalid access link in function call stack");
2248
2249 if (data_offset >= frame->size ())
2250 return LOCAL;
2251
2252 return frame->get_scope_flag (data_offset);
2253 }
2254
2256 {
2257 std::size_t frame_offset = sym.frame_offset ();
2258 std::size_t data_offset = sym.data_offset ();
2259
2260 // Follow frame_offset access links to stack frame that holds
2261 // the value.
2262
2263 const stack_frame *frame = this;
2264
2265 for (std::size_t i = 0; i < frame_offset; i++)
2266 {
2267 std::shared_ptr<stack_frame> nxt = frame->access_link ();
2268 frame = nxt.get ();
2269 }
2270
2271 if (! frame)
2272 error ("internal error: invalid access link in function call stack");
2273
2274 if (data_offset >= frame->size ())
2275 return octave_value ();
2276
2277 switch (frame->get_scope_flag (data_offset))
2278 {
2279 case LOCAL:
2280 return frame->varval (data_offset);
2281
2282 case PERSISTENT:
2283 {
2284 symbol_scope scope = frame->get_scope ();
2285
2286 return scope.persistent_varval (data_offset);
2287 }
2288
2289 case GLOBAL:
2290 return m_evaluator.global_varval (sym.name ());
2291 }
2292
2293 error ("internal error: invalid switch case");
2294 }
2295
2297 {
2298 std::size_t frame_offset = sym.frame_offset ();
2299 std::size_t data_offset = sym.data_offset ();
2300
2301 // Follow frame_offset access links to stack frame that holds
2302 // the value.
2303
2304 stack_frame *frame = this;
2305
2306 for (std::size_t i = 0; i < frame_offset; i++)
2307 {
2308 std::shared_ptr<stack_frame> nxt = frame->access_link ();
2309 frame = nxt.get ();
2310 }
2311
2312 if (data_offset >= frame->size ())
2313 frame->resize (data_offset+1);
2314
2315 switch (frame->get_scope_flag (data_offset))
2316 {
2317 case LOCAL:
2318 return frame->varref (data_offset);
2319
2320 case PERSISTENT:
2321 {
2322 symbol_scope scope = frame->get_scope ();
2323
2324 return scope.persistent_varref (data_offset);
2325 }
2326
2327 case GLOBAL:
2328 return m_evaluator.global_varref (sym.name ());
2329 }
2330
2331 error ("internal error: invalid switch case");
2332 }
2333
2335 {
2336 std::size_t frame_offset = sym.frame_offset ();
2337
2338 if (frame_offset > 0 && (flag == PERSISTENT || flag == GLOBAL))
2339 error ("variables must be made PERSISTENT or GLOBAL in the first scope in which they are used");
2340
2341 std::size_t data_offset = sym.data_offset ();
2342
2343 if (data_offset >= size ())
2344 resize (data_offset+1);
2345
2346 set_scope_flag (data_offset, flag);
2347 }
2348
2349 void user_fcn_stack_frame::display (bool follow) const
2350 {
2351 std::ostream& os = octave_stdout;
2352
2353 os << "-- [user_fcn_stack_frame] (" << this << ") --" << std::endl;
2355
2356 os << "fcn: " << m_fcn->name ()
2357 << " (" << m_fcn->type_name () << ")" << std::endl;
2358
2359 display_scope (os, get_scope ());
2360 }
2361
2363 {
2364 sfw.visit_user_fcn_stack_frame (*this);
2365 }
2366
2367 void user_fcn_stack_frame::break_closure_cycles (const std::shared_ptr<stack_frame>& frame)
2368 {
2369 for (auto& val : m_values)
2370 val.break_closure_cycles (frame);
2371
2372 if (m_access_link)
2373 m_access_link->break_closure_cycles (frame);
2374 }
2375
2377 {
2378 // There is no access link for scope frames, so there is no other
2379 // frame to search in and the offset must be zero.
2380
2382
2383 if (sym)
2384 return sym;
2385
2386 // If the symbol is not found, insert it. We only need to search in
2387 // the local scope object. This operation should never fail.
2388
2389 sym = m_scope.find_symbol (name);
2390
2391 assert (sym);
2392
2393 return sym;
2394 }
2395
2398 {
2399 // There is no access link for scope frames, so the frame
2400 // offset must be zero.
2401
2402 std::size_t data_offset = sym.data_offset ();
2403
2404 if (data_offset >= size ())
2405 return LOCAL;
2406
2407 return get_scope_flag (data_offset);
2408 }
2409
2411 {
2412 // There is no access link for scope frames, so the frame
2413 // offset must be zero.
2414
2415 std::size_t data_offset = sym.data_offset ();
2416
2417 if (data_offset >= size ())
2418 return octave_value ();
2419
2420 switch (get_scope_flag (data_offset))
2421 {
2422 case LOCAL:
2423 return m_values.at (data_offset);
2424
2425 case PERSISTENT:
2426 return m_scope.persistent_varval (data_offset);
2427
2428 case GLOBAL:
2429 return m_evaluator.global_varval (sym.name ());
2430 }
2431
2432 error ("internal error: invalid switch case");
2433 }
2434
2436 {
2437 // There is no access link for scope frames, so the frame
2438 // offset must be zero.
2439
2440 std::size_t data_offset = sym.data_offset ();
2441
2442 if (data_offset >= size ())
2443 resize (data_offset+1);
2444
2445 switch (get_scope_flag (data_offset))
2446 {
2447 case LOCAL:
2448 return m_values.at (data_offset);
2449
2450 case PERSISTENT:
2451 return m_scope.persistent_varref (data_offset);
2452
2453 case GLOBAL:
2454 return m_evaluator.global_varref (sym.name ());
2455 }
2456
2457 error ("internal error: invalid switch case");
2458 }
2459
2461 scope_flags flag)
2462 {
2463 // There is no access link for scope frames, so the frame
2464 // offset must be zero.
2465
2466 std::size_t data_offset = sym.data_offset ();
2467
2468 if (data_offset >= size ())
2469 resize (data_offset+1);
2470
2471 set_scope_flag (data_offset, flag);
2472 }
2473
2474 void scope_stack_frame::display (bool follow) const
2475 {
2476 std::ostream& os = octave_stdout;
2477
2478 os << "-- [scope_stack_frame] (" << this << ") --" << std::endl;
2480
2481 display_scope (os, m_scope);
2482 }
2483
2485 {
2486 sfw.visit_scope_stack_frame (*this);
2487 }
2488}
Definition: Cell.h:43
bool match(const std::string &str) const
Definition: glob-match.cc:35
void append(const elt_type &s)
Definition: base-list.h:92
bool empty(void) const
Definition: base-list.h:50
void push_back(const elt_type &s)
Definition: base-list.h:86
void resize(std::size_t size)
Definition: stack-frame.cc:315
stack_frame::scope_flags get_scope_flag(std::size_t data_offset) const
Definition: stack-frame.cc:321
base_value_stack_frame(tree_evaluator &tw, std::size_t num_symbols, std::size_t index, const std::shared_ptr< stack_frame > &parent_link, const std::shared_ptr< stack_frame > &static_link, const std::shared_ptr< stack_frame > &access_link)
Definition: stack-frame.cc:292
void set_scope_flag(std::size_t data_offset, scope_flags flag)
Definition: stack-frame.cc:326
void display(bool follow=true) const
octave_value get_auto_fcn_var(auto_var_type avt) const
Definition: stack-frame.cc:331
octave_value varval(std::size_t data_offset) const
Definition: stack-frame.cc:347
std::vector< scope_flags > m_flags
Definition: stack-frame.cc:373
std::vector< octave_value > m_values
Definition: stack-frame.cc:364
std::vector< octave_value > m_auto_vars
Definition: stack-frame.cc:378
base_value_stack_frame & operator=(const base_value_stack_frame &elt)=delete
std::size_t size(void) const
Definition: stack-frame.cc:310
octave_value & varref(std::size_t data_offset)
Definition: stack-frame.cc:352
base_value_stack_frame(const base_value_stack_frame &elt)=default
void set_auto_fcn_var(auto_var_type avt, const octave_value &val)
Definition: stack-frame.cc:336
~base_value_stack_frame(void)=default
compiled_fcn_stack_frame & operator=(const compiled_fcn_stack_frame &elt)=delete
bool is_compiled_fcn_frame(void) const
Definition: stack-frame.cc:74
void display(bool follow=true) const
symbol_record insert_symbol(const std::string &name)
Definition: stack-frame.cc:88
symbol_record lookup_symbol(const std::string &name) const
Definition: stack-frame.cc:83
stack_frame::scope_flags scope_flag(const symbol_record &sym) const
Definition: stack-frame.cc:93
void mark_scope(const symbol_record &sym, scope_flags flag)
Definition: stack-frame.cc:133
compiled_fcn_stack_frame(const compiled_fcn_stack_frame &elt)=default
void set_auto_fcn_var(auto_var_type avt, const octave_value &val)
Definition: stack-frame.cc:101
octave_value varval(const symbol_record &sym) const
Definition: stack-frame.cc:117
octave_value & varref(const symbol_record &sym)
Definition: stack-frame.cc:125
compiled_fcn_stack_frame(tree_evaluator &tw, octave_function *fcn, std::size_t index, const std::shared_ptr< stack_frame > &parent_link, const std::shared_ptr< stack_frame > &static_link)
Definition: stack-frame.cc:58
symbol_scope get_scope(void) const
Definition: stack-frame.cc:76
void accept(stack_frame_walker &sfw)
octave_function * function(void) const
Definition: stack-frame.cc:81
octave_value get_auto_fcn_var(auto_var_type avt) const
Definition: stack-frame.cc:106
bool is_match(const std::string &buffer) const
Definition: lo-regexp.cc:440
~scope_stack_frame(void)=default
void display(bool follow=true) const
void accept(stack_frame_walker &sfw)
void mark_scope(const symbol_record &sym, scope_flags flag)
bool is_scope_frame(void) const
Definition: stack-frame.cc:524
symbol_record insert_symbol(const std::string &)
octave_value varval(const symbol_record &sym) const
octave_value & varref(const symbol_record &sym)
scope_stack_frame & operator=(const scope_stack_frame &elt)=delete
scope_stack_frame(const scope_stack_frame &elt)=default
scope_stack_frame(tree_evaluator &tw, const symbol_scope &scope, std::size_t index, const std::shared_ptr< stack_frame > &parent_link, const std::shared_ptr< stack_frame > &static_link)
Definition: stack-frame.cc:509
scope_stack_frame(void)=delete
symbol_scope get_scope(void) const
Definition: stack-frame.cc:526
symbol_record lookup_symbol(const std::string &name) const
Definition: stack-frame.cc:528
scope_flags scope_flag(const symbol_record &sym) const
octave_value & varref(const symbol_record &sym)
octave_value varval(const symbol_record &sym) const
bool get_val_offsets(const symbol_record &sym, std::size_t &frame_offset, std::size_t &data_offset) const
script_stack_frame(const script_stack_frame &elt)=default
void set_auto_fcn_var(auto_var_type avt, const octave_value &val)
Definition: stack-frame.cc:238
unwind_protect * unwind_protect_frame(void)
void set_script_offsets_internal(const std::map< std::string, symbol_record > &symbols)
std::vector< std::size_t > m_lexical_frame_offsets
Definition: stack-frame.cc:279
script_stack_frame(void)=delete
void resize(std::size_t size)
Definition: stack-frame.cc:219
bool is_user_script_frame(void) const
Definition: stack-frame.cc:193
octave_function * function(void) const
Definition: stack-frame.cc:209
void display(bool follow=true) const
unwind_protect * m_unwind_protect_frame
Definition: stack-frame.cc:272
scope_flags scope_flag(const symbol_record &sym) const
script_stack_frame & operator=(const script_stack_frame &elt)=delete
static std::shared_ptr< stack_frame > get_access_link(const std::shared_ptr< stack_frame > &static_link)
void mark_scope(const symbol_record &sym, scope_flags flag)
symbol_record insert_symbol(const std::string &)
void get_val_offsets_with_insert(const symbol_record &sym, std::size_t &frame_offset, std::size_t &data_offset)
symbol_record lookup_symbol(const std::string &name) const
symbol_scope get_scope(void) const
Definition: stack-frame.cc:207
octave_value get_auto_fcn_var(auto_var_type avt) const
Definition: stack-frame.cc:243
std::size_t size(void) const
Definition: stack-frame.cc:217
octave_user_script * m_script
Definition: stack-frame.cc:268
bool get_val_offsets_internal(const symbol_record &sym, std::size_t &frame_offset, std::size_t &data_offset) const
static std::size_t get_num_symbols(octave_user_script *script)
void accept(stack_frame_walker &sfw)
std::vector< std::size_t > m_value_offsets
Definition: stack-frame.cc:280
void resize_and_update_script_offsets(const symbol_record &sym)
virtual void visit_compiled_fcn_stack_frame(compiled_fcn_stack_frame &)=0
virtual void visit_script_stack_frame(script_stack_frame &)=0
virtual void visit_scope_stack_frame(scope_stack_frame &)=0
virtual void visit_user_fcn_stack_frame(user_fcn_stack_frame &)=0
virtual ~stack_frame_walker(void)=default
stack_frame_walker & operator=(const stack_frame_walker &)=delete
stack_frame_walker(const stack_frame_walker &)=delete
bool is_persistent(const symbol_record &sym) const
Definition: stack-frame.h:403
void clear_variables(void)
std::size_t index(void) const
Definition: stack-frame.h:202
octave_value value(const symbol_record &sym, const std::string &type, const std::list< octave_value_list > &idx) const
Definition: stack-frame.h:490
void clear_variable_regexp(const std::string &pattern)
octave_value who(const string_vector &patterns, bool have_regexp, bool return_list, bool verbose, const std::string &whos_line_fmt, const std::string &msg)
virtual symbol_scope get_scope(void) const =0
virtual scope_flags get_scope_flag(std::size_t) const
void assign(const symbol_record &sym, const octave_value &val)
Definition: stack-frame.h:445
std::shared_ptr< stack_frame > m_static_link
Definition: stack-frame.h:586
std::shared_ptr< stack_frame > access_link(void) const
Definition: stack-frame.h:317
virtual void resize(std::size_t)
bool is_global(const symbol_record &sym) const
Definition: stack-frame.h:391
symbol_info_list all_variables(void)
symbol_info_list regexp_symbol_info(const std::string &pattern)
int line(void) const
Definition: stack-frame.h:205
void clear_objects(void)
tree_evaluator & m_evaluator
Definition: stack-frame.h:565
virtual void set_scope_flag(std::size_t, scope_flags)
void clear_variable_pattern(const std::string &pattern)
virtual void display(bool follow=true) const
symbol_info_list make_symbol_info_list(const std::list< symbol_record > &symrec_list) const
std::list< std::string > variable_names(void) const
std::shared_ptr< stack_frame > m_parent_link
Definition: stack-frame.h:581
std::shared_ptr< stack_frame > static_link(void) const
Definition: stack-frame.h:314
std::shared_ptr< stack_frame > parent_link(void) const
Definition: stack-frame.h:311
void clear_variable(const std::string &name)
bool is_defined(const symbol_record &sym) const
Definition: stack-frame.h:343
octave_value workspace(void)
std::shared_ptr< stack_frame > m_access_link
Definition: stack-frame.h:591
std::string fcn_name(bool print_subfn=true) const
Definition: stack-frame.h:217
virtual void clear_values(void)
virtual octave_value & varref(const symbol_record &sym)=0
virtual std::size_t size(void) const
void mark_global(const symbol_record &sym)
Definition: stack-frame.h:323
bool is_variable(const symbol_record &sym) const
Definition: stack-frame.h:350
static stack_frame * create(tree_evaluator &tw, octave_function *fcn, std::size_t index, const std::shared_ptr< stack_frame > &parent_link, const std::shared_ptr< stack_frame > &static_link)
void clear(const symbol_record &sym)
Definition: stack-frame.h:517
std::string fcn_file_name(void) const
Definition: stack-frame.h:210
bool is_object(const symbol_record &sym) const
Definition: stack-frame.h:371
symbol_info_list glob_symbol_info(const std::string &pattern)
void install_variable(const symbol_record &sym, const octave_value &value, bool global)
std::map< std::string, octave_value > local_vars_map
Definition: stack-frame.h:112
std::size_t m_index
Definition: stack-frame.h:577
virtual bool is_user_fcn_frame(void) const
Definition: stack-frame.h:197
virtual octave_value varval(const symbol_record &sym) const =0
virtual void accept(stack_frame_walker &sfw)=0
void display_stopped_in_message(std::ostream &os) const
void visit_compiled_fcn_stack_frame(compiled_fcn_stack_frame &frame)
Definition: stack-frame.cc:643
void clear_symbols(stack_frame &frame, const std::list< symbol_record > &symbols)
Definition: stack-frame.cc:711
void visit_scope_stack_frame(scope_stack_frame &frame)
Definition: stack-frame.cc:673
symbol_cleaner(const std::string &pattern, bool have_regexp=false)
Definition: stack-frame.cc:619
symbol_cleaner(const string_vector &patterns, bool have_regexp=false)
Definition: stack-frame.cc:625
~symbol_cleaner(void)=default
string_vector m_patterns
Definition: stack-frame.cc:765
void visit_script_stack_frame(script_stack_frame &frame)
Definition: stack-frame.cc:655
void visit_user_fcn_stack_frame(user_fcn_stack_frame &frame)
Definition: stack-frame.cc:663
symbol_cleaner(const symbol_cleaner &)=delete
void maybe_clear_symbol(stack_frame &frame, const symbol_record &sym)
Definition: stack-frame.cc:685
void clean_frame(stack_frame &frame)
Definition: stack-frame.cc:755
symbol_cleaner(bool clear_all_names=true, bool clear_objects=false)
Definition: stack-frame.cc:631
symbol_cleaner & operator=(const symbol_cleaner &)=delete
std::set< std::string > m_cleared_names
Definition: stack-frame.cc:771
symbol_info_list symbol_info(void) const
Definition: stack-frame.cc:834
void visit_user_fcn_stack_frame(user_fcn_stack_frame &frame)
Definition: stack-frame.cc:905
void visit_compiled_fcn_stack_frame(compiled_fcn_stack_frame &frame)
Definition: stack-frame.cc:885
std::list< std::pair< std::string, symbol_info_list > > m_sym_inf_list
~symbol_info_accumulator(void)=default
symbol_info_accumulator(const symbol_info_accumulator &)=delete
octave_map map_value(void) const
Definition: stack-frame.cc:849
void append_list(stack_frame &frame)
symbol_info_accumulator(const string_vector &patterns, bool have_regexp=false)
Definition: stack-frame.cc:785
symbol_info_accumulator & operator=(const symbol_info_accumulator &)=delete
void visit_scope_stack_frame(scope_stack_frame &frame)
Definition: stack-frame.cc:915
std::set< std::string > m_found_names
void visit_script_stack_frame(script_stack_frame &frame)
Definition: stack-frame.cc:897
std::list< symbol_record > filter(stack_frame &frame, const std::list< symbol_record > &symbols)
Definition: stack-frame.cc:934
void display(std::ostream &os, const std::string &format) const
Definition: stack-frame.cc:873
symbol_info_accumulator(const std::string &pattern, bool have_regexp=false)
Definition: stack-frame.cc:778
symbol_info_accumulator(bool match_all=true, bool first_only=true)
Definition: stack-frame.cc:792
std::pair< std::string, symbol_info_list > syminf_list_elt
Definition: stack-frame.cc:927
std::list< std::string > names(void) const
Definition: stack-frame.cc:817
octave_map map_value(const std::string &caller_function_name, int nesting_level) const
Definition: syminfo.cc:191
octave_value varval(const std::string &name) const
Definition: syminfo.cc:169
void display(std::ostream &os, const std::string &format) const
Definition: syminfo.cc:331
std::list< std::string > names(void) const
Definition: syminfo.cc:180
symbol_record dup(void) const
Definition: symrec.h:205
std::size_t data_offset(void) const
Definition: symrec.h:203
std::size_t frame_offset(void) const
Definition: symrec.h:199
void set_frame_offset(std::size_t offset)
Definition: symrec.h:197
std::string name(void) const
Definition: symrec.h:207
std::string name(void) const
Definition: symscope.h:571
const std::map< std::string, symbol_record > & symbols(void) const
Definition: symscope.h:703
std::size_t num_symbols(void) const
Definition: symscope.h:399
symbol_record lookup_symbol(const std::string &name) const
Definition: symscope.h:480
std::shared_ptr< symbol_scope_rep > parent_scope(void) const
Definition: symscope.h:447
symbol_record find_symbol(const std::string &name)
Definition: symscope.h:474
octave_value & persistent_varref(std::size_t data_offset)
Definition: symscope.h:462
octave_value persistent_varval(std::size_t data_offset) const
Definition: symscope.h:469
symbol_record insert(const std::string &name)
Definition: symscope.h:485
std::list< symbol_record > symbol_list(void) const
Definition: symscope.h:717
bool is_nested(void) const
Definition: symscope.h:415
std::size_t nesting_depth(void) const
Definition: symscope.h:431
static std::shared_ptr< stack_frame > get_access_link(octave_user_function *fcn, const std::shared_ptr< stack_frame > &static_link)
user_fcn_stack_frame(tree_evaluator &tw, octave_user_function *fcn, std::size_t index, const std::shared_ptr< stack_frame > &parent_link, const std::shared_ptr< stack_frame > &static_link, const std::shared_ptr< stack_frame > &access_link=std::shared_ptr< stack_frame >())
Definition: stack-frame.cc:398
unwind_protect * m_unwind_protect_frame
Definition: stack-frame.cc:493
void mark_scope(const symbol_record &sym, scope_flags flag)
octave_user_function * m_fcn
Definition: stack-frame.cc:489
unwind_protect * unwind_protect_frame(void)
octave_value & varref(const symbol_record &sym)
symbol_record insert_symbol(const std::string &)
user_fcn_stack_frame & operator=(const user_fcn_stack_frame &elt)=delete
void display(bool follow=true) const
octave_value varval(const symbol_record &sym) const
symbol_scope get_scope(void) const
Definition: stack-frame.cc:455
bool is_user_fcn_frame(void) const
Definition: stack-frame.cc:440
static std::size_t get_num_symbols(octave_user_function *fcn)
Definition: stack-frame.cc:446
scope_flags scope_flag(const symbol_record &sym) const
user_fcn_stack_frame(const user_fcn_stack_frame &elt)=default
void break_closure_cycles(const std::shared_ptr< stack_frame > &frame)
octave_function * function(void) const
Definition: stack-frame.cc:457
user_fcn_stack_frame(tree_evaluator &tw, octave_user_function *fcn, std::size_t index, const std::shared_ptr< stack_frame > &parent_link, const std::shared_ptr< stack_frame > &static_link, const local_vars_map &local_vars, const std::shared_ptr< stack_frame > &access_link=std::shared_ptr< stack_frame >())
Definition: stack-frame.cc:411
symbol_record lookup_symbol(const std::string &name) const
void accept(stack_frame_walker &sfw)
virtual std::string type_name(void) const
Definition: ov-base.h:922
std::string name(void) const
Definition: ov-fcn.h:207
static octave_map cat(int dim, octave_idx_type n, const octave_scalar_map *map_list)
Definition: oct-map.cc:690
void assign(const std::string &k, const octave_value &val)
Definition: oct-map.h:238
octave::symbol_scope scope(void)
Definition: ov-usr-fcn.h:93
std::string type_name(void) const
Definition: ov-usr-fcn.h:479
std::string type_name(void) const
Definition: ov-usr-fcn.h:202
octave_idx_type get_count(void) const
Definition: ov.h:475
void call_object_destructor(void)
Definition: ov.h:1558
bool is_defined(void) const
Definition: ov.h:637
std::string type_name(void) const
Definition: ov.h:1449
std::ostream & list_in_columns(std::ostream &, int width=0, const std::string &prefix="") const
Definition: str-vec.cc:201
octave_idx_type numel(void) const
Definition: str-vec.h:100
bool empty(void) const
Definition: str-vec.h:77
octave_value & global_varref(const std::string &name)
Definition: pt-eval.cc:1974
octave_value global_varval(const std::string &name) const
Definition: pt-eval.cc:1968
void warning(const char *fmt,...)
Definition: error.cc:1055
void warning_with_id(const char *id, const char *fmt,...)
Definition: error.cc:1070
void error(const char *fmt,...)
Definition: error.cc:980
#define panic_impossible()
Definition: error.h:411
QString name
static void display_scope(std::ostream &os, const symbol_scope &scope)
Definition: stack-frame.cc:563
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
Definition: oct-locbuf.h:44
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
#define octave_stdout
Definition: pager.h:314
std::size_t format(std::ostream &os, const char *fmt,...)
Definition: utils.cc:1471