Mercurial > hg > octave-lyh
changeset 2949:49b42be38aa1
[project @ 1997-05-09 13:54:29 by jwe]
author | jwe |
---|---|
date | Fri, 09 May 1997 13:58:09 +0000 |
parents | 56be458e237f |
children | 5252c7275b8c |
files | src/ChangeLog src/symtab.cc src/variables.cc src/variables.h |
diffstat | 4 files changed, 119 insertions(+), 77 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,49 @@ +Fri May 9 07:40:59 1997 John W. Eaton <jwe@bevo.che.wisc.edu> + + * variables.h (class octave_variable_reference): Rewrite to work + as a proxy class to store a pointer to octave_value and, + optionally, the change function to call and the name of the + structure element we are referencing. Handle assignment, + increment, decrement, and value operations. + + * ov-re-mat.h, ov-re-mat.cc (struct_elt_ref, struct_elt_val, + assign_struct_elt): Provide functions for looking up and setting + matrix dimensions. + + * symtab.cc (symbol_record::define): Don't call sv_fcn here. + Don't save and restore value here. + (symbol_record::define_builtin_var): Do call sv_fcn here. + (symbol_record::variable_reference): Don't make value unique here. + Return pointer to sv_fcn in octave_variable_reference. + + * pt-misc.cc (tree_parameter_list::initialize_undefined_elements): + Simplify. + + * pt-id.h, pt-id.cc (tree_identifier::reference): Return + octave_variable_reference, not octave_value&. + * symtab.h, symtab.cc (symbol_record::variable_reference): Ditto. + * pt-indir.h, pt-indir.cc (tree_indirect_ref::reference): Ditto. + Simplify too. + + * pt-const.h (tree_constant::reference, tree_constant::value, + tree_constant::assign): Delete unnecessary functions. + * pt-id.h, pt-id.cc (tree_identifier::assign): Ditto. + + * pt-cmd.cc (tree_for_command::do_for_loop_once): Simplify. + + * ov.h, ov.cc, ov-base.h, ov-base.cc, ov-struct.h, ov-struct.cc + (struct_elt_ref): New arg, octave_value* parent. + Allow deferred lookup. Return octave_variable_reference, not + octave_value&. + + * ov.h, ov.cc, ov-re-mat.h, ov-re-mat.cc (assign_struct_elt): + New virtual functions. + + * ov.h, ov.cc (Vresize_on_range_error): Now static. + + * pt-mvr.cc (tree_index_expression::eval): Delete redundant check + of error_state. + Wed May 7 21:17:00 1997 John W. Eaton <jwe@bevo.che.wisc.edu> * input.cc (generate_completion): Rename from command_generator.
--- a/src/symtab.cc +++ b/src/symtab.cc @@ -356,9 +356,6 @@ if (! (is_variable () && read_only_error ("redefine"))) { - octave_symbol *saved_def = 0; - unsigned int saved_type = symbol_def::UNKNOWN; - if (! definition) { definition = new symbol_def (); @@ -369,25 +366,11 @@ push_def (new symbol_def ()); definition->count = 1; } - else if (is_variable ()) - { - saved_def = definition->def (); - saved_type = definition->symbol_type (); - } - if (saved_type == symbol_def::BUILTIN_VARIABLE) - sym_type = saved_type; + if (definition->symbol_type () == symbol_def::BUILTIN_VARIABLE) + sym_type = symbol_def::BUILTIN_VARIABLE; definition->define (new octave_value (v), sym_type); - - if (sv_fcn && sv_fcn () < 0) - definition->define (saved_def, saved_type); - else - { - retval = 1; - - delete saved_def; - } } return retval; @@ -396,7 +379,12 @@ int symbol_record::define_builtin_var (const octave_value& v) { - return define (v, symbol_def::BUILTIN_VARIABLE); + int retval = define (v, symbol_def::BUILTIN_VARIABLE); + + if (sv_fcn) + sv_fcn (); + + return retval; } int @@ -553,7 +541,7 @@ return retval; } -octave_value& +octave_variable_reference symbol_record::variable_reference (void) { if (is_function ()) @@ -568,11 +556,8 @@ define (octave_value ()); } - octave_value *tmp = static_cast<octave_value *> (def ()); - - tmp->make_unique (); - - return *tmp; + return octave_variable_reference + (static_cast<octave_value *> (def ()), sv_fcn); } symbol_record *
--- a/src/variables.cc +++ b/src/variables.cc @@ -109,29 +109,22 @@ // Symbol table for global symbols. symbol_table *global_sym_tab = 0; -octave_variable_reference::octave_variable_reference (tree_indirect_ref *i) - : id (0), indir (i) -{ - if (indir->is_identifier_only ()) - { - id = indir->ident (); - indir = 0; - } -} - void octave_variable_reference::assign (octave_value::assign_op op, const octave_value& rhs) { - if (id) - id->assign (op, rhs); - else if (indir) - { - octave_value& ult = indir->reference (); - ult.assign (op, rhs); - } + // octave_value saved_val; + + // if (chg_fcn) + // octave_value saved_val = *val; + + if (struct_elt_name.empty ()) + val->assign (op, rhs); else - panic_impossible (); + val->assign_struct_elt (op, struct_elt_name, rhs); + + // if (chg_fcn && chg_fcn () < 0) + // *val = saved_val; } void @@ -139,32 +132,20 @@ const octave_value_list& idx, const octave_value& rhs) { - if (id) - id->assign (op, idx, rhs); - else if (indir) - { - octave_value& ult = indir->reference (); - ult.assign (op, idx, rhs); - } + octave_value saved_val; + + if (chg_fcn) + octave_value saved_val = *val; + + if (struct_elt_name.empty ()) + val->assign (op, idx, rhs); else - panic_impossible (); + val->assign_struct_elt (op, struct_elt_name, idx, rhs); + + if (chg_fcn && chg_fcn () < 0) + *val = saved_val; } -octave_value -octave_variable_reference::value (void) -{ - octave_value retval; - - if (id) - retval = id->value (); - else if (indir) - retval = indir->value (); - else - panic_impossible (); - - return retval; -} - // Initialization. // Create the initial symbol tables and set the current scope at the
--- a/src/variables.h +++ b/src/variables.h @@ -62,30 +62,60 @@ { public: - octave_variable_reference (tree_identifier *i) : id (i), indir (0) { } + octave_variable_reference (octave_value *v = 0, sv_Function f = 0) + : val (v), chg_fcn (f), struct_elt_name () { } + + octave_variable_reference (octave_value *v, const string& nm, + sv_Function f = 0) + : val (v), chg_fcn (f), struct_elt_name (nm) { } + + octave_variable_reference (const octave_variable_reference& vr) + : val (vr.val), chg_fcn (vr.chg_fcn), + struct_elt_name (vr.struct_elt_name) { } - octave_variable_reference (tree_indirect_ref *i); + octave_variable_reference& operator = (const octave_variable_reference& vr) + { + if (this != &vr) + { + val = vr.val; + chg_fcn = vr.chg_fcn; + struct_elt_name = vr.struct_elt_name; + } + + return *this; + } ~octave_variable_reference (void) { } + bool is_undefined (void) { return val->is_undefined (); } + + void define (const octave_value& v) { *val = v; } + void assign (octave_value::assign_op, const octave_value&); void assign (octave_value::assign_op, const octave_value_list&, const octave_value&); - octave_value value (void); + octave_variable_reference struct_elt_ref (const string& nm) + { return val->struct_elt_ref (nm); } + + void increment (void) { val->increment (); } + + void decrement (void) { val->decrement (); } + + octave_value value (void) + { + return struct_elt_name.empty () + ? *val : val->struct_elt_val (struct_elt_name); + } private: - tree_identifier *id; - - tree_indirect_ref *indir; + octave_value *val; - // No copying! + sv_Function chg_fcn; - octave_variable_reference (const octave_variable_reference&); - - octave_variable_reference& operator = (const octave_variable_reference&); + string struct_elt_name; }; typedef octave_value_list (*Octave_builtin_fcn)(const octave_value_list&, int);