comparison libinterp/corefcn/symscope.h @ 31607:aac27ad79be6 stable

maint: Re-indent code after switch to using namespace macros. * build-env.h, build-env.in.cc, Cell.h, __betainc__.cc, __eigs__.cc, __ftp__.cc, __ichol__.cc, __ilu__.cc, __isprimelarge__.cc, __magick_read__.cc, __pchip_deriv__.cc, amd.cc, base-text-renderer.cc, base-text-renderer.h, besselj.cc, bitfcns.cc, bsxfun.cc, c-file-ptr-stream.h, call-stack.cc, call-stack.h, ccolamd.cc, cellfun.cc, chol.cc, colamd.cc, dasrt.cc, data.cc, debug.cc, defaults.cc, defaults.h, det.cc, display.cc, display.h, dlmread.cc, dynamic-ld.cc, dynamic-ld.h, ellipj.cc, environment.cc, environment.h, error.cc, error.h, errwarn.h, event-manager.cc, event-manager.h, event-queue.cc, event-queue.h, fcn-info.cc, fcn-info.h, fft.cc, fft2.cc, file-io.cc, filter.cc, find.cc, ft-text-renderer.cc, ft-text-renderer.h, gcd.cc, gl-render.cc, gl-render.h, gl2ps-print.cc, gl2ps-print.h, graphics-toolkit.cc, graphics-toolkit.h, graphics.cc, gsvd.cc, gtk-manager.cc, gtk-manager.h, help.cc, help.h, hook-fcn.cc, hook-fcn.h, input.cc, input.h, interpreter-private.cc, interpreter-private.h, interpreter.cc, interpreter.h, inv.cc, jsondecode.cc, jsonencode.cc, latex-text-renderer.cc, latex-text-renderer.h, load-path.cc, load-path.h, load-save.cc, load-save.h, lookup.cc, ls-hdf5.cc, ls-mat4.cc, ls-mat5.cc, lsode.cc, lu.cc, mappers.cc, matrix_type.cc, max.cc, mex.cc, mexproto.h, mxarray.h, mxtypes.in.h, oct-errno.in.cc, oct-hdf5-types.cc, oct-hist.cc, oct-hist.h, oct-map.cc, oct-map.h, oct-opengl.h, oct-prcstrm.h, oct-process.cc, oct-process.h, oct-stdstrm.h, oct-stream.cc, oct-stream.h, oct-strstrm.h, octave-default-image.h, ordqz.cc, ordschur.cc, pager.cc, pager.h, pinv.cc, pow2.cc, pr-output.cc, psi.cc, qr.cc, quadcc.cc, rand.cc, regexp.cc, settings.cc, settings.h, sighandlers.cc, sighandlers.h, sparse-xpow.cc, sqrtm.cc, stack-frame.cc, stack-frame.h, stream-euler.cc, strfns.cc, svd.cc, syminfo.cc, syminfo.h, symrcm.cc, symrec.cc, symrec.h, symscope.cc, symscope.h, symtab.cc, symtab.h, sysdep.cc, sysdep.h, text-engine.cc, text-engine.h, text-renderer.cc, text-renderer.h, time.cc, toplev.cc, typecast.cc, url-handle-manager.cc, url-handle-manager.h, urlwrite.cc, utils.cc, utils.h, variables.cc, variables.h, xdiv.cc, __delaunayn__.cc, __init_fltk__.cc, __init_gnuplot__.cc, __ode15__.cc, __voronoi__.cc, audioread.cc, convhulln.cc, gzip.cc, cdef-class.cc, cdef-class.h, cdef-fwd.h, cdef-manager.cc, cdef-manager.h, cdef-method.cc, cdef-method.h, cdef-object.cc, cdef-object.h, cdef-package.cc, cdef-package.h, cdef-property.cc, cdef-property.h, cdef-utils.cc, cdef-utils.h, ov-base-diag.cc, ov-base-int.cc, ov-base-mat.cc, ov-base-mat.h, ov-base-scalar.cc, ov-base.cc, ov-base.h, ov-bool-mat.cc, ov-bool-mat.h, ov-bool-sparse.cc, ov-bool.cc, ov-builtin.h, ov-cell.cc, ov-ch-mat.cc, ov-class.cc, ov-class.h, ov-classdef.cc, ov-classdef.h, ov-complex.cc, ov-cx-diag.cc, ov-cx-mat.cc, ov-cx-sparse.cc, ov-dld-fcn.cc, ov-dld-fcn.h, ov-fcn-handle.cc, ov-fcn-handle.h, ov-fcn.h, ov-float.cc, ov-flt-complex.cc, ov-flt-cx-diag.cc, ov-flt-cx-mat.cc, ov-flt-re-diag.cc, ov-flt-re-mat.cc, ov-flt-re-mat.h, ov-intx.h, ov-java.cc, ov-lazy-idx.cc, ov-legacy-range.cc, ov-magic-int.cc, ov-mex-fcn.cc, ov-mex-fcn.h, ov-null-mat.cc, ov-perm.cc, ov-range.cc, ov-re-diag.cc, ov-re-mat.cc, ov-re-mat.h, ov-re-sparse.cc, ov-scalar.cc, ov-str-mat.cc, ov-struct.cc, ov-typeinfo.cc, ov-typeinfo.h, ov-usr-fcn.cc, ov-usr-fcn.h, ov.cc, ov.h, ovl.h, octave.cc, octave.h, op-b-sbm.cc, op-bm-sbm.cc, op-cs-scm.cc, op-fm-fcm.cc, op-fs-fcm.cc, op-s-scm.cc, op-scm-cs.cc, op-scm-s.cc, op-sm-cs.cc, ops.h, anon-fcn-validator.cc, anon-fcn-validator.h, bp-table.cc, bp-table.h, comment-list.cc, comment-list.h, filepos.h, lex.h, oct-lvalue.cc, oct-lvalue.h, parse.h, profiler.cc, profiler.h, pt-anon-scopes.cc, pt-anon-scopes.h, pt-arg-list.cc, pt-arg-list.h, pt-args-block.cc, pt-args-block.h, pt-array-list.cc, pt-array-list.h, pt-assign.cc, pt-assign.h, pt-binop.cc, pt-binop.h, pt-bp.cc, pt-bp.h, pt-cbinop.cc, pt-cbinop.h, pt-cell.cc, pt-cell.h, pt-check.cc, pt-check.h, pt-classdef.cc, pt-classdef.h, pt-cmd.h, pt-colon.cc, pt-colon.h, pt-const.cc, pt-const.h, pt-decl.cc, pt-decl.h, pt-eval.cc, pt-eval.h, pt-except.cc, pt-except.h, pt-exp.cc, pt-exp.h, pt-fcn-handle.cc, pt-fcn-handle.h, pt-id.cc, pt-id.h, pt-idx.cc, pt-idx.h, pt-jump.h, pt-loop.cc, pt-loop.h, pt-mat.cc, pt-mat.h, pt-misc.cc, pt-misc.h, pt-pr-code.cc, pt-pr-code.h, pt-select.cc, pt-select.h, pt-spmd.cc, pt-spmd.h, pt-stmt.cc, pt-stmt.h, pt-tm-const.cc, pt-tm-const.h, pt-unop.cc, pt-unop.h, pt-walk.cc, pt-walk.h, pt.cc, pt.h, token.cc, token.h, Range.cc, Range.h, idx-vector.cc, idx-vector.h, range-fwd.h, CollocWt.cc, CollocWt.h, aepbalance.cc, aepbalance.h, chol.cc, chol.h, gepbalance.cc, gepbalance.h, gsvd.cc, gsvd.h, hess.cc, hess.h, lo-mappers.cc, lo-mappers.h, lo-specfun.cc, lo-specfun.h, lu.cc, lu.h, oct-convn.cc, oct-convn.h, oct-fftw.cc, oct-fftw.h, oct-norm.cc, oct-norm.h, oct-rand.cc, oct-rand.h, oct-spparms.cc, oct-spparms.h, qr.cc, qr.h, qrp.cc, qrp.h, randgamma.cc, randgamma.h, randmtzig.cc, randmtzig.h, randpoisson.cc, randpoisson.h, schur.cc, schur.h, sparse-chol.cc, sparse-chol.h, sparse-lu.cc, sparse-lu.h, sparse-qr.cc, sparse-qr.h, svd.cc, svd.h, child-list.cc, child-list.h, dir-ops.cc, dir-ops.h, file-ops.cc, file-ops.h, file-stat.cc, file-stat.h, lo-sysdep.cc, lo-sysdep.h, lo-sysinfo.cc, lo-sysinfo.h, mach-info.cc, mach-info.h, oct-env.cc, oct-env.h, oct-group.cc, oct-group.h, oct-password.cc, oct-password.h, oct-syscalls.cc, oct-syscalls.h, oct-time.cc, oct-time.h, oct-uname.cc, oct-uname.h, action-container.cc, action-container.h, base-list.h, cmd-edit.cc, cmd-edit.h, cmd-hist.cc, cmd-hist.h, f77-fcn.h, file-info.cc, file-info.h, lo-array-errwarn.cc, lo-array-errwarn.h, lo-hash.cc, lo-hash.h, lo-ieee.h, lo-regexp.cc, lo-regexp.h, lo-utils.cc, lo-utils.h, oct-base64.cc, oct-base64.h, oct-glob.cc, oct-glob.h, oct-inttypes.h, oct-mutex.cc, oct-mutex.h, oct-refcount.h, oct-shlib.cc, oct-shlib.h, oct-sparse.cc, oct-sparse.h, oct-string.h, octave-preserve-stream-state.h, pathsearch.cc, pathsearch.h, quit.cc, quit.h, unwind-prot.cc, unwind-prot.h, url-transfer.cc, url-transfer.h: Re-indent code after switch to using namespace macros.
author Rik <rik@octave.org>
date Thu, 01 Dec 2022 18:02:15 -0800
parents e88a07dec498
children 597f3ee61a48
comparison
equal deleted inserted replaced
31605:e88a07dec498 31607:aac27ad79be6
46 #include "ovl.h" 46 #include "ovl.h"
47 #include "symrec.h" 47 #include "symrec.h"
48 48
49 OCTAVE_BEGIN_NAMESPACE(octave) 49 OCTAVE_BEGIN_NAMESPACE(octave)
50 50
51 class symbol_scope; 51 class symbol_scope;
52 52
53 class symbol_scope_rep 53 class symbol_scope_rep
54 : public std::enable_shared_from_this<symbol_scope_rep> 54 : public std::enable_shared_from_this<symbol_scope_rep>
55 { 55 {
56 public: 56 public:
57 57
58 typedef std::map<std::string, symbol_record>::const_iterator 58 typedef std::map<std::string, symbol_record>::const_iterator
59 table_const_iterator; 59 table_const_iterator;
60 typedef std::map<std::string, symbol_record>::iterator 60 typedef std::map<std::string, symbol_record>::iterator
61 table_iterator; 61 table_iterator;
62 62
63 typedef std::map<std::string, octave_value>::const_iterator 63 typedef std::map<std::string, octave_value>::const_iterator
64 subfunctions_const_iterator; 64 subfunctions_const_iterator;
65 typedef std::map<std::string, octave_value>::iterator 65 typedef std::map<std::string, octave_value>::iterator
66 subfunctions_iterator; 66 subfunctions_iterator;
67 67
68 symbol_scope_rep (const std::string& name = "") 68 symbol_scope_rep (const std::string& name = "")
69 : m_name (name), m_symbols (), m_subfunctions (), 69 : m_name (name), m_symbols (), m_subfunctions (),
70 m_persistent_values (), m_code (nullptr), m_fcn_name (), 70 m_persistent_values (), m_code (nullptr), m_fcn_name (),
71 m_fcn_file_name (), m_dir_name (), m_parent (), 71 m_fcn_file_name (), m_dir_name (), m_parent (),
72 m_primary_parent (), m_children (), m_nesting_depth (0), 72 m_primary_parent (), m_children (), m_nesting_depth (0),
73 m_is_static (false), m_is_primary_fcn_scope (false) 73 m_is_static (false), m_is_primary_fcn_scope (false)
74 { 74 {
75 // All scopes have ans as the first symbol, initially undefined. 75 // All scopes have ans as the first symbol, initially undefined.
76 76
77 insert_local ("ans"); 77 insert_local ("ans");
78 } 78 }
79 79
80 // No copying! 80 // No copying!
81 81
82 symbol_scope_rep (const symbol_scope&) = delete; 82 symbol_scope_rep (const symbol_scope&) = delete;
83 83
84 symbol_scope_rep& operator = (const symbol_scope&) = delete; 84 symbol_scope_rep& operator = (const symbol_scope&) = delete;
85 85
86 ~symbol_scope_rep (void) = default; 86 ~symbol_scope_rep (void) = default;
87 87
88 std::size_t num_symbols (void) const { return m_symbols.size (); } 88 std::size_t num_symbols (void) const { return m_symbols.size (); }
89 89
90 // Simply inserts symbol. No non-local searching. 90 // Simply inserts symbol. No non-local searching.
91 91
92 symbol_record insert_local (const std::string& name); 92 symbol_record insert_local (const std::string& name);
93 93
94 void insert_symbol_record (symbol_record& sr); 94 void insert_symbol_record (symbol_record& sr);
95 95
96 bool is_nested (void) const { return m_nesting_depth > 0; } 96 bool is_nested (void) const { return m_nesting_depth > 0; }
97 97
98 std::size_t nesting_depth (void) const { return m_nesting_depth; } 98 std::size_t nesting_depth (void) const { return m_nesting_depth; }
99 99
100 void set_nesting_depth (std::size_t depth) { m_nesting_depth = depth; } 100 void set_nesting_depth (std::size_t depth) { m_nesting_depth = depth; }
101 101
102 bool is_parent (void) const { return ! m_children.empty (); } 102 bool is_parent (void) const { return ! m_children.empty (); }
103 103
104 bool is_static (void) const { return m_is_static; } 104 bool is_static (void) const { return m_is_static; }
105 105
106 void mark_static (void) { m_is_static = true; } 106 void mark_static (void) { m_is_static = true; }
107 107
108 std::shared_ptr<symbol_scope_rep> parent_scope_rep (void) const 108 std::shared_ptr<symbol_scope_rep> parent_scope_rep (void) const
109 { 109 {
110 return m_parent.lock (); 110 return m_parent.lock ();
111 } 111 }
112 112
113 std::shared_ptr<symbol_scope_rep> primary_parent_scope_rep (void) const 113 std::shared_ptr<symbol_scope_rep> primary_parent_scope_rep (void) const
114 { 114 {
115 return m_primary_parent.lock (); 115 return m_primary_parent.lock ();
116 } 116 }
117 117
118 std::shared_ptr<symbol_scope_rep> dup (void) const 118 std::shared_ptr<symbol_scope_rep> dup (void) const
119 { 119 {
120 std::shared_ptr<symbol_scope_rep> new_sid 120 std::shared_ptr<symbol_scope_rep> new_sid
121 = std::shared_ptr<symbol_scope_rep> (new symbol_scope_rep (m_name)); 121 = std::shared_ptr<symbol_scope_rep> (new symbol_scope_rep (m_name));
122 122
123 for (const auto& nm_sr : m_symbols) 123 for (const auto& nm_sr : m_symbols)
124 new_sid->m_symbols[nm_sr.first] = nm_sr.second.dup (); 124 new_sid->m_symbols[nm_sr.first] = nm_sr.second.dup ();
125 125
126 new_sid->m_subfunctions = m_subfunctions; 126 new_sid->m_subfunctions = m_subfunctions;
127 new_sid->m_persistent_values = m_persistent_values; 127 new_sid->m_persistent_values = m_persistent_values;
128 new_sid->m_subfunction_names = m_subfunction_names; 128 new_sid->m_subfunction_names = m_subfunction_names;
129 new_sid->m_code = m_code; 129 new_sid->m_code = m_code;
130 new_sid->m_fcn_name = m_fcn_name; 130 new_sid->m_fcn_name = m_fcn_name;
131 new_sid->m_fcn_file_name = m_fcn_file_name; 131 new_sid->m_fcn_file_name = m_fcn_file_name;
132 new_sid->m_dir_name = m_dir_name; 132 new_sid->m_dir_name = m_dir_name;
133 new_sid->m_parent = m_parent; 133 new_sid->m_parent = m_parent;
134 new_sid->m_primary_parent = m_primary_parent; 134 new_sid->m_primary_parent = m_primary_parent;
135 new_sid->m_children = m_children; 135 new_sid->m_children = m_children;
136 new_sid->m_nesting_depth = m_nesting_depth; 136 new_sid->m_nesting_depth = m_nesting_depth;
137 new_sid->m_is_static = m_is_static; 137 new_sid->m_is_static = m_is_static;
138 new_sid->m_is_primary_fcn_scope = m_is_primary_fcn_scope; 138 new_sid->m_is_primary_fcn_scope = m_is_primary_fcn_scope;
139 139
140 return new_sid; 140 return new_sid;
141 } 141 }
142 142
143 octave_value& persistent_varref (std::size_t data_offset) 143 octave_value& persistent_varref (std::size_t data_offset)
144 { 144 {
145 return m_persistent_values[data_offset]; 145 return m_persistent_values[data_offset];
146 } 146 }
147 147
148 octave_value persistent_varval (std::size_t data_offset) const 148 octave_value persistent_varval (std::size_t data_offset) const
149 { 149 {
150 auto p = m_persistent_values.find (data_offset); 150 auto p = m_persistent_values.find (data_offset);
151 151
152 return p == m_persistent_values.end () ? octave_value () : p->second; 152 return p == m_persistent_values.end () ? octave_value () : p->second;
153 } 153 }
154 154
155 symbol_record find_symbol (const std::string& name) 155 symbol_record find_symbol (const std::string& name)
156 { 156 {
157 auto p = m_symbols.find (name); 157 auto p = m_symbols.find (name);
158 158
159 if (p == m_symbols.end ()) 159 if (p == m_symbols.end ())
160 return insert (name); 160 return insert (name);
161 else 161 else
162 return p->second; 162 return p->second;
163 } 163 }
164 164
165 symbol_record lookup_symbol (const std::string& name) const 165 symbol_record lookup_symbol (const std::string& name) const
166 { 166 {
167 auto p = m_symbols.find (name); 167 auto p = m_symbols.find (name);
168 168
169 return p == m_symbols.end () ? symbol_record () : p->second; 169 return p == m_symbols.end () ? symbol_record () : p->second;
170 } 170 }
171 171
172 symbol_record insert (const std::string& name); 172 symbol_record insert (const std::string& name);
173 173
174 void rename (const std::string& old_name, const std::string& new_name) 174 void rename (const std::string& old_name, const std::string& new_name)
175 { 175 {
176 auto p = m_symbols.find (old_name); 176 auto p = m_symbols.find (old_name);
177 177
178 if (p != m_symbols.end ()) 178 if (p != m_symbols.end ())
179 { 179 {
180 symbol_record sr = p->second; 180 symbol_record sr = p->second;
181 181
182 sr.rename (new_name); 182 sr.rename (new_name);
183 183
184 m_symbols.erase (p); 184 m_symbols.erase (p);
185 185
186 m_symbols[new_name] = sr; 186 m_symbols[new_name] = sr;
187 } 187 }
188 } 188 }
189 189
190 void install_subfunction (const std::string& name, 190 void install_subfunction (const std::string& name,
191 const octave_value& fval) 191 const octave_value& fval)
192 { 192 {
193 m_subfunctions[name] = fval; 193 m_subfunctions[name] = fval;
194 } 194 }
195 195
196 void install_nestfunction (const std::string& name, 196 void install_nestfunction (const std::string& name,
197 const octave_value& fval, 197 const octave_value& fval,
198 const symbol_scope& fcn_scope) 198 const symbol_scope& fcn_scope)
199 { 199 {
200 m_subfunctions[name] = fval; 200 m_subfunctions[name] = fval;
201 201
202 m_children.push_back (fcn_scope); 202 m_children.push_back (fcn_scope);
203 } 203 }
204 204
205 octave_value find_subfunction (const std::string& name) const; 205 octave_value find_subfunction (const std::string& name) const;
206 206
207 void lock_subfunctions (void) 207 void lock_subfunctions (void)
208 { 208 {
209 for (auto& nm_sf : m_subfunctions) 209 for (auto& nm_sf : m_subfunctions)
210 nm_sf.second.lock (); 210 nm_sf.second.lock ();
211 } 211 }
212 212
213 void unlock_subfunctions (void) 213 void unlock_subfunctions (void)
214 { 214 {
215 for (auto& nm_sf : m_subfunctions) 215 for (auto& nm_sf : m_subfunctions)
216 nm_sf.second.unlock (); 216 nm_sf.second.unlock ();
217 } 217 }
218 218
219 // Pairs of name, function objects. 219 // Pairs of name, function objects.
220 std::map<std::string, octave_value> subfunctions (void) const 220 std::map<std::string, octave_value> subfunctions (void) const
221 { 221 {
222 return m_subfunctions; 222 return m_subfunctions;
223 } 223 }
224 224
225 void erase_subfunctions (void) 225 void erase_subfunctions (void)
226 { 226 {
227 m_subfunctions.clear (); 227 m_subfunctions.clear ();
228 } 228 }
229 229
230 void mark_subfunctions_in_scope_as_private (const std::string& class_name); 230 void mark_subfunctions_in_scope_as_private (const std::string& class_name);
231 231
232 bool has_subfunctions (void) const 232 bool has_subfunctions (void) const
233 { 233 {
234 return ! m_subfunction_names.empty (); 234 return ! m_subfunction_names.empty ();
235 } 235 }
236 236
237 void stash_subfunction_names (const std::list<std::string>& names) 237 void stash_subfunction_names (const std::list<std::string>& names)
238 { 238 {
239 m_subfunction_names = names; 239 m_subfunction_names = names;
240 } 240 }
241 241
242 std::list<std::string> subfunction_names (void) const 242 std::list<std::string> subfunction_names (void) const
243 { 243 {
244 return m_subfunction_names; 244 return m_subfunction_names;
245 } 245 }
246 246
247 std::list<octave_value> localfunctions (void) const; 247 std::list<octave_value> localfunctions (void) const;
248 248
249 octave_value dump (void) const; 249 octave_value dump (void) const;
250 250
251 std::string name (void) const { return m_name; } 251 std::string name (void) const { return m_name; }
252 252
253 void cache_name (const std::string& name) { m_name = name; } 253 void cache_name (const std::string& name) { m_name = name; }
254 254
255 std::string fcn_name (void) const { return m_fcn_name; } 255 std::string fcn_name (void) const { return m_fcn_name; }
256 256
257 void cache_fcn_name (const std::string& name) { m_fcn_name = name; } 257 void cache_fcn_name (const std::string& name) { m_fcn_name = name; }
258 258
259 std::list<std::string> parent_fcn_names (void) const; 259 std::list<std::string> parent_fcn_names (void) const;
260 260
261 octave_user_code * user_code (void) const { return m_code; } 261 octave_user_code * user_code (void) const { return m_code; }
262 262
263 void set_user_code (octave_user_code *code) { m_code = code; } 263 void set_user_code (octave_user_code *code) { m_code = code; }
264 264
265 void set_parent (const std::shared_ptr<symbol_scope_rep>& parent); 265 void set_parent (const std::shared_ptr<symbol_scope_rep>& parent);
266 266
267 void set_primary_parent (const std::shared_ptr<symbol_scope_rep>& parent); 267 void set_primary_parent (const std::shared_ptr<symbol_scope_rep>& parent);
268 268
269 void cache_fcn_file_name (const std::string& name) 269 void cache_fcn_file_name (const std::string& name)
270 { 270 {
271 m_fcn_file_name = name; 271 m_fcn_file_name = name;
272 } 272 }
273 273
274 std::string fcn_file_name (void) const { return m_fcn_file_name; } 274 std::string fcn_file_name (void) const { return m_fcn_file_name; }
275 275
276 void cache_dir_name (const std::string& name); 276 void cache_dir_name (const std::string& name);
277 277
278 std::string dir_name (void) const { return m_dir_name; } 278 std::string dir_name (void) const { return m_dir_name; }
279 279
280 void mark_primary_fcn_scope (void) { m_is_primary_fcn_scope = true; } 280 void mark_primary_fcn_scope (void) { m_is_primary_fcn_scope = true; }
281 281
282 bool is_primary_fcn_scope (void) const { return m_is_primary_fcn_scope; } 282 bool is_primary_fcn_scope (void) const { return m_is_primary_fcn_scope; }
283 283
284 bool is_relative (const std::shared_ptr<symbol_scope_rep>& scope) const; 284 bool is_relative (const std::shared_ptr<symbol_scope_rep>& scope) const;
285 285
286 void mark_as_variable (const std::string& nm); 286 void mark_as_variable (const std::string& nm);
287 void mark_as_variables (const std::list<std::string>& lst); 287 void mark_as_variables (const std::list<std::string>& lst);
288 288
289 bool is_variable (const std::string& nm) const; 289 bool is_variable (const std::string& nm) const;
290 290
291 void update_nest (void); 291 void update_nest (void);
292 292
293 bool look_nonlocal (const std::string& name, std::size_t offset, 293 bool look_nonlocal (const std::string& name, std::size_t offset,
294 symbol_record& result); 294 symbol_record& result);
295 295
296 octave_value dump_symbols_map (void) const; 296 octave_value dump_symbols_map (void) const;
297 297
298 const std::map<std::string, symbol_record>& symbols (void) const 298 const std::map<std::string, symbol_record>& symbols (void) const
299 { 299 {
300 return m_symbols; 300 return m_symbols;
301 } 301 }
302 302
303 std::map<std::string, symbol_record>& symbols (void) 303 std::map<std::string, symbol_record>& symbols (void)
304 { 304 {
305 return m_symbols; 305 return m_symbols;
306 } 306 }
307 307
308 std::list<symbol_record> symbol_list (void) const; 308 std::list<symbol_record> symbol_list (void) const;
309 309
310 private: 310 private:
311 311
312 //! Name for this scope (usually the corresponding filename of the 312 //! Name for this scope (usually the corresponding filename of the
313 //! function corresponding to the scope). 313 //! function corresponding to the scope).
314 314
315 std::string m_name; 315 std::string m_name;
316 316
317 //! Map from symbol names to symbol info. 317 //! Map from symbol names to symbol info.
318 318
319 std::map<std::string, symbol_record> m_symbols; 319 std::map<std::string, symbol_record> m_symbols;
320 320
321 //! Map from symbol names to subfunctions. 321 //! Map from symbol names to subfunctions.
322 322
323 std::map<std::string, octave_value> m_subfunctions; 323 std::map<std::string, octave_value> m_subfunctions;
324 324
325 //! Map from data offset to persistent values in this scope. 325 //! Map from data offset to persistent values in this scope.
326 std::map<std::size_t, octave_value> m_persistent_values; 326 std::map<std::size_t, octave_value> m_persistent_values;
327 327
328 //! The list of subfunctions (if any) in the order they appear in 328 //! The list of subfunctions (if any) in the order they appear in
329 //! the function file. 329 //! the function file.
330 330
331 std::list<std::string> m_subfunction_names; 331 std::list<std::string> m_subfunction_names;
332 332
333 //! The associated user code (may be null). 333 //! The associated user code (may be null).
334 334
335 octave_user_code *m_code; 335 octave_user_code *m_code;
336 336
337 //! Simple name of the function corresponding to this scope. 337 //! Simple name of the function corresponding to this scope.
338 338
339 std::string m_fcn_name; 339 std::string m_fcn_name;
340 340
341 //! The file name associated with m_code. 341 //! The file name associated with m_code.
342 342
343 std::string m_fcn_file_name; 343 std::string m_fcn_file_name;
344 344
345 //! The directory associated with m_code. 345 //! The directory associated with m_code.
346 346
347 std::string m_dir_name; 347 std::string m_dir_name;
348 348
349 //! Parent of nested function (may be null). 349 //! Parent of nested function (may be null).
350 350
351 std::weak_ptr<symbol_scope_rep> m_parent; 351 std::weak_ptr<symbol_scope_rep> m_parent;
352 352
353 //! Primary (top) parent of nested function (may be null). Used 353 //! Primary (top) parent of nested function (may be null). Used
354 //! to determine whether two nested functions are related. 354 //! to determine whether two nested functions are related.
355 355
356 std::weak_ptr<symbol_scope_rep> m_primary_parent; 356 std::weak_ptr<symbol_scope_rep> m_primary_parent;
357 357
358 //! Child nested functions. 358 //! Child nested functions.
359 359
360 std::vector<symbol_scope> m_children; 360 std::vector<symbol_scope> m_children;
361 361
362 //! If true, then this scope belongs to a nested function. 362 //! If true, then this scope belongs to a nested function.
363 363
364 std::size_t m_nesting_depth; 364 std::size_t m_nesting_depth;
365 365
366 //! If true then no variables can be added. 366 //! If true then no variables can be added.
367 367
368 bool m_is_static; 368 bool m_is_static;
369 369
370 //! If true, this is the scope of a primary function. 370 //! If true, this is the scope of a primary function.
371 bool m_is_primary_fcn_scope; 371 bool m_is_primary_fcn_scope;
372 }; 372 };
373 373
374 class symbol_scope 374 class symbol_scope
375 { 375 {
376 public: 376 public:
377 377
378 // Create a valid but possibly unnamed scope. 378 // Create a valid but possibly unnamed scope.
379 symbol_scope (const std::string& name) 379 symbol_scope (const std::string& name)
380 : m_rep (new symbol_scope_rep (name)) 380 : m_rep (new symbol_scope_rep (name))
381 { } 381 { }
382 382
383 // NEW_REP must be dynamically allocated or nullptr. If it is 383 // NEW_REP must be dynamically allocated or nullptr. If it is
384 // nullptr, the scope is invalid. 384 // nullptr, the scope is invalid.
385 symbol_scope (const std::shared_ptr<symbol_scope_rep> new_rep = nullptr) 385 symbol_scope (const std::shared_ptr<symbol_scope_rep> new_rep = nullptr)
386 : m_rep (new_rep) 386 : m_rep (new_rep)
387 { } 387 { }
388 388
389 symbol_scope (const symbol_scope&) = default; 389 symbol_scope (const symbol_scope&) = default;
390 390
391 symbol_scope& operator = (const symbol_scope&) = default; 391 symbol_scope& operator = (const symbol_scope&) = default;
392 392
393 ~symbol_scope (void) = default; 393 ~symbol_scope (void) = default;
394 394
395 bool is_valid (void) const { return bool (m_rep); } 395 bool is_valid (void) const { return bool (m_rep); }
396 396
397 explicit operator bool () const { return bool (m_rep); } 397 explicit operator bool () const { return bool (m_rep); }
398 398
399 std::size_t num_symbols (void) const 399 std::size_t num_symbols (void) const
400 { 400 {
401 return m_rep ? m_rep->num_symbols () : 0; 401 return m_rep ? m_rep->num_symbols () : 0;
402 } 402 }
403 403
404 symbol_record insert_local (const std::string& name) 404 symbol_record insert_local (const std::string& name)
405 { 405 {
406 return m_rep ? m_rep->insert_local (name) : symbol_record (); 406 return m_rep ? m_rep->insert_local (name) : symbol_record ();
407 } 407 }
408 408
409 void insert_symbol_record (symbol_record& sr) 409 void insert_symbol_record (symbol_record& sr)
410 { 410 {
411 if (m_rep) 411 if (m_rep)
412 m_rep->insert_symbol_record (sr); 412 m_rep->insert_symbol_record (sr);
413 } 413 }
414 414
415 bool is_nested (void) const 415 bool is_nested (void) const
416 { 416 {
417 return m_rep ? m_rep->is_nested () : false; 417 return m_rep ? m_rep->is_nested () : false;
418 } 418 }
419 419
420 bool is_parent (void) const 420 bool is_parent (void) const
421 { 421 {
422 return m_rep ? m_rep->is_parent () : false; 422 return m_rep ? m_rep->is_parent () : false;
423 } 423 }
424 424
425 void set_nesting_depth (std::size_t depth) 425 void set_nesting_depth (std::size_t depth)
426 { 426 {
427 if (m_rep) 427 if (m_rep)
428 m_rep->set_nesting_depth (depth); 428 m_rep->set_nesting_depth (depth);
429 } 429 }
430 430
431 std::size_t nesting_depth (void) const 431 std::size_t nesting_depth (void) const
432 { 432 {
433 return m_rep ? m_rep->nesting_depth () : 0; 433 return m_rep ? m_rep->nesting_depth () : 0;
434 } 434 }
435 435
436 bool is_static (void) const 436 bool is_static (void) const
437 { 437 {
438 return m_rep ? m_rep->is_static () : false; 438 return m_rep ? m_rep->is_static () : false;
439 } 439 }
440 440
441 void mark_static (void) 441 void mark_static (void)
442 { 442 {
443 if (m_rep) 443 if (m_rep)
444 m_rep->mark_static (); 444 m_rep->mark_static ();
445 } 445 }
446 446
447 std::shared_ptr<symbol_scope_rep> parent_scope (void) const 447 std::shared_ptr<symbol_scope_rep> parent_scope (void) const
448 { 448 {
449 return m_rep ? m_rep->parent_scope_rep () : nullptr; 449 return m_rep ? m_rep->parent_scope_rep () : nullptr;
450 } 450 }
451 451
452 std::shared_ptr<symbol_scope_rep> primary_parent_scope (void) const 452 std::shared_ptr<symbol_scope_rep> primary_parent_scope (void) const
453 { 453 {
454 return m_rep ? m_rep->primary_parent_scope_rep () : nullptr; 454 return m_rep ? m_rep->primary_parent_scope_rep () : nullptr;
455 } 455 }
456 456
457 symbol_scope dup (void) const 457 symbol_scope dup (void) const
458 { 458 {
459 return symbol_scope (m_rep ? m_rep->dup () : nullptr); 459 return symbol_scope (m_rep ? m_rep->dup () : nullptr);
460 } 460 }
461 461
462 octave_value& persistent_varref (std::size_t data_offset) 462 octave_value& persistent_varref (std::size_t data_offset)
463 { 463 {
464 static octave_value dummy_value; 464 static octave_value dummy_value;
465 465
466 return m_rep ? m_rep->persistent_varref (data_offset) : dummy_value; 466 return m_rep ? m_rep->persistent_varref (data_offset) : dummy_value;
467 } 467 }
468 468
469 octave_value persistent_varval (std::size_t data_offset) const 469 octave_value persistent_varval (std::size_t data_offset) const
470 { 470 {
471 return m_rep ? m_rep->persistent_varval (data_offset) : octave_value (); 471 return m_rep ? m_rep->persistent_varval (data_offset) : octave_value ();
472 } 472 }
473 473
474 symbol_record find_symbol (const std::string& name) 474 symbol_record find_symbol (const std::string& name)
475 { 475 {
476 return m_rep ? m_rep->find_symbol (name) : symbol_record (); 476 return m_rep ? m_rep->find_symbol (name) : symbol_record ();
477 } 477 }
478 478
479 // Like find_symbol, but does not insert. 479 // Like find_symbol, but does not insert.
480 symbol_record lookup_symbol (const std::string& name) const 480 symbol_record lookup_symbol (const std::string& name) const
481 { 481 {
482 return m_rep ? m_rep->lookup_symbol (name) : symbol_record (); 482 return m_rep ? m_rep->lookup_symbol (name) : symbol_record ();
483 } 483 }
484 484
485 symbol_record insert (const std::string& name) 485 symbol_record insert (const std::string& name)
486 { 486 {
487 return m_rep ? m_rep->insert (name) : symbol_record (); 487 return m_rep ? m_rep->insert (name) : symbol_record ();
488 } 488 }
489 489
490 void rename (const std::string& old_name, const std::string& new_name) 490 void rename (const std::string& old_name, const std::string& new_name)
491 { 491 {
492 if (m_rep) 492 if (m_rep)
493 m_rep->rename (old_name, new_name); 493 m_rep->rename (old_name, new_name);
494 } 494 }
495 495
496 void install_subfunction (const std::string& name, 496 void install_subfunction (const std::string& name,
497 const octave_value& fval) 497 const octave_value& fval)
498 { 498 {
499 if (m_rep) 499 if (m_rep)
500 m_rep->install_subfunction (name, fval); 500 m_rep->install_subfunction (name, fval);
501 } 501 }
502 502
503 void install_nestfunction (const std::string& name, 503 void install_nestfunction (const std::string& name,
504 const octave_value& fval, 504 const octave_value& fval,
505 const symbol_scope& fcn_scope) 505 const symbol_scope& fcn_scope)
506 { 506 {
507 if (m_rep) 507 if (m_rep)
508 m_rep->install_nestfunction (name, fval, fcn_scope); 508 m_rep->install_nestfunction (name, fval, fcn_scope);
509 } 509 }
510 510
511 octave_value find_subfunction (const std::string& name) const 511 octave_value find_subfunction (const std::string& name) const
512 { 512 {
513 return m_rep ? m_rep->find_subfunction (name) : octave_value (); 513 return m_rep ? m_rep->find_subfunction (name) : octave_value ();
514 } 514 }
515 515
516 void lock_subfunctions (void) 516 void lock_subfunctions (void)
517 { 517 {
518 if (m_rep) 518 if (m_rep)
519 m_rep->lock_subfunctions (); 519 m_rep->lock_subfunctions ();
520 } 520 }
521 521
522 void unlock_subfunctions (void) 522 void unlock_subfunctions (void)
523 { 523 {
524 if (m_rep) 524 if (m_rep)
525 m_rep->unlock_subfunctions (); 525 m_rep->unlock_subfunctions ();
526 } 526 }
527 527
528 std::map<std::string, octave_value> subfunctions (void) const 528 std::map<std::string, octave_value> subfunctions (void) const
529 { 529 {
530 return (m_rep 530 return (m_rep
531 ? m_rep->subfunctions () 531 ? m_rep->subfunctions ()
532 : std::map<std::string, octave_value> ()); 532 : std::map<std::string, octave_value> ());
533 } 533 }
534 534
535 void erase_subfunctions (void) 535 void erase_subfunctions (void)
536 { 536 {
537 if (m_rep) 537 if (m_rep)
538 m_rep->erase_subfunctions (); 538 m_rep->erase_subfunctions ();
539 } 539 }
540 540
541 void mark_subfunctions_in_scope_as_private (const std::string& class_name) 541 void mark_subfunctions_in_scope_as_private (const std::string& class_name)
542 { 542 {
543 if (m_rep) 543 if (m_rep)
544 m_rep->mark_subfunctions_in_scope_as_private (class_name); 544 m_rep->mark_subfunctions_in_scope_as_private (class_name);
545 } 545 }
546 546
547 bool has_subfunctions (void) const 547 bool has_subfunctions (void) const
548 { 548 {
549 return m_rep ? m_rep->has_subfunctions () : false; 549 return m_rep ? m_rep->has_subfunctions () : false;
550 } 550 }
551 551
552 void stash_subfunction_names (const std::list<std::string>& names) 552 void stash_subfunction_names (const std::list<std::string>& names)
553 { 553 {
554 if (m_rep) 554 if (m_rep)
555 m_rep->stash_subfunction_names (names); 555 m_rep->stash_subfunction_names (names);
556 } 556 }
557 557
558 std::list<std::string> subfunction_names (void) const 558 std::list<std::string> subfunction_names (void) const
559 { 559 {
560 return m_rep ? m_rep->subfunction_names () : std::list<std::string> (); 560 return m_rep ? m_rep->subfunction_names () : std::list<std::string> ();
561 } 561 }
562 562
563 // List of function handle objects. 563 // List of function handle objects.
564 std::list<octave_value> localfunctions (void) const; 564 std::list<octave_value> localfunctions (void) const;
565 565
566 octave_value dump (void) const 566 octave_value dump (void) const
567 { 567 {
568 return m_rep ? m_rep->dump () : octave_value (); 568 return m_rep ? m_rep->dump () : octave_value ();
569 } 569 }
570 570
571 std::string name (void) const 571 std::string name (void) const
572 { 572 {
573 return m_rep ? m_rep->name () : ""; 573 return m_rep ? m_rep->name () : "";
574 } 574 }
575 575
576 void cache_name (const std::string& name) 576 void cache_name (const std::string& name)
577 { 577 {
578 if (m_rep) 578 if (m_rep)
579 m_rep->cache_name (name); 579 m_rep->cache_name (name);
580 } 580 }
581 581
582 std::string fcn_name (void) const 582 std::string fcn_name (void) const
583 { 583 {
584 return m_rep ? m_rep->fcn_name () : ""; 584 return m_rep ? m_rep->fcn_name () : "";
585 } 585 }
586 586
587 void cache_fcn_name (const std::string& name) 587 void cache_fcn_name (const std::string& name)
588 { 588 {
589 if (m_rep) 589 if (m_rep)
590 m_rep->cache_fcn_name (name); 590 m_rep->cache_fcn_name (name);
591 } 591 }
592 592
593 std::list<std::string> parent_fcn_names (void) const 593 std::list<std::string> parent_fcn_names (void) const
594 { 594 {
595 return m_rep ? m_rep->parent_fcn_names () : std::list<std::string> (); 595 return m_rep ? m_rep->parent_fcn_names () : std::list<std::string> ();
596 } 596 }
597 597
598 octave_user_code * user_code (void) const 598 octave_user_code * user_code (void) const
599 { 599 {
600 return m_rep ? m_rep->user_code () : nullptr; 600 return m_rep ? m_rep->user_code () : nullptr;
601 } 601 }
602 602
603 void set_user_code (octave_user_code *code) 603 void set_user_code (octave_user_code *code)
604 { 604 {
605 if (m_rep) 605 if (m_rep)
606 m_rep->set_user_code (code); 606 m_rep->set_user_code (code);
607 } 607 }
608 608
609 void set_parent (const symbol_scope& p) 609 void set_parent (const symbol_scope& p)
610 { 610 {
611 if (m_rep) 611 if (m_rep)
612 m_rep->set_parent (p.get_rep ()); 612 m_rep->set_parent (p.get_rep ());
613 } 613 }
614 614
615 void set_primary_parent (const symbol_scope& p) 615 void set_primary_parent (const symbol_scope& p)
616 { 616 {
617 if (m_rep) 617 if (m_rep)
618 m_rep->set_primary_parent (p.get_rep ()); 618 m_rep->set_primary_parent (p.get_rep ());
619 } 619 }
620 620
621 void cache_fcn_file_name (const std::string& name) 621 void cache_fcn_file_name (const std::string& name)
622 { 622 {
623 if (m_rep) 623 if (m_rep)
624 m_rep->cache_fcn_file_name (name); 624 m_rep->cache_fcn_file_name (name);
625 } 625 }
626 626
627 void cache_dir_name (const std::string& name) 627 void cache_dir_name (const std::string& name)
628 { 628 {
629 if (m_rep) 629 if (m_rep)
630 m_rep->cache_dir_name (name); 630 m_rep->cache_dir_name (name);
631 } 631 }
632 632
633 std::string fcn_file_name (void) const 633 std::string fcn_file_name (void) const
634 { 634 {
635 return m_rep ? m_rep->fcn_file_name () : ""; 635 return m_rep ? m_rep->fcn_file_name () : "";
636 } 636 }
637 637
638 std::string dir_name (void) const 638 std::string dir_name (void) const
639 { 639 {
640 return m_rep ? m_rep->dir_name () : ""; 640 return m_rep ? m_rep->dir_name () : "";
641 } 641 }
642 642
643 void mark_primary_fcn_scope (void) 643 void mark_primary_fcn_scope (void)
644 { 644 {
645 if (m_rep) 645 if (m_rep)
646 m_rep->mark_primary_fcn_scope (); 646 m_rep->mark_primary_fcn_scope ();
647 } 647 }
648 648
649 bool is_primary_fcn_scope (void) const 649 bool is_primary_fcn_scope (void) const
650 { 650 {
651 return m_rep ? m_rep->is_primary_fcn_scope () : false; 651 return m_rep ? m_rep->is_primary_fcn_scope () : false;
652 } 652 }
653 653
654 bool is_relative (const symbol_scope& scope) const 654 bool is_relative (const symbol_scope& scope) const
655 { 655 {
656 return m_rep ? m_rep->is_relative (scope.get_rep ()) : false; 656 return m_rep ? m_rep->is_relative (scope.get_rep ()) : false;
657 } 657 }
658 658
659 void mark_as_variable (const std::string& nm) 659 void mark_as_variable (const std::string& nm)
660 { 660 {
661 if (m_rep) 661 if (m_rep)
662 m_rep->mark_as_variable (nm); 662 m_rep->mark_as_variable (nm);
663 } 663 }
664 664
665 void mark_as_variables (const std::list<std::string>& lst) 665 void mark_as_variables (const std::list<std::string>& lst)
666 { 666 {
667 if (m_rep) 667 if (m_rep)
668 m_rep->mark_as_variables (lst); 668 m_rep->mark_as_variables (lst);
669 } 669 }
670 670
671 bool is_variable (const std::string& nm) const 671 bool is_variable (const std::string& nm) const
672 { 672 {
673 return m_rep ? m_rep->is_variable (nm) : false; 673 return m_rep ? m_rep->is_variable (nm) : false;
674 } 674 }
675 675
676 void update_nest (void) 676 void update_nest (void)
677 { 677 {
678 if (m_rep) 678 if (m_rep)
679 m_rep->update_nest (); 679 m_rep->update_nest ();
680 } 680 }
681 681
682 bool look_nonlocal (const std::string& name, std::size_t offset, 682 bool look_nonlocal (const std::string& name, std::size_t offset,
683 symbol_record& result) 683 symbol_record& result)
684 { 684 {
685 return m_rep ? m_rep->look_nonlocal (name, offset, result) : false; 685 return m_rep ? m_rep->look_nonlocal (name, offset, result) : false;
686 } 686 }
687 687
688 std::shared_ptr<symbol_scope_rep> get_rep (void) const 688 std::shared_ptr<symbol_scope_rep> get_rep (void) const
689 { 689 {
690 return m_rep; 690 return m_rep;
691 } 691 }
692 692
693 friend bool operator == (const symbol_scope& a, const symbol_scope& b) 693 friend bool operator == (const symbol_scope& a, const symbol_scope& b)
694 { 694 {
695 return a.m_rep == b.m_rep; 695 return a.m_rep == b.m_rep;
696 } 696 }
697 697
698 friend bool operator != (const symbol_scope& a, const symbol_scope& b) 698 friend bool operator != (const symbol_scope& a, const symbol_scope& b)
699 { 699 {
700 return a.m_rep != b.m_rep; 700 return a.m_rep != b.m_rep;
701 } 701 }
702 702
703 const std::map<std::string, symbol_record>& symbols (void) const 703 const std::map<std::string, symbol_record>& symbols (void) const
704 { 704 {
705 static const std::map<std::string, symbol_record> empty_map; 705 static const std::map<std::string, symbol_record> empty_map;
706 706
707 return m_rep ? m_rep->symbols () : empty_map; 707 return m_rep ? m_rep->symbols () : empty_map;
708 } 708 }
709 709
710 std::map<std::string, symbol_record>& symbols (void) 710 std::map<std::string, symbol_record>& symbols (void)
711 { 711 {
712 static std::map<std::string, symbol_record> empty_map; 712 static std::map<std::string, symbol_record> empty_map;
713 713
714 return m_rep ? m_rep->symbols () : empty_map; 714 return m_rep ? m_rep->symbols () : empty_map;
715 } 715 }
716 716
717 std::list<symbol_record> symbol_list (void) const 717 std::list<symbol_record> symbol_list (void) const
718 { 718 {
719 static const std::list<symbol_record> empty_list; 719 static const std::list<symbol_record> empty_list;
720 720
721 return m_rep ? m_rep->symbol_list () : empty_list; 721 return m_rep ? m_rep->symbol_list () : empty_list;
722 } 722 }
723 723
724 private: 724 private:
725 725
726 std::shared_ptr<symbol_scope_rep> m_rep; 726 std::shared_ptr<symbol_scope_rep> m_rep;
727 }; 727 };
728 728
729 OCTAVE_END_NAMESPACE(octave) 729 OCTAVE_END_NAMESPACE(octave)
730 730
731 #endif 731 #endif