Mercurial > octave
annotate libinterp/corefcn/symscope.cc @ 26661:cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
Apologies for the massive commit. I see no way to untangle these
changes into a set of smaller incremental changes in a way that would
be more useful.
Previously, handling data for recursive function calls was managed by
a stack of values in the symbol_record class and an auxiliary integer
variable was used for managing the recursion depth (context_id). Now,
values for local variables are in the stack_frame class and recursion
is handled naturally by the call_stack as a new stack frame is added
to the call_stack object for any call to a function or a script.
Values for internal function call information (nargin, nargout, etc.)
are now stored specially in the stack_frame object. Values for global
variables are now stored in a map in the call_stack object. Values
for persistent variables are stored in the corresponding
octave_user_function object. Access to non-local variables inside
nested functions is managed through pointers to stack_frame objects
for the parent function scopes. The new implementation more closely
resembles the techniques described in standard compiler literature.
These changes should make it easier to create proper closures and
finally solve bug #39257 (handles to nested functions are not yet
supported). They may also make it easier to implement JIT compiler,
though that is probably still a long way off.
The new stack-frame.h file has some details about the new
implementation of stack frames that should help in understanding how
things work now.
Describing each change to each file and function will probably not
provide much greater understanding of the changes and would be quite
tedious to write so I am omitting them.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 28 Jan 2019 18:01:46 +0000 |
parents | 00f796120a6d |
children | b442ec6dda5c |
rev | line source |
---|---|
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1 /* |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
2 |
26376
00f796120a6d
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
26119
diff
changeset
|
3 Copyright (C) 1993-2019 John W. Eaton |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
4 Copyright (C) 2009 VZLU Prague, a.s. |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
5 |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
6 This file is part of Octave. |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
7 |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24361
diff
changeset
|
8 Octave is free software: you can redistribute it and/or modify it |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
9 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24361
diff
changeset
|
10 the Free Software Foundation, either version 3 of the License, or |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
11 (at your option) any later version. |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
12 |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
13 Octave is distributed in the hope that it will be useful, but |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
14 WITHOUT ANY WARRANTY; without even the implied warranty of |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
16 GNU General Public License for more details. |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
17 |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
18 You should have received a copy of the GNU General Public License |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
19 along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24361
diff
changeset
|
20 <https://www.gnu.org/licenses/>. |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
21 |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
22 */ |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
23 |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
24 #if defined (HAVE_CONFIG_H) |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
25 # include "config.h" |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
26 #endif |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
27 |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
28 #include <sstream> |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
29 |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
30 #include "fcn-info.h" |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
31 #include "interpreter-private.h" |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
32 #include "interpreter.h" |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
33 #include "ov-fcn.h" |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
34 #include "ov-usr-fcn.h" |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
35 #include "symrec.h" |
24269
f494b87d2a93
rename scope to symbol_scope
John W. Eaton <jwe@octave.org>
parents:
24263
diff
changeset
|
36 #include "symscope.h" |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
37 #include "utils.h" |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
38 |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
39 namespace octave |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
40 { |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
41 symbol_record symbol_scope_rep::insert_local (const std::string& name) |
26040
0af4653e48a4
install auto function vars in symbol scope when parsing function
John W. Eaton <jwe@octave.org>
parents:
25201
diff
changeset
|
42 { |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
43 symbol_record sym (name); |
26040
0af4653e48a4
install auto function vars in symbol scope when parsing function
John W. Eaton <jwe@octave.org>
parents:
25201
diff
changeset
|
44 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
45 insert_symbol_record (sym); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
46 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
47 return sym; |
26040
0af4653e48a4
install auto function vars in symbol scope when parsing function
John W. Eaton <jwe@octave.org>
parents:
25201
diff
changeset
|
48 } |
0af4653e48a4
install auto function vars in symbol scope when parsing function
John W. Eaton <jwe@octave.org>
parents:
25201
diff
changeset
|
49 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
50 void symbol_scope_rep::insert_symbol_record (symbol_record& sr) |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
51 { |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
52 size_t data_offset = num_symbols (); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
53 std::string name = sr.name (); |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
54 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
55 sr.set_data_offset (data_offset); |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
56 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
57 m_symbols[name] = sr; |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
58 } |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
59 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
60 symbol_record symbol_scope_rep::insert (const std::string& name) |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
61 { |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
62 table_iterator p = m_symbols.find (name); |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
63 |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
64 if (p == m_symbols.end ()) |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
65 { |
24356
8b14ba8296af
refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents:
24352
diff
changeset
|
66 symbol_record ret (name); |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
67 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
68 size_t data_offset = num_symbols (); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
69 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
70 ret.set_data_offset (data_offset); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
71 |
24706
30e1d0bf7ade
use weak_ptr for symbol_scope_rep and symbol_record_rep pointers (bug #53092)
John W. Eaton <jwe@octave.org>
parents:
24705
diff
changeset
|
72 auto t_parent = m_parent.lock (); |
30e1d0bf7ade
use weak_ptr for symbol_scope_rep and symbol_record_rep pointers (bug #53092)
John W. Eaton <jwe@octave.org>
parents:
24705
diff
changeset
|
73 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
74 size_t offset = 0; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
75 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
76 if (is_nested () && t_parent |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
77 && t_parent->look_nonlocal (name, offset, ret)) |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
78 return m_symbols[name] = ret; |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
79 else |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
80 { |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
81 if (m_is_static) |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
82 ret.mark_added_static (); |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
83 |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
84 return m_symbols[name] = ret; |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
85 } |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
86 } |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
87 else |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
88 return p->second; |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
89 } |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
90 |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
91 octave_value |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24356
diff
changeset
|
92 symbol_scope_rep::dump (void) const |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
93 { |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
94 std::map<std::string, octave_value> m |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
95 = {{ "name", m_name }, |
26060
edcb09d4b1f5
store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents:
26040
diff
changeset
|
96 { "nesting_depth", m_nesting_depth }, |
edcb09d4b1f5
store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents:
26040
diff
changeset
|
97 { "is_static", m_is_static }, |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
98 { "symbols", dump_symbols_map () }, |
26060
edcb09d4b1f5
store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents:
26040
diff
changeset
|
99 { "subfunction_names", string_vector (m_subfunction_names) }, |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
100 { "subfunctions", dump_function_map (m_subfunctions) }}; |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
101 |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
102 return octave_value (m); |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
103 } |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
104 |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
105 octave_value |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24356
diff
changeset
|
106 symbol_scope_rep::dump_symbols_map (void) const |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
107 { |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
108 std::map<std::string, octave_value> info_map; |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
109 |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
110 for (const auto& nm_sr : m_symbols) |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
111 { |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
112 std::string nm = nm_sr.first; |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
113 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:
26376
diff
changeset
|
114 info_map[nm] = sr.dump (); |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
115 } |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
116 |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
117 return octave_value (info_map); |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
118 } |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
119 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
120 std::list<symbol_record> symbol_scope_rep::symbol_list (void) const |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
121 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
122 std::list<symbol_record> retval; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
123 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
124 for (const auto& nm_sr : m_symbols) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
125 retval.push_back (nm_sr.second); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
126 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
127 return retval; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
128 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
129 |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
130 octave_value |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24356
diff
changeset
|
131 symbol_scope_rep::find_subfunction (const std::string& name) const |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
132 { |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
133 subfunctions_const_iterator p = m_subfunctions.find (name); |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
134 |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
135 if (p != m_subfunctions.end ()) |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
136 return p->second; |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
137 |
24706
30e1d0bf7ade
use weak_ptr for symbol_scope_rep and symbol_record_rep pointers (bug #53092)
John W. Eaton <jwe@octave.org>
parents:
24705
diff
changeset
|
138 auto t_parent = m_parent.lock (); |
30e1d0bf7ade
use weak_ptr for symbol_scope_rep and symbol_record_rep pointers (bug #53092)
John W. Eaton <jwe@octave.org>
parents:
24705
diff
changeset
|
139 |
30e1d0bf7ade
use weak_ptr for symbol_scope_rep and symbol_record_rep pointers (bug #53092)
John W. Eaton <jwe@octave.org>
parents:
24705
diff
changeset
|
140 if (t_parent) |
30e1d0bf7ade
use weak_ptr for symbol_scope_rep and symbol_record_rep pointers (bug #53092)
John W. Eaton <jwe@octave.org>
parents:
24705
diff
changeset
|
141 return t_parent->find_subfunction (name); |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
142 |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
143 return octave_value (); |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
144 } |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
145 |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
146 void |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24356
diff
changeset
|
147 symbol_scope_rep::mark_subfunctions_in_scope_as_private (const std::string& class_name) |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
148 { |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
149 for (auto& nm_sf : m_subfunctions) |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
150 { |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
151 octave_function *fcn = nm_sf.second.function_value (); |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
152 |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
153 if (fcn) |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
154 fcn->mark_as_private_function (class_name); |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
155 } |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
156 } |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
157 |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
158 void |
24706
30e1d0bf7ade
use weak_ptr for symbol_scope_rep and symbol_record_rep pointers (bug #53092)
John W. Eaton <jwe@octave.org>
parents:
24705
diff
changeset
|
159 symbol_scope_rep::set_parent (const std::shared_ptr<symbol_scope_rep>& parent) |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
160 { |
24706
30e1d0bf7ade
use weak_ptr for symbol_scope_rep and symbol_record_rep pointers (bug #53092)
John W. Eaton <jwe@octave.org>
parents:
24705
diff
changeset
|
161 m_parent = std::weak_ptr<symbol_scope_rep> (parent); |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
162 } |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
163 |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
164 void |
26060
edcb09d4b1f5
store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents:
26040
diff
changeset
|
165 symbol_scope_rep::set_primary_parent (const std::shared_ptr<symbol_scope_rep>& parent) |
edcb09d4b1f5
store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents:
26040
diff
changeset
|
166 { |
edcb09d4b1f5
store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents:
26040
diff
changeset
|
167 m_primary_parent = std::weak_ptr<symbol_scope_rep> (parent); |
edcb09d4b1f5
store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents:
26040
diff
changeset
|
168 } |
edcb09d4b1f5
store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents:
26040
diff
changeset
|
169 |
edcb09d4b1f5
store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents:
26040
diff
changeset
|
170 bool |
edcb09d4b1f5
store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents:
26040
diff
changeset
|
171 symbol_scope_rep::is_relative (const std::shared_ptr<symbol_scope_rep>& scope) const |
edcb09d4b1f5
store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents:
26040
diff
changeset
|
172 { |
edcb09d4b1f5
store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents:
26040
diff
changeset
|
173 if (is_nested ()) |
edcb09d4b1f5
store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents:
26040
diff
changeset
|
174 { |
edcb09d4b1f5
store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents:
26040
diff
changeset
|
175 // Since is_nested is true, the following should always return a |
edcb09d4b1f5
store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents:
26040
diff
changeset
|
176 // valid scope. |
edcb09d4b1f5
store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents:
26040
diff
changeset
|
177 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
178 auto t_parent = m_parent.lock (); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
179 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
180 if (t_parent) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
181 { |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
182 // SCOPE is the parent of this scope: this scope is a child |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
183 // of SCOPE. |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
184 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
185 if (t_parent == scope) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
186 return true; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
187 } |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
188 |
26060
edcb09d4b1f5
store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents:
26040
diff
changeset
|
189 auto t_primary_parent = m_primary_parent.lock (); |
edcb09d4b1f5
store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents:
26040
diff
changeset
|
190 |
edcb09d4b1f5
store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents:
26040
diff
changeset
|
191 if (t_primary_parent) |
edcb09d4b1f5
store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents:
26040
diff
changeset
|
192 { |
edcb09d4b1f5
store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents:
26040
diff
changeset
|
193 // SCOPE is the primary parent of this scope: this scope is a |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
194 // child (or grandchild) of SCOPE. |
26060
edcb09d4b1f5
store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents:
26040
diff
changeset
|
195 if (t_primary_parent == scope) |
edcb09d4b1f5
store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents:
26040
diff
changeset
|
196 return true; |
edcb09d4b1f5
store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents:
26040
diff
changeset
|
197 |
edcb09d4b1f5
store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents:
26040
diff
changeset
|
198 // SCOPE and this scope share the same primary parent: they are |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
199 // siblings (or cousins) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
200 auto scope_primary_parent = scope->primary_parent_scope_rep (); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
201 if (t_primary_parent == scope_primary_parent) |
26060
edcb09d4b1f5
store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents:
26040
diff
changeset
|
202 return true; |
edcb09d4b1f5
store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents:
26040
diff
changeset
|
203 } |
edcb09d4b1f5
store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents:
26040
diff
changeset
|
204 } |
edcb09d4b1f5
store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents:
26040
diff
changeset
|
205 |
edcb09d4b1f5
store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents:
26040
diff
changeset
|
206 return false; |
edcb09d4b1f5
store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents:
26040
diff
changeset
|
207 } |
edcb09d4b1f5
store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents:
26040
diff
changeset
|
208 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
209 void symbol_scope_rep::update_nest (void) |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
210 { |
24706
30e1d0bf7ade
use weak_ptr for symbol_scope_rep and symbol_record_rep pointers (bug #53092)
John W. Eaton <jwe@octave.org>
parents:
24705
diff
changeset
|
211 auto t_parent = m_parent.lock (); |
30e1d0bf7ade
use weak_ptr for symbol_scope_rep and symbol_record_rep pointers (bug #53092)
John W. Eaton <jwe@octave.org>
parents:
24705
diff
changeset
|
212 |
30e1d0bf7ade
use weak_ptr for symbol_scope_rep and symbol_record_rep pointers (bug #53092)
John W. Eaton <jwe@octave.org>
parents:
24705
diff
changeset
|
213 if (t_parent) |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
214 { |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
215 // fix bad symbol_records |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
216 for (auto& nm_sr : m_symbols) |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
217 { |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
218 symbol_record& ours = nm_sr.second; |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
219 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
220 size_t offset = 0; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
221 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
222 if (! ours.is_formal () && is_nested ()) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
223 t_parent->look_nonlocal (nm_sr.first, offset, ours); |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
224 } |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
225 |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
226 // The scopes of nested functions are static. |
26060
edcb09d4b1f5
store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents:
26040
diff
changeset
|
227 if (is_nested ()) |
24952
1fbd8afcf625
Ensure that local functions do not have a static workspace (bug #53405).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24706
diff
changeset
|
228 m_is_static = true; |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
229 } |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
230 else if (m_children.size ()) |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
231 { |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
232 // Parents of nested functions have static scopes. |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
233 m_is_static = true; |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
234 } |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
235 |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24356
diff
changeset
|
236 for (auto& scope_obj : m_children) |
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24356
diff
changeset
|
237 scope_obj.update_nest (); |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
238 } |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
239 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
240 bool symbol_scope_rep::look_nonlocal (const std::string& name, |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
241 size_t offset, symbol_record& result) |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
242 { |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
243 offset++; |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
244 |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
245 table_iterator p = m_symbols.find (name); |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
246 |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
247 if (p == m_symbols.end ()) |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
248 { |
24706
30e1d0bf7ade
use weak_ptr for symbol_scope_rep and symbol_record_rep pointers (bug #53092)
John W. Eaton <jwe@octave.org>
parents:
24705
diff
changeset
|
249 auto t_parent = m_parent.lock (); |
30e1d0bf7ade
use weak_ptr for symbol_scope_rep and symbol_record_rep pointers (bug #53092)
John W. Eaton <jwe@octave.org>
parents:
24705
diff
changeset
|
250 |
26060
edcb09d4b1f5
store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents:
26040
diff
changeset
|
251 if (is_nested () && t_parent) |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
252 return t_parent->look_nonlocal (name, offset, result); |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
253 } |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
254 else |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
255 { |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
256 // Add scope offsets because the one we found may be used in |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
257 // this scope but initially from another parent scope beyond |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
258 // that. The parent offset will already point to the first |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
259 // occurrence because we do the overall nesting update from the |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
260 // parent function down through the lists of all children. |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
261 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
262 size_t t_frame_offset = offset + p->second.frame_offset (); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
263 size_t t_data_offset = p->second.data_offset (); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
264 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
265 result.set_frame_offset (t_frame_offset); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
266 result.set_data_offset (t_data_offset); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
267 |
24263
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
268 return true; |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
269 } |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
270 |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
271 return false; |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
272 } |
3b302b2890d7
disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
273 } |