annotate libinterp/corefcn/stack-frame.cc @ 28327:8db2d4c9a64f stable

correctly find all symbols in script when saving values (bug #58382) * stack-frame.h, stack-frame.cc (stack_frame::glob_symbol_info, stack_frame::regexp_symbol_info): Use symbol_info_accumulator to find all symbols visible in current stack frame, including those in parent frames accessible throuch access_links. Move definition from header to source file.
author John W. Eaton <jwe@octave.org>
date Mon, 18 May 2020 16:06:27 -0400
parents b018f553fd85
children 5cb09ac94e81
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
3 // Copyright (C) 1995-2020 The Octave Project Developers
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26 #if defined (HAVE_CONFIG_H)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 # include "config.h"
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 #endif
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30 #include "lo-regexp.h"
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 #include "str-vec.h"
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 #include "defun.h"
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 #include "interpreter.h"
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 #include "interpreter-private.h"
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 #include "oct-map.h"
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37 #include "ov.h"
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 #include "ov-fcn.h"
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 #include "ov-fcn-handle.h"
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 #include "ov-usr-fcn.h"
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 #include "pager.h"
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 #include "parse.h"
27211
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27149
diff changeset
43 #include "pt-eval.h"
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44 #include "stack-frame.h"
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45 #include "stack-frame-walker.h"
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46 #include "syminfo.h"
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47 #include "syminfo-accumulator.h"
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48 #include "symrec.h"
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 #include "symscope.h"
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50 #include "variables.h"
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52 namespace octave
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
53 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54 // FIXME: There should probably be a display method for the script,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55 // fcn, and scope objects and the script and function objects should
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56 // be responsible for displaying the scopes they contain.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58 static void display_scope (std::ostream& os, const symbol_scope& scope)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
60 if (scope)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
62 os << "scope: " << scope.name () << std::endl;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64 if (scope.num_symbols () > 0)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66 os << "name (frame offset, data offset, storage class):"
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67 << std::endl;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69 std::list<symbol_record> symbols = scope.symbol_list ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71 for (auto& sym : symbols)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73 os << " " << sym.name () << " (" << sym.frame_offset ()
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74 << ", " << sym.data_offset () << ", " << sym.storage_class ()
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75 << ")" << std::endl;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
77 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
80
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81 class symbol_cleaner : public stack_frame_walker
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
82 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83 public:
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
85 symbol_cleaner (const std::string& pattern, bool have_regexp = false)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
86 : stack_frame_walker (), m_patterns (pattern),
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
87 m_clear_all_names (false), m_clear_objects (false),
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
88 m_have_regexp (have_regexp), m_cleared_names ()
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
89 { }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
90
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
91 symbol_cleaner (const string_vector& patterns, bool have_regexp = false)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
92 : stack_frame_walker (), m_patterns (patterns),
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
93 m_clear_all_names (false), m_clear_objects (false),
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
94 m_have_regexp (have_regexp), m_cleared_names ()
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95 { }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
97 symbol_cleaner (bool clear_all_names = true, bool clear_objects = false)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
98 : stack_frame_walker (), m_patterns (),
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
99 m_clear_all_names (clear_all_names), m_clear_objects (clear_objects),
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
100 m_have_regexp (false), m_cleared_names ()
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
101 { }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
102
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
103 symbol_cleaner (const symbol_cleaner&) = delete;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
104
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
105 symbol_cleaner& operator = (const symbol_cleaner&) = delete;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
106
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
107 ~symbol_cleaner (void) = default;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
108
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
109 void visit_compiled_fcn_stack_frame (compiled_fcn_stack_frame& frame)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
110 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
111 // This one follows static link always. Hmm, should the access
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
112 // link for a compiled_fcn_stack_frame be the same as the static
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
113 // link?
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
114
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
115 stack_frame *slink = frame.static_link ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
116
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
117 if (slink)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
118 slink->accept (*this);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
119 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
120
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
121 void visit_script_stack_frame (script_stack_frame& frame)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
122 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
123 stack_frame *alink = frame.access_link ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
124
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
125 if (alink)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
126 alink->accept (*this);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
127 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
128
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
129 void visit_user_fcn_stack_frame (user_fcn_stack_frame& frame)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
130 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
131 clean_frame (frame);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
132
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
133 stack_frame *alink = frame.access_link ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
134
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
135 if (alink)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
136 alink->accept (*this);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
137 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
138
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
139 void visit_scope_stack_frame (scope_stack_frame& frame)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
140 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
141 clean_frame (frame);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
142
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
143 stack_frame *alink = frame.access_link ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
144
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
145 if (alink)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
146 alink->accept (*this);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
147 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
148
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
149 private:
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
150
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
151 void maybe_clear_symbol (stack_frame& frame, const symbol_record& sym)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
152 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
153 std::string name = sym.name ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
154
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
155 if (m_cleared_names.find (name) == m_cleared_names.end ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
156 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
157 // FIXME: Should we check that the name is defined and skip if
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
158 // it is not? Is it possible for another symbol with the same
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
159 // name to appear in a later stack frame?
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
160
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
161 // FIXME: If we are clearing objects and a symbol is found,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
162 // should we add it to the list of cleared names (since
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
163 // we did find a symbol) but skip clearing the object?
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
164
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
165 if (m_clear_objects && ! frame.is_object (sym))
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
166 return;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
167
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
168 m_cleared_names.insert (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
169
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
170 frame.clear (sym);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
171 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
172 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
173
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
174 // FIXME: It would be nice to avoid the duplication in the following
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
175 // function.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
176
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
177 void clear_symbols (stack_frame& frame,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
178 const std::list<symbol_record>& symbols)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
179 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
180 if (m_clear_all_names)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
181 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
182 for (const auto& sym : symbols)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
183 maybe_clear_symbol (frame, sym);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
184 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
185 else if (m_have_regexp)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
186 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
187 octave_idx_type npatterns = m_patterns.numel ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
188
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
189 for (octave_idx_type j = 0; j < npatterns; j++)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
190 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
191 std::string pattern = m_patterns[j];
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
192
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
193 regexp pat (pattern);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
194
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
195 for (const auto& sym : symbols)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
196 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
197 if (pat.is_match (sym.name ()))
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
198 maybe_clear_symbol (frame, sym);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
199 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
200 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
201 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
202 else
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
203 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
204 octave_idx_type npatterns = m_patterns.numel ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
205
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
206 for (octave_idx_type j = 0; j < npatterns; j++)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
207 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
208 std::string pattern = m_patterns[j];
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
209
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
210 glob_match pat (pattern);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
211
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
212 for (const auto& sym : symbols)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
213 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
214 if (pat.match (sym.name ()))
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
215 maybe_clear_symbol (frame, sym);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
216 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
217 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
218 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
219 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
220
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
221 void clean_frame (stack_frame& frame)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
222 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
223 symbol_scope scope = frame.get_scope ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
224
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
225 std::list<symbol_record> symbols = scope.symbol_list ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
226
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
227 if (m_clear_all_names || ! m_patterns.empty ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
228 clear_symbols (frame, symbols);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
229 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
230
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
231 string_vector m_patterns;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
232
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
233 bool m_clear_all_names;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
234 bool m_clear_objects;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
235 bool m_have_regexp;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
236
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
237 std::set<std::string> m_cleared_names;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
238 };
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
239
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
240 // This function is only implemented for user_fcn stack frames and
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
241 // only called for those objects using unwind_protect and the
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
242 // call_stack::clear_current_frame_values function. Anything else
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
243 // indicates an error in the implementation.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
244
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
245 void stack_frame::clear_values (void)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
246 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
247 panic_impossible ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
248 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
249
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
250 // Return first occurrence of variables in current stack frame and any
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
251 // parent frames reachable through access links.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
252
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
253 symbol_info_list stack_frame::all_variables (void)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
254 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
255 symbol_info_accumulator sia (true, true);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
256
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
257 accept (sia);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
258
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
259 return sia.symbol_info ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
260 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
261
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
262 std::list<symbol_record>
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
263 stack_frame::glob (const std::string& pattern) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
264 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
265 std::list<symbol_record> retval;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
266
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
267 symbol_scope scope = get_scope ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
268
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
269 const std::map<std::string, symbol_record>& symbols = scope.symbols ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
270
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
271 glob_match pat (pattern);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
272
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
273 for (const auto& nm_sr : symbols)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
274 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
275 if (pat.match (nm_sr.first))
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
276 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
277 symbol_record sr = nm_sr.second;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
278
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
279 if (! is_variable (sr))
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
280 continue;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
281
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
282 retval.push_back (sr);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
283 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
284 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
285
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
286 return retval;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
287 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
288
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
289 std::list<symbol_record>
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
290 stack_frame::regexp (const std::string& pattern) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
291 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
292 std::list<symbol_record> retval;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
293
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
294 symbol_scope scope = get_scope ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
295
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
296 const std::map<std::string, symbol_record>& symbols = scope.symbols ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
297
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
298 octave::regexp pat (pattern);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
299
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
300 for (const auto& nm_sr : symbols)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
301 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
302 if (pat.is_match (nm_sr.first))
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
303 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
304 symbol_record sr = nm_sr.second;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
305
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
306 if (! is_variable (sr))
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
307 continue;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
308
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
309 retval.push_back (sr);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
310 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
311 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
312
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
313 return retval;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
314 }
28327
8db2d4c9a64f correctly find all symbols in script when saving values (bug #58382)
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
315 // FIXME: Should this function also find any variables in parent
8db2d4c9a64f correctly find all symbols in script when saving values (bug #58382)
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
316 // scopes accessible through access_links?
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
317
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
318 std::list<std::string> stack_frame::variable_names (void) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
319 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
320 std::list<std::string> retval;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
321
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
322 symbol_scope scope = get_scope ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
323
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
324 const std::map<std::string, symbol_record>& symbols = scope.symbols ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
325
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
326 for (const auto& nm_sr : symbols)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
327 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
328 if (is_variable (nm_sr.second))
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
329 retval.push_back (nm_sr.first);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
330 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
331
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
332 retval.sort ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
333
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
334 return retval;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
335 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
336
28327
8db2d4c9a64f correctly find all symbols in script when saving values (bug #58382)
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
337 symbol_info_list stack_frame::glob_symbol_info (const std::string& pattern)
8db2d4c9a64f correctly find all symbols in script when saving values (bug #58382)
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
338 {
8db2d4c9a64f correctly find all symbols in script when saving values (bug #58382)
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
339 symbol_info_accumulator sia (pattern, false);
8db2d4c9a64f correctly find all symbols in script when saving values (bug #58382)
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
340
8db2d4c9a64f correctly find all symbols in script when saving values (bug #58382)
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
341 accept (sia);
8db2d4c9a64f correctly find all symbols in script when saving values (bug #58382)
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
342
8db2d4c9a64f correctly find all symbols in script when saving values (bug #58382)
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
343 return sia.symbol_info ();
8db2d4c9a64f correctly find all symbols in script when saving values (bug #58382)
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
344 }
8db2d4c9a64f correctly find all symbols in script when saving values (bug #58382)
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
345
8db2d4c9a64f correctly find all symbols in script when saving values (bug #58382)
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
346 symbol_info_list stack_frame::regexp_symbol_info (const std::string& pattern)
8db2d4c9a64f correctly find all symbols in script when saving values (bug #58382)
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
347 {
8db2d4c9a64f correctly find all symbols in script when saving values (bug #58382)
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
348 symbol_info_accumulator sia (pattern, true);
8db2d4c9a64f correctly find all symbols in script when saving values (bug #58382)
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
349
8db2d4c9a64f correctly find all symbols in script when saving values (bug #58382)
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
350 accept (sia);
8db2d4c9a64f correctly find all symbols in script when saving values (bug #58382)
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
351
8db2d4c9a64f correctly find all symbols in script when saving values (bug #58382)
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
352 return sia.symbol_info ();
8db2d4c9a64f correctly find all symbols in script when saving values (bug #58382)
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
353 }
8db2d4c9a64f correctly find all symbols in script when saving values (bug #58382)
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
354
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
355 size_t stack_frame::size (void) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
356 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
357 // This function should only be called for user_fcn_stack_frame or
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
358 // scope_stack_frame objects. Anything else indicates an error in
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
359 // the implementation.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
360
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
361 panic_impossible ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
362 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
363
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
364 void stack_frame::resize (size_t)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
365 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
366 // This function should only be called for user_fcn_stack_frame or
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
367 // scope_stack_frame objects. Anything else indicates an error in
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
368 // the implementation.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
369
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
370 panic_impossible ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
371 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
372
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
373 stack_frame::scope_flags stack_frame::get_scope_flag (size_t) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
374 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
375 // This function should only be called for user_fcn_stack_frame or
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
376 // scope_stack_frame objects. Anything else indicates an error in
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
377 // the implementation.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
378
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
379 panic_impossible ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
380 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
381
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
382 void stack_frame::set_scope_flag (size_t, scope_flags)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
383 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
384 // This function should only be called for user_fcn_stack_frame or
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
385 // scope_stack_frame objects. Anything else indicates an error in
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
386 // the implementation.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
387
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
388 panic_impossible ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
389 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
390
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
391 void stack_frame::install_variable (const symbol_record& sym,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
392 const octave_value& value, bool global)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
393 {
26673
4271b53b24a6 when installing global variable don't warn if it is already global
John W. Eaton <jwe@octave.org>
parents: 26663
diff changeset
394 if (global && ! is_global (sym))
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
395 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
396 octave_value val = varval (sym);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
397
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
398 if (val.is_defined ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
399 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
400 std::string nm = sym.name ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
401
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
402 warning_with_id ("Octave:global-local-conflict",
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
403 "global: '%s' is defined in the current scope.\n",
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
404 nm.c_str ());
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
405 warning_with_id ("Octave:global-local-conflict",
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
406 "global: in a future version, global variables must be declared before use.\n");
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
407
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
408 // If the symbol is defined in the local but not the
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
409 // global scope, then use the local value as the
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
410 // initial value. This value will also override any
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
411 // initializer in the global statement.
27211
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27149
diff changeset
412 octave_value global_val = m_evaluator.global_varval (nm);
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
413
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
414 if (global_val.is_defined ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
415 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
416 warning_with_id ("Octave:global-local-conflict",
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
417 "global: global value overrides existing local value");
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
418
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
419 clear (sym);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
420 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
421 else
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
422 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
423 warning_with_id ("Octave:global-local-conflict",
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
424 "global: existing local value used to initialize global variable");
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
425
27211
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27149
diff changeset
426 m_evaluator.global_varref (nm) = val;
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
427 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
428 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
429
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
430 mark_global (sym);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
431 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
432
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
433 if (value.is_defined ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
434 assign (sym, value);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
435 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
436
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
437 octave_value stack_frame::varval (size_t) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
438 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
439 // This function should only be called for user_fcn_stack_frame or
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
440 // scope_stack_frame objects. Anything else indicates an error in
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
441 // the implementation.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
442
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
443 panic_impossible ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
444 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
445
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
446 octave_value& stack_frame::varref (size_t)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
447 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
448 // This function should only be called for user_fcn_stack_frame or
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
449 // scope_stack_frame objects. Anything else indicates an error in
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
450 // the implementation.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
451
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
452 panic_impossible ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
453 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
454
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
455 void stack_frame::clear_objects (void)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
456 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
457 symbol_cleaner sc (true, true);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
458
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
459 accept (sc);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
460 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
461
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
462 void stack_frame::clear_variable (const std::string& name)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
463 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
464 symbol_cleaner sc (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
465
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
466 accept (sc);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
467 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
468
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
469 void stack_frame::clear_variable_pattern (const std::string& pattern)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
470 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
471 symbol_cleaner sc (pattern);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
472
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
473 accept (sc);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
474 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
475
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
476 void stack_frame::clear_variable_pattern (const string_vector& patterns)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
477 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
478 symbol_cleaner sc (patterns);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
479
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
480 accept (sc);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
481 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
482
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
483 void stack_frame::clear_variable_regexp (const std::string& pattern)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
484 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
485 symbol_cleaner sc (pattern, true);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
486
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
487 accept (sc);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
488 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
489
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
490 void stack_frame::clear_variable_regexp (const string_vector& patterns)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
491 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
492 symbol_cleaner sc (patterns, true);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
493
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
494 accept (sc);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
495 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
496
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
497 void stack_frame::clear_variables (void)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
498 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
499 symbol_cleaner sc;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
500
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
501 accept (sc);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
502 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
503
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 26824
diff changeset
504 void stack_frame::display_stopped_in_message (std::ostream& os) const
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 26824
diff changeset
505 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 26824
diff changeset
506 if (index () == 0)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 26824
diff changeset
507 os << "at top level" << std::endl;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 26824
diff changeset
508 else
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 26824
diff changeset
509 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 26824
diff changeset
510 os << "stopped in " << fcn_name ();
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 26824
diff changeset
511
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 26824
diff changeset
512 int l = line ();
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 26824
diff changeset
513 if (l > 0)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 26824
diff changeset
514 os << " at line " << line ();
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 26824
diff changeset
515
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 26824
diff changeset
516 os << " [" << fcn_file_name () << "] " << std::endl;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 26824
diff changeset
517 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 26824
diff changeset
518 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 26824
diff changeset
519
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
520 void stack_frame::display (bool follow) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
521 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
522 std::ostream& os = octave_stdout;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
523
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
524 os << "-- [stack_frame] (" << this << ") --" << std::endl;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
525
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
526 os << "static link: ";
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
527 if (m_static_link)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
528 os << m_static_link;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
529 else
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
530 os << "NULL";
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
531 os << std::endl;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
532
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
533 os << "access link: ";
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
534 if (m_access_link)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
535 os << m_access_link;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
536 else
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
537 os << "NULL";
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
538 os << std::endl;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
539
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
540 os << "line: " << m_line << std::endl;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
541 os << "column: " << m_column << std::endl;
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 26824
diff changeset
542 os << "index: " << m_index << std::endl;
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
543
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
544 os << std::endl;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
545
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
546 if (! follow)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
547 return;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
548
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
549 os << "FOLLOWING ACCESS LINKS:" << std::endl;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
550 const stack_frame *frm = access_link ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
551 while (frm)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
552 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
553 frm->display (false);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
554 os << std::endl;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
555
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
556 frm = frm->access_link ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
557 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
558 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
559
26824
d9770844392e provide virtual dup methods for stack frames
John W. Eaton <jwe@octave.org>
parents: 26673
diff changeset
560 compiled_fcn_stack_frame *
d9770844392e provide virtual dup methods for stack frames
John W. Eaton <jwe@octave.org>
parents: 26673
diff changeset
561 compiled_fcn_stack_frame::dup (void) const
d9770844392e provide virtual dup methods for stack frames
John W. Eaton <jwe@octave.org>
parents: 26673
diff changeset
562 {
d9770844392e provide virtual dup methods for stack frames
John W. Eaton <jwe@octave.org>
parents: 26673
diff changeset
563 return new compiled_fcn_stack_frame (*this);
d9770844392e provide virtual dup methods for stack frames
John W. Eaton <jwe@octave.org>
parents: 26673
diff changeset
564 }
d9770844392e provide virtual dup methods for stack frames
John W. Eaton <jwe@octave.org>
parents: 26673
diff changeset
565
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
566 void compiled_fcn_stack_frame::display (bool follow) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
567 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
568 std::ostream& os = octave_stdout;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
569
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
570 os << "-- [compiled_fcn_stack_frame] (" << this << ") --" << std::endl;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
571 stack_frame::display (follow);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
572
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
573 os << "fcn: " << m_fcn->name ()
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
574 << " (" << m_fcn->type_name () << ")" << std::endl;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
575 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
576
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
577 void compiled_fcn_stack_frame::accept (stack_frame_walker& sfw)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
578 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
579 sfw.visit_compiled_fcn_stack_frame (*this);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
580 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
581
27211
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27149
diff changeset
582 script_stack_frame::script_stack_frame (tree_evaluator& tw,
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
583 octave_user_script *script,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
584 unwind_protect *up_frame,
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 26824
diff changeset
585 size_t index,
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
586 stack_frame *static_link)
27211
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27149
diff changeset
587 : stack_frame (tw, index, static_link, get_access_link (static_link)),
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
588 m_script (script), m_unwind_protect_frame (up_frame),
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
589 m_lexical_frame_offsets (get_num_symbols (script), 1),
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
590 m_value_offsets (get_num_symbols (script), 0)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
591 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
592 set_script_offsets ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
593 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
594
26824
d9770844392e provide virtual dup methods for stack frames
John W. Eaton <jwe@octave.org>
parents: 26673
diff changeset
595 script_stack_frame *
d9770844392e provide virtual dup methods for stack frames
John W. Eaton <jwe@octave.org>
parents: 26673
diff changeset
596 script_stack_frame::dup (void) const
d9770844392e provide virtual dup methods for stack frames
John W. Eaton <jwe@octave.org>
parents: 26673
diff changeset
597 {
d9770844392e provide virtual dup methods for stack frames
John W. Eaton <jwe@octave.org>
parents: 26673
diff changeset
598 return new script_stack_frame (*this);
d9770844392e provide virtual dup methods for stack frames
John W. Eaton <jwe@octave.org>
parents: 26673
diff changeset
599 }
d9770844392e provide virtual dup methods for stack frames
John W. Eaton <jwe@octave.org>
parents: 26673
diff changeset
600
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
601 size_t script_stack_frame::get_num_symbols (octave_user_script *script)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
602 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
603 symbol_scope script_scope = script->scope ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
604
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
605 return script_scope.num_symbols ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
606 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
607
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
608 void script_stack_frame::set_script_offsets (void)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
609 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
610 // Set frame and data offsets inside stack frame based on enclosing
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
611 // scope(s).
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
612
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
613 symbol_scope script_scope = m_script->scope ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
614
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
615 size_t num_script_symbols = script_scope.num_symbols ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
616
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
617 resize (num_script_symbols);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
618
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
619 const std::map<std::string, symbol_record>& script_symbols
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
620 = script_scope.symbols ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
621
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
622 set_script_offsets_internal (script_symbols);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
623 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
624
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
625 void script_stack_frame::set_script_offsets_internal
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
626 (const std::map<std::string, symbol_record>& script_symbols)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
627 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
628 // This scope will be used to evaluate the script. Find (or
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
629 // possibly insert) symbols from the dummy script scope here.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
630
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
631 symbol_scope eval_scope = m_access_link->get_scope ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
632
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
633 if (eval_scope.is_nested ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
634 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
635 bool found = false;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
636
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
637 for (const auto& nm_sr : script_symbols)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
638 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
639 std::string name = nm_sr.first;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
640 symbol_record script_sr = nm_sr.second;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
641
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
642 symbol_scope parent_scope = eval_scope;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
643
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
644 size_t count = 1;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
645
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
646 while (parent_scope)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
647 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
648 const std::map<std::string, symbol_record>& parent_scope_symbols
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
649 = parent_scope.symbols ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
650
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
651 auto p = parent_scope_symbols.find (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
652
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
653 if (p != parent_scope_symbols.end ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
654 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
655 found = true;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
656 symbol_record parent_scope_sr = p->second;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
657
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
658 size_t script_sr_data_offset = script_sr.data_offset ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
659
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
660 m_lexical_frame_offsets.at (script_sr_data_offset)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
661 = parent_scope_sr.frame_offset () + 1;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
662
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
663 m_value_offsets.at (script_sr_data_offset)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
664 = parent_scope_sr.data_offset ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
665
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
666 break;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
667 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
668 else
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
669 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
670 count++;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
671 parent_scope = parent_scope.parent_scope ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
672 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
673 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
674
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
675 if (! found)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
676 error ("symbol '%s' cannot be added to static scope",
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
677 name.c_str ());
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
678 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
679 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
680 else
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
681 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
682 const std::map<std::string, symbol_record>& eval_scope_symbols
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
683 = eval_scope.symbols ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
684
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
685 for (const auto& nm_sr : script_symbols)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
686 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
687 std::string name = nm_sr.first;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
688 symbol_record script_sr = nm_sr.second;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
689
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
690 auto p = eval_scope_symbols.find (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
691
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
692 symbol_record eval_scope_sr;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
693
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
694 if (p == eval_scope_symbols.end ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
695 eval_scope_sr = eval_scope.insert (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
696 else
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
697 eval_scope_sr = p->second;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
698
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
699 size_t script_sr_data_offset = script_sr.data_offset ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
700
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
701 // The +1 is for going from the script frame to the eval
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
702 // frame. Only one access_link should need to be followed.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
703
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
704 m_lexical_frame_offsets.at (script_sr_data_offset)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
705 = eval_scope_sr.frame_offset () + 1;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
706
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
707 m_value_offsets.at (script_sr_data_offset)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
708 = eval_scope_sr.data_offset ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
709 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
710 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
711 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
712
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
713 void script_stack_frame::resize_and_update_script_offsets (const symbol_record& sym)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
714 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
715 size_t data_offset = sym.data_offset ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
716
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
717 // This function is called when adding new symbols to a script
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
718 // scope. If the symbol wasn't present before, it should be outside
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
719 // the range so we need to resize then update offsets.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
720
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
721 assert (data_offset >= size ());
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
722
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
723 resize (data_offset+1);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
724
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
725 // FIXME: We should be able to avoid creating the map object and the
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
726 // looping in the set_scripts_offsets_internal function. Can we do
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
727 // that without (or with minimal) code duplication?
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
728
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
729 std::map<std::string, symbol_record> tmp_symbols;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
730 tmp_symbols[sym.name ()] = sym;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
731 set_script_offsets_internal (tmp_symbols);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
732 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
733
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
734 // If this is a nested scope, set access_link to nearest parent
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
735 // stack frame that corresponds to the lexical parent of this scope.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
736
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
737 stack_frame *
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
738 script_stack_frame::get_access_link (stack_frame *static_link)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
739 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
740 stack_frame *alink = nullptr;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
741
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
742 // If this script is called from another script, set access
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
743 // link to ultimate parent stack frame.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
744
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
745 alink = static_link;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
746
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
747 while (alink->is_user_script_frame ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
748 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
749 if (alink->access_link ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
750 alink = alink->access_link ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
751 else
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
752 break;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
753 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
754
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
755 return alink;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
756 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
757
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
758 symbol_record script_stack_frame::lookup_symbol (const std::string& name) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
759 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
760 symbol_scope scope = get_scope ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
761
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
762 symbol_record sym = scope.lookup_symbol (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
763
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
764 if (sym)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
765 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
766 assert (sym.frame_offset () == 0);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
767
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
768 return sym;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
769 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
770
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
771 sym = m_access_link->lookup_symbol (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
772
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
773 // Return symbol record with adjusted frame offset.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
774 symbol_record new_sym = sym.dup ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
775
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
776 new_sym.set_frame_offset (sym.frame_offset () + 1);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
777
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
778 return new_sym;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
779 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
780
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
781 symbol_record script_stack_frame::insert_symbol (const std::string& name)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
782 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
783 // If the symbols is already in the immediate scope, there is
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
784 // nothing more to do.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
785
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
786 symbol_scope scope = get_scope ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
787
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
788 symbol_record sym = scope.lookup_symbol (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
789
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
790 if (sym)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
791 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
792 // All symbol records in a script scope should have zero offset,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
793 // which means we redirect our lookup using
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
794 // lexical_frame_offsets and values_offets.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
795 assert (sym.frame_offset () == 0);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
796
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
797 return sym;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
798 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
799
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
800 // Insert the symbol in the current scope then resize and update
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
801 // offsets. This operation should never fail.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
802
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
803 sym = scope.find_symbol (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
804
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
805 assert (sym);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
806
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
807 resize_and_update_script_offsets (sym);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
808
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
809 return sym;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
810 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
811
26663
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
812 // Similar to set_script_offsets_internal except that we only return
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
813 // frame and data offsets for symbols found by name in parent scopes
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
814 // instead of updating the offsets stored in the script frame itself.
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
815
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
816 bool
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
817 script_stack_frame::get_val_offsets_internal (const symbol_record& script_sr,
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
818 size_t& frame_offset,
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
819 size_t& data_offset) const
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
820 {
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
821 bool found = false;
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
822
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
823 // This scope will be used to evaluate the script. Find symbols
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
824 // here by name.
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
825
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
826 symbol_scope eval_scope = m_access_link->get_scope ();
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
827
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
828 if (eval_scope.is_nested ())
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
829 {
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
830 std::string name = script_sr.name ();
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
831
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
832 symbol_scope parent_scope = eval_scope;
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
833
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
834 size_t count = 1;
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
835
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
836 while (parent_scope)
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
837 {
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
838 const std::map<std::string, symbol_record>& parent_scope_symbols
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
839 = parent_scope.symbols ();
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
840
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
841 auto p = parent_scope_symbols.find (name);
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
842
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
843 if (p != parent_scope_symbols.end ())
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
844 {
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
845 found = true;
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
846 symbol_record parent_scope_sr = p->second;
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
847
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
848 frame_offset = parent_scope_sr.frame_offset () + 1;
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
849
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
850 data_offset = parent_scope_sr.data_offset ();
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
851
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
852 break;
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
853 }
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
854 else
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
855 {
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
856 count++;
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
857 parent_scope = parent_scope.parent_scope ();
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
858 }
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
859 }
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
860 }
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
861 else
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
862 {
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
863 const std::map<std::string, symbol_record>& eval_scope_symbols
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
864 = eval_scope.symbols ();
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
865
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
866 std::string name = script_sr.name ();
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
867
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
868 auto p = eval_scope_symbols.find (name);
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
869
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
870 symbol_record eval_scope_sr;
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
871
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
872 if (p != eval_scope_symbols.end ())
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
873 {
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
874 found = true;
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
875 eval_scope_sr = p->second;
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
876
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
877 // The +1 is for going from the script frame to the eval
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
878 // frame. Only one access_link should need to be followed.
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
879
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
880 frame_offset = eval_scope_sr.frame_offset () + 1;
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
881
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
882 data_offset = eval_scope_sr.data_offset ();
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
883 }
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
884 }
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
885
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
886 return found;
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
887 }
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
888
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
889 bool script_stack_frame::get_val_offsets (const symbol_record& sym,
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
890 size_t& frame_offset,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
891 size_t& data_offset) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
892 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
893 data_offset = sym.data_offset ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
894 frame_offset = sym.frame_offset ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
895
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
896 if (frame_offset == 0)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
897 {
26663
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
898 // An out of range data_offset value here means that we have a
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
899 // symbol that was not originally in the script. But this
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
900 // function is called in places where we can't insert a new
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
901 // symbol, so we fail and it is up to the caller to decide what
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
902 // to do.
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
903
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
904 if (data_offset >= size ())
26663
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
905 return get_val_offsets_internal (sym, frame_offset, data_offset);
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
906
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
907 // Use frame and value offsets stored in this stack frame,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
908 // indexed by data_offset from the symbol_record to find the
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
909 // values. These offsets were determined by
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
910 // script_stack_frame::set_script_offsets when this script was
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
911 // invoked.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
912
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
913 frame_offset = m_lexical_frame_offsets.at (data_offset);
27149
61226b7bd6b9 fix calculation of value offsets for variables added to script scopes
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
914
61226b7bd6b9 fix calculation of value offsets for variables added to script scopes
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
915 if (frame_offset == 0)
61226b7bd6b9 fix calculation of value offsets for variables added to script scopes
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
916 {
61226b7bd6b9 fix calculation of value offsets for variables added to script scopes
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
917 // If the frame offset stored in m_lexical_frame_offsets is
61226b7bd6b9 fix calculation of value offsets for variables added to script scopes
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
918 // zero, then the data offset in the evaluation scope has
61226b7bd6b9 fix calculation of value offsets for variables added to script scopes
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
919 // not been determined so try to do that now. The symbol
61226b7bd6b9 fix calculation of value offsets for variables added to script scopes
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
920 // may have been added by eval and without calling
61226b7bd6b9 fix calculation of value offsets for variables added to script scopes
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
921 // resize_and_update_script_offsets.
61226b7bd6b9 fix calculation of value offsets for variables added to script scopes
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
922
61226b7bd6b9 fix calculation of value offsets for variables added to script scopes
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
923 return get_val_offsets_internal (sym, frame_offset, data_offset);
61226b7bd6b9 fix calculation of value offsets for variables added to script scopes
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
924 }
61226b7bd6b9 fix calculation of value offsets for variables added to script scopes
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
925
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
926 data_offset = m_value_offsets.at (data_offset);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
927 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
928 else
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
929 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
930 // If frame_offset is not zero, then then we must have a symbol
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
931 // that was not originally in the script. The values should
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
932 // have been determined by the script_stack_frame::lookup function.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
933 }
26663
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
934
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
935 return true;
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
936 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
937
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
938 void script_stack_frame::get_val_offsets_with_insert (const symbol_record& sym,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
939 size_t& frame_offset,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
940 size_t& data_offset)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
941 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
942 data_offset = sym.data_offset ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
943 frame_offset = sym.frame_offset ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
944
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
945 if (frame_offset == 0)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
946 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
947 if (data_offset >= size ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
948 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
949 // If the data_offset is out of range, then we must have a
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
950 // symbol that was not originally in the script. Resize and
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
951 // update the offsets.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
952
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
953 resize_and_update_script_offsets (sym);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
954 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
955
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
956 // Use frame and value offsets stored in this stack frame,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
957 // indexed by data_offset from the symbol_record to find the
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
958 // values. These offsets were determined by
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
959 // script_stack_frame::set_script_offsets when this script was
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
960 // invoked.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
961
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
962 frame_offset = m_lexical_frame_offsets.at (data_offset);
27149
61226b7bd6b9 fix calculation of value offsets for variables added to script scopes
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
963
61226b7bd6b9 fix calculation of value offsets for variables added to script scopes
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
964 if (frame_offset == 0)
61226b7bd6b9 fix calculation of value offsets for variables added to script scopes
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
965 {
61226b7bd6b9 fix calculation of value offsets for variables added to script scopes
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
966 // If the frame offset stored in m_lexical_frame_offsets is
61226b7bd6b9 fix calculation of value offsets for variables added to script scopes
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
967 // zero, then the data offset in the evaluation scope has
61226b7bd6b9 fix calculation of value offsets for variables added to script scopes
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
968 // not been determined so try to do that now. The symbol
61226b7bd6b9 fix calculation of value offsets for variables added to script scopes
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
969 // may have been added by eval and without calling
61226b7bd6b9 fix calculation of value offsets for variables added to script scopes
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
970 // resize_and_update_script_offsets.
61226b7bd6b9 fix calculation of value offsets for variables added to script scopes
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
971
61226b7bd6b9 fix calculation of value offsets for variables added to script scopes
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
972 // We don't need to resize here. That case is handled above.
61226b7bd6b9 fix calculation of value offsets for variables added to script scopes
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
973
61226b7bd6b9 fix calculation of value offsets for variables added to script scopes
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
974 // FIXME: We should be able to avoid creating the map object
61226b7bd6b9 fix calculation of value offsets for variables added to script scopes
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
975 // and the looping in the set_scripts_offsets_internal
61226b7bd6b9 fix calculation of value offsets for variables added to script scopes
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
976 // function. Can we do that without (or with minimal) code
61226b7bd6b9 fix calculation of value offsets for variables added to script scopes
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
977 // duplication?
61226b7bd6b9 fix calculation of value offsets for variables added to script scopes
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
978
61226b7bd6b9 fix calculation of value offsets for variables added to script scopes
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
979 std::map<std::string, symbol_record> tmp_symbols;
61226b7bd6b9 fix calculation of value offsets for variables added to script scopes
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
980 tmp_symbols[sym.name ()] = sym;
61226b7bd6b9 fix calculation of value offsets for variables added to script scopes
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
981 set_script_offsets_internal (tmp_symbols);
61226b7bd6b9 fix calculation of value offsets for variables added to script scopes
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
982 }
61226b7bd6b9 fix calculation of value offsets for variables added to script scopes
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
983
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
984 data_offset = m_value_offsets.at (data_offset);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
985 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
986 else
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
987 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
988 // If frame_offset is not zero, then then we must have a symbol
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
989 // that was not originally in the script. The values were
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
990 // determined by the script_stack_frame::lookup function.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
991 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
992 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
993
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
994 stack_frame::scope_flags
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
995 script_stack_frame::scope_flag (const symbol_record& sym) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
996 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
997 size_t frame_offset;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
998 size_t data_offset;
26663
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
999
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
1000 bool found = get_val_offsets (sym, frame_offset, data_offset);
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
1001
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
1002 // It can't be global or persistent, so call it local.
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
1003 if (! found)
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
1004 return LOCAL;
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1005
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1006 // Follow frame_offset access links to stack frame that holds
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1007 // the value.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1008
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1009 const stack_frame *frame = this;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1010
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1011 for (size_t i = 0; i < frame_offset; i++)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1012 frame = frame->access_link ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1013
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1014 if (! frame)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1015 error ("internal error: invalid access link in function call stack");
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1016
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1017 if (data_offset >= frame->size ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1018 return LOCAL;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1019
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1020 return frame->get_scope_flag (data_offset);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1021 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1022
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1023 octave_value script_stack_frame::varval (const symbol_record& sym) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1024 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1025 size_t frame_offset;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1026 size_t data_offset;
26663
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
1027
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
1028 bool found = get_val_offsets (sym, frame_offset, data_offset);
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
1029
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
1030 if (! found)
fad3f19de1be don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
1031 return octave_value ();
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1032
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1033 // Follow frame_offset access links to stack frame that holds
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1034 // the value.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1035
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1036 const stack_frame *frame = this;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1037
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1038 for (size_t i = 0; i < frame_offset; i++)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1039 frame = frame->access_link ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1040
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1041 if (! frame)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1042 error ("internal error: invalid access link in function call stack");
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1043
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1044 if (data_offset >= frame->size ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1045 return octave_value ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1046
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1047 switch (frame->get_scope_flag (data_offset))
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1048 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1049 case LOCAL:
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1050 return frame->varval (data_offset);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1051
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1052 case PERSISTENT:
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1053 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1054 symbol_scope scope = frame->get_scope ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1055
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1056 return scope.persistent_varval (data_offset);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1057 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1058
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1059 case GLOBAL:
27211
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27149
diff changeset
1060 return m_evaluator.global_varval (sym.name ());
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1061 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1062
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1063 error ("internal error: invalid switch case");
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1064 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1065
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1066 octave_value& script_stack_frame::varref (const symbol_record& sym)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1067 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1068 size_t frame_offset;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1069 size_t data_offset;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1070 get_val_offsets_with_insert (sym, frame_offset, data_offset);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1071
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1072 // Follow frame_offset access links to stack frame that holds
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1073 // the value.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1074
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1075 stack_frame *frame = this;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1076
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1077 for (size_t i = 0; i < frame_offset; i++)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1078 frame = frame->access_link ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1079
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1080 if (data_offset >= frame->size ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1081 frame->resize (data_offset+1);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1082
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1083 switch (frame->get_scope_flag (data_offset))
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1084 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1085 case LOCAL:
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1086 return frame->varref (data_offset);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1087
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1088 case PERSISTENT:
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1089 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1090 symbol_scope scope = frame->get_scope ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1091
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1092 return scope.persistent_varref (data_offset);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1093 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1094
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1095 case GLOBAL:
27211
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27149
diff changeset
1096 return m_evaluator.global_varref (sym.name ());
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1097 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1098
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1099 error ("internal error: invalid switch case");
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1100 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1101
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1102 void script_stack_frame::mark_scope (const symbol_record& sym,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1103 scope_flags flag)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1104 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1105 size_t data_offset = sym.data_offset ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1106
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1107 // Redirection to evaluation context for the script.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1108
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1109 size_t frame_offset = m_lexical_frame_offsets.at (data_offset);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1110 data_offset = m_value_offsets.at (data_offset);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1111
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1112 if (frame_offset > 1)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1113 error ("variables must be made PERSISTENT or GLOBAL in the first scope in which they are used");
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1114
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1115 stack_frame *frame = access_link ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1116
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1117 if (data_offset >= frame->size ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1118 frame->resize (data_offset+1);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1119
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1120 frame->set_scope_flag (data_offset, flag);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1121 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1122
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1123 void script_stack_frame::display (bool follow) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1124 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1125 std::ostream& os = octave_stdout;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1126
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1127 os << "-- [script_stack_frame] (" << this << ") --" << std::endl;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1128 stack_frame::display (follow);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1129
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1130 os << "script: " << m_script->name ()
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1131 << " (" << m_script->type_name () << ")" << std::endl;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1132
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1133 os << "lexical_offsets: " << m_lexical_frame_offsets.size ()
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1134 << " elements:";
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1135
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1136 for (size_t i = 0; i < m_lexical_frame_offsets.size (); i++)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1137 os << " " << m_lexical_frame_offsets.at (i);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1138 os << std::endl;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1139
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1140 os << "value_offsets: " << m_value_offsets.size () << " elements:";
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1141 for (size_t i = 0; i < m_value_offsets.size (); i++)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1142 os << " " << m_value_offsets.at (i);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1143 os << std::endl;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1144
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1145 display_scope (os, get_scope ());
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1146 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1147
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1148 void script_stack_frame::accept (stack_frame_walker& sfw)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1149 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1150 sfw.visit_script_stack_frame (*this);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1151 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1152
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1153 void base_value_stack_frame::display (bool follow) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1154 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1155 std::ostream& os = octave_stdout;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1156
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1157 os << "-- [base_value_stack_frame] (" << this << ") --" << std::endl;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1158 stack_frame::display (follow);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1159
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1160 os << "values: " << m_values.size ()
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1161 << " elements (idx, scope flag, type):" << std::endl;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1162
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1163 for (size_t i = 0; i < m_values.size (); i++)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1164 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1165 os << " (" << i << ", " << m_flags.at (i) << ", ";
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1166
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1167 octave_value val = varval (i);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1168
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1169 os << (val.is_defined () ? val.type_name () : " UNDEFINED") << ")"
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1170 << std::endl;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1171 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1172 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1173
26824
d9770844392e provide virtual dup methods for stack frames
John W. Eaton <jwe@octave.org>
parents: 26673
diff changeset
1174 user_fcn_stack_frame *
d9770844392e provide virtual dup methods for stack frames
John W. Eaton <jwe@octave.org>
parents: 26673
diff changeset
1175 user_fcn_stack_frame::dup (void) const
d9770844392e provide virtual dup methods for stack frames
John W. Eaton <jwe@octave.org>
parents: 26673
diff changeset
1176 {
d9770844392e provide virtual dup methods for stack frames
John W. Eaton <jwe@octave.org>
parents: 26673
diff changeset
1177 return new user_fcn_stack_frame (*this);
d9770844392e provide virtual dup methods for stack frames
John W. Eaton <jwe@octave.org>
parents: 26673
diff changeset
1178 }
d9770844392e provide virtual dup methods for stack frames
John W. Eaton <jwe@octave.org>
parents: 26673
diff changeset
1179
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1180 // If this is a nested scope, set access_link to nearest parent
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1181 // stack frame that corresponds to the lexical parent of this scope.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1182
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1183 stack_frame *
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1184 user_fcn_stack_frame::get_access_link (octave_user_function *fcn,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1185 stack_frame *static_link)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1186 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1187 stack_frame *alink = nullptr;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1188
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1189 symbol_scope fcn_scope = fcn->scope ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1190
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1191 if (fcn_scope.is_nested ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1192 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1193 if (! static_link)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1194 error ("internal call stack error (invalid static link)");
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1195
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1196 symbol_scope caller_scope = static_link->get_scope ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1197
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1198 int nesting_depth = fcn_scope.nesting_depth ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1199 int caller_nesting_depth = caller_scope.nesting_depth ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1200
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1201 if (caller_nesting_depth < nesting_depth)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1202 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1203 // FIXME: do we need to ensure that the called
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1204 // function is a child of the caller? Does it hurt
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1205 // to assert this condition, at least for now?
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1206
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1207 alink = static_link;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1208 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1209 else
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1210 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1211 // FIXME: do we need to check that the parent of the
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1212 // called function is also a parent of the caller?
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1213 // Does it hurt to assert this condition, at least
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1214 // for now?
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1215
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1216 int links_to_follow = caller_nesting_depth - nesting_depth + 1;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1217
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1218 alink = static_link;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1219
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1220 while (alink && --links_to_follow >= 0)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1221 alink = alink->access_link ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1222
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1223 if (! alink)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1224 error ("internal function nesting error (invalid access link)");
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1225 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1226 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1227
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1228 return alink;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1229 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1230
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1231 void user_fcn_stack_frame::clear_values (void)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1232 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1233 symbol_scope fcn_scope = m_fcn->scope ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1234
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1235 const std::list<symbol_record>& symbols = fcn_scope.symbol_list ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1236
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1237 if (size () == 0)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1238 return;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1239
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1240 for (const auto& sym : symbols)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1241 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1242 size_t frame_offset = sym.frame_offset ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1243
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1244 if (frame_offset > 0)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1245 continue;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1246
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1247 size_t data_offset = sym.data_offset ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1248
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1249 if (data_offset >= size ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1250 continue;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1251
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1252 if (get_scope_flag (data_offset) == LOCAL)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1253 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1254 octave_value& ref = m_values.at (data_offset);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1255
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1256 if (ref.get_count () == 1)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1257 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1258 ref.call_object_destructor ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1259 ref = octave_value ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1260 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1261 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1262 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1263 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1264
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1265 symbol_record user_fcn_stack_frame::lookup_symbol (const std::string& name) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1266 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1267 const stack_frame *frame = this;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1268
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1269 while (frame)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1270 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1271 symbol_scope scope = frame->get_scope ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1272
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1273 symbol_record sym = scope.lookup_symbol (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1274
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1275 if (sym)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1276 return sym;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1277
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1278 frame = frame->access_link ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1279 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1280
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1281 return symbol_record ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1282 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1283
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1284 symbol_record user_fcn_stack_frame::insert_symbol (const std::string& name)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1285 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1286 // If the symbols is already in the immediate scope, there is
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1287 // nothing more to do.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1288
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1289 symbol_scope scope = get_scope ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1290
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1291 symbol_record sym = scope.lookup_symbol (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1292
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1293 if (sym)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1294 return sym;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1295
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1296 // FIXME: This needs some thought... We may need to add a symbol to
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1297 // a static workspace, but the symbol can never be defined as a
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1298 // variable. This currently works by tagging the added symbol as
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1299 // "added_static". Aside from the bad name, this doesn't seem like
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1300 // the best solution. Maybe scopes should have a separate set of
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1301 // symbols that may only be defined as functions?
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1302
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1303 // Insert the symbol in the current scope. This is not possible for
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1304 // anonymous functions, nested functions, or functions that contain
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1305 // nested functions (their scopes will all be marked static).
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1306
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1307 // if (scope.is_static ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1308 // error ("can not add variable '%s' to a static workspace",
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1309 // name.c_str ());
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1310
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1311 // At this point, non-local references are not possible so we only
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1312 // need to look in the current scope and insert there. This
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1313 // operation should never fail.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1314
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1315 sym = scope.find_symbol (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1316
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1317 assert (sym);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1318
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1319 return sym;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1320 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1321
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1322 stack_frame::scope_flags
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1323 user_fcn_stack_frame::scope_flag (const symbol_record& sym) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1324 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1325 size_t frame_offset = sym.frame_offset ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1326 size_t data_offset = sym.data_offset ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1327
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1328 // Follow frame_offset access links to stack frame that holds
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1329 // the value.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1330
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1331 const stack_frame *frame = this;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1332
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1333 for (size_t i = 0; i < frame_offset; i++)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1334 frame = frame->access_link ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1335
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1336 if (! frame)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1337 error ("internal error: invalid access link in function call stack");
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1338
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1339 if (data_offset >= frame->size ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1340 return LOCAL;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1341
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1342 return frame->get_scope_flag (data_offset);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1343 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1344
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1345 octave_value user_fcn_stack_frame::varval (const symbol_record& sym) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1346 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1347 size_t frame_offset = sym.frame_offset ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1348 size_t data_offset = sym.data_offset ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1349
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1350 // Follow frame_offset access links to stack frame that holds
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1351 // the value.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1352
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1353 const stack_frame *frame = this;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1354
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1355 for (size_t i = 0; i < frame_offset; i++)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1356 frame = frame->access_link ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1357
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1358 if (! frame)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1359 error ("internal error: invalid access link in function call stack");
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1360
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1361 if (data_offset >= frame->size ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1362 return octave_value ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1363
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1364 switch (frame->get_scope_flag (data_offset))
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1365 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1366 case LOCAL:
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1367 return frame->varval (data_offset);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1368
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1369 case PERSISTENT:
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1370 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1371 symbol_scope scope = frame->get_scope ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1372
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1373 return scope.persistent_varval (data_offset);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1374 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1375
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1376 case GLOBAL:
27211
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27149
diff changeset
1377 return m_evaluator.global_varval (sym.name ());
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1378 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1379
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1380 error ("internal error: invalid switch case");
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1381 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1382
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1383 octave_value& user_fcn_stack_frame::varref (const symbol_record& sym)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1384 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1385 size_t frame_offset = sym.frame_offset ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1386 size_t data_offset = sym.data_offset ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1387
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1388 // Follow frame_offset access links to stack frame that holds
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1389 // the value.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1390
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1391 stack_frame *frame = this;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1392
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1393 for (size_t i = 0; i < frame_offset; i++)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1394 frame = frame->access_link ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1395
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1396 if (data_offset >= frame->size ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1397 frame->resize (data_offset+1);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1398
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1399 switch (frame->get_scope_flag (data_offset))
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1400 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1401 case LOCAL:
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1402 return frame->varref (data_offset);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1403
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1404 case PERSISTENT:
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1405 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1406 symbol_scope scope = frame->get_scope ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1407
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1408 return scope.persistent_varref (data_offset);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1409 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1410
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1411 case GLOBAL:
27211
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27149
diff changeset
1412 return m_evaluator.global_varref (sym.name ());
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1413 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1414
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1415 error ("internal error: invalid switch case");
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1416 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1417
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1418 void user_fcn_stack_frame::mark_scope (const symbol_record& sym, scope_flags flag)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1419 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1420 size_t frame_offset = sym.frame_offset ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1421
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1422 if (frame_offset > 0 && (flag == PERSISTENT || flag == GLOBAL))
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1423 error ("variables must be made PERSISTENT or GLOBAL in the first scope in which they are used");
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1424
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1425 size_t data_offset = sym.data_offset ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1426
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1427 if (data_offset >= size ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1428 resize (data_offset+1);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1429
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1430 set_scope_flag (data_offset, flag);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1431 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1432
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1433 void user_fcn_stack_frame::display (bool follow) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1434 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1435 std::ostream& os = octave_stdout;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1436
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1437 os << "-- [user_fcn_stack_frame] (" << this << ") --" << std::endl;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1438 base_value_stack_frame::display (follow);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1439
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1440 os << "fcn: " << m_fcn->name ()
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1441 << " (" << m_fcn->type_name () << ")" << std::endl;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1442
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1443 display_scope (os, get_scope ());
27932
b018f553fd85 maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents: 27923
diff changeset
1444 }
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1445
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1446 void user_fcn_stack_frame::accept (stack_frame_walker& sfw)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1447 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1448 sfw.visit_user_fcn_stack_frame (*this);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1449 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1450
26824
d9770844392e provide virtual dup methods for stack frames
John W. Eaton <jwe@octave.org>
parents: 26673
diff changeset
1451 scope_stack_frame *
d9770844392e provide virtual dup methods for stack frames
John W. Eaton <jwe@octave.org>
parents: 26673
diff changeset
1452 scope_stack_frame::dup (void) const
d9770844392e provide virtual dup methods for stack frames
John W. Eaton <jwe@octave.org>
parents: 26673
diff changeset
1453 {
d9770844392e provide virtual dup methods for stack frames
John W. Eaton <jwe@octave.org>
parents: 26673
diff changeset
1454 return new scope_stack_frame (*this);
d9770844392e provide virtual dup methods for stack frames
John W. Eaton <jwe@octave.org>
parents: 26673
diff changeset
1455 }
d9770844392e provide virtual dup methods for stack frames
John W. Eaton <jwe@octave.org>
parents: 26673
diff changeset
1456
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1457 symbol_record scope_stack_frame::insert_symbol (const std::string& name)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1458 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1459 // There is no access link for scope frames, so there is no other
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1460 // frame to search in and the offset must be zero.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1461
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1462 symbol_record sym = m_scope.lookup_symbol (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1463
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1464 if (sym)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1465 return sym;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1466
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1467 // If the symbol is not found, insert it. We only need to search in
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1468 // the local scope object. This operation should never fail.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1469
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1470 sym = m_scope.find_symbol (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1471
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1472 assert (sym);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1473
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1474 return sym;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1475 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1476
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1477 stack_frame::scope_flags
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1478 scope_stack_frame::scope_flag (const symbol_record& sym) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1479 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1480 // There is no access link for scope frames, so the frame
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1481 // offset must be zero.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1482
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1483 size_t data_offset = sym.data_offset ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1484
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1485 if (data_offset >= size ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1486 return LOCAL;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1487
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1488 return get_scope_flag (data_offset);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1489 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1490
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1491 octave_value scope_stack_frame::varval (const symbol_record& sym) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1492 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1493 // There is no access link for scope frames, so the frame
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1494 // offset must be zero.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1495
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1496 size_t data_offset = sym.data_offset ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1497
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1498 if (data_offset >= size ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1499 return octave_value ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1500
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1501 switch (get_scope_flag (data_offset))
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1502 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1503 case LOCAL:
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1504 return m_values.at (data_offset);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1505
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1506 case PERSISTENT:
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1507 return m_scope.persistent_varval (data_offset);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1508
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1509 case GLOBAL:
27211
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27149
diff changeset
1510 return m_evaluator.global_varval (sym.name ());
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1511 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1512
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1513 error ("internal error: invalid switch case");
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1514 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1515
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1516 octave_value& scope_stack_frame::varref (const symbol_record& sym)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1517 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1518 // There is no access link for scope frames, so the frame
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1519 // offset must be zero.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1520
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1521 size_t data_offset = sym.data_offset ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1522
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1523 if (data_offset >= size ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1524 resize (data_offset+1);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1525
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1526 switch (get_scope_flag (data_offset))
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1527 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1528 case LOCAL:
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1529 return m_values.at (data_offset);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1530
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1531 case PERSISTENT:
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1532 return m_scope.persistent_varref (data_offset);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1533
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1534 case GLOBAL:
27211
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27149
diff changeset
1535 return m_evaluator.global_varref (sym.name ());
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1536 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1537
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1538 error ("internal error: invalid switch case");
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1539 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1540
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1541 void scope_stack_frame::mark_scope (const symbol_record& sym,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1542 scope_flags flag)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1543 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1544 // There is no access link for scope frames, so the frame
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1545 // offset must be zero.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1546
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1547 size_t data_offset = sym.data_offset ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1548
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1549 if (data_offset >= size ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1550 resize (data_offset+1);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1551
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1552 set_scope_flag (data_offset, flag);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1553 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1554
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1555 void scope_stack_frame::display (bool follow) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1556 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1557 std::ostream& os = octave_stdout;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1558
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1559 os << "-- [scope_stack_frame] (" << this << ") --" << std::endl;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1560 base_value_stack_frame::display (follow);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1561
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1562 display_scope (os, m_scope);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1563 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1564
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1565 void scope_stack_frame::accept (stack_frame_walker& sfw)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1566 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1567 sfw.visit_scope_stack_frame (*this);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1568 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1569 }