annotate libinterp/corefcn/symscope.h @ 24706:30e1d0bf7ade

use weak_ptr for symbol_scope_rep and symbol_record_rep pointers (bug #53092) * symrec.h, symrec.cc (symbol_record_rep::m_fwd_scope): Manage with std::weak_ptr. Change all uses. Wrap symbol_record_rep and symbol_scope_rep pointers in std::shared_ptr<>. * symscope.h, symscope.cc (symbol_scope_rep::m_parent): Manage with std::weak_ptr. Change all uses. Wrap symbol_record_rep and symbol_scope_rep pointers in std::shared_ptr<>. (symbol_scope_rep::m_parent_fcn): Delete. (symbol_scope_rep::set_parent): Simplify. (symbol_scope_rep): Derive from std::enable_shared_from_this. (symbol_scope_rep::look_nonlocal): Use shared_from_this instead of raw pointer to this. (symbol_scope_rep::get_rep_ptr, symbol_scope_rep::parent_scope_rep, symbol_scope_rep::parent_fcn, symbol_scope::parent_fcn): Delete. Delete <, <=, >=, and > operators. * call-stack.cc (call_stack::goto_frame, call_stack::backtrace): Don't display or return pointer to symbol_scope_rep. diff --git a/libinterp/corefcn/call-stack.cc b/libinterp/corefcn/call-stack.cc --- a/libinterp/corefcn/call-stack.cc +++ b/libinterp/corefcn/call-stack.cc @@ -394,7 +394,6 @@ namespace octave << " at line " << elt.m_line << " column " << elt.m_column << " [" << elt.fcn_file_name () << "] " - << " (scope = " << elt.m_scope.get_rep_ptr () << "[context = " << elt.m_context << "])" << std::endl; } @@ -578,14 +577,12 @@ namespace octave Cell& name = retval.contents (1); Cell& line = retval.contents (2); Cell& column = retval.contents (3); - Cell& scope = retval.contents (4); Cell& context = retval.contents (5); octave_idx_type k = 0; for (const auto& frm : frames) { - scope(k) = frm.m_scope.get_rep_ptr (); context(k) = frm.m_context; file(k) = frm.fcn_file_name (); name(k) = frm.fcn_name (print_subfn); diff --git a/libinterp/corefcn/symrec.cc b/libinterp/corefcn/symrec.cc --- a/libinterp/corefcn/symrec.cc +++ b/libinterp/corefcn/symrec.cc @@ -49,7 +49,8 @@ namespace octave // only in symbol_record::symbol_record_rep::varref and // symbol_record::symbol_record_rep::varval. - return m_fwd_scope ? m_fwd_scope->current_context () : 0; + auto t_fwd_scope = m_fwd_scope.lock (); + return t_fwd_scope ? t_fwd_scope->current_context () : 0; } void @@ -64,8 +65,8 @@ namespace octave mark_persistent (); } - symbol_record::symbol_record_rep * - symbol_record::symbol_record_rep::dup (symbol_scope_rep *new_scope) const + std::shared_ptr<symbol_record::symbol_record_rep> + symbol_record::symbol_record_rep::dup (const std::shared_ptr<symbol_scope_rep>& new_scope) const { // FIXME: is this the right thing do to? if (auto t_fwd_rep = m_fwd_rep.lock ()) @@ -73,8 +74,9 @@ namespace octave static const context_id FIXME_CONTEXT = 0; - return new symbol_record_rep (m_name, varval (FIXME_CONTEXT), - m_storage_class); + return std::shared_ptr<symbol_record_rep> + (new symbol_record_rep (m_name, varval (FIXME_CONTEXT), + m_storage_class)); } octave_value diff --git a/libinterp/corefcn/symrec.h b/libinterp/corefcn/symrec.h --- a/libinterp/corefcn/symrec.h +++ b/libinterp/corefcn/symrec.h @@ -80,7 +80,7 @@ namespace octave symbol_record_rep (const std::string& nm, const octave_value& v, unsigned int sc) - : m_storage_class (sc), m_name (nm), m_fwd_scope (nullptr), + : m_storage_class (sc), m_name (nm), m_fwd_scope (), m_fwd_rep (), m_value_stack () { m_value_stack.push_back (v); @@ -478,7 +478,7 @@ namespace octave void init_persistent (void); - void bind_fwd_rep (symbol_scope_rep *fwd_scope, + void bind_fwd_rep (const std::shared_ptr<symbol_scope_rep>& fwd_scope, const std::shared_ptr<symbol_record_rep>& fwd_rep) { // If this object is already bound to another scope (for @@ -504,11 +504,12 @@ namespace octave // global in a script remain linked as globals in the // enclosing scope. - m_fwd_scope = nullptr; + m_fwd_scope = std::weak_ptr<symbol_scope_rep> (); m_fwd_rep.reset (); } - symbol_record_rep * dup (symbol_scope_rep *new_scope) const; + std::shared_ptr<symbol_record_rep> + dup (const std::shared_ptr<symbol_scope_rep>& new_scope) const; octave_value dump (context_id context) const; @@ -522,7 +523,7 @@ namespace octave std::string m_name; - symbol_scope_rep *m_fwd_scope; + std::weak_ptr<symbol_scope_rep> m_fwd_scope; std::weak_ptr<symbol_record_rep> m_fwd_rep; @@ -543,7 +544,7 @@ namespace octave ~symbol_record (void) = default; - symbol_record dup (symbol_scope_rep *sid) const + symbol_record dup (const std::shared_ptr<symbol_scope_rep>& sid) const { return symbol_record (m_rep->dup (sid)); } @@ -652,7 +653,8 @@ namespace octave unsigned int storage_class (void) const { return m_rep->storage_class (); } - void bind_fwd_rep (symbol_scope_rep *fwd_scope, const symbol_record& sr) + void bind_fwd_rep (const std::shared_ptr<symbol_scope_rep>& fwd_scope, + const symbol_record& sr) { m_rep->bind_fwd_rep (fwd_scope, sr.m_rep); } @@ -669,7 +671,9 @@ namespace octave std::shared_ptr<symbol_record_rep> m_rep; // NEW_REP must be dynamically allocated or nullptr. - symbol_record (symbol_record_rep *new_rep) : m_rep (new_rep) { } + symbol_record (const std::shared_ptr<symbol_record_rep>& new_rep) + : m_rep (new_rep) + { } octave_value find_function (const std::string& name, const octave_value_list& args) const; diff --git a/libinterp/corefcn/symscope.cc b/libinterp/corefcn/symscope.cc --- a/libinterp/corefcn/symscope.cc +++ b/libinterp/corefcn/symscope.cc @@ -93,7 +93,9 @@ namespace octave { symbol_record ret (name); - if (m_is_nested && m_parent && m_parent->look_nonlocal (name, ret)) + auto t_parent = m_parent.lock (); + + if (m_is_nested && t_parent && t_parent->look_nonlocal (name, ret)) return m_symbols[name] = ret; else { @@ -141,8 +143,10 @@ namespace octave if (p != m_subfunctions.end ()) return p->second; - if (m_parent) - return m_parent->find_subfunction (name); + auto t_parent = m_parent.lock (); + + if (t_parent) + return t_parent->find_subfunction (name); return octave_value (); } @@ -160,31 +164,17 @@ namespace octave } void - symbol_scope_rep::set_parent (symbol_scope_rep *p) + symbol_scope_rep::set_parent (const std::shared_ptr<symbol_scope_rep>& parent) { - m_parent = p; - - if (m_parent) - { - // If m_parent is the top-level scope, there will be no parent - // function. - - octave_function *current_fcn = function (); - - if (current_fcn && current_fcn->is_anonymous_function ()) - { - octave_function *parent_fcn = m_parent->function (); - - if (parent_fcn) - m_parent_fcn = octave_value (parent_fcn, true); - } - } + m_parent = std::weak_ptr<symbol_scope_rep> (parent); } void symbol_scope_rep::update_nest (void) { - if (m_parent) + auto t_parent = m_parent.lock (); + + if (t_parent) { // fix bad symbol_records for (auto& nm_sr : m_symbols) @@ -192,7 +182,7 @@ namespace octave symbol_record& ours = nm_sr.second; if (! ours.is_formal () - && m_is_nested && m_parent->look_nonlocal (nm_sr.first, ours)) + && m_is_nested && t_parent->look_nonlocal (nm_sr.first, ours)) { if (ours.is_global () || ours.is_persistent ()) error ("global and persistent may only be used in the topmost level in which a nested variable is used"); @@ -219,12 +209,14 @@ namespace octave table_iterator p = m_symbols.find (name); if (p == m_symbols.end ()) { - if (m_is_nested && m_parent) - return m_parent->look_nonlocal (name, result); + auto t_parent = m_parent.lock (); + + if (m_is_nested && t_parent) + return t_parent->look_nonlocal (name, result); } else if (! p->second.is_automatic ()) { - result.bind_fwd_rep (this, p->second); + result.bind_fwd_rep (shared_from_this (), p->second); return true; } @@ -232,7 +224,8 @@ namespace octave } void - symbol_scope_rep::bind_script_symbols (symbol_scope_rep *curr_scope) + symbol_scope_rep::bind_script_symbols + (const std::shared_ptr<symbol_scope_rep>& curr_scope) { for (auto& nm_sr : m_symbols) nm_sr.second.bind_fwd_rep (curr_scope, diff --git a/libinterp/corefcn/symscope.h b/libinterp/corefcn/symscope.h --- a/libinterp/corefcn/symscope.h +++ b/libinterp/corefcn/symscope.h @@ -50,6 +50,7 @@ namespace octave class symbol_scope; class symbol_scope_rep + : public std::enable_shared_from_this<symbol_scope_rep> { public: @@ -64,9 +65,8 @@ namespace octave subfunctions_iterator; symbol_scope_rep (const std::string& name = "") - : m_name (name), m_symbols (), m_subfunctions (), - m_fcn (nullptr), m_parent (nullptr), m_parent_fcn (), - m_children (), m_is_nested (false), + : m_name (name), m_symbols (), m_subfunctions (), m_fcn (nullptr), + m_parent (), m_children (), m_is_nested (false), m_is_static (false), m_context (0) { } @@ -91,19 +91,20 @@ namespace octave void mark_static (void) { m_is_static = true; } - symbol_scope_rep * parent_scope_rep (void) const { return m_parent; } - - octave_value parent_fcn (void) const { return m_parent_fcn; } + std::shared_ptr<symbol_scope_rep> parent_scope_rep (void) const + { + return m_parent.lock (); + } - symbol_scope_rep * dup (void) const + std::shared_ptr<symbol_scope_rep> dup (void) const { - symbol_scope_rep *new_sid = new symbol_scope_rep (m_name); + std::shared_ptr<symbol_scope_rep> new_sid + = std::shared_ptr<symbol_scope_rep> (new symbol_scope_rep (m_name)); for (const auto& nm_sr : m_symbols) new_sid->insert_symbol_record (nm_sr.second.dup (new_sid)); new_sid->m_parent = m_parent; - new_sid->m_parent_fcn = m_parent_fcn; return new_sid; } @@ -128,7 +129,8 @@ namespace octave return p->second; } - void inherit_internal (symbol_scope_rep& donor_scope_rep) + void inherit_internal + (const std::shared_ptr<symbol_scope_rep>& donor_scope_rep) { for (auto& nm_sr : m_symbols) { @@ -140,7 +142,7 @@ namespace octave if (nm != "__retval__") { - octave_value val = donor_scope_rep.varval (nm); + octave_value val = donor_scope_rep->varval (nm); if (val.is_defined ()) { @@ -153,14 +155,16 @@ namespace octave } } - void inherit (symbol_scope_rep *donor_scope_rep) + void inherit (const std::shared_ptr<symbol_scope_rep>& donor_scope_rep) { - while (donor_scope_rep) + std::shared_ptr<symbol_scope_rep> dsr = donor_scope_rep; + + while (dsr) { - inherit_internal (*donor_scope_rep); + inherit_internal (dsr); - if (donor_scope_rep->is_nested ()) - donor_scope_rep = parent_scope_rep (); + if (dsr->is_nested ()) + dsr = parent_scope_rep (); else break; } @@ -513,13 +517,13 @@ namespace octave void set_function (octave_user_function *fcn) { m_fcn = fcn; } - void set_parent (symbol_scope_rep *p); + void set_parent (const std::shared_ptr<symbol_scope_rep>& parent); void update_nest (void); bool look_nonlocal (const std::string& name, symbol_record& result); - void bind_script_symbols (symbol_scope_rep *curr_scope); + void bind_script_symbols (const std::shared_ptr<symbol_scope_rep>& curr_scope); void unbind_script_symbols (void); @@ -545,8 +549,7 @@ namespace octave octave_user_function *m_fcn; // Parent of nested function (may be null). - symbol_scope_rep *m_parent; - octave_value m_parent_fcn; + std::weak_ptr<symbol_scope_rep> m_parent; // Child nested functions. std::vector<symbol_scope> m_children; @@ -571,7 +574,9 @@ namespace octave // NEW_REP must be dynamically allocated or nullptr. If it is // nullptr, the scope is invalid. - symbol_scope (symbol_scope_rep *new_rep = nullptr) : m_rep (new_rep) { } + symbol_scope (const std::shared_ptr<symbol_scope_rep> new_rep = nullptr) + : m_rep (new_rep) + { } symbol_scope (const symbol_scope&) = default; @@ -611,15 +616,17 @@ namespace octave m_rep->mark_static (); } - symbol_scope_rep * parent_scope (void) const + std::shared_ptr<symbol_scope_rep> parent_scope (void) const { return m_rep ? m_rep->parent_scope_rep () : nullptr; } - octave_value parent_fcn (void) const + octave_value parent_fcn (void) const; +#if 0 { return m_rep ? m_rep->parent_fcn () : octave_value (); } +#endif symbol_scope dup (void) const { @@ -906,12 +913,6 @@ namespace octave m_rep->set_parent (p.get_rep ()); } - void set_parent (symbol_scope_rep *p) - { - if (m_rep) - m_rep->set_parent (p); - } - void update_nest (void) { if (m_rep) @@ -935,9 +936,9 @@ namespace octave m_rep->unbind_script_symbols (); } - symbol_scope_rep * get_rep (void) const + std::shared_ptr<symbol_scope_rep> get_rep (void) const { - return m_rep.get (); + return m_rep; } friend bool operator == (const symbol_scope& a, const symbol_scope& b) @@ -950,28 +951,6 @@ namespace octave return a.m_rep != b.m_rep; } - friend bool operator < (const symbol_scope& a, const symbol_scope& b) - { - return a.m_rep < b.m_rep; - } - - friend bool operator <= (const symbol_scope& a, const symbol_scope& b) - { - return a.m_rep <= b.m_rep; - } - - friend bool operator >= (const symbol_scope& a, const symbol_scope& b) - { - return a.m_rep >= b.m_rep; - } - - friend bool operator > (const symbol_scope& a, const symbol_scope& b) - { - return a.m_rep > b.m_rep; - } - - symbol_scope_rep * get_rep_ptr (void) const { return m_rep.get (); } - private: std::shared_ptr<symbol_scope_rep> m_rep; @@ -980,11 +959,6 @@ namespace octave { return m_rep ? m_rep->dump_symbols_map () : octave_value (); } - - symbol_scope_rep * parent_scope_rep (void) const - { - return m_rep ? m_rep->parent_scope_rep () : nullptr; - } }; }
author John W. Eaton <jwe@octave.org>
date Thu, 08 Feb 2018 04:06:03 -0500
parents 8b346a19108e
children 7edf1fb1d4b2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1 /*
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3 Copyright (C) 1993-2017 John W. Eaton
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4 Copyright (C) 2009 VZLU Prague
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6 This file is part of Octave.
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24377
diff changeset
8 Octave is free software: you can redistribute it and/or modify it
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24377
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11 (at your option) any later version.
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
12
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
14 WITHOUT ANY WARRANTY; without even the implied warranty of
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16 GNU General Public License for more details.
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24377
diff changeset
20 <https://www.gnu.org/licenses/>.
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22 */
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
23
24269
f494b87d2a93 rename scope to symbol_scope
John W. Eaton <jwe@octave.org>
parents: 24263
diff changeset
24 #if ! defined (octave_symscope_h)
f494b87d2a93 rename scope to symbol_scope
John W. Eaton <jwe@octave.org>
parents: 24263
diff changeset
25 #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
26
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 #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
28
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29 #include <deque>
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30 #include <limits>
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 #include <list>
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 #include <map>
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
33 #include <memory>
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 #include <set>
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 #include <string>
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37 #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
38 #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
39 #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
40
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 class tree_argument_list;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 class octave_user_function;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44 #include "ov.h"
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45 #include "ovl.h"
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46 #include "symrec.h"
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48 namespace octave
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 {
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
50 class symbol_scope;
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
51
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
52 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
53 : 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
54 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55 public:
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57 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
58 table_const_iterator;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59 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
60 table_iterator;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
62 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
63 subfunctions_const_iterator;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64 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
65 subfunctions_iterator;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
67 symbol_scope_rep (const std::string& name = "")
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
68 : m_name (name), m_symbols (), m_subfunctions (), m_fcn (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
69 m_parent (), m_children (), m_is_nested (false),
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70 m_is_static (false), m_context (0)
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71 { }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73 // No copying!
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
75 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
76
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
77 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
78
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
79 ~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
80
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81 void insert_symbol_record (const symbol_record& sr)
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
82 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83 m_symbols[sr.name ()] = sr;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
85
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
86 bool is_nested (void) const { return m_is_nested; }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
87
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
88 void mark_nested (void) { m_is_nested = true; }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
89
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
90 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
91
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
92 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
93
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
94 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
95 {
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
96 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
97 }
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
98
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
99 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
100 {
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
101 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
102 = 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
103
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
104 for (const auto& nm_sr : m_symbols)
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
105 new_sid->insert_symbol_record (nm_sr.second.dup (new_sid));
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
106
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
107 new_sid->m_parent = m_parent;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
108
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
109 return new_sid;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
110 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
111
24362
3fc24b792a24 avoid including symtab.h, symscope.h, or symrec.h unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24361
diff changeset
112 void set_context (symbol_record::context_id context)
3fc24b792a24 avoid including symtab.h, symscope.h, or symrec.h unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24361
diff changeset
113 {
3fc24b792a24 avoid including symtab.h, symscope.h, or symrec.h unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24361
diff changeset
114 m_context = context;
3fc24b792a24 avoid including symtab.h, symscope.h, or symrec.h unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24361
diff changeset
115 }
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
116
24362
3fc24b792a24 avoid including symtab.h, symscope.h, or symrec.h unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24361
diff changeset
117 symbol_record::context_id current_context (void) const
3fc24b792a24 avoid including symtab.h, symscope.h, or symrec.h unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24361
diff changeset
118 {
3fc24b792a24 avoid including symtab.h, symscope.h, or symrec.h unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24361
diff changeset
119 return m_context;
3fc24b792a24 avoid including symtab.h, symscope.h, or symrec.h unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24361
diff changeset
120 }
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 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
123 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
124 table_iterator p = m_symbols.find (name);
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
125
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
126 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
127 return insert (name);
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
128 else
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
129 return p->second;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
130 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
131
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
132 void inherit_internal
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
133 (const std::shared_ptr<symbol_scope_rep>& donor_scope_rep)
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
134 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
135 for (auto& nm_sr : m_symbols)
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
136 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
137 symbol_record& sr = nm_sr.second;
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 if (! (sr.is_automatic () || sr.is_formal ()))
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
140 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
141 std::string nm = sr.name ();
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
142
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
143 if (nm != "__retval__")
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
144 {
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
145 octave_value val = donor_scope_rep->varval (nm);
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
146
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
147 if (val.is_defined ())
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
148 {
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24354
diff changeset
149 sr.assign (val, m_context);
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
150
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
151 sr.mark_inherited ();
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
152 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
153 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
154 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
155 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
156 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
157
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
158 void inherit (const std::shared_ptr<symbol_scope_rep>& donor_scope_rep)
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
159 {
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
160 std::shared_ptr<symbol_scope_rep> dsr = donor_scope_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
161
30e1d0bf7ade use weak_ptr for symbol_scope_rep and symbol_record_rep pointers (bug #53092)
John W. Eaton <jwe@octave.org>
parents: 24705
diff changeset
162 while (dsr)
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
163 {
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
164 inherit_internal (dsr);
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
165
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
166 if (dsr->is_nested ())
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
167 dsr = parent_scope_rep ();
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
168 else
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
169 break;
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 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
172
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
173 octave_value
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
174 find (const std::string& name, const octave_value_list& args,
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
175 bool skip_variables, bool local_funcs);
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&
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
178 insert (const std::string& name, bool force_add = false);
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
179
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
180 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
181 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
182 table_iterator p = m_symbols.find (old_name);
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
183
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
184 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
185 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
186 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
187
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
188 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
189
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
190 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
191
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
192 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
193 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
194 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
195
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
196 void assign (const std::string& name, const octave_value& value,
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
197 bool force_add)
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
198 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
199 table_iterator p = m_symbols.find (name);
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
200
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
201 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
202 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
203 symbol_record& sr = insert (name, force_add);
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
204
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24354
diff changeset
205 sr.assign (value, m_context);
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
206 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
207 else
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24354
diff changeset
208 p->second.assign (value, m_context);
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
209 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
210
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
211 void assign (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
212 const octave_value& value = octave_value ())
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
213 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
214 assign (name, value, false);
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
215 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
216
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
217 void force_assign (const std::string& name, const octave_value& value)
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
218 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
219 table_iterator p = m_symbols.find (name);
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
220
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
221 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
222 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
223 symbol_record& sr = insert (name, true);
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
224
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24354
diff changeset
225 sr.assign (value, m_context);
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
226 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
227 else
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24354
diff changeset
228 p->second.assign (value, m_context);
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
229 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
230
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
231 octave_value varval (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
232 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
233 table_const_iterator p = m_symbols.find (name);
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
234
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
235 return (p != m_symbols.end ()
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24354
diff changeset
236 ? p->second.varval (m_context) : octave_value ());
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
237 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
238
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
239 bool is_variable (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
240 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
241 bool retval = false;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
242
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
243 table_const_iterator p = m_symbols.find (name);
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
244
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
245 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
246 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
247 const 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
248
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24354
diff changeset
249 retval = sr.is_variable (m_context);
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
250 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
251
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
252 return retval;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
253 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
254
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
255 void push_context (void)
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
256 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
257 for (auto& nm_sr : m_symbols)
24348
64691264dd21 eliminate some uses of decl_scope in symbol_record class
John W. Eaton <jwe@octave.org>
parents: 24325
diff changeset
258 nm_sr.second.push_context ();
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
259 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
260
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
261 void pop_context (void)
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
262 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
263 table_iterator tbl_it = m_symbols.begin ();
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
264
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
265 while (tbl_it != m_symbols.end ())
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
266 {
24348
64691264dd21 eliminate some uses of decl_scope in symbol_record class
John W. Eaton <jwe@octave.org>
parents: 24325
diff changeset
267 if (tbl_it->second.pop_context () == 0)
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
268 m_symbols.erase (tbl_it++);
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
269 else
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
270 tbl_it++;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
271 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
272 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
273
24325
bc65aa8a5ff1 don't store persistent variables separately in scope object
John W. Eaton <jwe@octave.org>
parents: 24324
diff changeset
274 void refresh (void)
bc65aa8a5ff1 don't store persistent variables separately in scope object
John W. Eaton <jwe@octave.org>
parents: 24324
diff changeset
275 {
bc65aa8a5ff1 don't store persistent variables separately in scope object
John W. Eaton <jwe@octave.org>
parents: 24324
diff changeset
276 for (auto& nm_sr : m_symbols)
bc65aa8a5ff1 don't store persistent variables separately in scope object
John W. Eaton <jwe@octave.org>
parents: 24324
diff changeset
277 {
bc65aa8a5ff1 don't store persistent variables separately in scope object
John W. Eaton <jwe@octave.org>
parents: 24324
diff changeset
278 symbol_record& sr = nm_sr.second;
bc65aa8a5ff1 don't store persistent variables separately in scope object
John W. Eaton <jwe@octave.org>
parents: 24324
diff changeset
279
bc65aa8a5ff1 don't store persistent variables separately in scope object
John W. Eaton <jwe@octave.org>
parents: 24324
diff changeset
280 if (! sr.is_persistent ())
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24354
diff changeset
281 sr.clear (m_context);
24325
bc65aa8a5ff1 don't store persistent variables separately in scope object
John W. Eaton <jwe@octave.org>
parents: 24324
diff changeset
282 }
bc65aa8a5ff1 don't store persistent variables separately in scope object
John W. Eaton <jwe@octave.org>
parents: 24324
diff changeset
283 }
bc65aa8a5ff1 don't store persistent variables separately in scope object
John W. Eaton <jwe@octave.org>
parents: 24324
diff changeset
284
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
285 void clear_variables (void)
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
286 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
287 for (auto& nm_sr : m_symbols)
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24354
diff changeset
288 nm_sr.second.clear (m_context);
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
289 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
290
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
291 void clear_objects (void)
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
292 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
293 for (auto& nm_sr : m_symbols)
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
294 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
295 symbol_record& sr = nm_sr.second;
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24354
diff changeset
296 octave_value val = sr.varval (m_context);
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
297 if (val.isobject ())
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24354
diff changeset
298 nm_sr.second.clear (m_context);
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
299 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
300 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
301
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
302 void clear_variable (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
303 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
304 table_iterator p = m_symbols.find (name);
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
305
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
306 if (p != m_symbols.end ())
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24354
diff changeset
307 p->second.clear (m_context);
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
308 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
309
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
310 void clear_variable_pattern (const std::string& pat)
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
311 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
312 glob_match pattern (pat);
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
313
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
314 for (auto& nm_sr : m_symbols)
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
315 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
316 symbol_record& sr = nm_sr.second;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
317
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24354
diff changeset
318 if (sr.is_defined (m_context) || sr.is_global ())
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
319 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
320 if (pattern.match (sr.name ()))
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24354
diff changeset
321 sr.clear (m_context);
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
322 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
323 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
324 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
325
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
326 void clear_variable_regexp (const std::string& pat)
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
327 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
328 octave::regexp pattern (pat);
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
329
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
330 for (auto& nm_sr : m_symbols)
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
331 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
332 symbol_record& sr = nm_sr.second;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
333
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24354
diff changeset
334 if (sr.is_defined (m_context) || sr.is_global ())
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
335 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
336 if (pattern.is_match (sr.name ()))
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24354
diff changeset
337 sr.clear (m_context);
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
338 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
339 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
340 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
341
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
342 void mark_automatic (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
343 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
344 insert (name).mark_automatic ();
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
345 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
346
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
347 void mark_hidden (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
348 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
349 insert (name).mark_hidden ();
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
350 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
351
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
352 void mark_global (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
353 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
354 insert (name).mark_global ();
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
355 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
356
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
357 std::list<symbol_record>
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
358 all_variables (bool defined_only = true,
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
359 unsigned int exclude = symbol_record::hidden) const
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
360 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
361 std::list<symbol_record> retval;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
362
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
363 for (const auto& nm_sr : m_symbols)
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
364 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
365 const symbol_record& sr = nm_sr.second;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
366
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24354
diff changeset
367 if ((defined_only && ! sr.is_defined (m_context))
24272
dd810f9d26e7 use m_ prefix for symbol_record class data members
John W. Eaton <jwe@octave.org>
parents: 24269
diff changeset
368 || (sr.storage_class () & exclude))
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
369 continue;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
370
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
371 retval.push_back (sr);
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
372 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
373
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
374 return retval;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
375 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
376
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
377 std::list<symbol_record>
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
378 glob (const std::string& pattern, bool vars_only = false) const
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
379 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
380 std::list<symbol_record> retval;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
381
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
382 glob_match pat (pattern);
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
383
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
384 for (const auto& nm_sr : m_symbols)
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
385 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
386 if (pat.match (nm_sr.first))
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
387 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
388 const symbol_record& sr = nm_sr.second;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
389
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24354
diff changeset
390 if (vars_only && ! sr.is_variable (m_context))
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
391 continue;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
392
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
393 retval.push_back (sr);
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
394 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
395 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
396
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
397 return retval;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
398 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
399
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
400 std::list<symbol_record>
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
401 regexp (const std::string& pattern, bool vars_only = false) const
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
402 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
403 std::list<symbol_record> retval;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
404
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
405 octave::regexp pat (pattern);
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
406
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
407 for (const auto& nm_sr : m_symbols)
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
408 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
409 if (pat.is_match (nm_sr.first))
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
410 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
411 const symbol_record& sr = nm_sr.second;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
412
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24354
diff changeset
413 if (vars_only && ! sr.is_variable (m_context))
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
414 continue;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
415
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
416 retval.push_back (sr);
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
417 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
418 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
419
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
420 return retval;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
421 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
422
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
423 std::list<std::string> variable_names (void)
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
424 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
425 std::list<std::string> retval;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
426
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
427 for (const auto& nm_sr : m_symbols)
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
428 {
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24354
diff changeset
429 if (nm_sr.second.is_variable (m_context))
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
430 retval.push_back (nm_sr.first);
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
431 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
432
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
433 retval.sort ();
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
434
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
435 return retval;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
436 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
437
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
438 bool is_local_variable (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
439 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
440 table_const_iterator p = m_symbols.find (name);
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
441
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
442 return (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
443 && ! p->second.is_global ()
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24354
diff changeset
444 && p->second.is_defined (m_context));
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
445 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
446
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
447 bool is_global (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
448 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
449 table_const_iterator p = m_symbols.find (name);
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
450
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
451 return p != m_symbols.end () && p->second.is_global ();
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
452 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
453
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
454 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
455 const octave_value& fval)
8b346a19108e mark objects as nested or subfunctions when parsing
John W. Eaton <jwe@octave.org>
parents: 24645
diff changeset
456 {
8b346a19108e mark objects as nested or subfunctions when parsing
John W. Eaton <jwe@octave.org>
parents: 24645
diff changeset
457 m_subfunctions[name] = fval;
8b346a19108e mark objects as nested or subfunctions when parsing
John W. Eaton <jwe@octave.org>
parents: 24645
diff changeset
458 }
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
459
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
460 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
461 const octave_value& fval,
8b346a19108e mark objects as nested or subfunctions when parsing
John W. Eaton <jwe@octave.org>
parents: 24645
diff changeset
462 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
463 {
24705
8b346a19108e mark objects as nested or subfunctions when parsing
John W. Eaton <jwe@octave.org>
parents: 24645
diff changeset
464 m_subfunctions[name] = fval;
8b346a19108e mark objects as nested or subfunctions when parsing
John W. Eaton <jwe@octave.org>
parents: 24645
diff changeset
465
8b346a19108e mark objects as nested or subfunctions when parsing
John W. Eaton <jwe@octave.org>
parents: 24645
diff changeset
466 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
467 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
468
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
469 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
470
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
471 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
472 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
473 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
474 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
475 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
476
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
477 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
478 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
479 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
480 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
481 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
482
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
483 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
484 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
485 return m_subfunctions;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
486 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
487
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
488 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
489 {
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
490 m_subfunctions.clear ();
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
491 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
492
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
493 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
494
24285
d22d2936f580 store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents: 24272
diff changeset
495 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
496 {
d22d2936f580 store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents: 24272
diff changeset
497 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
498 }
d22d2936f580 store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents: 24272
diff changeset
499
d22d2936f580 store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents: 24272
diff changeset
500 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
501 {
d22d2936f580 store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents: 24272
diff changeset
502 m_subfunction_names = names;
d22d2936f580 store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents: 24272
diff changeset
503 }
d22d2936f580 store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents: 24272
diff changeset
504
d22d2936f580 store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents: 24272
diff changeset
505 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
506 {
d22d2936f580 store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents: 24272
diff changeset
507 return m_subfunction_names;
d22d2936f580 store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents: 24272
diff changeset
508 }
d22d2936f580 store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents: 24272
diff changeset
509
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
510 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
511
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
512 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
513
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
514 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
515
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
516 octave_user_function *function (void) { return m_fcn; }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
517
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
518 void set_function (octave_user_function *fcn) { m_fcn = fcn; }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
519
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
520 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
521
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
522 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
523
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
524 bool look_nonlocal (const std::string& name, symbol_record& result);
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
525
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
526 void bind_script_symbols (const std::shared_ptr<symbol_scope_rep>& curr_scope);
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
527
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
528 void unbind_script_symbols (void);
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
529
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
530 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
531
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
532 private:
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
533
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
534 // Name for this scope (usually the corresponding filename of the
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
535 // function corresponding to the scope).
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
536 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
537
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
538 // Map from symbol names to symbol info.
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
539 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
540
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
541 // Map from symbol names to subfunctions.
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
542 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
543
24285
d22d2936f580 store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents: 24272
diff changeset
544 // The list of subfunctions (if any) in the order they appear in
d22d2936f580 store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents: 24272
diff changeset
545 // the function file.
d22d2936f580 store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents: 24272
diff changeset
546 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
547
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
548 // The associated user code (may be null).
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
549 octave_user_function *m_fcn;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
550
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
551 // Parent of nested function (may be null).
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
552 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
553
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
554 // Child nested functions.
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
555 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
556
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
557 // If true, then this scope belongs to a nested function.
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
558 bool m_is_nested;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
559
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
560 // If true then no variables can be added.
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
561 bool m_is_static;
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
562
24362
3fc24b792a24 avoid including symtab.h, symscope.h, or symrec.h unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24361
diff changeset
563 symbol_record::context_id m_context;
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
564 };
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
565
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
566 class symbol_scope
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
567 {
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
568 public:
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
569
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
570 // 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
571 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
572 : 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
573 { }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
574
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
575 // 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
576 // 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
577 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
578 : 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
579 { }
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
580
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
581 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
582
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
583 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
584
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
585 ~symbol_scope (void) = default;
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
586
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
587 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
588
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
589 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
590
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
591 void insert_symbol_record (const symbol_record& sr)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
592 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
593 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
594 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
595 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
596
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
597 bool is_nested (void) const
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
598 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
599 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
600 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
601
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
602 void mark_nested (void)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
603 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
604 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
605 m_rep->mark_nested ();
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
606 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
607
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
608 bool is_static (void) const
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
609 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
610 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
611 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
612
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
613 void mark_static (void)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
614 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
615 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
616 m_rep->mark_static ();
24361
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
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
619 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
620 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
621 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
622 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
623
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
624 symbol_scope dup (void) const
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
625 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
626 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
627 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
628
24362
3fc24b792a24 avoid including symtab.h, symscope.h, or symrec.h unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24361
diff changeset
629 void set_context (symbol_record::context_id context)
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
630 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
631 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
632 m_rep->set_context (context);
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
633 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
634
24362
3fc24b792a24 avoid including symtab.h, symscope.h, or symrec.h unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24361
diff changeset
635 symbol_record::context_id current_context (void) const
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
636 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
637 return m_rep ? m_rep->current_context () : 0;
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
638 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
639
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
640 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
641 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
642 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
643 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
644
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
645 void inherit (const symbol_scope& donor_scope)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
646 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
647 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
648 m_rep->inherit (donor_scope.get_rep ());
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
649 }
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 octave_value
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
652 find (const std::string& name, const octave_value_list& args,
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
653 bool skip_variables, bool local_funcs)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
654 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
655 return (m_rep
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
656 ? m_rep->find (name, args, skip_variables, local_funcs)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
657 : octave_value ());
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
658 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
659
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
660 symbol_record&
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
661 insert (const std::string& name, bool force_add = false)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
662 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
663 static symbol_record dummy_symrec;
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
664 return m_rep ? m_rep->insert (name, force_add) : dummy_symrec;
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
665 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
666
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
667 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
668 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
669 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
670 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
671 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
672
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
673 void assign (const std::string& name, const octave_value& value,
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
674 bool force_add)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
675 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
676 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
677 m_rep->assign (name, value, force_add);
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
678 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
679
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
680 void assign (const std::string& name,
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
681 const octave_value& value = octave_value ())
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
682 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
683 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
684 m_rep->assign (name, value);
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
685 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
686
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
687 void force_assign (const std::string& name, const octave_value& value)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
688 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
689 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
690 m_rep->force_assign (name, value);
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
691 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
692
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
693 octave_value varval (const std::string& name) const
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
694 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
695 return m_rep ? m_rep->varval (name) : octave_value ();
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
696 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
697
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
698 bool is_variable (const std::string& name) const
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
699 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
700 return m_rep ? m_rep->is_variable (name) : false;
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
701 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
702
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
703 void push_context (void)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
704 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
705 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
706 m_rep->push_context ();
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
707 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
708
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
709 void pop_context (void)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
710 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
711 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
712 m_rep->pop_context ();
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
713 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
714
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
715 void refresh (void)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
716 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
717 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
718 m_rep->refresh ();
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
719 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
720
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
721 void clear_variables (void)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
722 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
723 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
724 m_rep->clear_variables ();
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
725 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
726
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
727 void clear_objects (void)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
728 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
729 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
730 m_rep->clear_objects ();
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
731 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
732
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
733 void clear_variable (const std::string& name)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
734 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
735 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
736 m_rep->clear_variable (name);
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
737 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
738
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
739 void clear_variable_pattern (const std::string& pat)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
740 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
741 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
742 m_rep->clear_variable_pattern (pat);
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
743 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
744
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
745 void clear_variable_regexp (const std::string& pat)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
746 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
747 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
748 m_rep->clear_variable_regexp (pat);
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
749 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
750
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
751 void mark_automatic (const std::string& name)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
752 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
753 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
754 m_rep->mark_automatic (name);
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
755 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
756
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
757 void mark_hidden (const std::string& name)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
758 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
759 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
760 m_rep->mark_hidden (name);
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
761 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
762
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
763 void mark_global (const std::string& name)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
764 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
765 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
766 m_rep->mark_global (name);
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
767 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
768
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
769 std::list<symbol_record>
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
770 all_variables (bool defined_only = true,
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
771 unsigned int exclude = symbol_record::hidden) const
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
772 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
773 return (m_rep
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
774 ? m_rep->all_variables (defined_only, exclude)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
775 : std::list<symbol_record> ());
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
776 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
777
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
778 std::list<symbol_record>
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
779 glob (const std::string& pattern, bool vars_only = false) const
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
780 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
781 return (m_rep
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
782 ? m_rep->glob (pattern, vars_only)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
783 : std::list<symbol_record> ());
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
784 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
785
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
786 std::list<symbol_record>
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
787 regexp (const std::string& pattern, bool vars_only = false) const
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
788 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
789 return (m_rep
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
790 ? m_rep->regexp (pattern, vars_only)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
791 : std::list<symbol_record> ());
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
792 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
793
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
794 std::list<std::string> variable_names (void)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
795 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
796 return m_rep ? m_rep->variable_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
797 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
798
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
799 bool is_local_variable (const std::string& name) const
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
800 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
801 return m_rep ? m_rep->is_local_variable (name) : false;
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
802 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
803
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
804 bool is_global (const std::string& name) const
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
805 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
806 return m_rep ? m_rep->is_global (name) : false;
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
807 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
808
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
809 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
810 const octave_value& fval)
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
811 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
812 if (m_rep)
24705
8b346a19108e mark objects as nested or subfunctions when parsing
John W. Eaton <jwe@octave.org>
parents: 24645
diff changeset
813 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
814 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
815
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
816 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
817 const octave_value& fval,
8b346a19108e mark objects as nested or subfunctions when parsing
John W. Eaton <jwe@octave.org>
parents: 24645
diff changeset
818 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
819 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
820 if (m_rep)
24705
8b346a19108e mark objects as nested or subfunctions when parsing
John W. Eaton <jwe@octave.org>
parents: 24645
diff changeset
821 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
822 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
823
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
824 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
825 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
826 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
827 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
828
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
829 void lock_subfunctions (void)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
830 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
831 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
832 m_rep->lock_subfunctions ();
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
833 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
834
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
835 void unlock_subfunctions (void)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
836 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
837 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
838 m_rep->unlock_subfunctions ();
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
839 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
840
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
841 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
842 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
843 return (m_rep
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
844 ? m_rep->subfunctions ()
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
845 : 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
846 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
847
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
848 void erase_subfunctions (void)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
849 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
850 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
851 m_rep->erase_subfunctions ();
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
852 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
853
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
854 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
855 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
856 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
857 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
858 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
859
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
860 bool has_subfunctions (void) const
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
861 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
862 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
863 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
864
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
865 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
866 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
867 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
868 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
869 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
870
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
871 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
872 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
873 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
874 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
875
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
876 octave_value dump (void) const
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
877 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
878 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
879 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
880
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
881 std::string name (void) const
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
882 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
883 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
884 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
885
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
886 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
887 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
888 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
889 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
890 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
891
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
892 octave_user_function * function (void)
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
893 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
894 return m_rep ? m_rep->function () : nullptr;
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
895 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
896
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
897 void set_function (octave_user_function *fcn)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
898 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
899 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
900 m_rep->set_function (fcn);
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
901 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
902
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
903 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
904 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
905 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
906 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
907 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
908
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
909 void update_nest (void)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
910 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
911 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
912 m_rep->update_nest ();
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
913 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
914
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
915 bool look_nonlocal (const std::string& name, symbol_record& result)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
916 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
917 return m_rep ? m_rep->look_nonlocal (name, result) : false;
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
918 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
919
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
920 void bind_script_symbols (const symbol_scope& curr_scope)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
921 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
922 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
923 m_rep->bind_script_symbols (curr_scope.get_rep ());
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
924 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
925
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
926 void unbind_script_symbols (void)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
927 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
928 if (m_rep)
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
929 m_rep->unbind_script_symbols ();
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
930 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
931
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
932 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
933 {
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
934 return m_rep;
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
935 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
936
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
937 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
938 {
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
939 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
940 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
941
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
942 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
943 {
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
944 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
945 }
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
946
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
947 private:
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
948
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
949 std::shared_ptr<symbol_scope_rep> m_rep;
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
950
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
951 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
952 {
24377
ea3458c1d884 improve handling of invalid symbol_scope objects (bug #52607)
John W. Eaton <jwe@octave.org>
parents: 24362
diff changeset
953 return m_rep ? m_rep->dump_symbols_map () : octave_value ();
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
954 }
24263
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
955 };
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
956 }
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
957
3b302b2890d7 disentangle symbol_record, scope, and fcn_info from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
958 #endif