Mercurial > octave
annotate libinterp/corefcn/stack-frame.cc @ 26663:fad3f19de1be
don't fail if symbol in script can't be found (bug #55626)
* stack-frame.h, stack-frame.cc
(script_stack_frame::get_val_offsets_internal): New function.
(script_stack_frame::get_val_offsets): Return flag indicating whether
symbol is found instead of crashing if it is missing. If frame_offset
is zero and data_offset is out of range, call get_val_offsets_internal
to attempt to find symbol in parent scopes.
(script_stack_frame::varval): If symbol can't be found, return
undefined value.
(script_stack_frame::scope_flag): If symbol can't be found, return
LOCAL flag.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 01 Feb 2019 20:44:15 +0000 |
parents | cf9e10ce3351 |
children | 4271b53b24a6 |
rev | line source |
---|---|
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1 /* |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
2 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
3 Copyright (C) 1995-2018 John W. Eaton |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
4 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
5 This file is part of Octave. |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
6 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
7 Octave is free software: you can redistribute it and/or modify it |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
10 (at your option) any later version. |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
11 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
15 GNU General Public License for more details. |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
16 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
17 You should have received a copy of the GNU General Public License |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
18 along with Octave; see the file COPYING. If not, see |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
19 <https://www.gnu.org/licenses/>. |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
20 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
21 */ |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
22 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
23 #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
|
24 # include "config.h" |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
25 #endif |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
26 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
27 #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
|
28 #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
|
29 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
30 #include "call-stack.h" |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
31 #include "defun.h" |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
32 #include "interpreter.h" |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
33 #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
|
34 #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
|
35 #include "ov.h" |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
36 #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
|
37 #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
|
38 #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
|
39 #include "pager.h" |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
40 #include "parse.h" |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
41 #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
|
42 #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
|
43 #include "syminfo.h" |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
44 #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
|
45 #include "symrec.h" |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
46 #include "symscope.h" |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
47 #include "variables.h" |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
48 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
49 namespace octave |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
50 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
51 // 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
|
52 // 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
|
53 // 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
|
54 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
55 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
|
56 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
57 if (scope) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
58 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
59 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
|
60 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
61 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
|
62 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
63 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
|
64 << std::endl; |
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 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
|
67 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
68 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
|
69 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
70 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
|
71 << ", " << 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
|
72 << ")" << std::endl; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
73 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
74 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
75 } |
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 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
|
79 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
80 public: |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
81 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
82 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
|
83 : 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
|
84 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
|
85 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
|
86 { } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
87 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
88 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
|
89 : 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
|
90 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
|
91 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
|
92 { } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
93 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
94 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
|
95 : 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
|
96 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
|
97 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
|
98 { } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
99 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
100 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
|
101 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
102 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
|
103 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
104 ~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
|
105 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
106 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
|
107 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
108 // 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
|
109 // 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
|
110 // link? |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
111 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
112 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
|
113 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
114 if (slink) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
115 slink->accept (*this); |
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 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
118 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
|
119 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
120 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
|
121 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
122 if (alink) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
123 alink->accept (*this); |
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 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
126 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
|
127 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
128 clean_frame (frame); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
129 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
130 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
|
131 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
132 if (alink) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
133 alink->accept (*this); |
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 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
136 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
|
137 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
138 clean_frame (frame); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
139 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
140 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
|
141 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
142 if (alink) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
143 alink->accept (*this); |
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 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
146 private: |
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 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
|
149 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
150 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
|
151 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
152 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
|
153 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
154 // 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
|
155 // 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
|
156 // 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
|
157 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
158 // 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
|
159 // 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
|
160 // 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
|
161 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
162 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
|
163 return; |
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 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
|
166 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
167 frame.clear (sym); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
168 } |
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 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
171 // 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
|
172 // function. |
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 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
|
175 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
|
176 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
177 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
|
178 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
179 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
|
180 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
|
181 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
182 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
|
183 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
184 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
|
185 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
186 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
|
187 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
188 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
|
189 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
190 regexp pat (pattern); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
191 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
192 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
|
193 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
194 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
|
195 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
|
196 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
197 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
198 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
199 else |
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 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
|
202 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
203 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
|
204 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
205 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
|
206 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
207 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
|
208 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
209 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
|
210 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
211 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
|
212 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
|
213 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
214 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
215 } |
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 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
|
219 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
220 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
|
221 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
222 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
|
223 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
224 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
|
225 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
|
226 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
227 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
228 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
|
229 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
230 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
|
231 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
|
232 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
|
233 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
234 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
|
235 }; |
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 // 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
|
238 // 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
|
239 // 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
|
240 // 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
|
241 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
242 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
|
243 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
244 panic_impossible (); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
245 } |
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 // 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
|
248 // 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
|
249 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
250 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
|
251 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
252 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
|
253 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
254 accept (sia); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
255 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
256 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
|
257 } |
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 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
|
260 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
|
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> retval; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
263 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
264 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
|
265 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
266 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
|
267 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
268 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
|
269 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
270 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
|
271 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
272 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
|
273 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
274 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
|
275 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
276 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
|
277 continue; |
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 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
|
280 } |
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 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
283 return retval; |
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 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
|
287 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
|
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> retval; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
290 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
291 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
|
292 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
293 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
|
294 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
295 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
|
296 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
297 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
|
298 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
299 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
|
300 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
301 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
|
302 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
303 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
|
304 continue; |
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 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
|
307 } |
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 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
310 return retval; |
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 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
|
314 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
315 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
|
316 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
317 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
|
318 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
319 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
|
320 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
321 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
|
322 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
323 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
|
324 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
|
325 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
326 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
327 retval.sort (); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
328 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
329 return retval; |
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 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
|
333 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
334 // 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
|
335 // 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
|
336 // the implementation. |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
337 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
338 panic_impossible (); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
339 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
340 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
341 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
|
342 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
343 // 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
|
344 // 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
|
345 // the implementation. |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
346 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
347 panic_impossible (); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
348 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
349 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
350 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
|
351 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
352 // 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
|
353 // 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
|
354 // the implementation. |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
355 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
356 panic_impossible (); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
357 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
358 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
359 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
|
360 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
361 // 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
|
362 // 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
|
363 // the implementation. |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
364 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
365 panic_impossible (); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
366 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
367 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
368 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
|
369 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
|
370 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
371 if (global) |
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 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
|
374 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
375 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
|
376 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
377 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
|
378 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
379 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
|
380 "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
|
381 nm.c_str ()); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
382 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
|
383 "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
|
384 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
385 // 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
|
386 // 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
|
387 // 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
|
388 // initializer in the global statement. |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
389 octave_value global_val = m_call_stack.global_varval (nm); |
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 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
|
392 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
393 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
|
394 "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
|
395 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
396 clear (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 else |
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 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
|
401 "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
|
402 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
403 m_call_stack.global_varref (nm) = val; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
404 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
405 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
406 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
407 mark_global (sym); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
408 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
409 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
410 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
|
411 assign (sym, value); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
412 } |
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 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
|
415 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
416 // 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
|
417 // 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
|
418 // the implementation. |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
419 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
420 panic_impossible (); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
421 } |
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 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
|
424 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
425 // 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
|
426 // 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
|
427 // the implementation. |
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 panic_impossible (); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
430 } |
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 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
|
433 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
434 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
|
435 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
436 accept (sc); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
437 } |
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 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
|
440 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
441 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
|
442 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
443 accept (sc); |
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 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
|
447 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
448 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
|
449 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
450 accept (sc); |
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 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
453 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
|
454 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
455 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
|
456 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
457 accept (sc); |
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 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
460 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
|
461 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
462 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
|
463 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
464 accept (sc); |
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 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
467 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
|
468 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
469 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
|
470 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
471 accept (sc); |
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 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
474 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
|
475 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
476 symbol_cleaner sc; |
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 accept (sc); |
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 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
481 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
|
482 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
483 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
|
484 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
485 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
|
486 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
487 os << "static link: "; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
488 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
|
489 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
|
490 else |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
491 os << "NULL"; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
492 os << std::endl; |
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 os << "access link: "; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
495 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
|
496 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
|
497 else |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
498 os << "NULL"; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
499 os << std::endl; |
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 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
|
502 os << "column: " << m_column << std::endl; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
503 os << "prev: " << m_prev << std::endl; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
504 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
505 os << std::endl; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
506 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
507 if (! follow) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
508 return; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
509 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
510 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
|
511 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
|
512 while (frm) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
513 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
514 frm->display (false); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
515 os << std::endl; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
516 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
517 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
|
518 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
519 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
520 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
521 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
|
522 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
523 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
|
524 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
525 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
|
526 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
|
527 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
528 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
|
529 << " (" << 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
|
530 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
531 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
532 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
|
533 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
534 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
|
535 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
536 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
537 script_stack_frame::script_stack_frame (call_stack& cs, |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
538 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
|
539 unwind_protect *up_frame, |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
540 size_t prev, |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
541 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
|
542 : stack_frame (cs, prev, static_link, get_access_link (static_link)), |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
543 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
|
544 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
|
545 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
|
546 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
547 set_script_offsets (); |
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 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
550 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
|
551 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
552 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
|
553 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
554 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
|
555 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
556 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
557 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
|
558 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
559 // 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
|
560 // scope(s). |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
561 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
562 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
|
563 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
564 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
|
565 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
566 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
|
567 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
568 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
|
569 = script_scope.symbols (); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
570 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
571 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
|
572 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
573 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
574 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
|
575 (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
|
576 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
577 // 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
|
578 // 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
|
579 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
580 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
|
581 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
582 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
|
583 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
584 bool found = false; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
585 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
586 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
|
587 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
588 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
|
589 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
|
590 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
591 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
|
592 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
593 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
|
594 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
595 while (parent_scope) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
596 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
597 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
|
598 = parent_scope.symbols (); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
599 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
600 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
|
601 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
602 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
|
603 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
604 found = true; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
605 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
|
606 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
607 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
|
608 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
609 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
|
610 = 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
|
611 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
612 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
|
613 = 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
|
614 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
615 break; |
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 else |
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 count++; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
620 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
|
621 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
622 } |
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 if (! found) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
625 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
|
626 name.c_str ()); |
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 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
629 else |
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 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
|
632 = eval_scope.symbols (); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
633 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
634 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
|
635 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
636 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
|
637 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
|
638 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
639 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
|
640 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
641 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
|
642 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
643 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
|
644 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
|
645 else |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
646 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
|
647 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
648 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
|
649 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
650 // 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
|
651 // 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
|
652 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
653 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
|
654 = 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
|
655 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
656 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
|
657 = 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
|
658 } |
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 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
661 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
662 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
|
663 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
664 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
|
665 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
666 // 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
|
667 // 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
|
668 // 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
|
669 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
670 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
|
671 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
672 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
|
673 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
674 // 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
|
675 // 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
|
676 // 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
|
677 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
678 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
|
679 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
|
680 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
|
681 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
682 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
683 // 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
|
684 // 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
|
685 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
686 stack_frame * |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
687 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
|
688 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
689 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
|
690 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
691 // 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
|
692 // 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
|
693 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
694 alink = static_link; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
695 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
696 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
|
697 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
698 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
|
699 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
|
700 else |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
701 break; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
702 } |
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 return alink; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
705 } |
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 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
|
708 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
709 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
|
710 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
711 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
|
712 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
713 if (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 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
|
716 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
717 return sym; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
718 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
719 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
720 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
|
721 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
722 // 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
|
723 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
|
724 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
725 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
|
726 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
727 return new_sym; |
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 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
730 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
|
731 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
732 // 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
|
733 // 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
|
734 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
735 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
|
736 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
737 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
|
738 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
739 if (sym) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
740 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
741 // 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
|
742 // 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
|
743 // 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
|
744 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
|
745 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
746 return sym; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
747 } |
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 // 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
|
750 // 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
|
751 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
752 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
|
753 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
754 assert (sym); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
755 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
756 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
|
757 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
758 return sym; |
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 |
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
|
761 // 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
|
762 // 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
|
763 // 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
|
764 |
fad3f19de1be
don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
765 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
|
766 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
|
767 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
|
768 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
|
769 { |
fad3f19de1be
don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
770 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
|
771 |
fad3f19de1be
don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
772 // 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
|
773 // 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
|
774 |
fad3f19de1be
don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
775 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
|
776 |
fad3f19de1be
don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
777 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
|
778 { |
fad3f19de1be
don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
779 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
|
780 |
fad3f19de1be
don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
781 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
|
782 |
fad3f19de1be
don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
783 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
|
784 |
fad3f19de1be
don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
785 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
|
786 { |
fad3f19de1be
don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
787 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
|
788 = 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
|
789 |
fad3f19de1be
don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
790 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
|
791 |
fad3f19de1be
don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
792 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
|
793 { |
fad3f19de1be
don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
794 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
|
795 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
|
796 |
fad3f19de1be
don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
797 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
|
798 |
fad3f19de1be
don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
799 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
|
800 |
fad3f19de1be
don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
801 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
|
802 } |
fad3f19de1be
don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
803 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
|
804 { |
fad3f19de1be
don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
805 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
|
806 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
|
807 } |
fad3f19de1be
don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
808 } |
fad3f19de1be
don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
809 } |
fad3f19de1be
don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
810 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
|
811 { |
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 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
|
813 = 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
|
814 |
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 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
|
816 |
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 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
|
818 |
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 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
|
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 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
|
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 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
|
824 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
|
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 // 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
|
827 // 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
|
828 |
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 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
|
830 |
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 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
|
832 } |
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 |
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 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
|
836 } |
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 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
|
839 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
|
840 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
|
841 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
842 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
|
843 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
|
844 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
845 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
|
846 { |
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
|
847 // 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
|
848 // 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
|
849 // 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
|
850 // 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
|
851 // to do. |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
852 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
853 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
|
854 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
|
855 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
856 // 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
|
857 // 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
|
858 // 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
|
859 // 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
|
860 // invoked. |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
861 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
862 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
|
863 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
|
864 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
865 else |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
866 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
867 // 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
|
868 // 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
|
869 // 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
|
870 } |
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
|
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 return true; |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
873 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
874 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
875 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
|
876 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
|
877 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
|
878 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
879 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
|
880 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
|
881 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
882 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
|
883 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
884 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
|
885 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
886 // 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
|
887 // 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
|
888 // update the offsets. |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
889 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
890 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
|
891 } |
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 // 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
|
894 // 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
|
895 // 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
|
896 // 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
|
897 // invoked. |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
898 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
899 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
|
900 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
|
901 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
902 else |
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 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
|
905 // 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
|
906 // 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
|
907 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
908 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
909 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
910 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
|
911 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
|
912 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
913 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
|
914 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
|
915 |
fad3f19de1be
don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
916 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
|
917 |
fad3f19de1be
don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
918 // 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
|
919 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
|
920 return LOCAL; |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
921 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
922 // 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
|
923 // the value. |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
924 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
925 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
|
926 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
927 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
|
928 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
|
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) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
931 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
|
932 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
933 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
|
934 return LOCAL; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
935 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
936 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
|
937 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
938 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
939 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
|
940 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
941 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
|
942 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
|
943 |
fad3f19de1be
don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
944 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
|
945 |
fad3f19de1be
don't fail if symbol in script can't be found (bug #55626)
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
946 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
|
947 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
|
948 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
949 // 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
|
950 // the value. |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
951 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
952 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
|
953 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
954 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
|
955 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
|
956 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
957 if (! frame) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
958 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
|
959 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
960 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
|
961 return octave_value (); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
962 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
963 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
|
964 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
965 case LOCAL: |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
966 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
|
967 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
968 case PERSISTENT: |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
969 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
970 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
|
971 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
972 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
|
973 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
974 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
975 case GLOBAL: |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
976 return m_call_stack.global_varval (sym.name ()); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
977 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
978 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
979 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
|
980 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
981 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
982 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
|
983 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
984 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
|
985 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
|
986 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
|
987 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
988 // 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
|
989 // the value. |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
990 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
991 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
|
992 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
993 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
|
994 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
|
995 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
996 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
|
997 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
|
998 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
999 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
|
1000 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1001 case LOCAL: |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1002 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
|
1003 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1004 case PERSISTENT: |
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 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
|
1007 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1008 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
|
1009 } |
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 case GLOBAL: |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1012 return m_call_stack.global_varref (sym.name ()); |
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 |
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 switch case"); |
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 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1018 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
|
1019 scope_flags flag) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1020 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1021 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
|
1022 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1023 // 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
|
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 = 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
|
1026 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
|
1027 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1028 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
|
1029 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
|
1030 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1031 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
|
1032 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1033 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
|
1034 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
|
1035 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1036 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
|
1037 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1038 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1039 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
|
1040 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1041 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
|
1042 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1043 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
|
1044 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
|
1045 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1046 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
|
1047 << " (" << 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
|
1048 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1049 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
|
1050 << " elements:"; |
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 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
|
1053 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
|
1054 os << std::endl; |
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 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
|
1057 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
|
1058 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
|
1059 os << std::endl; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1060 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1061 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
|
1062 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1063 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1064 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
|
1065 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1066 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
|
1067 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1068 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1069 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
|
1070 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1071 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
|
1072 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1073 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
|
1074 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
|
1075 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1076 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
|
1077 << " 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
|
1078 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1079 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
|
1080 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1081 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
|
1082 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1083 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
|
1084 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1085 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
|
1086 << std::endl; |
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 } |
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 // 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
|
1091 // 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
|
1092 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1093 stack_frame * |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1094 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
|
1095 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
|
1096 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1097 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
|
1098 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1099 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
|
1100 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1101 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
|
1102 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1103 if (! static_link) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1104 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
|
1105 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1106 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
|
1107 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1108 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
|
1109 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
|
1110 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1111 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
|
1112 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1113 // 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
|
1114 // 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
|
1115 // 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
|
1116 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1117 alink = static_link; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1118 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1119 else |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1120 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1121 // 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
|
1122 // 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
|
1123 // 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
|
1124 // for now? |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1125 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1126 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
|
1127 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1128 alink = static_link; |
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 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
|
1131 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
|
1132 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1133 if (! alink) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1134 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
|
1135 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1136 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1137 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1138 return alink; |
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 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1141 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
|
1142 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1143 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
|
1144 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1145 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
|
1146 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1147 if (size () == 0) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1148 return; |
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 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
|
1151 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1152 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
|
1153 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1154 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
|
1155 continue; |
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 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
|
1158 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1159 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
|
1160 continue; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1161 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1162 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
|
1163 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1164 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
|
1165 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1166 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
|
1167 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1168 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
|
1169 ref = octave_value (); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1170 } |
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 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1174 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1175 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
|
1176 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1177 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
|
1178 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1179 while (frame) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1180 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1181 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
|
1182 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1183 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
|
1184 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1185 if (sym) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1186 return sym; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1187 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1188 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
|
1189 } |
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 return symbol_record (); |
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 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1194 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
|
1195 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1196 // 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
|
1197 // 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
|
1198 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1199 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
|
1200 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1201 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
|
1202 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1203 if (sym) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1204 return sym; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1205 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1206 // 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
|
1207 // 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
|
1208 // 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
|
1209 // "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
|
1210 // 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
|
1211 // 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
|
1212 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1213 // 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
|
1214 // 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
|
1215 // 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
|
1216 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1217 // 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
|
1218 // 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
|
1219 // name.c_str ()); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1220 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1221 // 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
|
1222 // 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
|
1223 // 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
|
1224 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1225 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
|
1226 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1227 assert (sym); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1228 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1229 return sym; |
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 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1232 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
|
1233 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
|
1234 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1235 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
|
1236 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
|
1237 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1238 // 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
|
1239 // the value. |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1240 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1241 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
|
1242 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1243 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
|
1244 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
|
1245 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1246 if (! frame) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1247 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
|
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 >= frame->size ()) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1250 return LOCAL; |
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 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
|
1253 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1254 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1255 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
|
1256 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1257 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
|
1258 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
|
1259 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1260 // 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
|
1261 // the value. |
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 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
|
1264 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1265 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
|
1266 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
|
1267 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1268 if (! frame) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1269 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
|
1270 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1271 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
|
1272 return octave_value (); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1273 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1274 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
|
1275 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1276 case LOCAL: |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1277 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
|
1278 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1279 case PERSISTENT: |
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 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
|
1282 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1283 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
|
1284 } |
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 case GLOBAL: |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1287 return m_call_stack.global_varval (sym.name ()); |
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 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1290 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
|
1291 } |
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 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
|
1294 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1295 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
|
1296 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
|
1297 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1298 // 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
|
1299 // the value. |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1300 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1301 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
|
1302 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1303 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
|
1304 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
|
1305 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1306 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
|
1307 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
|
1308 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1309 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
|
1310 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1311 case LOCAL: |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1312 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
|
1313 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1314 case PERSISTENT: |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1315 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1316 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
|
1317 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1318 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
|
1319 } |
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 case GLOBAL: |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1322 return m_call_stack.global_varref (sym.name ()); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1323 } |
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 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
|
1326 } |
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 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
|
1329 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1330 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
|
1331 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1332 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
|
1333 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
|
1334 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1335 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
|
1336 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1337 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
|
1338 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
|
1339 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1340 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
|
1341 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1342 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1343 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
|
1344 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1345 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
|
1346 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1347 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
|
1348 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
|
1349 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1350 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
|
1351 << " (" << 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
|
1352 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1353 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
|
1354 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1355 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1356 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
|
1357 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1358 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
|
1359 } |
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 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
|
1362 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1363 // 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
|
1364 // 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
|
1365 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1366 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
|
1367 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1368 if (sym) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1369 return sym; |
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 // 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
|
1372 // 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
|
1373 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1374 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
|
1375 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1376 assert (sym); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1377 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1378 return sym; |
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 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1381 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
|
1382 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
|
1383 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1384 // 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
|
1385 // 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
|
1386 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1387 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
|
1388 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1389 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
|
1390 return LOCAL; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1391 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1392 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
|
1393 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1394 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1395 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
|
1396 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1397 // 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
|
1398 // 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
|
1399 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1400 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
|
1401 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1402 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
|
1403 return octave_value (); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1404 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1405 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
|
1406 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1407 case LOCAL: |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1408 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
|
1409 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1410 case PERSISTENT: |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1411 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
|
1412 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1413 case GLOBAL: |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1414 return m_call_stack.global_varval (sym.name ()); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1415 } |
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 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
|
1418 } |
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 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
|
1421 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1422 // 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
|
1423 // 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
|
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 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
|
1431 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1432 case LOCAL: |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1433 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
|
1434 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1435 case PERSISTENT: |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1436 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
|
1437 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1438 case GLOBAL: |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1439 return m_call_stack.global_varref (sym.name ()); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1440 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1441 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1442 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
|
1443 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1444 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1445 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
|
1446 scope_flags flag) |
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 // 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
|
1449 // 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
|
1450 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1451 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
|
1452 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1453 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
|
1454 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
|
1455 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1456 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
|
1457 } |
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 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
|
1460 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1461 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
|
1462 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1463 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
|
1464 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
|
1465 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1466 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
|
1467 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1468 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1469 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
|
1470 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1471 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
|
1472 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1473 } |