annotate libinterp/corefcn/symscope.cc @ 26040:0af4653e48a4

install auto function vars in symbol scope when parsing function * symscope.h, symscope.cc (symbol_scope::install_auto_fcn_vars, symbol_scope_rep::install_auto_fcn_vars, symbol_scope_rep::install_auto_fcn_var): New functions. * oct-parse.yy (base_parser::finish_function): Call symbol_scope::install_auto_fcn_vars.
author John W. Eaton <jwe@octave.org>
date Sat, 03 Nov 2018 09:27:37 -0400
parents c80323fe4938
children edcb09d4b1f5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
25054
6652d3823428 maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 24982
diff changeset
3 Copyright (C) 1993-2018 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 "symtab.h"
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 #include "utils.h"
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 namespace octave
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 {
26040
0af4653e48a4 install auto function vars in symbol scope when parsing function
John W. Eaton <jwe@octave.org>
parents: 25201
diff changeset
42 void symbol_scope_rep::install_auto_fcn_vars (void)
0af4653e48a4 install auto function vars in symbol scope when parsing function
John W. Eaton <jwe@octave.org>
parents: 25201
diff changeset
43 {
0af4653e48a4 install auto function vars in symbol scope when parsing function
John W. Eaton <jwe@octave.org>
parents: 25201
diff changeset
44 install_auto_fcn_var (".argn.");
0af4653e48a4 install auto function vars in symbol scope when parsing function
John W. Eaton <jwe@octave.org>
parents: 25201
diff changeset
45 install_auto_fcn_var (".ignored.");
0af4653e48a4 install auto function vars in symbol scope when parsing function
John W. Eaton <jwe@octave.org>
parents: 25201
diff changeset
46 install_auto_fcn_var (".nargin.");
0af4653e48a4 install auto function vars in symbol scope when parsing function
John W. Eaton <jwe@octave.org>
parents: 25201
diff changeset
47 install_auto_fcn_var (".nargout.");
0af4653e48a4 install auto function vars in symbol scope when parsing function
John W. Eaton <jwe@octave.org>
parents: 25201
diff changeset
48 install_auto_fcn_var (".saved_warning_states.");
0af4653e48a4 install auto function vars in symbol scope when parsing function
John W. Eaton <jwe@octave.org>
parents: 25201
diff changeset
49 }
0af4653e48a4 install auto function vars in symbol scope when parsing function
John W. Eaton <jwe@octave.org>
parents: 25201
diff changeset
50
0af4653e48a4 install auto function vars in symbol scope when parsing function
John W. Eaton <jwe@octave.org>
parents: 25201
diff changeset
51 void symbol_scope_rep::install_auto_fcn_var (const std::string& name)
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 insert (name, true);
0af4653e48a4 install auto function vars in symbol scope when parsing function
John W. Eaton <jwe@octave.org>
parents: 25201
diff changeset
54 mark_hidden (name);
0af4653e48a4 install auto function vars in symbol scope when parsing function
John W. Eaton <jwe@octave.org>
parents: 25201
diff changeset
55 mark_automatic (name);
0af4653e48a4 install auto function vars in symbol scope when parsing function
John W. Eaton <jwe@octave.org>
parents: 25201
diff changeset
56 }
0af4653e48a4 install auto function vars in symbol scope when parsing function
John W. Eaton <jwe@octave.org>
parents: 25201
diff changeset
57
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58 octave_value
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
59 symbol_scope_rep::find (const std::string& name,
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
60 const octave_value_list& args,
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
61 bool skip_variables, bool local_funcs)
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 // Variable.
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65 symbol_table& symtab
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
66 = __get_symbol_table__ ("symbol_scope_rep::find");
24263
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 (! skip_variables)
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70 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
71
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72 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
73 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74 symbol_record sr = p->second;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76 if (sr.is_global ())
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
77 return symtab.global_varval (name);
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78 else
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79 {
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24352
diff changeset
80 octave_value val = sr.varval (m_context);
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
82 if (val.is_defined ())
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83 return val;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84 }
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
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
88 if (local_funcs)
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 // Subfunction. I think it only makes sense to check for
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
91 // subfunctions if we are currently executing a function defined
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
92 // from a .m file.
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 octave_value fcn = find_subfunction (name);
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96 if (fcn.is_defined ())
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
97 return fcn;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
98 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
99
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
100 return symtab.fcn_table_find (name, args, local_funcs);
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
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
103 symbol_record&
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
104 symbol_scope_rep::insert (const std::string& name, bool force_add)
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
105 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
106 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
107
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
108 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
109 {
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24352
diff changeset
110 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
111
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
112 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
113
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
114 if (m_is_nested && t_parent && t_parent->look_nonlocal (name, ret))
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
115 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
116 else
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
117 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
118 if (m_is_static && ! force_add)
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
119 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
120
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
121 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
122 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
123 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
124 else
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
125 return p->second;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
126 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
127
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
128 octave_value
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
129 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
130 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
131 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
132 = {{ "name", m_name },
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
133 { "symbols", dump_symbols_map () },
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
134 { "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
135
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
136 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
137 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
138
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
139 octave_value
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
140 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
141 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
142 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
143
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
144 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
145 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
146 std::string nm = nm_sr.first;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
147 const symbol_record& sr = nm_sr.second;
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24352
diff changeset
148 info_map[nm] = sr.dump (m_context);
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
149 }
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 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
152 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
153
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
154 octave_value
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
155 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
156 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
157 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
158
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
159 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
160 return p->second;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
161
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
162 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
163
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
164 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
165 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
166
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
167 return octave_value ();
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
168 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
169
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
170 void
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
171 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
172 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
173 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
174 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
175 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
176
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
177 if (fcn)
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
178 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
179 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
180 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
181
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
182 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
183 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
184 {
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
185 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
186 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
187
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
188 void
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
189 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
190 {
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
191 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
192
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
193 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
194 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
195 // 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
196 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
197 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
198 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
199
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
200 if (! ours.is_formal ()
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
201 && m_is_nested && t_parent->look_nonlocal (nm_sr.first, ours))
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
202 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
203 if (ours.is_global () || ours.is_persistent ())
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
204 error ("global and persistent may only be used in the topmost level in which a nested variable is used");
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
205 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
206 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
207
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
208 // The scopes of nested functions are static.
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
209 if (m_is_nested)
1fbd8afcf625 Ensure that local functions do not have a static workspace (bug #53405).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24706
diff changeset
210 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
211 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
212 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
213 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
214 // 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
215 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
216 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
217
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
218 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
219 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
220 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
221
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
222 bool
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
223 symbol_scope_rep::look_nonlocal (const std::string& name,
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
224 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
225 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
226 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
227 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
228 {
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
229 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
230
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
231 if (m_is_nested && 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
232 return t_parent->look_nonlocal (name, result);
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
233 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
234 else if (! p->second.is_automatic ())
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
235 {
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
236 result.bind_fwd_rep (shared_from_this (), p->second);
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
237 return true;
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
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
240 return false;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
241 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
242
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
243 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
244 symbol_scope_rep::bind_script_symbols
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
245 (const std::shared_ptr<symbol_scope_rep>& curr_scope)
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
246 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
247 for (auto& nm_sr : m_symbols)
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24352
diff changeset
248 nm_sr.second.bind_fwd_rep (curr_scope,
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24352
diff changeset
249 curr_scope->find_symbol (nm_sr.first));
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
250 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
251
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
252 void
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
253 symbol_scope_rep::unbind_script_symbols (void)
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
254 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
255 for (auto& nm_sr : m_symbols)
25201
c80323fe4938 improve handling of global symbols (bug #53599)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
256 nm_sr.second.unbind_fwd_rep ();
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
257 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
258 }