Mercurial > hg > octave-lojdl
changeset 2880:0a076230ca87
[project @ 1997-04-24 09:47:41 by jwe]
author | jwe |
---|---|
date | Thu, 24 Apr 1997 09:47:41 +0000 |
parents | 4309724baab6 |
children | b99a6a2619aa |
files | src/ov.cc src/ov.h |
diffstat | 2 files changed, 156 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ov.cc +++ b/src/ov.cc @@ -42,11 +42,13 @@ #include "ov-str-mat.h" #include "ov-range.h" #include "ov-struct.h" +#include "ov-list.h" #include "ov-colon.h" #include "ov-va-args.h" #include "ov-typeinfo.h" #include "defun.h" +#include "error.h" #include "gripes.h" #include "pager.h" #include "pr-output.h" @@ -124,6 +126,23 @@ struct_indent -= 2; } +// Indentation level for lists. +int list_indent = 0; + +void +increment_list_indent (void) +{ + list_indent += 2; +} + +void +decrement_list_indent (void) +{ + list_indent -= 2; +} + +// XXX FIXME XXX + // Octave's value type. string @@ -216,6 +235,56 @@ return retval; } +string +octave_value::assign_op_as_string (assign_op op) +{ + string retval; + + switch (op) + { + case asn_eq: + retval = "="; + break; + + case add_eq: + retval = "+="; + break; + + case sub_eq: + retval = "-="; + break; + + case mul_eq: + retval = "*="; + break; + + case div_eq: + retval = "/="; + break; + + case el_mul_eq: + retval = ".*="; + break; + + case el_div_eq: + retval = "./="; + break; + + case el_and_eq: + retval = "&="; + break; + + case el_or_eq: + retval = "|="; + break; + + default: + retval = "<unknown>"; + } + + return retval; +} + octave_value::octave_value (void) : rep (new octave_base_value ()) { @@ -355,7 +424,13 @@ : rep (new octave_struct (m)) { rep->count = 1; - } +} + +octave_value::octave_value (const octave_value_list& l) + : rep (new octave_list (l)) +{ + rep->count = 1; +} octave_value::octave_value (octave_value::magic_colon) : rep (new octave_magic_colon ()) @@ -389,6 +464,12 @@ } } +octave_value * +octave_value::clone (void) +{ + panic_impossible (); +} + void octave_value::maybe_mutate (void) { @@ -412,15 +493,25 @@ } octave_value& -octave_value::assign (const octave_value_list& idx, const octave_value& rhs) +octave_value::assign (assign_op, const octave_value& rhs) +{ + // XXX FIXME XXX -- make this work for ops other than `='. + + return operator = (rhs); +} + +octave_value& +octave_value::assign (octave_value::assign_op op, + const octave_value_list& idx, + const octave_value& rhs) { make_unique (); - bool assignment_ok = try_assignment (idx, rhs); + bool assignment_ok = try_assignment (op, idx, rhs); if (! (error_state || assignment_ok)) { - assignment_ok = try_assignment_with_conversion (idx, rhs); + assignment_ok = try_assignment_with_conversion (op,idx, rhs); if (! (error_state || assignment_ok)) gripe_no_conversion (type_name (), rhs.type_name ()); @@ -438,6 +529,12 @@ return rep->map_value (); } +octave_value_list +octave_value::list_value (void) const +{ + return rep->list_value (); +} + ColumnVector octave_value::vector_value (bool force_string_conv, bool force_vector_conversion) const @@ -595,7 +692,8 @@ } bool -octave_value::convert_and_assign (const octave_value_list& idx, +octave_value::convert_and_assign (octave_value::assign_op op, + const octave_value_list& idx, const octave_value& rhs) { bool assignment_ok = false; @@ -621,7 +719,7 @@ rep = tmp; rep->count = 1; - assignment_ok = try_assignment (idx, rhs); + assignment_ok = try_assignment (op, idx, rhs); if (! assignment_ok && old_rep) { @@ -646,10 +744,11 @@ } bool -octave_value::try_assignment_with_conversion (const octave_value_list& idx, +octave_value::try_assignment_with_conversion (octave_value::assign_op op, + const octave_value_list& idx, const octave_value& rhs) { - bool assignment_ok = convert_and_assign (idx, rhs); + bool assignment_ok = convert_and_assign (op, idx, rhs); if (! (error_state || assignment_ok)) { @@ -673,10 +772,10 @@ if (cf_this || cf_rhs) { - assignment_ok = try_assignment (idx, tmp_rhs); + assignment_ok = try_assignment (op, idx, tmp_rhs); if (! (error_state || assignment_ok)) - assignment_ok = convert_and_assign (idx, tmp_rhs); + assignment_ok = convert_and_assign (op, idx, tmp_rhs); } if (! assignment_ok && old_rep) @@ -696,7 +795,8 @@ } bool -octave_value::try_assignment (const octave_value_list& idx, +octave_value::try_assignment (octave_value::assign_op op, + const octave_value_list& idx, const octave_value& rhs) { bool retval = false; @@ -704,7 +804,8 @@ int t_lhs = type_id (); int t_rhs = rhs.type_id (); - assign_op_fcn f = octave_value_typeinfo::lookup_assign_op (t_lhs, t_rhs); + assign_op_fcn f + = octave_value_typeinfo::lookup_assign_op (op, t_lhs, t_rhs); if (f) { @@ -793,6 +894,7 @@ octave_char_matrix::register_type (); octave_char_matrix_str::register_type (); octave_struct::register_type (); + octave_list::register_type (); octave_all_va_args::register_type (); octave_magic_colon::register_type (); }
--- a/src/ov.h +++ b/src/ov.h @@ -37,11 +37,9 @@ #include "idx-vector.h" #include "mx-base.h" #include "oct-alloc.h" +#include "oct-sym.h" #include "str-vec.h" -#include "error.h" -#include "pt-exp.h" - class Octave_map; class octave_value_list; @@ -73,7 +71,7 @@ typedef octave_value * (*type_conv_fcn) (const octave_value&); class -octave_value +octave_value : public octave_symbol { public: @@ -102,8 +100,25 @@ unknown_binary_op }; + enum assign_op + { + asn_eq, + add_eq, + sub_eq, + mul_eq, + div_eq, + el_mul_eq, + el_div_eq, + el_and_eq, + el_or_eq, + num_assign_ops, + unknown_assign_op + }; + static string binary_op_as_string (binary_op); + static string assign_op_as_string (assign_op); + enum magic_colon { magic_colon_t }; enum all_va_args { all_va_args_t }; @@ -127,6 +142,7 @@ octave_value (double base, double limit, double inc); octave_value (const Range& r); octave_value (const Octave_map& m); + octave_value (const octave_value_list& m); octave_value (octave_value::magic_colon); octave_value (octave_value::all_va_args); @@ -147,7 +163,7 @@ // This should only be called for derived types. - virtual octave_value *clone (void) { panic_impossible (); } + virtual octave_value *clone (void); void make_unique (void) { @@ -192,7 +208,10 @@ virtual octave_value index (const octave_value_list& idx) const { return rep->index (idx); } - octave_value& assign (const octave_value_list& idx, const octave_value& rhs); + octave_value& assign (assign_op, const octave_value& rhs); + + octave_value& assign (assign_op, const octave_value_list& idx, + const octave_value& rhs); virtual idx_vector index_vector (void) const { return rep->index_vector (); } @@ -246,6 +265,9 @@ virtual bool is_map (void) const { return rep->is_map (); } + virtual bool is_list (void) const + { return rep->is_list (); } + virtual bool is_magic_colon (void) const { return rep->is_magic_colon (); } @@ -326,6 +348,8 @@ virtual Octave_map map_value (void) const; + virtual octave_value_list list_value (void) const; + virtual bool bool_value (void) const { return rep->bool_value (); } @@ -409,13 +433,14 @@ int count; // A reference count. }; - bool convert_and_assign (const octave_value_list& idx, + bool convert_and_assign (assign_op, const octave_value_list& idx, const octave_value& rhs); - bool try_assignment_with_conversion (const octave_value_list& idx, + bool try_assignment_with_conversion (assign_op, + const octave_value_list& idx, const octave_value& rhs); - bool try_assignment (const octave_value_list& idx, + bool try_assignment (assign_op, const octave_value_list& idx, const octave_value& rhs); }; @@ -472,11 +497,17 @@ // Indentation level for structures. extern int struct_indent; -extern void symbols_of_value (void); - extern void increment_struct_indent (void); extern void decrement_struct_indent (void); +// Indentation level for lists. +extern int list_indent; + +extern void increment_list_indent (void); +extern void decrement_list_indent (void); + +extern void symbols_of_value (void); + extern void install_types (void); #endif