26 #if ! defined (octave_symscope_h)
27 #define octave_symscope_h 1
29 #include "octave-config.h"
42 class tree_argument_list;
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
118 std::shared_ptr<symbol_scope_rep>
dup (
void)
const
120 std::shared_ptr<symbol_scope_rep> new_sid
124 new_sid->m_symbols[nm_sr.first] = nm_sr.second.dup ();
175 void rename (
const std::string& old_name,
const std::string& new_name)
211 nm_sf.second.lock ();
217 nm_sf.second.unlock ();
274 void set_parent (
const std::shared_ptr<symbol_scope_rep>& parent);
293 bool is_relative (
const std::shared_ptr<symbol_scope_rep>& scope)
const;
302 const std::map<std::string, symbol_record>&
symbols (
void)
const
307 std::map<std::string, symbol_record>&
symbols (
void)
393 symbol_scope (
const std::shared_ptr<symbol_scope_rep> new_rep =
nullptr)
405 explicit operator bool ()
const {
return bool (
m_rep); }
420 m_rep->insert_symbol_record (sr);
436 m_rep->set_nesting_depth (depth);
452 m_rep->mark_static ();
457 return m_rep ?
m_rep->parent_scope_rep () :
nullptr;
462 return m_rep ?
m_rep->primary_parent_scope_rep () :
nullptr;
474 return m_rep ?
m_rep->persistent_varref (data_offset) : dummy_value;
498 void rename (
const std::string& old_name,
const std::string& new_name)
501 m_rep->rename (old_name, new_name);
516 m_rep->install_nestfunction (
name, fval, fcn_scope);
527 m_rep->lock_subfunctions ();
533 m_rep->unlock_subfunctions ();
539 ?
m_rep->subfunctions ()
540 : std::map<std::string, octave_value> ());
546 m_rep->erase_subfunctions ();
552 m_rep->mark_subfunctions_in_scope_as_private (class_name);
557 return m_rep ?
m_rep->has_subfunctions () :
false;
563 m_rep->stash_subfunction_names (names);
568 return m_rep ?
m_rep->subfunction_names () : std::list<std::string> ();
603 return m_rep ?
m_rep->parent_fcn_names () : std::list<std::string> ();
609 m_rep->cache_parent_fcn_names (names);
620 m_rep->set_user_code (code);
660 m_rep->mark_primary_fcn_scope ();
665 return m_rep ?
m_rep->is_primary_fcn_scope () :
false;
676 m_rep->update_nest ();
682 return m_rep ?
m_rep->look_nonlocal (
name, offset, result) :
false;
685 std::shared_ptr<symbol_scope_rep>
get_rep (
void)
const
700 const std::map<std::string, symbol_record>&
symbols (
void)
const
702 static const std::map<std::string, symbol_record> empty_map;
707 std::map<std::string, symbol_record>&
symbols (
void)
709 static std::map<std::string, symbol_record> empty_map;
716 static const std::list<symbol_record> empty_list;
718 return m_rep ?
m_rep->symbol_list () : empty_list;
723 std::shared_ptr<symbol_scope_rep>
m_rep;
void rename(const std::string &new_name)
std::weak_ptr< symbol_scope_rep > m_primary_parent
Primary (top) parent of nested function (may be null).
std::string m_name
Name for this scope (usually the corresponding filename of the function corresponding to the scope).
void set_nesting_depth(size_t depth)
void unlock_subfunctions(void)
std::vector< symbol_scope > m_children
Child nested functions.
std::shared_ptr< symbol_scope_rep > parent_scope_rep(void) const
std::string name(void) const
std::map< std::string, symbol_record >::iterator table_iterator
bool has_subfunctions(void) const
std::list< std::string > m_parent_fcn_names
List Simple names of the parent functions corresponding to this scope.
void stash_subfunction_names(const std::list< std::string > &names)
std::string m_dir_name
The directory associated with m_code.
std::shared_ptr< symbol_scope_rep > dup(void) const
void install_nestfunction(const std::string &name, const octave_value &fval, const symbol_scope &fcn_scope)
std::string m_fcn_file_name
The file name associated with m_code.
std::map< std::string, octave_value >::const_iterator subfunctions_const_iterator
void cache_parent_fcn_names(const std::list< std::string > &names)
bool is_primary_fcn_scope(void) const
std::map< std::string, octave_value > m_subfunctions
Map from symbol names to subfunctions.
bool is_relative(const std::shared_ptr< symbol_scope_rep > &scope) const
void cache_fcn_name(const std::string &name)
octave_value dump(void) const
size_t m_nesting_depth
If true, then this scope belongs to a nested function.
void set_parent(const std::shared_ptr< symbol_scope_rep > &parent)
std::map< std::string, symbol_record > m_symbols
Map from symbol names to symbol info.
void erase_subfunctions(void)
symbol_record insert_local(const std::string &name)
octave_value & persistent_varref(size_t data_offset)
std::map< std::string, symbol_record >::const_iterator table_const_iterator
std::string fcn_file_name(void) const
void mark_subfunctions_in_scope_as_private(const std::string &class_name)
void mark_primary_fcn_scope(void)
std::string m_fcn_name
Simple name of the function corresponding to this scope.
size_t nesting_depth(void) const
void lock_subfunctions(void)
bool look_nonlocal(const std::string &name, size_t offset, symbol_record &result)
octave_value dump_symbols_map(void) const
size_t num_symbols(void) const
std::list< std::string > m_subfunction_names
The list of subfunctions (if any) in the order they appear in the function file.
void rename(const std::string &old_name, const std::string &new_name)
symbol_scope_rep(const symbol_scope &)=delete
symbol_scope_rep(const std::string &name="")
bool is_parent(void) const
~symbol_scope_rep(void)=default
symbol_record insert(const std::string &name)
octave_value find_subfunction(const std::string &name) const
std::shared_ptr< symbol_scope_rep > primary_parent_scope_rep(void) const
symbol_scope_rep & operator=(const symbol_scope &)=delete
std::list< octave_value > localfunctions(void) const
std::list< std::string > subfunction_names(void) const
void cache_fcn_file_name(const std::string &name)
bool m_is_static
If true then no variables can be added.
symbol_record lookup_symbol(const std::string &name) const
bool is_static(void) const
std::weak_ptr< symbol_scope_rep > m_parent
Parent of nested function (may be null).
std::map< size_t, octave_value > m_persistent_values
Map from data offset to persistent values in this scope.
std::string dir_name(void) const
bool is_nested(void) const
octave_user_code * user_code(void) const
std::map< std::string, octave_value > subfunctions(void) const
symbol_record find_symbol(const std::string &name)
bool m_is_primary_fcn_scope
If true, this is the scope of a primary function.
std::map< std::string, octave_value >::iterator subfunctions_iterator
void set_primary_parent(const std::shared_ptr< symbol_scope_rep > &parent)
const std::map< std::string, symbol_record > & symbols(void) const
void insert_symbol_record(symbol_record &sr)
std::string fcn_name(void) const
void install_subfunction(const std::string &name, const octave_value &fval)
std::list< std::string > parent_fcn_names(void) const
octave_value persistent_varval(size_t data_offset) const
void cache_name(const std::string &name)
octave_user_code * m_code
The associated user code (may be null).
void cache_dir_name(const std::string &name)
std::list< symbol_record > symbol_list(void) const
std::map< std::string, symbol_record > & symbols(void)
void set_user_code(octave_user_code *code)
symbol_scope & operator=(const symbol_scope &)=default
friend bool operator==(const symbol_scope &a, const symbol_scope &b)
std::string name(void) const
friend bool operator!=(const symbol_scope &a, const symbol_scope &b)
void install_subfunction(const std::string &name, const octave_value &fval)
void set_primary_parent(const symbol_scope &p)
void mark_primary_fcn_scope(void)
octave_value & persistent_varref(size_t data_offset)
symbol_scope dup(void) const
std::shared_ptr< symbol_scope_rep > m_rep
size_t nesting_depth(void) const
void install_nestfunction(const std::string &name, const octave_value &fval, const symbol_scope &fcn_scope)
void cache_parent_fcn_names(const std::list< std::string > &names)
std::shared_ptr< symbol_scope_rep > parent_scope(void) const
octave_user_code * user_code(void) const
std::map< std::string, octave_value > subfunctions(void) const
symbol_record lookup_symbol(const std::string &name) const
std::string fcn_file_name(void) const
void set_user_code(octave_user_code *code)
octave_value find_subfunction(const std::string &name) const
symbol_record insert_local(const std::string &name)
std::list< symbol_record > symbol_list(void) const
std::list< std::string > subfunction_names(void) const
void erase_subfunctions(void)
void unlock_subfunctions(void)
~symbol_scope(void)=default
bool is_static(void) const
symbol_record find_symbol(const std::string &name)
symbol_scope(const std::string &name)
void set_parent(const symbol_scope &p)
void mark_subfunctions_in_scope_as_private(const std::string &class_name)
void set_nesting_depth(size_t depth)
bool look_nonlocal(const std::string &name, size_t offset, symbol_record &result)
std::list< std::string > parent_fcn_names(void) const
void cache_dir_name(const std::string &name)
std::string fcn_name(void) const
bool is_valid(void) const
symbol_scope(const std::shared_ptr< symbol_scope_rep > new_rep=nullptr)
symbol_record insert(const std::string &name)
size_t num_symbols(void) const
octave_value persistent_varval(size_t data_offset) const
void stash_subfunction_names(const std::list< std::string > &names)
void lock_subfunctions(void)
std::map< std::string, symbol_record > & symbols(void)
bool is_primary_fcn_scope(void) const
bool is_relative(const symbol_scope &scope) const
void cache_fcn_name(const std::string &name)
std::shared_ptr< symbol_scope_rep > primary_parent_scope(void) const
const std::map< std::string, symbol_record > & symbols(void) const
bool is_nested(void) const
void rename(const std::string &old_name, const std::string &new_name)
std::list< octave_value > localfunctions(void) const
void insert_symbol_record(symbol_record &sr)
void cache_fcn_file_name(const std::string &name)
void cache_name(const std::string &name)
symbol_scope(const symbol_scope &)=default
std::shared_ptr< symbol_scope_rep > get_rep(void) const
bool is_parent(void) const
std::string dir_name(void) const
bool has_subfunctions(void) const
octave_value dump(void) const
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))