26 #if ! defined (octave_symscope_h)
27 #define octave_symscope_h 1
29 #include "octave-config.h"
54 :
public std::enable_shared_from_this<symbol_scope_rep>
58 typedef std::map<std::string, symbol_record>::const_iterator
60 typedef std::map<std::string, symbol_record>::iterator
63 typedef std::map<std::string, octave_value>::const_iterator
65 typedef std::map<std::string, octave_value>::iterator
69 : m_name (
name), m_symbols (), m_subfunctions (),
70 m_persistent_values (), m_code (nullptr), m_fcn_name (),
71 m_fcn_file_name (), m_dir_name (), m_parent (),
72 m_primary_parent (), m_children (), m_nesting_depth (0),
73 m_is_static (false), m_is_primary_fcn_scope (false)
84 std::size_t
num_symbols ()
const {
return m_symbols.size (); }
92 bool is_nested ()
const {
return m_nesting_depth > 0; }
98 bool is_parent ()
const {
return ! m_children.empty (); }
106 return m_parent.lock ();
111 return m_primary_parent.lock ();
114 std::shared_ptr<symbol_scope_rep>
dup ()
const
116 std::shared_ptr<symbol_scope_rep> new_sid
119 for (
const auto& nm_sr : m_symbols)
120 new_sid->m_symbols[nm_sr.first] = nm_sr.second.dup ();
122 new_sid->m_subfunctions = m_subfunctions;
123 new_sid->m_persistent_values = m_persistent_values;
124 new_sid->m_subfunction_names = m_subfunction_names;
125 new_sid->m_code = m_code;
126 new_sid->m_fcn_name = m_fcn_name;
127 new_sid->m_fcn_file_name = m_fcn_file_name;
128 new_sid->m_dir_name = m_dir_name;
129 new_sid->m_parent = m_parent;
130 new_sid->m_primary_parent = m_primary_parent;
131 new_sid->m_children = m_children;
132 new_sid->m_nesting_depth = m_nesting_depth;
133 new_sid->m_is_static = m_is_static;
134 new_sid->m_is_primary_fcn_scope = m_is_primary_fcn_scope;
141 return m_persistent_values[data_offset];
146 auto p = m_persistent_values.find (data_offset);
148 return p == m_persistent_values.end () ?
octave_value () : p->second;
153 auto p = m_symbols.find (
name);
155 if (p == m_symbols.end ())
163 auto p = m_symbols.find (
name);
170 void rename (
const std::string& old_name,
const std::string& new_name)
172 auto p = m_symbols.find (old_name);
174 if (p != m_symbols.end ())
182 m_symbols[new_name] = sr;
189 m_subfunctions[
name] = fval;
196 m_subfunctions[
name] = fval;
198 m_children.push_back (fcn_scope);
205 for (
auto& nm_sf : m_subfunctions)
206 nm_sf.second.lock ();
211 for (
auto& nm_sf : m_subfunctions)
212 nm_sf.second.unlock ();
218 return m_subfunctions;
223 m_subfunctions.clear ();
230 return ! m_subfunction_names.empty ();
235 m_subfunction_names = names;
240 return m_subfunction_names;
247 std::string
name ()
const {
return m_name; }
251 std::string
fcn_name ()
const {
return m_fcn_name; }
261 void set_parent (
const std::shared_ptr<symbol_scope_rep>& parent);
267 m_fcn_file_name =
name;
274 std::string
dir_name ()
const {
return m_dir_name; }
280 bool is_relative (
const std::shared_ptr<symbol_scope_rep>& scope)
const;
294 const std::map<std::string, symbol_record>&
symbols ()
const
299 std::map<std::string, symbol_record>&
symbols ()
315 std::map<std::string, symbol_record> m_symbols;
319 std::map<std::string, octave_value> m_subfunctions;
322 std::map<std::size_t, octave_value> m_persistent_values;
327 std::list<std::string> m_subfunction_names;
335 std::string m_fcn_name;
339 std::string m_fcn_file_name;
343 std::string m_dir_name;
347 std::weak_ptr<symbol_scope_rep> m_parent;
352 std::weak_ptr<symbol_scope_rep> m_primary_parent;
356 std::vector<symbol_scope> m_children;
360 std::size_t m_nesting_depth;
367 bool m_is_primary_fcn_scope;
402 return symbol_scope (std::shared_ptr<symbol_scope_rep> (
nullptr));
412 explicit operator bool ()
const {
return is_valid (); }
416 return m_rep ? m_rep->num_symbols () : 0;
427 m_rep->insert_symbol_record (sr);
432 return m_rep ? m_rep->is_nested () :
false;
437 return m_rep ? m_rep->is_parent () :
false;
443 m_rep->set_nesting_depth (depth);
448 return m_rep ? m_rep->nesting_depth () : 0;
453 return m_rep ? m_rep->is_static () :
false;
459 m_rep->mark_static ();
464 return m_rep ? m_rep->parent_scope_rep () :
nullptr;
469 return m_rep ? m_rep->primary_parent_scope_rep () :
nullptr;
481 return m_rep ? m_rep->persistent_varref (data_offset) : dummy_value;
486 return m_rep ? m_rep->persistent_varval (data_offset) :
octave_value ();
505 void rename (
const std::string& old_name,
const std::string& new_name)
508 m_rep->rename (old_name, new_name);
515 m_rep->install_subfunction (
name, fval);
523 m_rep->install_nestfunction (
name, fval, fcn_scope);
534 m_rep->lock_subfunctions ();
540 m_rep->unlock_subfunctions ();
546 ? m_rep->subfunctions ()
547 : std::map<std::string, octave_value> ());
553 m_rep->erase_subfunctions ();
559 m_rep->mark_subfunctions_in_scope_as_private (class_name);
564 return m_rep ? m_rep->has_subfunctions () :
false;
570 m_rep->stash_subfunction_names (names);
575 return m_rep ? m_rep->subfunction_names () : std::list<std::string> ();
588 return m_rep ? m_rep->name () :
"";
594 m_rep->cache_name (
name);
599 return m_rep ? m_rep->fcn_name () :
"";
605 m_rep->cache_fcn_name (
name);
610 return m_rep ? m_rep->parent_fcn_names () : std::list<std::string> ();
615 return m_rep ? m_rep->user_code () :
nullptr;
621 m_rep->set_user_code (code);
627 m_rep->set_parent (p.
get_rep ());
633 m_rep->set_primary_parent (p.
get_rep ());
639 m_rep->cache_fcn_file_name (
name);
645 m_rep->cache_dir_name (
name);
650 return m_rep ? m_rep->fcn_file_name () :
"";
655 return m_rep ? m_rep->dir_name () :
"";
661 m_rep->mark_primary_fcn_scope ();
666 return m_rep ? m_rep->is_primary_fcn_scope () :
false;
671 return m_rep ? m_rep->is_relative (scope.
get_rep ()) :
false;
677 m_rep->mark_as_variable (nm);
683 m_rep->mark_as_variables (lst);
688 return m_rep ? m_rep->is_variable (nm) :
false;
694 m_rep->update_nest ();
700 return m_rep ? m_rep->look_nonlocal (
name, offset, result) :
false;
703 std::shared_ptr<symbol_scope_rep>
get_rep ()
const
710 return a.m_rep == b.m_rep;
715 return a.m_rep != b.m_rep;
718 const std::map<std::string, symbol_record>&
symbols ()
const
720 static const std::map<std::string, symbol_record> empty_map;
722 return m_rep ? m_rep->symbols () : empty_map;
725 std::map<std::string, symbol_record>&
symbols ()
727 static std::map<std::string, symbol_record> empty_map;
729 return m_rep ? m_rep->symbols () : empty_map;
734 static const std::list<symbol_record> empty_list;
736 return m_rep ? m_rep->symbol_list () : empty_list;
741 std::shared_ptr<symbol_scope_rep> m_rep;
744 OCTAVE_END_NAMESPACE(
octave)
void rename(const std::string &new_name)
std::size_t nesting_depth() const
symbol_record insert_local(const std::string &name)
void erase_subfunctions()
void mark_subfunctions_in_scope_as_private(const std::string &class_name)
std::shared_ptr< symbol_scope_rep > parent_scope_rep() const
void mark_primary_fcn_scope()
octave_user_code * user_code() const
void rename(const std::string &old_name, const std::string &new_name)
octave_value dump_symbols_map() const
std::map< std::string, octave_value >::iterator subfunctions_iterator
std::string fcn_name() const
void cache_fcn_file_name(const std::string &name)
~symbol_scope_rep()=default
void cache_dir_name(const std::string &name)
bool is_primary_fcn_scope() const
const std::map< std::string, symbol_record > & symbols() const
bool is_relative(const std::shared_ptr< symbol_scope_rep > &scope) const
std::map< std::string, symbol_record > & symbols()
std::shared_ptr< symbol_scope_rep > dup() const
void unlock_subfunctions()
void set_nesting_depth(std::size_t depth)
std::map< std::string, octave_value > subfunctions() const
void cache_fcn_name(const std::string &name)
void set_primary_parent(const std::shared_ptr< symbol_scope_rep > &parent)
std::map< std::string, symbol_record >::iterator table_iterator
symbol_record find_symbol(const std::string &name)
std::list< std::string > parent_fcn_names() const
void mark_as_variables(const std::list< std::string > &lst)
void install_nestfunction(const std::string &name, const octave_value &fval, const symbol_scope &fcn_scope)
bool is_variable(const std::string &nm) const
symbol_scope_rep(const std::string &name="", bool add_ans=true)
std::map< std::string, octave_value >::const_iterator subfunctions_const_iterator
std::size_t num_symbols() const
void cache_name(const std::string &name)
void stash_subfunction_names(const std::list< std::string > &names)
symbol_record insert(const std::string &name)
std::shared_ptr< symbol_scope_rep > primary_parent_scope_rep() const
octave_value find_subfunction(const std::string &name) const
octave_value & persistent_varref(std::size_t data_offset)
void set_user_code(octave_user_code *code)
octave_value dump() const
void set_parent(const std::shared_ptr< symbol_scope_rep > &parent)
void mark_as_variable(const std::string &nm)
bool has_subfunctions() const
std::list< std::string > subfunction_names() const
symbol_record lookup_symbol(const std::string &name) const
std::list< symbol_record > symbol_list() const
std::map< std::string, symbol_record >::const_iterator table_const_iterator
octave_value persistent_varval(std::size_t data_offset) const
void insert_symbol_record(symbol_record &sr)
std::string fcn_file_name() const
std::list< octave_value > localfunctions() const
bool look_nonlocal(const std::string &name, std::size_t offset, symbol_record &result)
std::string dir_name() const
void install_subfunction(const std::string &name, const octave_value &fval)
octave_user_code * user_code() const
bool is_primary_fcn_scope() const
std::map< std::string, symbol_record > & symbols()
friend bool operator==(const symbol_scope &a, const symbol_scope &b)
friend bool operator!=(const symbol_scope &a, const symbol_scope &b)
symbol_record insert_local(const std::string &name)
std::shared_ptr< symbol_scope_rep > primary_parent_scope() const
std::string fcn_file_name() const
void set_user_code(octave_user_code *code)
void insert_symbol_record(symbol_record &sr)
void stash_subfunction_names(const std::list< std::string > &names)
symbol_scope(const std::shared_ptr< symbol_scope_rep > new_rep)
std::list< octave_value > localfunctions() const
void cache_fcn_name(const std::string &name)
void mark_as_variable(const std::string &nm)
symbol_scope(const std::string &name)
octave_value find_subfunction(const std::string &name) const
bool is_variable(const std::string &nm) const
static symbol_scope anonymous()
std::map< std::string, octave_value > subfunctions() const
symbol_record find_symbol(const std::string &name)
std::size_t num_symbols() const
void mark_primary_fcn_scope()
std::list< symbol_record > symbol_list() const
static symbol_scope invalid()
std::string dir_name() const
symbol_scope(const symbol_scope &)=default
std::shared_ptr< symbol_scope_rep > parent_scope() const
void set_parent(const symbol_scope &p)
std::shared_ptr< symbol_scope_rep > get_rep() const
void mark_as_variables(const std::list< std::string > &lst)
void install_subfunction(const std::string &name, const octave_value &fval)
bool has_subfunctions() const
octave_value dump() const
symbol_scope & operator=(const symbol_scope &)=default
octave_value persistent_varval(std::size_t data_offset) const
symbol_record insert(const std::string &name)
void cache_fcn_file_name(const std::string &name)
void unlock_subfunctions()
std::list< std::string > parent_fcn_names() const
void erase_subfunctions()
octave_value & persistent_varref(std::size_t data_offset)
const std::map< std::string, symbol_record > & symbols() const
void set_nesting_depth(std::size_t depth)
void rename(const std::string &old_name, const std::string &new_name)
void set_primary_parent(const symbol_scope &p)
bool is_relative(const symbol_scope &scope) const
std::list< std::string > subfunction_names() const
symbol_record lookup_symbol(const std::string &name) const
void mark_subfunctions_in_scope_as_private(const std::string &class_name)
void cache_name(const std::string &name)
void install_nestfunction(const std::string &name, const octave_value &fval, const symbol_scope &fcn_scope)
void cache_dir_name(const std::string &name)
std::string fcn_name() const
bool look_nonlocal(const std::string &name, std::size_t offset, symbol_record &result)
std::size_t nesting_depth() const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))