Mercurial > octave-nkf
diff libinterp/interpfcn/symtab.h @ 16442:302157614308
deprecate symbol_table::varref functions
* ov-usr-fcn.h (octave_user_function::argn_varref,
octave_user_function::nargin_varref,
octave_user_function::nargout_varref,
octave_user_function::varargin_varref): Delete unused variables.
* symtab.h (symbol_table::symbol_record::symbol_record_ref::assign,
symbol_table::symbol_record::symbol_record_ref::do_non_const_unary_op,
symbol_table::symbol_record::do_non_const_unary_op,
(symbol_table::symbol_record::is_undefined,
symbol_table::symbol_record::assign, symbol_table::assign,
symbol_table::force_assign, symbol_table::global_assign,
symbol_table::persistent_assign, symbol_table::top_level_assign,
symbol_table::do_assign, symbol_table::do_persistent_assign):
New functions.
(symbol_table::symbol_record::symbol_record_ref::varref):
Avoid calls to deprecated functions.
(symbol_table::varref, symbol_table::force_varref,
symbol_table::global_varref, symbol_table::persistent_varref,
symbol_table::top_level_varref, symbol_table::do_varref,
symbol_table::do_persistent_varref): Deprecate.
(symbol_table::symbol_reference::is_black_hole): New function.
* oct-lvalue.h, oct-lvalue.cc: Store symbol_reference instead of
pointer to octave_value object.
(octave_lvalue::value): Now const.
(octave_lvalue::object): Delete.
* pt-id.cc (tree_identifier::lvalue): Construct octave_lvalue from
sym, not sym->varref.
* ls-mat5.cc, oct-lvalue.cc, oct-lvalue.h, pt-jit.cc, error.cc,
load-save.cc, symtab.cc, symtab.h, variables.cc, ov-fcn-handle.cc,
ov-usr-fcn.cc, ov-usr-fcn.h, oct-parse.in.yy, pt-eval.cc, pt-id.h,
pt-idx.cc, mex.cc: Change all uses of varref functions to use assign
instead. Use varval instead of varref where appropriate.
* load-save.cc (install_loaded_variable): Don't manipulate
symbol_record directly.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 06 Apr 2013 11:51:23 -0400 |
parents | 09f0cb9cac7d |
children | 0f143f68078d |
line wrap: on
line diff
--- a/libinterp/interpfcn/symtab.h Sat Apr 06 07:53:00 2013 -0400 +++ b/libinterp/interpfcn/symtab.h Sat Apr 06 11:51:23 2013 -0400 @@ -215,12 +215,63 @@ value_stack.push_back (v); } + void assign (const octave_value& value, + context_id context = xdefault_context) + { + varref (context) = value; + } + + void assign (octave_value::assign_op op, + const std::string& type, + const std::list<octave_value_list>& idx, + const octave_value& value, + context_id context = xdefault_context) + { + varref(context).assign (op, type, idx, value); + } + + void assign (octave_value::assign_op op, const octave_value& value, + context_id context = xdefault_context) + { + varref(context).assign (op, value); + } + + void do_non_const_unary_op (octave_value::unary_op op, + context_id context = xdefault_context) + { + varref(context).do_non_const_unary_op (op); + } + + void do_non_const_unary_op (octave_value::unary_op op, + const std::string& type, + const std::list<octave_value_list>& idx, + context_id context = xdefault_context) + { + varref(context).do_non_const_unary_op (op, type, idx); + } + octave_value& varref (context_id context = xdefault_context) { + // We duplicate global_varref and persistent_varref here to + // avoid calling deprecated functions. + if (is_global ()) - return symbol_table::global_varref (name); + { + symbol_table::global_table_iterator p + = symbol_table::global_table.find (name); + + return (p == symbol_table::global_table.end ()) + ? symbol_table::global_table[name] : p->second; + } else if (is_persistent ()) - return symbol_table::persistent_varref (name); + { + static octave_value foobar; + + symbol_table *inst + = symbol_table::get_instance (symbol_table::current_scope ()); + + return inst ? inst->do_persistent_varref (name) : foobar; + } else { if (context == xdefault_context) @@ -299,13 +350,12 @@ if (is_persistent ()) { - symbol_table::persistent_varref (name) - = varval (); + symbol_table::persistent_assign (name, varval ()); unmark_persistent (); } - varref () = octave_value (); + assign (octave_value ()); } } @@ -375,7 +425,7 @@ { mark_persistent (); - varref () = symbol_table::persistent_varval (name); + assign (symbol_table::persistent_varval (name)); } // FIXME -- this causes trouble with recursive calls. // else @@ -479,6 +529,40 @@ octave_value find (const octave_value_list& args = octave_value_list ()) const; + void assign (const octave_value& value, + context_id context = xdefault_context) + { + rep->assign (value, context); + } + + void assign (octave_value::assign_op op, + const std::string& type, + const std::list<octave_value_list>& idx, + const octave_value& value, + context_id context = xdefault_context) + { + rep->assign (op, type, idx, value, context); + } + + void assign (octave_value::assign_op op, const octave_value& value, + context_id context = xdefault_context) + { + rep->assign (op, value, context); + } + + void do_non_const_unary_op (octave_value::unary_op op) + { + rep->do_non_const_unary_op (op); + } + + void do_non_const_unary_op (octave_value::unary_op op, + const std::string& type, + const std::list<octave_value_list>& idx) + { + rep->do_non_const_unary_op (op, type, idx); + } + + // Delete when deprecated varref functions are removed. octave_value& varref (context_id context = xdefault_context) { return rep->varref (context); @@ -502,6 +586,11 @@ return rep->is_defined (context); } + bool is_undefined (context_id context = xdefault_context) const + { + return ! rep->is_defined (context); + } + bool is_valid (void) const { return rep->is_valid (); @@ -572,20 +661,30 @@ symbol_reference { public: - symbol_reference (void) : scope (-1) {} - - symbol_reference (symbol_record record, - scope_id curr_scope = symbol_table::current_scope ()) + + symbol_reference (void) : scope (-1) { } + + symbol_reference (const symbol_record& record, + scope_id curr_scope = symbol_table::current_scope ()) : scope (curr_scope), sym (record) - {} + { } + + symbol_reference (const symbol_reference& ref) + : scope (ref.scope), sym (ref.sym) + { } symbol_reference& operator = (const symbol_reference& ref) { - scope = ref.scope; - sym = ref.sym; + if (this != &ref) + { + scope = ref.scope; + sym = ref.sym; + } return *this; } + bool is_black_hole (void) const { return scope < 0; } + // The name is the same regardless of scope. const std::string& name (void) const { return sym.name (); } @@ -612,9 +711,11 @@ } }; private: + void update (void) const { scope_id curr_scope = symbol_table::current_scope (); + if (scope != curr_scope || ! sym.is_valid ()) { scope = curr_scope; @@ -1181,10 +1282,25 @@ return inst ? inst->do_insert (name) : foobar; } - static octave_value& varref (const std::string& name, - scope_id scope = xcurrent_scope, - context_id context = xdefault_context, - bool force_add = false) + static void assign (const std::string& name, + const octave_value& value = octave_value (), + scope_id scope = xcurrent_scope, + context_id context = xdefault_context, + bool force_add = false) + { + static octave_value foobar; + + symbol_table *inst = get_instance (scope); + + if (inst) + inst->do_assign (name, value, context, force_add); + } + + // Use assign (name, value, scope, context, force_add) instead. + static octave_value& + varref (const std::string& name, scope_id scope = xcurrent_scope, + context_id context = xdefault_context, bool force_add = false) + GCC_ATTR_DEPRECATED { static octave_value foobar; @@ -1193,13 +1309,27 @@ return inst ? inst->do_varref (name, context, force_add) : foobar; } - // Convenience function to greatly simplify + // Convenience function to simplify // octave_user_function::bind_automatic_vars - static octave_value& force_varref (const std::string& name, - scope_id scope = xcurrent_scope, - context_id context = xdefault_context) + + static void force_assign (const std::string& name, + const octave_value& value = octave_value (), + scope_id scope = xcurrent_scope, + context_id context = xdefault_context) { - return varref (name, scope, context, true); + assign (name, value, scope, context, true); + } + + // Use force_assign (name, value, scope, context) instead. + static octave_value& + force_varref (const std::string& name, scope_id scope = xcurrent_scope, + context_id context = xdefault_context) GCC_ATTR_DEPRECATED + { + static octave_value foobar; + + symbol_table *inst = get_instance (scope); + + return inst ? inst->do_varref (name, context, true) : foobar; } static octave_value varval (const std::string& name, @@ -1211,8 +1341,23 @@ return inst ? inst->do_varval (name, context) : octave_value (); } + static void + global_assign (const std::string& name, + const octave_value& value = octave_value ()) + + { + global_table_iterator p = global_table.find (name); + + if (p == global_table.end ()) + global_table[name] = value; + else + p->second = value; + } + + // Use global_assign (name, value) instead. static octave_value& - global_varref (const std::string& name) + global_varref (const std::string& name) GCC_ATTR_DEPRECATED + { global_table_iterator p = global_table.find (name); @@ -1227,10 +1372,22 @@ return (p != global_table.end ()) ? p->second : octave_value (); } + static void + top_level_assign (const std::string& name, + const octave_value& value = octave_value ()) + { + assign (name, value, top_scope (), 0); + } + + // Use top_level_assign (name, value) instead. static octave_value& - top_level_varref (const std::string& name) + top_level_varref (const std::string& name) GCC_ATTR_DEPRECATED { - return varref (name, top_scope (), 0); + static octave_value foobar; + + symbol_table *inst = get_instance (top_scope ()); + + return inst ? inst->do_varref (name, 0, true) : foobar; } static octave_value @@ -1239,7 +1396,19 @@ return varval (name, top_scope (), 0); } + static void + persistent_assign (const std::string& name, + const octave_value& value = octave_value ()) + { + symbol_table *inst = get_instance (xcurrent_scope); + + if (inst) + inst->do_persistent_assign (name, value); + } + + // Use persistent_assign (name, value) instead. static octave_value& persistent_varref (const std::string& name) + GCC_ATTR_DEPRECATED { static octave_value foobar; @@ -2241,7 +2410,7 @@ if (val.is_defined ()) { - sr.varref (0) = val; + sr.assign (val, 0); sr.mark_inherited (); } @@ -2284,7 +2453,25 @@ return p->second; } - octave_value& do_varref (const std::string& name, context_id context, bool force_add) + void do_assign (const std::string& name, const octave_value& value, + context_id context, bool force_add) + { + table_iterator p = table.find (name); + + if (p == table.end ()) + { + symbol_record& sr = do_insert (name, force_add); + + sr.assign (value, context); + } + else + p->second.assign (value, context); + } + + // Use do_assign (name, value, context, force_add) instead. + // Delete when deprecated varref functions are removed. + octave_value& do_varref (const std::string& name, context_id context, + bool force_add) { table_iterator p = table.find (name); @@ -2305,6 +2492,19 @@ return (p != table.end ()) ? p->second.varval (context) : octave_value (); } + void do_persistent_assign (const std::string& name, + const octave_value& value) + { + persistent_table_iterator p = persistent_table.find (name); + + if (p == persistent_table.end ()) + persistent_table[name] = value; + else + p->second = value; + } + + // Use do_persistent_assign (name, value) instead. + // Delete when deprecated varref functions are removed. octave_value& do_persistent_varref (const std::string& name) { persistent_table_iterator p = persistent_table.find (name); @@ -2372,7 +2572,7 @@ for (table_iterator p = table.begin (); p != table.end (); p++) { symbol_record& sr = p->second; - octave_value& val = sr.varref (); + octave_value val = sr.varval (); if (val.is_object ()) p->second.clear (my_scope); }