annotate libinterp/corefcn/symscope.h @ 28026:262cdfc6faf9

allow reloading of handles to private functions (bug #57439) To allow a handle to a private function to reload the function it references after the function has been cleared and/or when the directory where the function was defined is no longer in the load path, store the directory in the symbol scope for the function, not just in the function itself. Also use the canonical directory name as the key for the private_function map in the load path. * fcn-info.cc (fcn_info::fcn_info_rep::load_private_function): Use canonical directory name as key in private_functions map. (fcn_info::fcn_info_rep::xfind): Get function file and directory names directly from the search scope. (fcn_info::fcn_info_rep::x_builtin_find): Likewise. * load-path.h, load-path.cc (load_path::M_FILE, load_path::OCT_FILE, load_path::MEX_FILE): Now public. (find_private_fcn_file): New static function. (load_path::package_info::remove): Use canonical directory name as key for private function map. (load_path::package_info::add_to_private_fcn_map): Likewise. (load_path::package_info::add_to_method_map): Likewise. (load_path::package_info::remove_private_fcn_map): Likewise. (load_path::package_info::find_private_fcn): Likewise. If function is not found in map, search filesystem. * symscope.h, symscope.cc (symbol_scope_rep::m_fcn_file_name, symbol_scope_rep::m_dir_name): New data members. (symbol_scope::dup): Copy them. (symbol_scope::cache_fcn_file_name, symbol_scope::cache_dir_name, symbol_scope::fcn_file_name, symbol_scope::dir_name, symbol_scope_rep::cache_fcn_file_name, symbol_scope_rep::cache_dir_name, symbol_scope_rep::fcn_file_name, symbol_scope_rep::dir_name): New functions. * oct-parse.yy (base_parser::make_script): Also cache file and directory names in script scope. (base_parser::finish_function): Also cache file and directory names in function scope. * pt-fcn-handle.cc (tree_anon_fcn_handle::evaluate): Also cache file and directory names in new scope associated with the anonymous function object.
author John W. Eaton <jwe@octave.org>
date Thu, 30 Jan 2020 15:12:52 -0500
parents bd51beb6205e
children 71c34141cc2d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
3 // Copyright (C) 1993-2020 The Octave Project Developers
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25
24269
f494b87d2a93 rename scope to symbol_scope
John W. Eaton <jwe@octave.org>
parents: 24263
diff changeset
26 #if ! defined (octave_symscope_h)
f494b87d2a93 rename scope to symbol_scope
John W. Eaton <jwe@octave.org>
parents: 24263
diff changeset
27 #define octave_symscope_h 1
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29 #include "octave-config.h"
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 #include <deque>
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 #include <list>
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 #include <map>
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
34 #include <memory>
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 #include <set>
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 #include <string>
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 #include "glob-match.h"
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 #include "lo-regexp.h"
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 #include "oct-refcount.h"
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 class tree_argument_list;
28026
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
43 class octave_user_code;
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45 #include "ov.h"
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46 #include "ovl.h"
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47 #include "symrec.h"
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 namespace octave
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50 {
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
51 class symbol_scope;
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
52
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
53 class symbol_scope_rep
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
54 : public std::enable_shared_from_this<symbol_scope_rep>
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56 public:
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58 typedef std::map<std::string, symbol_record>::const_iterator
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59 table_const_iterator;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
60 typedef std::map<std::string, symbol_record>::iterator
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61 table_iterator;
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 typedef std::map<std::string, octave_value>::const_iterator
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64 subfunctions_const_iterator;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65 typedef std::map<std::string, octave_value>::iterator
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66 subfunctions_iterator;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
68 symbol_scope_rep (const std::string& name = "")
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
69 : m_name (name), m_symbols (), m_subfunctions (),
28026
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
70 m_persistent_values (), m_code (nullptr), m_fcn_file_name (),
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
71 m_dir_name (), m_parent (), m_primary_parent (), m_children (),
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
72 m_nesting_depth (0), m_is_static (false)
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 // All scopes have ans as the first symbol, initially undefined.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
75
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
76 insert_local ("ans");
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
77 }
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79 // No copying!
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
80
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
81 symbol_scope_rep (const symbol_scope&) = delete;
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
82
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
83 symbol_scope_rep& operator = (const symbol_scope&) = delete;
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
85 ~symbol_scope_rep (void) = default;
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
86
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
87 size_t num_symbols (void) const { return m_symbols.size (); }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
88
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
89 // Simply inserts symbol. No non-local searching.
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
90
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
91 symbol_record 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: 25438
diff changeset
92
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
93 void insert_symbol_record (symbol_record& sr);
26040
0af4653e48a4 install auto function vars in symbol scope when parsing function
John W. Eaton <jwe@octave.org>
parents: 25438
diff changeset
94
26060
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
95 bool is_nested (void) const { return m_nesting_depth > 0; }
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96
26060
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
97 size_t nesting_depth (void) const { return 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
98
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
99 void set_nesting_depth (size_t depth) { m_nesting_depth = depth; }
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
100
26825
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
101 bool is_parent (void) const { return ! m_children.empty (); }
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
102
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
103 bool is_static (void) const { return m_is_static; }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
104
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
105 void mark_static (void) { 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
106
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
107 std::shared_ptr<symbol_scope_rep> parent_scope_rep (void) const
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
108 {
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
109 return 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
110 }
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
111
26060
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
112 std::shared_ptr<symbol_scope_rep> primary_parent_scope_rep (void) const
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
113 {
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
114 return 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
115 }
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
116
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
117 std::shared_ptr<symbol_scope_rep> dup (void) const
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
118 {
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
119 std::shared_ptr<symbol_scope_rep> new_sid
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
120 = std::shared_ptr<symbol_scope_rep> (new symbol_scope_rep (m_name));
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
121
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
122 for (const auto& nm_sr : m_symbols)
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
123 new_sid->m_symbols[nm_sr.first] = nm_sr.second.dup ();
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
124
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
125 new_sid->m_subfunctions = m_subfunctions;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
126 new_sid->m_persistent_values = m_persistent_values;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
127 new_sid->m_subfunction_names = m_subfunction_names;
27745
7a45100a40c4 allow private scripts to be called from other private scripts
John W. Eaton <jwe@octave.org>
parents: 26940
diff changeset
128 new_sid->m_code = m_code;
28026
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
129 new_sid->m_fcn_file_name = m_fcn_file_name;
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
130 new_sid->m_dir_name = m_dir_name;
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
131 new_sid->m_parent = m_parent;
26060
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
132 new_sid->m_primary_parent = m_primary_parent;
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
133 new_sid->m_children = m_children;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
134 new_sid->m_nesting_depth = m_nesting_depth;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
135 new_sid->m_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
136
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
137 return new_sid;
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
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
140 octave_value& persistent_varref (size_t data_offset)
24362
3fc24b792a24 avoid including symtab.h, symscope.h, or symrec.h unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24361
diff changeset
141 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
142 return m_persistent_values[data_offset];
24362
3fc24b792a24 avoid including symtab.h, symscope.h, or symrec.h unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24361
diff changeset
143 }
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
144
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
145 octave_value persistent_varval (size_t data_offset) const
24362
3fc24b792a24 avoid including symtab.h, symscope.h, or symrec.h unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24361
diff changeset
146 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
147 auto p = m_persistent_values.find (data_offset);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
148
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
149 return p == m_persistent_values.end () ? octave_value () : p->second;
24362
3fc24b792a24 avoid including symtab.h, symscope.h, or symrec.h unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24361
diff changeset
150 }
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
151
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
152 symbol_record find_symbol (const std::string& name)
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
153 {
25337
3ff9192b676e use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents: 25203
diff changeset
154 auto p = m_symbols.find (name);
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
155
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
156 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
157 return insert (name);
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
158 else
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
159 return p->second;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
160 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
161
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
162 symbol_record lookup_symbol (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
163 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
164 auto p = m_symbols.find (name);
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
165
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
166 return p == m_symbols.end () ? symbol_record () : p->second;
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
167 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
168
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
169 symbol_record 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
170
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
171 void rename (const std::string& old_name, const std::string& new_name)
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
172 {
25337
3ff9192b676e use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents: 25203
diff changeset
173 auto p = m_symbols.find (old_name);
24263
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 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
176 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
177 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
178
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
179 sr.rename (new_name);
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 m_symbols.erase (p);
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
182
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
183 m_symbols[new_name] = sr;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
184 }
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 install_subfunction (const std::string& name,
24705
8b346a19108e mark objects as nested or subfunctions when parsing
John W. Eaton <jwe@octave.org>
parents: 24645
diff changeset
188 const octave_value& fval)
8b346a19108e mark objects as nested or subfunctions when parsing
John W. Eaton <jwe@octave.org>
parents: 24645
diff changeset
189 {
8b346a19108e mark objects as nested or subfunctions when parsing
John W. Eaton <jwe@octave.org>
parents: 24645
diff changeset
190 m_subfunctions[name] = fval;
8b346a19108e mark objects as nested or subfunctions when parsing
John W. Eaton <jwe@octave.org>
parents: 24645
diff changeset
191 }
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
192
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
193 void install_nestfunction (const std::string& name,
24705
8b346a19108e mark objects as nested or subfunctions when parsing
John W. Eaton <jwe@octave.org>
parents: 24645
diff changeset
194 const octave_value& fval,
8b346a19108e mark objects as nested or subfunctions when parsing
John W. Eaton <jwe@octave.org>
parents: 24645
diff changeset
195 const symbol_scope& fcn_scope)
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
196 {
24705
8b346a19108e mark objects as nested or subfunctions when parsing
John W. Eaton <jwe@octave.org>
parents: 24645
diff changeset
197 m_subfunctions[name] = fval;
8b346a19108e mark objects as nested or subfunctions when parsing
John W. Eaton <jwe@octave.org>
parents: 24645
diff changeset
198
8b346a19108e mark objects as nested or subfunctions when parsing
John W. Eaton <jwe@octave.org>
parents: 24645
diff changeset
199 m_children.push_back (fcn_scope);
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
200 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
201
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
202 octave_value find_subfunction (const std::string& name) const;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
203
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
204 void lock_subfunctions (void)
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 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
207 nm_sf.second.lock ();
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
208 }
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 void unlock_subfunctions (void)
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 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
213 nm_sf.second.unlock ();
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
214 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
215
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
216 std::map<std::string, octave_value> subfunctions (void) const
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
217 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
218 return m_subfunctions;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
219 }
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 void erase_subfunctions (void)
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
222 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
223 m_subfunctions.clear ();
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
224 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
225
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
226 void mark_subfunctions_in_scope_as_private (const std::string& class_name);
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
227
24285
d22d2936f580 store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents: 24272
diff changeset
228 bool has_subfunctions (void) const
d22d2936f580 store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents: 24272
diff changeset
229 {
d22d2936f580 store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents: 24272
diff changeset
230 return ! m_subfunction_names.empty ();
d22d2936f580 store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents: 24272
diff changeset
231 }
d22d2936f580 store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents: 24272
diff changeset
232
d22d2936f580 store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents: 24272
diff changeset
233 void stash_subfunction_names (const std::list<std::string>& names)
d22d2936f580 store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents: 24272
diff changeset
234 {
d22d2936f580 store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents: 24272
diff changeset
235 m_subfunction_names = names;
d22d2936f580 store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents: 24272
diff changeset
236 }
d22d2936f580 store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents: 24272
diff changeset
237
d22d2936f580 store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents: 24272
diff changeset
238 std::list<std::string> subfunction_names (void) const
d22d2936f580 store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents: 24272
diff changeset
239 {
d22d2936f580 store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents: 24272
diff changeset
240 return m_subfunction_names;
d22d2936f580 store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents: 24272
diff changeset
241 }
d22d2936f580 store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents: 24272
diff changeset
242
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
243 octave_value dump (void) const;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
244
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
245 std::string name (void) const { return m_name; }
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 void cache_name (const std::string& name) { m_name = name; }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
248
27745
7a45100a40c4 allow private scripts to be called from other private scripts
John W. Eaton <jwe@octave.org>
parents: 26940
diff changeset
249 octave_user_code *user_code (void) const { return m_code; }
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
250
27745
7a45100a40c4 allow private scripts to be called from other private scripts
John W. Eaton <jwe@octave.org>
parents: 26940
diff changeset
251 void set_user_code (octave_user_code *code) { m_code = code; }
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
252
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
253 void 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
254
26060
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
255 void 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
256
28026
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
257 void cache_fcn_file_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
258 {
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
259 m_fcn_file_name = name;
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
260 }
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
261
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
262 void 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
263
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
264 std::string fcn_file_name (void) const { return m_fcn_file_name; }
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
265
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
266 std::string dir_name (void) const { return m_dir_name; }
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
267
26060
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
268 bool 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
269
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
270 void update_nest (void);
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
271
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
272 bool look_nonlocal (const std::string& name, size_t offset,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
273 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
274
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
275 octave_value dump_symbols_map (void) const;
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
276
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
277 const std::map<std::string, symbol_record>& symbols (void) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
278 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
279 return m_symbols;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
280 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
281
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
282 std::map<std::string, symbol_record>& symbols (void)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
283 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
284 return m_symbols;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
285 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
286
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
287 std::list<symbol_record> 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
288
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
289 private:
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
290
24940
7edf1fb1d4b2 doc: Add Doxygen documentation.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24706
diff changeset
291 //! Name for this scope (usually the corresponding filename of the
7edf1fb1d4b2 doc: Add Doxygen documentation.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24706
diff changeset
292 //! function corresponding to the scope).
7edf1fb1d4b2 doc: Add Doxygen documentation.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24706
diff changeset
293
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
294 std::string m_name;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
295
24940
7edf1fb1d4b2 doc: Add Doxygen documentation.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24706
diff changeset
296 //! Map from symbol names to symbol info.
7edf1fb1d4b2 doc: Add Doxygen documentation.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24706
diff changeset
297
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
298 std::map<std::string, symbol_record> m_symbols;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
299
24940
7edf1fb1d4b2 doc: Add Doxygen documentation.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24706
diff changeset
300 //! Map from symbol names to subfunctions.
7edf1fb1d4b2 doc: Add Doxygen documentation.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24706
diff changeset
301
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
302 std::map<std::string, octave_value> m_subfunctions;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
303
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
304 //! Map from data offset to persistent values in this scope.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
305 std::map<size_t, octave_value> m_persistent_values;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
306
24940
7edf1fb1d4b2 doc: Add Doxygen documentation.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24706
diff changeset
307 //! The list of subfunctions (if any) in the order they appear in
7edf1fb1d4b2 doc: Add Doxygen documentation.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24706
diff changeset
308 //! the function file.
7edf1fb1d4b2 doc: Add Doxygen documentation.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24706
diff changeset
309
24285
d22d2936f580 store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents: 24272
diff changeset
310 std::list<std::string> m_subfunction_names;
d22d2936f580 store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents: 24272
diff changeset
311
24940
7edf1fb1d4b2 doc: Add Doxygen documentation.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24706
diff changeset
312 //! The associated user code (may be null).
7edf1fb1d4b2 doc: Add Doxygen documentation.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24706
diff changeset
313
27745
7a45100a40c4 allow private scripts to be called from other private scripts
John W. Eaton <jwe@octave.org>
parents: 26940
diff changeset
314 octave_user_code *m_code;
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
315
28026
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
316 //! The file name associated with m_code.
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
317
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
318 std::string m_fcn_file_name;
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
319
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
320 //! The directory associated with m_code.
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
321
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
322 std::string m_dir_name;
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
323
24940
7edf1fb1d4b2 doc: Add Doxygen documentation.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24706
diff changeset
324 //! Parent of nested function (may be null).
7edf1fb1d4b2 doc: Add Doxygen documentation.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24706
diff changeset
325
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
326 std::weak_ptr<symbol_scope_rep> m_parent;
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
327
26060
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
328 //! Primary (top) parent of nested function (may be null). Used
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
329 //! to determine whether two nested functions are related.
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
330
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
331 std::weak_ptr<symbol_scope_rep> m_primary_parent;
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
332
24940
7edf1fb1d4b2 doc: Add Doxygen documentation.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24706
diff changeset
333 //! Child nested functions.
7edf1fb1d4b2 doc: Add Doxygen documentation.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24706
diff changeset
334
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
335 std::vector<symbol_scope> m_children;
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
336
24940
7edf1fb1d4b2 doc: Add Doxygen documentation.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24706
diff changeset
337 //! If true, then this scope belongs to a nested function.
7edf1fb1d4b2 doc: Add Doxygen documentation.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24706
diff changeset
338
26060
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
339 size_t m_nesting_depth;
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
340
24940
7edf1fb1d4b2 doc: Add Doxygen documentation.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24706
diff changeset
341 //! If true then no variables can be added.
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
342
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
343 bool m_is_static;
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
344 };
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
345
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
346 class symbol_scope
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
347 {
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
348 public:
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
349
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
350 // Create a valid but possibly unnamed scope.
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
351 symbol_scope (const std::string& name)
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
352 : m_rep (new symbol_scope_rep (name))
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
353 { }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
354
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
355 // NEW_REP must be dynamically allocated or nullptr. If it is
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
356 // nullptr, the scope is invalid.
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
357 symbol_scope (const std::shared_ptr<symbol_scope_rep> new_rep = nullptr)
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
358 : m_rep (new_rep)
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
359 { }
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
360
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
361 symbol_scope (const symbol_scope&) = default;
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
362
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
363 symbol_scope& operator = (const symbol_scope&) = default;
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
364
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
365 ~symbol_scope (void) = default;
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
366
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
367 bool is_valid (void) const { return bool (m_rep); }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
368
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
369 explicit operator bool () const { return bool (m_rep); }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
370
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
371 size_t num_symbols (void) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
372 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
373 return m_rep ? m_rep->num_symbols () : 0;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
374 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
375
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
376 symbol_record insert_local (const std::string& name)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
377 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
378 return m_rep ? m_rep->insert_local (name) : symbol_record ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
379 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
380
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
381 void insert_symbol_record (symbol_record& sr)
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
382 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
383 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
384 m_rep->insert_symbol_record (sr);
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
385 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
386
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
387 bool is_nested (void) const
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
388 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
389 return m_rep ? m_rep->is_nested () : false;
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
390 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
391
26825
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
392 bool is_parent (void) const
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
393 {
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
394 return m_rep ? m_rep->is_parent () : false;
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
395 }
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
396
26060
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
397 void set_nesting_depth (size_t depth)
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
398 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
399 if (m_rep)
26060
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
400 m_rep->set_nesting_depth (depth);
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
401 }
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
402
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
403 size_t nesting_depth (void) const
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
404 {
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
405 return m_rep ? m_rep->nesting_depth () : 0;
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
406 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
407
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
408 bool is_static (void) const
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
409 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
410 return m_rep ? m_rep->is_static () : false;
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
411 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
412
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
413 void mark_static (void)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
414 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
415 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
416 m_rep->mark_static ();
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
417 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
418
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
419 std::shared_ptr<symbol_scope_rep> parent_scope (void) const
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
420 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
421 return m_rep ? m_rep->parent_scope_rep () : nullptr;
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
422 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
423
26060
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
424 std::shared_ptr<symbol_scope_rep> primary_parent_scope (void) const
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
425 {
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
426 return m_rep ? m_rep->primary_parent_scope_rep () : nullptr;
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
427 }
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
428
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
429 symbol_scope dup (void) const
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
430 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
431 return symbol_scope (m_rep ? m_rep->dup () : nullptr);
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
432 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
433
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
434 octave_value& persistent_varref (size_t data_offset)
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
435 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
436 static octave_value dummy_value;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
437
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
438 return m_rep ? m_rep->persistent_varref (data_offset) : dummy_value;
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
439 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
440
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
441 octave_value persistent_varval (size_t data_offset) const
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
442 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
443 return m_rep ? m_rep->persistent_varval (data_offset) : octave_value ();
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
444 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
445
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
446 symbol_record find_symbol (const std::string& name)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
447 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
448 return m_rep ? m_rep->find_symbol (name) : symbol_record ();
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
449 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
450
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
451 // Like find_symbol, but does not insert.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
452 symbol_record lookup_symbol (const std::string& name) const
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
453 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
454 return m_rep ? m_rep->lookup_symbol (name) : symbol_record ();
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
455 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
456
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
457 symbol_record insert (const std::string& name)
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
458 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
459 return m_rep ? m_rep->insert (name) : symbol_record ();
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
460 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
461
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
462 void rename (const std::string& old_name, const std::string& new_name)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
463 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
464 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
465 m_rep->rename (old_name, new_name);
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
466 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
467
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
468 void install_subfunction (const std::string& name,
24705
8b346a19108e mark objects as nested or subfunctions when parsing
John W. Eaton <jwe@octave.org>
parents: 24645
diff changeset
469 const octave_value& fval)
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
470 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
471 if (m_rep)
24705
8b346a19108e mark objects as nested or subfunctions when parsing
John W. Eaton <jwe@octave.org>
parents: 24645
diff changeset
472 m_rep->install_subfunction (name, fval);
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
473 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
474
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
475 void install_nestfunction (const std::string& name,
24705
8b346a19108e mark objects as nested or subfunctions when parsing
John W. Eaton <jwe@octave.org>
parents: 24645
diff changeset
476 const octave_value& fval,
8b346a19108e mark objects as nested or subfunctions when parsing
John W. Eaton <jwe@octave.org>
parents: 24645
diff changeset
477 const symbol_scope& fcn_scope)
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
478 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
479 if (m_rep)
24705
8b346a19108e mark objects as nested or subfunctions when parsing
John W. Eaton <jwe@octave.org>
parents: 24645
diff changeset
480 m_rep->install_nestfunction (name, fval, fcn_scope);
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
481 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
482
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
483 octave_value find_subfunction (const std::string& name) const
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
484 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
485 return m_rep ? m_rep->find_subfunction (name) : octave_value ();
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
486 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
487
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
488 void lock_subfunctions (void)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
489 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
490 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
491 m_rep->lock_subfunctions ();
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
492 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
493
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
494 void unlock_subfunctions (void)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
495 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
496 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
497 m_rep->unlock_subfunctions ();
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
498 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
499
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
500 std::map<std::string, octave_value> subfunctions (void) const
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
501 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
502 return (m_rep
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
503 ? m_rep->subfunctions ()
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
504 : std::map<std::string, octave_value> ());
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
505 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
506
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
507 void erase_subfunctions (void)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
508 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
509 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
510 m_rep->erase_subfunctions ();
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
511 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
512
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
513 void mark_subfunctions_in_scope_as_private (const std::string& class_name)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
514 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
515 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
516 m_rep->mark_subfunctions_in_scope_as_private (class_name);
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
517 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
518
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
519 bool has_subfunctions (void) const
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
520 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
521 return m_rep ? m_rep->has_subfunctions () : false;
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
522 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
523
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
524 void stash_subfunction_names (const std::list<std::string>& names)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
525 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
526 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
527 m_rep->stash_subfunction_names (names);
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
528 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
529
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
530 std::list<std::string> subfunction_names (void) const
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
531 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
532 return m_rep ? m_rep->subfunction_names () : std::list<std::string> ();
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
533 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
534
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
535 octave_value dump (void) const
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
536 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
537 return m_rep ? m_rep->dump () : octave_value ();
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
538 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
539
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
540 std::string name (void) const
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
541 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
542 return m_rep ? m_rep->name () : "";
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
543 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
544
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
545 void cache_name (const std::string& name)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
546 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
547 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
548 m_rep->cache_name (name);
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
549 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
550
27745
7a45100a40c4 allow private scripts to be called from other private scripts
John W. Eaton <jwe@octave.org>
parents: 26940
diff changeset
551 octave_user_code * user_code (void) const
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
552 {
27745
7a45100a40c4 allow private scripts to be called from other private scripts
John W. Eaton <jwe@octave.org>
parents: 26940
diff changeset
553 return m_rep ? m_rep->user_code () : nullptr;
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
554 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
555
27745
7a45100a40c4 allow private scripts to be called from other private scripts
John W. Eaton <jwe@octave.org>
parents: 26940
diff changeset
556 void set_user_code (octave_user_code *code)
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
557 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
558 if (m_rep)
27745
7a45100a40c4 allow private scripts to be called from other private scripts
John W. Eaton <jwe@octave.org>
parents: 26940
diff changeset
559 m_rep->set_user_code (code);
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
560 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
561
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
562 void set_parent (const symbol_scope& p)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
563 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
564 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
565 m_rep->set_parent (p.get_rep ());
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
566 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
567
26060
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
568 void set_primary_parent (const symbol_scope& p)
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
569 {
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
570 if (m_rep)
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
571 m_rep->set_primary_parent (p.get_rep ());
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
572 }
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
573
28026
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
574 void cache_fcn_file_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
575 {
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
576 if (m_rep)
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
577 m_rep->cache_fcn_file_name (name);
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
578 }
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
579
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
580 void 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
581 {
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
582 if (m_rep)
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
583 m_rep->cache_dir_name (name);
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
584 }
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
585
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
586 std::string fcn_file_name (void) const
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
587 {
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
588 return m_rep ? m_rep->fcn_file_name () : "";
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
589 }
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
590
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
591 std::string dir_name (void) const
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
592 {
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
593 return m_rep ? m_rep->dir_name () : "";
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
594 }
262cdfc6faf9 allow reloading of handles to private functions (bug #57439)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
595
26060
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
596 bool is_relative (const symbol_scope& scope) const
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
597 {
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
598 return m_rep ? m_rep->is_relative (scope.get_rep ()) : false;
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
599 }
edcb09d4b1f5 store nesting depth and primary parent info in nested function scopes
John W. Eaton <jwe@octave.org>
parents: 26040
diff changeset
600
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
601 void update_nest (void)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
602 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
603 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
604 m_rep->update_nest ();
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
605 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
606
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
607 bool look_nonlocal (const std::string& name, size_t offset,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
608 symbol_record& result)
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
609 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
610 return m_rep ? m_rep->look_nonlocal (name, offset, result) : false;
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
611 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
612
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
613 std::shared_ptr<symbol_scope_rep> get_rep (void) const
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
614 {
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
615 return m_rep;
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
616 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
617
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
618 friend bool operator == (const symbol_scope& a, const symbol_scope& b)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
619 {
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
620 return a.m_rep == b.m_rep;
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
621 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
622
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
623 friend bool operator != (const symbol_scope& a, const symbol_scope& b)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
624 {
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
625 return a.m_rep != b.m_rep;
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
626 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
627
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
628 const std::map<std::string, symbol_record>& symbols (void) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
629 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
630 static const std::map<std::string, symbol_record> empty_map;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
631
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
632 return m_rep ? m_rep->symbols () : empty_map;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
633 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
634
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
635 std::map<std::string, symbol_record>& symbols (void)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
636 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
637 static std::map<std::string, symbol_record> empty_map;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
638
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
639 return m_rep ? m_rep->symbols () : empty_map;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
640 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
641
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
642 std::list<symbol_record> 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
643 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
644 static const std::list<symbol_record> empty_list;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
645
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
646 return m_rep ? m_rep->symbol_list () : empty_list;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
647 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
648
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
649 private:
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
650
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
651 std::shared_ptr<symbol_scope_rep> m_rep;
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
652 };
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
653 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
654
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
655 #endif