annotate libinterp/corefcn/symscope.cc @ 30105:67994b92a613

eliminate redundant storage of parent function name in function objects * ov-usr-fcn.h, ov-usr-fcn.cc (octave_user_function::m_parent_name): Delete member variable and all uses. (octave_user_function::stash_parent_fcn_name): Delete member function and all uses. (octave_user_function::parent_fcn_name): Get parent name from parent scope.
author John W. Eaton <jwe@octave.org>
date Wed, 01 Sep 2021 23:50:07 -0400
parents 761210f338c7
children 3efce22b7350
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
29358
0a5b15007766 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3 // Copyright (C) 1993-2021 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26 #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
27 # include "config.h"
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 #endif
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 <sstream>
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31
28026
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
32 #include "file-ops.h"
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
33
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 #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
35 #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
36 #include "interpreter.h"
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37 #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
38 #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
39 #include "symrec.h"
24269
f494b87d2a93 rename scope to symbol_scope
John W. Eaton <jwe@octave.org>
parents: 24263
diff changeset
40 #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
41 #include "utils.h"
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43 namespace octave
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
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 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
46 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
47 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
48
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
49 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
50
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
51 return sym;
26040
0af4653e48a4 install auto function vars in symbol scope when parsing function
John W. Eaton <jwe@octave.org>
parents: 25201
diff changeset
52 }
0af4653e48a4 install auto function vars in symbol scope when parsing function
John W. Eaton <jwe@octave.org>
parents: 25201
diff changeset
53
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
54 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
55 {
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
56 std::size_t data_offset = num_symbols ();
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
57 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
58
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
59 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
60
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
61 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
62 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
64 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
65 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66 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
67
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68 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
69 {
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24352
diff changeset
70 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
71
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
72 std::size_t data_offset = num_symbols ();
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
73
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
74 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
75
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
76 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
77
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
78 std::size_t offset = 0;
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
79
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
80 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
81 && 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
82 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
83 else
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
85 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
86 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
87
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
88 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
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 else
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
92 return p->second;
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
28432
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
95 std::list<octave_value> symbol_scope_rep::localfunctions (void) const
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
96 {
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
97 std::list<octave_value> retval;
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
98
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
99 // Find the subfunctions of this function (which should be the
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
100 // primary parent function for this scope).
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
101
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
102 // 1) m_subfunction_names contains only valid subfunctions
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
103 // 2) m_subfunctions contains both nested functions and subfunctions
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
104
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
105 // loop over them.
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
106
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
107 for (const auto& nm : m_subfunction_names)
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
108 {
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
109 auto nm_fcn_iter = m_subfunctions.find (nm);
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
110
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
111 if (nm_fcn_iter != m_subfunctions.end ())
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
112 {
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
113 octave_value ov_fcn = nm_fcn_iter->second;
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
114 octave_user_code *fcn = ov_fcn.user_code_value ();
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
115
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
116 if (! fcn)
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
117 continue;
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
118
28857
43ad651cf5a0 eliminate unnecessary uses of octave:: namespace qualifier
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
119 symbol_scope scope = fcn->scope ();
28432
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
120
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
121 std::list<std::string> plst = scope.parent_fcn_names ();
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
122
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
123 octave_fcn_handle *fh = new octave_fcn_handle (ov_fcn, nm, plst);
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
124
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
125 retval.push_back (octave_value (fh));
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
126 }
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
127 }
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
128
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
129 return retval;
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
130 }
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
131
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
132 octave_value
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
133 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
134 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
135 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
136 = {{ "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
137 { "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
138 { "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
139 { "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
140 { "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
141 { "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
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 (m);
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 octave_value
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
147 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
148 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
149 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
150
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
151 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
152 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
153 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
154 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
155 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
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 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
159 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
160
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
161 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
162 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
163 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
164
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
165 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
166 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
167
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
168 return retval;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
169 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
170
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
171 octave_value
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
172 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
173 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
174 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
175
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
176 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
177 return p->second;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
178
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
179 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
180
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
181 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
182 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
183
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
184 return octave_value ();
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
185 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
186
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
187 void
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
188 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
189 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
190 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
191 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
192 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
193
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
194 if (fcn)
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
195 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
196 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
197 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
198
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
199 void
30103
55eeb7f0850b store parent name in function object when caching parents in scope (bug #61105)
John W. Eaton <jwe@octave.org>
parents: 29654
diff changeset
200 symbol_scope_rep::cache_parent_fcn_names (const std::list<std::string>& names)
55eeb7f0850b store parent name in function object when caching parents in scope (bug #61105)
John W. Eaton <jwe@octave.org>
parents: 29654
diff changeset
201 {
55eeb7f0850b store parent name in function object when caching parents in scope (bug #61105)
John W. Eaton <jwe@octave.org>
parents: 29654
diff changeset
202 m_parent_fcn_names = names;
55eeb7f0850b store parent name in function object when caching parents in scope (bug #61105)
John W. Eaton <jwe@octave.org>
parents: 29654
diff changeset
203 }
55eeb7f0850b store parent name in function object when caching parents in scope (bug #61105)
John W. Eaton <jwe@octave.org>
parents: 29654
diff changeset
204
55eeb7f0850b store parent name in function object when caching parents in scope (bug #61105)
John W. Eaton <jwe@octave.org>
parents: 29654
diff changeset
205 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
206 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
207 {
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
208 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
209 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
210
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
211 void
26060
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
212 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
213 {
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
214 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
215 }
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
216
28026
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
217 void
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
218 symbol_scope_rep::cache_dir_name (const std::string& name)
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
219 {
28857
43ad651cf5a0 eliminate unnecessary uses of octave:: namespace qualifier
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
220 m_dir_name = sys::canonicalize_file_name (name);
28026
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
221 }
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
222
26060
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
223 bool
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
224 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
225 {
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
226 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
227 {
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
228 // 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
229 // valid scope.
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
230
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
231 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
232
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
233 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
234 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
235 // 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
236 // of SCOPE.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
237
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
238 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
239 return true;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
240 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
241
26060
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
242 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
243
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
244 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
245 {
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
246 // 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
247 // 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
248 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
249 return true;
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
250
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
251 // 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
252 // 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
253 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
254 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
255 return true;
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
256 }
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
257 }
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
258
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
259 return false;
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
260 }
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
261
29864
e2e493712818 improve previous change for command syntax parsing (bug #60882)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
262 void symbol_scope_rep::mark_as_variable (const std::string& nm)
e2e493712818 improve previous change for command syntax parsing (bug #60882)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
263 {
e2e493712818 improve previous change for command syntax parsing (bug #60882)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
264 table_iterator p = m_symbols.find (nm);
e2e493712818 improve previous change for command syntax parsing (bug #60882)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
265
e2e493712818 improve previous change for command syntax parsing (bug #60882)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
266 if (p != m_symbols.end ())
e2e493712818 improve previous change for command syntax parsing (bug #60882)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
267 p->second.mark_as_variable ();
e2e493712818 improve previous change for command syntax parsing (bug #60882)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
268 }
e2e493712818 improve previous change for command syntax parsing (bug #60882)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
269
e2e493712818 improve previous change for command syntax parsing (bug #60882)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
270 void symbol_scope_rep::mark_as_variables (const std::list<std::string>& lst)
e2e493712818 improve previous change for command syntax parsing (bug #60882)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
271 {
e2e493712818 improve previous change for command syntax parsing (bug #60882)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
272 for (const auto& nm : lst)
e2e493712818 improve previous change for command syntax parsing (bug #60882)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
273 mark_as_variable (nm);
e2e493712818 improve previous change for command syntax parsing (bug #60882)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
274 }
e2e493712818 improve previous change for command syntax parsing (bug #60882)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
275
e2e493712818 improve previous change for command syntax parsing (bug #60882)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
276 bool symbol_scope_rep::is_variable (const std::string& nm) const
e2e493712818 improve previous change for command syntax parsing (bug #60882)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
277 {
e2e493712818 improve previous change for command syntax parsing (bug #60882)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
278 table_const_iterator p = m_symbols.find (nm);
e2e493712818 improve previous change for command syntax parsing (bug #60882)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
279
e2e493712818 improve previous change for command syntax parsing (bug #60882)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
280 // FIXME: maybe we should also mark formal parameters as variables?
e2e493712818 improve previous change for command syntax parsing (bug #60882)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
281
e2e493712818 improve previous change for command syntax parsing (bug #60882)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
282 if (p != m_symbols.end () && p->second.is_variable ())
e2e493712818 improve previous change for command syntax parsing (bug #60882)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
283 return true;
e2e493712818 improve previous change for command syntax parsing (bug #60882)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
284
e2e493712818 improve previous change for command syntax parsing (bug #60882)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
285 if (is_nested ())
e2e493712818 improve previous change for command syntax parsing (bug #60882)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
286 {
e2e493712818 improve previous change for command syntax parsing (bug #60882)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
287 auto t_parent = m_parent.lock ();
e2e493712818 improve previous change for command syntax parsing (bug #60882)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
288
e2e493712818 improve previous change for command syntax parsing (bug #60882)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
289 return t_parent ? t_parent->is_variable (nm) : false;
e2e493712818 improve previous change for command syntax parsing (bug #60882)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
290 }
e2e493712818 improve previous change for command syntax parsing (bug #60882)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
291
e2e493712818 improve previous change for command syntax parsing (bug #60882)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
292 return false;
e2e493712818 improve previous change for command syntax parsing (bug #60882)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
293 }
e2e493712818 improve previous change for command syntax parsing (bug #60882)
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
294
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
295 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
296 {
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
297 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
298
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
299 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
300 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
301 // 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
302 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
303 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
304 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
305
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
306 std::size_t offset = 0;
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
307
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
308 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
309 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
310 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
311
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
312 // 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
313 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
314 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
315 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
316 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
317 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
318 // 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
319 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
320 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
321
28432
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
322 std::list<std::string> plst = parent_fcn_names ();
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
323 plst.push_front (m_fcn_name);
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
324
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
325 for (auto& scope_obj : m_children)
28432
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
326 {
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
327 scope_obj.cache_parent_fcn_names (plst);
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
328 scope_obj.update_nest ();
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
329 }
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
330 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
331
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
332 bool symbol_scope_rep::look_nonlocal (const std::string& name,
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
333 std::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
334 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
335 offset++;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
336
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
337 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
338
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
339 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
340 {
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
341 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
342
26060
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
343 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
344 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
345 }
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
346 else
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
347 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
348 // 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
349 // 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
350 // 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
351 // 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
352 // 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
353
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
354 std::size_t t_frame_offset = offset + p->second.frame_offset ();
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
355 std::size_t t_data_offset = p->second.data_offset ();
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
356
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
357 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
358 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
359
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
360 return true;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
361 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
362
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
363 return false;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
364 }
28432
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
365
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
366 std::list<octave_value> symbol_scope::localfunctions (void) const
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
367 {
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
368 if (! m_rep)
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
369 return std::list<octave_value> ();
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
370
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
371 if (is_primary_fcn_scope ())
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
372 return m_rep->localfunctions ();
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
373
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
374 std::shared_ptr<symbol_scope_rep> ppsr
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
375 = m_rep->primary_parent_scope_rep ();
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
376
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
377 if (! ppsr)
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
378 return std::list<octave_value> ();
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
379
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
380 return ppsr->localfunctions ();
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28026
diff changeset
381 }
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
382 }